ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/SimInfo.cpp
(Generate patch)

Comparing trunk/src/brains/SimInfo.cpp (file contents):
Revision 764 by gezelter, Mon Nov 21 22:59:21 2005 UTC vs.
Revision 1024 by tim, Wed Aug 30 18:42:29 2006 UTC

# Line 53 | Line 53
53   #include "brains/SimInfo.hpp"
54   #include "math/Vector3.hpp"
55   #include "primitives/Molecule.hpp"
56 + #include "primitives/StuntDouble.hpp"
57   #include "UseTheForce/fCutoffPolicy.h"
58   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
59   #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h"
# Line 63 | Line 64
64   #include "utils/MemoryUtils.hpp"
65   #include "utils/simError.h"
66   #include "selection/SelectionManager.hpp"
67 + #include "io/ForceFieldOptions.hpp"
68 + #include "UseTheForce/ForceField.hpp"
69  
70   #ifdef IS_MPI
71   #include "UseTheForce/mpiComponentPlan.h"
# Line 80 | Line 83 | namespace oopse {
83      return result;
84    }
85    
86 <  SimInfo::SimInfo(MakeStamps* stamps, std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
87 <                   ForceField* ff, Globals* simParams) :
88 <    stamps_(stamps), forceField_(ff), simParams_(simParams),
86 <    ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
86 >  SimInfo::SimInfo(ForceField* ff, Globals* simParams) :
87 >    forceField_(ff), simParams_(simParams),
88 >    ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
89      nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
90      nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
91      nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nRigidBodies_(0),
92      nIntegrableObjects_(0),  nCutoffGroups_(0), nConstraints_(0),
93 <    sman_(NULL), fortranInitialized_(false) {
93 >    sman_(NULL), fortranInitialized_(false), calcBoxDipole_(false) {
94  
93            
94      std::vector<std::pair<MoleculeStamp*, int> >::iterator i;
95        MoleculeStamp* molStamp;
96        int nMolWithSameStamp;
97        int nCutoffAtoms = 0; // number of atoms belong to cutoff groups
# Line 99 | Line 99 | namespace oopse {
99        CutoffGroupStamp* cgStamp;    
100        RigidBodyStamp* rbStamp;
101        int nRigidAtoms = 0;
102 <    
103 <      for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) {
104 <        molStamp = i->first;
105 <        nMolWithSameStamp = i->second;
102 >      std::vector<Component*> components = simParams->getComponents();
103 >      
104 >      for (std::vector<Component*>::iterator i = components.begin(); i !=components.end(); ++i) {
105 >        molStamp = (*i)->getMoleculeStamp();
106 >        nMolWithSameStamp = (*i)->getNMol();
107          
108          addMoleculeStamp(molStamp, nMolWithSameStamp);
109  
110          //calculate atoms in molecules
111          nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;  
112  
112
113          //calculate atoms in cutoff groups
114          int nAtomsInGroups = 0;
115          int nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
116          
117          for (int j=0; j < nCutoffGroupsInStamp; j++) {
118 <          cgStamp = molStamp->getCutoffGroup(j);
118 >          cgStamp = molStamp->getCutoffGroupStamp(j);
119            nAtomsInGroups += cgStamp->getNMembers();
120          }
121  
# Line 128 | Line 128 | namespace oopse {
128          int nRigidBodiesInStamp = molStamp->getNRigidBodies();
129          
130          for (int j=0; j < nRigidBodiesInStamp; j++) {
131 <          rbStamp = molStamp->getRigidBody(j);
131 >          rbStamp = molStamp->getRigidBodyStamp(j);
132            nAtomsInRigidBodies += rbStamp->getNMembers();
133          }
134  
# Line 167 | Line 167 | namespace oopse {
167      }
168      molecules_.clear();
169        
170    delete stamps_;
170      delete sman_;
171      delete simParams_;
172      delete forceField_;
# Line 274 | Line 273 | namespace oopse {
273            }
274          }
275              
276 <      }//end for (integrableObject)
277 <    }// end for (mol)
276 >      }
277 >    }
278      
279      // n_constraints is local, so subtract them on each processor
280      ndf_local -= nConstraints_;
# Line 292 | Line 291 | namespace oopse {
291  
292    }
293  
294 +  int SimInfo::getFdf() {
295 + #ifdef IS_MPI
296 +    MPI_Allreduce(&fdf_local,&fdf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
297 + #else
298 +    fdf_ = fdf_local;
299 + #endif
300 +    return fdf_;
301 +  }
302 +    
303    void SimInfo::calcNdfRaw() {
304      int ndfRaw_local;
305  
# Line 595 | Line 603 | namespace oopse {
603      
604      setupElectrostaticSummationMethod( isError );
605      setupSwitchingFunction();
606 +    setupAccumulateBoxDipole();
607  
608      if(isError){
609        sprintf( painCave.errMsg,
# Line 654 | Line 663 | namespace oopse {
663      int usePBC = simParams_->getUsePeriodicBoundaryConditions();
664      int useRF;
665      int useSF;
666 +    int useSP;
667 +    int useBoxDipole;
668      std::string myMethod;
669  
670      // set the useRF logical
# Line 664 | Line 675 | namespace oopse {
675      if (simParams_->haveElectrostaticSummationMethod()) {
676        std::string myMethod = simParams_->getElectrostaticSummationMethod();
677        toUpper(myMethod);
678 <      if (myMethod == "REACTION_FIELD") {
678 >      if (myMethod == "REACTION_FIELD"){
679          useRF=1;
680 <      } else {
681 <        if (myMethod == "SHIFTED_FORCE") {
682 <          useSF = 1;
683 <        }
680 >      } else if (myMethod == "SHIFTED_FORCE"){
681 >        useSF = 1;
682 >      } else if (myMethod == "SHIFTED_POTENTIAL"){
683 >        useSP = 1;
684        }
685      }
686 +    
687 +    if (simParams_->haveAccumulateBoxDipole())
688 +      if (simParams_->getAccumulateBoxDipole())
689 +        useBoxDipole = 1;
690  
691      //loop over all of the atom types
692      for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
# Line 742 | Line 757 | namespace oopse {
757      MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
758  
759      temp = useSF;
760 <    MPI_Allreduce(&temp, &useSF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
760 >    MPI_Allreduce(&temp, &useSF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);  
761  
762 +    temp = useSP;
763 +    MPI_Allreduce(&temp, &useSP, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
764 +
765 +    temp = useBoxDipole;
766 +    MPI_Allreduce(&temp, &useBoxDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
767 +
768   #endif
769  
770      fInfo_.SIM_uses_PBC = usePBC;    
# Line 761 | Line 782 | namespace oopse {
782      fInfo_.SIM_uses_FLARB = useFLARB;
783      fInfo_.SIM_uses_RF = useRF;
784      fInfo_.SIM_uses_SF = useSF;
785 +    fInfo_.SIM_uses_SP = useSP;
786 +    fInfo_.SIM_uses_BoxDipole = useBoxDipole;
787  
788      if( myMethod == "REACTION_FIELD") {
789        
# Line 792 | Line 815 | namespace oopse {
815      }
816  
817      //calculate mass ratio of cutoff group
818 <    std::vector<double> mfact;
818 >    std::vector<RealType> mfact;
819      SimInfo::MoleculeIterator mi;
820      Molecule* mol;
821      Molecule::CutoffGroupIterator ci;
822      CutoffGroup* cg;
823      Molecule::AtomIterator ai;
824      Atom* atom;
825 <    double totalMass;
825 >    RealType totalMass;
826  
827      //to avoid memory reallocation, reserve enough space for mfact
828      mfact.reserve(getNCutoffGroups());
# Line 924 | Line 947 | namespace oopse {
947  
948    void SimInfo::setupCutoff() {          
949      
950 +    ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
951 +
952      // Check the cutoff policy
953 <    int cp =  TRADITIONAL_CUTOFF_POLICY;
954 <    if (simParams_->haveCutoffPolicy()) {
955 <      std::string myPolicy = simParams_->getCutoffPolicy();
953 >    int cp =  TRADITIONAL_CUTOFF_POLICY; // Set to traditional by default
954 >
955 >    std::string myPolicy;
956 >    if (forceFieldOptions_.haveCutoffPolicy()){
957 >      myPolicy = forceFieldOptions_.getCutoffPolicy();
958 >    }else if (simParams_->haveCutoffPolicy()) {
959 >      myPolicy = simParams_->getCutoffPolicy();
960 >    }
961 >
962 >    if (!myPolicy.empty()){
963        toUpper(myPolicy);
964        if (myPolicy == "MIX") {
965          cp = MIX_CUTOFF_POLICY;
# Line 950 | Line 982 | namespace oopse {
982      notifyFortranCutoffPolicy(&cp);
983  
984      // Check the Skin Thickness for neighborlists
985 <    double skin;
985 >    RealType skin;
986      if (simParams_->haveSkinThickness()) {
987        skin = simParams_->getSkinThickness();
988        notifyFortranSkinThickness(&skin);
# Line 962 | Line 994 | namespace oopse {
994        if (simParams_->haveSwitchingRadius()) {
995          rsw_  = simParams_->getSwitchingRadius();
996        } else {
997 <        rsw_ = rcut_;
997 >        if (fInfo_.SIM_uses_Charges |
998 >            fInfo_.SIM_uses_Dipoles |
999 >            fInfo_.SIM_uses_RF) {
1000 >          
1001 >          rsw_ = 0.85 * rcut_;
1002 >          sprintf(painCave.errMsg,
1003 >                  "SimCreator Warning: No value was set for the switchingRadius.\n"
1004 >                  "\tOOPSE will use a default value of 85 percent of the cutoffRadius.\n"
1005 >                  "\tswitchingRadius = %f. for this simulation\n", rsw_);
1006 >        painCave.isFatal = 0;
1007 >        simError();
1008 >        } else {
1009 >          rsw_ = rcut_;
1010 >          sprintf(painCave.errMsg,
1011 >                  "SimCreator Warning: No value was set for the switchingRadius.\n"
1012 >                  "\tOOPSE will use the same value as the cutoffRadius.\n"
1013 >                  "\tswitchingRadius = %f. for this simulation\n", rsw_);
1014 >          painCave.isFatal = 0;
1015 >          simError();
1016 >        }
1017        }
1018 +      
1019        notifyFortranCutoffs(&rcut_, &rsw_);
1020        
1021      } else {
# Line 1020 | Line 1072 | namespace oopse {
1072      int errorOut;
1073      int esm =  NONE;
1074      int sm = UNDAMPED;
1075 <    double alphaVal;
1076 <    double dielectric;
1075 >    RealType alphaVal;
1076 >    RealType dielectric;
1077  
1078      errorOut = isError;
1079      alphaVal = simParams_->getDampingAlpha();
# Line 1092 | Line 1144 | namespace oopse {
1144      
1145      // let's pass some summation method variables to fortran
1146      setElectrostaticSummationMethod( &esm );
1147 <    notifyFortranElectrostaticMethod( &esm );
1147 >    setFortranElectrostaticMethod( &esm );
1148      setScreeningMethod( &sm );
1149      setDampingAlpha( &alphaVal );
1150      setReactionFieldDielectric( &dielectric );
# Line 1125 | Line 1177 | namespace oopse {
1177  
1178    }
1179  
1180 +  void SimInfo::setupAccumulateBoxDipole() {    
1181 +
1182 +    // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true
1183 +    if ( simParams_->haveAccumulateBoxDipole() )
1184 +      if ( simParams_->getAccumulateBoxDipole() ) {
1185 +        setAccumulateBoxDipole();
1186 +        calcBoxDipole_ = true;
1187 +      }
1188 +
1189 +  }
1190 +
1191    void SimInfo::addProperty(GenericData* genData) {
1192      properties_.addProperty(genData);  
1193    }
# Line 1181 | Line 1244 | namespace oopse {
1244      Molecule* mol;
1245  
1246      Vector3d comVel(0.0);
1247 <    double totalMass = 0.0;
1247 >    RealType totalMass = 0.0;
1248      
1249  
1250      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1251 <      double mass = mol->getMass();
1251 >      RealType mass = mol->getMass();
1252        totalMass += mass;
1253        comVel += mass * mol->getComVel();
1254      }  
1255  
1256   #ifdef IS_MPI
1257 <    double tmpMass = totalMass;
1257 >    RealType tmpMass = totalMass;
1258      Vector3d tmpComVel(comVel);    
1259 <    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1260 <    MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1259 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1260 >    MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1261   #endif
1262  
1263      comVel /= totalMass;
# Line 1207 | Line 1270 | namespace oopse {
1270      Molecule* mol;
1271  
1272      Vector3d com(0.0);
1273 <    double totalMass = 0.0;
1273 >    RealType totalMass = 0.0;
1274      
1275      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1276 <      double mass = mol->getMass();
1276 >      RealType mass = mol->getMass();
1277        totalMass += mass;
1278        com += mass * mol->getCom();
1279      }  
1280  
1281   #ifdef IS_MPI
1282 <    double tmpMass = totalMass;
1282 >    RealType tmpMass = totalMass;
1283      Vector3d tmpCom(com);    
1284 <    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1285 <    MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1284 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1285 >    MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1286   #endif
1287  
1288      com /= totalMass;
# Line 1243 | Line 1306 | namespace oopse {
1306        Molecule* mol;
1307        
1308      
1309 <      double totalMass = 0.0;
1309 >      RealType totalMass = 0.0;
1310      
1311  
1312        for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1313 <         double mass = mol->getMass();
1313 >         RealType mass = mol->getMass();
1314           totalMass += mass;
1315           com += mass * mol->getCom();
1316           comVel += mass * mol->getComVel();          
1317        }  
1318        
1319   #ifdef IS_MPI
1320 <      double tmpMass = totalMass;
1320 >      RealType tmpMass = totalMass;
1321        Vector3d tmpCom(com);  
1322        Vector3d tmpComVel(comVel);
1323 <      MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1324 <      MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1325 <      MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1323 >      MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1324 >      MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1325 >      MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1326   #endif
1327        
1328        com /= totalMass;
# Line 1278 | Line 1341 | namespace oopse {
1341     void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){
1342        
1343  
1344 <      double xx = 0.0;
1345 <      double yy = 0.0;
1346 <      double zz = 0.0;
1347 <      double xy = 0.0;
1348 <      double xz = 0.0;
1349 <      double yz = 0.0;
1344 >      RealType xx = 0.0;
1345 >      RealType yy = 0.0;
1346 >      RealType zz = 0.0;
1347 >      RealType xy = 0.0;
1348 >      RealType xz = 0.0;
1349 >      RealType yz = 0.0;
1350        Vector3d com(0.0);
1351        Vector3d comVel(0.0);
1352        
# Line 1295 | Line 1358 | namespace oopse {
1358        Vector3d thisq(0.0);
1359        Vector3d thisv(0.0);
1360  
1361 <      double thisMass = 0.0;
1361 >      RealType thisMass = 0.0;
1362      
1363        
1364        
# Line 1333 | Line 1396 | namespace oopse {
1396   #ifdef IS_MPI
1397        Mat3x3d tmpI(inertiaTensor);
1398        Vector3d tmpAngMom;
1399 <      MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1400 <      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1399 >      MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1400 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1401   #endif
1402                
1403        return;
# Line 1355 | Line 1418 | namespace oopse {
1418        Vector3d thisr(0.0);
1419        Vector3d thisp(0.0);
1420        
1421 <      double thisMass;
1421 >      RealType thisMass;
1422        
1423        for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {        
1424          thisMass = mol->getMass();
# Line 1368 | Line 1431 | namespace oopse {
1431        
1432   #ifdef IS_MPI
1433        Vector3d tmpAngMom;
1434 <      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1434 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1435   #endif
1436        
1437        return angularMomentum;
1438     }
1439    
1440 <  
1440 >  StuntDouble* SimInfo::getIOIndexToIntegrableObject(int index) {
1441 >    return IOIndexToIntegrableObject.at(index);
1442 >  }
1443 >  
1444 >  void SimInfo::setIOIndexToIntegrableObject(const std::vector<StuntDouble*>& v) {
1445 >    IOIndexToIntegrableObject= v;
1446 >  }
1447 >
1448 > /*
1449 >   void SimInfo::setStuntDoubleFromGlobalIndex(std::vector<StuntDouble*> v) {
1450 >      assert( v.size() == nAtoms_ + nRigidBodies_);
1451 >      sdByGlobalIndex_ = v;
1452 >    }
1453 >
1454 >    StuntDouble* SimInfo::getStuntDoubleFromGlobalIndex(int index) {
1455 >      //assert(index < nAtoms_ + nRigidBodies_);
1456 >      return sdByGlobalIndex_.at(index);
1457 >    }  
1458 > */  
1459   }//end namespace oopse
1460  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines