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