# | 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 | ||
29 | SimInfo::SimInfo(){ | |
30 | excludes = NULL; | |
31 | n_constraints = 0; | |
32 | + | nZconstraints = 0; |
33 | n_oriented = 0; | |
34 | n_dipoles = 0; | |
35 | ndf = 0; | |
36 | ndfRaw = 0; | |
37 | + | nZconstraints = 0; |
38 | the_integrator = NULL; | |
39 | setTemp = 0; | |
40 | thermalTime = 0.0; | |
# | Line 37 | Line 42 | SimInfo::SimInfo(){ | |
42 | rCut = 0.0; | |
43 | ecr = 0.0; | |
44 | est = 0.0; | |
40 | – | oldEcr = 0.0; |
41 | – | 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; | |
58 | < | useDipole = 0; |
58 | > | useCharges = 0; |
59 | > | useDipoles = 0; |
60 | useReactionField = 0; | |
61 | useGB = 0; | |
62 | useEAM = 0; | |
# | Line 89 | Line 96 | void SimInfo::setBoxM( double theBox[3][3] ){ | |
96 | ||
97 | void SimInfo::setBoxM( double theBox[3][3] ){ | |
98 | ||
99 | < | int i, j, status; |
93 | < | double smallestBoxL, maxCutoff; |
99 | > | int i, j; |
100 | double FortranHmat[9]; // to preserve compatibility with Fortran the | |
101 | // ordering in the array is as follows: | |
102 | // [ 0 3 6 ] | |
# | Line 98 | Line 104 | void SimInfo::setBoxM( double theBox[3][3] ){ | |
104 | // [ 2 5 8 ] | |
105 | double FortranHmatInv[9]; // the inverted Hmat (for Fortran); | |
106 | ||
101 | – | |
107 | if( !boxIsInit ) boxIsInit = 1; | |
108 | ||
109 | for(i=0; i < 3; i++) | |
# | Line 142 | Line 147 | void SimInfo::calcHmatInv( void ) { | |
147 | ||
148 | void SimInfo::calcHmatInv( void ) { | |
149 | ||
150 | + | int oldOrtho; |
151 | int i,j; | |
152 | double smallDiag; | |
153 | double tol; | |
# | Line 149 | Line 155 | void SimInfo::calcHmatInv( void ) { | |
155 | ||
156 | invertMat3( Hmat, HmatInv ); | |
157 | ||
152 | – | // Check the inverse to make sure it is sane: |
153 | – | |
154 | – | matMul3( Hmat, HmatInv, sanity ); |
155 | – | |
158 | // check to see if Hmat is orthorhombic | |
159 | ||
160 | < | smallDiag = Hmat[0][0]; |
159 | < | if(smallDiag > Hmat[1][1]) smallDiag = Hmat[1][1]; |
160 | < | if(smallDiag > Hmat[2][2]) smallDiag = Hmat[2][2]; |
161 | < | tol = smallDiag * 1E-6; |
160 | > | oldOrtho = orthoRhombic; |
161 | ||
162 | + | smallDiag = fabs(Hmat[0][0]); |
163 | + | if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); |
164 | + | if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); |
165 | + | tol = smallDiag * orthoTolerance; |
166 | + | |
167 | orthoRhombic = 1; | |
168 | ||
169 | for (i = 0; i < 3; i++ ) { | |
170 | for (j = 0 ; j < 3; j++) { | |
171 | if (i != j) { | |
172 | if (orthoRhombic) { | |
173 | < | if (Hmat[i][j] >= tol) orthoRhombic = 0; |
173 | > | if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
174 | } | |
175 | } | |
176 | } | |
177 | } | |
178 | + | |
179 | + | if( oldOrtho != orthoRhombic ){ |
180 | + | |
181 | + | if( orthoRhombic ){ |
182 | + | sprintf( painCave.errMsg, |
183 | + | "Hmat is switching from Non-Orthorhombic to OrthoRhombic\n" |
184 | + | " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
185 | + | orthoTolerance); |
186 | + | simError(); |
187 | + | } |
188 | + | else { |
189 | + | sprintf( painCave.errMsg, |
190 | + | "Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" |
191 | + | " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
192 | + | orthoTolerance); |
193 | + | simError(); |
194 | + | } |
195 | + | } |
196 | } | |
197 | ||
198 | double SimInfo::matDet3(double a[3][3]) { | |
# | Line 275 | Line 297 | void SimInfo::printMat9(double A[9] ){ | |
297 | << "[ " << A[0] << ", " << A[1] << ", " << A[2] << " ]\n" | |
298 | << "[ " << A[3] << ", " << A[4] << ", " << A[5] << " ]\n" | |
299 | << "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; | |
300 | + | } |
301 | + | |
302 | + | |
303 | + | void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){ |
304 | + | |
305 | + | out[0] = a[1] * b[2] - a[2] * b[1]; |
306 | + | out[1] = a[2] * b[0] - a[0] * b[2] ; |
307 | + | out[2] = a[0] * b[1] - a[1] * b[0]; |
308 | + | |
309 | + | } |
310 | + | |
311 | + | double SimInfo::dotProduct3(double a[3], double b[3]){ |
312 | + | return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2]; |
313 | } | |
314 | ||
315 | + | double SimInfo::length3(double a[3]){ |
316 | + | return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); |
317 | + | } |
318 | + | |
319 | void SimInfo::calcBoxL( void ){ | |
320 | ||
321 | double dx, dy, dz, dsq; | |
283 | – | int i; |
322 | ||
323 | // boxVol = Determinant of Hmat | |
324 | ||
# | Line 291 | Line 329 | void SimInfo::calcBoxL( void ){ | |
329 | dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; | |
330 | dsq = dx*dx + dy*dy + dz*dz; | |
331 | boxL[0] = sqrt( dsq ); | |
332 | < | maxCutoff = 0.5 * boxL[0]; |
332 | > | //maxCutoff = 0.5 * boxL[0]; |
333 | ||
334 | // boxLy | |
335 | ||
336 | dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; | |
337 | dsq = dx*dx + dy*dy + dz*dz; | |
338 | boxL[1] = sqrt( dsq ); | |
339 | < | if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
339 | > | //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
340 | ||
341 | + | |
342 | // boxLz | |
343 | ||
344 | dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; | |
345 | dsq = dx*dx + dy*dy + dz*dz; | |
346 | boxL[2] = sqrt( dsq ); | |
347 | < | if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
347 | > | //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
348 | > | |
349 | > | //calculate the max cutoff |
350 | > | maxCutoff = calcMaxCutOff(); |
351 | ||
352 | checkCutOffs(); | |
353 | ||
354 | } | |
355 | ||
356 | ||
357 | + | double SimInfo::calcMaxCutOff(){ |
358 | + | |
359 | + | double ri[3], rj[3], rk[3]; |
360 | + | double rij[3], rjk[3], rki[3]; |
361 | + | double minDist; |
362 | + | |
363 | + | ri[0] = Hmat[0][0]; |
364 | + | ri[1] = Hmat[1][0]; |
365 | + | ri[2] = Hmat[2][0]; |
366 | + | |
367 | + | rj[0] = Hmat[0][1]; |
368 | + | rj[1] = Hmat[1][1]; |
369 | + | rj[2] = Hmat[2][1]; |
370 | + | |
371 | + | rk[0] = Hmat[0][2]; |
372 | + | rk[1] = Hmat[1][2]; |
373 | + | rk[2] = Hmat[2][2]; |
374 | + | |
375 | + | crossProduct3(ri,rj, rij); |
376 | + | distXY = dotProduct3(rk,rij) / length3(rij); |
377 | + | |
378 | + | crossProduct3(rj,rk, rjk); |
379 | + | distYZ = dotProduct3(ri,rjk) / length3(rjk); |
380 | + | |
381 | + | crossProduct3(rk,ri, rki); |
382 | + | distZX = dotProduct3(rj,rki) / length3(rki); |
383 | + | |
384 | + | minDist = min(min(distXY, distYZ), distZX); |
385 | + | return minDist/2; |
386 | + | |
387 | + | } |
388 | + | |
389 | void SimInfo::wrapVector( double thePos[3] ){ | |
390 | ||
391 | < | int i, j, k; |
391 | > | int i; |
392 | double scaled[3]; | |
393 | ||
394 | if( !orthoRhombic ){ | |
# | Line 352 | Line 426 | int SimInfo::getNDF(){ | |
426 | ||
427 | ||
428 | int SimInfo::getNDF(){ | |
429 | < | int ndf_local, ndf; |
429 | > | int ndf_local; |
430 | ||
431 | ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; | |
432 | ||
# | Line 362 | Line 436 | int SimInfo::getNDF(){ | |
436 | ndf = ndf_local; | |
437 | #endif | |
438 | ||
439 | < | ndf = ndf - 3; |
439 | > | ndf = ndf - 3 - nZconstraints; |
440 | ||
441 | return ndf; | |
442 | } | |
443 | ||
444 | int SimInfo::getNDFraw() { | |
445 | < | int ndfRaw_local, ndfRaw; |
445 | > | int ndfRaw_local; |
446 | ||
447 | // Raw degrees of freedom that we have to set | |
448 | ndfRaw_local = 3 * n_atoms + 3 * n_oriented; | |
# | Line 381 | Line 455 | int SimInfo::getNDFraw() { | |
455 | ||
456 | return ndfRaw; | |
457 | } | |
458 | < | |
458 | > | |
459 | > | int SimInfo::getNDFtranslational() { |
460 | > | int ndfTrans_local; |
461 | > | |
462 | > | ndfTrans_local = 3 * n_atoms - n_constraints; |
463 | > | |
464 | > | #ifdef IS_MPI |
465 | > | MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
466 | > | #else |
467 | > | ndfTrans = ndfTrans_local; |
468 | > | #endif |
469 | > | |
470 | > | ndfTrans = ndfTrans - 3 - nZconstraints; |
471 | > | |
472 | > | return ndfTrans; |
473 | > | } |
474 | > | |
475 | void SimInfo::refreshSim(){ | |
476 | ||
477 | simtype fInfo; | |
# | Line 391 | Line 481 | void SimInfo::refreshSim(){ | |
481 | ||
482 | fInfo.dielect = 0.0; | |
483 | ||
484 | < | if( useDipole ){ |
484 | > | if( useDipoles ){ |
485 | if( useReactionField )fInfo.dielect = dielectric; | |
486 | } | |
487 | ||
# | Line 400 | Line 490 | void SimInfo::refreshSim(){ | |
490 | fInfo.SIM_uses_LJ = useLJ; | |
491 | fInfo.SIM_uses_sticky = useSticky; | |
492 | //fInfo.SIM_uses_sticky = 0; | |
493 | < | fInfo.SIM_uses_dipoles = useDipole; |
493 | > | fInfo.SIM_uses_charges = useCharges; |
494 | > | fInfo.SIM_uses_dipoles = useDipoles; |
495 | //fInfo.SIM_uses_dipoles = 0; | |
496 | //fInfo.SIM_uses_RF = useReactionField; | |
497 | fInfo.SIM_uses_RF = 0; | |
# | Line 437 | Line 528 | void SimInfo::refreshSim(){ | |
528 | ||
529 | this->ndf = this->getNDF(); | |
530 | this->ndfRaw = this->getNDFraw(); | |
531 | < | |
531 | > | this->ndfTrans = this->getNDFtranslational(); |
532 | } | |
533 | ||
534 | + | void SimInfo::setDefaultRcut( double theRcut ){ |
535 | ||
536 | < | void SimInfo::setRcut( double theRcut ){ |
536 | > | haveRcut = 1; |
537 | > | rCut = theRcut; |
538 | ||
539 | < | if( !haveOrigRcut ){ |
447 | < | haveOrigRcut = 1; |
448 | < | origRcut = theRcut; |
449 | < | } |
539 | > | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
540 | ||
541 | < | rCut = theRcut; |
452 | < | checkCutOffs(); |
541 | > | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
542 | } | |
543 | ||
544 | < | void SimInfo::setEcr( double theEcr ){ |
544 | > | void SimInfo::setDefaultEcr( double theEcr ){ |
545 | ||
546 | < | if( !haveOrigEcr ){ |
458 | < | haveOrigEcr = 1; |
459 | < | origEcr = theEcr; |
460 | < | } |
461 | < | |
546 | > | haveEcr = 1; |
547 | ecr = theEcr; | |
548 | < | checkCutOffs(); |
548 | > | |
549 | > | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
550 | > | |
551 | > | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
552 | } | |
553 | ||
554 | < | void SimInfo::setEcr( double theEcr, double theEst ){ |
554 | > | void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
555 | ||
556 | est = theEst; | |
557 | < | setEcr( theEcr ); |
557 | > | setDefaultEcr( theEcr ); |
558 | } | |
559 | ||
560 | ||
561 | void SimInfo::checkCutOffs( void ){ | |
562 | < | |
475 | < | int cutChanged = 0; |
476 | < | |
477 | < | |
478 | < | |
562 | > | |
563 | if( boxIsInit ){ | |
564 | ||
565 | //we need to check cutOffs against the box | |
566 | < | |
567 | < | if(( maxCutoff > rCut )&&(usePBC)){ |
568 | < | if( rCut < origRcut ){ |
569 | < | rCut = origRcut; |
570 | < | if (rCut > maxCutoff) rCut = maxCutoff; |
571 | < | |
572 | < | sprintf( painCave.errMsg, |
573 | < | "New Box size is setting the long range cutoff radius " |
574 | < | "to %lf\n", |
575 | < | rCut ); |
576 | < | painCave.isFatal = 0; |
577 | < | simError(); |
578 | < | } |
566 | > | |
567 | > | if( rCut > maxCutoff ){ |
568 | > | sprintf( painCave.errMsg, |
569 | > | "Box size is too small for the long range cutoff radius, " |
570 | > | "%G, at time %G\n" |
571 | > | " [ %G %G %G ]\n" |
572 | > | " [ %G %G %G ]\n" |
573 | > | " [ %G %G %G ]\n", |
574 | > | rCut, currentTime, |
575 | > | Hmat[0][0], Hmat[0][1], Hmat[0][2], |
576 | > | Hmat[1][0], Hmat[1][1], Hmat[1][2], |
577 | > | Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
578 | > | painCave.isFatal = 1; |
579 | > | simError(); |
580 | } | |
581 | < | |
582 | < | if( maxCutoff > ecr ){ |
583 | < | if( ecr < origEcr ){ |
499 | < | rCut = origEcr; |
500 | < | if (ecr > maxCutoff) ecr = maxCutoff; |
501 | < | |
581 | > | |
582 | > | if( haveEcr ){ |
583 | > | if( ecr > maxCutoff ){ |
584 | sprintf( painCave.errMsg, | |
585 | < | "New Box size is setting the electrostaticCutoffRadius " |
586 | < | "to %lf\n", |
587 | < | ecr ); |
588 | < | painCave.isFatal = 0; |
585 | > | "Box size is too small for the electrostatic cutoff radius, " |
586 | > | "%G, at time %G\n" |
587 | > | " [ %G %G %G ]\n" |
588 | > | " [ %G %G %G ]\n" |
589 | > | " [ %G %G %G ]\n", |
590 | > | ecr, currentTime, |
591 | > | Hmat[0][0], Hmat[0][1], Hmat[0][2], |
592 | > | Hmat[1][0], Hmat[1][1], Hmat[1][2], |
593 | > | Hmat[2][0], Hmat[2][1], Hmat[2][2]); |
594 | > | painCave.isFatal = 1; |
595 | simError(); | |
596 | } | |
597 | } | |
598 | < | |
599 | < | |
600 | < | if ((rCut > maxCutoff)&&(usePBC)) { |
601 | < | sprintf( painCave.errMsg, |
602 | < | "New Box size is setting the long range cutoff radius " |
603 | < | "to %lf\n", |
516 | < | maxCutoff ); |
517 | < | painCave.isFatal = 0; |
518 | < | simError(); |
519 | < | rCut = maxCutoff; |
520 | < | } |
521 | < | |
522 | < | if( ecr > maxCutoff){ |
523 | < | sprintf( painCave.errMsg, |
524 | < | "New Box size is setting the electrostaticCutoffRadius " |
525 | < | "to %lf\n", |
526 | < | maxCutoff ); |
527 | < | painCave.isFatal = 0; |
528 | < | simError(); |
529 | < | ecr = maxCutoff; |
530 | < | } |
531 | < | |
532 | < | |
598 | > | } else { |
599 | > | // initialize this stuff before using it, OK? |
600 | > | sprintf( painCave.errMsg, |
601 | > | "Trying to check cutoffs without a box. Be smarter.\n" ); |
602 | > | painCave.isFatal = 1; |
603 | > | simError(); |
604 | } | |
534 | – | |
535 | – | |
536 | – | if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1; |
537 | – | |
538 | – | // rlist is the 1.0 plus max( rcut, ecr ) |
605 | ||
540 | – | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
541 | – | |
542 | – | if( cutChanged ){ |
543 | – | |
544 | – | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
545 | – | } |
546 | – | |
547 | – | oldEcr = ecr; |
548 | – | oldRcut = rCut; |
606 | } | |
607 | ||
608 | void SimInfo::addProperty(GenericData* prop){ | |
# | Line 595 | Line 652 | vector<GenericData*> SimInfo::getProperties(){ | |
652 | return result; | |
653 | } | |
654 | ||
655 | + | double SimInfo::matTrace3(double m[3][3]){ |
656 | + | double trace; |
657 | + | trace = m[0][0] + m[1][1] + m[2][2]; |
658 | ||
659 | + | return trace; |
660 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |