ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimInfo.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/SimInfo.cpp (file contents):
Revision 790 by mmeineke, Mon Sep 29 21:16:11 2003 UTC vs.
Revision 941 by gezelter, Tue Jan 13 23:01:43 2004 UTC

# 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    resetTime = 1e99;
52  
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 102 | Line 104 | void SimInfo::setBoxM( double theBox[3][3] ){
104                           // [ 2 5 8 ]
105    double FortranHmatInv[9]; // the inverted Hmat (for Fortran);
106  
105  
107    if( !boxIsInit ) boxIsInit = 1;
108  
109    for(i=0; i < 3; i++)
# Line 146 | 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 153 | Line 155 | void SimInfo::calcHmatInv( void ) {
155  
156    invertMat3( Hmat, HmatInv );
157  
156  // Check the inverse to make sure it is sane:
157
158  matMul3( Hmat, HmatInv, sanity );
159    
158    // check to see if Hmat is orthorhombic
159    
160 <  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;
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 463 | 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 472 | 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 512 | Line 531 | void SimInfo::refreshSim(){
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 ){
519 <    haveOrigRcut = 1;
520 <    origRcut = theRcut;
521 <  }
539 >  ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
540  
541 <  rCut = theRcut;
524 <  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 ){
530 <    haveOrigEcr = 1;
531 <    origEcr = theEcr;
532 <  }
533 <
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 ){
546
547  int cutChanged = 0;
562    
563    if( boxIsInit ){
564      
565      //we need to check cutOffs against the box
566 <
567 <    //detect the change of rCut
554 <    if(( maxCutoff > rCut )&&(usePBC)){
555 <      if( rCut < origRcut ){
556 <        rCut = origRcut;
557 <        
558 <        if (rCut > maxCutoff)
559 <          rCut = maxCutoff;
560 <  
561 <          sprintf( painCave.errMsg,
562 <                    "New Box size is setting the long range cutoff radius "
563 <                    "to %lf at time %lf\n",
564 <                    rCut, currentTime );
565 <          painCave.isFatal = 0;
566 <          simError();
567 <      }
568 <    }
569 <    else if ((rCut > maxCutoff)&&(usePBC)) {
566 >    
567 >    if( rCut > maxCutoff ){
568        sprintf( painCave.errMsg,
569 <               "New Box size is setting the long range cutoff radius "
570 <               "to %lf at time %lf\n",
571 <               maxCutoff, currentTime );
572 <      painCave.isFatal = 0;
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();
576      rCut = maxCutoff;
580      }
581 <
582 <
583 <    //detect the change of ecr
584 <    if( maxCutoff > ecr ){
585 <      if( ecr < origEcr ){
586 <        ecr = origEcr;
587 <        if (ecr > maxCutoff) ecr = maxCutoff;
588 <  
589 <          sprintf( painCave.errMsg,
590 <                    "New Box size is setting the electrostaticCutoffRadius "
591 <                    "to %lf at time %lf\n",
592 <                    ecr, currentTime );
593 <            painCave.isFatal = 0;
594 <            simError();
581 >    
582 >    if( haveEcr ){
583 >      if( ecr > maxCutoff ){
584 >        sprintf( painCave.errMsg,
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      }
594    else if( ecr > maxCutoff){
595      sprintf( painCave.errMsg,
596               "New Box size is setting the electrostaticCutoffRadius "
597               "to %lf at time %lf\n",
598               maxCutoff, currentTime  );
599      painCave.isFatal = 0;
600      simError();      
601      ecr = maxCutoff;
602    }
603
604    if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1;
605    
606    // rlist is the 1.0 plus max( rcut, ecr )
607    
608    ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
609    
610    if( cutChanged ){
611      
612      notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
613    }
614    
615    oldEcr = ecr;
616    oldRcut = rCut;
617    
598    } else {
599      // initialize this stuff before using it, OK?
600      sprintf( painCave.errMsg,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines