1 |
< |
#include <iostream> |
2 |
< |
#include <stdlib.h> |
3 |
< |
#include <math.h> |
4 |
< |
#ifdef IS_MPI |
5 |
< |
#include "brains/mpiSimulation.hpp" |
6 |
< |
#include <unistd.h> |
7 |
< |
#endif //is_mpi |
8 |
< |
|
9 |
< |
#ifdef PROFILE |
10 |
< |
#include "profiling/mdProfile.hpp" |
11 |
< |
#endif // profile |
12 |
< |
|
1 |
> |
/* |
2 |
> |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
> |
* |
4 |
> |
* The University of Notre Dame grants you ("Licensee") a |
5 |
> |
* non-exclusive, royalty free, license to use, modify and |
6 |
> |
* redistribute this software in source and binary code form, provided |
7 |
> |
* that the following conditions are met: |
8 |
> |
* |
9 |
> |
* 1. Acknowledgement of the program authors must be made in any |
10 |
> |
* publication of scientific results based in part on use of the |
11 |
> |
* program. An acceptable form of acknowledgement is citation of |
12 |
> |
* the article in which the program was described (Matthew |
13 |
> |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
> |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
> |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
> |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
> |
* |
18 |
> |
* 2. Redistributions of source code must retain the above copyright |
19 |
> |
* notice, this list of conditions and the following disclaimer. |
20 |
> |
* |
21 |
> |
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
> |
* notice, this list of conditions and the following disclaimer in the |
23 |
> |
* documentation and/or other materials provided with the |
24 |
> |
* distribution. |
25 |
> |
* |
26 |
> |
* This software is provided "AS IS," without a warranty of any |
27 |
> |
* kind. All express or implied conditions, representations and |
28 |
> |
* warranties, including any implied warranty of merchantability, |
29 |
> |
* fitness for a particular purpose or non-infringement, are hereby |
30 |
> |
* excluded. The University of Notre Dame and its licensors shall not |
31 |
> |
* be liable for any damages suffered by licensee as a result of |
32 |
> |
* using, modifying or distributing the software or its |
33 |
> |
* derivatives. In no event will the University of Notre Dame or its |
34 |
> |
* licensors be liable for any lost revenue, profit or data, or for |
35 |
> |
* direct, indirect, special, consequential, incidental or punitive |
36 |
> |
* damages, however caused and regardless of the theory of liability, |
37 |
> |
* arising out of the use of or inability to use software, even if the |
38 |
> |
* University of Notre Dame has been advised of the possibility of |
39 |
> |
* such damages. |
40 |
> |
*/ |
41 |
> |
|
42 |
> |
#include "brains/Snapshot.hpp" |
43 |
|
#include "integrators/Integrator.hpp" |
44 |
|
#include "utils/simError.h" |
45 |
+ |
namespace oopse { |
46 |
+ |
Integrator::Integrator(SimInfo* info) |
47 |
+ |
: info_(info), forceMan_(NULL) , needPotential(false), needStress(false), velocitizer_(NULL), |
48 |
+ |
needVelocityScaling(false), dumpWriter(NULL), statWriter(NULL), thermo(info), |
49 |
+ |
currentSnapshot_(info->getSnapshotManager()->getCurrentSnapshot()) { |
50 |
|
|
51 |
+ |
simParams = info->getSimParams(); |
52 |
|
|
53 |
< |
template<typename T> Integrator<T>::Integrator(SimInfo* theInfo, |
54 |
< |
ForceFields* the_ff){ |
55 |
< |
info = theInfo; |
56 |
< |
myFF = the_ff; |
57 |
< |
isFirst = 1; |
58 |
< |
|
59 |
< |
molecules = info->molecules; |
24 |
< |
nMols = info->n_mol; |
25 |
< |
|
26 |
< |
// give a little love back to the SimInfo object |
27 |
< |
|
28 |
< |
if (info->the_integrator != NULL){ |
29 |
< |
delete info->the_integrator; |
30 |
< |
} |
31 |
< |
|
32 |
< |
nAtoms = info->n_atoms; |
33 |
< |
integrableObjects = info->integrableObjects; |
34 |
< |
|
35 |
< |
|
36 |
< |
// check for constraints |
37 |
< |
|
38 |
< |
constrainedA = NULL; |
39 |
< |
constrainedB = NULL; |
40 |
< |
constrainedDsqr = NULL; |
41 |
< |
moving = NULL; |
42 |
< |
moved = NULL; |
43 |
< |
oldPos = NULL; |
44 |
< |
|
45 |
< |
nConstrained = 0; |
46 |
< |
|
47 |
< |
checkConstraints(); |
48 |
< |
|
49 |
< |
} |
50 |
< |
|
51 |
< |
template<typename T> Integrator<T>::~Integrator(){ |
52 |
< |
|
53 |
< |
if (nConstrained){ |
54 |
< |
delete[] constrainedA; |
55 |
< |
delete[] constrainedB; |
56 |
< |
delete[] constrainedDsqr; |
57 |
< |
delete[] moving; |
58 |
< |
delete[] moved; |
59 |
< |
delete[] oldPos; |
60 |
< |
} |
61 |
< |
|
62 |
< |
} |
63 |
< |
|
64 |
< |
|
65 |
< |
template<typename T> void Integrator<T>::checkConstraints(void){ |
66 |
< |
isConstrained = 0; |
67 |
< |
|
68 |
< |
Constraint* temp_con; |
69 |
< |
Constraint* dummy_plug; |
70 |
< |
temp_con = new Constraint[info->n_SRI]; |
71 |
< |
nConstrained = 0; |
72 |
< |
int constrained = 0; |
73 |
< |
|
74 |
< |
SRI** theArray; |
75 |
< |
for (int i = 0; i < nMols; i++){ |
76 |
< |
|
77 |
< |
theArray = (SRI * *) molecules[i].getMyBonds(); |
78 |
< |
for (int j = 0; j < molecules[i].getNBonds(); j++){ |
79 |
< |
constrained = theArray[j]->is_constrained(); |
80 |
< |
|
81 |
< |
if (constrained){ |
82 |
< |
dummy_plug = theArray[j]->get_constraint(); |
83 |
< |
temp_con[nConstrained].set_a(dummy_plug->get_a()); |
84 |
< |
temp_con[nConstrained].set_b(dummy_plug->get_b()); |
85 |
< |
temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
86 |
< |
|
87 |
< |
nConstrained++; |
88 |
< |
constrained = 0; |
89 |
< |
} |
53 |
> |
if (simParams->haveDt()) { |
54 |
> |
dt = simParams->getDt(); |
55 |
> |
} else { |
56 |
> |
sprintf(painCave.errMsg, |
57 |
> |
"Integrator Error: dt is not set\n"); |
58 |
> |
painCave.isFatal = 1; |
59 |
> |
simError(); |
60 |
|
} |
61 |
< |
|
62 |
< |
theArray = (SRI * *) molecules[i].getMyBends(); |
63 |
< |
for (int j = 0; j < molecules[i].getNBends(); j++){ |
64 |
< |
constrained = theArray[j]->is_constrained(); |
65 |
< |
|
66 |
< |
if (constrained){ |
67 |
< |
dummy_plug = theArray[j]->get_constraint(); |
68 |
< |
temp_con[nConstrained].set_a(dummy_plug->get_a()); |
99 |
< |
temp_con[nConstrained].set_b(dummy_plug->get_b()); |
100 |
< |
temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
101 |
< |
|
102 |
< |
nConstrained++; |
103 |
< |
constrained = 0; |
104 |
< |
} |
61 |
> |
|
62 |
> |
if (simParams->haveRunTime()) { |
63 |
> |
runTime = simParams->getRunTime(); |
64 |
> |
} else { |
65 |
> |
sprintf(painCave.errMsg, |
66 |
> |
"Integrator Error: runTime is not set\n"); |
67 |
> |
painCave.isFatal = 1; |
68 |
> |
simError(); |
69 |
|
} |
70 |
< |
|
71 |
< |
theArray = (SRI * *) molecules[i].getMyTorsions(); |
72 |
< |
for (int j = 0; j < molecules[i].getNTorsions(); j++){ |
73 |
< |
constrained = theArray[j]->is_constrained(); |
74 |
< |
|
75 |
< |
if (constrained){ |
76 |
< |
dummy_plug = theArray[j]->get_constraint(); |
113 |
< |
temp_con[nConstrained].set_a(dummy_plug->get_a()); |
114 |
< |
temp_con[nConstrained].set_b(dummy_plug->get_b()); |
115 |
< |
temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); |
116 |
< |
|
117 |
< |
nConstrained++; |
118 |
< |
constrained = 0; |
119 |
< |
} |
70 |
> |
// set the status, sample, and thermal kick times |
71 |
> |
if (simParams->haveSampleTime()){ |
72 |
> |
sampleTime = simParams->getSampleTime(); |
73 |
> |
statusTime = sampleTime; |
74 |
> |
} else{ |
75 |
> |
sampleTime = simParams->getRunTime(); |
76 |
> |
statusTime = sampleTime; |
77 |
|
} |
121 |
– |
} |
78 |
|
|
79 |
< |
|
80 |
< |
if (nConstrained > 0){ |
125 |
< |
isConstrained = 1; |
126 |
< |
|
127 |
< |
if (constrainedA != NULL) |
128 |
< |
delete[] constrainedA; |
129 |
< |
if (constrainedB != NULL) |
130 |
< |
delete[] constrainedB; |
131 |
< |
if (constrainedDsqr != NULL) |
132 |
< |
delete[] constrainedDsqr; |
133 |
< |
|
134 |
< |
constrainedA = new int[nConstrained]; |
135 |
< |
constrainedB = new int[nConstrained]; |
136 |
< |
constrainedDsqr = new double[nConstrained]; |
137 |
< |
|
138 |
< |
for (int i = 0; i < nConstrained; i++){ |
139 |
< |
constrainedA[i] = temp_con[i].get_a(); |
140 |
< |
constrainedB[i] = temp_con[i].get_b(); |
141 |
< |
constrainedDsqr[i] = temp_con[i].get_dsqr(); |
79 |
> |
if (simParams->haveStatusTime()){ |
80 |
> |
statusTime = simParams->getStatusTime(); |
81 |
|
} |
82 |
|
|
83 |
< |
|
84 |
< |
// save oldAtoms to check for lode balancing later on. |
85 |
< |
|
86 |
< |
oldAtoms = nAtoms; |
148 |
< |
|
149 |
< |
moving = new int[nAtoms]; |
150 |
< |
moved = new int[nAtoms]; |
151 |
< |
|
152 |
< |
oldPos = new double[nAtoms * 3]; |
153 |
< |
} |
154 |
< |
|
155 |
< |
delete[] temp_con; |
156 |
< |
} |
157 |
< |
|
158 |
< |
|
159 |
< |
template<typename T> void Integrator<T>::integrate(void){ |
160 |
< |
|
161 |
< |
double runTime = info->run_time; |
162 |
< |
double sampleTime = info->sampleTime; |
163 |
< |
double statusTime = info->statusTime; |
164 |
< |
double thermalTime = info->thermalTime; |
165 |
< |
double resetTime = info->resetTime; |
166 |
< |
|
167 |
< |
double difference; |
168 |
< |
double currSample; |
169 |
< |
double currThermal; |
170 |
< |
double currStatus; |
171 |
< |
double currReset; |
172 |
< |
|
173 |
< |
int calcPot, calcStress; |
174 |
< |
int i; |
175 |
< |
int localIndex; |
176 |
< |
|
177 |
< |
#ifdef IS_MPI |
178 |
< |
int which_node; |
179 |
< |
#endif // is_mpi |
180 |
< |
|
181 |
< |
vector<StuntDouble*> particles; |
182 |
< |
string inAngle; |
183 |
< |
|
184 |
< |
tStats = new Thermo(info); |
185 |
< |
statOut = new StatWriter(info); |
186 |
< |
dumpOut = new DumpWriter(info); |
187 |
< |
|
188 |
< |
if (info->useSolidThermInt && !info->useLiquidThermInt) { |
189 |
< |
restOut = new RestraintWriter(info); |
190 |
< |
initRestraints = new RestraintReader(info); |
191 |
< |
} |
192 |
< |
|
193 |
< |
atoms = info->atoms; |
194 |
< |
|
195 |
< |
dt = info->dt; |
196 |
< |
dt2 = 0.5 * dt; |
197 |
< |
|
198 |
< |
readyCheck(); |
199 |
< |
|
200 |
< |
// remove center of mass drift velocity (in case we passed in a configuration |
201 |
< |
// that was drifting |
202 |
< |
tStats->removeCOMdrift(); |
203 |
< |
|
204 |
< |
// initialize the retraints if necessary |
205 |
< |
if (info->useSolidThermInt && !info->useLiquidThermInt) { |
206 |
< |
initRestraints->zeroZangle(); |
207 |
< |
inAngle = info->zAngleName + "_in"; |
208 |
< |
initRestraints->readZangle(inAngle.c_str()); |
209 |
< |
initRestraints->readIdealCrystal(); |
210 |
< |
} |
211 |
< |
|
212 |
< |
// initialize the forces before the first step |
213 |
< |
calcForce(1, 1); |
214 |
< |
|
215 |
< |
//execute constraint algorithm to make sure at the very beginning the system is constrained |
216 |
< |
if(nConstrained){ |
217 |
< |
preMove(); |
218 |
< |
constrainA(); |
219 |
< |
calcForce(1, 1); |
220 |
< |
constrainB(); |
221 |
< |
} |
222 |
< |
|
223 |
< |
if (info->setTemp){ |
224 |
< |
thermalize(); |
225 |
< |
} |
226 |
< |
|
227 |
< |
calcPot = 0; |
228 |
< |
calcStress = 0; |
229 |
< |
currSample = sampleTime + info->getTime(); |
230 |
< |
currThermal = thermalTime+ info->getTime(); |
231 |
< |
currStatus = statusTime + info->getTime(); |
232 |
< |
currReset = resetTime + info->getTime(); |
233 |
< |
|
234 |
< |
dumpOut->writeDump(info->getTime()); |
235 |
< |
statOut->writeStat(info->getTime()); |
236 |
< |
restOut->writeZangle(info->getTime()); |
237 |
< |
|
238 |
< |
#ifdef IS_MPI |
239 |
< |
strcpy(checkPointMsg, "The integrator is ready to go."); |
240 |
< |
MPIcheckPoint(); |
241 |
< |
#endif // is_mpi |
242 |
< |
|
243 |
< |
while (info->getTime() < runTime && !stopIntegrator()){ |
244 |
< |
difference = info->getTime() + dt - currStatus; |
245 |
< |
if (difference > 0 || fabs(difference) < 1e-4 ){ |
246 |
< |
calcPot = 1; |
247 |
< |
calcStress = 1; |
83 |
> |
if (simParams->haveThermalTime()){ |
84 |
> |
thermalTime = simParams->getThermalTime(); |
85 |
> |
} else { |
86 |
> |
thermalTime = simParams->getRunTime(); |
87 |
|
} |
88 |
|
|
89 |
< |
#ifdef PROFILE |
90 |
< |
startProfile( pro1 ); |
252 |
< |
#endif |
253 |
< |
|
254 |
< |
integrateStep(calcPot, calcStress); |
255 |
< |
|
256 |
< |
#ifdef PROFILE |
257 |
< |
endProfile( pro1 ); |
258 |
< |
|
259 |
< |
startProfile( pro2 ); |
260 |
< |
#endif // profile |
261 |
< |
|
262 |
< |
info->incrTime(dt); |
263 |
< |
|
264 |
< |
if (info->setTemp){ |
265 |
< |
if (info->getTime() >= currThermal){ |
266 |
< |
thermalize(); |
267 |
< |
currThermal += thermalTime; |
268 |
< |
} |
89 |
> |
if (!simParams->getUseInitTime()) { |
90 |
> |
currentSnapshot_->setTime(0.0); |
91 |
|
} |
270 |
– |
|
271 |
– |
if (info->getTime() >= currSample){ |
272 |
– |
dumpOut->writeDump(info->getTime()); |
273 |
– |
// write a zAng file to coincide with each dump or eor file |
274 |
– |
if (info->useSolidThermInt && !info->useLiquidThermInt) |
275 |
– |
restOut->writeZangle(info->getTime()); |
276 |
– |
currSample += sampleTime; |
277 |
– |
} |
278 |
– |
|
279 |
– |
if (info->getTime() >= currStatus){ |
280 |
– |
statOut->writeStat(info->getTime()); |
281 |
– |
calcPot = 0; |
282 |
– |
calcStress = 0; |
283 |
– |
currStatus += statusTime; |
284 |
– |
} |
285 |
– |
|
286 |
– |
if (info->resetIntegrator){ |
287 |
– |
if (info->getTime() >= currReset){ |
288 |
– |
this->resetIntegrator(); |
289 |
– |
currReset += resetTime; |
290 |
– |
} |
291 |
– |
} |
92 |
|
|
93 |
< |
#ifdef PROFILE |
94 |
< |
endProfile( pro2 ); |
95 |
< |
#endif //profile |
296 |
< |
|
297 |
< |
#ifdef IS_MPI |
298 |
< |
strcpy(checkPointMsg, "successfully took a time step."); |
299 |
< |
MPIcheckPoint(); |
300 |
< |
#endif // is_mpi |
301 |
< |
} |
302 |
< |
|
303 |
< |
dumpOut->writeFinal(info->getTime()); |
304 |
< |
|
305 |
< |
// write the file containing the omega values of the final configuration |
306 |
< |
if (info->useSolidThermInt && !info->useLiquidThermInt){ |
307 |
< |
restOut->writeZangle(info->getTime()); |
308 |
< |
restOut->writeZangle(info->getTime(), inAngle.c_str()); |
309 |
< |
} |
310 |
< |
|
311 |
< |
delete dumpOut; |
312 |
< |
delete statOut; |
313 |
< |
} |
314 |
< |
|
315 |
< |
template<typename T> void Integrator<T>::integrateStep(int calcPot, |
316 |
< |
int calcStress){ |
317 |
< |
// Position full step, and velocity half step |
318 |
< |
|
319 |
< |
#ifdef PROFILE |
320 |
< |
startProfile(pro3); |
321 |
< |
#endif //profile |
322 |
< |
|
323 |
< |
//save old state (position, velocity etc) |
324 |
< |
preMove(); |
325 |
< |
#ifdef PROFILE |
326 |
< |
endProfile(pro3); |
327 |
< |
|
328 |
< |
startProfile(pro4); |
329 |
< |
#endif // profile |
330 |
< |
|
331 |
< |
moveA(); |
332 |
< |
|
333 |
< |
#ifdef PROFILE |
334 |
< |
endProfile(pro4); |
335 |
< |
|
336 |
< |
startProfile(pro5); |
337 |
< |
#endif//profile |
338 |
< |
|
339 |
< |
|
340 |
< |
#ifdef IS_MPI |
341 |
< |
strcpy(checkPointMsg, "Succesful moveA\n"); |
342 |
< |
MPIcheckPoint(); |
343 |
< |
#endif // is_mpi |
344 |
< |
|
345 |
< |
// calc forces |
346 |
< |
calcForce(calcPot, calcStress); |
347 |
< |
|
348 |
< |
#ifdef IS_MPI |
349 |
< |
strcpy(checkPointMsg, "Succesful doForces\n"); |
350 |
< |
MPIcheckPoint(); |
351 |
< |
#endif // is_mpi |
352 |
< |
|
353 |
< |
#ifdef PROFILE |
354 |
< |
endProfile( pro5 ); |
355 |
< |
|
356 |
< |
startProfile( pro6 ); |
357 |
< |
#endif //profile |
358 |
< |
|
359 |
< |
// finish the velocity half step |
360 |
< |
|
361 |
< |
moveB(); |
362 |
< |
|
363 |
< |
#ifdef PROFILE |
364 |
< |
endProfile(pro6); |
365 |
< |
#endif // profile |
366 |
< |
|
367 |
< |
#ifdef IS_MPI |
368 |
< |
strcpy(checkPointMsg, "Succesful moveB\n"); |
369 |
< |
MPIcheckPoint(); |
370 |
< |
#endif // is_mpi |
371 |
< |
} |
372 |
< |
|
373 |
< |
|
374 |
< |
template<typename T> void Integrator<T>::moveA(void){ |
375 |
< |
size_t i, j; |
376 |
< |
DirectionalAtom* dAtom; |
377 |
< |
double Tb[3], ji[3]; |
378 |
< |
double vel[3], pos[3], frc[3]; |
379 |
< |
double mass; |
380 |
< |
double omega; |
381 |
< |
|
382 |
< |
for (i = 0; i < integrableObjects.size() ; i++){ |
383 |
< |
integrableObjects[i]->getVel(vel); |
384 |
< |
integrableObjects[i]->getPos(pos); |
385 |
< |
integrableObjects[i]->getFrc(frc); |
386 |
< |
// std::cerr << "f = " << frc[0] << "\t" << frc[1] << "\t" << frc[2] << "\n"; |
93 |
> |
//create a default ForceManager |
94 |
> |
//if the subclass wants to use a different ForceManager, use setForceManager |
95 |
> |
forceMan_ = new ForceManager(info); |
96 |
|
|
97 |
< |
mass = integrableObjects[i]->getMass(); |
98 |
< |
|
99 |
< |
for (j = 0; j < 3; j++){ |
100 |
< |
// velocity half step |
101 |
< |
vel[j] += (dt2 * frc[j] / mass) * eConvert; |
393 |
< |
// position whole step |
394 |
< |
pos[j] += dt * vel[j]; |
97 |
> |
//set the force manager for thermodynamic integration if specified |
98 |
> |
if (simParams->getUseSolidThermInt() || simParams->getUseLiquidThermInt()){ |
99 |
> |
ThermoIntegrationForceManager* thermoForce_ |
100 |
> |
= new ThermoIntegrationForceManager(info); |
101 |
> |
setForceManager(thermoForce_); |
102 |
|
} |
103 |
+ |
|
104 |
+ |
// check for the temperature set flag (velocity scaling) |
105 |
+ |
if (simParams->haveTempSet()) { |
106 |
+ |
needVelocityScaling = simParams->getTempSet(); |
107 |
|
|
108 |
< |
integrableObjects[i]->setVel(vel); |
109 |
< |
integrableObjects[i]->setPos(pos); |
110 |
< |
|
111 |
< |
|
112 |
< |
if (integrableObjects[i]->isDirectional()){ |
113 |
< |
|
403 |
< |
// get and convert the torque to body frame |
404 |
< |
|
405 |
< |
integrableObjects[i]->getTrq(Tb); |
406 |
< |
|
407 |
< |
// std::cerr << "t = " << Tb[0] << "\t" << Tb[1] << "\t" << Tb[2] << "\n"; |
408 |
< |
integrableObjects[i]->lab2Body(Tb); |
409 |
< |
|
410 |
< |
// get the angular momentum, and propagate a half step |
411 |
< |
|
412 |
< |
integrableObjects[i]->getJ(ji); |
413 |
< |
|
414 |
< |
for (j = 0; j < 3; j++) |
415 |
< |
ji[j] += (dt2 * Tb[j]) * eConvert; |
416 |
< |
|
417 |
< |
this->rotationPropagation( integrableObjects[i], ji ); |
418 |
< |
|
419 |
< |
integrableObjects[i]->setJ(ji); |
420 |
< |
} |
421 |
< |
} |
422 |
< |
|
423 |
< |
if(nConstrained) |
424 |
< |
constrainA(); |
425 |
< |
} |
426 |
< |
|
427 |
< |
|
428 |
< |
template<typename T> void Integrator<T>::moveB(void){ |
429 |
< |
int i, j; |
430 |
< |
double Tb[3], ji[3]; |
431 |
< |
double vel[3], frc[3]; |
432 |
< |
double mass; |
433 |
< |
|
434 |
< |
for (i = 0; i < integrableObjects.size(); i++){ |
435 |
< |
integrableObjects[i]->getVel(vel); |
436 |
< |
integrableObjects[i]->getFrc(frc); |
437 |
< |
|
438 |
< |
mass = integrableObjects[i]->getMass(); |
439 |
< |
|
440 |
< |
// velocity half step |
441 |
< |
for (j = 0; j < 3; j++) |
442 |
< |
vel[j] += (dt2 * frc[j] / mass) * eConvert; |
443 |
< |
|
444 |
< |
integrableObjects[i]->setVel(vel); |
445 |
< |
|
446 |
< |
if (integrableObjects[i]->isDirectional()){ |
447 |
< |
|
448 |
< |
// get and convert the torque to body frame |
449 |
< |
|
450 |
< |
integrableObjects[i]->getTrq(Tb); |
451 |
< |
integrableObjects[i]->lab2Body(Tb); |
452 |
< |
|
453 |
< |
// get the angular momentum, and propagate a half step |
454 |
< |
|
455 |
< |
integrableObjects[i]->getJ(ji); |
456 |
< |
|
457 |
< |
for (j = 0; j < 3; j++) |
458 |
< |
ji[j] += (dt2 * Tb[j]) * eConvert; |
459 |
< |
|
460 |
< |
|
461 |
< |
integrableObjects[i]->setJ(ji); |
462 |
< |
} |
463 |
< |
} |
464 |
< |
|
465 |
< |
if(nConstrained) |
466 |
< |
constrainB(); |
467 |
< |
} |
468 |
< |
|
469 |
< |
|
470 |
< |
template<typename T> void Integrator<T>::preMove(void){ |
471 |
< |
int i, j; |
472 |
< |
double pos[3]; |
473 |
< |
|
474 |
< |
if (nConstrained){ |
475 |
< |
for (i = 0; i < nAtoms; i++){ |
476 |
< |
atoms[i]->getPos(pos); |
477 |
< |
|
478 |
< |
for (j = 0; j < 3; j++){ |
479 |
< |
oldPos[3 * i + j] = pos[j]; |
480 |
< |
} |
481 |
< |
} |
482 |
< |
} |
483 |
< |
} |
484 |
< |
|
485 |
< |
template<typename T> void Integrator<T>::constrainA(){ |
486 |
< |
int i, j; |
487 |
< |
int done; |
488 |
< |
double posA[3], posB[3]; |
489 |
< |
double velA[3], velB[3]; |
490 |
< |
double pab[3]; |
491 |
< |
double rab[3]; |
492 |
< |
int a, b, ax, ay, az, bx, by, bz; |
493 |
< |
double rma, rmb; |
494 |
< |
double dx, dy, dz; |
495 |
< |
double rpab; |
496 |
< |
double rabsq, pabsq, rpabsq; |
497 |
< |
double diffsq; |
498 |
< |
double gab; |
499 |
< |
int iteration; |
500 |
< |
|
501 |
< |
for (i = 0; i < nAtoms; i++){ |
502 |
< |
moving[i] = 0; |
503 |
< |
moved[i] = 1; |
504 |
< |
} |
505 |
< |
|
506 |
< |
iteration = 0; |
507 |
< |
done = 0; |
508 |
< |
while (!done && (iteration < maxIteration)){ |
509 |
< |
done = 1; |
510 |
< |
for (i = 0; i < nConstrained; i++){ |
511 |
< |
a = constrainedA[i]; |
512 |
< |
b = constrainedB[i]; |
513 |
< |
|
514 |
< |
ax = (a * 3) + 0; |
515 |
< |
ay = (a * 3) + 1; |
516 |
< |
az = (a * 3) + 2; |
517 |
< |
|
518 |
< |
bx = (b * 3) + 0; |
519 |
< |
by = (b * 3) + 1; |
520 |
< |
bz = (b * 3) + 2; |
521 |
< |
|
522 |
< |
if (moved[a] || moved[b]){ |
523 |
< |
atoms[a]->getPos(posA); |
524 |
< |
atoms[b]->getPos(posB); |
525 |
< |
|
526 |
< |
for (j = 0; j < 3; j++) |
527 |
< |
pab[j] = posA[j] - posB[j]; |
528 |
< |
|
529 |
< |
//periodic boundary condition |
530 |
< |
|
531 |
< |
info->wrapVector(pab); |
532 |
< |
|
533 |
< |
pabsq = pab[0] * pab[0] + pab[1] * pab[1] + pab[2] * pab[2]; |
534 |
< |
|
535 |
< |
rabsq = constrainedDsqr[i]; |
536 |
< |
diffsq = rabsq - pabsq; |
537 |
< |
|
538 |
< |
// the original rattle code from alan tidesley |
539 |
< |
if (fabs(diffsq) > (tol * rabsq * 2)){ |
540 |
< |
rab[0] = oldPos[ax] - oldPos[bx]; |
541 |
< |
rab[1] = oldPos[ay] - oldPos[by]; |
542 |
< |
rab[2] = oldPos[az] - oldPos[bz]; |
543 |
< |
|
544 |
< |
info->wrapVector(rab); |
545 |
< |
|
546 |
< |
rpab = rab[0] * pab[0] + rab[1] * pab[1] + rab[2] * pab[2]; |
547 |
< |
|
548 |
< |
rpabsq = rpab * rpab; |
549 |
< |
|
550 |
< |
|
551 |
< |
if (rpabsq < (rabsq * -diffsq)){ |
552 |
< |
#ifdef IS_MPI |
553 |
< |
a = atoms[a]->getGlobalIndex(); |
554 |
< |
b = atoms[b]->getGlobalIndex(); |
555 |
< |
#endif //is_mpi |
556 |
< |
sprintf(painCave.errMsg, |
557 |
< |
"Constraint failure in constrainA at atom %d and %d.\n", a, |
558 |
< |
b); |
108 |
> |
if (simParams->haveTargetTemp()) { |
109 |
> |
targetScalingTemp = simParams->getTargetTemp(); |
110 |
> |
} |
111 |
> |
else { |
112 |
> |
sprintf(painCave.errMsg, |
113 |
> |
"Integrator Error: Target Temperature is not set\n"); |
114 |
|
painCave.isFatal = 1; |
115 |
|
simError(); |
561 |
– |
} |
116 |
|
|
563 |
– |
rma = 1.0 / atoms[a]->getMass(); |
564 |
– |
rmb = 1.0 / atoms[b]->getMass(); |
565 |
– |
|
566 |
– |
gab = diffsq / (2.0 * (rma + rmb) * rpab); |
567 |
– |
|
568 |
– |
dx = rab[0] * gab; |
569 |
– |
dy = rab[1] * gab; |
570 |
– |
dz = rab[2] * gab; |
571 |
– |
|
572 |
– |
posA[0] += rma * dx; |
573 |
– |
posA[1] += rma * dy; |
574 |
– |
posA[2] += rma * dz; |
575 |
– |
|
576 |
– |
atoms[a]->setPos(posA); |
577 |
– |
|
578 |
– |
posB[0] -= rmb * dx; |
579 |
– |
posB[1] -= rmb * dy; |
580 |
– |
posB[2] -= rmb * dz; |
581 |
– |
|
582 |
– |
atoms[b]->setPos(posB); |
583 |
– |
|
584 |
– |
dx = dx / dt; |
585 |
– |
dy = dy / dt; |
586 |
– |
dz = dz / dt; |
587 |
– |
|
588 |
– |
atoms[a]->getVel(velA); |
589 |
– |
|
590 |
– |
velA[0] += rma * dx; |
591 |
– |
velA[1] += rma * dy; |
592 |
– |
velA[2] += rma * dz; |
593 |
– |
|
594 |
– |
atoms[a]->setVel(velA); |
595 |
– |
|
596 |
– |
atoms[b]->getVel(velB); |
597 |
– |
|
598 |
– |
velB[0] -= rmb * dx; |
599 |
– |
velB[1] -= rmb * dy; |
600 |
– |
velB[2] -= rmb * dz; |
601 |
– |
|
602 |
– |
atoms[b]->setVel(velB); |
603 |
– |
|
604 |
– |
moving[a] = 1; |
605 |
– |
moving[b] = 1; |
606 |
– |
done = 0; |
117 |
|
} |
608 |
– |
} |
118 |
|
} |
610 |
– |
|
611 |
– |
for (i = 0; i < nAtoms; i++){ |
612 |
– |
moved[i] = moving[i]; |
613 |
– |
moving[i] = 0; |
614 |
– |
} |
615 |
– |
|
616 |
– |
iteration++; |
617 |
– |
} |
618 |
– |
|
619 |
– |
if (!done){ |
620 |
– |
sprintf(painCave.errMsg, |
621 |
– |
"Constraint failure in constrainA, too many iterations: %d\n", |
622 |
– |
iteration); |
623 |
– |
painCave.isFatal = 1; |
624 |
– |
simError(); |
625 |
– |
} |
626 |
– |
|
627 |
– |
} |
628 |
– |
|
629 |
– |
template<typename T> void Integrator<T>::constrainB(void){ |
630 |
– |
int i, j; |
631 |
– |
int done; |
632 |
– |
double posA[3], posB[3]; |
633 |
– |
double velA[3], velB[3]; |
634 |
– |
double vxab, vyab, vzab; |
635 |
– |
double rab[3]; |
636 |
– |
int a, b, ax, ay, az, bx, by, bz; |
637 |
– |
double rma, rmb; |
638 |
– |
double dx, dy, dz; |
639 |
– |
double rvab; |
640 |
– |
double gab; |
641 |
– |
int iteration; |
642 |
– |
|
643 |
– |
for (i = 0; i < nAtoms; i++){ |
644 |
– |
moving[i] = 0; |
645 |
– |
moved[i] = 1; |
646 |
– |
} |
647 |
– |
|
648 |
– |
done = 0; |
649 |
– |
iteration = 0; |
650 |
– |
while (!done && (iteration < maxIteration)){ |
651 |
– |
done = 1; |
652 |
– |
|
653 |
– |
for (i = 0; i < nConstrained; i++){ |
654 |
– |
a = constrainedA[i]; |
655 |
– |
b = constrainedB[i]; |
656 |
– |
|
657 |
– |
ax = (a * 3) + 0; |
658 |
– |
ay = (a * 3) + 1; |
659 |
– |
az = (a * 3) + 2; |
660 |
– |
|
661 |
– |
bx = (b * 3) + 0; |
662 |
– |
by = (b * 3) + 1; |
663 |
– |
bz = (b * 3) + 2; |
664 |
– |
|
665 |
– |
if (moved[a] || moved[b]){ |
666 |
– |
atoms[a]->getVel(velA); |
667 |
– |
atoms[b]->getVel(velB); |
668 |
– |
|
669 |
– |
vxab = velA[0] - velB[0]; |
670 |
– |
vyab = velA[1] - velB[1]; |
671 |
– |
vzab = velA[2] - velB[2]; |
672 |
– |
|
673 |
– |
atoms[a]->getPos(posA); |
674 |
– |
atoms[b]->getPos(posB); |
675 |
– |
|
676 |
– |
for (j = 0; j < 3; j++) |
677 |
– |
rab[j] = posA[j] - posB[j]; |
678 |
– |
|
679 |
– |
info->wrapVector(rab); |
680 |
– |
|
681 |
– |
rma = 1.0 / atoms[a]->getMass(); |
682 |
– |
rmb = 1.0 / atoms[b]->getMass(); |
683 |
– |
|
684 |
– |
rvab = rab[0] * vxab + rab[1] * vyab + rab[2] * vzab; |
685 |
– |
|
686 |
– |
gab = -rvab / ((rma + rmb) * constrainedDsqr[i]); |
687 |
– |
|
688 |
– |
if (fabs(gab) > tol){ |
689 |
– |
dx = rab[0] * gab; |
690 |
– |
dy = rab[1] * gab; |
691 |
– |
dz = rab[2] * gab; |
692 |
– |
|
693 |
– |
velA[0] += rma * dx; |
694 |
– |
velA[1] += rma * dy; |
695 |
– |
velA[2] += rma * dz; |
696 |
– |
|
697 |
– |
atoms[a]->setVel(velA); |
698 |
– |
|
699 |
– |
velB[0] -= rmb * dx; |
700 |
– |
velB[1] -= rmb * dy; |
701 |
– |
velB[2] -= rmb * dz; |
702 |
– |
|
703 |
– |
atoms[b]->setVel(velB); |
704 |
– |
|
705 |
– |
moving[a] = 1; |
706 |
– |
moving[b] = 1; |
707 |
– |
done = 0; |
708 |
– |
} |
709 |
– |
} |
710 |
– |
} |
711 |
– |
|
712 |
– |
for (i = 0; i < nAtoms; i++){ |
713 |
– |
moved[i] = moving[i]; |
714 |
– |
moving[i] = 0; |
715 |
– |
} |
716 |
– |
|
717 |
– |
iteration++; |
718 |
– |
} |
719 |
– |
|
720 |
– |
if (!done){ |
721 |
– |
sprintf(painCave.errMsg, |
722 |
– |
"Constraint failure in constrainB, too many iterations: %d\n", |
723 |
– |
iteration); |
724 |
– |
painCave.isFatal = 1; |
725 |
– |
simError(); |
726 |
– |
} |
727 |
– |
} |
728 |
– |
|
729 |
– |
template<typename T> void Integrator<T>::rotationPropagation |
730 |
– |
( StuntDouble* sd, double ji[3] ){ |
731 |
– |
|
732 |
– |
double angle; |
733 |
– |
double A[3][3], I[3][3]; |
734 |
– |
int i, j, k; |
735 |
– |
|
736 |
– |
// use the angular velocities to propagate the rotation matrix a |
737 |
– |
// full time step |
738 |
– |
|
739 |
– |
sd->getA(A); |
740 |
– |
sd->getI(I); |
741 |
– |
|
742 |
– |
if (sd->isLinear()) { |
743 |
– |
|
744 |
– |
i = sd->linearAxis(); |
745 |
– |
j = (i+1)%3; |
746 |
– |
k = (i+2)%3; |
747 |
– |
|
748 |
– |
angle = dt2 * ji[j] / I[j][j]; |
749 |
– |
this->rotate( k, i, angle, ji, A ); |
750 |
– |
|
751 |
– |
angle = dt * ji[k] / I[k][k]; |
752 |
– |
this->rotate( i, j, angle, ji, A); |
753 |
– |
|
754 |
– |
angle = dt2 * ji[j] / I[j][j]; |
755 |
– |
this->rotate( k, i, angle, ji, A ); |
756 |
– |
|
757 |
– |
} else { |
758 |
– |
// rotate about the x-axis |
759 |
– |
angle = dt2 * ji[0] / I[0][0]; |
760 |
– |
this->rotate( 1, 2, angle, ji, A ); |
119 |
|
|
120 |
< |
// rotate about the y-axis |
121 |
< |
angle = dt2 * ji[1] / I[1][1]; |
122 |
< |
this->rotate( 2, 0, angle, ji, A ); |
120 |
> |
//create a default a velocitizer |
121 |
> |
//if the subclass want to using different velocitizer, use setVelocitizer |
122 |
> |
velocitizer_ = new Velocitizer(info); |
123 |
|
|
766 |
– |
// rotate about the z-axis |
767 |
– |
angle = dt * ji[2] / I[2][2]; |
768 |
– |
sd->addZangle(angle); |
769 |
– |
this->rotate( 0, 1, angle, ji, A); |
770 |
– |
|
771 |
– |
// rotate about the y-axis |
772 |
– |
angle = dt2 * ji[1] / I[1][1]; |
773 |
– |
this->rotate( 2, 0, angle, ji, A ); |
774 |
– |
|
775 |
– |
// rotate about the x-axis |
776 |
– |
angle = dt2 * ji[0] / I[0][0]; |
777 |
– |
this->rotate( 1, 2, angle, ji, A ); |
778 |
– |
|
779 |
– |
} |
780 |
– |
sd->setA( A ); |
124 |
|
} |
125 |
|
|
126 |
< |
template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
127 |
< |
double angle, double ji[3], |
128 |
< |
double A[3][3]){ |
129 |
< |
int i, j, k; |
130 |
< |
double sinAngle; |
131 |
< |
double cosAngle; |
132 |
< |
double angleSqr; |
790 |
< |
double angleSqrOver4; |
791 |
< |
double top, bottom; |
792 |
< |
double rot[3][3]; |
793 |
< |
double tempA[3][3]; |
794 |
< |
double tempJ[3]; |
795 |
< |
|
796 |
< |
// initialize the tempA |
797 |
< |
|
798 |
< |
for (i = 0; i < 3; i++){ |
799 |
< |
for (j = 0; j < 3; j++){ |
800 |
< |
tempA[j][i] = A[i][j]; |
801 |
< |
} |
802 |
< |
} |
803 |
< |
|
804 |
< |
// initialize the tempJ |
805 |
< |
|
806 |
< |
for (i = 0; i < 3; i++) |
807 |
< |
tempJ[i] = ji[i]; |
808 |
< |
|
809 |
< |
// initalize rot as a unit matrix |
810 |
< |
|
811 |
< |
rot[0][0] = 1.0; |
812 |
< |
rot[0][1] = 0.0; |
813 |
< |
rot[0][2] = 0.0; |
814 |
< |
|
815 |
< |
rot[1][0] = 0.0; |
816 |
< |
rot[1][1] = 1.0; |
817 |
< |
rot[1][2] = 0.0; |
818 |
< |
|
819 |
< |
rot[2][0] = 0.0; |
820 |
< |
rot[2][1] = 0.0; |
821 |
< |
rot[2][2] = 1.0; |
822 |
< |
|
823 |
< |
// use a small angle aproximation for sin and cosine |
824 |
< |
|
825 |
< |
angleSqr = angle * angle; |
826 |
< |
angleSqrOver4 = angleSqr / 4.0; |
827 |
< |
top = 1.0 - angleSqrOver4; |
828 |
< |
bottom = 1.0 + angleSqrOver4; |
829 |
< |
|
830 |
< |
cosAngle = top / bottom; |
831 |
< |
sinAngle = angle / bottom; |
832 |
< |
|
833 |
< |
rot[axes1][axes1] = cosAngle; |
834 |
< |
rot[axes2][axes2] = cosAngle; |
835 |
< |
|
836 |
< |
rot[axes1][axes2] = sinAngle; |
837 |
< |
rot[axes2][axes1] = -sinAngle; |
838 |
< |
|
839 |
< |
// rotate the momentum acoording to: ji[] = rot[][] * ji[] |
840 |
< |
|
841 |
< |
for (i = 0; i < 3; i++){ |
842 |
< |
ji[i] = 0.0; |
843 |
< |
for (k = 0; k < 3; k++){ |
844 |
< |
ji[i] += rot[i][k] * tempJ[k]; |
845 |
< |
} |
846 |
< |
} |
847 |
< |
|
848 |
< |
// rotate the Rotation matrix acording to: |
849 |
< |
// A[][] = A[][] * transpose(rot[][]) |
850 |
< |
|
851 |
< |
|
852 |
< |
// NOte for as yet unknown reason, we are performing the |
853 |
< |
// calculation as: |
854 |
< |
// transpose(A[][]) = transpose(A[][]) * transpose(rot[][]) |
855 |
< |
|
856 |
< |
for (i = 0; i < 3; i++){ |
857 |
< |
for (j = 0; j < 3; j++){ |
858 |
< |
A[j][i] = 0.0; |
859 |
< |
for (k = 0; k < 3; k++){ |
860 |
< |
A[j][i] += tempA[i][k] * rot[j][k]; |
861 |
< |
} |
862 |
< |
} |
863 |
< |
} |
126 |
> |
Integrator::~Integrator(){ |
127 |
> |
delete forceMan_; |
128 |
> |
delete velocitizer_; |
129 |
> |
|
130 |
> |
delete dumpWriter; |
131 |
> |
delete statWriter; |
132 |
> |
delete restWriter; |
133 |
|
} |
134 |
|
|
866 |
– |
template<typename T> void Integrator<T>::calcForce(int calcPot, int calcStress){ |
867 |
– |
myFF->doForces(calcPot, calcStress); |
868 |
– |
} |
135 |
|
|
870 |
– |
template<typename T> void Integrator<T>::thermalize(){ |
871 |
– |
tStats->velocitize(); |
136 |
|
} |
137 |
|
|
874 |
– |
template<typename T> double Integrator<T>::getConservedQuantity(void){ |
875 |
– |
return tStats->getTotalE(); |
876 |
– |
} |
877 |
– |
template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
878 |
– |
//By default, return a null string |
879 |
– |
//The reason we use string instead of char* is that if we use char*, we will |
880 |
– |
//return a pointer point to local variable which might cause problem |
881 |
– |
return string(); |
882 |
– |
} |