--- trunk/OOPSE/libmdtools/SimInfo.cpp 2004/04/12 20:32:20 1097 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2004/05/11 16:00:22 1154 @@ -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; @@ -70,6 +69,8 @@ SimInfo::SimInfo(){ has_minimizer = false; the_minimizer =NULL; + + ngroup = 0; wrapMeSimInfo( this ); } @@ -83,7 +84,7 @@ SimInfo::~SimInfo(){ for(i = properties.begin(); i != properties.end(); i++) delete (*i).second; - + } void SimInfo::setBox(double newBox[3]) { @@ -322,10 +323,16 @@ int SimInfo::getNDF(){ int SimInfo::getNDF(){ int ndf_local; + ndf_local = 0; + for(int i = 0; i < integrableObjects.size(); i++){ ndf_local += 3; - if (integrableObjects[i]->isDirectional()) - ndf_local += 3; + if (integrableObjects[i]->isDirectional()) { + if (integrableObjects[i]->isLinear()) + ndf_local += 2; + else + ndf_local += 3; + } } // n_constraints is local, so subtract them on each processor: @@ -350,11 +357,16 @@ int SimInfo::getNDFraw() { int ndfRaw_local; // Raw degrees of freedom that we have to set + ndfRaw_local = 0; for(int i = 0; i < integrableObjects.size(); i++){ ndfRaw_local += 3; - if (integrableObjects[i]->isDirectional()) - ndfRaw_local += 3; + if (integrableObjects[i]->isDirectional()) { + if (integrableObjects[i]->isLinear()) + ndfRaw_local += 2; + else + ndfRaw_local += 3; + } } #ifdef IS_MPI @@ -383,6 +395,23 @@ int SimInfo::getNDFtranslational() { return ndfTrans; } +int SimInfo::getTotIntegrableObjects() { + int nObjs_local; + int nObjs; + + nObjs_local = integrableObjects.size(); + + +#ifdef IS_MPI + MPI_Allreduce(&nObjs_local,&nObjs,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); +#else + nObjs = nObjs_local; +#endif + + + return nObjs; +} + void SimInfo::refreshSim(){ simtype fInfo; @@ -411,62 +440,53 @@ void SimInfo::refreshSim(){ n_exclude = excludes->getSize(); excl = excludes->getFortranArray(); - + #ifdef IS_MPI n_global = mpiSim->getTotAtoms(); #else n_global = n_atoms; #endif - + isError = 0; - + + getFortranGroupArray(this, mfact, ngroup, groupList, groupStart); + setFsimulation( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl, - &nGlobalExcludes, globalExcludes, molMembershipArray, - &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 ); } @@ -478,42 +498,21 @@ 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, %G" + "\n" "\t[ %G %G %G ]\n" "\t[ %G %G %G ]\n" "\t[ %G %G %G ]\n", - rCut, currentTime, maxCutoff, + rCut, 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(); - } - - 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, @@ -561,13 +560,68 @@ GenericData* SimInfo::getProperty(const string& propNa return NULL; } -vector SimInfo::getProperties(){ - vector result; - map::iterator i; +void getFortranGroupArray(SimInfo* info, vector& mfact, int& ngroup, + vector& groupList, vector& groupStart){ + Molecule* mol; + Atom** myAtoms; + int numAtom; + int curIndex; + double mtot; + + mfact.clear(); + groupList.clear(); + groupStart.clear(); - for(i = properties.begin(); i != properties.end(); i++) - result.push_back((*i).second); + //Be careful, fortran array begin at 1 + curIndex = 1; + + if(info->useMolecularCutoffs){ - return result; +#ifdef IS_MPI + ngroup = mpiSim->getMyNMol(); +#else + ngroup = info->n_mol; +#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); + + } + + groupStart.push_back(curIndex); + curIndex += numAtom; + + } //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) + }