ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/brains/SimInfo.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/brains/SimInfo.cpp (file contents):
Revision 1824 by tim, Thu Dec 2 03:12:25 2004 UTC vs.
Revision 1883 by tim, Mon Dec 13 22:30:27 2004 UTC

# Line 39 | Line 39 | namespace oopse {
39   #include "utils/MemoryUtils.hpp"
40   #include "utils/simError.h"
41  
42 + #ifdef IS_MPI
43 + #include "UseTheForce/mpiComponentPlan.h"
44 + #include "UseTheForce/DarkSide/simParallel_interface.h"
45 + #endif
46 +
47   namespace oopse {
48  
49   SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
50 <                                ForceField* ff, Globals* globals) :
51 <                                forceField_(ff), globals_(globals), nAtoms_(0), nBonds_(0),
52 <                                nBends_(0), nTorsions_(0), nRigidBodies_(0), nIntegrableObjects_(0),
53 <                                nCutoffGroups_(0), nConstraints_(0), nZconstraint_(0), sman_(NULL),
54 <                                fortranInitialized_(false) {
50 >                                ForceField* ff, Globals* simParams) :
51 >                                forceField_(ff), simParams_(simParams),
52 >                                ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
53 >                                nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
54 >                                nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
55 >                                nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nRigidBodies_(0),
56 >                                nIntegrableObjects_(0),  nCutoffGroups_(0), nConstraints_(0),
57 >                                sman_(NULL), fortranInitialized_(false) {
58  
59 +            
60      std::vector<std::pair<MoleculeStamp*, int> >::iterator i;
61      MoleculeStamp* molStamp;
62      int nMolWithSameStamp;
63 <    int nCutoffAtoms; // number of atoms belong to cutoff groups
64 <    int nGroups;          //total cutoff groups defined in meta-data file
65 <    CutoffGroupStamp* cgStamp;
57 <    int nAtomsInGroups;
58 <    int nCutoffGroupsInStamp;
59 <    
63 >    int nCutoffAtoms = 0; // number of atoms belong to cutoff groups
64 >    int nGroups = 0;          //total cutoff groups defined in meta-data file
65 >    CutoffGroupStamp* cgStamp;    
66      RigidBodyStamp* rbStamp;
67 <    int nAtomsInRigidBodies;
62 <    int nRigidBodiesInStamp;
63 <    int nRigidAtoms;
64 <    int nRigidBodies;
65 <        
66 <    nGlobalAtoms_ =  0;
67 <    
68 <    nGroups = 0;
69 <    nCutoffAtoms = 0;
70 <    nRigidBodies = 0;
67 >    int nRigidAtoms = 0;
68      
69      for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) {
70          molStamp = i->first;
# Line 80 | Line 77 | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*,
77  
78  
79          //calculate atoms in cutoff groups
80 <        nAtomsInGroups = 0;
81 <        nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
80 >        int nAtomsInGroups = 0;
81 >        int nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
82          
83          for (int j=0; j < nCutoffGroupsInStamp; j++) {
84              cgStamp = molStamp->getCutoffGroup(j);
# Line 92 | Line 89 | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*,
89          nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp;            
90  
91          //calculate atoms in rigid bodies
92 <        nAtomsInRigidBodies = 0;
93 <        nRigidBodiesInStamp = molStamp->getNCutoffGroups();
92 >        int nAtomsInRigidBodies = 0;
93 >        int nRigidBodiesInStamp = molStamp->getNCutoffGroups();
94          
95          for (int j=0; j < nRigidBodiesInStamp; j++) {
96              rbStamp = molStamp->getRigidBody(j);
97 <            nRigidBodiesInStamp += rbStamp->getNMembers();
97 >            nAtomsInRigidBodies += rbStamp->getNMembers();
98          }
99  
100 <        nRigidBodies += nRigidBodiesInStamp * nMolWithSameStamp;
100 >        nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp;
101          nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp;            
102          
103      }
# Line 111 | Line 108 | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*,
108      //file plus the number of cutoff groups defined in meta-data file
109      nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
110  
111 <    //every free atom (atom does not belong to rigid bodies) is a rigid body
112 <    //therefore the total number of cutoff groups in the system is equal to
111 >    //every free atom (atom does not belong to rigid bodies) is an integrable object
112 >    //therefore the total number of  integrable objects in the system is equal to
113      //the total number of atoms minus number of atoms belong to  rigid body defined in meta-data
114      //file plus the number of  rigid bodies defined in meta-data file
115 <    nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nRigidBodies;
115 >    nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nGlobalRigidBodies_;
116  
120    //initialize globalGroupMembership_, every element of this array will be 0
121    globalGroupMembership_.insert(globalGroupMembership_.end(), nGlobalAtoms_, 0);
122
117      nGlobalMols_ = molStampIds_.size();
118  
119   #ifdef IS_MPI    
# Line 134 | Line 128 | SimInfo::~SimInfo() {
128      MemoryUtils::deleteVectorOfPointer(moleculeStamps_);
129      
130      delete sman_;
131 <    delete globals_;
131 >    delete simParams_;
132      delete forceField_;
133  
134   }
# Line 144 | Line 138 | bool SimInfo::addMolecule(Molecule* mol) {
138      MoleculeIterator i;
139  
140      i = molecules_.find(mol->getGlobalIndex());
141 <    if (i != molecules_.end() ) {
141 >    if (i == molecules_.end() ) {
142  
143 <        molecules_.insert(make_pair(mol->getGlobalIndex(), mol));
143 >        molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol));
144          
145          nAtoms_ += mol->getNAtoms();
146          nBonds_ += mol->getNBonds();
# Line 157 | Line 151 | bool SimInfo::addMolecule(Molecule* mol) {
151          nCutoffGroups_ += mol->getNCutoffGroups();
152          nConstraints_ += mol->getNConstraints();
153  
154 +        addExcludePairs(mol);
155 +        
156          return true;
157      } else {
158          return false;
# Line 180 | Line 176 | bool SimInfo::removeMolecule(Molecule* mol) {
176          nCutoffGroups_ -= mol->getNCutoffGroups();
177          nConstraints_ -= mol->getNConstraints();
178  
179 +        removeExcludePairs(mol);
180          molecules_.erase(mol->getGlobalIndex());
181  
182          delete mol;
# Line 462 | Line 459 | void SimInfo::setupSimType() {
459      int useFLARB = 0; //it is not in AtomType yet
460      int useDirectionalAtom = 0;    
461      int useElectrostatics = 0;
462 <    //usePBC and useRF are from globals
463 <    bool usePBC = globals_->getPBC();
464 <    bool useRF = globals_->getUseRF();
462 >    //usePBC and useRF are from simParams
463 >    bool usePBC = simParams_->getPBC();
464 >    bool useRF = simParams_->getUseRF();
465  
466      //loop over all of the atom types
467      for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
# Line 543 | Line 540 | void SimInfo::setupSimType() {
540  
541      if( fInfo_.SIM_uses_Dipoles && fInfo_.SIM_uses_RF) {
542  
543 <        if (globals_->haveDielectric()) {
544 <            fInfo_.dielect = globals_->getDielectric();
543 >        if (simParams_->haveDielectric()) {
544 >            fInfo_.dielect = simParams_->getDielectric();
545          } else {
546              sprintf(painCave.errMsg,
547                      "SimSetup Error: No Dielectric constant was set.\n"
# Line 613 | Line 610 | void SimInfo::setupFortranSim() {
610      //molMembershipArray is filled by SimCreator    
611      std::vector<int> molMembershipArray(nGlobalAtoms_);
612      for (int i = 0; i < nGlobalAtoms_; i++) {
613 <        molMembershipArray.push_back(globalMolMembership_[i] + 1);
613 >        molMembershipArray[i] = globalMolMembership_[i] + 1;
614      }
615      
616      //setup fortran simulation
# Line 681 | Line 678 | void SimInfo::setupFortranParallel() {
678      parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
679      parallelData.nGroupsLocal = getNCutoffGroups();
680      parallelData.myNode = worldRank;
681 <    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData->nProcessors));
681 >    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
682  
683      //pass mpiSimData struct and index arrays to fortran
684 <    setFsimParallel(parallelData, &(parallelData->nAtomsLocal),
685 <                    &localToGlobalAtomIndex[0],  &(parallelData->nGroupsLocal),
684 >    setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
685 >                    &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal),
686                      &localToGlobalCutoffGroupIndex[0], &isError);
687  
688      if (isError) {
# Line 732 | Line 729 | void SimInfo::setupCutoff() {
729      
730      if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
731          
732 <        if (!globals_->haveRcut()){
732 >        if (!simParams_->haveRcut()){
733              sprintf(painCave.errMsg,
734                  "SimCreator Warning: No value was set for the cutoffRadius.\n"
735                  "\tOOPSE will use a default value of 15.0 angstroms"
# Line 741 | Line 738 | void SimInfo::setupCutoff() {
738              simError();
739              rcut_ = 15.0;
740          } else{
741 <            rcut_ = globals_->getRcut();
741 >            rcut_ = simParams_->getRcut();
742          }
743  
744 <        if (!globals_->haveRsw()){
744 >        if (!simParams_->haveRsw()){
745              sprintf(painCave.errMsg,
746                  "SimCreator Warning: No value was set for switchingRadius.\n"
747                  "\tOOPSE will use a default value of\n"
# Line 753 | Line 750 | void SimInfo::setupCutoff() {
750              simError();
751              rsw_ = 0.95 * rcut_;
752          } else{
753 <            rsw_ = globals_->getRsw();
753 >            rsw_ = simParams_->getRsw();
754          }
755  
756      } else {
757          // if charge, dipole or reaction field is not used and the cutofff radius is not specified in
758          //meta-data file, the maximum cutoff radius calculated from forcefiled will be used
759          
760 <        if (globals_->haveRcut()) {
761 <            rcut_ = globals_->getRcut();
760 >        if (simParams_->haveRcut()) {
761 >            rcut_ = simParams_->getRcut();
762          } else {
763              //set cutoff radius to the maximum cutoff radius based on atom types in the whole system
764              rcut_ = calcMaxCutoffRadius();
765          }
766  
767 <        if (globals_->haveRsw()) {
768 <            rsw_  = globals_->getRsw();
767 >        if (simParams_->haveRsw()) {
768 >            rsw_  = simParams_->getRsw();
769          } else {
770              rsw_ = rcut_;
771          }
# Line 828 | Line 825 | std::ostream& operator <<(ostream& o, SimInfo& info) {
825      
826   }
827  
828 < std::ostream& operator <<(ostream& o, SimInfo& info) {
828 > Vector3d SimInfo::getComVel(){
829 >    SimInfo::MoleculeIterator i;
830 >    Molecule* mol;
831  
832 +    Vector3d comVel(0.0);
833 +    double totalMass = 0.0;
834 +    
835 +
836 +    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
837 +        double mass = mol->getMass();
838 +        totalMass += mass;
839 +        comVel += mass * mol->getComVel();
840 +    }  
841 +
842 +    comVel /= totalMass;
843 +
844 +    return comVel;
845 + }
846 +
847 + Vector3d SimInfo::getCom(){
848 +    SimInfo::MoleculeIterator i;
849 +    Molecule* mol;
850 +
851 +    Vector3d com(0.0);
852 +    double totalMass = 0.0;
853 +    
854 +    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
855 +        double mass = mol->getMass();
856 +        totalMass += mass;
857 +        com += mass * mol->getCom();
858 +    }  
859 +
860 +    com /= totalMass;
861 +
862 +    return com;
863 +
864 + }        
865 +
866 + std::ostream& operator <<(std::ostream& o, SimInfo& info) {
867 +
868      return o;
869   }
870  
871   }//end namespace oopse
872 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines