# | Line 11 | Line 11 | |
---|---|---|
11 | #include "simError.h" | |
12 | ||
13 | ||
14 | < | Integrator::Integrator( SimInfo *theInfo, ForceFields* the_ff ){ |
15 | < | |
14 | > | template<typename T> Integrator<T>::Integrator(SimInfo* theInfo, |
15 | > | ForceFields* the_ff){ |
16 | info = theInfo; | |
17 | myFF = the_ff; | |
18 | isFirst = 1; | |
# | Line 21 | Line 21 | Integrator::Integrator( SimInfo *theInfo, ForceFields* | |
21 | nMols = info->n_mol; | |
22 | ||
23 | // give a little love back to the SimInfo object | |
24 | < | |
25 | < | if( info->the_integrator != NULL ) delete info->the_integrator; |
24 | > | |
25 | > | if (info->the_integrator != NULL){ |
26 | > | delete info->the_integrator; |
27 | > | } |
28 | info->the_integrator = this; | |
29 | ||
30 | nAtoms = info->n_atoms; | |
31 | ||
32 | // check for constraints | |
33 | < | |
34 | < | constrainedA = NULL; |
35 | < | constrainedB = NULL; |
33 | > | |
34 | > | constrainedA = NULL; |
35 | > | constrainedB = NULL; |
36 | constrainedDsqr = NULL; | |
37 | < | moving = NULL; |
38 | < | moved = NULL; |
39 | < | oldPos = NULL; |
40 | < | |
37 | > | moving = NULL; |
38 | > | moved = NULL; |
39 | > | oldPos = NULL; |
40 | > | |
41 | nConstrained = 0; | |
42 | ||
43 | checkConstraints(); | |
44 | } | |
45 | ||
46 | < | Integrator::~Integrator() { |
47 | < | |
46 | < | if( nConstrained ){ |
46 | > | template<typename T> Integrator<T>::~Integrator(){ |
47 | > | if (nConstrained){ |
48 | delete[] constrainedA; | |
49 | delete[] constrainedB; | |
50 | delete[] constrainedDsqr; | |
# | Line 51 | Line 52 | Integrator::~Integrator() { | |
52 | delete[] moved; | |
53 | delete[] oldPos; | |
54 | } | |
54 | – | |
55 | } | |
56 | ||
57 | < | void Integrator::checkConstraints( void ){ |
58 | < | |
59 | < | |
57 | > | template<typename T> void Integrator<T>::checkConstraints(void){ |
58 | isConstrained = 0; | |
59 | ||
60 | < | Constraint *temp_con; |
61 | < | Constraint *dummy_plug; |
60 | > | Constraint* temp_con; |
61 | > | Constraint* dummy_plug; |
62 | temp_con = new Constraint[info->n_SRI]; | |
63 | nConstrained = 0; | |
64 | int constrained = 0; | |
65 | < | |
65 | > | |
66 | SRI** theArray; | |
67 | < | for(int i = 0; i < nMols; i++){ |
68 | < | |
69 | < | theArray = (SRI**) molecules[i].getMyBonds(); |
72 | < | for(int j=0; j<molecules[i].getNBonds(); j++){ |
73 | < | |
67 | > | for (int i = 0; i < nMols; i++){ |
68 | > | theArray = (SRI * *) molecules[i].getMyBonds(); |
69 | > | for (int j = 0; j < molecules[i].getNBonds(); j++){ |
70 | constrained = theArray[j]->is_constrained(); | |
71 | ||
72 | < | if(constrained){ |
72 | > | if (constrained){ |
73 | > | dummy_plug = theArray[j]->get_constraint(); |
74 | > | temp_con[nConstrained].set_a(dummy_plug->get_a()); |
75 | > | temp_con[nConstrained].set_b(dummy_plug->get_b()); |
76 | > | temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
77 | ||
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 | < | } |
78 | > | nConstrained++; |
79 | > | constrained = 0; |
80 | > | } |
81 | } | |
82 | ||
83 | < | theArray = (SRI**) molecules[i].getMyBends(); |
84 | < | for(int j=0; j<molecules[i].getNBends(); j++){ |
90 | < | |
83 | > | theArray = (SRI * *) molecules[i].getMyBends(); |
84 | > | for (int j = 0; j < molecules[i].getNBends(); j++){ |
85 | constrained = theArray[j]->is_constrained(); | |
86 | < | |
87 | < | if(constrained){ |
88 | < | |
89 | < | dummy_plug = theArray[j]->get_constraint(); |
90 | < | temp_con[nConstrained].set_a( dummy_plug->get_a() ); |
91 | < | temp_con[nConstrained].set_b( dummy_plug->get_b() ); |
92 | < | temp_con[nConstrained].set_dsqr( dummy_plug->get_dsqr() ); |
93 | < | |
94 | < | nConstrained++; |
101 | < | constrained = 0; |
86 | > | |
87 | > | if (constrained){ |
88 | > | dummy_plug = theArray[j]->get_constraint(); |
89 | > | temp_con[nConstrained].set_a(dummy_plug->get_a()); |
90 | > | temp_con[nConstrained].set_b(dummy_plug->get_b()); |
91 | > | temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
92 | > | |
93 | > | nConstrained++; |
94 | > | constrained = 0; |
95 | } | |
96 | } | |
97 | ||
98 | < | theArray = (SRI**) molecules[i].getMyTorsions(); |
99 | < | for(int j=0; j<molecules[i].getNTorsions(); j++){ |
107 | < | |
98 | > | theArray = (SRI * *) molecules[i].getMyTorsions(); |
99 | > | for (int j = 0; j < molecules[i].getNTorsions(); j++){ |
100 | constrained = theArray[j]->is_constrained(); | |
101 | < | |
102 | < | if(constrained){ |
103 | < | |
104 | < | dummy_plug = theArray[j]->get_constraint(); |
105 | < | temp_con[nConstrained].set_a( dummy_plug->get_a() ); |
106 | < | temp_con[nConstrained].set_b( dummy_plug->get_b() ); |
107 | < | temp_con[nConstrained].set_dsqr( dummy_plug->get_dsqr() ); |
108 | < | |
109 | < | nConstrained++; |
118 | < | constrained = 0; |
101 | > | |
102 | > | if (constrained){ |
103 | > | dummy_plug = theArray[j]->get_constraint(); |
104 | > | temp_con[nConstrained].set_a(dummy_plug->get_a()); |
105 | > | temp_con[nConstrained].set_b(dummy_plug->get_b()); |
106 | > | temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
107 | > | |
108 | > | nConstrained++; |
109 | > | constrained = 0; |
110 | } | |
111 | } | |
112 | } | |
113 | ||
114 | < | if(nConstrained > 0){ |
124 | < | |
114 | > | if (nConstrained > 0){ |
115 | isConstrained = 1; | |
116 | ||
117 | < | if(constrainedA != NULL ) delete[] constrainedA; |
118 | < | if(constrainedB != NULL ) delete[] constrainedB; |
119 | < | if(constrainedDsqr != NULL ) delete[] constrainedDsqr; |
117 | > | if (constrainedA != NULL) |
118 | > | delete[] constrainedA; |
119 | > | if (constrainedB != NULL) |
120 | > | delete[] constrainedB; |
121 | > | if (constrainedDsqr != NULL) |
122 | > | delete[] constrainedDsqr; |
123 | ||
124 | < | constrainedA = new int[nConstrained]; |
125 | < | constrainedB = new int[nConstrained]; |
124 | > | constrainedA = new int[nConstrained]; |
125 | > | constrainedB = new int[nConstrained]; |
126 | constrainedDsqr = new double[nConstrained]; | |
127 | < | |
128 | < | for( int i = 0; i < nConstrained; i++){ |
136 | < | |
127 | > | |
128 | > | for (int i = 0; i < nConstrained; i++){ |
129 | constrainedA[i] = temp_con[i].get_a(); | |
130 | constrainedB[i] = temp_con[i].get_b(); | |
131 | constrainedDsqr[i] = temp_con[i].get_dsqr(); | |
140 | – | |
132 | } | |
133 | ||
134 | < | |
134 | > | |
135 | // save oldAtoms to check for lode balanceing later on. | |
136 | < | |
136 | > | |
137 | oldAtoms = nAtoms; | |
138 | < | |
138 | > | |
139 | moving = new int[nAtoms]; | |
140 | < | moved = new int[nAtoms]; |
140 | > | moved = new int[nAtoms]; |
141 | ||
142 | < | oldPos = new double[nAtoms*3]; |
142 | > | oldPos = new double[nAtoms * 3]; |
143 | } | |
144 | < | |
144 | > | |
145 | delete[] temp_con; | |
146 | } | |
147 | ||
148 | ||
149 | < | void Integrator::integrate( void ){ |
159 | < | |
149 | > | template<typename T> void Integrator<T>::integrate(void){ |
150 | int i, j; // loop counters | |
151 | ||
152 | < | double runTime = info->run_time; |
153 | < | double sampleTime = info->sampleTime; |
154 | < | double statusTime = info->statusTime; |
152 | > | double runTime = info->run_time; |
153 | > | double sampleTime = info->sampleTime; |
154 | > | double statusTime = info->statusTime; |
155 | double thermalTime = info->thermalTime; | |
156 | ||
157 | double currSample; | |
# | Line 171 | Line 161 | void Integrator::integrate( void ){ | |
161 | int calcPot, calcStress; | |
162 | int isError; | |
163 | ||
164 | < | tStats = new Thermo( info ); |
165 | < | statOut = new StatWriter( info ); |
166 | < | dumpOut = new DumpWriter( info ); |
164 | > | tStats = new Thermo(info); |
165 | > | statOut = new StatWriter(info); |
166 | > | dumpOut = new DumpWriter(info); |
167 | ||
168 | atoms = info->atoms; | |
169 | DirectionalAtom* dAtom; | |
# | Line 183 | Line 173 | void Integrator::integrate( void ){ | |
173 | ||
174 | // initialize the forces before the first step | |
175 | ||
176 | < | myFF->doForces(1,1); |
177 | < | |
178 | < | if( info->setTemp ){ |
179 | < | |
180 | < | tStats->velocitize(); |
176 | > | calcForce(1, 1); |
177 | > | // myFF->doForces(1,1); |
178 | > | |
179 | > | if (info->setTemp){ |
180 | > | thermalize(); |
181 | } | |
182 | + | |
183 | + | calcPot = 0; |
184 | + | calcStress = 0; |
185 | + | currSample = sampleTime; |
186 | + | currThermal = thermalTime; |
187 | + | currStatus = statusTime; |
188 | ||
189 | calcPot = 0; | |
190 | calcStress = 0; | |
191 | < | currSample = sampleTime; |
192 | < | currThermal = thermalTime; |
193 | < | currStatus = statusTime; |
191 | > | currSample = sampleTime + info->getTime(); |
192 | > | currThermal = thermalTime+ info->getTime(); |
193 | > | currStatus = statusTime + info->getTime(); |
194 | > | >>>>>>> 1.18 |
195 | ||
196 | < | dumpOut->writeDump( info->currTime ); |
197 | < | statOut->writeStat( info->currTime ); |
196 | > | dumpOut->writeDump(info->getTime()); |
197 | > | statOut->writeStat(info->getTime()); |
198 | ||
199 | readyCheck(); | |
200 | ||
201 | #ifdef IS_MPI | |
202 | < | strcpy( checkPointMsg, |
206 | < | "The integrator is ready to go." ); |
202 | > | strcpy(checkPointMsg, "The integrator is ready to go."); |
203 | MPIcheckPoint(); | |
204 | #endif // is_mpi | |
205 | ||
206 | < | while( info->currTime < runTime ){ |
207 | < | |
212 | < | if( (info->currTime+dt) >= currStatus ){ |
206 | > | while (info->getTime() < runTime){ |
207 | > | if ((info->getTime() + dt) >= currStatus){ |
208 | calcPot = 1; | |
209 | calcStress = 1; | |
210 | } | |
211 | ||
212 | < | integrateStep( calcPot, calcStress ); |
218 | < | |
219 | < | info->currTime += dt; |
220 | < | info->setTime(info->currTime); |
212 | > | integrateStep(calcPot, calcStress); |
213 | ||
214 | < | if( info->setTemp ){ |
215 | < | if( info->currTime >= currThermal ){ |
216 | < | tStats->velocitize(); |
217 | < | currThermal += thermalTime; |
214 | > | info->incrTime(dt); |
215 | > | |
216 | > | if (info->setTemp){ |
217 | > | if (info->getTime() >= currThermal){ |
218 | > | thermalize(); |
219 | > | currThermal += thermalTime; |
220 | } | |
221 | } | |
222 | ||
223 | < | if( info->currTime >= currSample ){ |
224 | < | dumpOut->writeDump( info->currTime ); |
223 | > | if (info->getTime() >= currSample){ |
224 | > | dumpOut->writeDump(info->getTime()); |
225 | currSample += sampleTime; | |
226 | } | |
227 | ||
228 | < | if( info->currTime >= currStatus ){ |
229 | < | statOut->writeStat( info->currTime ); |
228 | > | if (info->getTime() >= currStatus){ |
229 | > | statOut->writeStat(info->getTime()); |
230 | calcPot = 0; | |
231 | calcStress = 0; | |
232 | currStatus += statusTime; | |
233 | } | |
234 | ||
235 | #ifdef IS_MPI | |
236 | < | strcpy( checkPointMsg, |
243 | < | "successfully took a time step." ); |
236 | > | strcpy(checkPointMsg, "successfully took a time step."); |
237 | MPIcheckPoint(); | |
238 | #endif // is_mpi | |
246 | – | |
239 | } | |
240 | ||
241 | < | dumpOut->writeFinal(info->currTime); |
241 | > | dumpOut->writeFinal(info->getTime()); |
242 | ||
243 | delete dumpOut; | |
244 | delete statOut; | |
245 | } | |
246 | ||
247 | < | void Integrator::integrateStep( int calcPot, int calcStress ){ |
248 | < | |
257 | < | |
258 | < | |
247 | > | template<typename T> void Integrator<T>::integrateStep(int calcPot, |
248 | > | int calcStress){ |
249 | // Position full step, and velocity half step | |
260 | – | |
250 | preMove(); | |
251 | + | |
252 | moveA(); | |
263 | – | if( nConstrained ) constrainA(); |
253 | ||
254 | < | |
254 | > | if (nConstrained){ |
255 | > | constrainA(); |
256 | > | } |
257 | > | |
258 | > | |
259 | #ifdef IS_MPI | |
260 | < | strcpy( checkPointMsg, "Succesful moveA\n" ); |
260 | > | strcpy(checkPointMsg, "Succesful moveA\n"); |
261 | MPIcheckPoint(); | |
262 | #endif // is_mpi | |
270 | – | |
263 | ||
264 | + | |
265 | // calc forces | |
266 | ||
267 | < | myFF->doForces(calcPot,calcStress); |
267 | > | calcForce(calcPot, calcStress); |
268 | ||
269 | #ifdef IS_MPI | |
270 | < | strcpy( checkPointMsg, "Succesful doForces\n" ); |
270 | > | strcpy(checkPointMsg, "Succesful doForces\n"); |
271 | MPIcheckPoint(); | |
272 | #endif // is_mpi | |
280 | – | |
273 | ||
274 | + | |
275 | // finish the velocity half step | |
276 | < | |
276 | > | |
277 | moveB(); | |
278 | < | if( nConstrained ) constrainB(); |
279 | < | |
278 | > | |
279 | > | if (nConstrained){ |
280 | > | constrainB(); |
281 | > | } |
282 | > | |
283 | #ifdef IS_MPI | |
284 | < | strcpy( checkPointMsg, "Succesful moveB\n" ); |
284 | > | strcpy(checkPointMsg, "Succesful moveB\n"); |
285 | MPIcheckPoint(); | |
286 | #endif // is_mpi | |
291 | – | |
292 | – | |
287 | } | |
288 | ||
289 | ||
290 | < | void Integrator::moveA( void ){ |
297 | < | |
290 | > | template<typename T> void Integrator<T>::moveA(void){ |
291 | int i, j; | |
292 | DirectionalAtom* dAtom; | |
293 | double Tb[3], ji[3]; | |
# | Line 303 | Line 296 | void Integrator::moveA( void ){ | |
296 | double vel[3], pos[3], frc[3]; | |
297 | double mass; | |
298 | ||
299 | < | for( i=0; i<nAtoms; i++ ){ |
299 | > | for (i = 0; i < nAtoms; i++){ |
300 | > | atoms[i]->getVel(vel); |
301 | > | atoms[i]->getPos(pos); |
302 | > | atoms[i]->getFrc(frc); |
303 | ||
308 | – | atoms[i]->getVel( vel ); |
309 | – | atoms[i]->getPos( pos ); |
310 | – | atoms[i]->getFrc( frc ); |
311 | – | |
304 | mass = atoms[i]->getMass(); | |
305 | ||
306 | < | for (j=0; j < 3; j++) { |
306 | > | for (j = 0; j < 3; j++){ |
307 | // velocity half step | |
308 | < | vel[j] += ( dt2 * frc[j] / mass ) * eConvert; |
308 | > | vel[j] += (dt2 * frc[j] / mass) * eConvert; |
309 | // position whole step | |
310 | pos[j] += dt * vel[j]; | |
311 | } | |
312 | ||
313 | < | atoms[i]->setVel( vel ); |
314 | < | atoms[i]->setPos( pos ); |
313 | > | atoms[i]->setVel(vel); |
314 | > | atoms[i]->setPos(pos); |
315 | ||
316 | < | if( atoms[i]->isDirectional() ){ |
316 | > | if (atoms[i]->isDirectional()){ |
317 | > | dAtom = (DirectionalAtom *) atoms[i]; |
318 | ||
326 | – | dAtom = (DirectionalAtom *)atoms[i]; |
327 | – | |
319 | // get and convert the torque to body frame | |
329 | – | |
330 | – | dAtom->getTrq( Tb ); |
331 | – | dAtom->lab2Body( Tb ); |
320 | ||
321 | + | dAtom->getTrq(Tb); |
322 | + | dAtom->lab2Body(Tb); |
323 | + | |
324 | // get the angular momentum, and propagate a half step | |
325 | ||
326 | < | dAtom->getJ( ji ); |
326 | > | dAtom->getJ(ji); |
327 | ||
328 | < | for (j=0; j < 3; j++) |
328 | > | for (j = 0; j < 3; j++) |
329 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
330 | < | |
330 | > | |
331 | // use the angular velocities to propagate the rotation matrix a | |
332 | // full time step | |
333 | ||
334 | dAtom->getA(A); | |
335 | dAtom->getI(I); | |
336 | < | |
336 | > | |
337 | // rotate about the x-axis | |
338 | angle = dt2 * ji[0] / I[0][0]; | |
339 | < | this->rotate( 1, 2, angle, ji, A ); |
339 | > | this->rotate(1, 2, angle, ji, A); |
340 | ||
341 | // rotate about the y-axis | |
342 | angle = dt2 * ji[1] / I[1][1]; | |
343 | < | this->rotate( 2, 0, angle, ji, A ); |
344 | < | |
343 | > | this->rotate(2, 0, angle, ji, A); |
344 | > | |
345 | // rotate about the z-axis | |
346 | angle = dt * ji[2] / I[2][2]; | |
347 | < | this->rotate( 0, 1, angle, ji, A); |
348 | < | |
347 | > | this->rotate(0, 1, angle, ji, A); |
348 | > | |
349 | // rotate about the y-axis | |
350 | angle = dt2 * ji[1] / I[1][1]; | |
351 | < | this->rotate( 2, 0, angle, ji, A ); |
352 | < | |
353 | < | // rotate about the x-axis |
351 | > | this->rotate(2, 0, angle, ji, A); |
352 | > | |
353 | > | // rotate about the x-axis |
354 | angle = dt2 * ji[0] / I[0][0]; | |
355 | < | this->rotate( 1, 2, angle, ji, A ); |
365 | < | |
355 | > | this->rotate(1, 2, angle, ji, A); |
356 | ||
357 | < | dAtom->setJ( ji ); |
358 | < | dAtom->setA( A ); |
359 | < | |
360 | < | } |
357 | > | |
358 | > | dAtom->setJ(ji); |
359 | > | dAtom->setA(A); |
360 | > | } |
361 | } | |
362 | } | |
363 | ||
364 | ||
365 | < | void Integrator::moveB( void ){ |
365 | > | template<typename T> void Integrator<T>::moveB(void){ |
366 | int i, j; | |
367 | DirectionalAtom* dAtom; | |
368 | double Tb[3], ji[3]; | |
369 | double vel[3], frc[3]; | |
370 | double mass; | |
371 | ||
372 | < | for( i=0; i<nAtoms; i++ ){ |
373 | < | |
374 | < | atoms[i]->getVel( vel ); |
385 | < | atoms[i]->getFrc( frc ); |
372 | > | for (i = 0; i < nAtoms; i++){ |
373 | > | atoms[i]->getVel(vel); |
374 | > | atoms[i]->getFrc(frc); |
375 | ||
376 | mass = atoms[i]->getMass(); | |
377 | ||
378 | // velocity half step | |
379 | < | for (j=0; j < 3; j++) |
380 | < | vel[j] += ( dt2 * frc[j] / mass ) * eConvert; |
392 | < | |
393 | < | atoms[i]->setVel( vel ); |
394 | < | |
395 | < | if( atoms[i]->isDirectional() ){ |
379 | > | for (j = 0; j < 3; j++) |
380 | > | vel[j] += (dt2 * frc[j] / mass) * eConvert; |
381 | ||
382 | < | dAtom = (DirectionalAtom *)atoms[i]; |
382 | > | atoms[i]->setVel(vel); |
383 | ||
384 | + | if (atoms[i]->isDirectional()){ |
385 | + | dAtom = (DirectionalAtom *) atoms[i]; |
386 | + | |
387 | // get and convert the torque to body frame | |
388 | ||
389 | < | dAtom->getTrq( Tb ); |
390 | < | dAtom->lab2Body( Tb ); |
389 | > | dAtom->getTrq(Tb); |
390 | > | dAtom->lab2Body(Tb); |
391 | ||
392 | // get the angular momentum, and propagate a half step | |
393 | ||
394 | < | dAtom->getJ( ji ); |
394 | > | dAtom->getJ(ji); |
395 | ||
396 | < | for (j=0; j < 3; j++) |
396 | > | for (j = 0; j < 3; j++) |
397 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
410 | – | |
398 | ||
399 | < | dAtom->setJ( ji ); |
399 | > | |
400 | > | dAtom->setJ(ji); |
401 | } | |
402 | } | |
403 | } | |
404 | ||
405 | < | void Integrator::preMove( void ){ |
405 | > | template<typename T> void Integrator<T>::preMove(void){ |
406 | int i, j; | |
407 | double pos[3]; | |
408 | ||
409 | < | if( nConstrained ){ |
409 | > | if (nConstrained){ |
410 | > | for (i = 0; i < nAtoms; i++){ |
411 | > | atoms[i]->getPos(pos); |
412 | ||
413 | < | for(i=0; i < nAtoms; i++) { |
414 | < | |
425 | < | atoms[i]->getPos( pos ); |
426 | < | |
427 | < | for (j = 0; j < 3; j++) { |
428 | < | oldPos[3*i + j] = pos[j]; |
413 | > | for (j = 0; j < 3; j++){ |
414 | > | oldPos[3 * i + j] = pos[j]; |
415 | } | |
430 | – | |
416 | } | |
417 | < | } |
417 | > | } |
418 | } | |
419 | ||
420 | < | void Integrator::constrainA(){ |
421 | < | |
437 | < | int i,j,k; |
420 | > | template<typename T> void Integrator<T>::constrainA(){ |
421 | > | int i, j, k; |
422 | int done; | |
423 | double posA[3], posB[3]; | |
424 | double velA[3], velB[3]; | |
# | Line 449 | Line 433 | void Integrator::constrainA(){ | |
433 | double gab; | |
434 | int iteration; | |
435 | ||
436 | < | for( i=0; i<nAtoms; i++){ |
436 | > | for (i = 0; i < nAtoms; i++){ |
437 | moving[i] = 0; | |
438 | < | moved[i] = 1; |
438 | > | moved[i] = 1; |
439 | } | |
440 | ||
441 | iteration = 0; | |
442 | done = 0; | |
443 | < | while( !done && (iteration < maxIteration )){ |
460 | < | |
443 | > | while (!done && (iteration < maxIteration)){ |
444 | done = 1; | |
445 | < | for(i=0; i<nConstrained; i++){ |
463 | < | |
445 | > | for (i = 0; i < nConstrained; i++){ |
446 | a = constrainedA[i]; | |
447 | b = constrainedB[i]; | |
466 | – | |
467 | – | ax = (a*3) + 0; |
468 | – | ay = (a*3) + 1; |
469 | – | az = (a*3) + 2; |
448 | ||
449 | < | bx = (b*3) + 0; |
450 | < | by = (b*3) + 1; |
451 | < | bz = (b*3) + 2; |
449 | > | ax = (a * 3) + 0; |
450 | > | ay = (a * 3) + 1; |
451 | > | az = (a * 3) + 2; |
452 | ||
453 | < | if( moved[a] || moved[b] ){ |
454 | < | |
455 | < | atoms[a]->getPos( posA ); |
456 | < | atoms[b]->getPos( posB ); |
457 | < | |
458 | < | for (j = 0; j < 3; j++ ) |
453 | > | bx = (b * 3) + 0; |
454 | > | by = (b * 3) + 1; |
455 | > | bz = (b * 3) + 2; |
456 | > | |
457 | > | if (moved[a] || moved[b]){ |
458 | > | atoms[a]->getPos(posA); |
459 | > | atoms[b]->getPos(posB); |
460 | > | |
461 | > | for (j = 0; j < 3; j++) |
462 | pab[j] = posA[j] - posB[j]; | |
482 | – | |
483 | – | //periodic boundary condition |
463 | ||
464 | < | info->wrapVector( pab ); |
464 | > | //periodic boundary condition |
465 | ||
466 | < | pabsq = pab[0] * pab[0] + pab[1] * pab[1] + pab[2] * pab[2]; |
466 | > | info->wrapVector(pab); |
467 | ||
468 | < | rabsq = constrainedDsqr[i]; |
490 | < | diffsq = rabsq - pabsq; |
468 | > | pabsq = pab[0] * pab[0] + pab[1] * pab[1] + pab[2] * pab[2]; |
469 | ||
470 | < | // the original rattle code from alan tidesley |
471 | < | if (fabs(diffsq) > (tol*rabsq*2)) { |
494 | < | rab[0] = oldPos[ax] - oldPos[bx]; |
495 | < | rab[1] = oldPos[ay] - oldPos[by]; |
496 | < | rab[2] = oldPos[az] - oldPos[bz]; |
470 | > | rabsq = constrainedDsqr[i]; |
471 | > | diffsq = rabsq - pabsq; |
472 | ||
473 | < | info->wrapVector( rab ); |
473 | > | // the original rattle code from alan tidesley |
474 | > | if (fabs(diffsq) > (tol * rabsq * 2)){ |
475 | > | rab[0] = oldPos[ax] - oldPos[bx]; |
476 | > | rab[1] = oldPos[ay] - oldPos[by]; |
477 | > | rab[2] = oldPos[az] - oldPos[bz]; |
478 | ||
479 | < | rpab = rab[0] * pab[0] + rab[1] * pab[1] + rab[2] * pab[2]; |
479 | > | info->wrapVector(rab); |
480 | ||
481 | < | rpabsq = rpab * rpab; |
481 | > | rpab = rab[0] * pab[0] + rab[1] * pab[1] + rab[2] * pab[2]; |
482 | ||
483 | + | rpabsq = rpab * rpab; |
484 | ||
505 | – | if (rpabsq < (rabsq * -diffsq)){ |
485 | ||
486 | + | if (rpabsq < (rabsq * -diffsq)){ |
487 | #ifdef IS_MPI | |
488 | < | a = atoms[a]->getGlobalIndex(); |
489 | < | b = atoms[b]->getGlobalIndex(); |
488 | > | a = atoms[a]->getGlobalIndex(); |
489 | > | b = atoms[b]->getGlobalIndex(); |
490 | #endif //is_mpi | |
491 | < | sprintf( painCave.errMsg, |
492 | < | "Constraint failure in constrainA at atom %d and %d.\n", |
493 | < | a, b ); |
494 | < | painCave.isFatal = 1; |
495 | < | simError(); |
496 | < | } |
491 | > | sprintf(painCave.errMsg, |
492 | > | "Constraint failure in constrainA at atom %d and %d.\n", a, |
493 | > | b); |
494 | > | painCave.isFatal = 1; |
495 | > | simError(); |
496 | > | } |
497 | ||
498 | < | rma = 1.0 / atoms[a]->getMass(); |
499 | < | rmb = 1.0 / atoms[b]->getMass(); |
498 | > | rma = 1.0 / atoms[a]->getMass(); |
499 | > | rmb = 1.0 / atoms[b]->getMass(); |
500 | ||
501 | < | gab = diffsq / ( 2.0 * ( rma + rmb ) * rpab ); |
501 | > | gab = diffsq / (2.0 * (rma + rmb) * rpab); |
502 | ||
503 | dx = rab[0] * gab; | |
504 | dy = rab[1] * gab; | |
505 | dz = rab[2] * gab; | |
506 | ||
507 | < | posA[0] += rma * dx; |
508 | < | posA[1] += rma * dy; |
509 | < | posA[2] += rma * dz; |
507 | > | posA[0] += rma * dx; |
508 | > | posA[1] += rma * dy; |
509 | > | posA[2] += rma * dz; |
510 | ||
511 | < | atoms[a]->setPos( posA ); |
511 | > | atoms[a]->setPos(posA); |
512 | ||
513 | < | posB[0] -= rmb * dx; |
514 | < | posB[1] -= rmb * dy; |
515 | < | posB[2] -= rmb * dz; |
513 | > | posB[0] -= rmb * dx; |
514 | > | posB[1] -= rmb * dy; |
515 | > | posB[2] -= rmb * dz; |
516 | ||
517 | < | atoms[b]->setPos( posB ); |
517 | > | atoms[b]->setPos(posB); |
518 | ||
519 | dx = dx / dt; | |
520 | dy = dy / dt; | |
521 | dz = dz / dt; | |
522 | ||
523 | < | atoms[a]->getVel( velA ); |
523 | > | atoms[a]->getVel(velA); |
524 | ||
525 | < | velA[0] += rma * dx; |
526 | < | velA[1] += rma * dy; |
527 | < | velA[2] += rma * dz; |
525 | > | velA[0] += rma * dx; |
526 | > | velA[1] += rma * dy; |
527 | > | velA[2] += rma * dz; |
528 | ||
529 | < | atoms[a]->setVel( velA ); |
529 | > | atoms[a]->setVel(velA); |
530 | ||
531 | < | atoms[b]->getVel( velB ); |
531 | > | atoms[b]->getVel(velB); |
532 | ||
533 | < | velB[0] -= rmb * dx; |
534 | < | velB[1] -= rmb * dy; |
535 | < | velB[2] -= rmb * dz; |
533 | > | velB[0] -= rmb * dx; |
534 | > | velB[1] -= rmb * dy; |
535 | > | velB[2] -= rmb * dz; |
536 | ||
537 | < | atoms[b]->setVel( velB ); |
537 | > | atoms[b]->setVel(velB); |
538 | ||
539 | < | moving[a] = 1; |
540 | < | moving[b] = 1; |
541 | < | done = 0; |
542 | < | } |
539 | > | moving[a] = 1; |
540 | > | moving[b] = 1; |
541 | > | done = 0; |
542 | > | } |
543 | } | |
544 | } | |
545 | < | |
546 | < | for(i=0; i<nAtoms; i++){ |
567 | < | |
545 | > | |
546 | > | for (i = 0; i < nAtoms; i++){ |
547 | moved[i] = moving[i]; | |
548 | moving[i] = 0; | |
549 | } | |
# | Line 572 | Line 551 | void Integrator::constrainA(){ | |
551 | iteration++; | |
552 | } | |
553 | ||
554 | < | if( !done ){ |
555 | < | |
556 | < | sprintf( painCave.errMsg, |
557 | < | "Constraint failure in constrainA, too many iterations: %d\n", |
579 | < | iteration ); |
554 | > | if (!done){ |
555 | > | sprintf(painCave.errMsg, |
556 | > | "Constraint failure in constrainA, too many iterations: %d\n", |
557 | > | iteration); |
558 | painCave.isFatal = 1; | |
559 | simError(); | |
560 | } | |
583 | – | |
561 | } | |
562 | ||
563 | < | void Integrator::constrainB( void ){ |
564 | < | |
588 | < | int i,j,k; |
563 | > | template<typename T> void Integrator<T>::constrainB(void){ |
564 | > | int i, j, k; |
565 | int done; | |
566 | double posA[3], posB[3]; | |
567 | double velA[3], velB[3]; | |
# | Line 599 | Line 575 | void Integrator::constrainB( void ){ | |
575 | double gab; | |
576 | int iteration; | |
577 | ||
578 | < | for(i=0; i<nAtoms; i++){ |
578 | > | for (i = 0; i < nAtoms; i++){ |
579 | moving[i] = 0; | |
580 | moved[i] = 1; | |
581 | } | |
582 | ||
583 | done = 0; | |
584 | iteration = 0; | |
585 | < | while( !done && (iteration < maxIteration ) ){ |
610 | < | |
585 | > | while (!done && (iteration < maxIteration)){ |
586 | done = 1; | |
587 | ||
588 | < | for(i=0; i<nConstrained; i++){ |
614 | < | |
588 | > | for (i = 0; i < nConstrained; i++){ |
589 | a = constrainedA[i]; | |
590 | b = constrainedB[i]; | |
591 | ||
592 | < | ax = (a*3) + 0; |
593 | < | ay = (a*3) + 1; |
594 | < | az = (a*3) + 2; |
592 | > | ax = (a * 3) + 0; |
593 | > | ay = (a * 3) + 1; |
594 | > | az = (a * 3) + 2; |
595 | ||
596 | < | bx = (b*3) + 0; |
597 | < | by = (b*3) + 1; |
598 | < | bz = (b*3) + 2; |
625 | < | |
626 | < | if( moved[a] || moved[b] ){ |
596 | > | bx = (b * 3) + 0; |
597 | > | by = (b * 3) + 1; |
598 | > | bz = (b * 3) + 2; |
599 | ||
600 | < | atoms[a]->getVel( velA ); |
601 | < | atoms[b]->getVel( velB ); |
602 | < | |
631 | < | vxab = velA[0] - velB[0]; |
632 | < | vyab = velA[1] - velB[1]; |
633 | < | vzab = velA[2] - velB[2]; |
600 | > | if (moved[a] || moved[b]){ |
601 | > | atoms[a]->getVel(velA); |
602 | > | atoms[b]->getVel(velB); |
603 | ||
604 | < | atoms[a]->getPos( posA ); |
605 | < | atoms[b]->getPos( posB ); |
604 | > | vxab = velA[0] - velB[0]; |
605 | > | vyab = velA[1] - velB[1]; |
606 | > | vzab = velA[2] - velB[2]; |
607 | ||
608 | < | for (j = 0; j < 3; j++) |
608 | > | atoms[a]->getPos(posA); |
609 | > | atoms[b]->getPos(posB); |
610 | > | |
611 | > | for (j = 0; j < 3; j++) |
612 | 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(); |
613 | ||
614 | < | rvab = rab[0] * vxab + rab[1] * vyab + rab[2] * vzab; |
647 | < | |
648 | < | gab = -rvab / ( ( rma + rmb ) * constrainedDsqr[i] ); |
614 | > | info->wrapVector(rab); |
615 | ||
616 | < | if (fabs(gab) > tol) { |
617 | < | |
652 | < | dx = rab[0] * gab; |
653 | < | dy = rab[1] * gab; |
654 | < | dz = rab[2] * gab; |
655 | < | |
656 | < | velA[0] += rma * dx; |
657 | < | velA[1] += rma * dy; |
658 | < | velA[2] += rma * dz; |
616 | > | rma = 1.0 / atoms[a]->getMass(); |
617 | > | rmb = 1.0 / atoms[b]->getMass(); |
618 | ||
619 | < | atoms[a]->setVel( velA ); |
619 | > | rvab = rab[0] * vxab + rab[1] * vyab + rab[2] * vzab; |
620 | ||
621 | < | velB[0] -= rmb * dx; |
663 | < | velB[1] -= rmb * dy; |
664 | < | velB[2] -= rmb * dz; |
621 | > | gab = -rvab / ((rma + rmb) * constrainedDsqr[i]); |
622 | ||
623 | < | atoms[b]->setVel( velB ); |
624 | < | |
625 | < | moving[a] = 1; |
626 | < | moving[b] = 1; |
627 | < | done = 0; |
628 | < | } |
623 | > | if (fabs(gab) > tol){ |
624 | > | dx = rab[0] * gab; |
625 | > | dy = rab[1] * gab; |
626 | > | dz = rab[2] * gab; |
627 | > | |
628 | > | velA[0] += rma * dx; |
629 | > | velA[1] += rma * dy; |
630 | > | velA[2] += rma * dz; |
631 | > | |
632 | > | atoms[a]->setVel(velA); |
633 | > | |
634 | > | velB[0] -= rmb * dx; |
635 | > | velB[1] -= rmb * dy; |
636 | > | velB[2] -= rmb * dz; |
637 | > | |
638 | > | atoms[b]->setVel(velB); |
639 | > | |
640 | > | moving[a] = 1; |
641 | > | moving[b] = 1; |
642 | > | done = 0; |
643 | > | } |
644 | } | |
645 | } | |
646 | ||
647 | < | for(i=0; i<nAtoms; i++){ |
647 | > | for (i = 0; i < nAtoms; i++){ |
648 | moved[i] = moving[i]; | |
649 | moving[i] = 0; | |
650 | } | |
651 | < | |
651 | > | |
652 | iteration++; | |
653 | } | |
682 | – | |
683 | – | if( !done ){ |
654 | ||
655 | < | |
656 | < | sprintf( painCave.errMsg, |
657 | < | "Constraint failure in constrainB, too many iterations: %d\n", |
658 | < | iteration ); |
655 | > | if (!done){ |
656 | > | sprintf(painCave.errMsg, |
657 | > | "Constraint failure in constrainB, too many iterations: %d\n", |
658 | > | iteration); |
659 | painCave.isFatal = 1; | |
660 | simError(); | |
661 | < | } |
692 | < | |
661 | > | } |
662 | } | |
663 | ||
664 | < | void Integrator::rotate( int axes1, int axes2, double angle, double ji[3], |
665 | < | double A[3][3] ){ |
666 | < | |
667 | < | int i,j,k; |
664 | > | template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
665 | > | double angle, double ji[3], |
666 | > | double A[3][3]){ |
667 | > | int i, j, k; |
668 | double sinAngle; | |
669 | double cosAngle; | |
670 | double angleSqr; | |
# | Line 707 | Line 676 | void Integrator::rotate( int axes1, int axes2, double | |
676 | ||
677 | // initialize the tempA | |
678 | ||
679 | < | for(i=0; i<3; i++){ |
680 | < | for(j=0; j<3; j++){ |
679 | > | for (i = 0; i < 3; i++){ |
680 | > | for (j = 0; j < 3; j++){ |
681 | tempA[j][i] = A[i][j]; | |
682 | } | |
683 | } | |
684 | ||
685 | // initialize the tempJ | |
686 | ||
687 | < | for( i=0; i<3; i++) tempJ[i] = ji[i]; |
688 | < | |
687 | > | for (i = 0; i < 3; i++) |
688 | > | tempJ[i] = ji[i]; |
689 | > | |
690 | // initalize rot as a unit matrix | |
691 | ||
692 | rot[0][0] = 1.0; | |
# | Line 726 | Line 696 | void Integrator::rotate( int axes1, int axes2, double | |
696 | rot[1][0] = 0.0; | |
697 | rot[1][1] = 1.0; | |
698 | rot[1][2] = 0.0; | |
699 | < | |
699 | > | |
700 | rot[2][0] = 0.0; | |
701 | rot[2][1] = 0.0; | |
702 | rot[2][2] = 1.0; | |
703 | < | |
703 | > | |
704 | // use a small angle aproximation for sin and cosine | |
705 | ||
706 | < | angleSqr = angle * angle; |
706 | > | angleSqr = angle * angle; |
707 | angleSqrOver4 = angleSqr / 4.0; | |
708 | top = 1.0 - angleSqrOver4; | |
709 | bottom = 1.0 + angleSqrOver4; | |
# | Line 746 | Line 716 | void Integrator::rotate( int axes1, int axes2, double | |
716 | ||
717 | rot[axes1][axes2] = sinAngle; | |
718 | rot[axes2][axes1] = -sinAngle; | |
719 | < | |
719 | > | |
720 | // rotate the momentum acoording to: ji[] = rot[][] * ji[] | |
721 | < | |
722 | < | for(i=0; i<3; i++){ |
721 | > | |
722 | > | for (i = 0; i < 3; i++){ |
723 | ji[i] = 0.0; | |
724 | < | for(k=0; k<3; k++){ |
724 | > | for (k = 0; k < 3; k++){ |
725 | ji[i] += rot[i][k] * tempJ[k]; | |
726 | } | |
727 | } | |
# | Line 764 | Line 734 | void Integrator::rotate( int axes1, int axes2, double | |
734 | // calculation as: | |
735 | // transpose(A[][]) = transpose(A[][]) * transpose(rot[][]) | |
736 | ||
737 | < | for(i=0; i<3; i++){ |
738 | < | for(j=0; j<3; j++){ |
737 | > | for (i = 0; i < 3; i++){ |
738 | > | for (j = 0; j < 3; j++){ |
739 | A[j][i] = 0.0; | |
740 | < | for(k=0; k<3; k++){ |
741 | < | A[j][i] += tempA[i][k] * rot[j][k]; |
740 | > | for (k = 0; k < 3; k++){ |
741 | > | A[j][i] += tempA[i][k] * rot[j][k]; |
742 | } | |
743 | } | |
744 | } | |
745 | } | |
746 | + | |
747 | + | template<typename T> void Integrator<T>::calcForce(int calcPot, int calcStress){ |
748 | + | myFF->doForces(calcPot, calcStress); |
749 | + | } |
750 | + | |
751 | + | template<typename T> void Integrator<T>::thermalize(){ |
752 | + | tStats->velocitize(); |
753 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |