--- trunk/OOPSE/libmdtools/SimInfo.cpp 2004/05/11 16:00:22 1154 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2004/05/12 14:30:12 1163 @@ -62,6 +62,8 @@ SimInfo::SimInfo(){ useReactionField = 0; useGB = 0; useEAM = 0; + + haveCutoffGroups = false; excludes = Exclude::Instance(); @@ -450,7 +452,9 @@ void SimInfo::refreshSim(){ 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); @@ -563,65 +567,71 @@ void getFortranGroupArray(SimInfo* info, vector& mfact, int& ngroup, vector& groupList, vector& groupStart){ - Molecule* mol; + 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; - - if(info->useMolecularCutoffs){ - -#ifdef IS_MPI - ngroup = mpiSim->getMyNMol(); + + myMols = info->molecules; + numMol = info->n_mol; + for(int i = 0; i < numMol; i++){ + numAtom = myMols[i].getNAtoms(); + myAtoms = myMols[i].getMyAtoms(); + + + for(int j = 0; j < numAtom; j++){ + + +#ifdef IS_MPI + atomIndex = myAtoms[j]->getGlobalIndex(); #else - ngroup = info->n_mol; + atomIndex = myAtoms[j]->getIndex(); #endif - - for(int i = 0; i < ngroup; i ++){ - mol = &(info->molecules[i]); - numAtom = mol->getNAtoms(); - myAtoms = mol->getMyAtoms(); - mtot = 0.0; - for(int j=0; j < numAtom; j++) - mtot += myAtoms[j]->getMass(); - - for(int j=0; j < numAtom; j++){ - - // We want the local Index: - groupList.push_back(myAtoms[j]->getIndex() + 1); - mfact.push_back(myAtoms[j]->getMass() / mtot); - + if(myMols[i].belongToCutoffGroup(atomIndex)) + continue; + else{ + // this is a fraction of the cutoff group's mass, not the mass itself! + mfact.push_back(1.0); + groupList.push_back(myAtoms[j]->getIndex() + 1); + groupStart.push_back(curIndex++); } + } - groupStart.push_back(curIndex); - curIndex += numAtom; + numCutoffGroups = myMols[i].getNCutoffGroups(); + for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff); myCutoffGroup != NULL; + myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){ + + totalMass = myCutoffGroup->getMass(); - } //end for(int i =0 ; i < ngroup; i++) - } - else{ - //using atomic cutoff, every single atom is just a group - -#ifdef IS_MPI - ngroup = mpiSim->getMyNlocal(); -#else - ngroup = info->n_atoms; -#endif - - for(int i =0 ; i < ngroup; i++){ - groupStart.push_back(curIndex++); - groupList.push_back((info->atoms[i])->getIndex() + 1); - mfact.push_back(1.0); - - }//end for(int i =0 ; i < ngroup; i++) - - }//end if (info->useMolecularCutoffs) + 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(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff)) + + }//end for(int i = 0; i < numMol; i++) + ngroup = groupStart.size(); }