1 |
< |
#include <cstdlib> |
2 |
< |
#include <cstring> |
3 |
< |
#include <cmath> |
1 |
> |
#include <stdlib.h> |
2 |
> |
#include <string.h> |
3 |
> |
#include <math.h> |
4 |
|
|
5 |
|
#include <iostream> |
6 |
|
using namespace std; |
26 |
|
SimInfo::SimInfo(){ |
27 |
|
excludes = NULL; |
28 |
|
n_constraints = 0; |
29 |
+ |
nZconstraints = 0; |
30 |
|
n_oriented = 0; |
31 |
|
n_dipoles = 0; |
32 |
|
ndf = 0; |
33 |
|
ndfRaw = 0; |
34 |
+ |
nZconstraints = 0; |
35 |
|
the_integrator = NULL; |
36 |
|
setTemp = 0; |
37 |
|
thermalTime = 0.0; |
39 |
|
rCut = 0.0; |
40 |
|
ecr = 0.0; |
41 |
|
est = 0.0; |
40 |
– |
oldEcr = 0.0; |
41 |
– |
oldRcut = 0.0; |
42 |
|
|
43 |
< |
haveOrigRcut = 0; |
44 |
< |
haveOrigEcr = 0; |
43 |
> |
haveRcut = 0; |
44 |
> |
haveEcr = 0; |
45 |
|
boxIsInit = 0; |
46 |
|
|
47 |
< |
|
47 |
> |
resetTime = 1e99; |
48 |
|
|
49 |
+ |
orthoTolerance = 1E-6; |
50 |
+ |
useInitXSstate = true; |
51 |
+ |
|
52 |
|
usePBC = 0; |
53 |
|
useLJ = 0; |
54 |
|
useSticky = 0; |
57 |
|
useGB = 0; |
58 |
|
useEAM = 0; |
59 |
|
|
60 |
+ |
myConfiguration = new SimState(); |
61 |
+ |
|
62 |
|
wrapMeSimInfo( this ); |
63 |
|
} |
64 |
|
|
65 |
+ |
|
66 |
|
SimInfo::~SimInfo(){ |
67 |
|
|
68 |
+ |
delete myConfiguration; |
69 |
+ |
|
70 |
|
map<string, GenericData*>::iterator i; |
71 |
|
|
72 |
|
for(i = properties.begin(); i != properties.end(); i++) |
73 |
|
delete (*i).second; |
74 |
< |
|
67 |
< |
|
74 |
> |
|
75 |
|
} |
76 |
|
|
77 |
|
void SimInfo::setBox(double newBox[3]) { |
92 |
|
|
93 |
|
void SimInfo::setBoxM( double theBox[3][3] ){ |
94 |
|
|
95 |
< |
int i, j, status; |
89 |
< |
double smallestBoxL, maxCutoff; |
95 |
> |
int i, j; |
96 |
|
double FortranHmat[9]; // to preserve compatibility with Fortran the |
97 |
|
// ordering in the array is as follows: |
98 |
|
// [ 0 3 6 ] |
100 |
|
// [ 2 5 8 ] |
101 |
|
double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
102 |
|
|
97 |
– |
|
103 |
|
if( !boxIsInit ) boxIsInit = 1; |
104 |
|
|
105 |
|
for(i=0; i < 3; i++) |
143 |
|
|
144 |
|
void SimInfo::calcHmatInv( void ) { |
145 |
|
|
146 |
+ |
int oldOrtho; |
147 |
|
int i,j; |
148 |
|
double smallDiag; |
149 |
|
double tol; |
151 |
|
|
152 |
|
invertMat3( Hmat, HmatInv ); |
153 |
|
|
148 |
– |
// Check the inverse to make sure it is sane: |
149 |
– |
|
150 |
– |
matMul3( Hmat, HmatInv, sanity ); |
151 |
– |
|
154 |
|
// check to see if Hmat is orthorhombic |
155 |
|
|
156 |
< |
smallDiag = Hmat[0][0]; |
155 |
< |
if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
156 |
< |
if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
157 |
< |
tol = smallDiag * 1E-6; |
156 |
> |
oldOrtho = orthoRhombic; |
157 |
|
|
158 |
+ |
smallDiag = fabs(Hmat[0][0]); |
159 |
+ |
if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); |
160 |
+ |
if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); |
161 |
+ |
tol = smallDiag * orthoTolerance; |
162 |
+ |
|
163 |
|
orthoRhombic = 1; |
164 |
|
|
165 |
|
for (i = 0; i < 3; i++ ) { |
166 |
|
for (j = 0 ; j < 3; j++) { |
167 |
|
if (i != j) { |
168 |
|
if (orthoRhombic) { |
169 |
< |
if (Hmat[i][j] >= tol) orthoRhombic = 0; |
169 |
> |
if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
170 |
|
} |
171 |
|
} |
172 |
|
} |
173 |
|
} |
174 |
+ |
|
175 |
+ |
if( oldOrtho != orthoRhombic ){ |
176 |
+ |
|
177 |
+ |
if( orthoRhombic ){ |
178 |
+ |
sprintf( painCave.errMsg, |
179 |
+ |
"Hmat is switching from Non-Orthorhombic to OrthoRhombic\n" |
180 |
+ |
" If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
181 |
+ |
orthoTolerance); |
182 |
+ |
simError(); |
183 |
+ |
} |
184 |
+ |
else { |
185 |
+ |
sprintf( painCave.errMsg, |
186 |
+ |
"Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" |
187 |
+ |
" If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
188 |
+ |
orthoTolerance); |
189 |
+ |
simError(); |
190 |
+ |
} |
191 |
+ |
} |
192 |
|
} |
193 |
|
|
194 |
|
double SimInfo::matDet3(double a[3][3]) { |
295 |
|
<< "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; |
296 |
|
} |
297 |
|
|
298 |
+ |
|
299 |
+ |
void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){ |
300 |
+ |
|
301 |
+ |
out[0] = a[1] * b[2] - a[2] * b[1]; |
302 |
+ |
out[1] = a[2] * b[0] - a[0] * b[2] ; |
303 |
+ |
out[2] = a[0] * b[1] - a[1] * b[0]; |
304 |
+ |
|
305 |
+ |
} |
306 |
+ |
|
307 |
+ |
double SimInfo::dotProduct3(double a[3], double b[3]){ |
308 |
+ |
return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2]; |
309 |
+ |
} |
310 |
+ |
|
311 |
+ |
double SimInfo::length3(double a[3]){ |
312 |
+ |
return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); |
313 |
+ |
} |
314 |
+ |
|
315 |
|
void SimInfo::calcBoxL( void ){ |
316 |
|
|
317 |
|
double dx, dy, dz, dsq; |
279 |
– |
int i; |
318 |
|
|
319 |
|
// boxVol = Determinant of Hmat |
320 |
|
|
325 |
|
dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; |
326 |
|
dsq = dx*dx + dy*dy + dz*dz; |
327 |
|
boxL[0] = sqrt( dsq ); |
328 |
< |
maxCutoff = 0.5 * boxL[0]; |
328 |
> |
//maxCutoff = 0.5 * boxL[0]; |
329 |
|
|
330 |
|
// boxLy |
331 |
|
|
332 |
|
dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; |
333 |
|
dsq = dx*dx + dy*dy + dz*dz; |
334 |
|
boxL[1] = sqrt( dsq ); |
335 |
< |
if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
335 |
> |
//if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
336 |
|
|
337 |
+ |
|
338 |
|
// boxLz |
339 |
|
|
340 |
|
dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; |
341 |
|
dsq = dx*dx + dy*dy + dz*dz; |
342 |
|
boxL[2] = sqrt( dsq ); |
343 |
< |
if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
343 |
> |
//if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
344 |
> |
|
345 |
> |
//calculate the max cutoff |
346 |
> |
maxCutoff = calcMaxCutOff(); |
347 |
|
|
348 |
|
checkCutOffs(); |
349 |
|
|
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
+ |
double SimInfo::calcMaxCutOff(){ |
354 |
+ |
|
355 |
+ |
double ri[3], rj[3], rk[3]; |
356 |
+ |
double rij[3], rjk[3], rki[3]; |
357 |
+ |
double minDist; |
358 |
+ |
|
359 |
+ |
ri[0] = Hmat[0][0]; |
360 |
+ |
ri[1] = Hmat[1][0]; |
361 |
+ |
ri[2] = Hmat[2][0]; |
362 |
+ |
|
363 |
+ |
rj[0] = Hmat[0][1]; |
364 |
+ |
rj[1] = Hmat[1][1]; |
365 |
+ |
rj[2] = Hmat[2][1]; |
366 |
+ |
|
367 |
+ |
rk[0] = Hmat[0][2]; |
368 |
+ |
rk[1] = Hmat[1][2]; |
369 |
+ |
rk[2] = Hmat[2][2]; |
370 |
+ |
|
371 |
+ |
crossProduct3(ri,rj, rij); |
372 |
+ |
distXY = dotProduct3(rk,rij) / length3(rij); |
373 |
+ |
|
374 |
+ |
crossProduct3(rj,rk, rjk); |
375 |
+ |
distYZ = dotProduct3(ri,rjk) / length3(rjk); |
376 |
+ |
|
377 |
+ |
crossProduct3(rk,ri, rki); |
378 |
+ |
distZX = dotProduct3(rj,rki) / length3(rki); |
379 |
+ |
|
380 |
+ |
minDist = min(min(distXY, distYZ), distZX); |
381 |
+ |
return minDist/2; |
382 |
+ |
|
383 |
+ |
} |
384 |
+ |
|
385 |
|
void SimInfo::wrapVector( double thePos[3] ){ |
386 |
|
|
387 |
< |
int i, j, k; |
387 |
> |
int i; |
388 |
|
double scaled[3]; |
389 |
|
|
390 |
|
if( !orthoRhombic ){ |
422 |
|
|
423 |
|
|
424 |
|
int SimInfo::getNDF(){ |
425 |
< |
int ndf_local, ndf; |
425 |
> |
int ndf_local; |
426 |
|
|
427 |
|
ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; |
428 |
|
|
432 |
|
ndf = ndf_local; |
433 |
|
#endif |
434 |
|
|
435 |
< |
ndf = ndf - 3; |
435 |
> |
ndf = ndf - 3 - nZconstraints; |
436 |
|
|
437 |
|
return ndf; |
438 |
|
} |
439 |
|
|
440 |
|
int SimInfo::getNDFraw() { |
441 |
< |
int ndfRaw_local, ndfRaw; |
441 |
> |
int ndfRaw_local; |
442 |
|
|
443 |
|
// Raw degrees of freedom that we have to set |
444 |
|
ndfRaw_local = 3 * n_atoms + 3 * n_oriented; |
451 |
|
|
452 |
|
return ndfRaw; |
453 |
|
} |
454 |
< |
|
454 |
> |
|
455 |
> |
int SimInfo::getNDFtranslational() { |
456 |
> |
int ndfTrans_local; |
457 |
> |
|
458 |
> |
ndfTrans_local = 3 * n_atoms - n_constraints; |
459 |
> |
|
460 |
> |
#ifdef IS_MPI |
461 |
> |
MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
462 |
> |
#else |
463 |
> |
ndfTrans = ndfTrans_local; |
464 |
> |
#endif |
465 |
> |
|
466 |
> |
ndfTrans = ndfTrans - 3 - nZconstraints; |
467 |
> |
|
468 |
> |
return ndfTrans; |
469 |
> |
} |
470 |
> |
|
471 |
|
void SimInfo::refreshSim(){ |
472 |
|
|
473 |
|
simtype fInfo; |
523 |
|
|
524 |
|
this->ndf = this->getNDF(); |
525 |
|
this->ndfRaw = this->getNDFraw(); |
526 |
< |
|
526 |
> |
this->ndfTrans = this->getNDFtranslational(); |
527 |
|
} |
528 |
|
|
529 |
+ |
void SimInfo::setDefaultRcut( double theRcut ){ |
530 |
|
|
531 |
< |
void SimInfo::setRcut( double theRcut ){ |
531 |
> |
haveRcut = 1; |
532 |
> |
rCut = theRcut; |
533 |
|
|
534 |
< |
if( !haveOrigRcut ){ |
443 |
< |
haveOrigRcut = 1; |
444 |
< |
origRcut = theRcut; |
445 |
< |
} |
534 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
535 |
|
|
536 |
< |
rCut = theRcut; |
448 |
< |
checkCutOffs(); |
536 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
537 |
|
} |
538 |
|
|
539 |
< |
void SimInfo::setEcr( double theEcr ){ |
539 |
> |
void SimInfo::setDefaultEcr( double theEcr ){ |
540 |
|
|
541 |
< |
if( !haveOrigEcr ){ |
542 |
< |
haveOrigEcr = 1; |
543 |
< |
origEcr = theEcr; |
456 |
< |
} |
541 |
> |
haveEcr = 1; |
542 |
> |
|
543 |
> |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
544 |
|
|
545 |
|
ecr = theEcr; |
546 |
< |
checkCutOffs(); |
546 |
> |
|
547 |
> |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
548 |
|
} |
549 |
|
|
550 |
< |
void SimInfo::setEcr( double theEcr, double theEst ){ |
550 |
> |
void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
551 |
|
|
552 |
|
est = theEst; |
553 |
< |
setEcr( theEcr ); |
553 |
> |
setDefaultEcr( theEcr ); |
554 |
|
} |
555 |
|
|
556 |
|
|
557 |
|
void SimInfo::checkCutOffs( void ){ |
558 |
< |
|
471 |
< |
int cutChanged = 0; |
472 |
< |
|
473 |
< |
|
474 |
< |
|
558 |
> |
|
559 |
|
if( boxIsInit ){ |
560 |
|
|
561 |
|
//we need to check cutOffs against the box |
562 |
< |
|
563 |
< |
if(( maxCutoff > rCut )&&(usePBC)){ |
564 |
< |
if( rCut < origRcut ){ |
565 |
< |
rCut = origRcut; |
566 |
< |
if (rCut > maxCutoff) rCut = maxCutoff; |
567 |
< |
|
568 |
< |
sprintf( painCave.errMsg, |
569 |
< |
"New Box size is setting the long range cutoff radius " |
486 |
< |
"to %lf\n", |
487 |
< |
rCut ); |
488 |
< |
painCave.isFatal = 0; |
489 |
< |
simError(); |
490 |
< |
} |
562 |
> |
|
563 |
> |
if( rCut > maxCutoff ){ |
564 |
> |
sprintf( painCave.errMsg, |
565 |
> |
"Box size is too small for the long range cutoff radius, " |
566 |
> |
"%lf, at time %lf\n", |
567 |
> |
rCut, currentTime ); |
568 |
> |
painCave.isFatal = 1; |
569 |
> |
simError(); |
570 |
|
} |
571 |
< |
|
572 |
< |
if( maxCutoff > ecr ){ |
573 |
< |
if( ecr < origEcr ){ |
495 |
< |
rCut = origEcr; |
496 |
< |
if (ecr > maxCutoff) ecr = maxCutoff; |
497 |
< |
|
571 |
> |
|
572 |
> |
if( haveEcr ){ |
573 |
> |
if( ecr > maxCutoff ){ |
574 |
|
sprintf( painCave.errMsg, |
575 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
576 |
< |
"to %lf\n", |
577 |
< |
ecr ); |
578 |
< |
painCave.isFatal = 0; |
575 |
> |
"Box size is too small for the electrostatic cutoff radius, " |
576 |
> |
"%lf, at time %lf\n", |
577 |
> |
ecr, currentTime ); |
578 |
> |
painCave.isFatal = 1; |
579 |
|
simError(); |
580 |
|
} |
581 |
|
} |
582 |
< |
|
583 |
< |
|
584 |
< |
if ((rCut > maxCutoff)&&(usePBC)) { |
585 |
< |
sprintf( painCave.errMsg, |
586 |
< |
"New Box size is setting the long range cutoff radius " |
587 |
< |
"to %lf\n", |
512 |
< |
maxCutoff ); |
513 |
< |
painCave.isFatal = 0; |
514 |
< |
simError(); |
515 |
< |
rCut = maxCutoff; |
516 |
< |
} |
517 |
< |
|
518 |
< |
if( ecr > maxCutoff){ |
519 |
< |
sprintf( painCave.errMsg, |
520 |
< |
"New Box size is setting the electrostaticCutoffRadius " |
521 |
< |
"to %lf\n", |
522 |
< |
maxCutoff ); |
523 |
< |
painCave.isFatal = 0; |
524 |
< |
simError(); |
525 |
< |
ecr = maxCutoff; |
526 |
< |
} |
527 |
< |
|
528 |
< |
|
582 |
> |
} else { |
583 |
> |
// initialize this stuff before using it, OK? |
584 |
> |
sprintf( painCave.errMsg, |
585 |
> |
"Trying to check cutoffs without a box. Be smarter.\n" ); |
586 |
> |
painCave.isFatal = 1; |
587 |
> |
simError(); |
588 |
|
} |
530 |
– |
|
531 |
– |
|
532 |
– |
if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; |
533 |
– |
|
534 |
– |
// rlist is the 1.0 plus max( rcut, ecr ) |
589 |
|
|
536 |
– |
( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
537 |
– |
|
538 |
– |
if( cutChanged ){ |
539 |
– |
|
540 |
– |
notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
541 |
– |
} |
542 |
– |
|
543 |
– |
oldEcr = ecr; |
544 |
– |
oldRcut = rCut; |
590 |
|
} |
591 |
|
|
592 |
|
void SimInfo::addProperty(GenericData* prop){ |
636 |
|
return result; |
637 |
|
} |
638 |
|
|
639 |
+ |
double SimInfo::matTrace3(double m[3][3]){ |
640 |
+ |
double trace; |
641 |
+ |
trace = m[0][0] + m[1][1] + m[2][2]; |
642 |
|
|
643 |
+ |
return trace; |
644 |
+ |
} |