Changes in src/molecule_dynamics.cpp [112b09:1513a74]
- File:
-
- 1 edited
-
src/molecule_dynamics.cpp (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/molecule_dynamics.cpp
r112b09 r1513a74 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp"9 10 8 #include "World.hpp" 11 9 #include "atom.hpp" 12 10 #include "config.hpp" 13 11 #include "element.hpp" 14 #include "info.hpp"15 12 #include "log.hpp" 16 13 #include "memoryallocator.hpp" … … 31 28 gsl_matrix *A = gsl_matrix_alloc(NDIM,NDIM); 32 29 gsl_vector *x = gsl_vector_alloc(NDIM); 30 atom * Runner = mol->start; 33 31 atom *Sprinter = NULL; 34 32 Vector trajectory1, trajectory2, normal, TestVector; 35 33 double Norm1, Norm2, tmp, result = 0.; 36 34 37 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 38 if ((*iter) == Walker) // hence, we only go up to the Walker, not beyond (similar to i=0; i<j; i++) 35 while (Runner->next != mol->end) { 36 Runner = Runner->next; 37 if (Runner == Walker) // hence, we only go up to the Walker, not beyond (similar to i=0; i<j; i++) 39 38 break; 40 39 // determine normalized trajectories direction vector (n1, n2) … … 43 42 trajectory1.Normalize(); 44 43 Norm1 = trajectory1.Norm(); 45 Sprinter = Params.PermutationMap[ (*iter)->nr]; // find second target point46 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - (*iter)->Trajectory.R.at(Params.startstep);44 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 45 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep); 47 46 trajectory2.Normalize(); 48 47 Norm2 = trajectory1.Norm(); 49 48 // check whether either is zero() 50 49 if ((Norm1 < MYEPSILON) && (Norm2 < MYEPSILON)) { 51 tmp = Walker->Trajectory.R.at(Params.startstep).distance( (*iter)->Trajectory.R.at(Params.startstep));50 tmp = Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.startstep)); 52 51 } else if (Norm1 < MYEPSILON) { 53 52 Sprinter = Params.PermutationMap[Walker->nr]; // find first target point 54 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - (*iter)->Trajectory.R.at(Params.startstep);53 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep); 55 54 trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything 56 55 trajectory1 -= trajectory2; // project the part in norm direction away 57 56 tmp = trajectory1.Norm(); // remaining norm is distance 58 57 } else if (Norm2 < MYEPSILON) { 59 Sprinter = Params.PermutationMap[ (*iter)->nr]; // find second target point58 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 60 59 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); // copy second offset 61 60 trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything … … 67 66 // Log() << Verbose(0) << " and "; 68 67 // Log() << Verbose(0) << trajectory2; 69 tmp = Walker->Trajectory.R.at(Params.startstep).distance( (*iter)->Trajectory.R.at(Params.startstep));68 tmp = Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.startstep)); 70 69 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 71 70 } else { // determine distance by finding minimum distance 72 // Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << * (*iter)<< " are linear independent ";71 // Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *Runner << " are linear independent "; 73 72 // Log() << Verbose(0) << endl; 74 73 // Log() << Verbose(0) << "First Trajectory: "; … … 86 85 gsl_matrix_set(A, 1, i, trajectory2[i]); 87 86 gsl_matrix_set(A, 2, i, normal[i]); 88 gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - (*iter)->Trajectory.R.at(Params.startstep)[i]));87 gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - Runner->Trajectory.R.at(Params.startstep)[i])); 89 88 } 90 89 // solve the linear system by Householder transformations … … 97 96 trajectory2.Scale(gsl_vector_get(x,1)); 98 97 normal.Scale(gsl_vector_get(x,2)); 99 TestVector = (*iter)->Trajectory.R.at(Params.startstep) + trajectory2 + normal98 TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal 100 99 - (Walker->Trajectory.R.at(Params.startstep) + trajectory1); 101 100 if (TestVector.Norm() < MYEPSILON) { … … 126 125 { 127 126 double result = 0.; 128 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 129 if ((Params.PermutationMap[Walker->nr] == Params.PermutationMap[(*iter)->nr]) && (Walker->nr < (*iter)->nr)) { 127 atom * Runner = mol->start; 128 while (Runner->next != mol->end) { 129 Runner = Runner->next; 130 if ((Params.PermutationMap[Walker->nr] == Params.PermutationMap[Runner->nr]) && (Walker->nr < Runner->nr)) { 130 131 // atom *Sprinter = PermutationMap[Walker->nr]; 131 // Log() << Verbose(0) << *Walker << " and " << * (*iter)<< " are heading to the same target at ";132 // Log() << Verbose(0) << *Walker << " and " << *Runner << " are heading to the same target at "; 132 133 // Log() << Verbose(0) << Sprinter->Trajectory.R.at(endstep); 133 134 // Log() << Verbose(0) << ", penalting." << endl; … … 160 161 // go through every atom 161 162 atom *Runner = NULL; 162 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 163 atom *Walker = start; 164 while (Walker->next != end) { 165 Walker = Walker->next; 163 166 // first term: distance to target 164 Runner = Params.PermutationMap[ (*iter)->nr]; // find target point165 tmp = ( (*iter)->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.endstep)));167 Runner = Params.PermutationMap[Walker->nr]; // find target point 168 tmp = (Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.endstep))); 166 169 tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem; 167 170 result += Params.PenaltyConstants[0] * tmp; … … 169 172 170 173 // second term: sum of distances to other trajectories 171 result += SumDistanceOfTrajectories( (*iter), this, Params);174 result += SumDistanceOfTrajectories(Walker, this, Params); 172 175 173 176 // third term: penalty for equal targets 174 result += PenalizeEqualTargets( (*iter), this, Params);177 result += PenalizeEqualTargets(Walker, this, Params); 175 178 } 176 179 … … 186 189 { 187 190 stringstream zeile1, zeile2; 188 int *DoubleList = new int[AtomCount]; 189 for(int i=0;i<AtomCount;i++) 190 DoubleList[i] = 0; 191 int *DoubleList = Calloc<int>(AtomCount, "PrintPermutationMap: *DoubleList"); 191 192 int doubles = 0; 192 193 zeile1 << "PermutationMap: "; … … 202 203 if (doubles >0) 203 204 DoLog(2) && (Log() << Verbose(2) << "Found " << doubles << " Doubles." << endl); 204 delete[](DoubleList);205 Free(&DoubleList); 205 206 // Log() << Verbose(2) << zeile1.str() << endl << zeile2.str() << endl; 206 207 }; … … 212 213 void FillDistanceList(molecule *mol, struct EvaluatePotential &Params) 213 214 { 214 for (int i=mol-> getAtomCount(); i--;) {215 for (int i=mol->AtomCount; i--;) { 215 216 Params.DistanceList[i] = new DistanceMap; // is the distance sorted target list per atom 216 217 Params.DistanceList[i]->clear(); 217 218 } 218 219 219 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 220 for (molecule::const_iterator runner = mol->begin(); runner != mol->end(); ++runner) { 221 Params.DistanceList[(*iter)->nr]->insert( DistancePair((*iter)->Trajectory.R.at(Params.startstep).distance((*runner)->Trajectory.R.at(Params.endstep)), (*runner)) ); 220 atom *Runner = NULL; 221 atom *Walker = mol->start; 222 while (Walker->next != mol->end) { 223 Walker = Walker->next; 224 Runner = mol->start; 225 while(Runner->next != mol->end) { 226 Runner = Runner->next; 227 Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.endstep)), Runner) ); 222 228 } 223 229 } … … 231 237 void CreateInitialLists(molecule *mol, struct EvaluatePotential &Params) 232 238 { 233 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 234 Params.StepList[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin(); // stores the step to the next iterator that could be a possible next target 235 Params.PermutationMap[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin()->second; // always pick target with the smallest distance 236 Params.DoubleList[Params.DistanceList[(*iter)->nr]->begin()->second->nr]++; // increase this target's source count (>1? not injective) 237 Params.DistanceIterators[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin(); // and remember which one we picked 238 DoLog(2) && (Log() << Verbose(2) << **iter << " starts with distance " << Params.DistanceList[(*iter)->nr]->begin()->first << "." << endl); 239 atom *Walker = mol->start; 240 while (Walker->next != mol->end) { 241 Walker = Walker->next; 242 Params.StepList[Walker->nr] = Params.DistanceList[Walker->nr]->begin(); // stores the step to the next iterator that could be a possible next target 243 Params.PermutationMap[Walker->nr] = Params.DistanceList[Walker->nr]->begin()->second; // always pick target with the smallest distance 244 Params.DoubleList[Params.DistanceList[Walker->nr]->begin()->second->nr]++; // increase this target's source count (>1? not injective) 245 Params.DistanceIterators[Walker->nr] = Params.DistanceList[Walker->nr]->begin(); // and remember which one we picked 246 DoLog(2) && (Log() << Verbose(2) << *Walker << " starts with distance " << Params.DistanceList[Walker->nr]->begin()->first << "." << endl); 239 247 } 240 248 }; … … 277 285 void MakeInjectivePermutation(molecule *mol, struct EvaluatePotential &Params) 278 286 { 279 molecule::const_iterator iter = mol->begin();287 atom *Walker = mol->start; 280 288 DistanceMap::iterator NewBase; 281 289 double Potential = fabs(mol->ConstrainedPotential(Params)); 282 290 283 if (mol->empty()) {284 eLog() << Verbose(1) << "Molecule is empty." << endl;285 return;286 }287 291 while ((Potential) > Params.PenaltyConstants[2]) { 288 PrintPermutationMap(mol-> getAtomCount(), Params);289 iter++;290 if ( iter == mol->end()) // round-robin at the end291 iter = mol->begin();292 if (Params.DoubleList[Params.DistanceIterators[ (*iter)->nr]->second->nr] <= 1) // no need to make those injective that aren't292 PrintPermutationMap(mol->AtomCount, Params); 293 Walker = Walker->next; 294 if (Walker == mol->end) // round-robin at the end 295 Walker = mol->start->next; 296 if (Params.DoubleList[Params.DistanceIterators[Walker->nr]->second->nr] <= 1) // no need to make those injective that aren't 293 297 continue; 294 298 // now, try finding a new one 295 Potential = TryNextNearestNeighbourForInjectivePermutation(mol, (*iter), Potential, Params);296 } 297 for (int i=mol-> getAtomCount(); i--;) // now each single entry in the DoubleList should be <=1299 Potential = TryNextNearestNeighbourForInjectivePermutation(mol, Walker, Potential, Params); 300 } 301 for (int i=mol->AtomCount; i--;) // now each single entry in the DoubleList should be <=1 298 302 if (Params.DoubleList[i] > 1) { 299 303 DoeLog(0) && (eLog()<< Verbose(0) << "Failed to create an injective PermutationMap!" << endl); … … 334 338 double Potential, OldPotential, OlderPotential; 335 339 struct EvaluatePotential Params; 336 Params.PermutationMap = new atom *[getAtomCount()];337 Params.DistanceList = new DistanceMap *[getAtomCount()];338 Params.DistanceIterators = new DistanceMap::iterator[getAtomCount()];339 Params.DoubleList = new int[getAtomCount()];340 Params.StepList = new DistanceMap::iterator[getAtomCount()];340 Params.PermutationMap = Calloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap"); 341 Params.DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**DistanceList"); 342 Params.DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DistanceIterators"); 343 Params.DoubleList = Calloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList"); 344 Params.StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*StepList"); 341 345 int round; 342 atom * Sprinter = NULL;346 atom *Walker = NULL, *Runner = NULL, *Sprinter = NULL; 343 347 DistanceMap::iterator Rider, Strider; 344 345 // set to zero346 for (int i=0;i<getAtomCount();i++) {347 Params.PermutationMap[i] = NULL;348 Params.DoubleList[i] = 0;349 }350 348 351 349 /// Minimise the potential … … 364 362 DoLog(1) && (Log() << Verbose(1) << "Making the PermutationMap injective ... " << endl); 365 363 MakeInjectivePermutation(this, Params); 366 delete[](Params.DoubleList);364 Free(&Params.DoubleList); 367 365 368 366 // argument minimise the constrained potential in this injective PermutationMap … … 373 371 DoLog(2) && (Log() << Verbose(2) << "Starting round " << ++round << ", at current potential " << OldPotential << " ... " << endl); 374 372 OlderPotential = OldPotential; 375 molecule::const_iterator iter;376 373 do { 377 iter = begin(); 378 for (; iter != end(); ++iter) { 379 PrintPermutationMap(getAtomCount(), Params); 380 Sprinter = Params.DistanceIterators[(*iter)->nr]->second; // store initial partner 381 Strider = Params.DistanceIterators[(*iter)->nr]; //remember old iterator 382 Params.DistanceIterators[(*iter)->nr] = Params.StepList[(*iter)->nr]; 383 if (Params.DistanceIterators[(*iter)->nr] == Params.DistanceList[(*iter)->nr]->end()) {// stop, before we run through the list and still on 384 Params.DistanceIterators[(*iter)->nr] == Params.DistanceList[(*iter)->nr]->begin(); 374 Walker = start; 375 while (Walker->next != end) { // pick one 376 Walker = Walker->next; 377 PrintPermutationMap(AtomCount, Params); 378 Sprinter = Params.DistanceIterators[Walker->nr]->second; // store initial partner 379 Strider = Params.DistanceIterators[Walker->nr]; //remember old iterator 380 Params.DistanceIterators[Walker->nr] = Params.StepList[Walker->nr]; 381 if (Params.DistanceIterators[Walker->nr] == Params.DistanceList[Walker->nr]->end()) {// stop, before we run through the list and still on 382 Params.DistanceIterators[Walker->nr] == Params.DistanceList[Walker->nr]->begin(); 385 383 break; 386 384 } 387 //Log() << Verbose(2) << "Current Walker: " << * (*iter) << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[(*iter)->nr]->second << "." << endl;385 //Log() << Verbose(2) << "Current Walker: " << *Walker << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[Walker->nr]->second << "." << endl; 388 386 // find source of the new target 389 molecule::const_iterator runner = begin();390 for (; runner != end(); ++runner) { // find the source whose toes we might be stepping on (Walker's new target should be in use by another already)391 if (Params.PermutationMap[ (*runner)->nr] == Params.DistanceIterators[(*iter)->nr]->second) {392 //Log() << Verbose(2) << "Found the corresponding owner " << * (*runner) << " to " << *PermutationMap[(*runner)->nr] << "." << endl;387 Runner = start->next; 388 while(Runner != end) { // find the source whose toes we might be stepping on (Walker's new target should be in use by another already) 389 if (Params.PermutationMap[Runner->nr] == Params.DistanceIterators[Walker->nr]->second) { 390 //Log() << Verbose(2) << "Found the corresponding owner " << *Runner << " to " << *PermutationMap[Runner->nr] << "." << endl; 393 391 break; 394 392 } 393 Runner = Runner->next; 395 394 } 396 if ( runner != end()) { // we found the other source395 if (Runner != end) { // we found the other source 397 396 // then look in its distance list for Sprinter 398 Rider = Params.DistanceList[ (*runner)->nr]->begin();399 for (; Rider != Params.DistanceList[ (*runner)->nr]->end(); Rider++)397 Rider = Params.DistanceList[Runner->nr]->begin(); 398 for (; Rider != Params.DistanceList[Runner->nr]->end(); Rider++) 400 399 if (Rider->second == Sprinter) 401 400 break; 402 if (Rider != Params.DistanceList[ (*runner)->nr]->end()) { // if we have found one403 //Log() << Verbose(2) << "Current Other: " << * (*runner) << " with old/next candidate " << *PermutationMap[(*runner)->nr] << "/" << *Rider->second << "." << endl;401 if (Rider != Params.DistanceList[Runner->nr]->end()) { // if we have found one 402 //Log() << Verbose(2) << "Current Other: " << *Runner << " with old/next candidate " << *PermutationMap[Runner->nr] << "/" << *Rider->second << "." << endl; 404 403 // exchange both 405 Params.PermutationMap[ (*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second; // put next farther distance into PermutationMap406 Params.PermutationMap[ (*runner)->nr] = Sprinter; // and hand the old target to its respective owner407 PrintPermutationMap( getAtomCount(), Params);404 Params.PermutationMap[Walker->nr] = Params.DistanceIterators[Walker->nr]->second; // put next farther distance into PermutationMap 405 Params.PermutationMap[Runner->nr] = Sprinter; // and hand the old target to its respective owner 406 PrintPermutationMap(AtomCount, Params); 408 407 // calculate the new potential 409 408 //Log() << Verbose(2) << "Checking new potential ..." << endl; … … 411 410 if (Potential > OldPotential) { // we made everything worse! Undo ... 412 411 //Log() << Verbose(3) << "Nay, made the potential worse: " << Potential << " vs. " << OldPotential << "!" << endl; 413 //Log() << Verbose(3) << "Setting " << * (*runner) << "'s source to " << *Params.DistanceIterators[(*runner)->nr]->second << "." << endl;412 //Log() << Verbose(3) << "Setting " << *Runner << "'s source to " << *Params.DistanceIterators[Runner->nr]->second << "." << endl; 414 413 // Undo for Runner (note, we haven't moved the iteration yet, we may use this) 415 Params.PermutationMap[ (*runner)->nr] = Params.DistanceIterators[(*runner)->nr]->second;414 Params.PermutationMap[Runner->nr] = Params.DistanceIterators[Runner->nr]->second; 416 415 // Undo for Walker 417 Params.DistanceIterators[ (*iter)->nr] = Strider; // take next farther distance target418 //Log() << Verbose(3) << "Setting " << * (*iter) << "'s source to " << *Params.DistanceIterators[(*iter)->nr]->second << "." << endl;419 Params.PermutationMap[ (*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second;416 Params.DistanceIterators[Walker->nr] = Strider; // take next farther distance target 417 //Log() << Verbose(3) << "Setting " << *Walker << "'s source to " << *Params.DistanceIterators[Walker->nr]->second << "." << endl; 418 Params.PermutationMap[Walker->nr] = Params.DistanceIterators[Walker->nr]->second; 420 419 } else { 421 Params.DistanceIterators[ (*runner)->nr] = Rider; // if successful also move the pointer in the iterator list420 Params.DistanceIterators[Runner->nr] = Rider; // if successful also move the pointer in the iterator list 422 421 DoLog(3) && (Log() << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl); 423 422 OldPotential = Potential; … … 429 428 //Log() << Verbose(0) << endl; 430 429 } else { 431 DoeLog(1) && (eLog()<< Verbose(1) << * *runner << " was not the owner of " << *Sprinter << "!" << endl);430 DoeLog(1) && (eLog()<< Verbose(1) << *Runner << " was not the owner of " << *Sprinter << "!" << endl); 432 431 exit(255); 433 432 } 434 433 } else { 435 Params.PermutationMap[ (*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second; // new target has no source!434 Params.PermutationMap[Walker->nr] = Params.DistanceIterators[Walker->nr]->second; // new target has no source! 436 435 } 437 Params.StepList[ (*iter)->nr]++; // take next farther distance target436 Params.StepList[Walker->nr]++; // take next farther distance target 438 437 } 439 } while ( ++iter != end());438 } while (Walker->next != end); 440 439 } while ((OlderPotential - OldPotential) > 1e-3); 441 440 DoLog(1) && (Log() << Verbose(1) << "done." << endl); … … 443 442 444 443 /// free memory and return with evaluated potential 445 for (int i= getAtomCount(); i--;)444 for (int i=AtomCount; i--;) 446 445 Params.DistanceList[i]->clear(); 447 delete[](Params.DistanceList);448 delete[](Params.DistanceIterators);446 Free(&Params.DistanceList); 447 Free(&Params.DistanceIterators); 449 448 return ConstrainedPotential(Params); 450 449 }; … … 484 483 // Get the Permutation Map by MinimiseConstrainedPotential 485 484 atom **PermutationMap = NULL; 486 atom * Sprinter = NULL;485 atom *Walker = NULL, *Sprinter = NULL; 487 486 if (!MapByIdentity) 488 487 MinimiseConstrainedPotential(PermutationMap, startstep, endstep, configuration.GetIsAngstroem()); 489 488 else { 490 PermutationMap = new atom *[getAtomCount()];489 PermutationMap = Malloc<atom *>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap"); 491 490 SetIndexedArrayForEachAtomTo( PermutationMap, &atom::nr ); 492 491 } … … 503 502 mol = World::getInstance().createMolecule(); 504 503 MoleculePerStep->insert(mol); 505 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 504 Walker = start; 505 while (Walker->next != end) { 506 Walker = Walker->next; 506 507 // add to molecule list 507 Sprinter = mol->AddCopyAtom( (*iter));508 Sprinter = mol->AddCopyAtom(Walker); 508 509 for (int n=NDIM;n--;) { 509 Sprinter->x[n] = (*iter)->Trajectory.R.at(startstep)[n] + (PermutationMap[(*iter)->nr]->Trajectory.R.at(endstep)[n] - (*iter)->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);510 Sprinter->x[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps); 510 511 // add to Trajectories 511 512 //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl; 512 513 if (step < MaxSteps) { 513 (*iter)->Trajectory.R.at(step)[n] = (*iter)->Trajectory.R.at(startstep)[n] + (PermutationMap[(*iter)->nr]->Trajectory.R.at(endstep)[n] - (*iter)->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);514 (*iter)->Trajectory.U.at(step)[n] = 0.;515 (*iter)->Trajectory.F.at(step)[n] = 0.;514 Walker->Trajectory.R.at(step)[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps); 515 Walker->Trajectory.U.at(step)[n] = 0.; 516 Walker->Trajectory.F.at(step)[n] = 0.; 516 517 } 517 518 } … … 521 522 522 523 // store the list to single step files 523 int *SortIndex = new int[getAtomCount()];524 for (int i= getAtomCount(); i--; )524 int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex"); 525 for (int i=AtomCount; i--; ) 525 526 SortIndex[i] = i; 526 527 status = MoleculePerStep->OutputConfigForListOfFragments(&configuration, SortIndex); 527 delete[](SortIndex);528 528 529 529 // free and return 530 delete[](PermutationMap);530 Free(&PermutationMap); 531 531 delete(MoleculePerStep); 532 532 return status; … … 548 548 bool molecule::VerletForceIntegration(char *file, config &configuration) 549 549 { 550 Info FunctionInfo(__func__);551 550 ifstream input(file); 552 551 string token; … … 568 567 return false; 569 568 } 570 if (Force.RowCounter[0] != getAtomCount()) {571 DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << getAtomCount()<< "." << endl);569 if (Force.RowCounter[0] != AtomCount) { 570 DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << AtomCount << "." << endl); 572 571 performCriticalExit(); 573 572 return false; … … 575 574 // correct Forces 576 575 Velocity.Zero(); 577 for(int i=0;i< getAtomCount();i++)576 for(int i=0;i<AtomCount;i++) 578 577 for(int d=0;d<NDIM;d++) { 579 578 Velocity[d] += Force.Matrix[0][i][d+5]; 580 579 } 581 for(int i=0;i< getAtomCount();i++)580 for(int i=0;i<AtomCount;i++) 582 581 for(int d=0;d<NDIM;d++) { 583 Force.Matrix[0][i][d+5] -= Velocity[d]/ static_cast<double>(getAtomCount());582 Force.Matrix[0][i][d+5] -= Velocity[d]/(double)AtomCount; 584 583 } 585 584 // solve a constrained potential if we are meant to … … 589 588 ConstrainedPotentialEnergy = MinimiseConstrainedPotential(PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem()); 590 589 EvaluateConstrainedForces(configuration.DoConstrainedMD, 0, PermutationMap, &Force); 591 delete[](PermutationMap);590 Free(&PermutationMap); 592 591 } 593 592 594 593 // and perform Verlet integration for each atom with position, velocity and force vector 595 594 // check size of vectors 596 //ActOnAllAtoms( &atom::ResizeTrajectory, MDSteps+10 );597 598 ActOnAllAtoms( &atom::VelocityVerletUpdate, MDSteps +1, &configuration, &Force);595 ActOnAllAtoms( &atom::ResizeTrajectory, MDSteps+10 ); 596 597 ActOnAllAtoms( &atom::VelocityVerletUpdate, MDSteps, &configuration, &Force); 599 598 } 600 599 // correct velocities (rather momenta) so that center of mass remains motionless 601 600 Velocity.Zero(); 602 601 IonMass = 0.; 603 ActOnAllAtoms ( &atom::SumUpKineticEnergy, MDSteps +1, &IonMass, &Velocity );602 ActOnAllAtoms ( &atom::SumUpKineticEnergy, MDSteps, &IonMass, &Velocity ); 604 603 605 604 // correct velocities (rather momenta) so that center of mass remains motionless 606 605 Velocity.Scale(1./IonMass); 607 606 ActualTemp = 0.; 608 ActOnAllAtoms ( &atom::CorrectVelocity, &ActualTemp, MDSteps +1, &Velocity );607 ActOnAllAtoms ( &atom::CorrectVelocity, &ActualTemp, MDSteps, &Velocity ); 609 608 Thermostats(configuration, ActualTemp, Berendsen); 610 609 MDSteps++; … … 684 683 delta_alpha = 0.; 685 684 ActOnAllAtoms( &atom::Thermostat_NoseHoover_init, MDSteps, &delta_alpha ); 686 delta_alpha = (delta_alpha - (3.* getAtomCount()+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass);685 delta_alpha = (delta_alpha - (3.*AtomCount+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass); 687 686 configuration.alpha += delta_alpha*configuration.Deltat; 688 687 DoLog(3) && (Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl);
Note:
See TracChangeset
for help on using the changeset viewer.
