--- trunk/mdtools/interface_implementation/SimSetup.cpp 2002/09/30 20:35:42 124 +++ trunk/mdtools/interface_implementation/SimSetup.cpp 2002/12/06 21:20:42 198 @@ -6,11 +6,21 @@ #include "parse_me.h" #include "LRI.hpp" #include "Integrator.hpp" -#include "mpiInterface.h" +#include "simError.h" +#ifdef IS_MPI +#include "mpiBASS.h" +#include "bassDiag.hpp" +#endif + SimSetup::SimSetup(){ stamps = new MakeStamps(); globals = new Globals(); + +#ifdef IS_MPI + strcpy( checkPointMsg, "SimSetup creation successful" ); + MPIcheckPoint(); +#endif // IS_MPI } SimSetup::~SimSetup(){ @@ -20,26 +30,43 @@ void SimSetup::parseFile( char* fileName ){ void SimSetup::parseFile( char* fileName ){ - inFileName = fileName; - set_interface_stamps( stamps, globals ); -#ifdef MPI - mpiEventInit(); +#ifdef IS_MPI + if( worldRank == 0 ){ +#endif // is_mpi + + inFileName = fileName; + set_interface_stamps( stamps, globals ); + +#ifdef IS_MPI + mpiEventInit(); #endif - yacc_BASS( fileName ); -#ifdef MPI - throwMPIEvent(NULL); + + yacc_BASS( fileName ); + +#ifdef IS_MPI + throwMPIEvent(NULL); + } + else receiveParse(); #endif } -#ifdef MPI +#ifdef IS_MPI void SimSetup::receiveParse(void){ set_interface_stamps( stamps, globals ); mpiEventInit(); + MPIcheckPoint(); mpiEventLoop(); } + + +void SimSetup::testMe(void){ + bassDiag* dumpMe = new bassDiag(globals,stamps); + dumpMe->dumpStamps(); + delete dumpMe; +} #endif void SimSetup::createSim( void ){ @@ -66,11 +93,18 @@ void SimSetup::createSim( void ){ else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF(); else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF(); else{ - std::cerr<< "SimSetup Error. Unrecognized force field -> " - << force_field << "\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup Error. Unrecognized force field -> %s\n", + force_field ); + painCave.isFatal = 1; + simError(); } +#ifdef IS_MPI + strcpy( checkPointMsg, "ForceField creation successful" ); + 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]; @@ -85,9 +119,11 @@ void SimSetup::createSim( void ){ if( !the_components[i]->haveNMol() ){ // we have a problem - std::cerr << "SimSetup Error. No global NMol or component NMol" - << " given. Cannot calculate the number of atoms.\n"; - exit( 8 ); + sprintf( painCave.errMsg, + "SimSetup Error. No global NMol or component NMol" + " given. Cannot calculate the number of atoms.\n" ); + painCave.isFatal = 1; + simError(); } tot_nmol += the_components[i]->getNMol(); @@ -95,32 +131,81 @@ void SimSetup::createSim( void ){ } } else{ - std::cerr << "NOT A SUPPORTED FEATURE\n"; - -// tot_nmol = the_globals->getNMol(); - -// //we have the total number of molecules, now we check for molfractions -// for( i=0; ihaveMolFraction() ){ - -// if( !the_components[i]->haveNMol() ){ -// //we have a problem -// std::cerr << "SimSetup error. Neither molFraction nor " -// << " nMol was given in component - + sprintf( painCave.errMsg, + "SimSetup error.\n" + "\tSorry, the ability to specify total" + " nMols and then give molfractions in the components\n" + "\tis not currently supported." + " Please give nMol in the components.\n" ); + painCave.isFatal = 1; + simError(); + + + // tot_nmol = the_globals->getNMol(); + + // //we have the total number of molecules, now we check for molfractions + // for( i=0; ihaveMolFraction() ){ + + // if( !the_components[i]->haveNMol() ){ + // //we have a problem + // std::cerr << "SimSetup error. Neither molFraction nor " + // << " nMol was given in component + } +#ifdef IS_MPI + strcpy( checkPointMsg, "Have the number of components" ); + MPIcheckPoint(); +#endif // is_mpi + // make an array of molecule stamps that match the components used. + // also extract the used stamps out into a separate linked list + simnfo->nComponents = n_components; + simnfo->componentsNmol = components_nmol; + simnfo->compStamps = comp_stamps; + simnfo->headStamp = new LinkedMolStamp(); + + char* id; + LinkedMolStamp* headStamp = simnfo->headStamp; + LinkedMolStamp* currentStamp = NULL; for( i=0; igetMolecule( the_components[i]->getType() ); + id = the_components[i]->getType(); + comp_stamps[i] = NULL; + + // check to make sure the component isn't already in the list + + comp_stamps[i] = headStamp->match( id ); + if( comp_stamps[i] == NULL ){ + + // extract the component from the list; + + currentStamp = the_stamps->extractMolStamp( id ); + if( currentStamp == NULL ){ + sprintf( painCave.errMsg, + "SimSetup error: Component \"%s\" was not found in the " + "list of declared molecules\n" + id ); + painCave.isFatal = 1; + simError(); + } + + headStamp->add( currentStamp ); + comp_stamps[i] = headStamp->match( id ); + } } +#ifdef IS_MPI + strcpy( checkPointMsg, "Component stamps successfully extracted\n" ); + MPIcheckPoint(); +#endif // is_mpi + + // caclulate the number of atoms, bonds, bends and torsions tot_atoms = 0; @@ -142,16 +227,30 @@ void SimSetup::createSim( void ){ simnfo->n_bends = tot_bends; simnfo->n_torsions = tot_torsions; simnfo->n_SRI = tot_SRI; + simnfo->n_mol = tot_nmol; + +#ifdef IS_MPI + + // divide the molecules among processors here. + + new mpiSimulation( simnfo ); + + simnfo->mpiSim->divideLabor( n_components, comp_stamps, components_nmol ); + +#endif // is_mpi + + // create the atom and short range interaction arrays - the_atoms = new Atom*[tot_atoms]; - the_molecules = new Molecule[tot_nmol]; + Atom::createArrays(simnfo->n_atoms); + the_atoms = new Atom*[simnfo->n_atoms]; + the_molecules = new Molecule[simnfo->n_mol]; - if( tot_SRI ){ - the_sris = new SRI*[tot_SRI]; - the_excludes = new ex_pair[tot_SRI]; + if( simnfo->n_SRI ){ + the_sris = new SRI*[simnfo->n_SRI]; + the_excludes = new ex_pair[simnfo->n_SRI]; } // set the arrays into the SimInfo object @@ -180,26 +279,34 @@ void SimSetup::createSim( void ){ makeTorsions(); } - // makeMolecules(); // get some of the tricky things that may still be in the globals if( simnfo->n_dipoles ){ if( !the_globals->haveRRF() ){ - std::cerr << "SimSetup Error, system has dipoles, but no rRF was set.\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup Error, system has dipoles, but no rRF was set.\n"); + painCave.isFatal = 1; + simError(); } if( !the_globals->haveDielectric() ){ - std::cerr << "SimSetup Error, system has dipoles, but no" - << " dielectric was set.\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup Error, system has dipoles, but no" + " dielectric was set.\n" ); + painCave.isFatal = 1; + simError(); } simnfo->rRF = the_globals->getRRF(); simnfo->dielectric = the_globals->getDielectric(); } +#ifdef IS_MPI + strcpy( checkPointMsg, "rRf and dielectric check out" ); + MPIcheckPoint(); +#endif // is_mpi + if( the_globals->haveBox() ){ simnfo->box_x = the_globals->getBox(); simnfo->box_y = the_globals->getBox(); @@ -215,25 +322,37 @@ void SimSetup::createSim( void ){ } else{ if( !the_globals->haveBoxX() ){ - std::cerr << "SimSetup error, no periodic BoxX size given.\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup error, no periodic BoxX size given.\n" ); + painCave.isFatal = 1; + simError(); } simnfo->box_x = the_globals->getBoxX(); if( !the_globals->haveBoxY() ){ - std::cerr << "SimSetup error, no periodic BoxY size given.\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup error, no periodic BoxY size given.\n" ); + painCave.isFatal = 1; + simError(); } simnfo->box_y = the_globals->getBoxY(); if( !the_globals->haveBoxZ() ){ - std::cerr << "SimSetup error, no periodic BoxZ size given.\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup error, no periodic BoxZ size given.\n" ); + painCave.isFatal = 1; + simError(); } simnfo->box_z = the_globals->getBoxZ(); } +#ifdef IS_MPI + strcpy( checkPointMsg, "Box size set up" ); + MPIcheckPoint(); +#endif // is_mpi + + // if( the_globals->haveInitialConfig() ){ // InitializeFromFile* fileInit; // fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); @@ -244,89 +363,117 @@ void SimSetup::createSim( void ){ // } // else{ - initFromBass(); +#ifdef IS_MPI + // no init from bass + + sprintf( painCave.errMsg, + "Cannot intialize a parallel simulation without an initial configuration file.\n" ); + painCave.isFatal; + simError(); + +#else -// } + initFromBass(); -// if( the_globals->haveFinalConfig() ){ -// strcpy( simnfo->finalName, the_globals->getFinalConfig() ); -// } -// else{ -// strcpy( simnfo->finalName, inFileName ); -// char* endTest; -// int nameLength = strlen( simnfo->finalName ); -// endTest = &(simnfo->finalName[nameLength - 5]); -// if( !strcmp( endTest, ".bass" ) ){ -// strcpy( endTest, ".eor" ); -// } -// else if( !strcmp( endTest, ".BASS" ) ){ -// strcpy( endTest, ".eor" ); -// } -// else{ -// endTest = &(simnfo->finalName[nameLength - 4]); -// if( !strcmp( endTest, ".bss" ) ){ -// strcpy( endTest, ".eor" ); -// } -// else if( !strcmp( endTest, ".mdl" ) ){ -// strcpy( endTest, ".eor" ); -// } -// else{ -// strcat( simnfo->finalName, ".eor" ); -// } -// } -// } +#endif // is_mpi + +#ifdef IS_MPI + strcpy( checkPointMsg, "Successfully read in the initial configuration" ); + MPIcheckPoint(); +#endif // is_mpi -// // make the sample and status out names -// strcpy( simnfo->sampleName, inFileName ); -// char* endTest; -// int nameLength = strlen( simnfo->sampleName ); -// endTest = &(simnfo->sampleName[nameLength - 5]); -// if( !strcmp( endTest, ".bass" ) ){ -// strcpy( endTest, ".dump" ); -// } -// else if( !strcmp( endTest, ".BASS" ) ){ -// strcpy( endTest, ".dump" ); -// } -// else{ -// endTest = &(simnfo->sampleName[nameLength - 4]); -// if( !strcmp( endTest, ".bss" ) ){ -// strcpy( endTest, ".dump" ); -// } -// else if( !strcmp( endTest, ".mdl" ) ){ -// strcpy( endTest, ".dump" ); -// } -// else{ -// strcat( simnfo->sampleName, ".dump" ); -// } -// } - -// strcpy( simnfo->statusName, inFileName ); -// nameLength = strlen( simnfo->statusName ); -// endTest = &(simnfo->statusName[nameLength - 5]); -// if( !strcmp( endTest, ".bass" ) ){ -// strcpy( endTest, ".stat" ); -// } -// else if( !strcmp( endTest, ".BASS" ) ){ -// strcpy( endTest, ".stat" ); -// } -// else{ -// endTest = &(simnfo->statusName[nameLength - 4]); -// if( !strcmp( endTest, ".bss" ) ){ -// strcpy( endTest, ".stat" ); -// } -// else if( !strcmp( endTest, ".mdl" ) ){ -// strcpy( endTest, ".stat" ); -// } -// else{ -// strcat( simnfo->statusName, ".stat" ); -// } -// } - - + + + + // } + +#ifdef IS_MPI + if( worldRank == 0 ){ +#endif // is_mpi + + if( the_globals->haveFinalConfig() ){ + strcpy( simnfo->finalName, the_globals->getFinalConfig() ); + } + else{ + strcpy( simnfo->finalName, inFileName ); + char* endTest; + int nameLength = strlen( simnfo->finalName ); + endTest = &(simnfo->finalName[nameLength - 5]); + if( !strcmp( endTest, ".bass" ) ){ + strcpy( endTest, ".eor" ); + } + else if( !strcmp( endTest, ".BASS" ) ){ + strcpy( endTest, ".eor" ); + } + else{ + endTest = &(simnfo->finalName[nameLength - 4]); + if( !strcmp( endTest, ".bss" ) ){ + strcpy( endTest, ".eor" ); + } + else if( !strcmp( endTest, ".mdl" ) ){ + strcpy( endTest, ".eor" ); + } + else{ + strcat( simnfo->finalName, ".eor" ); + } + } + } + + // make the sample and status out names + + strcpy( simnfo->sampleName, inFileName ); + char* endTest; + int nameLength = strlen( simnfo->sampleName ); + endTest = &(simnfo->sampleName[nameLength - 5]); + if( !strcmp( endTest, ".bass" ) ){ + strcpy( endTest, ".dump" ); + } + else if( !strcmp( endTest, ".BASS" ) ){ + strcpy( endTest, ".dump" ); + } + else{ + endTest = &(simnfo->sampleName[nameLength - 4]); + if( !strcmp( endTest, ".bss" ) ){ + strcpy( endTest, ".dump" ); + } + else if( !strcmp( endTest, ".mdl" ) ){ + strcpy( endTest, ".dump" ); + } + else{ + strcat( simnfo->sampleName, ".dump" ); + } + } + + strcpy( simnfo->statusName, inFileName ); + nameLength = strlen( simnfo->statusName ); + endTest = &(simnfo->statusName[nameLength - 5]); + if( !strcmp( endTest, ".bass" ) ){ + strcpy( endTest, ".stat" ); + } + else if( !strcmp( endTest, ".BASS" ) ){ + strcpy( endTest, ".stat" ); + } + else{ + endTest = &(simnfo->statusName[nameLength - 4]); + if( !strcmp( endTest, ".bss" ) ){ + strcpy( endTest, ".stat" ); + } + else if( !strcmp( endTest, ".mdl" ) ){ + strcpy( endTest, ".stat" ); + } + else{ + strcat( simnfo->statusName, ".stat" ); + } + } + +#ifdef IS_MPI + } +#endif // is_mpi + // set the status, sample, and themal kick times - + if( the_globals->haveSampleTime() ){ simnfo->sampleTime = the_globals->getSampleTime(); simnfo->statusTime = simnfo->sampleTime; @@ -382,7 +529,7 @@ void SimSetup::makeAtoms( void ){ current_atom = comp_stamps[i]->getAtom( k ); if( current_atom->haveOrientation() ){ - dAtom = new DirectionalAtom; + dAtom = new DirectionalAtom(index); simnfo->n_oriented++; the_atoms[index] = dAtom; @@ -402,7 +549,7 @@ void SimSetup::makeAtoms( void ){ dAtom->setSUz( uz ); } else{ - the_atoms[index] = new GeneralAtom; + the_atoms[index] = new GeneralAtom(index); } the_atoms[index]->setType( current_atom->getType() ); the_atoms[index]->setIndex( index ); @@ -549,8 +696,11 @@ void SimSetup::initFromBass( void ){ n_per_extra = (int)ceil( temp1 ); if( n_per_extra > 4){ - std::cerr << "THere has been an error in constructing the non-complete lattice.\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup error. There has been an error in constructing" + " the non-complete lattice.\n" ); + painCave.isFatal = 1; + simError(); } } else{ @@ -655,12 +805,15 @@ void SimSetup::makeElement( double x, double y, double current_atom = comp_stamps[current_comp]->getAtom( k ); if( !current_atom->havePosition() ){ - std::cerr << "Component " << comp_stamps[current_comp]->getID() - << ", atom " << current_atom->getType() - << " does not have a position specified.\n" - << "The initialization routine is unable to give a start" - << " position.\n"; - exit(8); + sprintf( painCave.errMsg, + "SimSetup:initFromBass error.\n" + "\tComponent %s, atom %s does not have a position specified.\n" + "\tThe initialization routine is unable to give a start" + " position.\n", + comp_stamps[current_comp]->getID(), + current_atom->getType() ); + painCave.isFatal = 1; + simError(); } the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );