--- trunk/OOPSE/libmdtools/SimInfo.cpp 2004/05/01 18:52:38 1144 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2004/05/11 21:14:26 1158 @@ -42,11 +42,10 @@ SimInfo::SimInfo(){ thermalTime = 0.0; currentTime = 0.0; rCut = 0.0; - ecr = 0.0; - est = 0.0; + rSw = 0.0; haveRcut = 0; - haveEcr = 0; + haveRsw = 0; boxIsInit = 0; resetTime = 1e99; @@ -63,7 +62,8 @@ SimInfo::SimInfo(){ useReactionField = 0; useGB = 0; useEAM = 0; - useMolecularCutoffs = 0; + + haveCutoffGroups = false; excludes = Exclude::Instance(); @@ -448,58 +448,49 @@ void SimInfo::refreshSim(){ #else n_global = n_atoms; #endif - - isError = 0; - - getFortranGroupArray(this, mfact, ngroup, groupList, groupStart); - + + isError = 0; + + getFortranGroupArray(this, mfact, ngroup, groupList, groupStart); + //it may not be a good idea to pass the address of first element in vector + //since c++ standard does not require vector to be stored continously in meomory + //Most of the compilers will organize the memory of vector continously setFsimulation( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl, - &nGlobalExcludes, globalExcludes, molMembershipArray, - &mfact[0], &ngroup, &groupList[0], &groupStart[0], &isError ); - - if( isError ){ - + &nGlobalExcludes, globalExcludes, molMembershipArray, + &mfact[0], &ngroup, &groupList[0], &groupStart[0], &isError); + + if( isError ){ + sprintf( painCave.errMsg, - "There was an error setting the simulation information in fortran.\n" ); + "There was an error setting the simulation information in fortran.\n" ); painCave.isFatal = 1; simError(); } - + #ifdef IS_MPI sprintf( checkPointMsg, "succesfully sent the simulation information to fortran.\n"); MPIcheckPoint(); #endif // is_mpi - + this->ndf = this->getNDF(); this->ndfRaw = this->getNDFraw(); this->ndfTrans = this->getNDFtranslational(); } void SimInfo::setDefaultRcut( double theRcut ){ - + haveRcut = 1; rCut = theRcut; - - ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; - - notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); -} - -void SimInfo::setDefaultEcr( double theEcr ){ - - haveEcr = 1; - ecr = theEcr; + rList = rCut + 1.0; - ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; - - notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); + notifyFortranCutOffs( &rCut, &rSw, &rList ); } -void SimInfo::setDefaultEcr( double theEcr, double theEst ){ +void SimInfo::setDefaultRcut( double theRcut, double theRsw ){ - est = theEst; - setDefaultEcr( theEcr ); + rSw = theRsw; + setDefaultRcut( theRcut ); } @@ -511,8 +502,8 @@ void SimInfo::checkCutOffs( void ){ if( rCut > maxCutoff ){ sprintf( painCave.errMsg, - "LJrcut is too large for the current periodic box.\n" - "\tCurrent Value of LJrcut = %G at time %G\n " + "cutoffRadius is too large for the current periodic box.\n" + "\tCurrent Value of cutoffRadius = %G at time %G\n " "\tThis is larger than half of at least one of the\n" "\tperiodic box vectors. Right now, the Box matrix is:\n" "\n" @@ -525,28 +516,7 @@ void SimInfo::checkCutOffs( void ){ Hmat[2][0], Hmat[2][1], Hmat[2][2]); painCave.isFatal = 1; simError(); - } - - if( haveEcr ){ - if( ecr > maxCutoff ){ - sprintf( painCave.errMsg, - "electrostaticCutoffRadius is too large for the current\n" - "\tperiodic box.\n\n" - "\tCurrent Value of ECR = %G at time %G\n " - "\tThis is larger than half of at least one of the\n" - "\tperiodic box vectors. Right now, the Box matrix is:\n" - "\n" - "\t[ %G %G %G ]\n" - "\t[ %G %G %G ]\n" - "\t[ %G %G %G ]\n", - ecr, currentTime, - Hmat[0][0], Hmat[0][1], Hmat[0][2], - Hmat[1][0], Hmat[1][1], Hmat[1][2], - Hmat[2][0], Hmat[2][1], Hmat[2][2]); - painCave.isFatal = 1; - simError(); - } - } + } } else { // initialize this stuff before using it, OK? sprintf( painCave.errMsg, @@ -596,53 +566,71 @@ void getFortranGroupArray(SimInfo* info, vector& mfact, int& ngroup, - vector& groupList, vector& groupStart){ - Molecule* mol; + vector& groupList, vector& groupStart){ + Molecule* myMols; + Atom** myAtoms; int numAtom; int curIndex; - + double mtot; + int numMol; + int numCutoffGroups; + CutoffGroup* myCutoffGroup; + vector::iterator iterCutoff; + Atom* cutoffAtom; + vector::iterator iterAtom; + int atomIndex; + double totalMass; + mfact.clear(); groupList.clear(); groupStart.clear(); - + //Be careful, fortran array begin at 1 curIndex = 1; + + myMols = info->molecules; + numMol = info->n_mol; + for(int i = 0; i < numMol; i++){ + numAtom = myMols[i].getNAtoms(); + myAtoms = myMols[i].getMyAtoms(); + - if(info->useMolecularCutoffs){ - //if using molecular cutoff - ngroup = info->n_mol; + for(int j = 0; j < numAtom; j++){ - for(int i = 0; i < ngroup; i ++){ - mol = &(info->molecules[i]); - numAtom = mol->getNAtoms(); - - for(int j=0; j < numAtom; j++){ -#ifdef IS_MPI - groupList.push_back((info->atoms[i])->getGlobalIndex() + 1); + +#ifdef IS_MPI + atomIndex = myAtoms[j]->getGlobalIndex(); #else - groupList.push_back((info->atoms[i])->getIndex() + 1); + atomIndex = myAtoms[j]->getIndex(); #endif - }//for(int j=0; j < numAtom; j++) - - groupStart.push_back(curIndex); - curIndex += numAtom; + + if(myMols[i].belongToCutoffGroup(atomIndex)) + continue; + else{ + mfact.push_back(myAtoms[j]->getMass()); + groupList.push_back(myAtoms[j]->getIndex() + 1); + groupStart.push_back(curIndex++); + } + } - }//end for(int i =0 ; i < ngroup; i++) - } - else{ - //using atomic cutoff, every single atom is just a group - ngroup = info->n_atoms; - for(int i =0 ; i < ngroup; i++){ - groupStart.push_back(curIndex++); + numCutoffGroups = myMols[i].getNCutoffGroups(); + for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff); myCutoffGroup != NULL; + myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){ -#ifdef IS_MPI - groupList.push_back((info->atoms[i])->getGlobalIndex() + 1); -#else - groupList.push_back((info->atoms[i])->getIndex() + 1); -#endif + totalMass = myCutoffGroup->getMass(); + + for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom); cutoffAtom != NULL; + cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){ + mfact.push_back(cutoffAtom->getMass()/totalMass); + groupList.push_back(cutoffAtom->getIndex() + 1); + } + + groupStart.push_back(curIndex); + curIndex += myCutoffGroup->getNumAtom(); - }//end for(int i =0 ; i < ngroup; i++) + }//end for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff)) - }//end if (info->useMolecularCutoffs) - + }//end for(int i = 0; i < numMol; i++) + + ngroup = groupStart.size(); }