# | Line 1 | Line 1 | |
---|---|---|
1 | #include <iostream> | |
2 | < | #include <cstdlib> |
3 | < | #include <cmath> |
2 | > | #include <stdlib.h> |
3 | > | #include <math.h> |
4 | ||
5 | #ifdef IS_MPI | |
6 | #include "mpiSimulation.hpp" | |
7 | #include <unistd.h> | |
8 | #endif //is_mpi | |
9 | ||
10 | + | #ifdef PROFILE |
11 | + | #include "mdProfile.hpp" |
12 | + | #endif // profile |
13 | + | |
14 | #include "Integrator.hpp" | |
15 | #include "simError.h" | |
16 | ||
17 | ||
18 | < | Integrator::Integrator( SimInfo *theInfo, ForceFields* the_ff ){ |
19 | < | |
18 | > | template<typename T> Integrator<T>::Integrator(SimInfo* theInfo, |
19 | > | ForceFields* the_ff){ |
20 | info = theInfo; | |
21 | myFF = the_ff; | |
22 | isFirst = 1; | |
# | Line 21 | Line 25 | Integrator::Integrator( SimInfo *theInfo, ForceFields* | |
25 | nMols = info->n_mol; | |
26 | ||
27 | // give a little love back to the SimInfo object | |
24 | – | |
25 | – | if( info->the_integrator != NULL ) delete info->the_integrator; |
26 | – | info->the_integrator = this; |
28 | ||
29 | < | nAtoms = info->n_atoms; |
29 | > | if (info->the_integrator != NULL){ |
30 | > | delete info->the_integrator; |
31 | > | } |
32 | ||
33 | + | nAtoms = info->n_atoms; |
34 | + | integrableObjects = info->integrableObjects; |
35 | + | |
36 | // check for constraints | |
37 | < | |
38 | < | constrainedA = NULL; |
39 | < | constrainedB = NULL; |
37 | > | |
38 | > | constrainedA = NULL; |
39 | > | constrainedB = NULL; |
40 | constrainedDsqr = NULL; | |
41 | < | moving = NULL; |
42 | < | moved = NULL; |
43 | < | oldPos = NULL; |
44 | < | |
41 | > | moving = NULL; |
42 | > | moved = NULL; |
43 | > | oldPos = NULL; |
44 | > | |
45 | nConstrained = 0; | |
46 | ||
47 | checkConstraints(); | |
48 | + | |
49 | } | |
50 | ||
51 | < | Integrator::~Integrator() { |
52 | < | |
46 | < | if( nConstrained ){ |
51 | > | template<typename T> Integrator<T>::~Integrator(){ |
52 | > | if (nConstrained){ |
53 | delete[] constrainedA; | |
54 | delete[] constrainedB; | |
55 | delete[] constrainedDsqr; | |
# | Line 51 | Line 57 | Integrator::~Integrator() { | |
57 | delete[] moved; | |
58 | delete[] oldPos; | |
59 | } | |
54 | – | |
60 | } | |
61 | ||
62 | < | void Integrator::checkConstraints( void ){ |
58 | < | |
59 | < | |
62 | > | template<typename T> void Integrator<T>::checkConstraints(void){ |
63 | isConstrained = 0; | |
64 | ||
65 | < | Constraint *temp_con; |
66 | < | Constraint *dummy_plug; |
65 | > | Constraint* temp_con; |
66 | > | Constraint* dummy_plug; |
67 | temp_con = new Constraint[info->n_SRI]; | |
68 | nConstrained = 0; | |
69 | int constrained = 0; | |
70 | < | |
70 | > | |
71 | SRI** theArray; | |
72 | < | for(int i = 0; i < nMols; i++){ |
73 | < | |
74 | < | theArray = (SRI**) molecules[i].getMyBonds(); |
75 | < | for(int j=0; j<molecules[i].getNBonds(); j++){ |
73 | < | |
72 | > | for (int i = 0; i < nMols; i++){ |
73 | > | |
74 | > | theArray = (SRI * *) molecules[i].getMyBonds(); |
75 | > | for (int j = 0; j < molecules[i].getNBonds(); j++){ |
76 | constrained = theArray[j]->is_constrained(); | |
77 | < | |
78 | < | if(constrained){ |
79 | < | |
80 | < | dummy_plug = theArray[j]->get_constraint(); |
81 | < | temp_con[nConstrained].set_a( dummy_plug->get_a() ); |
82 | < | temp_con[nConstrained].set_b( dummy_plug->get_b() ); |
83 | < | temp_con[nConstrained].set_dsqr( dummy_plug->get_dsqr() ); |
84 | < | |
85 | < | nConstrained++; |
84 | < | constrained = 0; |
77 | > | |
78 | > | if (constrained){ |
79 | > | dummy_plug = theArray[j]->get_constraint(); |
80 | > | temp_con[nConstrained].set_a(dummy_plug->get_a()); |
81 | > | temp_con[nConstrained].set_b(dummy_plug->get_b()); |
82 | > | temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
83 | > | |
84 | > | nConstrained++; |
85 | > | constrained = 0; |
86 | } | |
87 | } | |
88 | ||
89 | < | theArray = (SRI**) molecules[i].getMyBends(); |
90 | < | for(int j=0; j<molecules[i].getNBends(); j++){ |
90 | < | |
89 | > | theArray = (SRI * *) molecules[i].getMyBends(); |
90 | > | for (int j = 0; j < molecules[i].getNBends(); j++){ |
91 | constrained = theArray[j]->is_constrained(); | |
92 | < | |
93 | < | if(constrained){ |
94 | < | |
95 | < | dummy_plug = theArray[j]->get_constraint(); |
96 | < | temp_con[nConstrained].set_a( dummy_plug->get_a() ); |
97 | < | temp_con[nConstrained].set_b( dummy_plug->get_b() ); |
98 | < | temp_con[nConstrained].set_dsqr( dummy_plug->get_dsqr() ); |
99 | < | |
100 | < | nConstrained++; |
101 | < | constrained = 0; |
92 | > | |
93 | > | if (constrained){ |
94 | > | dummy_plug = theArray[j]->get_constraint(); |
95 | > | temp_con[nConstrained].set_a(dummy_plug->get_a()); |
96 | > | temp_con[nConstrained].set_b(dummy_plug->get_b()); |
97 | > | temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
98 | > | |
99 | > | nConstrained++; |
100 | > | constrained = 0; |
101 | } | |
102 | } | |
103 | ||
104 | < | theArray = (SRI**) molecules[i].getMyTorsions(); |
105 | < | for(int j=0; j<molecules[i].getNTorsions(); j++){ |
107 | < | |
104 | > | theArray = (SRI * *) molecules[i].getMyTorsions(); |
105 | > | for (int j = 0; j < molecules[i].getNTorsions(); j++){ |
106 | constrained = theArray[j]->is_constrained(); | |
107 | < | |
108 | < | if(constrained){ |
109 | < | |
110 | < | dummy_plug = theArray[j]->get_constraint(); |
111 | < | temp_con[nConstrained].set_a( dummy_plug->get_a() ); |
112 | < | temp_con[nConstrained].set_b( dummy_plug->get_b() ); |
113 | < | temp_con[nConstrained].set_dsqr( dummy_plug->get_dsqr() ); |
114 | < | |
115 | < | nConstrained++; |
118 | < | constrained = 0; |
107 | > | |
108 | > | if (constrained){ |
109 | > | dummy_plug = theArray[j]->get_constraint(); |
110 | > | temp_con[nConstrained].set_a(dummy_plug->get_a()); |
111 | > | temp_con[nConstrained].set_b(dummy_plug->get_b()); |
112 | > | temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
113 | > | |
114 | > | nConstrained++; |
115 | > | constrained = 0; |
116 | } | |
117 | } | |
118 | } | |
119 | ||
120 | < | if(nConstrained > 0){ |
121 | < | |
120 | > | |
121 | > | if (nConstrained > 0){ |
122 | isConstrained = 1; | |
123 | ||
124 | < | if(constrainedA != NULL ) delete[] constrainedA; |
125 | < | if(constrainedB != NULL ) delete[] constrainedB; |
126 | < | if(constrainedDsqr != NULL ) delete[] constrainedDsqr; |
124 | > | if (constrainedA != NULL) |
125 | > | delete[] constrainedA; |
126 | > | if (constrainedB != NULL) |
127 | > | delete[] constrainedB; |
128 | > | if (constrainedDsqr != NULL) |
129 | > | delete[] constrainedDsqr; |
130 | ||
131 | < | constrainedA = new int[nConstrained]; |
132 | < | constrainedB = new int[nConstrained]; |
131 | > | constrainedA = new int[nConstrained]; |
132 | > | constrainedB = new int[nConstrained]; |
133 | constrainedDsqr = new double[nConstrained]; | |
134 | < | |
135 | < | for( int i = 0; i < nConstrained; i++){ |
136 | < | |
134 | > | |
135 | > | for (int i = 0; i < nConstrained; i++){ |
136 | constrainedA[i] = temp_con[i].get_a(); | |
137 | constrainedB[i] = temp_con[i].get_b(); | |
138 | constrainedDsqr[i] = temp_con[i].get_dsqr(); | |
140 | – | |
139 | } | |
140 | ||
141 | < | |
142 | < | // save oldAtoms to check for lode balanceing later on. |
143 | < | |
141 | > | |
142 | > | // save oldAtoms to check for lode balancing later on. |
143 | > | |
144 | oldAtoms = nAtoms; | |
145 | < | |
145 | > | |
146 | moving = new int[nAtoms]; | |
147 | < | moved = new int[nAtoms]; |
147 | > | moved = new int[nAtoms]; |
148 | ||
149 | < | oldPos = new double[nAtoms*3]; |
149 | > | oldPos = new double[nAtoms * 3]; |
150 | } | |
151 | < | |
151 | > | |
152 | delete[] temp_con; | |
153 | } | |
154 | ||
155 | ||
156 | < | void Integrator::integrate( void ){ |
156 | > | template<typename T> void Integrator<T>::integrate(void){ |
157 | ||
158 | < | int i, j; // loop counters |
159 | < | |
160 | < | double runTime = info->run_time; |
163 | < | double sampleTime = info->sampleTime; |
164 | < | double statusTime = info->statusTime; |
158 | > | double runTime = info->run_time; |
159 | > | double sampleTime = info->sampleTime; |
160 | > | double statusTime = info->statusTime; |
161 | double thermalTime = info->thermalTime; | |
162 | + | double resetTime = info->resetTime; |
163 | ||
164 | + | double difference; |
165 | double currSample; | |
166 | double currThermal; | |
167 | double currStatus; | |
168 | < | double currTime; |
168 | > | double currReset; |
169 | ||
170 | int calcPot, calcStress; | |
173 | – | int isError; |
171 | ||
172 | + | tStats = new Thermo(info); |
173 | + | statOut = new StatWriter(info); |
174 | + | dumpOut = new DumpWriter(info); |
175 | ||
176 | – | |
177 | – | tStats = new Thermo( info ); |
178 | – | statOut = new StatWriter( info ); |
179 | – | dumpOut = new DumpWriter( info ); |
180 | – | |
176 | atoms = info->atoms; | |
182 | – | DirectionalAtom* dAtom; |
177 | ||
178 | dt = info->dt; | |
179 | dt2 = 0.5 * dt; | |
180 | ||
181 | + | readyCheck(); |
182 | + | |
183 | + | // remove center of mass drift velocity (in case we passed in a configuration |
184 | + | // that was drifting |
185 | + | tStats->removeCOMdrift(); |
186 | + | |
187 | + | // initialize the retraints if necessary |
188 | + | if (info->useSolidThermInt && !info->useLiquidThermInt) { |
189 | + | myFF->initRestraints(); |
190 | + | } |
191 | + | |
192 | // initialize the forces before the first step | |
193 | ||
194 | < | myFF->doForces(1,1); |
194 | > | calcForce(1, 1); |
195 | ||
196 | < | if( info->setTemp ){ |
197 | < | |
198 | < | tStats->velocitize(); |
196 | > | if (nConstrained){ |
197 | > | preMove(); |
198 | > | constrainA(); |
199 | > | calcForce(1, 1); |
200 | > | constrainB(); |
201 | } | |
202 | ||
203 | < | dumpOut->writeDump( 0.0 ); |
204 | < | statOut->writeStat( 0.0 ); |
205 | < | |
203 | > | if (info->setTemp){ |
204 | > | thermalize(); |
205 | > | } |
206 | > | |
207 | calcPot = 0; | |
208 | calcStress = 0; | |
209 | < | currSample = sampleTime; |
210 | < | currThermal = thermalTime; |
211 | < | currStatus = statusTime; |
212 | < | currTime = 0.0;; |
209 | > | currSample = sampleTime + info->getTime(); |
210 | > | currThermal = thermalTime+ info->getTime(); |
211 | > | currStatus = statusTime + info->getTime(); |
212 | > | currReset = resetTime + info->getTime(); |
213 | ||
214 | + | dumpOut->writeDump(info->getTime()); |
215 | + | statOut->writeStat(info->getTime()); |
216 | ||
207 | – | readyCheck(); |
217 | ||
218 | #ifdef IS_MPI | |
219 | < | strcpy( checkPointMsg, |
211 | < | "The integrator is ready to go." ); |
219 | > | strcpy(checkPointMsg, "The integrator is ready to go."); |
220 | MPIcheckPoint(); | |
221 | #endif // is_mpi | |
222 | ||
223 | < | |
224 | < | pos = Atom::getPosArray(); |
225 | < | vel = Atom::getVelArray(); |
218 | < | frc = Atom::getFrcArray(); |
219 | < | trq = Atom::getTrqArray(); |
220 | < | Amat = Atom::getAmatArray(); |
221 | < | |
222 | < | while( currTime < runTime ){ |
223 | < | |
224 | < | if( (currTime+dt) >= currStatus ){ |
223 | > | while (info->getTime() < runTime && !stopIntegrator()){ |
224 | > | difference = info->getTime() + dt - currStatus; |
225 | > | if (difference > 0 || fabs(difference) < 1e-4 ){ |
226 | calcPot = 1; | |
227 | calcStress = 1; | |
228 | } | |
229 | ||
230 | < | integrateStep( calcPot, calcStress ); |
231 | < | |
232 | < | currTime += dt; |
230 | > | #ifdef PROFILE |
231 | > | startProfile( pro1 ); |
232 | > | #endif |
233 | > | |
234 | > | integrateStep(calcPot, calcStress); |
235 | ||
236 | < | if( info->setTemp ){ |
237 | < | if( currTime >= currThermal ){ |
238 | < | tStats->velocitize(); |
239 | < | currThermal += thermalTime; |
236 | > | #ifdef PROFILE |
237 | > | endProfile( pro1 ); |
238 | > | |
239 | > | startProfile( pro2 ); |
240 | > | #endif // profile |
241 | > | |
242 | > | info->incrTime(dt); |
243 | > | |
244 | > | if (info->setTemp){ |
245 | > | if (info->getTime() >= currThermal){ |
246 | > | thermalize(); |
247 | > | currThermal += thermalTime; |
248 | } | |
249 | } | |
250 | ||
251 | < | if( currTime >= currSample ){ |
252 | < | dumpOut->writeDump( currTime ); |
251 | > | if (info->getTime() >= currSample){ |
252 | > | dumpOut->writeDump(info->getTime()); |
253 | currSample += sampleTime; | |
254 | } | |
255 | ||
256 | < | if( currTime >= currStatus ){ |
257 | < | statOut->writeStat( currTime ); |
258 | < | calcPot = 0; |
256 | > | if (info->getTime() >= currStatus){ |
257 | > | statOut->writeStat(info->getTime()); |
258 | > | if (info->useSolidThermInt || info->useLiquidThermInt) |
259 | > | statOut->writeRaw(info->getTime()); |
260 | > | calcPot = 0; |
261 | calcStress = 0; | |
262 | currStatus += statusTime; | |
263 | < | } |
263 | > | } |
264 | ||
265 | + | if (info->resetIntegrator){ |
266 | + | if (info->getTime() >= currReset){ |
267 | + | this->resetIntegrator(); |
268 | + | currReset += resetTime; |
269 | + | } |
270 | + | } |
271 | + | |
272 | + | #ifdef PROFILE |
273 | + | endProfile( pro2 ); |
274 | + | #endif //profile |
275 | + | |
276 | #ifdef IS_MPI | |
277 | < | strcpy( checkPointMsg, |
254 | < | "successfully took a time step." ); |
277 | > | strcpy(checkPointMsg, "successfully took a time step."); |
278 | MPIcheckPoint(); | |
279 | #endif // is_mpi | |
257 | – | |
280 | } | |
281 | ||
282 | < | dumpOut->writeFinal(); |
282 | > | // dump out a file containing the omega values for the final configuration |
283 | > | if (info->useSolidThermInt && !info->useLiquidThermInt) |
284 | > | myFF->dumpzAngle(); |
285 | > | |
286 | ||
287 | delete dumpOut; | |
288 | delete statOut; | |
289 | } | |
290 | ||
291 | < | void Integrator::integrateStep( int calcPot, int calcStress ){ |
292 | < | |
268 | < | |
269 | < | |
291 | > | template<typename T> void Integrator<T>::integrateStep(int calcPot, |
292 | > | int calcStress){ |
293 | // Position full step, and velocity half step | |
294 | ||
295 | + | #ifdef PROFILE |
296 | + | startProfile(pro3); |
297 | + | #endif //profile |
298 | + | |
299 | preMove(); | |
300 | + | |
301 | + | #ifdef PROFILE |
302 | + | endProfile(pro3); |
303 | + | |
304 | + | startProfile(pro4); |
305 | + | #endif // profile |
306 | + | |
307 | moveA(); | |
274 | – | if( nConstrained ) constrainA(); |
308 | ||
309 | + | #ifdef PROFILE |
310 | + | endProfile(pro4); |
311 | + | |
312 | + | startProfile(pro5); |
313 | + | #endif//profile |
314 | + | |
315 | + | |
316 | + | #ifdef IS_MPI |
317 | + | strcpy(checkPointMsg, "Succesful moveA\n"); |
318 | + | MPIcheckPoint(); |
319 | + | #endif // is_mpi |
320 | + | |
321 | // calc forces | |
322 | + | calcForce(calcPot, calcStress); |
323 | ||
324 | < | myFF->doForces(calcPot,calcStress); |
324 | > | #ifdef IS_MPI |
325 | > | strcpy(checkPointMsg, "Succesful doForces\n"); |
326 | > | MPIcheckPoint(); |
327 | > | #endif // is_mpi |
328 | ||
329 | + | #ifdef PROFILE |
330 | + | endProfile( pro5 ); |
331 | + | |
332 | + | startProfile( pro6 ); |
333 | + | #endif //profile |
334 | + | |
335 | // finish the velocity half step | |
336 | < | |
336 | > | |
337 | moveB(); | |
338 | < | if( nConstrained ) constrainB(); |
339 | < | |
338 | > | |
339 | > | #ifdef PROFILE |
340 | > | endProfile(pro6); |
341 | > | #endif // profile |
342 | > | |
343 | > | #ifdef IS_MPI |
344 | > | strcpy(checkPointMsg, "Succesful moveB\n"); |
345 | > | MPIcheckPoint(); |
346 | > | #endif // is_mpi |
347 | } | |
348 | ||
349 | ||
350 | < | void Integrator::moveA( void ){ |
351 | < | |
290 | < | int i,j,k; |
291 | < | int atomIndex, aMatIndex; |
350 | > | template<typename T> void Integrator<T>::moveA(void){ |
351 | > | size_t i, j; |
352 | DirectionalAtom* dAtom; | |
353 | < | double Tb[3]; |
354 | < | double ji[3]; |
355 | < | double angle; |
353 | > | double Tb[3], ji[3]; |
354 | > | double vel[3], pos[3], frc[3]; |
355 | > | double mass; |
356 | > | double omega; |
357 | > | |
358 | > | for (i = 0; i < integrableObjects.size() ; i++){ |
359 | > | integrableObjects[i]->getVel(vel); |
360 | > | integrableObjects[i]->getPos(pos); |
361 | > | integrableObjects[i]->getFrc(frc); |
362 | > | |
363 | > | mass = integrableObjects[i]->getMass(); |
364 | ||
365 | + | for (j = 0; j < 3; j++){ |
366 | + | // velocity half step |
367 | + | vel[j] += (dt2 * frc[j] / mass) * eConvert; |
368 | + | // position whole step |
369 | + | pos[j] += dt * vel[j]; |
370 | + | } |
371 | ||
372 | + | integrableObjects[i]->setVel(vel); |
373 | + | integrableObjects[i]->setPos(pos); |
374 | ||
375 | < | for( i=0; i<nAtoms; i++ ){ |
300 | < | atomIndex = i * 3; |
301 | < | aMatIndex = i * 9; |
375 | > | if (integrableObjects[i]->isDirectional()){ |
376 | ||
377 | < | // velocity half step |
304 | < | for( j=atomIndex; j<(atomIndex+3); j++ ) |
305 | < | vel[j] += ( dt2 * frc[j] / atoms[i]->getMass() ) * eConvert; |
377 | > | // get and convert the torque to body frame |
378 | ||
379 | < | // position whole step |
380 | < | for( j=atomIndex; j<(atomIndex+3); j++ ) pos[j] += dt * vel[j]; |
309 | < | |
310 | < | if( atoms[i]->isDirectional() ){ |
379 | > | integrableObjects[i]->getTrq(Tb); |
380 | > | integrableObjects[i]->lab2Body(Tb); |
381 | ||
312 | – | dAtom = (DirectionalAtom *)atoms[i]; |
313 | – | |
314 | – | // get and convert the torque to body frame |
315 | – | |
316 | – | Tb[0] = dAtom->getTx(); |
317 | – | Tb[1] = dAtom->getTy(); |
318 | – | Tb[2] = dAtom->getTz(); |
319 | – | |
320 | – | dAtom->lab2Body( Tb ); |
321 | – | |
382 | // get the angular momentum, and propagate a half step | |
383 | < | |
384 | < | ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert; |
385 | < | ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert; |
386 | < | ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert; |
387 | < | |
388 | < | // use the angular velocities to propagate the rotation matrix a |
389 | < | // full time step |
390 | < | |
391 | < | // rotate about the x-axis |
332 | < | angle = dt2 * ji[0] / dAtom->getIxx(); |
333 | < | this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] ); |
334 | < | |
335 | < | // rotate about the y-axis |
336 | < | angle = dt2 * ji[1] / dAtom->getIyy(); |
337 | < | this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] ); |
338 | < | |
339 | < | // rotate about the z-axis |
340 | < | angle = dt * ji[2] / dAtom->getIzz(); |
341 | < | this->rotate( 0, 1, angle, ji, &Amat[aMatIndex] ); |
342 | < | |
343 | < | // rotate about the y-axis |
344 | < | angle = dt2 * ji[1] / dAtom->getIyy(); |
345 | < | this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] ); |
346 | < | |
347 | < | // rotate about the x-axis |
348 | < | angle = dt2 * ji[0] / dAtom->getIxx(); |
349 | < | this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] ); |
350 | < | |
351 | < | dAtom->setJx( ji[0] ); |
352 | < | dAtom->setJy( ji[1] ); |
353 | < | dAtom->setJz( ji[2] ); |
383 | > | |
384 | > | integrableObjects[i]->getJ(ji); |
385 | > | |
386 | > | for (j = 0; j < 3; j++) |
387 | > | ji[j] += (dt2 * Tb[j]) * eConvert; |
388 | > | |
389 | > | this->rotationPropagation( integrableObjects[i], ji ); |
390 | > | |
391 | > | integrableObjects[i]->setJ(ji); |
392 | } | |
355 | – | |
393 | } | |
394 | + | |
395 | + | if (nConstrained){ |
396 | + | constrainA(); |
397 | + | } |
398 | } | |
399 | ||
400 | ||
401 | < | void Integrator::moveB( void ){ |
402 | < | int i,j,k; |
403 | < | int atomIndex; |
404 | < | DirectionalAtom* dAtom; |
405 | < | double Tb[3]; |
365 | < | double ji[3]; |
401 | > | template<typename T> void Integrator<T>::moveB(void){ |
402 | > | int i, j; |
403 | > | double Tb[3], ji[3]; |
404 | > | double vel[3], frc[3]; |
405 | > | double mass; |
406 | ||
407 | < | for( i=0; i<nAtoms; i++ ){ |
408 | < | atomIndex = i * 3; |
407 | > | for (i = 0; i < integrableObjects.size(); i++){ |
408 | > | integrableObjects[i]->getVel(vel); |
409 | > | integrableObjects[i]->getFrc(frc); |
410 | ||
411 | + | mass = integrableObjects[i]->getMass(); |
412 | + | |
413 | // velocity half step | |
414 | < | for( j=atomIndex; j<(atomIndex+3); j++ ) |
415 | < | vel[j] += ( dt2 * frc[j] / atoms[i]->getMass() ) * eConvert; |
414 | > | for (j = 0; j < 3; j++) |
415 | > | vel[j] += (dt2 * frc[j] / mass) * eConvert; |
416 | ||
417 | < | if( atoms[i]->isDirectional() ){ |
418 | < | |
419 | < | dAtom = (DirectionalAtom *)atoms[i]; |
420 | < | |
417 | > | integrableObjects[i]->setVel(vel); |
418 | > | |
419 | > | if (integrableObjects[i]->isDirectional()){ |
420 | > | |
421 | // get and convert the torque to body frame | |
379 | – | |
380 | – | Tb[0] = dAtom->getTx(); |
381 | – | Tb[1] = dAtom->getTy(); |
382 | – | Tb[2] = dAtom->getTz(); |
383 | – | |
384 | – | dAtom->lab2Body( Tb ); |
385 | – | |
386 | – | // get the angular momentum, and complete the angular momentum |
387 | – | // half step |
388 | – | |
389 | – | ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert; |
390 | – | ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert; |
391 | – | ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert; |
392 | – | |
393 | – | dAtom->setJx( ji[0] ); |
394 | – | dAtom->setJy( ji[1] ); |
395 | – | dAtom->setJz( ji[2] ); |
396 | – | } |
397 | – | } |
422 | ||
423 | < | } |
423 | > | integrableObjects[i]->getTrq(Tb); |
424 | > | integrableObjects[i]->lab2Body(Tb); |
425 | ||
426 | < | void Integrator::preMove( void ){ |
402 | < | int i; |
426 | > | // get the angular momentum, and propagate a half step |
427 | ||
428 | < | if( nConstrained ){ |
428 | > | integrableObjects[i]->getJ(ji); |
429 | ||
430 | < | for(i=0; i<(nAtoms*3); i++) oldPos[i] = pos[i]; |
430 | > | for (j = 0; j < 3; j++) |
431 | > | ji[j] += (dt2 * Tb[j]) * eConvert; |
432 | > | |
433 | > | |
434 | > | integrableObjects[i]->setJ(ji); |
435 | > | } |
436 | } | |
408 | – | } |
437 | ||
438 | < | void Integrator::constrainA(){ |
438 | > | if (nConstrained){ |
439 | > | constrainB(); |
440 | > | } |
441 | > | } |
442 | ||
443 | < | int i,j,k; |
443 | > | template<typename T> void Integrator<T>::preMove(void){ |
444 | > | int i, j; |
445 | > | double pos[3]; |
446 | > | |
447 | > | if (nConstrained){ |
448 | > | for (i = 0; i < nAtoms; i++){ |
449 | > | atoms[i]->getPos(pos); |
450 | > | |
451 | > | for (j = 0; j < 3; j++){ |
452 | > | oldPos[3 * i + j] = pos[j]; |
453 | > | } |
454 | > | } |
455 | > | } |
456 | > | } |
457 | > | |
458 | > | template<typename T> void Integrator<T>::constrainA(){ |
459 | > | int i, j; |
460 | int done; | |
461 | < | double pxab, pyab, pzab; |
462 | < | double rxab, ryab, rzab; |
461 | > | double posA[3], posB[3]; |
462 | > | double velA[3], velB[3]; |
463 | > | double pab[3]; |
464 | > | double rab[3]; |
465 | int a, b, ax, ay, az, bx, by, bz; | |
466 | double rma, rmb; | |
467 | double dx, dy, dz; | |
# | Line 422 | Line 471 | void Integrator::constrainA(){ | |
471 | double gab; | |
472 | int iteration; | |
473 | ||
474 | < | |
426 | < | |
427 | < | for( i=0; i<nAtoms; i++){ |
428 | < | |
474 | > | for (i = 0; i < nAtoms; i++){ |
475 | moving[i] = 0; | |
476 | < | moved[i] = 1; |
476 | > | moved[i] = 1; |
477 | } | |
478 | ||
479 | iteration = 0; | |
480 | done = 0; | |
481 | < | while( !done && (iteration < maxIteration )){ |
436 | < | |
481 | > | while (!done && (iteration < maxIteration)){ |
482 | done = 1; | |
483 | < | for(i=0; i<nConstrained; i++){ |
439 | < | |
483 | > | for (i = 0; i < nConstrained; i++){ |
484 | a = constrainedA[i]; | |
485 | b = constrainedB[i]; | |
442 | – | |
443 | – | ax = (a*3) + 0; |
444 | – | ay = (a*3) + 1; |
445 | – | az = (a*3) + 2; |
486 | ||
487 | < | bx = (b*3) + 0; |
488 | < | by = (b*3) + 1; |
489 | < | bz = (b*3) + 2; |
487 | > | ax = (a * 3) + 0; |
488 | > | ay = (a * 3) + 1; |
489 | > | az = (a * 3) + 2; |
490 | ||
491 | < | if( moved[a] || moved[b] ){ |
492 | < | |
493 | < | pxab = pos[ax] - pos[bx]; |
454 | < | pyab = pos[ay] - pos[by]; |
455 | < | pzab = pos[az] - pos[bz]; |
491 | > | bx = (b * 3) + 0; |
492 | > | by = (b * 3) + 1; |
493 | > | bz = (b * 3) + 2; |
494 | ||
495 | < | //periodic boundary condition |
496 | < | pxab = pxab - info->box_x * copysign(1, pxab) |
497 | < | * (int)( fabs(pxab / info->box_x) + 0.5); |
460 | < | pyab = pyab - info->box_y * copysign(1, pyab) |
461 | < | * (int)( fabs(pyab / info->box_y) + 0.5); |
462 | < | pzab = pzab - info->box_z * copysign(1, pzab) |
463 | < | * (int)( fabs(pzab / info->box_z) + 0.5); |
495 | > | if (moved[a] || moved[b]){ |
496 | > | atoms[a]->getPos(posA); |
497 | > | atoms[b]->getPos(posB); |
498 | ||
499 | < | pabsq = pxab * pxab + pyab * pyab + pzab * pzab; |
499 | > | for (j = 0; j < 3; j++) |
500 | > | pab[j] = posA[j] - posB[j]; |
501 | ||
502 | < | rabsq = constrainedDsqr[i]; |
468 | < | diffsq = rabsq - pabsq; |
502 | > | //periodic boundary condition |
503 | ||
504 | < | // the original rattle code from alan tidesley |
471 | < | if (fabs(diffsq) > (tol*rabsq*2)) { |
472 | < | rxab = oldPos[ax] - oldPos[bx]; |
473 | < | ryab = oldPos[ay] - oldPos[by]; |
474 | < | rzab = oldPos[az] - oldPos[bz]; |
504 | > | info->wrapVector(pab); |
505 | ||
506 | < | rxab = rxab - info->box_x * copysign(1, rxab) |
477 | < | * (int)( fabs(rxab / info->box_x) + 0.5); |
478 | < | ryab = ryab - info->box_y * copysign(1, ryab) |
479 | < | * (int)( fabs(ryab / info->box_y) + 0.5); |
480 | < | rzab = rzab - info->box_z * copysign(1, rzab) |
481 | < | * (int)( fabs(rzab / info->box_z) + 0.5); |
506 | > | pabsq = pab[0] * pab[0] + pab[1] * pab[1] + pab[2] * pab[2]; |
507 | ||
508 | < | rpab = rxab * pxab + ryab * pyab + rzab * pzab; |
508 | > | rabsq = constrainedDsqr[i]; |
509 | > | diffsq = rabsq - pabsq; |
510 | ||
511 | < | rpabsq = rpab * rpab; |
511 | > | // the original rattle code from alan tidesley |
512 | > | if (fabs(diffsq) > (tol * rabsq * 2)){ |
513 | > | rab[0] = oldPos[ax] - oldPos[bx]; |
514 | > | rab[1] = oldPos[ay] - oldPos[by]; |
515 | > | rab[2] = oldPos[az] - oldPos[bz]; |
516 | ||
517 | + | info->wrapVector(rab); |
518 | ||
519 | < | if (rpabsq < (rabsq * -diffsq)){ |
519 | > | rpab = rab[0] * pab[0] + rab[1] * pab[1] + rab[2] * pab[2]; |
520 | ||
521 | + | rpabsq = rpab * rpab; |
522 | + | |
523 | + | |
524 | + | if (rpabsq < (rabsq * -diffsq)){ |
525 | #ifdef IS_MPI | |
526 | < | a = atoms[a]->getGlobalIndex(); |
527 | < | b = atoms[b]->getGlobalIndex(); |
526 | > | a = atoms[a]->getGlobalIndex(); |
527 | > | b = atoms[b]->getGlobalIndex(); |
528 | #endif //is_mpi | |
529 | < | sprintf( painCave.errMsg, |
530 | < | "Constraint failure in constrainA at atom %d and %d.\n", |
531 | < | a, b ); |
532 | < | painCave.isFatal = 1; |
533 | < | simError(); |
534 | < | } |
529 | > | sprintf(painCave.errMsg, |
530 | > | "Constraint failure in constrainA at atom %d and %d.\n", a, |
531 | > | b); |
532 | > | painCave.isFatal = 1; |
533 | > | simError(); |
534 | > | } |
535 | ||
536 | < | rma = 1.0 / atoms[a]->getMass(); |
537 | < | rmb = 1.0 / atoms[b]->getMass(); |
536 | > | rma = 1.0 / atoms[a]->getMass(); |
537 | > | rmb = 1.0 / atoms[b]->getMass(); |
538 | ||
539 | < | gab = diffsq / ( 2.0 * ( rma + rmb ) * rpab ); |
539 | > | gab = diffsq / (2.0 * (rma + rmb) * rpab); |
540 | ||
541 | < | dx = rxab * gab; |
542 | < | dy = ryab * gab; |
543 | < | dz = rzab * gab; |
541 | > | dx = rab[0] * gab; |
542 | > | dy = rab[1] * gab; |
543 | > | dz = rab[2] * gab; |
544 | ||
545 | < | pos[ax] += rma * dx; |
546 | < | pos[ay] += rma * dy; |
547 | < | pos[az] += rma * dz; |
545 | > | posA[0] += rma * dx; |
546 | > | posA[1] += rma * dy; |
547 | > | posA[2] += rma * dz; |
548 | ||
549 | < | pos[bx] -= rmb * dx; |
515 | < | pos[by] -= rmb * dy; |
516 | < | pos[bz] -= rmb * dz; |
549 | > | atoms[a]->setPos(posA); |
550 | ||
551 | + | posB[0] -= rmb * dx; |
552 | + | posB[1] -= rmb * dy; |
553 | + | posB[2] -= rmb * dz; |
554 | + | |
555 | + | atoms[b]->setPos(posB); |
556 | + | |
557 | dx = dx / dt; | |
558 | dy = dy / dt; | |
559 | dz = dz / dt; | |
560 | ||
561 | < | vel[ax] += rma * dx; |
523 | < | vel[ay] += rma * dy; |
524 | < | vel[az] += rma * dz; |
561 | > | atoms[a]->getVel(velA); |
562 | ||
563 | < | vel[bx] -= rmb * dx; |
564 | < | vel[by] -= rmb * dy; |
565 | < | vel[bz] -= rmb * dz; |
563 | > | velA[0] += rma * dx; |
564 | > | velA[1] += rma * dy; |
565 | > | velA[2] += rma * dz; |
566 | ||
567 | < | moving[a] = 1; |
568 | < | moving[b] = 1; |
569 | < | done = 0; |
570 | < | } |
567 | > | atoms[a]->setVel(velA); |
568 | > | |
569 | > | atoms[b]->getVel(velB); |
570 | > | |
571 | > | velB[0] -= rmb * dx; |
572 | > | velB[1] -= rmb * dy; |
573 | > | velB[2] -= rmb * dz; |
574 | > | |
575 | > | atoms[b]->setVel(velB); |
576 | > | |
577 | > | moving[a] = 1; |
578 | > | moving[b] = 1; |
579 | > | done = 0; |
580 | > | } |
581 | } | |
582 | } | |
583 | < | |
584 | < | for(i=0; i<nAtoms; i++){ |
538 | < | |
583 | > | |
584 | > | for (i = 0; i < nAtoms; i++){ |
585 | moved[i] = moving[i]; | |
586 | moving[i] = 0; | |
587 | } | |
# | Line 543 | Line 589 | void Integrator::constrainA(){ | |
589 | iteration++; | |
590 | } | |
591 | ||
592 | < | if( !done ){ |
593 | < | |
594 | < | sprintf( painCave.errMsg, |
595 | < | "Constraint failure in constrainA, too many iterations: %d\n", |
550 | < | iteration ); |
592 | > | if (!done){ |
593 | > | sprintf(painCave.errMsg, |
594 | > | "Constraint failure in constrainA, too many iterations: %d\n", |
595 | > | iteration); |
596 | painCave.isFatal = 1; | |
597 | simError(); | |
598 | } | |
599 | ||
600 | } | |
601 | ||
602 | < | void Integrator::constrainB( void ){ |
603 | < | |
559 | < | int i,j,k; |
602 | > | template<typename T> void Integrator<T>::constrainB(void){ |
603 | > | int i, j; |
604 | int done; | |
605 | + | double posA[3], posB[3]; |
606 | + | double velA[3], velB[3]; |
607 | double vxab, vyab, vzab; | |
608 | < | double rxab, ryab, rzab; |
608 | > | double rab[3]; |
609 | int a, b, ax, ay, az, bx, by, bz; | |
610 | double rma, rmb; | |
611 | double dx, dy, dz; | |
612 | < | double rabsq, pabsq, rvab; |
567 | < | double diffsq; |
612 | > | double rvab; |
613 | double gab; | |
614 | int iteration; | |
615 | ||
616 | < | for(i=0; i<nAtoms; i++){ |
616 | > | for (i = 0; i < nAtoms; i++){ |
617 | moving[i] = 0; | |
618 | moved[i] = 1; | |
619 | } | |
620 | ||
621 | done = 0; | |
622 | iteration = 0; | |
623 | < | while( !done && (iteration < maxIteration ) ){ |
579 | < | |
623 | > | while (!done && (iteration < maxIteration)){ |
624 | done = 1; | |
625 | ||
626 | < | for(i=0; i<nConstrained; i++){ |
583 | < | |
626 | > | for (i = 0; i < nConstrained; i++){ |
627 | a = constrainedA[i]; | |
628 | b = constrainedB[i]; | |
629 | ||
630 | < | ax = (a*3) + 0; |
631 | < | ay = (a*3) + 1; |
632 | < | az = (a*3) + 2; |
590 | < | |
591 | < | bx = (b*3) + 0; |
592 | < | by = (b*3) + 1; |
593 | < | bz = (b*3) + 2; |
630 | > | ax = (a * 3) + 0; |
631 | > | ay = (a * 3) + 1; |
632 | > | az = (a * 3) + 2; |
633 | ||
634 | < | if( moved[a] || moved[b] ){ |
635 | < | |
636 | < | vxab = vel[ax] - vel[bx]; |
598 | < | vyab = vel[ay] - vel[by]; |
599 | < | vzab = vel[az] - vel[bz]; |
634 | > | bx = (b * 3) + 0; |
635 | > | by = (b * 3) + 1; |
636 | > | bz = (b * 3) + 2; |
637 | ||
638 | < | rxab = pos[ax] - pos[bx]; |
639 | < | ryab = pos[ay] - pos[by]; |
640 | < | rzab = pos[az] - pos[bz]; |
604 | < | |
638 | > | if (moved[a] || moved[b]){ |
639 | > | atoms[a]->getVel(velA); |
640 | > | atoms[b]->getVel(velB); |
641 | ||
642 | < | rxab = rxab - info->box_x * copysign(1, rxab) |
643 | < | * (int)( fabs(rxab / info->box_x) + 0.5); |
644 | < | ryab = ryab - info->box_y * copysign(1, ryab) |
609 | < | * (int)( fabs(ryab / info->box_y) + 0.5); |
610 | < | rzab = rzab - info->box_z * copysign(1, rzab) |
611 | < | * (int)( fabs(rzab / info->box_z) + 0.5); |
612 | < | |
613 | < | rma = 1.0 / atoms[a]->getMass(); |
614 | < | rmb = 1.0 / atoms[b]->getMass(); |
642 | > | vxab = velA[0] - velB[0]; |
643 | > | vyab = velA[1] - velB[1]; |
644 | > | vzab = velA[2] - velB[2]; |
645 | ||
646 | < | rvab = rxab * vxab + ryab * vyab + rzab * vzab; |
647 | < | |
618 | < | gab = -rvab / ( ( rma + rmb ) * constrainedDsqr[i] ); |
646 | > | atoms[a]->getPos(posA); |
647 | > | atoms[b]->getPos(posB); |
648 | ||
649 | < | if (fabs(gab) > tol) { |
650 | < | |
622 | < | dx = rxab * gab; |
623 | < | dy = ryab * gab; |
624 | < | dz = rzab * gab; |
625 | < | |
626 | < | vel[ax] += rma * dx; |
627 | < | vel[ay] += rma * dy; |
628 | < | vel[az] += rma * dz; |
649 | > | for (j = 0; j < 3; j++) |
650 | > | rab[j] = posA[j] - posB[j]; |
651 | ||
652 | < | vel[bx] -= rmb * dx; |
653 | < | vel[by] -= rmb * dy; |
654 | < | vel[bz] -= rmb * dz; |
655 | < | |
656 | < | moving[a] = 1; |
657 | < | moving[b] = 1; |
658 | < | done = 0; |
659 | < | } |
652 | > | info->wrapVector(rab); |
653 | > | |
654 | > | rma = 1.0 / atoms[a]->getMass(); |
655 | > | rmb = 1.0 / atoms[b]->getMass(); |
656 | > | |
657 | > | rvab = rab[0] * vxab + rab[1] * vyab + rab[2] * vzab; |
658 | > | |
659 | > | gab = -rvab / ((rma + rmb) * constrainedDsqr[i]); |
660 | > | |
661 | > | if (fabs(gab) > tol){ |
662 | > | dx = rab[0] * gab; |
663 | > | dy = rab[1] * gab; |
664 | > | dz = rab[2] * gab; |
665 | > | |
666 | > | velA[0] += rma * dx; |
667 | > | velA[1] += rma * dy; |
668 | > | velA[2] += rma * dz; |
669 | > | |
670 | > | atoms[a]->setVel(velA); |
671 | > | |
672 | > | velB[0] -= rmb * dx; |
673 | > | velB[1] -= rmb * dy; |
674 | > | velB[2] -= rmb * dz; |
675 | > | |
676 | > | atoms[b]->setVel(velB); |
677 | > | |
678 | > | moving[a] = 1; |
679 | > | moving[b] = 1; |
680 | > | done = 0; |
681 | > | } |
682 | } | |
683 | } | |
684 | ||
685 | < | for(i=0; i<nAtoms; i++){ |
685 | > | for (i = 0; i < nAtoms; i++){ |
686 | moved[i] = moving[i]; | |
687 | moving[i] = 0; | |
688 | } | |
689 | < | |
689 | > | |
690 | iteration++; | |
691 | } | |
692 | ||
693 | < | if( !done ){ |
694 | < | |
695 | < | |
696 | < | sprintf( painCave.errMsg, |
653 | < | "Constraint failure in constrainB, too many iterations: %d\n", |
654 | < | iteration ); |
693 | > | if (!done){ |
694 | > | sprintf(painCave.errMsg, |
695 | > | "Constraint failure in constrainB, too many iterations: %d\n", |
696 | > | iteration); |
697 | painCave.isFatal = 1; | |
698 | simError(); | |
699 | < | } |
658 | < | |
699 | > | } |
700 | } | |
701 | ||
702 | + | template<typename T> void Integrator<T>::rotationPropagation |
703 | + | ( StuntDouble* sd, double ji[3] ){ |
704 | ||
705 | + | double angle; |
706 | + | double A[3][3], I[3][3]; |
707 | + | int i, j, k; |
708 | ||
709 | + | // use the angular velocities to propagate the rotation matrix a |
710 | + | // full time step |
711 | ||
712 | + | sd->getA(A); |
713 | + | sd->getI(I); |
714 | ||
715 | + | if (sd->isLinear()) { |
716 | + | i = sd->linearAxis(); |
717 | + | j = (i+1)%3; |
718 | + | k = (i+2)%3; |
719 | + | |
720 | + | angle = dt2 * ji[j] / I[j][j]; |
721 | + | this->rotate( k, i, angle, ji, A ); |
722 | ||
723 | + | angle = dt * ji[k] / I[k][k]; |
724 | + | this->rotate( i, j, angle, ji, A); |
725 | ||
726 | < | void Integrator::rotate( int axes1, int axes2, double angle, double ji[3], |
727 | < | double A[9] ){ |
726 | > | angle = dt2 * ji[j] / I[j][j]; |
727 | > | this->rotate( k, i, angle, ji, A ); |
728 | ||
729 | < | int i,j,k; |
729 | > | } else { |
730 | > | // rotate about the x-axis |
731 | > | angle = dt2 * ji[0] / I[0][0]; |
732 | > | this->rotate( 1, 2, angle, ji, A ); |
733 | > | |
734 | > | // rotate about the y-axis |
735 | > | angle = dt2 * ji[1] / I[1][1]; |
736 | > | this->rotate( 2, 0, angle, ji, A ); |
737 | > | |
738 | > | // rotate about the z-axis |
739 | > | angle = dt * ji[2] / I[2][2]; |
740 | > | sd->addZangle(angle); |
741 | > | this->rotate( 0, 1, angle, ji, A); |
742 | > | |
743 | > | // rotate about the y-axis |
744 | > | angle = dt2 * ji[1] / I[1][1]; |
745 | > | this->rotate( 2, 0, angle, ji, A ); |
746 | > | |
747 | > | // rotate about the x-axis |
748 | > | angle = dt2 * ji[0] / I[0][0]; |
749 | > | this->rotate( 1, 2, angle, ji, A ); |
750 | > | |
751 | > | } |
752 | > | sd->setA( A ); |
753 | > | } |
754 | > | |
755 | > | template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
756 | > | double angle, double ji[3], |
757 | > | double A[3][3]){ |
758 | > | int i, j, k; |
759 | double sinAngle; | |
760 | double cosAngle; | |
761 | double angleSqr; | |
# | Line 679 | Line 767 | void Integrator::rotate( int axes1, int axes2, double | |
767 | ||
768 | // initialize the tempA | |
769 | ||
770 | < | for(i=0; i<3; i++){ |
771 | < | for(j=0; j<3; j++){ |
772 | < | tempA[j][i] = A[3*i + j]; |
770 | > | for (i = 0; i < 3; i++){ |
771 | > | for (j = 0; j < 3; j++){ |
772 | > | tempA[j][i] = A[i][j]; |
773 | } | |
774 | } | |
775 | ||
776 | // initialize the tempJ | |
777 | ||
778 | < | for( i=0; i<3; i++) tempJ[i] = ji[i]; |
779 | < | |
778 | > | for (i = 0; i < 3; i++) |
779 | > | tempJ[i] = ji[i]; |
780 | > | |
781 | // initalize rot as a unit matrix | |
782 | ||
783 | rot[0][0] = 1.0; | |
# | Line 698 | Line 787 | void Integrator::rotate( int axes1, int axes2, double | |
787 | rot[1][0] = 0.0; | |
788 | rot[1][1] = 1.0; | |
789 | rot[1][2] = 0.0; | |
790 | < | |
790 | > | |
791 | rot[2][0] = 0.0; | |
792 | rot[2][1] = 0.0; | |
793 | rot[2][2] = 1.0; | |
794 | < | |
794 | > | |
795 | // use a small angle aproximation for sin and cosine | |
796 | ||
797 | < | angleSqr = angle * angle; |
797 | > | angleSqr = angle * angle; |
798 | angleSqrOver4 = angleSqr / 4.0; | |
799 | top = 1.0 - angleSqrOver4; | |
800 | bottom = 1.0 + angleSqrOver4; | |
# | Line 718 | Line 807 | void Integrator::rotate( int axes1, int axes2, double | |
807 | ||
808 | rot[axes1][axes2] = sinAngle; | |
809 | rot[axes2][axes1] = -sinAngle; | |
810 | < | |
810 | > | |
811 | // rotate the momentum acoording to: ji[] = rot[][] * ji[] | |
812 | < | |
813 | < | for(i=0; i<3; i++){ |
812 | > | |
813 | > | for (i = 0; i < 3; i++){ |
814 | ji[i] = 0.0; | |
815 | < | for(k=0; k<3; k++){ |
815 | > | for (k = 0; k < 3; k++){ |
816 | ji[i] += rot[i][k] * tempJ[k]; | |
817 | } | |
818 | } | |
819 | ||
820 | < | // rotate the Rotation matrix acording to: |
820 | > | // rotate the Rotation matrix acording to: |
821 | // A[][] = A[][] * transpose(rot[][]) | |
822 | ||
823 | ||
# | Line 736 | Line 825 | void Integrator::rotate( int axes1, int axes2, double | |
825 | // calculation as: | |
826 | // transpose(A[][]) = transpose(A[][]) * transpose(rot[][]) | |
827 | ||
828 | < | for(i=0; i<3; i++){ |
829 | < | for(j=0; j<3; j++){ |
830 | < | A[3*j + i] = 0.0; |
831 | < | for(k=0; k<3; k++){ |
832 | < | A[3*j + i] += tempA[i][k] * rot[j][k]; |
828 | > | for (i = 0; i < 3; i++){ |
829 | > | for (j = 0; j < 3; j++){ |
830 | > | A[j][i] = 0.0; |
831 | > | for (k = 0; k < 3; k++){ |
832 | > | A[j][i] += tempA[i][k] * rot[j][k]; |
833 | } | |
834 | } | |
835 | } | |
836 | } | |
837 | + | |
838 | + | template<typename T> void Integrator<T>::calcForce(int calcPot, int calcStress){ |
839 | + | myFF->doForces(calcPot, calcStress); |
840 | + | } |
841 | + | |
842 | + | template<typename T> void Integrator<T>::thermalize(){ |
843 | + | tStats->velocitize(); |
844 | + | } |
845 | + | |
846 | + | template<typename T> double Integrator<T>::getConservedQuantity(void){ |
847 | + | return tStats->getTotalE(); |
848 | + | } |
849 | + | template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
850 | + | //By default, return a null string |
851 | + | //The reason we use string instead of char* is that if we use char*, we will |
852 | + | //return a pointer point to local variable which might cause problem |
853 | + | return string(); |
854 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |