1 |
|
#include <iostream> |
2 |
|
#include <cstdlib> |
3 |
|
|
4 |
+ |
#ifdef IS_MPI |
5 |
+ |
#include "mpiSimulation.hpp" |
6 |
+ |
#include <unistd.h> |
7 |
+ |
#endif //is_mpi |
8 |
+ |
|
9 |
|
#include "Integrator.hpp" |
5 |
– |
#include "Thermo.hpp" |
6 |
– |
#include "ReadWrite.hpp" |
7 |
– |
#include "ForceFields.hpp" |
10 |
|
#include "simError.h" |
11 |
|
|
10 |
– |
extern "C"{ |
11 |
– |
|
12 |
– |
void v_constrain_a_( double &dt, int &n_atoms, double* mass, |
13 |
– |
double* Rx, double* Ry, double* Rz, |
14 |
– |
double* Vx, double* Vy, double* Vz, |
15 |
– |
double* Fx, double* Fy, double* Fz, |
16 |
– |
int &n_constrained, double *constr_sqr, |
17 |
– |
int* constr_i, int* constr_j, |
18 |
– |
double &box_x, double &box_y, double &box_z ); |
12 |
|
|
13 |
< |
void v_constrain_b_( double &dt, int &n_atoms, double* mass, |
14 |
< |
double* Rx, double* Ry, double* Rz, |
15 |
< |
double* Vx, double* Vy, double* Vz, |
23 |
< |
double* Fx, double* Fy, double* Fz, |
24 |
< |
double &Kinetic, |
25 |
< |
int &n_constrained, double *constr_sqr, |
26 |
< |
int* constr_i, int* constr_j, |
27 |
< |
double &box_x, double &box_y, double &box_z ); |
28 |
< |
} |
29 |
< |
|
30 |
< |
|
31 |
< |
|
32 |
< |
|
33 |
< |
Symplectic::Symplectic( SimInfo* the_entry_plug, ForceFields* the_ff ){ |
34 |
< |
entry_plug = the_entry_plug; |
13 |
> |
Symplectic::Symplectic( SimInfo* theInfo, ForceFields* the_ff ){ |
14 |
> |
|
15 |
> |
info = theInfo; |
16 |
|
myFF = the_ff; |
17 |
|
isFirst = 1; |
18 |
|
|
19 |
< |
molecules = entry_plug->molecules; |
20 |
< |
nMols = entry_plug->n_mol; |
19 |
> |
molecules = info->molecules; |
20 |
> |
nMols = info->n_mol; |
21 |
|
|
22 |
|
// give a little love back to the SimInfo object |
23 |
|
|
24 |
< |
if( entry_plug->the_integrator != NULL ) delete entry_plug->the_integrator; |
25 |
< |
entry_plug->the_integrator = this; |
24 |
> |
if( info->the_integrator != NULL ) delete info->the_integrator; |
25 |
> |
info->the_integrator = this; |
26 |
|
|
27 |
< |
// grab the masses |
27 |
> |
// check for constraints |
28 |
> |
|
29 |
> |
constrainedI = NULL; |
30 |
> |
constrainedJ = NULL; |
31 |
> |
constrainedDsqr = NULL; |
32 |
> |
nConstrained = 0; |
33 |
|
|
34 |
< |
mass = new double[entry_plug->n_atoms]; |
35 |
< |
for(int i = 0; i < entry_plug->n_atoms; i++){ |
50 |
< |
mass[i] = entry_plug->atoms[i]->getMass(); |
51 |
< |
} |
34 |
> |
checkConstraints(); |
35 |
> |
} |
36 |
|
|
37 |
+ |
Symplectic::~Symplectic() { |
38 |
|
|
39 |
< |
|
40 |
< |
// check for constraints |
39 |
> |
if( nConstrained ){ |
40 |
> |
delete[] constrainedI; |
41 |
> |
delete[] constrainedJ; |
42 |
> |
delete[] constrainedDsqr; |
43 |
> |
} |
44 |
> |
|
45 |
> |
} |
46 |
|
|
47 |
< |
is_constrained = 0; |
47 |
> |
void Symplectic::checkConstraints( void ){ |
48 |
|
|
49 |
+ |
|
50 |
+ |
isConstrained = 0; |
51 |
+ |
|
52 |
|
Constraint *temp_con; |
53 |
|
Constraint *dummy_plug; |
54 |
< |
temp_con = new Constraint[entry_plug->n_SRI]; |
55 |
< |
n_constrained = 0; |
54 |
> |
temp_con = new Constraint[info->n_SRI]; |
55 |
> |
nConstrained = 0; |
56 |
|
int constrained = 0; |
57 |
|
|
58 |
|
SRI** theArray; |
66 |
|
if(constrained){ |
67 |
|
|
68 |
|
dummy_plug = theArray[j]->get_constraint(); |
69 |
< |
temp_con[n_constrained].set_a( dummy_plug->get_a() ); |
70 |
< |
temp_con[n_constrained].set_b( dummy_plug->get_b() ); |
71 |
< |
temp_con[n_constrained].set_dsqr( dummy_plug->get_dsqr() ); |
69 |
> |
temp_con[nConstrained].set_a( dummy_plug->get_a() ); |
70 |
> |
temp_con[nConstrained].set_b( dummy_plug->get_b() ); |
71 |
> |
temp_con[nConstrained].set_dsqr( dummy_plug->get_dsqr() ); |
72 |
|
|
73 |
< |
n_constrained++; |
73 |
> |
nConstrained++; |
74 |
|
constrained = 0; |
75 |
|
} |
76 |
|
} |
83 |
|
if(constrained){ |
84 |
|
|
85 |
|
dummy_plug = theArray[j]->get_constraint(); |
86 |
< |
temp_con[n_constrained].set_a( dummy_plug->get_a() ); |
87 |
< |
temp_con[n_constrained].set_b( dummy_plug->get_b() ); |
88 |
< |
temp_con[n_constrained].set_dsqr( dummy_plug->get_dsqr() ); |
86 |
> |
temp_con[nConstrained].set_a( dummy_plug->get_a() ); |
87 |
> |
temp_con[nConstrained].set_b( dummy_plug->get_b() ); |
88 |
> |
temp_con[nConstrained].set_dsqr( dummy_plug->get_dsqr() ); |
89 |
|
|
90 |
< |
n_constrained++; |
90 |
> |
nConstrained++; |
91 |
|
constrained = 0; |
92 |
|
} |
93 |
|
} |
100 |
|
if(constrained){ |
101 |
|
|
102 |
|
dummy_plug = theArray[j]->get_constraint(); |
103 |
< |
temp_con[n_constrained].set_a( dummy_plug->get_a() ); |
104 |
< |
temp_con[n_constrained].set_b( dummy_plug->get_b() ); |
105 |
< |
temp_con[n_constrained].set_dsqr( dummy_plug->get_dsqr() ); |
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 |
< |
n_constrained++; |
107 |
> |
nConstrained++; |
108 |
|
constrained = 0; |
109 |
|
} |
110 |
|
} |
111 |
|
} |
112 |
|
|
113 |
< |
if(n_constrained > 0){ |
113 |
> |
if(nConstrained > 0){ |
114 |
|
|
115 |
< |
is_constrained = 1; |
116 |
< |
constrained_i = new int[n_constrained]; |
117 |
< |
constrained_j = new int[n_constrained]; |
118 |
< |
constrained_dsqr = new double[n_constrained]; |
115 |
> |
isConstrained = 1; |
116 |
> |
|
117 |
> |
if(constrainedI != NULL ) delete[] constrainedI; |
118 |
> |
if(constrainedJ != NULL ) delete[] constrainedJ; |
119 |
> |
if(constrainedDsqr != NULL ) delete[] constrainedDsqr; |
120 |
> |
|
121 |
> |
constrainedI = new int[nConstrained]; |
122 |
> |
constrainedJ = new int[nConstrained]; |
123 |
> |
constrainedDsqr = new double[nConstrained]; |
124 |
|
|
125 |
< |
for( int i = 0; i < n_constrained; i++){ |
125 |
> |
for( int i = 0; i < nConstrained; i++){ |
126 |
|
|
127 |
< |
/* add 1 to the index for the fortran arrays. */ |
128 |
< |
|
129 |
< |
constrained_i[i] = temp_con[i].get_a() + 1; |
132 |
< |
constrained_j[i] = temp_con[i].get_b() + 1; |
133 |
< |
constrained_dsqr[i] = temp_con[i].get_dsqr(); |
127 |
> |
constrainedI[i] = temp_con[i].get_a(); |
128 |
> |
constrainedJ[i] = temp_con[i].get_b(); |
129 |
> |
constrainedDsqr[i] = temp_con[i].get_dsqr(); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
|
delete[] temp_con; |
134 |
|
} |
135 |
|
|
140 |
– |
Symplectic::~Symplectic() { |
141 |
– |
|
142 |
– |
if( n_constrained ){ |
143 |
– |
delete[] constrained_i; |
144 |
– |
delete[] constrained_j; |
145 |
– |
delete[] constrained_dsqr; |
146 |
– |
} |
147 |
– |
|
148 |
– |
} |
136 |
|
|
150 |
– |
|
137 |
|
void Symplectic::integrate( void ){ |
138 |
|
|
153 |
– |
const double e_convert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2 |
154 |
– |
|
139 |
|
int i, j; // loop counters |
140 |
< |
int nAtoms = entry_plug->n_atoms; // the number of atoms |
140 |
> |
int nAtoms = info->n_atoms; // the number of atoms |
141 |
|
double kE = 0.0; // the kinetic energy |
142 |
|
double rot_kE; |
143 |
|
double trans_kE; |
145 |
|
double dt2; // half the dt |
146 |
|
|
147 |
|
double vx, vy, vz; // the velocities |
148 |
< |
// double vx2, vy2, vz2; // the square of the velocities |
148 |
> |
double vx2, vy2, vz2; // the square of the velocities |
149 |
|
double rx, ry, rz; // the postitions |
150 |
|
|
151 |
|
double ji[3]; // the body frame angular momentum |
153 |
|
double Tb[3]; // torque in the body frame |
154 |
|
double angle; // the angle through which to rotate the rotation matrix |
155 |
|
double A[3][3]; // the rotation matrix |
156 |
+ |
double press[9]; |
157 |
|
|
158 |
|
int time; |
159 |
|
|
160 |
< |
double dt = entry_plug->dt; |
161 |
< |
double runTime = entry_plug->run_time; |
162 |
< |
double sampleTime = entry_plug->sampleTime; |
163 |
< |
double statusTime = entry_plug->statusTime; |
164 |
< |
double thermalTime = entry_plug->thermalTime; |
160 |
> |
double dt = info->dt; |
161 |
> |
double runTime = info->run_time; |
162 |
> |
double sampleTime = info->sampleTime; |
163 |
> |
double statusTime = info->statusTime; |
164 |
> |
double thermalTime = info->thermalTime; |
165 |
|
|
166 |
|
int n_loops = (int)( runTime / dt ); |
167 |
|
int sample_n = (int)( sampleTime / dt ); |
168 |
|
int status_n = (int)( statusTime / dt ); |
169 |
|
int vel_n = (int)( thermalTime / dt ); |
170 |
|
|
171 |
< |
int calcPot; |
171 |
> |
int calcPot, calcStress; |
172 |
> |
int isError; |
173 |
|
|
174 |
< |
Thermo *tStats = new Thermo( entry_plug ); |
174 |
> |
tStats = new Thermo( info ); |
175 |
> |
e_out = new StatWriter( info ); |
176 |
> |
dump_out = new DumpWriter( info ); |
177 |
|
|
178 |
< |
StatWriter* e_out = new StatWriter( entry_plug ); |
191 |
< |
DumpWriter* dump_out = new DumpWriter( entry_plug ); |
192 |
< |
|
193 |
< |
Atom** atoms = entry_plug->atoms; |
178 |
> |
Atom** atoms = info->atoms; |
179 |
|
DirectionalAtom* dAtom; |
180 |
|
dt2 = 0.5 * dt; |
181 |
|
|
182 |
< |
// initialize the forces the before the first step |
182 |
> |
// initialize the forces before the first step |
183 |
|
|
184 |
< |
myFF->doForces(1,0); |
184 |
> |
myFF->doForces(1,1); |
185 |
|
|
186 |
< |
if( entry_plug->setTemp ){ |
186 |
> |
if( info->setTemp ){ |
187 |
|
|
188 |
|
tStats->velocitize(); |
189 |
|
} |
193 |
|
|
194 |
|
calcPot = 0; |
195 |
|
|
196 |
< |
if( n_constrained ){ |
196 |
> |
for( tl=0; tl<nLoops; tl++){ |
197 |
|
|
198 |
< |
double *Rx = new double[nAtoms]; |
199 |
< |
double *Ry = new double[nAtoms]; |
200 |
< |
double *Rz = new double[nAtoms]; |
198 |
> |
integrateStep( calcPot, calcStress ); |
199 |
> |
|
200 |
> |
time = tl + 1; |
201 |
|
|
202 |
< |
double *Vx = new double[nAtoms]; |
203 |
< |
double *Vy = new double[nAtoms]; |
204 |
< |
double *Vz = new double[nAtoms]; |
205 |
< |
|
206 |
< |
double *Fx = new double[nAtoms]; |
207 |
< |
double *Fy = new double[nAtoms]; |
208 |
< |
double *Fz = new double[nAtoms]; |
209 |
< |
|
202 |
> |
if( info->setTemp ){ |
203 |
> |
if( !(time % vel_n) ) tStats->velocitize(); |
204 |
> |
} |
205 |
> |
if( !(time % sample_n) ) dump_out->writeDump( time * dt ); |
206 |
> |
if( !((time+1) % status_n) ) { |
207 |
> |
calcPot = 1; |
208 |
> |
calcStress = 1; |
209 |
> |
} |
210 |
> |
if( !(time % status_n) ){ |
211 |
> |
e_out->writeStat( time * dt ); |
212 |
> |
calcPot = 0; |
213 |
> |
if (!strcasecmp(info->ensemble, "NPT")) calcStress = 1; |
214 |
> |
else calcStress = 0; |
215 |
> |
} |
216 |
|
|
217 |
< |
for( tl=0; tl < n_loops; tl++ ){ |
218 |
< |
|
228 |
< |
for( j=0; j<nAtoms; j++ ){ |
217 |
> |
|
218 |
> |
} |
219 |
|
|
220 |
< |
Rx[j] = atoms[j]->getX(); |
231 |
< |
Ry[j] = atoms[j]->getY(); |
232 |
< |
Rz[j] = atoms[j]->getZ(); |
220 |
> |
dump_out->writeFinal(); |
221 |
|
|
222 |
< |
Vx[j] = atoms[j]->get_vx(); |
223 |
< |
Vy[j] = atoms[j]->get_vy(); |
224 |
< |
Vz[j] = atoms[j]->get_vz(); |
222 |
> |
delete dump_out; |
223 |
> |
delete e_out; |
224 |
> |
} |
225 |
|
|
238 |
– |
Fx[j] = atoms[j]->getFx(); |
239 |
– |
Fy[j] = atoms[j]->getFy(); |
240 |
– |
Fz[j] = atoms[j]->getFz(); |
226 |
|
|
227 |
< |
} |
228 |
< |
|
229 |
< |
v_constrain_a_( dt, nAtoms, mass, Rx, Ry, Rz, Vx, Vy, Vz, |
230 |
< |
Fx, Fy, Fz, |
231 |
< |
n_constrained, constrained_dsqr, |
232 |
< |
constrained_i, constrained_j, |
233 |
< |
entry_plug->box_x, |
249 |
< |
entry_plug->box_y, |
250 |
< |
entry_plug->box_z ); |
251 |
< |
|
252 |
< |
for( j=0; j<nAtoms; j++ ){ |
227 |
> |
void Symplectic::moveA( void ){ |
228 |
> |
|
229 |
> |
int i,j,k; |
230 |
> |
int atomIndex, aMatIndex; |
231 |
> |
DirectionalAtom* dAtom; |
232 |
> |
double Tb[3]; |
233 |
> |
double ji[3]; |
234 |
|
|
235 |
< |
atoms[j]->setX(Rx[j]); |
236 |
< |
atoms[j]->setY(Ry[j]); |
237 |
< |
atoms[j]->setZ(Rz[j]); |
238 |
< |
|
239 |
< |
atoms[j]->set_vx(Vx[j]); |
240 |
< |
atoms[j]->set_vy(Vy[j]); |
241 |
< |
atoms[j]->set_vz(Vz[j]); |
261 |
< |
} |
235 |
> |
for( i=0; i<nAtoms; i++ ){ |
236 |
> |
atomIndex = i * 3; |
237 |
> |
aMatIndex = i * 9; |
238 |
> |
|
239 |
> |
// velocity half step |
240 |
> |
for( j=atomIndex; j<(atomIndex+3); j++ ) |
241 |
> |
vel[j] += ( dt2 * frc[j] / atoms[i]->getMass() ) * eConvert; |
242 |
|
|
243 |
+ |
// position whole step |
244 |
+ |
for( j=atomIndex; j<(atomIndex+3); j++ ) |
245 |
+ |
pos[j] += dt * vel[j]; |
246 |
|
|
247 |
< |
for( i=0; i<nAtoms; i++ ){ |
248 |
< |
if( atoms[i]->isDirectional() ){ |
249 |
< |
|
250 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
247 |
> |
|
248 |
> |
if( atoms[i]->isDirectional() ){ |
249 |
> |
|
250 |
> |
dAtom = (DirectionalAtom *)atoms[i]; |
251 |
|
|
252 |
< |
// get and convert the torque to body frame |
270 |
< |
|
271 |
< |
Tb[0] = dAtom->getTx(); |
272 |
< |
Tb[1] = dAtom->getTy(); |
273 |
< |
Tb[2] = dAtom->getTz(); |
274 |
< |
|
275 |
< |
dAtom->lab2Body( Tb ); |
276 |
< |
|
277 |
< |
// get the angular momentum, and propagate a half step |
278 |
< |
|
279 |
< |
ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * e_convert; |
280 |
< |
ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * e_convert; |
281 |
< |
ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * e_convert; |
282 |
< |
|
283 |
< |
// get the atom's rotation matrix |
284 |
< |
|
285 |
< |
A[0][0] = dAtom->getAxx(); |
286 |
< |
A[0][1] = dAtom->getAxy(); |
287 |
< |
A[0][2] = dAtom->getAxz(); |
288 |
< |
|
289 |
< |
A[1][0] = dAtom->getAyx(); |
290 |
< |
A[1][1] = dAtom->getAyy(); |
291 |
< |
A[1][2] = dAtom->getAyz(); |
292 |
< |
|
293 |
< |
A[2][0] = dAtom->getAzx(); |
294 |
< |
A[2][1] = dAtom->getAzy(); |
295 |
< |
A[2][2] = dAtom->getAzz(); |
296 |
< |
|
297 |
< |
|
298 |
< |
// use the angular velocities to propagate the rotation matrix a |
299 |
< |
// full time step |
300 |
< |
|
301 |
< |
|
302 |
< |
angle = dt2 * ji[0] / dAtom->getIxx(); |
303 |
< |
this->rotate( 1, 2, angle, ji, A ); // rotate about the x-axis |
304 |
< |
|
305 |
< |
angle = dt2 * ji[1] / dAtom->getIyy(); |
306 |
< |
this->rotate( 2, 0, angle, ji, A ); // rotate about the y-axis |
307 |
< |
|
308 |
< |
angle = dt * ji[2] / dAtom->getIzz(); |
309 |
< |
this->rotate( 0, 1, angle, ji, A ); // rotate about the z-axis |
310 |
< |
|
311 |
< |
angle = dt2 * ji[1] / dAtom->getIyy(); |
312 |
< |
this->rotate( 2, 0, angle, ji, A ); // rotate about the y-axis |
313 |
< |
|
314 |
< |
angle = dt2 * ji[0] / dAtom->getIxx(); |
315 |
< |
this->rotate( 1, 2, angle, ji, A ); // rotate about the x-axis |
316 |
< |
|
317 |
< |
|
318 |
< |
dAtom->setA( A ); |
319 |
< |
dAtom->setJx( ji[0] ); |
320 |
< |
dAtom->setJy( ji[1] ); |
321 |
< |
dAtom->setJz( ji[2] ); |
322 |
< |
} |
323 |
< |
} |
252 |
> |
// get and convert the torque to body frame |
253 |
|
|
254 |
< |
// calculate the forces |
255 |
< |
|
256 |
< |
myFF->doForces(calcPot, 0); |
328 |
< |
|
329 |
< |
// move b |
330 |
< |
|
331 |
< |
for( j=0; j<nAtoms; j++ ){ |
332 |
< |
|
333 |
< |
Rx[j] = atoms[j]->getX(); |
334 |
< |
Ry[j] = atoms[j]->getY(); |
335 |
< |
Rz[j] = atoms[j]->getZ(); |
336 |
< |
|
337 |
< |
Vx[j] = atoms[j]->get_vx(); |
338 |
< |
Vy[j] = atoms[j]->get_vy(); |
339 |
< |
Vz[j] = atoms[j]->get_vz(); |
340 |
< |
|
341 |
< |
Fx[j] = atoms[j]->getFx(); |
342 |
< |
Fy[j] = atoms[j]->getFy(); |
343 |
< |
Fz[j] = atoms[j]->getFz(); |
344 |
< |
} |
345 |
< |
|
346 |
< |
v_constrain_b_( dt, nAtoms, mass, Rx, Ry, Rz, Vx, Vy, Vz, |
347 |
< |
Fx, Fy, Fz, |
348 |
< |
kE, n_constrained, constrained_dsqr, |
349 |
< |
constrained_i, constrained_j, |
350 |
< |
entry_plug->box_x, |
351 |
< |
entry_plug->box_y, |
352 |
< |
entry_plug->box_z ); |
254 |
> |
Tb[0] = dAtom->getTx(); |
255 |
> |
Tb[1] = dAtom->getTy(); |
256 |
> |
Tb[2] = dAtom->getTz(); |
257 |
|
|
258 |
< |
for( j=0; j<nAtoms; j++ ){ |
355 |
< |
|
356 |
< |
atoms[j]->setX(Rx[j]); |
357 |
< |
atoms[j]->setY(Ry[j]); |
358 |
< |
atoms[j]->setZ(Rz[j]); |
359 |
< |
|
360 |
< |
atoms[j]->set_vx(Vx[j]); |
361 |
< |
atoms[j]->set_vy(Vy[j]); |
362 |
< |
atoms[j]->set_vz(Vz[j]); |
363 |
< |
} |
258 |
> |
dAtom->lab2Body( Tb ); |
259 |
|
|
260 |
< |
for( i=0; i< nAtoms; i++ ){ |
366 |
< |
|
367 |
< |
if( atoms[i]->isDirectional() ){ |
368 |
< |
|
369 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
370 |
< |
|
371 |
< |
// get and convert the torque to body frame |
372 |
< |
|
373 |
< |
Tb[0] = dAtom->getTx(); |
374 |
< |
Tb[1] = dAtom->getTy(); |
375 |
< |
Tb[2] = dAtom->getTz(); |
376 |
< |
|
377 |
< |
dAtom->lab2Body( Tb ); |
378 |
< |
|
379 |
< |
// get the angular momentum, and complete the angular momentum |
380 |
< |
// half step |
381 |
< |
|
382 |
< |
ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * e_convert; |
383 |
< |
ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * e_convert; |
384 |
< |
ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * e_convert; |
385 |
< |
|
386 |
< |
dAtom->setJx( ji[0] ); |
387 |
< |
dAtom->setJy( ji[1] ); |
388 |
< |
dAtom->setJz( ji[2] ); |
389 |
< |
} |
390 |
< |
} |
391 |
< |
|
392 |
< |
time = tl + 1; |
260 |
> |
// get the angular momentum, and propagate a half step |
261 |
|
|
262 |
< |
if( entry_plug->setTemp ){ |
263 |
< |
if( !(time % vel_n) ) tStats->velocitize(); |
264 |
< |
} |
265 |
< |
if( !(time % sample_n) ) dump_out->writeDump( time * dt ); |
266 |
< |
if( !((time+1) % status_n) ) calcPot = 1; |
267 |
< |
if( !(time % status_n) ){ e_out->writeStat( time * dt ); calcPot = 0; } |
262 |
> |
ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert; |
263 |
> |
ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert; |
264 |
> |
ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert; |
265 |
> |
|
266 |
> |
// use the angular velocities to propagate the rotation matrix a |
267 |
> |
// full time step |
268 |
> |
|
269 |
> |
// rotate about the x-axis |
270 |
> |
angle = dt2 * ji[0] / dAtom->getIxx(); |
271 |
> |
this->rotate( 1, 2, angle, ji, &aMat[aMatIndex] ); |
272 |
> |
|
273 |
> |
// rotate about the y-axis |
274 |
> |
angle = dt2 * ji[1] / dAtom->getIyy(); |
275 |
> |
this->rotate( 2, 0, angle, ji, &aMat[aMatIndex] ); |
276 |
> |
|
277 |
> |
// rotate about the z-axis |
278 |
> |
angle = dt * ji[2] / dAtom->getIzz(); |
279 |
> |
this->rotate( 0, 1, angle, ji, &aMat[aMatIndex] ); |
280 |
> |
|
281 |
> |
// rotate about the y-axis |
282 |
> |
angle = dt2 * ji[1] / dAtom->getIyy(); |
283 |
> |
this->rotate( 2, 0, angle, ji, &aMat[aMatIndex] ); |
284 |
> |
|
285 |
> |
// rotate about the x-axis |
286 |
> |
angle = dt2 * ji[0] / dAtom->getIxx(); |
287 |
> |
this->rotate( 1, 2, angle, ji, &aMat[aMatIndex] ); |
288 |
> |
|
289 |
> |
dAtom->setJx( ji[0] ); |
290 |
> |
dAtom->setJy( ji[1] ); |
291 |
> |
dAtom->setJz( ji[2] ); |
292 |
|
} |
293 |
+ |
|
294 |
|
} |
295 |
< |
else{ |
295 |
> |
} |
296 |
|
|
297 |
< |
for( tl=0; tl<n_loops; tl++ ){ |
297 |
> |
|
298 |
> |
void Integrator::moveB( void ){ |
299 |
> |
int i,j,k; |
300 |
> |
int atomIndex; |
301 |
> |
DirectionalAtom* dAtom; |
302 |
> |
double Tb[3]; |
303 |
> |
double ji[3]; |
304 |
> |
|
305 |
> |
for( i=0; i<nAtoms; i++ ){ |
306 |
> |
atomIndex = i * 3; |
307 |
> |
|
308 |
> |
// velocity half step |
309 |
> |
for( j=atomIndex; j<(atomIndex+3); j++ ) |
310 |
> |
vel[j] += ( dt2 * frc[j] / atoms[i]->getMass() ) * eConvert; |
311 |
> |
|
312 |
> |
if( atoms[i]->isDirectional() ){ |
313 |
|
|
314 |
< |
kE = 0.0; |
407 |
< |
rot_kE= 0.0; |
408 |
< |
trans_kE = 0.0; |
314 |
> |
dAtom = (DirectionalAtom *)atoms[i]; |
315 |
|
|
316 |
< |
for( i=0; i<nAtoms; i++ ){ |
411 |
< |
|
412 |
< |
// velocity half step |
413 |
< |
|
414 |
< |
vx = atoms[i]->get_vx() + |
415 |
< |
( dt2 * atoms[i]->getFx() / atoms[i]->getMass() ) * e_convert; |
416 |
< |
vy = atoms[i]->get_vy() + |
417 |
< |
( dt2 * atoms[i]->getFy() / atoms[i]->getMass() ) * e_convert; |
418 |
< |
vz = atoms[i]->get_vz() + |
419 |
< |
( dt2 * atoms[i]->getFz() / atoms[i]->getMass() ) * e_convert; |
420 |
< |
|
421 |
< |
// position whole step |
422 |
< |
|
423 |
< |
rx = atoms[i]->getX() + dt * vx; |
424 |
< |
ry = atoms[i]->getY() + dt * vy; |
425 |
< |
rz = atoms[i]->getZ() + dt * vz; |
426 |
< |
|
427 |
< |
atoms[i]->setX( rx ); |
428 |
< |
atoms[i]->setY( ry ); |
429 |
< |
atoms[i]->setZ( rz ); |
430 |
< |
|
431 |
< |
atoms[i]->set_vx( vx ); |
432 |
< |
atoms[i]->set_vy( vy ); |
433 |
< |
atoms[i]->set_vz( vz ); |
434 |
< |
|
435 |
< |
if( atoms[i]->isDirectional() ){ |
436 |
< |
|
437 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
438 |
< |
|
439 |
< |
// get and convert the torque to body frame |
440 |
< |
|
441 |
< |
Tb[0] = dAtom->getTx(); |
442 |
< |
Tb[1] = dAtom->getTy(); |
443 |
< |
Tb[2] = dAtom->getTz(); |
444 |
< |
|
445 |
< |
dAtom->lab2Body( Tb ); |
446 |
< |
|
447 |
< |
// get the angular momentum, and propagate a half step |
448 |
< |
|
449 |
< |
ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * e_convert; |
450 |
< |
ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * e_convert; |
451 |
< |
ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * e_convert; |
452 |
< |
|
453 |
< |
// get the atom's rotation matrix |
454 |
< |
|
455 |
< |
A[0][0] = dAtom->getAxx(); |
456 |
< |
A[0][1] = dAtom->getAxy(); |
457 |
< |
A[0][2] = dAtom->getAxz(); |
458 |
< |
|
459 |
< |
A[1][0] = dAtom->getAyx(); |
460 |
< |
A[1][1] = dAtom->getAyy(); |
461 |
< |
A[1][2] = dAtom->getAyz(); |
462 |
< |
|
463 |
< |
A[2][0] = dAtom->getAzx(); |
464 |
< |
A[2][1] = dAtom->getAzy(); |
465 |
< |
A[2][2] = dAtom->getAzz(); |
466 |
< |
|
467 |
< |
|
468 |
< |
// use the angular velocities to propagate the rotation matrix a |
469 |
< |
// full time step |
470 |
< |
|
471 |
< |
|
472 |
< |
angle = dt2 * ji[0] / dAtom->getIxx(); |
473 |
< |
this->rotate( 1, 2, angle, ji, A ); // rotate about the x-axis |
474 |
< |
|
475 |
< |
angle = dt2 * ji[1] / dAtom->getIyy(); |
476 |
< |
this->rotate( 2, 0, angle, ji, A ); // rotate about the y-axis |
477 |
< |
|
478 |
< |
angle = dt * ji[2] / dAtom->getIzz(); |
479 |
< |
this->rotate( 0, 1, angle, ji, A ); // rotate about the z-axis |
480 |
< |
|
481 |
< |
angle = dt2 * ji[1] / dAtom->getIyy(); |
482 |
< |
this->rotate( 2, 0, angle, ji, A ); // rotate about the y-axis |
483 |
< |
|
484 |
< |
angle = dt2 * ji[0] / dAtom->getIxx(); |
485 |
< |
this->rotate( 1, 2, angle, ji, A ); // rotate about the x-axis |
486 |
< |
|
487 |
< |
|
488 |
< |
dAtom->setA( A ); |
489 |
< |
dAtom->setJx( ji[0] ); |
490 |
< |
dAtom->setJy( ji[1] ); |
491 |
< |
dAtom->setJz( ji[2] ); |
492 |
< |
} |
493 |
< |
} |
316 |
> |
// get and convert the torque to body frame |
317 |
|
|
318 |
< |
// calculate the forces |
318 |
> |
Tb[0] = dAtom->getTx(); |
319 |
> |
Tb[1] = dAtom->getTy(); |
320 |
> |
Tb[2] = dAtom->getTz(); |
321 |
|
|
322 |
< |
myFF->doForces(calcPot,0); |
322 |
> |
dAtom->lab2Body( Tb ); |
323 |
|
|
324 |
< |
for( i=0; i< nAtoms; i++ ){ |
325 |
< |
|
501 |
< |
// complete the velocity half step |
502 |
< |
|
503 |
< |
vx = atoms[i]->get_vx() + |
504 |
< |
( dt2 * atoms[i]->getFx() / atoms[i]->getMass() ) * e_convert; |
505 |
< |
vy = atoms[i]->get_vy() + |
506 |
< |
( dt2 * atoms[i]->getFy() / atoms[i]->getMass() ) * e_convert; |
507 |
< |
vz = atoms[i]->get_vz() + |
508 |
< |
( dt2 * atoms[i]->getFz() / atoms[i]->getMass() ) * e_convert; |
509 |
< |
|
510 |
< |
atoms[i]->set_vx( vx ); |
511 |
< |
atoms[i]->set_vy( vy ); |
512 |
< |
atoms[i]->set_vz( vz ); |
513 |
< |
|
514 |
< |
// vx2 = vx * vx; |
515 |
< |
// vy2 = vy * vy; |
516 |
< |
// vz2 = vz * vz; |
517 |
< |
|
518 |
< |
if( atoms[i]->isDirectional() ){ |
519 |
< |
|
520 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
521 |
< |
|
522 |
< |
// get and convert the torque to body frame |
523 |
< |
|
524 |
< |
Tb[0] = dAtom->getTx(); |
525 |
< |
Tb[1] = dAtom->getTy(); |
526 |
< |
Tb[2] = dAtom->getTz(); |
527 |
< |
|
528 |
< |
dAtom->lab2Body( Tb ); |
529 |
< |
|
530 |
< |
// get the angular momentum, and complete the angular momentum |
531 |
< |
// half step |
532 |
< |
|
533 |
< |
ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * e_convert; |
534 |
< |
ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * e_convert; |
535 |
< |
ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * e_convert; |
536 |
< |
|
537 |
< |
jx2 = ji[0] * ji[0]; |
538 |
< |
jy2 = ji[1] * ji[1]; |
539 |
< |
jz2 = ji[2] * ji[2]; |
540 |
< |
|
541 |
< |
rot_kE += (jx2 / dAtom->getIxx()) + (jy2 / dAtom->getIyy()) |
542 |
< |
+ (jz2 / dAtom->getIzz()); |
543 |
< |
|
544 |
< |
dAtom->setJx( ji[0] ); |
545 |
< |
dAtom->setJy( ji[1] ); |
546 |
< |
dAtom->setJz( ji[2] ); |
547 |
< |
} |
548 |
< |
} |
324 |
> |
// get the angular momentum, and complete the angular momentum |
325 |
> |
// half step |
326 |
|
|
327 |
< |
time = tl + 1; |
327 |
> |
ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert; |
328 |
> |
ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert; |
329 |
> |
ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert; |
330 |
|
|
331 |
< |
if( entry_plug->setTemp ){ |
332 |
< |
if( !(time % vel_n) ) tStats->velocitize(); |
333 |
< |
} |
334 |
< |
if( !(time % sample_n) ) dump_out->writeDump( time * dt ); |
335 |
< |
if( !((time+1) % status_n) ) calcPot = 1; |
336 |
< |
if( !(time % status_n) ){ e_out->writeStat( time * dt ); calcPot = 0; } |
331 |
> |
jx2 = ji[0] * ji[0]; |
332 |
> |
jy2 = ji[1] * ji[1]; |
333 |
> |
jz2 = ji[2] * ji[2]; |
334 |
> |
|
335 |
> |
dAtom->setJx( ji[0] ); |
336 |
> |
dAtom->setJy( ji[1] ); |
337 |
> |
dAtom->setJz( ji[2] ); |
338 |
|
} |
339 |
|
} |
340 |
|
|
341 |
< |
dump_out->writeFinal(); |
341 |
> |
} |
342 |
|
|
343 |
< |
delete dump_out; |
344 |
< |
delete e_out; |
343 |
> |
|
344 |
> |
void Integrator::constrainA(){ |
345 |
> |
|
346 |
> |
|
347 |
> |
|
348 |
> |
|
349 |
|
} |
350 |
|
|
351 |
+ |
|
352 |
+ |
|
353 |
+ |
|
354 |
+ |
|
355 |
+ |
|
356 |
+ |
|
357 |
+ |
|
358 |
+ |
|
359 |
|
void Symplectic::rotate( int axes1, int axes2, double angle, double ji[3], |
360 |
|
double A[3][3] ){ |
361 |
|
|