--- trunk/mdtools/interface_implementation/SimSetup.cpp 2002/09/23 15:12:56 113 +++ trunk/mdtools/interface_implementation/SimSetup.cpp 2002/10/03 21:52:46 128 @@ -6,6 +6,7 @@ #include "parse_me.h" #include "LRI.hpp" #include "Integrator.hpp" +#include "mpiInterface.h" SimSetup::SimSetup(){ stamps = new MakeStamps(); @@ -21,9 +22,32 @@ void SimSetup::parseFile( char* fileName ){ inFileName = fileName; set_interface_stamps( stamps, globals ); +#ifdef MPI + mpiEventInit(); +#endif yacc_BASS( fileName ); +#ifdef MPI + throwMPIEvent(NULL); +#endif + } +#ifdef MPI +void SimSetup::receiveParse(void){ + + set_interface_stamps( stamps, globals ); + mpiEventInit(); + mpiEventLoop(); + +} +#endif + +void SimSetup::testMe(void){ + bassDiag* dumpMe = new bassDiag(globals,stamps); + dumpMe->dumpStamps(); + delete dumpMe; +} + void SimSetup::createSim( void ){ MakeStamps *the_stamps; @@ -43,12 +67,12 @@ void SimSetup::createSim( void ){ n_components = the_globals->getNComponents(); strcpy( force_field, the_globals->getForceField() ); strcpy( ensemble, the_globals->getEnsemble() ); - + 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{ - std::cerr<< "SimSetup Error. Unrecognized force field -> " + std::cerr<< "SimSetup Error. Unrecognized force field -> " << force_field << "\n"; exit(8); } @@ -57,14 +81,14 @@ void SimSetup::createSim( void ){ the_components = the_globals->getComponents(); components_nmol = new int[n_components]; comp_stamps = new MoleculeStamp*[n_components]; - + if( !the_globals->haveNMol() ){ - // we don't have the total number of molecules, so we assume it is + // we don't have the total number of molecules, so we assume it is // given in each component tot_nmol = 0; for( i=0; ihaveNMol() ){ // we have a problem std::cerr << "SimSetup Error. No global NMol or component NMol" @@ -78,14 +102,14 @@ 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 " @@ -97,12 +121,12 @@ void SimSetup::createSim( void ){ for( i=0; igetMolecule( the_components[i]->getType() ); } - + // caclulate the number of atoms, bonds, bends and torsions tot_atoms = 0; @@ -110,15 +134,15 @@ void SimSetup::createSim( void ){ tot_bends = 0; tot_torsions = 0; for( i=0; igetNAtoms(); tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds(); tot_bends += components_nmol[i] * comp_stamps[i]->getNBends(); tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); } - + tot_SRI = tot_bonds + tot_bends + tot_torsions; - + simnfo->n_atoms = tot_atoms; simnfo->n_bonds = tot_bonds; simnfo->n_bends = tot_bends; @@ -126,11 +150,11 @@ void SimSetup::createSim( void ){ simnfo->n_SRI = tot_SRI; // create the atom and short range interaction arrays - + the_atoms = new Atom*[tot_atoms]; the_molecules = new Molecule[tot_nmol]; - - + + if( tot_SRI ){ the_sris = new SRI*[tot_SRI]; the_excludes = new ex_pair[tot_SRI]; @@ -142,12 +166,12 @@ void SimSetup::createSim( void ){ simnfo->sr_interactions = the_sris; simnfo->n_exclude = tot_SRI; simnfo->excludes = the_excludes; - + // initialize the arrays - + the_ff->setSimInfo( simnfo ); - + makeAtoms(); if( tot_bonds ){ @@ -188,7 +212,7 @@ void SimSetup::createSim( void ){ simnfo->box_z = the_globals->getBox(); } else if( the_globals->haveDensity() ){ - + double vol; vol = (double)tot_nmol / the_globals->getDensity(); simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) ); @@ -214,103 +238,108 @@ void SimSetup::createSim( void ){ } simnfo->box_z = the_globals->getBoxZ(); } - - if( the_globals->haveInitialConfig() ){ - InitializeFromFile* fileInit; - fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); - - fileInit->read_xyz( simnfo ); // default velocities on - delete fileInit; - } - else{ + +// if( the_globals->haveInitialConfig() ){ +// InitializeFromFile* fileInit; +// fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); + +// fileInit->read_xyz( simnfo ); // default velocities on + +// delete fileInit; +// } +// 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 - 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" ); - } - } - +// } + +// 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" ); +// } +// } + + // set the status, sample, and themal kick times if( the_globals->haveSampleTime() ){ - simnfo->sampleTime = the_globals->getSampleTime(); + simnfo->sampleTime = the_globals->getSampleTime(); simnfo->statusTime = simnfo->sampleTime; simnfo->thermalTime = simnfo->sampleTime; } else{ - simnfo->sampleTime = the_globals->getRunTime(); + simnfo->sampleTime = the_globals->getRunTime(); simnfo->statusTime = simnfo->sampleTime; simnfo->thermalTime = simnfo->sampleTime; } @@ -326,49 +355,54 @@ void SimSetup::createSim( void ){ // check for the temperature set flag 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" ) ) new Verlet( *simnfo ); if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo ); if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo ); } void SimSetup::makeAtoms( void ){ - + int i, j, k, index; double ux, uy, uz, uSqr, u; AtomStamp* current_atom; DirectionalAtom* dAtom; + int molIndex, molStart, molEnd, nMemb; + + molIndex = 0; index = 0; for( i=0; igetNAtoms(); for( k=0; kgetNAtoms(); k++ ){ - + current_atom = comp_stamps[i]->getAtom( k ); - if( current_atom->haveOrientation() ){ + if( current_atom->haveOrientation() ){ dAtom = new DirectionalAtom; simnfo->n_oriented++; the_atoms[index] = dAtom; - + ux = current_atom->getOrntX(); uy = current_atom->getOrntY(); uz = current_atom->getOrntZ(); - + uSqr = (ux * ux) + (uy * uy) + (uz * uz); - + u = sqrt( uSqr ); ux = ux / u; uy = uy / u; uz = uz / u; - + dAtom->setSUx( ux ); dAtom->setSUy( uy ); dAtom->setSUz( uz ); @@ -378,13 +412,20 @@ void SimSetup::makeAtoms( void ){ } the_atoms[index]->setType( current_atom->getType() ); the_atoms[index]->setIndex( index ); - + // increment the index and repeat; index++; } + + molEnd = index -1; + the_molecules[molIndex].setNMembers( nMemb ); + the_molecules[molIndex].setStartAtom( molStart ); + the_molecules[molIndex].setEndAtom( molEnd ); + molIndex++; + } } - + the_ff->initializeAtoms(); } @@ -398,11 +439,11 @@ void SimSetup::makeBonds( void ){ index = 0; offset = 0; for( i=0; igetNBonds(); k++ ){ - + current_bond = comp_stamps[i]->getBond( k ); the_bonds[index].a = current_bond->getA() + offset; the_bonds[index].b = current_bond->getB() + offset; @@ -416,7 +457,7 @@ void SimSetup::makeBonds( void ){ offset += comp_stamps[i]->getNAtoms(); } } - + the_ff->initializeBonds( the_bonds ); } @@ -430,11 +471,11 @@ void SimSetup::makeBends( void ){ index = 0; offset = 0; for( i=0; igetNBends(); k++ ){ - + current_bend = comp_stamps[i]->getBend( k ); the_bends[index].a = current_bend->getA() + offset; the_bends[index].b = current_bend->getB() + offset; @@ -449,7 +490,7 @@ void SimSetup::makeBends( void ){ offset += comp_stamps[i]->getNAtoms(); } } - + the_ff->initializeBends( the_bends ); } @@ -463,11 +504,11 @@ void SimSetup::makeTorsions( void ){ index = 0; offset = 0; for( i=0; igetNTorsions(); k++ ){ - + current_torsion = comp_stamps[i]->getTorsion( k ); the_torsions[index].a = current_torsion->getA() + offset; the_torsions[index].b = current_torsion->getB() + offset; @@ -483,22 +524,10 @@ void SimSetup::makeTorsions( void ){ offset += comp_stamps[i]->getNAtoms(); } } - + the_ff->initializeTorsions( the_torsions ); } -void SimSetup::makeMolecules( void ){ - - int i,j,k; - - for( i=0; ibox_y / temp3; cellz = simnfo->box_z / temp3; } - + current_mol = 0; current_comp_mol = 0; current_comp = 0; current_atom_ndx = 0; - + for( i=0; i < n_cells ; i++ ){ for( j=0; j < n_cells; j++ ){ for( k=0; k < n_cells; k++ ){ - + makeElement( i * cellx, j * celly, k * cellz ); - + makeElement( i * cellx + 0.5 * cellx, j * celly + 0.5 * celly, k * cellz ); - + makeElement( i * cellx, j * celly + 0.5 * celly, k * cellz + 0.5 * cellz ); - + makeElement( i * cellx + 0.5 * cellx, j * celly, k * cellz + 0.5 * cellz ); @@ -567,41 +596,41 @@ void SimSetup::initFromBass( void ){ if( have_extra ){ done = 0; - + int start_ndx; for( i=0; i < (n_cells+1) && !done; i++ ){ for( j=0; j < (n_cells+1) && !done; j++ ){ - + if( i < n_cells ){ - + if( j < n_cells ){ start_ndx = n_cells; } else start_ndx = 0; } else start_ndx = 0; - + for( k=start_ndx; k < (n_cells+1) && !done; k++ ){ - + makeElement( i * cellx, j * celly, k * cellz ); done = ( current_mol >= tot_nmol ); - + if( !done && n_per_extra > 1 ){ makeElement( i * cellx + 0.5 * cellx, j * celly + 0.5 * celly, k * cellz ); done = ( current_mol >= tot_nmol ); } - + if( !done && n_per_extra > 2){ makeElement( i * cellx, j * celly + 0.5 * celly, k * cellz + 0.5 * cellz ); done = ( current_mol >= tot_nmol ); } - + if( !done && n_per_extra > 3){ makeElement( i * cellx + 0.5 * cellx, j * celly, @@ -612,8 +641,8 @@ void SimSetup::initFromBass( void ){ } } } - - + + for( i=0; in_atoms; i++ ){ simnfo->atoms[i]->set_vx( 0.0 ); simnfo->atoms[i]->set_vy( 0.0 ); @@ -629,7 +658,7 @@ void SimSetup::makeElement( double x, double y, double double rotMat[3][3]; for( k=0; kgetNAtoms(); k++ ){ - + current_atom = comp_stamps[current_comp]->getAtom( k ); if( !current_atom->havePosition() ){ std::cerr << "Component " << comp_stamps[current_comp]->getID() @@ -639,15 +668,15 @@ void SimSetup::makeElement( double x, double y, double << " position.\n"; exit(8); } - + the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() ); the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() ); the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() ); - + if( the_atoms[current_atom_ndx]->isDirectional() ){ - + dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx]; - + rotMat[0][0] = 1.0; rotMat[0][1] = 0.0; rotMat[0][2] = 0.0; @@ -665,12 +694,12 @@ void SimSetup::makeElement( double x, double y, double current_atom_ndx++; } - + current_mol++; current_comp_mol++; if( current_comp_mol >= components_nmol[current_comp] ){ - + current_comp_mol = 0; current_comp++; }