--- trunk/mdtools/interface_implementation/SimSetup.cpp 2002/10/17 21:59:12 144 +++ trunk/mdtools/interface_implementation/SimSetup.cpp 2002/11/26 21:04:43 189 @@ -6,6 +6,7 @@ #include "parse_me.h" #include "LRI.hpp" #include "Integrator.hpp" +#include "simError.h" #ifdef IS_MPI #include "mpiBASS.h" @@ -15,6 +16,11 @@ SimSetup::SimSetup(){ SimSetup::SimSetup(){ stamps = new MakeStamps(); globals = new Globals(); + +#ifdef IS_MPI + strcpy( checkPointMsg, "SimSetup creation successful" ); + MPIcheckPoint(); +#endif // IS_MPI } SimSetup::~SimSetup(){ @@ -24,14 +30,23 @@ void SimSetup::parseFile( char* fileName ){ void SimSetup::parseFile( char* fileName ){ - inFileName = fileName; - set_interface_stamps( stamps, globals ); #ifdef IS_MPI - mpiEventInit(); + if( worldRank == 0 ){ +#endif // is_mpi + + inFileName = fileName; + set_interface_stamps( stamps, globals ); + +#ifdef IS_MPI + mpiEventInit(); #endif - yacc_BASS( fileName ); + + yacc_BASS( fileName ); + #ifdef IS_MPI - throwMPIEvent(NULL); + throwMPIEvent(NULL); + } + else receiveParse(); #endif } @@ -41,6 +56,7 @@ void SimSetup::receiveParse(void){ set_interface_stamps( stamps, globals ); mpiEventInit(); + MPIcheckPoint(); mpiEventLoop(); } @@ -52,6 +68,7 @@ void SimSetup::createSim( void ){ delete dumpMe; } #endif + void SimSetup::createSim( void ){ MakeStamps *the_stamps; @@ -76,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]; @@ -95,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(); @@ -105,22 +131,35 @@ 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. for( i=0; in_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(); @@ -225,25 +274,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() ); @@ -254,89 +315,104 @@ void SimSetup::createSim( void ){ // } // 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" ); -// } -// } -// } - -// // make the sample and status out names + initFromBass(); + +#ifdef IS_MPI + strcpy( checkPointMsg, "initFromBass successfully created the lattice" ); + MPIcheckPoint(); +#endif // is_mpi -// 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; @@ -392,7 +468,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; @@ -412,7 +488,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 ); @@ -559,8 +635,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{ @@ -665,12 +744,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() );