--- trunk/OOPSE/libmdtools/SimSetup.cpp 2003/03/27 21:52:21 429 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2003/06/20 20:29:36 561 @@ -12,6 +12,16 @@ SimSetup::SimSetup(){ #include "mpiSimulation.hpp" #endif +// some defines for ensemble and Forcefield cases + +#define NVE_ENS 0 +#define NVT_ENS 1 +#define NPT_ENS 2 + +#define FF_DUFF 0 +#define FF_LJ 1 + + SimSetup::SimSetup(){ stamps = new MakeStamps(); globals = new Globals(); @@ -66,7 +76,13 @@ void SimSetup::createSim( void ){ MakeStamps *the_stamps; Globals* the_globals; - int i, j; + int i, j, k, globalAtomIndex; + + int ensembleCase; + int ffCase; + + ensembleCase = -1; + ffCase = -1; // get the stamps and globals; the_stamps = stamps; @@ -80,20 +96,109 @@ void SimSetup::createSim( void ){ // get the ones we know are there, yet still may need some work. n_components = the_globals->getNComponents(); strcpy( force_field, the_globals->getForceField() ); + + if( !strcasecmp( force_field, "DUFF" )) ffCase = FF_DUFF; + else if( !strcasecmp( force_field, "LJ" )) ffCase = FF_LJ; + else{ + sprintf( painCave.errMsg, + "SimSetup Error. Unrecognized force field -> %s\n", + force_field ); + painCave.isFatal = 1; + simError(); + } + + // get the ensemble: strcpy( ensemble, the_globals->getEnsemble() ); + + if( !strcasecmp( ensemble, "NVE" )) ensembleCase = NVE_ENS; + else if( !strcasecmp( ensemble, "NVT" )) ensembleCase = NVT_ENS; + else if( !strcasecmp( ensemble, "NPT" )) ensembleCase = NPT_ENS; + else{ + sprintf( painCave.errMsg, + "SimSetup Warning. Unrecognized Ensemble -> %s, " + "reverting to NVE for this simulation.\n", + ensemble ); + painCave.isFatal = 0; + simError(); + strcpy( ensemble, "NVE" ); + ensembleCase = NVE_ENS; + } strcpy( simnfo->ensemble, ensemble ); + +// if( !strcasecmp( ensemble, "NPT" ) ) { +// the_extendedsystem = new ExtendedSystem( simnfo ); +// the_extendedsystem->setTargetTemp(the_globals->getTargetTemp()); +// if (the_globals->haveTargetPressure()) +// the_extendedsystem->setTargetPressure(the_globals->getTargetPressure()); +// else { +// sprintf( painCave.errMsg, +// "SimSetup error: If you use the constant pressure\n" +// " ensemble, you must set targetPressure.\n" +// " This was found in the BASS file.\n"); +// painCave.isFatal = 1; +// simError(); +// } + +// if (the_globals->haveTauThermostat()) +// the_extendedsystem->setTauThermostat(the_globals->getTauThermostat()); +// else if (the_globals->haveQmass()) +// the_extendedsystem->setQmass(the_globals->getQmass()); +// else { +// sprintf( painCave.errMsg, +// "SimSetup error: If you use one of the constant temperature\n" +// " ensembles, you must set either tauThermostat or qMass.\n" +// " Neither of these was found in the BASS file.\n"); +// painCave.isFatal = 1; +// simError(); +// } + +// if (the_globals->haveTauBarostat()) +// the_extendedsystem->setTauBarostat(the_globals->getTauBarostat()); +// else { +// sprintf( painCave.errMsg, +// "SimSetup error: If you use the constant pressure\n" +// " ensemble, you must set tauBarostat.\n" +// " This was found in the BASS file.\n"); +// painCave.isFatal = 1; +// simError(); +// } + +// } else if ( !strcasecmp( ensemble, "NVT") ) { +// the_extendedsystem = new ExtendedSystem( simnfo ); +// the_extendedsystem->setTargetTemp(the_globals->getTargetTemp()); + +// if (the_globals->haveTauThermostat()) +// the_extendedsystem->setTauThermostat(the_globals->getTauThermostat()); +// else if (the_globals->haveQmass()) +// the_extendedsystem->setQmass(the_globals->getQmass()); +// else { +// sprintf( painCave.errMsg, +// "SimSetup error: If you use one of the constant temperature\n" +// " ensembles, you must set either tauThermostat or qMass.\n" +// " Neither of these was found in the BASS file.\n"); +// painCave.isFatal = 1; +// simError(); +// } + strcpy( simnfo->mixingRule, the_globals->getMixingRule() ); simnfo->usePBC = the_globals->getPBC(); + int usesDipoles = 0; + switch( ffCase ){ + case FF_DUFF: + the_ff = new DUFF(); + usesDipoles = 1; + break; - if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF(); - else if( !strcmp( force_field, "LJ" ) ) the_ff = new LJ_FF(); - else{ + case FF_LJ: + the_ff = new LJFF(); + break; + + default: sprintf( painCave.errMsg, - "SimSetup Error. Unrecognized force field -> %s\n", - force_field ); + "SimSetup Error. Unrecognized force field in case statement.\n"); painCave.isFatal = 1; simError(); } @@ -103,8 +208,6 @@ void SimSetup::createSim( void ){ MPIcheckPoint(); #endif // is_mpi - - // get the components and calculate the tot_nMol and indvidual n_mol the_components = the_globals->getComponents(); components_nmol = new int[n_components]; @@ -228,20 +331,17 @@ void SimSetup::createSim( void ){ simnfo->n_torsions = tot_torsions; simnfo->n_SRI = tot_SRI; simnfo->n_mol = tot_nmol; - + simnfo->molMembershipArray = new int[tot_atoms]; + #ifdef IS_MPI // divide the molecules among processors here. mpiSim = new mpiSimulation( simnfo ); - - globalIndex = mpiSim->divideLabor(); - - // set up the local variables int localMol, allMol; @@ -256,11 +356,14 @@ void SimSetup::createSim( void ){ local_bonds = 0; local_bends = 0; local_torsions = 0; + globalAtomIndex = 0; + + for( i=0; igetNAtoms(); local_bonds += comp_stamps[i]->getNBonds(); @@ -268,12 +371,16 @@ void SimSetup::createSim( void ){ local_torsions += comp_stamps[i]->getNTorsions(); localMol++; } - allMol++; + for (k = 0; k < comp_stamps[i]->getNAtoms(); k++) { + simnfo->molMembershipArray[globalAtomIndex] = allMol; + globalAtomIndex++; + } + + allMol++; } } local_SRI = local_bonds + local_bends + local_torsions; - simnfo->n_atoms = mpiSim->getMyNlocal(); if( local_atoms != simnfo->n_atoms ){ @@ -316,6 +423,8 @@ void SimSetup::createSim( void ){ if(mol2proc[i] == worldRank ){ the_molecules[molIndex].setStampID( molCompType[i] ); + the_molecules[molIndex].setMyIndex( molIndex ); + the_molecules[molIndex].setGlobalIndex( i ); molIndex++; } } @@ -323,9 +432,16 @@ void SimSetup::createSim( void ){ #else // is_mpi molIndex = 0; + globalAtomIndex = 0; for(i=0; igetNAtoms(); k++) { + simnfo->molMembershipArray[globalAtomIndex] = molIndex; + globalAtomIndex++; + } molIndex++; } } @@ -335,10 +451,12 @@ void SimSetup::createSim( void ){ if( simnfo->n_SRI ){ + Exclude::createArray(simnfo->n_SRI); the_excludes = new Exclude*[simnfo->n_SRI]; + for( int ex=0; exn_SRI; ex++) the_excludes[ex] = new Exclude(ex); simnfo->globalExcludes = new int; - simnfo->n_exclude = tot_SRI; + simnfo->n_exclude = simnfo->n_SRI; } else{ @@ -458,11 +576,11 @@ void SimSetup::createSim( void ){ } simnfo->dielectric = the_globals->getDielectric(); } else { - if (simnfo->n_dipoles) { + if (usesDipoles) { if( !the_globals->haveECR() ){ sprintf( painCave.errMsg, - "SimSetup Warning: using default value of 1/2 the smallest" + "SimSetup Warning: using default value of 1/2 the smallest " "box length for the electrostaticCutoffRadius.\n" "I hope you have a very fast processor!\n"); painCave.isFatal = 0; @@ -478,7 +596,7 @@ void SimSetup::createSim( void ){ if( !the_globals->haveEST() ){ sprintf( painCave.errMsg, - "SimSetup Warning: using default value of 5% of the" + "SimSetup Warning: using default value of 5%% of the " "electrostaticCutoffRadius for the " "electrostaticSkinThickness\n" ); @@ -649,17 +767,49 @@ void SimSetup::createSim( void ){ if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet(); -// // make the longe range forces and the integrator - -// new AllLong( simnfo ); - - if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo, the_ff ); - if( !strcmp( force_field, "LJ" ) ) new Verlet( *simnfo, the_ff ); + // make the integrator + + + NVT* myNVT = NULL; + switch( ensembleCase ){ + case NVE_ENS: + new NVE( simnfo, the_ff ); + break; + case NVT_ENS: + myNVT = new NVT( simnfo, the_ff ); + myNVT->setTargetTemp(the_globals->getTargetTemp()); + if (the_globals->haveTauThermostat()) + myNVT->setTauThermostat(the_globals->getTauThermostat()); + else if (the_globals->haveQmass()) + myNVT->setQmass(the_globals->getQmass()); + else { + sprintf( painCave.errMsg, + "SimSetup error: If you use the NVT\n" + " ensemble, you must set either tauThermostat or qMass.\n" + " Neither of these was found in the BASS file.\n"); + painCave.isFatal = 1; + simError(); + } + break; + + default: + sprintf( painCave.errMsg, + "SimSetup Error. Unrecognized ensemble in case statement.\n"); + painCave.isFatal = 1; + simError(); + } + + +#ifdef IS_MPI + mpiSim->mpiRefresh(); +#endif + // initialize the Fortran - + + simnfo->refreshSim(); if( !strcmp( simnfo->mixingRule, "standard") ){ @@ -778,8 +928,8 @@ void SimSetup::makeMolecules( void ){ theBonds[j].a = currentBond->getA() + atomOffset; theBonds[j].b = currentBond->getB() + atomOffset; - exI = theBonds[i].a; - exJ = theBonds[i].b; + exI = theBonds[j].a; + exJ = theBonds[j].b; // exclude_I must always be the smaller of the pair if( exI > exJ ){ @@ -795,6 +945,7 @@ void SimSetup::makeMolecules( void ){ the_excludes[j+excludeOffset]->setPair( exI, exJ ); #else // isn't MPI + the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) ); #endif //is_mpi } @@ -832,7 +983,7 @@ void SimSetup::makeMolecules( void ){ default: sprintf( painCave.errMsg, - "SimSetup Error: ghostVectorSource was neiter a " + "SimSetup Error: ghostVectorSource was neither a " "double nor an int.\n" "-->Bend[%d] in %s\n", j, comp_stamps[stampID]->getID() ); @@ -926,15 +1077,23 @@ void SimSetup::makeMolecules( void ){ the_molecules[i].initialize( info ); + + atomOffset += info.nAtoms; delete[] theBonds; delete[] theBends; delete[] theTorsions; } +#ifdef IS_MPI + sprintf( checkPointMsg, "all molecules initialized succesfully" ); + MPIcheckPoint(); +#endif // is_mpi + // clean up the forcefield the_ff->calcRcut(); the_ff->cleanMe(); + } void SimSetup::initFromBass( void ){