Changeset 0d111b for molecuilder/src/molecule_dynamics.cpp
- Timestamp:
- Apr 29, 2010, 1:55:21 PM (16 years ago)
- Children:
- 070651, 5d1a94
- Parents:
- 90c4460 (diff), 32842d8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
molecuilder/src/molecule_dynamics.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/molecule_dynamics.cpp
r90c4460 r0d111b 14 14 #include "molecule.hpp" 15 15 #include "parser.hpp" 16 #include "Plane.hpp" 16 17 17 18 /************************************* Functions for class molecule *********************************/ … … 38 39 // determine normalized trajectories direction vector (n1, n2) 39 40 Sprinter = Params.PermutationMap[Walker->nr]; // find first target point 40 trajectory1.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); 41 trajectory1.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); 41 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); 42 42 trajectory1.Normalize(); 43 43 Norm1 = trajectory1.Norm(); 44 44 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 45 trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); 46 trajectory2.SubtractVector(&Runner->Trajectory.R.at(Params.startstep)); 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( &Runner->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.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); // copy first offset 55 trajectory1.SubtractVector(&Runner->Trajectory.R.at(Params.startstep)); // subtract second offset 56 trajectory2.Scale( trajectory1.ScalarProduct(&trajectory2) ); // trajectory2 is scaled to unity, hence we don't need to divide by anything 57 trajectory1.SubtractVector(&trajectory2); // project the part in norm direction away 53 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep); 54 trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything 55 trajectory1 -= trajectory2; // project the part in norm direction away 58 56 tmp = trajectory1.Norm(); // remaining norm is distance 59 57 } else if (Norm2 < MYEPSILON) { 60 58 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 61 trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); // copy second offset 62 trajectory2.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); // subtract first offset 63 trajectory1.Scale( trajectory2.ScalarProduct(&trajectory1) ); // trajectory1 is scaled to unity, hence we don't need to divide by anything 64 trajectory2.SubtractVector(&trajectory1); // project the part in norm direction away 59 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); // copy second offset 60 trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything 61 trajectory2 -= trajectory1; // project the part in norm direction away 65 62 tmp = trajectory2.Norm(); // remaining norm is distance 66 } else if ((fabs(trajectory1.ScalarProduct( &trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent63 } else if ((fabs(trajectory1.ScalarProduct(trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent 67 64 // Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *Runner << " are linear dependent: "; 68 65 // Log() << Verbose(0) << trajectory1; 69 66 // Log() << Verbose(0) << " and "; 70 67 // Log() << Verbose(0) << trajectory2; 71 tmp = Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.startstep));68 tmp = Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.startstep)); 72 69 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 73 70 } else { // determine distance by finding minimum distance … … 79 76 // Log() << Verbose(0) << trajectory2 << endl; 80 77 // determine normal vector for both 81 normal .MakeNormalVector(&trajectory1, &trajectory2);78 normal = Plane(trajectory1, trajectory2,0).getNormal(); 82 79 // print all vectors for debugging 83 80 // Log() << Verbose(0) << "Normal vector in between: "; … … 85 82 // setup matrix 86 83 for (int i=NDIM;i--;) { 87 gsl_matrix_set(A, 0, i, trajectory1 .x[i]);88 gsl_matrix_set(A, 1, i, trajectory2 .x[i]);89 gsl_matrix_set(A, 2, i, normal .x[i]);90 gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep) .x[i] - Runner->Trajectory.R.at(Params.startstep).x[i]));84 gsl_matrix_set(A, 0, i, trajectory1[i]); 85 gsl_matrix_set(A, 1, i, trajectory2[i]); 86 gsl_matrix_set(A, 2, i, normal[i]); 87 gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - Runner->Trajectory.R.at(Params.startstep)[i])); 91 88 } 92 89 // solve the linear system by Householder transformations … … 96 93 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 97 94 // test whether we really have the intersection (by checking on c_1 and c_2) 98 TestVector.CopyVector(&Runner->Trajectory.R.at(Params.startstep));95 trajectory1.Scale(gsl_vector_get(x,0)); 99 96 trajectory2.Scale(gsl_vector_get(x,1)); 100 TestVector.AddVector(&trajectory2);101 97 normal.Scale(gsl_vector_get(x,2)); 102 TestVector.AddVector(&normal); 103 TestVector.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); 104 trajectory1.Scale(gsl_vector_get(x,0)); 105 TestVector.SubtractVector(&trajectory1); 98 TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal 99 - (Walker->Trajectory.R.at(Params.startstep) + trajectory1); 106 100 if (TestVector.Norm() < MYEPSILON) { 107 101 // Log() << Verbose(2) << "Test: ok.\tDistance of " << tmp << " is correct." << endl; … … 172 166 // first term: distance to target 173 167 Runner = Params.PermutationMap[Walker->nr]; // find target point 174 tmp = (Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.endstep)));168 tmp = (Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep))); 175 169 tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem; 176 170 result += Params.PenaltyConstants[0] * tmp; … … 231 225 while(Runner->next != mol->end) { 232 226 Runner = Runner->next; 233 Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.endstep)), Runner) );227 Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep)), Runner) ); 234 228 } 235 229 } … … 514 508 Sprinter = mol->AddCopyAtom(Walker); 515 509 for (int n=NDIM;n--;) { 516 Sprinter->x .x[n] = Walker->Trajectory.R.at(startstep).x[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep).x[n] - Walker->Trajectory.R.at(startstep).x[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); 517 511 // add to Trajectories 518 512 //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl; 519 513 if (step < MaxSteps) { 520 Walker->Trajectory.R.at(step) .x[n] = Walker->Trajectory.R.at(startstep).x[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep).x[n] - Walker->Trajectory.R.at(startstep).x[n])*((double)step/(double)MaxSteps);521 Walker->Trajectory.U.at(step) .x[n] = 0.;522 Walker->Trajectory.F.at(step) .x[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.; 523 517 } 524 518 } … … 582 576 for(int i=0;i<AtomCount;i++) 583 577 for(int d=0;d<NDIM;d++) { 584 Velocity .x[d] += Force.Matrix[0][i][d+5];578 Velocity[d] += Force.Matrix[0][i][d+5]; 585 579 } 586 580 for(int i=0;i<AtomCount;i++) 587 581 for(int d=0;d<NDIM;d++) { 588 Force.Matrix[0][i][d+5] -= Velocity .x[d]/(double)AtomCount;582 Force.Matrix[0][i][d+5] -= Velocity[d]/(double)AtomCount; 589 583 } 590 584 // solve a constrained potential if we are meant to
Note:
See TracChangeset
for help on using the changeset viewer.
