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; |
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; |
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 |
+ |
double resetTime = info->resetTime; |
157 |
|
|
158 |
+ |
|
159 |
|
double currSample; |
160 |
|
double currThermal; |
161 |
|
double currStatus; |
162 |
< |
double currTime; |
163 |
< |
|
162 |
> |
double currReset; |
163 |
> |
|
164 |
|
int calcPot, calcStress; |
165 |
|
int isError; |
166 |
|
|
167 |
< |
tStats = new Thermo( info ); |
168 |
< |
statOut = new StatWriter( info ); |
169 |
< |
dumpOut = new DumpWriter( info ); |
167 |
> |
tStats = new Thermo(info); |
168 |
> |
statOut = new StatWriter(info); |
169 |
> |
dumpOut = new DumpWriter(info); |
170 |
|
|
171 |
|
atoms = info->atoms; |
172 |
|
DirectionalAtom* dAtom; |
176 |
|
|
177 |
|
// initialize the forces before the first step |
178 |
|
|
179 |
< |
myFF->doForces(1,1); |
179 |
> |
calcForce(1, 1); |
180 |
|
|
181 |
< |
if( info->setTemp ){ |
182 |
< |
|
191 |
< |
tStats->velocitize(); |
181 |
> |
if (info->setTemp){ |
182 |
> |
thermalize(); |
183 |
|
} |
184 |
< |
|
194 |
< |
dumpOut->writeDump( 0.0 ); |
195 |
< |
statOut->writeStat( 0.0 ); |
196 |
< |
|
184 |
> |
|
185 |
|
calcPot = 0; |
186 |
|
calcStress = 0; |
187 |
< |
currSample = sampleTime; |
188 |
< |
currThermal = thermalTime; |
189 |
< |
currStatus = statusTime; |
190 |
< |
currTime = 0.0;; |
187 |
> |
currSample = sampleTime + info->getTime(); |
188 |
> |
currThermal = thermalTime+ info->getTime(); |
189 |
> |
currStatus = statusTime + info->getTime(); |
190 |
> |
currReset = resetTime + info->getTime(); |
191 |
|
|
192 |
+ |
dumpOut->writeDump(info->getTime()); |
193 |
+ |
statOut->writeStat(info->getTime()); |
194 |
|
|
195 |
|
readyCheck(); |
196 |
|
|
197 |
|
#ifdef IS_MPI |
198 |
< |
strcpy( checkPointMsg, |
209 |
< |
"The integrator is ready to go." ); |
198 |
> |
strcpy(checkPointMsg, "The integrator is ready to go."); |
199 |
|
MPIcheckPoint(); |
200 |
|
#endif // is_mpi |
201 |
|
|
202 |
< |
while( currTime < runTime ){ |
203 |
< |
|
215 |
< |
if( (currTime+dt) >= currStatus ){ |
202 |
> |
while (info->getTime() < runTime){ |
203 |
> |
if ((info->getTime() + dt) >= currStatus){ |
204 |
|
calcPot = 1; |
205 |
|
calcStress = 1; |
206 |
|
} |
207 |
|
|
208 |
< |
integrateStep( calcPot, calcStress ); |
221 |
< |
|
222 |
< |
currTime += dt; |
208 |
> |
integrateStep(calcPot, calcStress); |
209 |
|
|
210 |
< |
if( info->setTemp ){ |
211 |
< |
if( currTime >= currThermal ){ |
212 |
< |
tStats->velocitize(); |
213 |
< |
currThermal += thermalTime; |
210 |
> |
info->incrTime(dt); |
211 |
> |
|
212 |
> |
if (info->setTemp){ |
213 |
> |
if (info->getTime() >= currThermal){ |
214 |
> |
thermalize(); |
215 |
> |
currThermal += thermalTime; |
216 |
|
} |
217 |
|
} |
218 |
|
|
219 |
< |
if( currTime >= currSample ){ |
220 |
< |
dumpOut->writeDump( currTime ); |
219 |
> |
if (info->getTime() >= currSample){ |
220 |
> |
dumpOut->writeDump(info->getTime()); |
221 |
|
currSample += sampleTime; |
222 |
|
} |
223 |
|
|
224 |
< |
if( currTime >= currStatus ){ |
225 |
< |
statOut->writeStat( currTime ); |
224 |
> |
if (info->getTime() >= currStatus){ |
225 |
> |
statOut->writeStat(info->getTime()); |
226 |
|
calcPot = 0; |
227 |
|
calcStress = 0; |
228 |
|
currStatus += statusTime; |
229 |
|
} |
230 |
|
|
231 |
+ |
if (info->resetIntegrator){ |
232 |
+ |
if (info->getTime() >= currReset){ |
233 |
+ |
this->resetIntegrator(); |
234 |
+ |
currReset += resetTime; |
235 |
+ |
} |
236 |
+ |
} |
237 |
+ |
|
238 |
|
#ifdef IS_MPI |
239 |
< |
strcpy( checkPointMsg, |
245 |
< |
"successfully took a time step." ); |
239 |
> |
strcpy(checkPointMsg, "successfully took a time step."); |
240 |
|
MPIcheckPoint(); |
241 |
|
#endif // is_mpi |
248 |
– |
|
242 |
|
} |
243 |
|
|
244 |
< |
dumpOut->writeFinal(currTime); |
244 |
> |
dumpOut->writeFinal(info->getTime()); |
245 |
|
|
246 |
|
delete dumpOut; |
247 |
|
delete statOut; |
248 |
|
} |
249 |
|
|
250 |
< |
void Integrator::integrateStep( int calcPot, int calcStress ){ |
251 |
< |
|
259 |
< |
|
260 |
< |
|
250 |
> |
template<typename T> void Integrator<T>::integrateStep(int calcPot, |
251 |
> |
int calcStress){ |
252 |
|
// Position full step, and velocity half step |
262 |
– |
|
253 |
|
preMove(); |
254 |
+ |
|
255 |
|
moveA(); |
265 |
– |
if( nConstrained ) constrainA(); |
256 |
|
|
257 |
< |
|
257 |
> |
if (nConstrained){ |
258 |
> |
constrainA(); |
259 |
> |
} |
260 |
> |
|
261 |
> |
|
262 |
|
#ifdef IS_MPI |
263 |
< |
strcpy( checkPointMsg, "Succesful moveA\n" ); |
263 |
> |
strcpy(checkPointMsg, "Succesful moveA\n"); |
264 |
|
MPIcheckPoint(); |
265 |
|
#endif // is_mpi |
272 |
– |
|
266 |
|
|
267 |
+ |
|
268 |
|
// calc forces |
269 |
|
|
270 |
< |
myFF->doForces(calcPot,calcStress); |
270 |
> |
calcForce(calcPot, calcStress); |
271 |
|
|
272 |
|
#ifdef IS_MPI |
273 |
< |
strcpy( checkPointMsg, "Succesful doForces\n" ); |
273 |
> |
strcpy(checkPointMsg, "Succesful doForces\n"); |
274 |
|
MPIcheckPoint(); |
275 |
|
#endif // is_mpi |
282 |
– |
|
276 |
|
|
277 |
+ |
|
278 |
|
// finish the velocity half step |
279 |
< |
|
279 |
> |
|
280 |
|
moveB(); |
281 |
< |
if( nConstrained ) constrainB(); |
282 |
< |
|
281 |
> |
|
282 |
> |
if (nConstrained){ |
283 |
> |
constrainB(); |
284 |
> |
} |
285 |
> |
|
286 |
|
#ifdef IS_MPI |
287 |
< |
strcpy( checkPointMsg, "Succesful moveB\n" ); |
287 |
> |
strcpy(checkPointMsg, "Succesful moveB\n"); |
288 |
|
MPIcheckPoint(); |
289 |
|
#endif // is_mpi |
293 |
– |
|
294 |
– |
|
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
< |
void Integrator::moveA( void ){ |
299 |
< |
|
293 |
> |
template<typename T> void Integrator<T>::moveA(void){ |
294 |
|
int i, j; |
295 |
|
DirectionalAtom* dAtom; |
296 |
|
double Tb[3], ji[3]; |
299 |
|
double vel[3], pos[3], frc[3]; |
300 |
|
double mass; |
301 |
|
|
302 |
< |
for( i=0; i<nAtoms; i++ ){ |
302 |
> |
for (i = 0; i < nAtoms; i++){ |
303 |
> |
atoms[i]->getVel(vel); |
304 |
> |
atoms[i]->getPos(pos); |
305 |
> |
atoms[i]->getFrc(frc); |
306 |
|
|
310 |
– |
atoms[i]->getVel( vel ); |
311 |
– |
atoms[i]->getPos( pos ); |
312 |
– |
atoms[i]->getFrc( frc ); |
313 |
– |
|
307 |
|
mass = atoms[i]->getMass(); |
308 |
|
|
309 |
< |
for (j=0; j < 3; j++) { |
309 |
> |
for (j = 0; j < 3; j++){ |
310 |
|
// velocity half step |
311 |
< |
vel[j] += ( dt2 * frc[j] / mass ) * eConvert; |
311 |
> |
vel[j] += (dt2 * frc[j] / mass) * eConvert; |
312 |
|
// position whole step |
313 |
|
pos[j] += dt * vel[j]; |
314 |
|
} |
315 |
|
|
316 |
< |
atoms[i]->setVel( vel ); |
317 |
< |
atoms[i]->setPos( pos ); |
316 |
> |
atoms[i]->setVel(vel); |
317 |
> |
atoms[i]->setPos(pos); |
318 |
|
|
319 |
< |
if( atoms[i]->isDirectional() ){ |
319 |
> |
if (atoms[i]->isDirectional()){ |
320 |
> |
dAtom = (DirectionalAtom *) atoms[i]; |
321 |
|
|
328 |
– |
dAtom = (DirectionalAtom *)atoms[i]; |
329 |
– |
|
322 |
|
// get and convert the torque to body frame |
331 |
– |
|
332 |
– |
dAtom->getTrq( Tb ); |
333 |
– |
dAtom->lab2Body( Tb ); |
323 |
|
|
324 |
+ |
dAtom->getTrq(Tb); |
325 |
+ |
dAtom->lab2Body(Tb); |
326 |
+ |
|
327 |
|
// get the angular momentum, and propagate a half step |
328 |
|
|
329 |
< |
dAtom->getJ( ji ); |
329 |
> |
dAtom->getJ(ji); |
330 |
|
|
331 |
< |
for (j=0; j < 3; j++) |
331 |
> |
for (j = 0; j < 3; j++) |
332 |
|
ji[j] += (dt2 * Tb[j]) * eConvert; |
333 |
< |
|
333 |
> |
|
334 |
|
// use the angular velocities to propagate the rotation matrix a |
335 |
|
// full time step |
336 |
|
|
337 |
|
dAtom->getA(A); |
338 |
|
dAtom->getI(I); |
339 |
< |
|
339 |
> |
|
340 |
|
// rotate about the x-axis |
341 |
|
angle = dt2 * ji[0] / I[0][0]; |
342 |
< |
this->rotate( 1, 2, angle, ji, A ); |
342 |
> |
this->rotate(1, 2, angle, ji, A); |
343 |
|
|
344 |
|
// rotate about the y-axis |
345 |
|
angle = dt2 * ji[1] / I[1][1]; |
346 |
< |
this->rotate( 2, 0, angle, ji, A ); |
347 |
< |
|
346 |
> |
this->rotate(2, 0, angle, ji, A); |
347 |
> |
|
348 |
|
// rotate about the z-axis |
349 |
|
angle = dt * ji[2] / I[2][2]; |
350 |
< |
this->rotate( 0, 1, angle, ji, A); |
351 |
< |
|
350 |
> |
this->rotate(0, 1, angle, ji, A); |
351 |
> |
|
352 |
|
// rotate about the y-axis |
353 |
|
angle = dt2 * ji[1] / I[1][1]; |
354 |
< |
this->rotate( 2, 0, angle, ji, A ); |
355 |
< |
|
356 |
< |
// rotate about the x-axis |
354 |
> |
this->rotate(2, 0, angle, ji, A); |
355 |
> |
|
356 |
> |
// rotate about the x-axis |
357 |
|
angle = dt2 * ji[0] / I[0][0]; |
358 |
< |
this->rotate( 1, 2, angle, ji, A ); |
367 |
< |
|
358 |
> |
this->rotate(1, 2, angle, ji, A); |
359 |
|
|
360 |
< |
dAtom->setJ( ji ); |
361 |
< |
dAtom->setA( A ); |
362 |
< |
|
363 |
< |
} |
360 |
> |
|
361 |
> |
dAtom->setJ(ji); |
362 |
> |
dAtom->setA(A); |
363 |
> |
} |
364 |
|
} |
365 |
|
} |
366 |
|
|
367 |
|
|
368 |
< |
void Integrator::moveB( void ){ |
368 |
> |
template<typename T> void Integrator<T>::moveB(void){ |
369 |
|
int i, j; |
370 |
|
DirectionalAtom* dAtom; |
371 |
|
double Tb[3], ji[3]; |
372 |
|
double vel[3], frc[3]; |
373 |
|
double mass; |
374 |
|
|
375 |
< |
for( i=0; i<nAtoms; i++ ){ |
376 |
< |
|
377 |
< |
atoms[i]->getVel( vel ); |
387 |
< |
atoms[i]->getFrc( frc ); |
375 |
> |
for (i = 0; i < nAtoms; i++){ |
376 |
> |
atoms[i]->getVel(vel); |
377 |
> |
atoms[i]->getFrc(frc); |
378 |
|
|
379 |
|
mass = atoms[i]->getMass(); |
380 |
|
|
381 |
|
// velocity half step |
382 |
< |
for (j=0; j < 3; j++) |
383 |
< |
vel[j] += ( dt2 * frc[j] / mass ) * eConvert; |
394 |
< |
|
395 |
< |
atoms[i]->setVel( vel ); |
396 |
< |
|
397 |
< |
if( atoms[i]->isDirectional() ){ |
382 |
> |
for (j = 0; j < 3; j++) |
383 |
> |
vel[j] += (dt2 * frc[j] / mass) * eConvert; |
384 |
|
|
385 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
385 |
> |
atoms[i]->setVel(vel); |
386 |
|
|
387 |
+ |
if (atoms[i]->isDirectional()){ |
388 |
+ |
dAtom = (DirectionalAtom *) atoms[i]; |
389 |
+ |
|
390 |
|
// get and convert the torque to body frame |
391 |
|
|
392 |
< |
dAtom->getTrq( Tb ); |
393 |
< |
dAtom->lab2Body( Tb ); |
392 |
> |
dAtom->getTrq(Tb); |
393 |
> |
dAtom->lab2Body(Tb); |
394 |
|
|
395 |
|
// get the angular momentum, and propagate a half step |
396 |
|
|
397 |
< |
dAtom->getJ( ji ); |
397 |
> |
dAtom->getJ(ji); |
398 |
|
|
399 |
< |
for (j=0; j < 3; j++) |
399 |
> |
for (j = 0; j < 3; j++) |
400 |
|
ji[j] += (dt2 * Tb[j]) * eConvert; |
412 |
– |
|
401 |
|
|
402 |
< |
dAtom->setJ( ji ); |
402 |
> |
|
403 |
> |
dAtom->setJ(ji); |
404 |
|
} |
405 |
|
} |
406 |
|
} |
407 |
|
|
408 |
< |
void Integrator::preMove( void ){ |
408 |
> |
template<typename T> void Integrator<T>::preMove(void){ |
409 |
|
int i, j; |
410 |
|
double pos[3]; |
411 |
|
|
412 |
< |
if( nConstrained ){ |
412 |
> |
if (nConstrained){ |
413 |
> |
for (i = 0; i < nAtoms; i++){ |
414 |
> |
atoms[i]->getPos(pos); |
415 |
|
|
416 |
< |
for(i=0; i < nAtoms; i++) { |
417 |
< |
|
427 |
< |
atoms[i]->getPos( pos ); |
428 |
< |
|
429 |
< |
for (j = 0; j < 3; j++) { |
430 |
< |
oldPos[3*i + j] = pos[j]; |
416 |
> |
for (j = 0; j < 3; j++){ |
417 |
> |
oldPos[3 * i + j] = pos[j]; |
418 |
|
} |
432 |
– |
|
419 |
|
} |
420 |
< |
} |
420 |
> |
} |
421 |
|
} |
422 |
|
|
423 |
< |
void Integrator::constrainA(){ |
424 |
< |
|
439 |
< |
int i,j,k; |
423 |
> |
template<typename T> void Integrator<T>::constrainA(){ |
424 |
> |
int i, j, k; |
425 |
|
int done; |
426 |
|
double posA[3], posB[3]; |
427 |
|
double velA[3], velB[3]; |
436 |
|
double gab; |
437 |
|
int iteration; |
438 |
|
|
439 |
< |
for( i=0; i<nAtoms; i++){ |
439 |
> |
for (i = 0; i < nAtoms; i++){ |
440 |
|
moving[i] = 0; |
441 |
< |
moved[i] = 1; |
441 |
> |
moved[i] = 1; |
442 |
|
} |
443 |
|
|
444 |
|
iteration = 0; |
445 |
|
done = 0; |
446 |
< |
while( !done && (iteration < maxIteration )){ |
462 |
< |
|
446 |
> |
while (!done && (iteration < maxIteration)){ |
447 |
|
done = 1; |
448 |
< |
for(i=0; i<nConstrained; i++){ |
465 |
< |
|
448 |
> |
for (i = 0; i < nConstrained; i++){ |
449 |
|
a = constrainedA[i]; |
450 |
|
b = constrainedB[i]; |
468 |
– |
|
469 |
– |
ax = (a*3) + 0; |
470 |
– |
ay = (a*3) + 1; |
471 |
– |
az = (a*3) + 2; |
451 |
|
|
452 |
< |
bx = (b*3) + 0; |
453 |
< |
by = (b*3) + 1; |
454 |
< |
bz = (b*3) + 2; |
452 |
> |
ax = (a * 3) + 0; |
453 |
> |
ay = (a * 3) + 1; |
454 |
> |
az = (a * 3) + 2; |
455 |
|
|
456 |
< |
if( moved[a] || moved[b] ){ |
457 |
< |
|
458 |
< |
atoms[a]->getPos( posA ); |
459 |
< |
atoms[b]->getPos( posB ); |
460 |
< |
|
461 |
< |
for (j = 0; j < 3; j++ ) |
456 |
> |
bx = (b * 3) + 0; |
457 |
> |
by = (b * 3) + 1; |
458 |
> |
bz = (b * 3) + 2; |
459 |
> |
|
460 |
> |
if (moved[a] || moved[b]){ |
461 |
> |
atoms[a]->getPos(posA); |
462 |
> |
atoms[b]->getPos(posB); |
463 |
> |
|
464 |
> |
for (j = 0; j < 3; j++) |
465 |
|
pab[j] = posA[j] - posB[j]; |
484 |
– |
|
485 |
– |
//periodic boundary condition |
466 |
|
|
467 |
< |
info->wrapVector( pab ); |
467 |
> |
//periodic boundary condition |
468 |
|
|
469 |
< |
pabsq = pab[0] * pab[0] + pab[1] * pab[1] + pab[2] * pab[2]; |
469 |
> |
info->wrapVector(pab); |
470 |
|
|
471 |
< |
rabsq = constrainedDsqr[i]; |
492 |
< |
diffsq = rabsq - pabsq; |
471 |
> |
pabsq = pab[0] * pab[0] + pab[1] * pab[1] + pab[2] * pab[2]; |
472 |
|
|
473 |
< |
// the original rattle code from alan tidesley |
474 |
< |
if (fabs(diffsq) > (tol*rabsq*2)) { |
496 |
< |
rab[0] = oldPos[ax] - oldPos[bx]; |
497 |
< |
rab[1] = oldPos[ay] - oldPos[by]; |
498 |
< |
rab[2] = oldPos[az] - oldPos[bz]; |
473 |
> |
rabsq = constrainedDsqr[i]; |
474 |
> |
diffsq = rabsq - pabsq; |
475 |
|
|
476 |
< |
info->wrapVector( rab ); |
476 |
> |
// the original rattle code from alan tidesley |
477 |
> |
if (fabs(diffsq) > (tol * rabsq * 2)){ |
478 |
> |
rab[0] = oldPos[ax] - oldPos[bx]; |
479 |
> |
rab[1] = oldPos[ay] - oldPos[by]; |
480 |
> |
rab[2] = oldPos[az] - oldPos[bz]; |
481 |
|
|
482 |
< |
rpab = rab[0] * pab[0] + rab[1] * pab[1] + rab[2] * pab[2]; |
482 |
> |
info->wrapVector(rab); |
483 |
|
|
484 |
< |
rpabsq = rpab * rpab; |
484 |
> |
rpab = rab[0] * pab[0] + rab[1] * pab[1] + rab[2] * pab[2]; |
485 |
|
|
486 |
+ |
rpabsq = rpab * rpab; |
487 |
|
|
507 |
– |
if (rpabsq < (rabsq * -diffsq)){ |
488 |
|
|
489 |
+ |
if (rpabsq < (rabsq * -diffsq)){ |
490 |
|
#ifdef IS_MPI |
491 |
< |
a = atoms[a]->getGlobalIndex(); |
492 |
< |
b = atoms[b]->getGlobalIndex(); |
491 |
> |
a = atoms[a]->getGlobalIndex(); |
492 |
> |
b = atoms[b]->getGlobalIndex(); |
493 |
|
#endif //is_mpi |
494 |
< |
sprintf( painCave.errMsg, |
495 |
< |
"Constraint failure in constrainA at atom %d and %d.\n", |
496 |
< |
a, b ); |
497 |
< |
painCave.isFatal = 1; |
498 |
< |
simError(); |
499 |
< |
} |
494 |
> |
sprintf(painCave.errMsg, |
495 |
> |
"Constraint failure in constrainA at atom %d and %d.\n", a, |
496 |
> |
b); |
497 |
> |
painCave.isFatal = 1; |
498 |
> |
simError(); |
499 |
> |
} |
500 |
|
|
501 |
< |
rma = 1.0 / atoms[a]->getMass(); |
502 |
< |
rmb = 1.0 / atoms[b]->getMass(); |
501 |
> |
rma = 1.0 / atoms[a]->getMass(); |
502 |
> |
rmb = 1.0 / atoms[b]->getMass(); |
503 |
|
|
504 |
< |
gab = diffsq / ( 2.0 * ( rma + rmb ) * rpab ); |
504 |
> |
gab = diffsq / (2.0 * (rma + rmb) * rpab); |
505 |
|
|
506 |
|
dx = rab[0] * gab; |
507 |
|
dy = rab[1] * gab; |
508 |
|
dz = rab[2] * gab; |
509 |
|
|
510 |
< |
posA[0] += rma * dx; |
511 |
< |
posA[1] += rma * dy; |
512 |
< |
posA[2] += rma * dz; |
510 |
> |
posA[0] += rma * dx; |
511 |
> |
posA[1] += rma * dy; |
512 |
> |
posA[2] += rma * dz; |
513 |
|
|
514 |
< |
atoms[a]->setPos( posA ); |
514 |
> |
atoms[a]->setPos(posA); |
515 |
|
|
516 |
< |
posB[0] -= rmb * dx; |
517 |
< |
posB[1] -= rmb * dy; |
518 |
< |
posB[2] -= rmb * dz; |
516 |
> |
posB[0] -= rmb * dx; |
517 |
> |
posB[1] -= rmb * dy; |
518 |
> |
posB[2] -= rmb * dz; |
519 |
|
|
520 |
< |
atoms[b]->setPos( posB ); |
520 |
> |
atoms[b]->setPos(posB); |
521 |
|
|
522 |
|
dx = dx / dt; |
523 |
|
dy = dy / dt; |
524 |
|
dz = dz / dt; |
525 |
|
|
526 |
< |
atoms[a]->getVel( velA ); |
526 |
> |
atoms[a]->getVel(velA); |
527 |
|
|
528 |
< |
velA[0] += rma * dx; |
529 |
< |
velA[1] += rma * dy; |
530 |
< |
velA[2] += rma * dz; |
528 |
> |
velA[0] += rma * dx; |
529 |
> |
velA[1] += rma * dy; |
530 |
> |
velA[2] += rma * dz; |
531 |
|
|
532 |
< |
atoms[a]->setVel( velA ); |
532 |
> |
atoms[a]->setVel(velA); |
533 |
|
|
534 |
< |
atoms[b]->getVel( velB ); |
534 |
> |
atoms[b]->getVel(velB); |
535 |
|
|
536 |
< |
velB[0] -= rmb * dx; |
537 |
< |
velB[1] -= rmb * dy; |
538 |
< |
velB[2] -= rmb * dz; |
536 |
> |
velB[0] -= rmb * dx; |
537 |
> |
velB[1] -= rmb * dy; |
538 |
> |
velB[2] -= rmb * dz; |
539 |
|
|
540 |
< |
atoms[b]->setVel( velB ); |
540 |
> |
atoms[b]->setVel(velB); |
541 |
|
|
542 |
< |
moving[a] = 1; |
543 |
< |
moving[b] = 1; |
544 |
< |
done = 0; |
545 |
< |
} |
542 |
> |
moving[a] = 1; |
543 |
> |
moving[b] = 1; |
544 |
> |
done = 0; |
545 |
> |
} |
546 |
|
} |
547 |
|
} |
548 |
< |
|
549 |
< |
for(i=0; i<nAtoms; i++){ |
569 |
< |
|
548 |
> |
|
549 |
> |
for (i = 0; i < nAtoms; i++){ |
550 |
|
moved[i] = moving[i]; |
551 |
|
moving[i] = 0; |
552 |
|
} |
554 |
|
iteration++; |
555 |
|
} |
556 |
|
|
557 |
< |
if( !done ){ |
558 |
< |
|
559 |
< |
sprintf( painCave.errMsg, |
560 |
< |
"Constraint failure in constrainA, too many iterations: %d\n", |
581 |
< |
iteration ); |
557 |
> |
if (!done){ |
558 |
> |
sprintf(painCave.errMsg, |
559 |
> |
"Constraint failure in constrainA, too many iterations: %d\n", |
560 |
> |
iteration); |
561 |
|
painCave.isFatal = 1; |
562 |
|
simError(); |
563 |
|
} |
585 |
– |
|
564 |
|
} |
565 |
|
|
566 |
< |
void Integrator::constrainB( void ){ |
567 |
< |
|
590 |
< |
int i,j,k; |
566 |
> |
template<typename T> void Integrator<T>::constrainB(void){ |
567 |
> |
int i, j, k; |
568 |
|
int done; |
569 |
|
double posA[3], posB[3]; |
570 |
|
double velA[3], velB[3]; |
578 |
|
double gab; |
579 |
|
int iteration; |
580 |
|
|
581 |
< |
for(i=0; i<nAtoms; i++){ |
581 |
> |
for (i = 0; i < nAtoms; i++){ |
582 |
|
moving[i] = 0; |
583 |
|
moved[i] = 1; |
584 |
|
} |
585 |
|
|
586 |
|
done = 0; |
587 |
|
iteration = 0; |
588 |
< |
while( !done && (iteration < maxIteration ) ){ |
612 |
< |
|
588 |
> |
while (!done && (iteration < maxIteration)){ |
589 |
|
done = 1; |
590 |
|
|
591 |
< |
for(i=0; i<nConstrained; i++){ |
616 |
< |
|
591 |
> |
for (i = 0; i < nConstrained; i++){ |
592 |
|
a = constrainedA[i]; |
593 |
|
b = constrainedB[i]; |
594 |
|
|
595 |
< |
ax = (a*3) + 0; |
596 |
< |
ay = (a*3) + 1; |
597 |
< |
az = (a*3) + 2; |
595 |
> |
ax = (a * 3) + 0; |
596 |
> |
ay = (a * 3) + 1; |
597 |
> |
az = (a * 3) + 2; |
598 |
|
|
599 |
< |
bx = (b*3) + 0; |
600 |
< |
by = (b*3) + 1; |
601 |
< |
bz = (b*3) + 2; |
599 |
> |
bx = (b * 3) + 0; |
600 |
> |
by = (b * 3) + 1; |
601 |
> |
bz = (b * 3) + 2; |
602 |
|
|
603 |
< |
if( moved[a] || moved[b] ){ |
603 |
> |
if (moved[a] || moved[b]){ |
604 |
> |
atoms[a]->getVel(velA); |
605 |
> |
atoms[b]->getVel(velB); |
606 |
|
|
607 |
< |
atoms[a]->getVel( velA ); |
608 |
< |
atoms[b]->getVel( velB ); |
609 |
< |
|
633 |
< |
vxab = velA[0] - velB[0]; |
634 |
< |
vyab = velA[1] - velB[1]; |
635 |
< |
vzab = velA[2] - velB[2]; |
607 |
> |
vxab = velA[0] - velB[0]; |
608 |
> |
vyab = velA[1] - velB[1]; |
609 |
> |
vzab = velA[2] - velB[2]; |
610 |
|
|
611 |
< |
atoms[a]->getPos( posA ); |
612 |
< |
atoms[b]->getPos( posB ); |
611 |
> |
atoms[a]->getPos(posA); |
612 |
> |
atoms[b]->getPos(posB); |
613 |
|
|
614 |
< |
for (j = 0; j < 3; j++) |
614 |
> |
for (j = 0; j < 3; j++) |
615 |
|
rab[j] = posA[j] - posB[j]; |
642 |
– |
|
643 |
– |
info->wrapVector( rab ); |
644 |
– |
|
645 |
– |
rma = 1.0 / atoms[a]->getMass(); |
646 |
– |
rmb = 1.0 / atoms[b]->getMass(); |
616 |
|
|
617 |
< |
rvab = rab[0] * vxab + rab[1] * vyab + rab[2] * vzab; |
649 |
< |
|
650 |
< |
gab = -rvab / ( ( rma + rmb ) * constrainedDsqr[i] ); |
617 |
> |
info->wrapVector(rab); |
618 |
|
|
619 |
< |
if (fabs(gab) > tol) { |
620 |
< |
|
654 |
< |
dx = rab[0] * gab; |
655 |
< |
dy = rab[1] * gab; |
656 |
< |
dz = rab[2] * gab; |
657 |
< |
|
658 |
< |
velA[0] += rma * dx; |
659 |
< |
velA[1] += rma * dy; |
660 |
< |
velA[2] += rma * dz; |
619 |
> |
rma = 1.0 / atoms[a]->getMass(); |
620 |
> |
rmb = 1.0 / atoms[b]->getMass(); |
621 |
|
|
622 |
< |
atoms[a]->setVel( velA ); |
622 |
> |
rvab = rab[0] * vxab + rab[1] * vyab + rab[2] * vzab; |
623 |
|
|
624 |
< |
velB[0] -= rmb * dx; |
665 |
< |
velB[1] -= rmb * dy; |
666 |
< |
velB[2] -= rmb * dz; |
624 |
> |
gab = -rvab / ((rma + rmb) * constrainedDsqr[i]); |
625 |
|
|
626 |
< |
atoms[b]->setVel( velB ); |
627 |
< |
|
628 |
< |
moving[a] = 1; |
629 |
< |
moving[b] = 1; |
630 |
< |
done = 0; |
631 |
< |
} |
626 |
> |
if (fabs(gab) > tol){ |
627 |
> |
dx = rab[0] * gab; |
628 |
> |
dy = rab[1] * gab; |
629 |
> |
dz = rab[2] * gab; |
630 |
> |
|
631 |
> |
velA[0] += rma * dx; |
632 |
> |
velA[1] += rma * dy; |
633 |
> |
velA[2] += rma * dz; |
634 |
> |
|
635 |
> |
atoms[a]->setVel(velA); |
636 |
> |
|
637 |
> |
velB[0] -= rmb * dx; |
638 |
> |
velB[1] -= rmb * dy; |
639 |
> |
velB[2] -= rmb * dz; |
640 |
> |
|
641 |
> |
atoms[b]->setVel(velB); |
642 |
> |
|
643 |
> |
moving[a] = 1; |
644 |
> |
moving[b] = 1; |
645 |
> |
done = 0; |
646 |
> |
} |
647 |
|
} |
648 |
|
} |
649 |
|
|
650 |
< |
for(i=0; i<nAtoms; i++){ |
650 |
> |
for (i = 0; i < nAtoms; i++){ |
651 |
|
moved[i] = moving[i]; |
652 |
|
moving[i] = 0; |
653 |
|
} |
654 |
< |
|
654 |
> |
|
655 |
|
iteration++; |
656 |
|
} |
684 |
– |
|
685 |
– |
if( !done ){ |
657 |
|
|
658 |
< |
|
659 |
< |
sprintf( painCave.errMsg, |
660 |
< |
"Constraint failure in constrainB, too many iterations: %d\n", |
661 |
< |
iteration ); |
658 |
> |
if (!done){ |
659 |
> |
sprintf(painCave.errMsg, |
660 |
> |
"Constraint failure in constrainB, too many iterations: %d\n", |
661 |
> |
iteration); |
662 |
|
painCave.isFatal = 1; |
663 |
|
simError(); |
664 |
< |
} |
694 |
< |
|
664 |
> |
} |
665 |
|
} |
666 |
|
|
667 |
< |
void Integrator::rotate( int axes1, int axes2, double angle, double ji[3], |
668 |
< |
double A[3][3] ){ |
669 |
< |
|
670 |
< |
int i,j,k; |
667 |
> |
template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
668 |
> |
double angle, double ji[3], |
669 |
> |
double A[3][3]){ |
670 |
> |
int i, j, k; |
671 |
|
double sinAngle; |
672 |
|
double cosAngle; |
673 |
|
double angleSqr; |
679 |
|
|
680 |
|
// initialize the tempA |
681 |
|
|
682 |
< |
for(i=0; i<3; i++){ |
683 |
< |
for(j=0; j<3; j++){ |
682 |
> |
for (i = 0; i < 3; i++){ |
683 |
> |
for (j = 0; j < 3; j++){ |
684 |
|
tempA[j][i] = A[i][j]; |
685 |
|
} |
686 |
|
} |
687 |
|
|
688 |
|
// initialize the tempJ |
689 |
|
|
690 |
< |
for( i=0; i<3; i++) tempJ[i] = ji[i]; |
691 |
< |
|
690 |
> |
for (i = 0; i < 3; i++) |
691 |
> |
tempJ[i] = ji[i]; |
692 |
> |
|
693 |
|
// initalize rot as a unit matrix |
694 |
|
|
695 |
|
rot[0][0] = 1.0; |
699 |
|
rot[1][0] = 0.0; |
700 |
|
rot[1][1] = 1.0; |
701 |
|
rot[1][2] = 0.0; |
702 |
< |
|
702 |
> |
|
703 |
|
rot[2][0] = 0.0; |
704 |
|
rot[2][1] = 0.0; |
705 |
|
rot[2][2] = 1.0; |
706 |
< |
|
706 |
> |
|
707 |
|
// use a small angle aproximation for sin and cosine |
708 |
|
|
709 |
< |
angleSqr = angle * angle; |
709 |
> |
angleSqr = angle * angle; |
710 |
|
angleSqrOver4 = angleSqr / 4.0; |
711 |
|
top = 1.0 - angleSqrOver4; |
712 |
|
bottom = 1.0 + angleSqrOver4; |
719 |
|
|
720 |
|
rot[axes1][axes2] = sinAngle; |
721 |
|
rot[axes2][axes1] = -sinAngle; |
722 |
< |
|
722 |
> |
|
723 |
|
// rotate the momentum acoording to: ji[] = rot[][] * ji[] |
724 |
< |
|
725 |
< |
for(i=0; i<3; i++){ |
724 |
> |
|
725 |
> |
for (i = 0; i < 3; i++){ |
726 |
|
ji[i] = 0.0; |
727 |
< |
for(k=0; k<3; k++){ |
727 |
> |
for (k = 0; k < 3; k++){ |
728 |
|
ji[i] += rot[i][k] * tempJ[k]; |
729 |
|
} |
730 |
|
} |
737 |
|
// calculation as: |
738 |
|
// transpose(A[][]) = transpose(A[][]) * transpose(rot[][]) |
739 |
|
|
740 |
< |
for(i=0; i<3; i++){ |
741 |
< |
for(j=0; j<3; j++){ |
740 |
> |
for (i = 0; i < 3; i++){ |
741 |
> |
for (j = 0; j < 3; j++){ |
742 |
|
A[j][i] = 0.0; |
743 |
< |
for(k=0; k<3; k++){ |
744 |
< |
A[j][i] += tempA[i][k] * rot[j][k]; |
743 |
> |
for (k = 0; k < 3; k++){ |
744 |
> |
A[j][i] += tempA[i][k] * rot[j][k]; |
745 |
|
} |
746 |
|
} |
747 |
|
} |
748 |
|
} |
749 |
+ |
|
750 |
+ |
template<typename T> void Integrator<T>::calcForce(int calcPot, int calcStress){ |
751 |
+ |
myFF->doForces(calcPot, calcStress); |
752 |
+ |
} |
753 |
+ |
|
754 |
+ |
template<typename T> void Integrator<T>::thermalize(){ |
755 |
+ |
tStats->velocitize(); |
756 |
+ |
} |