--- trunk/OOPSE/libmdtools/SimSetup.cpp 2003/04/09 04:06:43 483 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2003/07/09 15:33:46 582 @@ -12,6 +12,18 @@ #include "mpiSimulation.hpp" #endif +// some defines for ensemble and Forcefield cases + +#define NVE_ENS 0 +#define NVT_ENS 1 +#define NPTi_ENS 2 +#define NPTf_ENS 3 + + +#define FF_DUFF 0 +#define FF_LJ 1 + + SimSetup::SimSetup(){ stamps = new MakeStamps(); globals = new Globals(); @@ -66,8 +78,13 @@ void SimSetup::createSim( void ){ MakeStamps *the_stamps; Globals* the_globals; - ExtendedSystem* the_extendedsystem; - int i, j; + int i, j, k, globalAtomIndex; + + int ensembleCase; + int ffCase; + + ensembleCase = -1; + ffCase = -1; // get the stamps and globals; the_stamps = stamps; @@ -82,65 +99,25 @@ void SimSetup::createSim( void ){ n_components = the_globals->getNComponents(); strcpy( force_field, the_globals->getForceField() ); - // get the ensemble and set up an extended system if we need it: + 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, "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(); - } - - } else if ( !strcasecmp( ensemble, "NVE") ) { - } else { + if( !strcasecmp( ensemble, "NVE" )) ensembleCase = NVE_ENS; + else if( !strcasecmp( ensemble, "NVT" )) ensembleCase = NVT_ENS; + else if( !strcasecmp( ensemble, "NPTi" ) || !strcasecmp( ensemble, "NPT") ) + ensembleCase = NPTi_ENS; + else if( !strcasecmp( ensemble, "NPTf" )) ensembleCase = NPTf_ENS; + else{ sprintf( painCave.errMsg, "SimSetup Warning. Unrecognized Ensemble -> %s, " "reverting to NVE for this simulation.\n", @@ -148,22 +125,84 @@ void SimSetup::createSim( void ){ 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; - if( !strcmp( force_field, "TraPPE_Ex" ) ){ - the_ff = new TraPPE_ExFF(); + switch( ffCase ){ + + case FF_DUFF: + the_ff = new DUFF(); usesDipoles = 1; - } - else if( !strcasecmp( force_field, "LJ" ) ) the_ff = new LJ_FF(); - else{ + break; + + 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(); } @@ -173,8 +212,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]; @@ -298,16 +335,15 @@ 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 @@ -324,11 +360,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(); @@ -336,12 +375,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 ){ @@ -385,6 +428,7 @@ 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++; } } @@ -392,10 +436,16 @@ void SimSetup::createSim( void ){ #else // is_mpi molIndex = 0; + globalAtomIndex = 0; for(i=0; igetNAtoms(); k++) { + simnfo->molMembershipArray[globalAtomIndex] = molIndex; + globalAtomIndex++; + } molIndex++; } } @@ -433,19 +483,23 @@ void SimSetup::createSim( void ){ // get some of the tricky things that may still be in the globals - + double boxVector[3]; if( the_globals->haveBox() ){ - simnfo->box_x = the_globals->getBox(); - simnfo->box_y = the_globals->getBox(); - simnfo->box_z = the_globals->getBox(); + boxVector[0] = the_globals->getBox(); + boxVector[1] = the_globals->getBox(); + boxVector[2] = the_globals->getBox(); + + simnfo->setBox( boxVector ); } else if( the_globals->haveDensity() ){ double vol; vol = (double)tot_nmol / the_globals->getDensity(); - simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) ); - simnfo->box_y = simnfo->box_x; - simnfo->box_z = simnfo->box_x; + boxVector[0] = pow( vol, ( 1.0 / 3.0 ) ); + boxVector[1] = boxVector[0]; + boxVector[2] = boxVector[0]; + + simnfo->setBox( boxVector ); } else{ if( !the_globals->haveBoxX() ){ @@ -454,7 +508,7 @@ void SimSetup::createSim( void ){ painCave.isFatal = 1; simError(); } - simnfo->box_x = the_globals->getBoxX(); + boxVector[0] = the_globals->getBoxX(); if( !the_globals->haveBoxY() ){ sprintf( painCave.errMsg, @@ -462,7 +516,7 @@ void SimSetup::createSim( void ){ painCave.isFatal = 1; simError(); } - simnfo->box_y = the_globals->getBoxY(); + boxVector[1] = the_globals->getBoxY(); if( !the_globals->haveBoxZ() ){ sprintf( painCave.errMsg, @@ -470,7 +524,9 @@ void SimSetup::createSim( void ){ painCave.isFatal = 1; simError(); } - simnfo->box_z = the_globals->getBoxZ(); + boxVector[2] = the_globals->getBoxZ(); + + simnfo->setBox( boxVector ); } #ifdef IS_MPI @@ -485,12 +541,8 @@ void SimSetup::createSim( void ){ makeMolecules(); simnfo->identArray = new int[simnfo->n_atoms]; - simnfo->molMembershipArray = new int[simnfo->n_atoms]; for(i=0; in_atoms; i++){ simnfo->identArray[i] = the_atoms[i]->getIdent(); - } - for(i=0; i< simnfo->n_mol; i++) { - the_molecules[i].atomicRollCall(simnfo->molMembershipArray); } if (the_globals->getUseRF() ) { @@ -504,9 +556,9 @@ void SimSetup::createSim( void ){ painCave.isFatal = 0; simError(); double smallest; - smallest = simnfo->box_x; - if (simnfo->box_y <= smallest) smallest = simnfo->box_y; - if (simnfo->box_z <= smallest) smallest = simnfo->box_z; + smallest = simnfo->boxLx; + if (simnfo->boxLy <= smallest) smallest = simnfo->boxLy; + if (simnfo->boxLz <= smallest) smallest = simnfo->boxLz; simnfo->ecr = 0.5 * smallest; } else { simnfo->ecr = the_globals->getECR(); @@ -544,9 +596,9 @@ void SimSetup::createSim( void ){ painCave.isFatal = 0; simError(); double smallest; - smallest = simnfo->box_x; - if (simnfo->box_y <= smallest) smallest = simnfo->box_y; - if (simnfo->box_z <= smallest) smallest = simnfo->box_z; + smallest = simnfo->boxLx; + if (simnfo->boxLy <= smallest) smallest = simnfo->boxLy; + if (simnfo->boxLz <= smallest) smallest = simnfo->boxLz; simnfo->ecr = 0.5 * smallest; } else { simnfo->ecr = the_globals->getECR(); @@ -725,21 +777,42 @@ void SimSetup::createSim( void ){ if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet(); -// // make the longe range forces and the integrator + // make the integrator + + + NVT* myNVT = NULL; + switch( ensembleCase ){ -// new AllLong( simnfo ); + case NVE_ENS: + new NVE( simnfo, the_ff ); + break; + case NVT_ENS: + myNVT = new NVT( simnfo, the_ff ); + myNVT->setTargetTemp(the_globals->getTargetTemp()); - if( !strcmp( force_field, "TraPPE_Ex" ) ){ - new Symplectic(simnfo, the_ff, the_extendedsystem); - } - else if( !strcmp( force_field, "LJ" ) ){ - new Verlet( *simnfo, the_ff, the_extendedsystem ); - } - else { - std::cerr << "I'm a bug.\n"; - fprintf( stderr, "Ima bug. stderr %s\n", force_field); + 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 @@ -1052,9 +1125,9 @@ void SimSetup::initFromBass( void ){ have_extra =1; n_cells = (int)temp3 - 1; - cellx = simnfo->box_x / temp3; - celly = simnfo->box_y / temp3; - cellz = simnfo->box_z / temp3; + cellx = simnfo->boxLx / temp3; + celly = simnfo->boxLy / temp3; + cellz = simnfo->boxLz / temp3; n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells ); temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) ); n_per_extra = (int)ceil( temp1 ); @@ -1069,9 +1142,9 @@ void SimSetup::initFromBass( void ){ } else{ n_cells = (int)temp3; - cellx = simnfo->box_x / temp3; - celly = simnfo->box_y / temp3; - cellz = simnfo->box_z / temp3; + cellx = simnfo->boxLx / temp3; + celly = simnfo->boxLy / temp3; + cellz = simnfo->boxLz / temp3; } current_mol = 0;