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