--- trunk/OOPSE/libmdtools/SimInfo.cpp 2004/01/13 23:01:43 941 +++ trunk/OOPSE/libmdtools/SimInfo.cpp 2004/05/11 21:14:26 1158 @@ -12,6 +12,8 @@ using namespace std; #include "fortranWrappers.hpp" +#include "MatVec3.h" + #ifdef IS_MPI #include "mpiSimulation.hpp" #endif @@ -27,7 +29,7 @@ SimInfo::SimInfo(){ SimInfo* currentInfo; SimInfo::SimInfo(){ - excludes = NULL; + n_constraints = 0; nZconstraints = 0; n_oriented = 0; @@ -40,15 +42,15 @@ 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; + orthoRhombic = 0; orthoTolerance = 1E-6; useInitXSstate = true; @@ -60,9 +62,18 @@ SimInfo::SimInfo(){ useReactionField = 0; useGB = 0; useEAM = 0; + + haveCutoffGroups = false; + excludes = Exclude::Instance(); + myConfiguration = new SimState(); + has_minimizer = false; + the_minimizer =NULL; + + ngroup = 0; + wrapMeSimInfo( this ); } @@ -75,7 +86,7 @@ SimInfo::~SimInfo(){ for(i = properties.begin(); i != properties.end(); i++) delete (*i).second; - + } void SimInfo::setBox(double newBox[3]) { @@ -180,142 +191,28 @@ void SimInfo::calcHmatInv( void ) { if( orthoRhombic ){ sprintf( painCave.errMsg, - "Hmat is switching from Non-Orthorhombic to OrthoRhombic\n" - " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", + "OOPSE is switching from the default Non-Orthorhombic\n" + "\tto the faster Orthorhombic periodic boundary computations.\n" + "\tThis is usually a good thing, but if you wan't the\n" + "\tNon-Orthorhombic computations, make the orthoBoxTolerance\n" + "\tvariable ( currently set to %G ) smaller.\n", orthoTolerance); simError(); } else { sprintf( painCave.errMsg, - "Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" - " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", + "OOPSE is switching from the faster Orthorhombic to the more\n" + "\tflexible Non-Orthorhombic periodic boundary computations.\n" + "\tThis is usually because the box has deformed under\n" + "\tNPTf integration. If you wan't to live on the edge with\n" + "\tthe Orthorhombic computations, make the orthoBoxTolerance\n" + "\tvariable ( currently set to %G ) larger.\n", orthoTolerance); simError(); - } - } -} - -double SimInfo::matDet3(double a[3][3]) { - int i, j, k; - double determinant; - - determinant = 0.0; - - for(i = 0; i < 3; i++) { - j = (i+1)%3; - k = (i+2)%3; - - determinant += a[0][i] * (a[1][j]*a[2][k] - a[1][k]*a[2][j]); - } - - return determinant; -} - -void SimInfo::invertMat3(double a[3][3], double b[3][3]) { - - int i, j, k, l, m, n; - double determinant; - - determinant = matDet3( a ); - - if (determinant == 0.0) { - sprintf( painCave.errMsg, - "Can't invert a matrix with a zero determinant!\n"); - painCave.isFatal = 1; - simError(); - } - - for (i=0; i < 3; i++) { - j = (i+1)%3; - k = (i+2)%3; - for(l = 0; l < 3; l++) { - m = (l+1)%3; - n = (l+2)%3; - - b[l][i] = (a[j][m]*a[k][n] - a[j][n]*a[k][m]) / determinant; - } - } -} - -void SimInfo::matMul3(double a[3][3], double b[3][3], double c[3][3]) { - double r00, r01, r02, r10, r11, r12, r20, r21, r22; - - r00 = a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0]; - r01 = a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1]; - r02 = a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2]; - - r10 = a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0]; - r11 = a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1]; - r12 = a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2]; - - r20 = a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0]; - r21 = a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1]; - r22 = a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2]; - - c[0][0] = r00; c[0][1] = r01; c[0][2] = r02; - c[1][0] = r10; c[1][1] = r11; c[1][2] = r12; - c[2][0] = r20; c[2][1] = r21; c[2][2] = r22; -} - -void SimInfo::matVecMul3(double m[3][3], double inVec[3], double outVec[3]) { - double a0, a1, a2; - - a0 = inVec[0]; a1 = inVec[1]; a2 = inVec[2]; - - outVec[0] = m[0][0]*a0 + m[0][1]*a1 + m[0][2]*a2; - outVec[1] = m[1][0]*a0 + m[1][1]*a1 + m[1][2]*a2; - outVec[2] = m[2][0]*a0 + m[2][1]*a1 + m[2][2]*a2; -} - -void SimInfo::transposeMat3(double in[3][3], double out[3][3]) { - double temp[3][3]; - int i, j; - - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - temp[j][i] = in[i][j]; } } - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - out[i][j] = temp[i][j]; - } - } } - -void SimInfo::printMat3(double A[3][3] ){ - std::cerr - << "[ " << A[0][0] << ", " << A[0][1] << ", " << A[0][2] << " ]\n" - << "[ " << A[1][0] << ", " << A[1][1] << ", " << A[1][2] << " ]\n" - << "[ " << A[2][0] << ", " << A[2][1] << ", " << A[2][2] << " ]\n"; -} - -void SimInfo::printMat9(double A[9] ){ - - std::cerr - << "[ " << A[0] << ", " << A[1] << ", " << A[2] << " ]\n" - << "[ " << A[3] << ", " << A[4] << ", " << A[5] << " ]\n" - << "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; -} - - -void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){ - - out[0] = a[1] * b[2] - a[2] * b[1]; - out[1] = a[2] * b[0] - a[0] * b[2] ; - out[2] = a[0] * b[1] - a[1] * b[0]; - -} - -double SimInfo::dotProduct3(double a[3], double b[3]){ - return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2]; -} - -double SimInfo::length3(double a[3]){ - return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); -} - void SimInfo::calcBoxL( void ){ double dx, dy, dz, dsq; @@ -371,15 +268,15 @@ double SimInfo::calcMaxCutOff(){ rk[0] = Hmat[0][2]; rk[1] = Hmat[1][2]; rk[2] = Hmat[2][2]; - - crossProduct3(ri,rj, rij); - distXY = dotProduct3(rk,rij) / length3(rij); + + crossProduct3(ri, rj, rij); + distXY = dotProduct3(rk,rij) / norm3(rij); crossProduct3(rj,rk, rjk); - distYZ = dotProduct3(ri,rjk) / length3(rjk); + distYZ = dotProduct3(ri,rjk) / norm3(rjk); crossProduct3(rk,ri, rki); - distZX = dotProduct3(rj,rki) / length3(rki); + distZX = dotProduct3(rj,rki) / norm3(rki); minDist = min(min(distXY, distYZ), distZX); return minDist/2; @@ -427,15 +324,32 @@ int SimInfo::getNDF(){ int SimInfo::getNDF(){ int ndf_local; + + ndf_local = 0; - ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; + for(int i = 0; i < integrableObjects.size(); i++){ + 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: + + ndf_local -= n_constraints; + #ifdef IS_MPI MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); #else ndf = ndf_local; #endif + // nZconstraints is global, as are the 3 COM translations for the + // entire system: + ndf = ndf - 3 - nZconstraints; return ndf; @@ -445,8 +359,18 @@ int SimInfo::getNDFraw() { int ndfRaw_local; // Raw degrees of freedom that we have to set - ndfRaw_local = 3 * n_atoms + 3 * n_oriented; - + ndfRaw_local = 0; + + for(int i = 0; i < integrableObjects.size(); i++){ + ndfRaw_local += 3; + if (integrableObjects[i]->isDirectional()) { + if (integrableObjects[i]->isLinear()) + ndfRaw_local += 2; + else + ndfRaw_local += 3; + } + } + #ifdef IS_MPI MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); #else @@ -459,8 +383,9 @@ int SimInfo::getNDFtranslational() { int SimInfo::getNDFtranslational() { int ndfTrans_local; - ndfTrans_local = 3 * n_atoms - n_constraints; + ndfTrans_local = 3 * integrableObjects.size() - n_constraints; + #ifdef IS_MPI MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); #else @@ -470,6 +395,23 @@ int SimInfo::getNDFtranslational() { ndfTrans = ndfTrans - 3 - nZconstraints; 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(){ @@ -493,68 +435,62 @@ void SimInfo::refreshSim(){ fInfo.SIM_uses_charges = useCharges; fInfo.SIM_uses_dipoles = useDipoles; //fInfo.SIM_uses_dipoles = 0; - //fInfo.SIM_uses_RF = useReactionField; - fInfo.SIM_uses_RF = 0; + fInfo.SIM_uses_RF = useReactionField; + //fInfo.SIM_uses_RF = 0; fInfo.SIM_uses_GB = useGB; fInfo.SIM_uses_EAM = useEAM; - excl = Exclude::getArray(); - + 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); + //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, - &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 ); } @@ -566,39 +502,26 @@ void SimInfo::checkCutOffs( void ){ if( rCut > maxCutoff ){ sprintf( painCave.errMsg, - "Box size is too small for the long range cutoff radius, " - "%G, at time %G\n" - " [ %G %G %G ]\n" - " [ %G %G %G ]\n" - " [ %G %G %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" + "\t[ %G %G %G ]\n" + "\t[ %G %G %G ]\n" + "\t[ %G %G %G ]\n", 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, - "Box size is too small for the electrostatic cutoff radius, " - "%G, at time %G\n" - " [ %G %G %G ]\n" - " [ %G %G %G ]\n" - " [ %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, - "Trying to check cutoffs without a box. Be smarter.\n" ); + "Trying to check cutoffs without a box.\n" + "\tOOPSE should have better programmers than that.\n" ); painCave.isFatal = 1; simError(); } @@ -641,20 +564,73 @@ 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* 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; - for(i = properties.begin(); i != properties.end(); i++) - result.push_back((*i).second); + 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(); + - return result; -} + for(int j = 0; j < numAtom; j++){ -double SimInfo::matTrace3(double m[3][3]){ - double trace; - trace = m[0][0] + m[1][1] + m[2][2]; + +#ifdef IS_MPI + atomIndex = myAtoms[j]->getGlobalIndex(); +#else + atomIndex = myAtoms[j]->getIndex(); +#endif - return trace; + if(myMols[i].belongToCutoffGroup(atomIndex)) + continue; + else{ + mfact.push_back(myAtoms[j]->getMass()); + groupList.push_back(myAtoms[j]->getIndex() + 1); + groupStart.push_back(curIndex++); + } + } + + numCutoffGroups = myMols[i].getNCutoffGroups(); + for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff); myCutoffGroup != NULL; + myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){ + + 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(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff)) + + }//end for(int i = 0; i < numMol; i++) + + ngroup = groupStart.size(); }