# | Line 1 | Line 1 | |
---|---|---|
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; | |
# | Line 20 | Line 20 | inline double roundMe( double x ){ | |
20 | return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); | |
21 | } | |
22 | ||
23 | + | inline double min( double a, double b ){ |
24 | + | return (a < b ) ? a : b; |
25 | + | } |
26 | ||
27 | SimInfo* currentInfo; | |
28 | ||
# | Line 37 | Line 40 | SimInfo::SimInfo(){ | |
40 | thermalTime = 0.0; | |
41 | currentTime = 0.0; | |
42 | rCut = 0.0; | |
40 | – | origRcut = -1.0; |
43 | ecr = 0.0; | |
42 | – | origEcr = -1.0; |
44 | est = 0.0; | |
44 | – | oldEcr = 0.0; |
45 | – | oldRcut = 0.0; |
45 | ||
46 | < | haveOrigRcut = 0; |
47 | < | haveOrigEcr = 0; |
46 | > | haveRcut = 0; |
47 | > | haveEcr = 0; |
48 | boxIsInit = 0; | |
49 | ||
50 | < | |
50 | > | resetTime = 1e99; |
51 | ||
52 | + | orthoTolerance = 1E-6; |
53 | + | useInitXSstate = true; |
54 | + | |
55 | usePBC = 0; | |
56 | useLJ = 0; | |
57 | useSticky = 0; | |
# | Line 93 | Line 95 | void SimInfo::setBoxM( double theBox[3][3] ){ | |
95 | ||
96 | void SimInfo::setBoxM( double theBox[3][3] ){ | |
97 | ||
98 | < | int i, j, status; |
97 | < | double smallestBoxL, maxCutoff; |
98 | > | int i, j; |
99 | double FortranHmat[9]; // to preserve compatibility with Fortran the | |
100 | // ordering in the array is as follows: | |
101 | // [ 0 3 6 ] | |
# | Line 102 | Line 103 | void SimInfo::setBoxM( double theBox[3][3] ){ | |
103 | // [ 2 5 8 ] | |
104 | double FortranHmatInv[9]; // the inverted Hmat (for Fortran); | |
105 | ||
105 | – | |
106 | if( !boxIsInit ) boxIsInit = 1; | |
107 | ||
108 | for(i=0; i < 3; i++) | |
# | Line 146 | Line 146 | void SimInfo::calcHmatInv( void ) { | |
146 | ||
147 | void SimInfo::calcHmatInv( void ) { | |
148 | ||
149 | + | int oldOrtho; |
150 | int i,j; | |
151 | double smallDiag; | |
152 | double tol; | |
# | Line 153 | Line 154 | void SimInfo::calcHmatInv( void ) { | |
154 | ||
155 | invertMat3( Hmat, HmatInv ); | |
156 | ||
156 | – | // Check the inverse to make sure it is sane: |
157 | – | |
158 | – | matMul3( Hmat, HmatInv, sanity ); |
159 | – | |
157 | // check to see if Hmat is orthorhombic | |
158 | ||
159 | < | smallDiag = Hmat[0][0]; |
163 | < | if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
164 | < | if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
165 | < | tol = smallDiag * 1E-6; |
159 | > | oldOrtho = orthoRhombic; |
160 | ||
161 | + | smallDiag = fabs(Hmat[0][0]); |
162 | + | if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); |
163 | + | if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); |
164 | + | tol = smallDiag * orthoTolerance; |
165 | + | |
166 | orthoRhombic = 1; | |
167 | ||
168 | for (i = 0; i < 3; i++ ) { | |
169 | for (j = 0 ; j < 3; j++) { | |
170 | if (i != j) { | |
171 | if (orthoRhombic) { | |
172 | < | if (Hmat[i][j] >= tol) orthoRhombic = 0; |
172 | > | if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
173 | } | |
174 | } | |
175 | } | |
176 | } | |
177 | + | |
178 | + | if( oldOrtho != orthoRhombic ){ |
179 | + | |
180 | + | if( orthoRhombic ){ |
181 | + | sprintf( painCave.errMsg, |
182 | + | "Hmat is switching from Non-Orthorhombic to OrthoRhombic\n" |
183 | + | " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
184 | + | orthoTolerance); |
185 | + | simError(); |
186 | + | } |
187 | + | else { |
188 | + | sprintf( painCave.errMsg, |
189 | + | "Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" |
190 | + | " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
191 | + | orthoTolerance); |
192 | + | simError(); |
193 | + | } |
194 | + | } |
195 | } | |
196 | ||
197 | double SimInfo::matDet3(double a[3][3]) { | |
# | Line 279 | Line 296 | void SimInfo::printMat9(double A[9] ){ | |
296 | << "[ " << A[0] << ", " << A[1] << ", " << A[2] << " ]\n" | |
297 | << "[ " << A[3] << ", " << A[4] << ", " << A[5] << " ]\n" | |
298 | << "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; | |
299 | + | } |
300 | + | |
301 | + | |
302 | + | void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){ |
303 | + | |
304 | + | out[0] = a[1] * b[2] - a[2] * b[1]; |
305 | + | out[1] = a[2] * b[0] - a[0] * b[2] ; |
306 | + | out[2] = a[0] * b[1] - a[1] * b[0]; |
307 | + | |
308 | } | |
309 | ||
310 | + | double SimInfo::dotProduct3(double a[3], double b[3]){ |
311 | + | return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2]; |
312 | + | } |
313 | + | |
314 | + | double SimInfo::length3(double a[3]){ |
315 | + | return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); |
316 | + | } |
317 | + | |
318 | void SimInfo::calcBoxL( void ){ | |
319 | ||
320 | double dx, dy, dz, dsq; | |
287 | – | int i; |
321 | ||
322 | // boxVol = Determinant of Hmat | |
323 | ||
# | Line 295 | Line 328 | void SimInfo::calcBoxL( void ){ | |
328 | dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; | |
329 | dsq = dx*dx + dy*dy + dz*dz; | |
330 | boxL[0] = sqrt( dsq ); | |
331 | < | maxCutoff = 0.5 * boxL[0]; |
331 | > | //maxCutoff = 0.5 * boxL[0]; |
332 | ||
333 | // boxLy | |
334 | ||
335 | dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; | |
336 | dsq = dx*dx + dy*dy + dz*dz; | |
337 | boxL[1] = sqrt( dsq ); | |
338 | < | if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
338 | > | //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
339 | ||
340 | + | |
341 | // boxLz | |
342 | ||
343 | dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; | |
344 | dsq = dx*dx + dy*dy + dz*dz; | |
345 | boxL[2] = sqrt( dsq ); | |
346 | < | if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
346 | > | //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
347 | > | |
348 | > | //calculate the max cutoff |
349 | > | maxCutoff = calcMaxCutOff(); |
350 | ||
351 | checkCutOffs(); | |
352 | ||
353 | } | |
354 | ||
355 | ||
356 | + | double SimInfo::calcMaxCutOff(){ |
357 | + | |
358 | + | double ri[3], rj[3], rk[3]; |
359 | + | double rij[3], rjk[3], rki[3]; |
360 | + | double minDist; |
361 | + | |
362 | + | ri[0] = Hmat[0][0]; |
363 | + | ri[1] = Hmat[1][0]; |
364 | + | ri[2] = Hmat[2][0]; |
365 | + | |
366 | + | rj[0] = Hmat[0][1]; |
367 | + | rj[1] = Hmat[1][1]; |
368 | + | rj[2] = Hmat[2][1]; |
369 | + | |
370 | + | rk[0] = Hmat[0][2]; |
371 | + | rk[1] = Hmat[1][2]; |
372 | + | rk[2] = Hmat[2][2]; |
373 | + | |
374 | + | crossProduct3(ri,rj, rij); |
375 | + | distXY = dotProduct3(rk,rij) / length3(rij); |
376 | + | |
377 | + | crossProduct3(rj,rk, rjk); |
378 | + | distYZ = dotProduct3(ri,rjk) / length3(rjk); |
379 | + | |
380 | + | crossProduct3(rk,ri, rki); |
381 | + | distZX = dotProduct3(rj,rki) / length3(rki); |
382 | + | |
383 | + | minDist = min(min(distXY, distYZ), distZX); |
384 | + | return minDist/2; |
385 | + | |
386 | + | } |
387 | + | |
388 | void SimInfo::wrapVector( double thePos[3] ){ | |
389 | ||
390 | < | int i, j, k; |
390 | > | int i; |
391 | double scaled[3]; | |
392 | ||
393 | if( !orthoRhombic ){ | |
# | Line 356 | Line 425 | int SimInfo::getNDF(){ | |
425 | ||
426 | ||
427 | int SimInfo::getNDF(){ | |
428 | < | int ndf_local, ndf; |
428 | > | int ndf_local; |
429 | ||
430 | ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; | |
431 | ||
# | Line 372 | Line 441 | int SimInfo::getNDFraw() { | |
441 | } | |
442 | ||
443 | int SimInfo::getNDFraw() { | |
444 | < | int ndfRaw_local, ndfRaw; |
444 | > | int ndfRaw_local; |
445 | ||
446 | // Raw degrees of freedom that we have to set | |
447 | ndfRaw_local = 3 * n_atoms + 3 * n_oriented; | |
# | Line 387 | Line 456 | int SimInfo::getNDFtranslational() { | |
456 | } | |
457 | ||
458 | int SimInfo::getNDFtranslational() { | |
459 | < | int ndfTrans_local, ndfTrans; |
459 | > | int ndfTrans_local; |
460 | ||
461 | ndfTrans_local = 3 * n_atoms - n_constraints; | |
462 | ||
# | Line 460 | Line 529 | void SimInfo::refreshSim(){ | |
529 | this->ndfTrans = this->getNDFtranslational(); | |
530 | } | |
531 | ||
532 | + | void SimInfo::setDefaultRcut( double theRcut ){ |
533 | ||
534 | < | void SimInfo::setRcut( double theRcut ){ |
465 | < | |
466 | < | if( !haveOrigRcut ){ |
467 | < | haveOrigRcut = 1; |
468 | < | origRcut = theRcut; |
469 | < | } |
470 | < | |
534 | > | haveRcut = 1; |
535 | rCut = theRcut; | |
472 | – | checkCutOffs(); |
473 | – | } |
536 | ||
537 | < | void SimInfo::setEcr( double theEcr ){ |
537 | > | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
538 | ||
539 | < | if( !haveOrigEcr ){ |
540 | < | haveOrigEcr = 1; |
479 | < | origEcr = theEcr; |
480 | < | } |
539 | > | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
540 | > | } |
541 | ||
542 | + | void SimInfo::setDefaultEcr( double theEcr ){ |
543 | + | |
544 | + | haveEcr = 1; |
545 | ecr = theEcr; | |
546 | < | checkCutOffs(); |
546 | > | |
547 | > | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
548 | > | |
549 | > | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
550 | } | |
551 | ||
552 | < | void SimInfo::setEcr( double theEcr, double theEst ){ |
552 | > | void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
553 | ||
554 | est = theEst; | |
555 | < | setEcr( theEcr ); |
555 | > | setDefaultEcr( theEcr ); |
556 | } | |
557 | ||
558 | ||
559 | void SimInfo::checkCutOffs( void ){ | |
560 | < | |
495 | < | int cutChanged = 0; |
496 | < | |
497 | < | |
498 | < | |
560 | > | |
561 | if( boxIsInit ){ | |
562 | ||
563 | //we need to check cutOffs against the box | |
564 | < | |
565 | < | if(( maxCutoff > rCut )&&(usePBC)){ |
566 | < | if( rCut < origRcut ){ |
567 | < | rCut = origRcut; |
568 | < | if (rCut > maxCutoff) rCut = maxCutoff; |
569 | < | |
570 | < | sprintf( painCave.errMsg, |
571 | < | "New Box size is setting the long range cutoff radius " |
572 | < | "to %lf\n", |
573 | < | rCut ); |
574 | < | painCave.isFatal = 0; |
575 | < | simError(); |
576 | < | } |
564 | > | |
565 | > | if( rCut > maxCutoff ){ |
566 | > | sprintf( painCave.errMsg, |
567 | > | "Box size is too small for the long range cutoff radius, " |
568 | > | "%G, at time %G\n" |
569 | > | " [ %G %G %G ]\n" |
570 | > | " [ %G %G %G ]\n" |
571 | > | " [ %G %G %G ]\n", |
572 | > | rCut, currentTime, |
573 | > | Hmat[0][0], Hmat[0][1], Hmat[0][2], |
574 | > | Hmat[1][0], Hmat[1][1], Hmat[1][2], |
575 | > | Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
576 | > | painCave.isFatal = 1; |
577 | > | simError(); |
578 | } | |
579 | < | |
580 | < | if( maxCutoff > ecr ){ |
581 | < | if( ecr < origEcr ){ |
519 | < | ecr = origEcr; |
520 | < | if (ecr > maxCutoff) ecr = maxCutoff; |
521 | < | |
579 | > | |
580 | > | if( haveEcr ){ |
581 | > | if( ecr > maxCutoff ){ |
582 | sprintf( painCave.errMsg, | |
583 | < | "New Box size is setting the electrostaticCutoffRadius " |
584 | < | "to %lf\n", |
585 | < | ecr ); |
586 | < | painCave.isFatal = 0; |
583 | > | "Box size is too small for the electrostatic cutoff radius, " |
584 | > | "%G, at time %G\n" |
585 | > | " [ %G %G %G ]\n" |
586 | > | " [ %G %G %G ]\n" |
587 | > | " [ %G %G %G ]\n", |
588 | > | ecr, currentTime, |
589 | > | Hmat[0][0], Hmat[0][1], Hmat[0][2], |
590 | > | Hmat[1][0], Hmat[1][1], Hmat[1][2], |
591 | > | Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
592 | > | painCave.isFatal = 1; |
593 | simError(); | |
594 | } | |
595 | } | |
530 | – | |
531 | – | |
532 | – | if ((rCut > maxCutoff)&&(usePBC)) { |
533 | – | sprintf( painCave.errMsg, |
534 | – | "New Box size is setting the long range cutoff radius " |
535 | – | "to %lf\n", |
536 | – | maxCutoff ); |
537 | – | painCave.isFatal = 0; |
538 | – | simError(); |
539 | – | rCut = maxCutoff; |
540 | – | } |
541 | – | |
542 | – | if( ecr > maxCutoff){ |
543 | – | sprintf( painCave.errMsg, |
544 | – | "New Box size is setting the electrostaticCutoffRadius " |
545 | – | "to %lf\n", |
546 | – | maxCutoff ); |
547 | – | painCave.isFatal = 0; |
548 | – | simError(); |
549 | – | ecr = maxCutoff; |
550 | – | } |
551 | – | |
552 | – | |
553 | – | if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; |
554 | – | |
555 | – | // rlist is the 1.0 plus max( rcut, ecr ) |
556 | – | |
557 | – | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
558 | – | |
559 | – | if( cutChanged ){ |
560 | – | |
561 | – | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
562 | – | } |
563 | – | |
564 | – | oldEcr = ecr; |
565 | – | oldRcut = rCut; |
566 | – | |
596 | } else { | |
597 | // initialize this stuff before using it, OK? | |
598 | < | sprintf( painCave.errMsg, |
599 | < | "Trying to check cutoffs without a box. Be smarter.\n" ); |
600 | < | painCave.isFatal = 1; |
601 | < | simError(); |
598 | > | sprintf( painCave.errMsg, |
599 | > | "Trying to check cutoffs without a box. Be smarter.\n" ); |
600 | > | painCave.isFatal = 1; |
601 | > | simError(); |
602 | } | |
603 | < | |
603 | > | |
604 | } | |
605 | ||
606 | void SimInfo::addProperty(GenericData* prop){ |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |