--- trunk/OOPSE/libmdtools/SimSetup.cpp 2003/03/27 17:32:03 420 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2003/04/10 20:08:56 489 @@ -66,6 +66,7 @@ void SimSetup::createSim( void ){ MakeStamps *the_stamps; Globals* the_globals; + ExtendedSystem* the_extendedsystem; int i, j; // get the stamps and globals; @@ -80,18 +81,85 @@ 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() ); + + // get the ensemble and set up an extended system if we need it: 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 { + sprintf( painCave.errMsg, + "SimSetup Warning. Unrecognized Ensemble -> %s, " + "reverting to NVE for this simulation.\n", + ensemble ); + painCave.isFatal = 0; + simError(); + strcpy( ensemble, "NVE" ); + } strcpy( simnfo->ensemble, ensemble ); strcpy( simnfo->mixingRule, the_globals->getMixingRule() ); simnfo->usePBC = the_globals->getPBC(); - - - if( !strcmp( force_field, "TraPPE" ) ) the_ff = new TraPPEFF(); - else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF(); - else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF(); - else if( !strcmp( force_field, "LJ" ) ) the_ff = new LJ_FF(); + int usesDipoles = 0; + if( !strcmp( force_field, "TraPPE_Ex" ) ){ + the_ff = new TraPPE_ExFF(); + usesDipoles = 1; + } + else if( !strcasecmp( force_field, "LJ" ) ) the_ff = new LJ_FF(); else{ sprintf( painCave.errMsg, "SimSetup Error. Unrecognized force field -> %s\n", @@ -242,12 +310,13 @@ void SimSetup::createSim( void ){ globalIndex = mpiSim->divideLabor(); - - // set up the local variables int localMol, allMol; int local_atoms, local_bonds, local_bends, local_torsions, local_SRI; + + int* mol2proc = mpiSim->getMolToProcMap(); + int* molCompType = mpiSim->getMolComponentType(); allMol = 0; localMol = 0; @@ -259,8 +328,7 @@ void SimSetup::createSim( void ){ for( j=0; jgetMyMolStart() <= allMol && - allMol <= mpiSim->getMyMolEnd() ){ + if( mol2proc[allMol] == worldRank ){ local_atoms += comp_stamps[i]->getNAtoms(); local_bonds += comp_stamps[i]->getNBonds(); @@ -279,7 +347,7 @@ void SimSetup::createSim( void ){ if( local_atoms != simnfo->n_atoms ){ sprintf( painCave.errMsg, "SimSetup error: mpiSim's localAtom (%d) and SimSetup's" - " localAtom (%d) are note equal.\n", + " localAtom (%d) are not equal.\n", simnfo->n_atoms, local_atoms ); painCave.isFatal = 1; @@ -304,13 +372,47 @@ void SimSetup::createSim( void ){ Atom::createArrays(simnfo->n_atoms); the_atoms = new Atom*[simnfo->n_atoms]; the_molecules = new Molecule[simnfo->n_mol]; + int molIndex; + // initialize the molecule's stampID's +#ifdef IS_MPI + + + molIndex = 0; + for(i=0; igetTotNmol(); i++){ + + if(mol2proc[i] == worldRank ){ + the_molecules[molIndex].setStampID( molCompType[i] ); + the_molecules[molIndex].setMyIndex( molIndex ); + the_molecules[molIndex].setGlobalIndex( i ); + molIndex++; + } + } + +#else // is_mpi + + molIndex = 0; + for(i=0; in_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{ @@ -326,7 +428,7 @@ void SimSetup::createSim( void ){ // set the arrays into the SimInfo object simnfo->atoms = the_atoms; - simnfo->sr_interactions = the_sris; + simnfo->molecules = the_molecules; simnfo->nGlobalExcludes = 0; simnfo->excludes = the_excludes; @@ -383,25 +485,16 @@ void SimSetup::createSim( void ){ the_ff->setSimInfo( simnfo ); - makeAtoms(); + 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(); } - - if( tot_bonds ){ - makeBonds(); + for(i=0; i< simnfo->n_mol; i++) { + the_molecules[i].atomicRollCall(simnfo->molMembershipArray); } - - if( tot_bends ){ - makeBends(); - } - - if( tot_torsions ){ - makeTorsions(); - } - - + if (the_globals->getUseRF() ) { simnfo->useReactionField = 1; @@ -443,11 +536,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; @@ -463,7 +556,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" ); @@ -637,16 +730,25 @@ void SimSetup::createSim( void ){ // // make the longe range forces and the integrator // new AllLong( simnfo ); - - if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo, the_ff ); - if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo, the_ff ); - if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo, the_ff ); - if( !strcmp( force_field, "LJ" ) ) new Verlet( *simnfo, the_ff ); + 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); + } +#ifdef IS_MPI + mpiSim->mpiRefresh(); +#endif // initialize the Fortran - + + simnfo->refreshSim(); if( !strcmp( simnfo->mixingRule, "standard") ){ @@ -683,14 +785,21 @@ void SimSetup::makeMolecules( void ){ BondStamp* currentBond; BendStamp* currentBend; TorsionStamp* currentTorsion; + + bond_pair* theBonds; + bend_set* theBends; + torsion_set* theTorsions; + //init the forceField paramters the_ff->readParams(); - // init the molecules + // init the atoms + double ux, uy, uz, u, uSqr; + atomOffset = 0; excludeOffset = 0; for(i=0; in_mol; i++){ @@ -707,7 +816,7 @@ void SimSetup::makeMolecules( void ){ info.myExcludes = &the_excludes[excludeOffset]; info.myBonds = new Bond*[info.nBonds]; info.myBends = new Bend*[info.nBends]; - info.myTorsions = new Torsions*[info.nTorsions]; + info.myTorsions = new Torsion*[info.nTorsions]; theBonds = new bond_pair[info.nBonds]; theBends = new bend_set[info.nBends]; @@ -717,7 +826,7 @@ void SimSetup::makeMolecules( void ){ for(j=0; jgetAtom( j ); + currentAtom = comp_stamps[stampID]->getAtom( j ); if( currentAtom->haveOrientation() ){ dAtom = new DirectionalAtom(j + atomOffset); @@ -758,8 +867,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 ){ @@ -775,6 +884,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 } @@ -790,7 +900,7 @@ void SimSetup::makeMolecules( void ){ if( currentBend->haveExtras() ){ - extras = current_bend->getExtras(); + extras = currentBend->getExtras(); current_extra = extras; while( current_extra != NULL ){ @@ -812,7 +922,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() ); @@ -906,12 +1016,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 ){