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

Comparing trunk/OOPSE/libmdtools/SimSetup.cpp (file contents):
Revision 722 by tim, Tue Aug 26 20:02:29 2003 UTC vs.
Revision 962 by tim, Mon Jan 19 18:36:21 2004 UTC

# Line 1 | Line 1
1   #include <algorithm>
2 < #include <cstdlib>
2 > #include <stdlib.h>
3   #include <iostream>
4 < #include <cmath>
4 > #include <math.h>
5   #include <string>
6   #include <sprng.h>
7
7   #include "SimSetup.hpp"
8   #include "ReadWrite.hpp"
9   #include "parse_me.h"
# Line 22 | Line 21
21   #define NVT_ENS        1
22   #define NPTi_ENS       2
23   #define NPTf_ENS       3
24 < #define NPTim_ENS      4
26 < #define NPTfm_ENS      5
24 > #define NPTxyz_ENS     4
25  
26 +
27   #define FF_DUFF 0
28   #define FF_LJ   1
29   #define FF_EAM  2
30  
31   using namespace std;
32  
33 + /**
34 + * Check whether dividend is divisble by divisor or not
35 + */
36 + bool isDivisible(double dividend, double divisor){
37 +  double tolerance = 0.000001;
38 +  double quotient;
39 +  double diff;
40 +  int intQuotient;
41 +  
42 +  quotient = dividend / divisor;
43 +
44 +  if (quotient < 0)
45 +    quotient = -quotient;
46 +
47 +  intQuotient = int (quotient + tolerance);
48 +
49 +  diff = fabs(fabs(dividend) - intQuotient  * fabs(divisor));
50 +
51 +  if (diff <= tolerance)
52 +    return true;
53 +  else
54 +    return false;  
55 + }
56 +
57   SimSetup::SimSetup(){
58 +  
59 +  initSuspend = false;
60    isInfoArray = 0;
61    nInfo = 1;
62  
# Line 54 | Line 79 | void SimSetup::setSimInfo(SimInfo* the_info, int theNi
79    info = the_info;
80    nInfo = theNinfo;
81    isInfoArray = 1;
82 +  initSuspend = true;
83   }
84  
85  
# Line 92 | Line 118 | void SimSetup::createSim(void){
118   #endif // is_mpi
119  
120   void SimSetup::createSim(void){
95  int i, j, k, globalAtomIndex;
121  
122    // gather all of the information from the Bass file
123  
# Line 108 | Line 133 | void SimSetup::createSim(void){
133  
134    // initialize the system coordinates
135  
136 <  if (!isInfoArray){
136 >  if ( !initSuspend ){
137      initSystemCoords();
138 +
139 +    if( !(globals->getUseInitTime()) )
140 +      info[0].currentTime = 0.0;
141    }  
142  
143    // make the output filenames
# Line 131 | Line 159 | void SimSetup::makeMolecules(void){
159  
160  
161   void SimSetup::makeMolecules(void){
162 <  int k, l;
162 >  int k;
163    int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
164    molInit molInfo;
165    DirectionalAtom* dAtom;
# Line 553 | Line 581 | void SimSetup::gatherInfo(void){
581  
582  
583   void SimSetup::gatherInfo(void){
584 <  int i, j, k;
584 >  int i;
585  
586    ensembleCase = -1;
587    ffCase = -1;
# Line 604 | Line 632 | void SimSetup::gatherInfo(void){
632    else if (!strcasecmp(ensemble, "NPTf")){
633      ensembleCase = NPTf_ENS;
634    }
635 <  else if (!strcasecmp(ensemble, "NPTim")){
636 <    ensembleCase = NPTim_ENS;
635 >  else if (!strcasecmp(ensemble, "NPTxyz")){
636 >    ensembleCase = NPTxyz_ENS;
637    }
610  else if (!strcasecmp(ensemble, "NPTfm")){
611    ensembleCase = NPTfm_ENS;
612  }
638    else{
639      sprintf(painCave.errMsg,
640              "SimSetup Warning. Unrecognized Ensemble -> %s, "
# Line 664 | Line 689 | void SimSetup::gatherInfo(void){
689              " Please give nMol in the components.\n");
690      painCave.isFatal = 1;
691      simError();
692 +  }
693 +
694 +  //check whether sample time, status time, thermal time and reset time are divisble by dt
695 +  if (!isDivisible(globals->getSampleTime(), globals->getDt())){
696 +    sprintf(painCave.errMsg,
697 +              "Sample time is not divisible by dt \n");
698 +    painCave.isFatal = 0;
699 +    simError();    
700 +  }
701 +
702 +  if (globals->haveStatusTime() && !isDivisible(globals->getSampleTime(), globals->getDt())){
703 +    sprintf(painCave.errMsg,
704 +              "Status time is not divisible by dt\n");
705 +    painCave.isFatal = 0;
706 +    simError();    
707    }
708  
709 +  if (globals->haveThermalTime() && !isDivisible(globals->getThermalTime(), globals->getDt())){
710 +    sprintf(painCave.errMsg,
711 +              "Thermal time is not divisible by dt\n");
712 +    painCave.isFatal = 0;
713 +    simError();    
714 +  }  
715 +
716 +  if (globals->haveResetTime() && !isDivisible(globals->getResetTime(), globals->getDt())){
717 +    sprintf(painCave.errMsg,
718 +              "Reset time is not divisible by dt\n");
719 +    painCave.isFatal = 0;
720 +    simError();    
721 +  }
722 +
723    // set the status, sample, and thermal kick times
724  
725    for (i = 0; i < nInfo; i++){
# Line 688 | Line 742 | void SimSetup::gatherInfo(void){
742        info[i].thermalTime = globals->getThermalTime();
743      }
744  
745 <    // check for the temperature set flag
745 >    info[i].resetIntegrator = 0;
746 >    if( globals->haveResetTime() ){
747 >      info[i].resetTime = globals->getResetTime();
748 >      info[i].resetIntegrator = 1;
749 >    }
750  
751 +    // check for the temperature set flag
752 +    
753      if (globals->haveTempSet())
754        info[i].setTemp = globals->getTempSet();
755  
756 <    // get some of the tricky things that may still be in the globals
756 >    // check for the extended State init
757  
758 <    double boxVector[3];
759 <    if (globals->haveBox()){
760 <      boxVector[0] = globals->getBox();
701 <      boxVector[1] = globals->getBox();
702 <      boxVector[2] = globals->getBox();
703 <
704 <      info[i].setBox(boxVector);
705 <    }
706 <    else if (globals->haveDensity()){
707 <      double vol;
708 <      vol = (double) tot_nmol / globals->getDensity();
709 <      boxVector[0] = pow(vol, (1.0 / 3.0));
710 <      boxVector[1] = boxVector[0];
711 <      boxVector[2] = boxVector[0];
712 <
713 <      info[i].setBox(boxVector);
714 <    }
715 <    else{
716 <      if (!globals->haveBoxX()){
717 <        sprintf(painCave.errMsg,
718 <                "SimSetup error, no periodic BoxX size given.\n");
719 <        painCave.isFatal = 1;
720 <        simError();
721 <      }
722 <      boxVector[0] = globals->getBoxX();
723 <
724 <      if (!globals->haveBoxY()){
725 <        sprintf(painCave.errMsg,
726 <                "SimSetup error, no periodic BoxY size given.\n");
727 <        painCave.isFatal = 1;
728 <        simError();
729 <      }
730 <      boxVector[1] = globals->getBoxY();
731 <
732 <      if (!globals->haveBoxZ()){
733 <        sprintf(painCave.errMsg,
734 <                "SimSetup error, no periodic BoxZ size given.\n");
735 <        painCave.isFatal = 1;
736 <        simError();
737 <      }
738 <      boxVector[2] = globals->getBoxZ();
739 <
740 <      info[i].setBox(boxVector);
741 <    }
758 >    info[i].useInitXSstate = globals->getUseInitXSstate();
759 >    info[i].orthoTolerance = globals->getOrthoBoxTolerance();
760 >    
761    }
762 <
762 >  
763    //setup seed for random number generator
764    int seedValue;
765  
# Line 815 | Line 834 | void SimSetup::finalInfoCheck(void){
834  
835        if (!globals->haveECR()){
836          sprintf(painCave.errMsg,
837 <                "SimSetup Warning: using default value of 1/2 the smallest "
838 <                "box length for the electrostaticCutoffRadius.\n"
820 <                "I hope you have a very fast processor!\n");
837 >                "SimSetup Warning: using default value of 15.0 angstroms"
838 >                "box length for the electrostaticCutoffRadius.\n");
839          painCave.isFatal = 0;
840          simError();
841 <        double smallest;
824 <        smallest = info[i].boxL[0];
825 <        if (info[i].boxL[1] <= smallest)
826 <          smallest = info[i].boxL[1];
827 <        if (info[i].boxL[2] <= smallest)
828 <          smallest = info[i].boxL[2];
829 <        theEcr = 0.5 * smallest;
841 >        theEcr = 15.0;
842        }
843        else{
844          theEcr = globals->getECR();
# Line 844 | Line 856 | void SimSetup::finalInfoCheck(void){
856          theEst = globals->getEST();
857        }
858  
859 <      info[i].setEcr(theEcr, theEst);
859 >      info[i].setDefaultEcr(theEcr, theEst);
860  
861        if (!globals->haveDielectric()){
862          sprintf(painCave.errMsg,
# Line 859 | Line 871 | void SimSetup::finalInfoCheck(void){
871        if (usesDipoles){
872          if (!globals->haveECR()){
873            sprintf(painCave.errMsg,
874 <                  "SimSetup Warning: using default value of 1/2 the smallest "
875 <                  "box length for the electrostaticCutoffRadius.\n"
876 <                  "I hope you have a very fast processor!\n");
877 <          painCave.isFatal = 0;
878 <          simError();
867 <          double smallest;
868 <          smallest = info[i].boxL[0];
869 <          if (info[i].boxL[1] <= smallest)
870 <            smallest = info[i].boxL[1];
871 <          if (info[i].boxL[2] <= smallest)
872 <            smallest = info[i].boxL[2];
873 <          theEcr = 0.5 * smallest;
874 >                  "SimSetup Warning: using default value of 15.0 angstroms"
875 >                  "box length for the electrostaticCutoffRadius.\n");
876 >          painCave.isFatal = 0;
877 >          simError();
878 >          theEcr = 15.0;
879          }
880          else{
881            theEcr = globals->getECR();
882          }
883 <
883 >        
884          if (!globals->haveEST()){
885            sprintf(painCave.errMsg,
886                    "SimSetup Warning: using default value of 0.05 * the "
# Line 888 | Line 893 | void SimSetup::finalInfoCheck(void){
893          else{
894            theEst = globals->getEST();
895          }
896 <
897 <        info[i].setEcr(theEcr, theEst);
896 >        
897 >        info[i].setDefaultEcr(theEcr, theEst);
898        }
899      }
900    }
896
901   #ifdef IS_MPI
902    strcpy(checkPointMsg, "post processing checks out");
903    MPIcheckPoint();
904   #endif // is_mpi
905   }
906 <
906 >  
907   void SimSetup::initSystemCoords(void){
908    int i;
909  
# Line 916 | Line 920 | void SimSetup::initSystemCoords(void){
920      if (worldRank == 0){
921   #endif //is_mpi
922        inName = globals->getInitialConfig();
919      double* tempDouble = new double[1000000];
923        fileInit = new InitializeFromFile(inName);
924   #ifdef IS_MPI
925      }
# Line 928 | Line 931 | void SimSetup::initSystemCoords(void){
931      delete fileInit;
932    }
933    else{
934 < #ifdef IS_MPI
935 <
936 <    // no init from bass
934 <
934 >    
935 >    // no init from bass
936 >    
937      sprintf(painCave.errMsg,
938 <            "Cannot intialize a parallel simulation without an initial configuration file.\n");
939 <    painCave.isFatal;
938 >            "Cannot intialize a simulation without an initial configuration file.\n");
939 >    painCave.isFatal = 1;;
940      simError();
941 <
940 < #else
941 <
942 <    initFromBass();
943 <
944 <
945 < #endif
941 >    
942    }
943  
944   #ifdef IS_MPI
# Line 1160 | Line 1156 | void SimSetup::calcSysValues(void){
1156   }
1157  
1158   void SimSetup::calcSysValues(void){
1159 <  int i, j, k;
1159 >  int i;
1160  
1161    int* molMembershipArray;
1162  
# Line 1259 | Line 1255 | void SimSetup::makeSysArrays(void){
1255  
1256  
1257   void SimSetup::makeSysArrays(void){
1258 <  int i, j, k, l;
1258 >
1259 > #ifndef IS_MPI
1260 >  int k, j;
1261 > #endif // is_mpi
1262 >  int i, l;
1263  
1264    Atom** the_atoms;
1265    Molecule* the_molecules;
# Line 1342 | Line 1342 | void SimSetup::makeIntegrator(void){
1342   void SimSetup::makeIntegrator(void){
1343    int k;
1344  
1345 +  NVE<RealIntegrator>* myNVE = NULL;
1346    NVT<RealIntegrator>* myNVT = NULL;
1347 <  NPTi<RealIntegrator>* myNPTi = NULL;
1348 <  NPTf<RealIntegrator>* myNPTf = NULL;
1349 <  NPTim<RealIntegrator>* myNPTim = NULL;
1350 <  NPTfm<RealIntegrator>* myNPTfm = NULL;
1350 <
1347 >  NPTi<NPT<RealIntegrator> >* myNPTi = NULL;
1348 >  NPTf<NPT<RealIntegrator> >* myNPTf = NULL;
1349 >  NPTxyz<NPT<RealIntegrator> >* myNPTxyz = NULL;
1350 >  
1351    for (k = 0; k < nInfo; k++){
1352      switch (ensembleCase){
1353        case NVE_ENS:
1354          if (globals->haveZconstraints()){
1355            setupZConstraint(info[k]);
1356 <          new ZConstraint<NVE<RealIntegrator> >(&(info[k]), the_ff);
1356 >          myNVE = new ZConstraint<NVE<RealIntegrator> >(&(info[k]), the_ff);
1357          }
1358 <        else
1359 <          new NVE<RealIntegrator>(&(info[k]), the_ff);
1358 >        else{
1359 >          myNVE = new NVE<RealIntegrator>(&(info[k]), the_ff);
1360 >        }
1361 >        
1362 >        info->the_integrator = myNVE;
1363          break;
1364  
1365        case NVT_ENS:
# Line 1378 | Line 1381 | void SimSetup::makeIntegrator(void){
1381            painCave.isFatal = 1;
1382            simError();
1383          }
1384 +
1385 +        info->the_integrator = myNVT;
1386          break;
1387  
1388        case NPTi_ENS:
1389          if (globals->haveZconstraints()){
1390            setupZConstraint(info[k]);
1391 <          myNPTi = new ZConstraint<NPTi<RealIntegrator> >(&(info[k]), the_ff);
1391 >          myNPTi = new ZConstraint<NPTi<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1392          }
1393          else
1394 <          myNPTi = new NPTi<RealIntegrator>(&(info[k]), the_ff);
1394 >          myNPTi = new NPTi<NPT<RealIntegrator> >(&(info[k]), the_ff);
1395  
1396          myNPTi->setTargetTemp(globals->getTargetTemp());
1397  
# Line 1419 | Line 1424 | void SimSetup::makeIntegrator(void){
1424            painCave.isFatal = 1;
1425            simError();
1426          }
1427 +
1428 +        info->the_integrator = myNPTi;
1429          break;
1430  
1431        case NPTf_ENS:
1432          if (globals->haveZconstraints()){
1433            setupZConstraint(info[k]);
1434 <          myNPTf = new ZConstraint<NPTf<RealIntegrator> >(&(info[k]), the_ff);
1434 >          myNPTf = new ZConstraint<NPTf<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1435          }
1436          else
1437 <          myNPTf = new NPTf<RealIntegrator>(&(info[k]), the_ff);
1437 >          myNPTf = new NPTf<NPT <RealIntegrator> >(&(info[k]), the_ff);
1438  
1439          myNPTf->setTargetTemp(globals->getTargetTemp());
1440  
# Line 1443 | Line 1450 | void SimSetup::makeIntegrator(void){
1450  
1451          if (globals->haveTauThermostat())
1452            myNPTf->setTauThermostat(globals->getTauThermostat());
1453 +
1454          else{
1455            sprintf(painCave.errMsg,
1456                    "SimSetup error: If you use an NPT\n"
# Line 1453 | Line 1461 | void SimSetup::makeIntegrator(void){
1461  
1462          if (globals->haveTauBarostat())
1463            myNPTf->setTauBarostat(globals->getTauBarostat());
1456        else{
1457          sprintf(painCave.errMsg,
1458                  "SimSetup error: If you use an NPT\n"
1459                  "    ensemble, you must set tauBarostat.\n");
1460          painCave.isFatal = 1;
1461          simError();
1462        }
1463        break;
1464  
1465      case NPTim_ENS:
1466        if (globals->haveZconstraints()){
1467          setupZConstraint(info[k]);
1468          myNPTim = new ZConstraint<NPTim<RealIntegrator> >(&(info[k]), the_ff);
1469        }
1470        else
1471          myNPTim = new NPTim<RealIntegrator>(&(info[k]), the_ff);
1472
1473        myNPTim->setTargetTemp(globals->getTargetTemp());
1474
1475        if (globals->haveTargetPressure())
1476          myNPTim->setTargetPressure(globals->getTargetPressure());
1465          else{
1466            sprintf(painCave.errMsg,
1479                  "SimSetup error: If you use a constant pressure\n"
1480                  "    ensemble, you must set targetPressure in the BASS file.\n");
1481          painCave.isFatal = 1;
1482          simError();
1483        }
1484
1485        if (globals->haveTauThermostat())
1486          myNPTim->setTauThermostat(globals->getTauThermostat());
1487        else{
1488          sprintf(painCave.errMsg,
1467                    "SimSetup error: If you use an NPT\n"
1490                  "    ensemble, you must set tauThermostat.\n");
1491          painCave.isFatal = 1;
1492          simError();
1493        }
1494
1495        if (globals->haveTauBarostat())
1496          myNPTim->setTauBarostat(globals->getTauBarostat());
1497        else{
1498          sprintf(painCave.errMsg,
1499                  "SimSetup error: If you use an NPT\n"
1468                    "    ensemble, you must set tauBarostat.\n");
1469            painCave.isFatal = 1;
1470            simError();
1471          }
1472 +
1473 +        info->the_integrator = myNPTf;
1474          break;
1475  
1476 <      case NPTfm_ENS:
1476 >      case NPTxyz_ENS:
1477          if (globals->haveZconstraints()){
1478            setupZConstraint(info[k]);
1479 <          myNPTfm = new ZConstraint<NPTfm<RealIntegrator> >(&(info[k]), the_ff);
1479 >          myNPTxyz = new ZConstraint<NPTxyz<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1480          }
1481          else
1482 <          myNPTfm = new NPTfm<RealIntegrator>(&(info[k]), the_ff);
1482 >          myNPTxyz = new NPTxyz<NPT <RealIntegrator> >(&(info[k]), the_ff);
1483  
1484 <        myNPTfm->setTargetTemp(globals->getTargetTemp());
1484 >        myNPTxyz->setTargetTemp(globals->getTargetTemp());
1485  
1486          if (globals->haveTargetPressure())
1487 <          myNPTfm->setTargetPressure(globals->getTargetPressure());
1487 >          myNPTxyz->setTargetPressure(globals->getTargetPressure());
1488          else{
1489            sprintf(painCave.errMsg,
1490                    "SimSetup error: If you use a constant pressure\n"
1491                    "    ensemble, you must set targetPressure in the BASS file.\n");
1492            painCave.isFatal = 1;
1493            simError();
1494 <        }
1494 >        }    
1495  
1496          if (globals->haveTauThermostat())
1497 <          myNPTfm->setTauThermostat(globals->getTauThermostat());
1497 >          myNPTxyz->setTauThermostat(globals->getTauThermostat());
1498          else{
1499            sprintf(painCave.errMsg,
1500                    "SimSetup error: If you use an NPT\n"
# Line 1534 | Line 1504 | void SimSetup::makeIntegrator(void){
1504          }
1505  
1506          if (globals->haveTauBarostat())
1507 <          myNPTfm->setTauBarostat(globals->getTauBarostat());
1507 >          myNPTxyz->setTauBarostat(globals->getTauBarostat());
1508          else{
1509            sprintf(painCave.errMsg,
1510                    "SimSetup error: If you use an NPT\n"
# Line 1542 | Line 1512 | void SimSetup::makeIntegrator(void){
1512            painCave.isFatal = 1;
1513            simError();
1514          }
1515 +
1516 +        info->the_integrator = myNPTxyz;
1517          break;
1518  
1519        default:
# Line 1615 | Line 1587 | void SimSetup::setupZConstraint(SimInfo& theInfo){
1587    }
1588    theInfo.addProperty(zconsTol);
1589  
1590 <  //set Force Substraction Policy
1590 >  //set Force Subtraction Policy
1591    StringData* zconsForcePolicy = new StringData();
1592    zconsForcePolicy->setID(ZCONSFORCEPOLICY_ID);
1593  
# Line 1624 | Line 1596 | void SimSetup::setupZConstraint(SimInfo& theInfo){
1596    }
1597    else{
1598      sprintf(painCave.errMsg,
1599 <            "ZConstraint Warning: User does not set force substraction policy, "
1600 <            "average force substraction policy is used\n");
1599 >            "ZConstraint Warning: User does not set force Subtraction policy, "
1600 >            "PolicyByMass is used\n");
1601      painCave.isFatal = 0;
1602      simError();
1603 <    zconsForcePolicy->setData("BYNUMBER");
1603 >    zconsForcePolicy->setData("BYMASS");
1604    }
1605  
1606    theInfo.addProperty(zconsForcePolicy);
# Line 1666 | Line 1638 | void SimSetup::setupZConstraint(SimInfo& theInfo){
1638      zconsParaData->addItem(tempParaItem);
1639    }
1640  
1641 +  //check the uniqueness of index  
1642 +  if(!zconsParaData->isIndexUnique()){
1643 +    sprintf(painCave.errMsg,
1644 +            "ZConstraint Error: molIndex is not unique\n");
1645 +    painCave.isFatal = 1;
1646 +    simError();
1647 +  }
1648 +
1649    //sort the parameters by index of molecules
1650    zconsParaData->sortByIndex();
1651 <
1651 >  
1652    //push data into siminfo, therefore, we can retrieve later
1653    theInfo.addProperty(zconsParaData);
1654   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines