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 963 by tim, Wed May 17 21:51:42 2006 UTC

# Line 63 | Line 63
63   #include "utils/MemoryUtils.hpp"
64   #include "utils/simError.h"
65   #include "selection/SelectionManager.hpp"
66 + #include "io/ForceFieldOptions.hpp"
67 + #include "UseTheForce/ForceField.hpp"
68  
69   #ifdef IS_MPI
70   #include "UseTheForce/mpiComponentPlan.h"
# Line 80 | Line 82 | namespace oopse {
82      return result;
83    }
84    
85 <  SimInfo::SimInfo(MakeStamps* stamps, std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
86 <                   ForceField* ff, Globals* simParams) :
87 <    stamps_(stamps), forceField_(ff), simParams_(simParams),
86 <    ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
85 >  SimInfo::SimInfo(ForceField* ff, Globals* simParams) :
86 >    forceField_(ff), simParams_(simParams),
87 >    ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
88      nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
89      nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
90      nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nRigidBodies_(0),
91      nIntegrableObjects_(0),  nCutoffGroups_(0), nConstraints_(0),
92      sman_(NULL), fortranInitialized_(false) {
93  
93            
94      std::vector<std::pair<MoleculeStamp*, int> >::iterator i;
94        MoleculeStamp* molStamp;
95        int nMolWithSameStamp;
96        int nCutoffAtoms = 0; // number of atoms belong to cutoff groups
# Line 99 | Line 98 | namespace oopse {
98        CutoffGroupStamp* cgStamp;    
99        RigidBodyStamp* rbStamp;
100        int nRigidAtoms = 0;
101 <    
102 <      for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) {
103 <        molStamp = i->first;
104 <        nMolWithSameStamp = i->second;
101 >      std::vector<Component*> components = simParams->getComponents();
102 >      
103 >      for (std::vector<Component*>::iterator i = components.begin(); i !=components.end(); ++i) {
104 >        molStamp = (*i)->getMoleculeStamp();
105 >        nMolWithSameStamp = (*i)->getNMol();
106          
107          addMoleculeStamp(molStamp, nMolWithSameStamp);
108  
109          //calculate atoms in molecules
110          nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;  
111  
112
112          //calculate atoms in cutoff groups
113          int nAtomsInGroups = 0;
114          int nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
115          
116          for (int j=0; j < nCutoffGroupsInStamp; j++) {
117 <          cgStamp = molStamp->getCutoffGroup(j);
117 >          cgStamp = molStamp->getCutoffGroupStamp(j);
118            nAtomsInGroups += cgStamp->getNMembers();
119          }
120  
# Line 128 | Line 127 | namespace oopse {
127          int nRigidBodiesInStamp = molStamp->getNRigidBodies();
128          
129          for (int j=0; j < nRigidBodiesInStamp; j++) {
130 <          rbStamp = molStamp->getRigidBody(j);
130 >          rbStamp = molStamp->getRigidBodyStamp(j);
131            nAtomsInRigidBodies += rbStamp->getNMembers();
132          }
133  
# Line 167 | Line 166 | namespace oopse {
166      }
167      molecules_.clear();
168        
170    delete stamps_;
169      delete sman_;
170      delete simParams_;
171      delete forceField_;
# Line 274 | Line 272 | namespace oopse {
272            }
273          }
274              
275 <      }//end for (integrableObject)
276 <    }// end for (mol)
275 >      }
276 >    }
277      
278      // n_constraints is local, so subtract them on each processor
279      ndf_local -= nConstraints_;
# Line 292 | Line 290 | namespace oopse {
290  
291    }
292  
293 +  int SimInfo::getFdf() {
294 + #ifdef IS_MPI
295 +    MPI_Allreduce(&fdf_local,&fdf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
296 + #else
297 +    fdf_ = fdf_local;
298 + #endif
299 +    return fdf_;
300 +  }
301 +    
302    void SimInfo::calcNdfRaw() {
303      int ndfRaw_local;
304  
# Line 792 | Line 799 | namespace oopse {
799      }
800  
801      //calculate mass ratio of cutoff group
802 <    std::vector<double> mfact;
802 >    std::vector<RealType> mfact;
803      SimInfo::MoleculeIterator mi;
804      Molecule* mol;
805      Molecule::CutoffGroupIterator ci;
806      CutoffGroup* cg;
807      Molecule::AtomIterator ai;
808      Atom* atom;
809 <    double totalMass;
809 >    RealType totalMass;
810  
811      //to avoid memory reallocation, reserve enough space for mfact
812      mfact.reserve(getNCutoffGroups());
# Line 924 | Line 931 | namespace oopse {
931  
932    void SimInfo::setupCutoff() {          
933      
934 +    ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
935 +
936      // Check the cutoff policy
937 <    int cp =  TRADITIONAL_CUTOFF_POLICY;
938 <    if (simParams_->haveCutoffPolicy()) {
939 <      std::string myPolicy = simParams_->getCutoffPolicy();
937 >    int cp =  TRADITIONAL_CUTOFF_POLICY; // Set to traditional by default
938 >
939 >    std::string myPolicy;
940 >    if (forceFieldOptions_.haveCutoffPolicy()){
941 >      myPolicy = forceFieldOptions_.getCutoffPolicy();
942 >    }else if (simParams_->haveCutoffPolicy()) {
943 >      myPolicy = simParams_->getCutoffPolicy();
944 >    }
945 >
946 >    if (!myPolicy.empty()){
947        toUpper(myPolicy);
948        if (myPolicy == "MIX") {
949          cp = MIX_CUTOFF_POLICY;
# Line 950 | Line 966 | namespace oopse {
966      notifyFortranCutoffPolicy(&cp);
967  
968      // Check the Skin Thickness for neighborlists
969 <    double skin;
969 >    RealType skin;
970      if (simParams_->haveSkinThickness()) {
971        skin = simParams_->getSkinThickness();
972        notifyFortranSkinThickness(&skin);
# Line 962 | Line 978 | namespace oopse {
978        if (simParams_->haveSwitchingRadius()) {
979          rsw_  = simParams_->getSwitchingRadius();
980        } else {
981 <        rsw_ = rcut_;
981 >        if (fInfo_.SIM_uses_Charges |
982 >            fInfo_.SIM_uses_Dipoles |
983 >            fInfo_.SIM_uses_RF) {
984 >          
985 >          rsw_ = 0.85 * rcut_;
986 >          sprintf(painCave.errMsg,
987 >                  "SimCreator Warning: No value was set for the switchingRadius.\n"
988 >                  "\tOOPSE will use a default value of 85 percent of the cutoffRadius.\n"
989 >                  "\tswitchingRadius = %f. for this simulation\n", rsw_);
990 >        painCave.isFatal = 0;
991 >        simError();
992 >        } else {
993 >          rsw_ = rcut_;
994 >          sprintf(painCave.errMsg,
995 >                  "SimCreator Warning: No value was set for the switchingRadius.\n"
996 >                  "\tOOPSE will use the same value as the cutoffRadius.\n"
997 >                  "\tswitchingRadius = %f. for this simulation\n", rsw_);
998 >          painCave.isFatal = 0;
999 >          simError();
1000 >        }
1001        }
1002 +      
1003        notifyFortranCutoffs(&rcut_, &rsw_);
1004        
1005      } else {
# Line 1020 | Line 1056 | namespace oopse {
1056      int errorOut;
1057      int esm =  NONE;
1058      int sm = UNDAMPED;
1059 <    double alphaVal;
1060 <    double dielectric;
1059 >    RealType alphaVal;
1060 >    RealType dielectric;
1061  
1062      errorOut = isError;
1063      alphaVal = simParams_->getDampingAlpha();
# Line 1092 | Line 1128 | namespace oopse {
1128      
1129      // let's pass some summation method variables to fortran
1130      setElectrostaticSummationMethod( &esm );
1131 <    notifyFortranElectrostaticMethod( &esm );
1131 >    setFortranElectrostaticMethod( &esm );
1132      setScreeningMethod( &sm );
1133      setDampingAlpha( &alphaVal );
1134      setReactionFieldDielectric( &dielectric );
# Line 1181 | Line 1217 | namespace oopse {
1217      Molecule* mol;
1218  
1219      Vector3d comVel(0.0);
1220 <    double totalMass = 0.0;
1220 >    RealType totalMass = 0.0;
1221      
1222  
1223      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1224 <      double mass = mol->getMass();
1224 >      RealType mass = mol->getMass();
1225        totalMass += mass;
1226        comVel += mass * mol->getComVel();
1227      }  
1228  
1229   #ifdef IS_MPI
1230 <    double tmpMass = totalMass;
1230 >    RealType tmpMass = totalMass;
1231      Vector3d tmpComVel(comVel);    
1232 <    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1233 <    MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1232 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1233 >    MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1234   #endif
1235  
1236      comVel /= totalMass;
# Line 1207 | Line 1243 | namespace oopse {
1243      Molecule* mol;
1244  
1245      Vector3d com(0.0);
1246 <    double totalMass = 0.0;
1246 >    RealType totalMass = 0.0;
1247      
1248      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1249 <      double mass = mol->getMass();
1249 >      RealType mass = mol->getMass();
1250        totalMass += mass;
1251        com += mass * mol->getCom();
1252      }  
1253  
1254   #ifdef IS_MPI
1255 <    double tmpMass = totalMass;
1255 >    RealType tmpMass = totalMass;
1256      Vector3d tmpCom(com);    
1257 <    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1258 <    MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1257 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1258 >    MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1259   #endif
1260  
1261      com /= totalMass;
# Line 1243 | Line 1279 | namespace oopse {
1279        Molecule* mol;
1280        
1281      
1282 <      double totalMass = 0.0;
1282 >      RealType totalMass = 0.0;
1283      
1284  
1285        for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1286 <         double mass = mol->getMass();
1286 >         RealType mass = mol->getMass();
1287           totalMass += mass;
1288           com += mass * mol->getCom();
1289           comVel += mass * mol->getComVel();          
1290        }  
1291        
1292   #ifdef IS_MPI
1293 <      double tmpMass = totalMass;
1293 >      RealType tmpMass = totalMass;
1294        Vector3d tmpCom(com);  
1295        Vector3d tmpComVel(comVel);
1296 <      MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1297 <      MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1298 <      MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1296 >      MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1297 >      MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1298 >      MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1299   #endif
1300        
1301        com /= totalMass;
# Line 1278 | Line 1314 | namespace oopse {
1314     void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){
1315        
1316  
1317 <      double xx = 0.0;
1318 <      double yy = 0.0;
1319 <      double zz = 0.0;
1320 <      double xy = 0.0;
1321 <      double xz = 0.0;
1322 <      double yz = 0.0;
1317 >      RealType xx = 0.0;
1318 >      RealType yy = 0.0;
1319 >      RealType zz = 0.0;
1320 >      RealType xy = 0.0;
1321 >      RealType xz = 0.0;
1322 >      RealType yz = 0.0;
1323        Vector3d com(0.0);
1324        Vector3d comVel(0.0);
1325        
# Line 1295 | Line 1331 | namespace oopse {
1331        Vector3d thisq(0.0);
1332        Vector3d thisv(0.0);
1333  
1334 <      double thisMass = 0.0;
1334 >      RealType thisMass = 0.0;
1335      
1336        
1337        
# Line 1333 | Line 1369 | namespace oopse {
1369   #ifdef IS_MPI
1370        Mat3x3d tmpI(inertiaTensor);
1371        Vector3d tmpAngMom;
1372 <      MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1373 <      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1372 >      MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1373 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1374   #endif
1375                
1376        return;
# Line 1355 | Line 1391 | namespace oopse {
1391        Vector3d thisr(0.0);
1392        Vector3d thisp(0.0);
1393        
1394 <      double thisMass;
1394 >      RealType thisMass;
1395        
1396        for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {        
1397          thisMass = mol->getMass();
# Line 1368 | Line 1404 | namespace oopse {
1404        
1405   #ifdef IS_MPI
1406        Vector3d tmpAngMom;
1407 <      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1407 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1408   #endif
1409        
1410        return angularMomentum;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines