--- trunk/OOPSE/libmdtools/SimSetup.cpp 2003/08/20 22:23:34 708 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2003/08/26 20:02:29 722 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "SimSetup.hpp" #include "ReadWrite.hpp" @@ -32,16 +32,15 @@ SimSetup::SimSetup(){ using namespace std; SimSetup::SimSetup(){ - isInfoArray = 0; nInfo = 1; - + stamps = new MakeStamps(); globals = new Globals(); - - + + #ifdef IS_MPI - strcpy( checkPointMsg, "SimSetup creation successful" ); + strcpy(checkPointMsg, "SimSetup creation successful"); MPIcheckPoint(); #endif // IS_MPI } @@ -51,52 +50,50 @@ void SimSetup::setSimInfo( SimInfo* the_info, int theN delete globals; } -void SimSetup::setSimInfo( SimInfo* the_info, int theNinfo ) { - info = the_info; - nInfo = theNinfo; - isInfoArray = 1; +void SimSetup::setSimInfo(SimInfo* the_info, int theNinfo){ + info = the_info; + nInfo = theNinfo; + isInfoArray = 1; } -void SimSetup::parseFile( char* fileName ){ - +void SimSetup::parseFile(char* fileName){ #ifdef IS_MPI - if( worldRank == 0 ){ + if (worldRank == 0){ #endif // is_mpi - + inFileName = fileName; - set_interface_stamps( stamps, globals ); - + set_interface_stamps(stamps, globals); + #ifdef IS_MPI mpiEventInit(); #endif - yacc_BASS( fileName ); + yacc_BASS(fileName); #ifdef IS_MPI throwMPIEvent(NULL); } - else receiveParse(); + else{ + receiveParse(); + } #endif } #ifdef IS_MPI void SimSetup::receiveParse(void){ - - set_interface_stamps( stamps, globals ); - mpiEventInit(); - MPIcheckPoint(); - mpiEventLoop(); - + set_interface_stamps(stamps, globals); + mpiEventInit(); + MPIcheckPoint(); + mpiEventLoop(); } #endif // is_mpi void SimSetup::createSim(void){ - int i, j, k, globalAtomIndex; - + // gather all of the information from the Bass file gatherInfo(); @@ -111,16 +108,18 @@ void SimSetup::createSim(void){ // initialize the system coordinates - if( !isInfoArray ) initSystemCoords(); + if (!isInfoArray){ + initSystemCoords(); + } // make the output filenames makeOutNames(); - + // make the integrator - + makeIntegrator(); - + #ifdef IS_MPI mpiSim->mpiRefresh(); #endif @@ -128,15 +127,11 @@ void SimSetup::createSim(void){ // initialize the Fortran initFortran(); - - - } -void SimSetup::makeMolecules( void ){ - - int k,l; +void SimSetup::makeMolecules(void){ + int k, l; int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset; molInit molInfo; DirectionalAtom* dAtom; @@ -151,261 +146,244 @@ void SimSetup::makeMolecules( void ){ bend_set* theBends; torsion_set* theTorsions; - + //init the forceField paramters the_ff->readParams(); - + // init the atoms double ux, uy, uz, u, uSqr; - - for(k=0; ksetSimInfo( &(info[k]) ); + for (k = 0; k < nInfo; k++){ + the_ff->setSimInfo(&(info[k])); + atomOffset = 0; excludeOffset = 0; - for(i=0; igetNAtoms(); - molInfo.nBonds = comp_stamps[stampID]->getNBonds(); - molInfo.nBends = comp_stamps[stampID]->getNBends(); + molInfo.nAtoms = comp_stamps[stampID]->getNAtoms(); + molInfo.nBonds = comp_stamps[stampID]->getNBonds(); + molInfo.nBends = comp_stamps[stampID]->getNBends(); molInfo.nTorsions = comp_stamps[stampID]->getNTorsions(); molInfo.nExcludes = molInfo.nBonds + molInfo.nBends + molInfo.nTorsions; - + molInfo.myAtoms = &(info[k].atoms[atomOffset]); molInfo.myExcludes = &(info[k].excludes[excludeOffset]); - molInfo.myBonds = new Bond*[molInfo.nBonds]; - molInfo.myBends = new Bend*[molInfo.nBends]; - molInfo.myTorsions = new Torsion*[molInfo.nTorsions]; + molInfo.myBonds = new Bond * [molInfo.nBonds]; + molInfo.myBends = new Bend * [molInfo.nBends]; + molInfo.myTorsions = new Torsion * [molInfo.nTorsions]; theBonds = new bond_pair[molInfo.nBonds]; theBends = new bend_set[molInfo.nBends]; theTorsions = new torsion_set[molInfo.nTorsions]; - + // make the Atoms - - for(j=0; jgetAtom( j ); - if( currentAtom->haveOrientation() ){ - - dAtom = new DirectionalAtom( (j + atomOffset), - info[k].getConfiguration() ); - info[k].n_oriented++; - molInfo.myAtoms[j] = dAtom; - - ux = currentAtom->getOrntX(); - uy = currentAtom->getOrntY(); - uz = currentAtom->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 ); - } - else{ - molInfo.myAtoms[j] = new GeneralAtom( (j + atomOffset), - info[k].getConfiguration() ); - } - molInfo.myAtoms[j]->setType( currentAtom->getType() ); - + + for (j = 0; j < molInfo.nAtoms; j++){ + currentAtom = comp_stamps[stampID]->getAtom(j); + if (currentAtom->haveOrientation()){ + dAtom = new DirectionalAtom((j + atomOffset), + info[k].getConfiguration()); + info[k].n_oriented++; + molInfo.myAtoms[j] = dAtom; + + ux = currentAtom->getOrntX(); + uy = currentAtom->getOrntY(); + uz = currentAtom->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); + } + else{ + molInfo.myAtoms[j] = new GeneralAtom((j + atomOffset), + info[k].getConfiguration()); + } + molInfo.myAtoms[j]->setType(currentAtom->getType()); + #ifdef IS_MPI - - molInfo.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] ); - + + molInfo.myAtoms[j]->setGlobalIndex(globalIndex[j + atomOffset]); + #endif // is_mpi } - - // make the bonds - for(j=0; jgetBond( j ); - theBonds[j].a = currentBond->getA() + atomOffset; - theBonds[j].b = currentBond->getB() + atomOffset; - - exI = theBonds[j].a; - exJ = theBonds[j].b; - - // exclude_I must always be the smaller of the pair - if( exI > exJ ){ - tempEx = exI; - exI = exJ; - exJ = tempEx; - } + + // make the bonds + for (j = 0; j < molInfo.nBonds; j++){ + currentBond = comp_stamps[stampID]->getBond(j); + theBonds[j].a = currentBond->getA() + atomOffset; + theBonds[j].b = currentBond->getB() + atomOffset; + + exI = theBonds[j].a; + exJ = theBonds[j].b; + + // exclude_I must always be the smaller of the pair + if (exI > exJ){ + tempEx = exI; + exI = exJ; + exJ = tempEx; + } #ifdef IS_MPI - tempEx = exI; - exI = info[k].atoms[tempEx]->getGlobalIndex() + 1; - tempEx = exJ; - exJ = info[k].atoms[tempEx]->getGlobalIndex() + 1; - - info[k].excludes[j+excludeOffset]->setPair( exI, exJ ); + tempEx = exI; + exI = info[k].atoms[tempEx]->getGlobalIndex() + 1; + tempEx = exJ; + exJ = info[k].atoms[tempEx]->getGlobalIndex() + 1; + + info[k].excludes[j + excludeOffset]->setPair(exI, exJ); #else // isn't MPI - - info[k].excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) ); + + info[k].excludes[j + excludeOffset]->setPair((exI + 1), (exJ + 1)); #endif //is_mpi } excludeOffset += molInfo.nBonds; - + //make the bends - for(j=0; jgetBend( j ); - theBends[j].a = currentBend->getA() + atomOffset; - theBends[j].b = currentBend->getB() + atomOffset; - theBends[j].c = currentBend->getC() + atomOffset; - - if( currentBend->haveExtras() ){ - - extras = currentBend->getExtras(); - current_extra = extras; - - while( current_extra != NULL ){ - if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){ - - switch( current_extra->getType() ){ - - case 0: - theBends[j].ghost = - current_extra->getInt() + atomOffset; - theBends[j].isGhost = 1; - break; - - case 1: - theBends[j].ghost = - (int)current_extra->getDouble() + atomOffset; - theBends[j].isGhost = 1; - break; - - default: - sprintf( painCave.errMsg, - "SimSetup Error: ghostVectorSource was neither a " - "double nor an int.\n" - "-->Bend[%d] in %s\n", - j, comp_stamps[stampID]->getID() ); - painCave.isFatal = 1; - simError(); - } - } - - else{ - - sprintf( painCave.errMsg, - "SimSetup Error: unhandled bend assignment:\n" - " -->%s in Bend[%d] in %s\n", - current_extra->getlhs(), - j, comp_stamps[stampID]->getID() ); - painCave.isFatal = 1; - simError(); - } - - current_extra = current_extra->getNext(); - } - } - - if( !theBends[j].isGhost ){ - - exI = theBends[j].a; - exJ = theBends[j].c; - } - else{ - - exI = theBends[j].a; - exJ = theBends[j].b; - } - - // exclude_I must always be the smaller of the pair - if( exI > exJ ){ - tempEx = exI; - exI = exJ; - exJ = tempEx; - } + for (j = 0; j < molInfo.nBends; j++){ + currentBend = comp_stamps[stampID]->getBend(j); + theBends[j].a = currentBend->getA() + atomOffset; + theBends[j].b = currentBend->getB() + atomOffset; + theBends[j].c = currentBend->getC() + atomOffset; + + if (currentBend->haveExtras()){ + extras = currentBend->getExtras(); + current_extra = extras; + + while (current_extra != NULL){ + if (!strcmp(current_extra->getlhs(), "ghostVectorSource")){ + switch (current_extra->getType()){ + case 0: + theBends[j].ghost = current_extra->getInt() + atomOffset; + theBends[j].isGhost = 1; + break; + + case 1: + theBends[j].ghost = (int) current_extra->getDouble() + + atomOffset; + theBends[j].isGhost = 1; + break; + + default: + sprintf(painCave.errMsg, + "SimSetup Error: ghostVectorSource was neither a " + "double nor an int.\n" + "-->Bend[%d] in %s\n", + j, comp_stamps[stampID]->getID()); + painCave.isFatal = 1; + simError(); + } + } + else{ + sprintf(painCave.errMsg, + "SimSetup Error: unhandled bend assignment:\n" + " -->%s in Bend[%d] in %s\n", + current_extra->getlhs(), j, comp_stamps[stampID]->getID()); + painCave.isFatal = 1; + simError(); + } + + current_extra = current_extra->getNext(); + } + } + + if (!theBends[j].isGhost){ + exI = theBends[j].a; + exJ = theBends[j].c; + } + else{ + exI = theBends[j].a; + exJ = theBends[j].b; + } + + // exclude_I must always be the smaller of the pair + if (exI > exJ){ + tempEx = exI; + exI = exJ; + exJ = tempEx; + } #ifdef IS_MPI - tempEx = exI; - exI = info[k].atoms[tempEx]->getGlobalIndex() + 1; - tempEx = exJ; - exJ = info[k].atoms[tempEx]->getGlobalIndex() + 1; - - info[k].excludes[j+excludeOffset]->setPair( exI, exJ ); + tempEx = exI; + exI = info[k].atoms[tempEx]->getGlobalIndex() + 1; + tempEx = exJ; + exJ = info[k].atoms[tempEx]->getGlobalIndex() + 1; + + info[k].excludes[j + excludeOffset]->setPair(exI, exJ); #else // isn't MPI - info[k].excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) ); + info[k].excludes[j + excludeOffset]->setPair((exI + 1), (exJ + 1)); #endif //is_mpi } excludeOffset += molInfo.nBends; - - for(j=0; jgetTorsion( j ); - theTorsions[j].a = currentTorsion->getA() + atomOffset; - theTorsions[j].b = currentTorsion->getB() + atomOffset; - theTorsions[j].c = currentTorsion->getC() + atomOffset; - theTorsions[j].d = currentTorsion->getD() + atomOffset; - - exI = theTorsions[j].a; - exJ = theTorsions[j].d; - - // exclude_I must always be the smaller of the pair - if( exI > exJ ){ - tempEx = exI; - exI = exJ; - exJ = tempEx; - } + + for (j = 0; j < molInfo.nTorsions; j++){ + currentTorsion = comp_stamps[stampID]->getTorsion(j); + theTorsions[j].a = currentTorsion->getA() + atomOffset; + theTorsions[j].b = currentTorsion->getB() + atomOffset; + theTorsions[j].c = currentTorsion->getC() + atomOffset; + theTorsions[j].d = currentTorsion->getD() + atomOffset; + + exI = theTorsions[j].a; + exJ = theTorsions[j].d; + + // exclude_I must always be the smaller of the pair + if (exI > exJ){ + tempEx = exI; + exI = exJ; + exJ = tempEx; + } #ifdef IS_MPI - tempEx = exI; - exI = info[k].atoms[tempEx]->getGlobalIndex() + 1; - tempEx = exJ; - exJ = info[k].atoms[tempEx]->getGlobalIndex() + 1; - - info[k].excludes[j+excludeOffset]->setPair( exI, exJ ); + tempEx = exI; + exI = info[k].atoms[tempEx]->getGlobalIndex() + 1; + tempEx = exJ; + exJ = info[k].atoms[tempEx]->getGlobalIndex() + 1; + + info[k].excludes[j + excludeOffset]->setPair(exI, exJ); #else // isn't MPI - info[k].excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) ); + info[k].excludes[j + excludeOffset]->setPair((exI + 1), (exJ + 1)); #endif //is_mpi } excludeOffset += molInfo.nTorsions; - - + + // send the arrays off to the forceField for init. - - the_ff->initializeAtoms( molInfo.nAtoms, molInfo.myAtoms ); - the_ff->initializeBonds( molInfo.nBonds, molInfo.myBonds, theBonds ); - the_ff->initializeBends( molInfo.nBends, molInfo.myBends, theBends ); - the_ff->initializeTorsions( molInfo.nTorsions, molInfo.myTorsions, theTorsions ); - - - info[k].molecules[i].initialize( molInfo ); - + the_ff->initializeAtoms(molInfo.nAtoms, molInfo.myAtoms); + the_ff->initializeBonds(molInfo.nBonds, molInfo.myBonds, theBonds); + the_ff->initializeBends(molInfo.nBends, molInfo.myBends, theBends); + the_ff->initializeTorsions(molInfo.nTorsions, molInfo.myTorsions, + theTorsions); + + + info[k].molecules[i].initialize(molInfo); + + atomOffset += molInfo.nAtoms; delete[] theBonds; delete[] theBends; delete[] theTorsions; } } - + #ifdef IS_MPI - sprintf( checkPointMsg, "all molecules initialized succesfully" ); + sprintf(checkPointMsg, "all molecules initialized succesfully"); MPIcheckPoint(); #endif // is_mpi - + // clean up the forcefield the_ff->calcRcut(); the_ff->cleanMe(); - } -void SimSetup::initFromBass( void ){ - +void SimSetup::initFromBass(void){ int i, j, k; int n_cells; double cellx, celly, cellz; @@ -419,32 +397,33 @@ void SimSetup::initFromBass( void ){ vel[1] = 0.0; vel[2] = 0.0; - temp1 = (double)tot_nmol / 4.0; - temp2 = pow( temp1, ( 1.0 / 3.0 ) ); - temp3 = ceil( temp2 ); + temp1 = (double) tot_nmol / 4.0; + temp2 = pow(temp1, (1.0 / 3.0)); + temp3 = ceil(temp2); - have_extra =0; - if( temp2 < temp3 ){ // we have a non-complete lattice - have_extra =1; + have_extra = 0; + if (temp2 < temp3){ + // we have a non-complete lattice + have_extra = 1; - n_cells = (int)temp3 - 1; + n_cells = (int) temp3 - 1; cellx = info[0].boxL[0] / temp3; celly = info[0].boxL[1] / temp3; cellz = info[0].boxL[2] / 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 ); + 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); - if( n_per_extra > 4){ - sprintf( painCave.errMsg, - "SimSetup error. There has been an error in constructing" - " the non-complete lattice.\n" ); + if (n_per_extra > 4){ + sprintf(painCave.errMsg, + "SimSetup error. There has been an error in constructing" + " the non-complete lattice.\n"); painCave.isFatal = 1; simError(); } } else{ - n_cells = (int)temp3; + n_cells = (int) temp3; cellx = info[0].boxL[0] / temp3; celly = info[0].boxL[1] / temp3; cellz = info[0].boxL[2] / temp3; @@ -455,114 +434,95 @@ void SimSetup::initFromBass( void ){ 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++ ){ + 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, - j * celly, - k * cellz ); + makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * 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, - j * celly + 0.5 * celly, - k * cellz + 0.5 * cellz ); - - makeElement( i * cellx + 0.5 * cellx, - j * celly, - k * cellz + 0.5 * cellz ); + makeElement(i * cellx + 0.5 * cellx, j * celly, k * cellz + 0.5 * cellz); } } } - if( have_extra ){ + 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++ ){ + 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; - if( i < n_cells ){ + for (k = start_ndx; k < (n_cells + 1) && !done; k++){ + makeElement(i * cellx, j * celly, k * cellz); + done = (current_mol >= tot_nmol); - if( j < n_cells ){ - start_ndx = n_cells; - } - else start_ndx = 0; - } - else start_ndx = 0; + if (!done && n_per_extra > 1){ + makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * celly, + k * cellz); + done = (current_mol >= tot_nmol); + } - 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 > 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, - k * cellz + 0.5 * cellz ); - done = ( current_mol >= tot_nmol ); - } - } + if (!done && n_per_extra > 3){ + makeElement(i * cellx + 0.5 * cellx, j * celly, + k * cellz + 0.5 * cellz); + done = (current_mol >= tot_nmol); + } + } } } } - for( i=0; isetVel( vel ); + for (i = 0; i < info[0].n_atoms; i++){ + info[0].atoms[i]->setVel(vel); } } -void SimSetup::makeElement( double x, double y, double z ){ - +void SimSetup::makeElement(double x, double y, double z){ int k; AtomStamp* current_atom; DirectionalAtom* dAtom; double rotMat[3][3]; double pos[3]; - for( k=0; kgetNAtoms(); k++ ){ - - current_atom = comp_stamps[current_comp]->getAtom( k ); - if( !current_atom->havePosition() ){ - 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() ); + for (k = 0; k < comp_stamps[current_comp]->getNAtoms(); k++){ + current_atom = comp_stamps[current_comp]->getAtom(k); + if (!current_atom->havePosition()){ + 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(); } - + pos[0] = x + current_atom->getPosX(); pos[1] = y + current_atom->getPosY(); pos[2] = z + current_atom->getPosZ(); - - info[0].atoms[current_atom_ndx]->setPos( pos ); - if( info[0].atoms[current_atom_ndx]->isDirectional() ){ + info[0].atoms[current_atom_ndx]->setPos(pos); - dAtom = (DirectionalAtom *)info[0].atoms[current_atom_ndx]; + if (info[0].atoms[current_atom_ndx]->isDirectional()){ + dAtom = (DirectionalAtom *) info[0].atoms[current_atom_ndx]; rotMat[0][0] = 1.0; rotMat[0][1] = 0.0; @@ -576,7 +536,7 @@ void SimSetup::makeElement( double x, double y, double rotMat[2][1] = 0.0; rotMat[2][2] = 1.0; - dAtom->setA( rotMat ); + dAtom->setA(rotMat); } current_atom_ndx++; @@ -585,23 +545,22 @@ void SimSetup::makeElement( double x, double y, double current_mol++; current_comp_mol++; - if( current_comp_mol >= components_nmol[current_comp] ){ - + if (current_comp_mol >= components_nmol[current_comp]){ current_comp_mol = 0; current_comp++; } } -void SimSetup::gatherInfo( void ){ - int i,j,k; +void SimSetup::gatherInfo(void){ + int i, j, k; ensembleCase = -1; ffCase = -1; // set the easy ones first - for( i=0; igetTargetTemp(); info[i].dt = globals->getDt(); info[i].run_time = globals->getRunTime(); @@ -611,71 +570,85 @@ void SimSetup::gatherInfo( void ){ // get the forceField - strcpy( force_field, globals->getForceField() ); + strcpy(force_field, globals->getForceField()); - if( !strcasecmp( force_field, "DUFF" )) ffCase = FF_DUFF; - else if( !strcasecmp( force_field, "LJ" )) ffCase = FF_LJ; - else if( !strcasecmp( force_field, "EAM" )) ffCase = FF_EAM; + if (!strcasecmp(force_field, "DUFF")){ + ffCase = FF_DUFF; + } + else if (!strcasecmp(force_field, "LJ")){ + ffCase = FF_LJ; + } + else if (!strcasecmp(force_field, "EAM")){ + ffCase = FF_EAM; + } else{ - sprintf( painCave.errMsg, - "SimSetup Error. Unrecognized force field -> %s\n", - force_field ); - painCave.isFatal = 1; - simError(); + sprintf(painCave.errMsg, "SimSetup Error. Unrecognized force field -> %s\n", + force_field); + painCave.isFatal = 1; + simError(); } - // get the ensemble + // get the ensemble - strcpy( ensemble, globals->getEnsemble() ); + strcpy(ensemble, globals->getEnsemble()); - if( !strcasecmp( ensemble, "NVE" )) ensembleCase = NVE_ENS; - else if( !strcasecmp( ensemble, "NVT" )) ensembleCase = NVT_ENS; - else if( !strcasecmp( ensemble, "NPTi" ) || !strcasecmp( ensemble, "NPT") ) + 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 if( !strcasecmp( ensemble, "NPTim" )) ensembleCase = NPTim_ENS; - else if( !strcasecmp( ensemble, "NPTfm" )) ensembleCase = NPTfm_ENS; + } + else if (!strcasecmp(ensemble, "NPTf")){ + ensembleCase = NPTf_ENS; + } + else if (!strcasecmp(ensemble, "NPTim")){ + ensembleCase = NPTim_ENS; + } + else if (!strcasecmp(ensemble, "NPTfm")){ + ensembleCase = NPTfm_ENS; + } else{ - sprintf( painCave.errMsg, - "SimSetup Warning. Unrecognized Ensemble -> %s, " - "reverting to NVE for this simulation.\n", - ensemble ); - painCave.isFatal = 0; - simError(); - strcpy( ensemble, "NVE" ); - ensembleCase = NVE_ENS; + sprintf(painCave.errMsg, + "SimSetup Warning. Unrecognized Ensemble -> %s, " + "reverting to NVE for this simulation.\n", + ensemble); + painCave.isFatal = 0; + simError(); + strcpy(ensemble, "NVE"); + ensembleCase = NVE_ENS; } - - for(i=0; igetMixingRule() ); + strcpy(info[i].mixingRule, globals->getMixingRule()); info[i].usePBC = globals->getPBC(); } - + // get the components and calculate the tot_nMol and indvidual n_mol - + the_components = globals->getComponents(); components_nmol = new int[n_components]; - if( !globals->haveNMol() ){ + if (!globals->haveNMol()){ // 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 - sprintf( painCave.errMsg, - "SimSetup Error. No global NMol or component NMol" - " given. Cannot calculate the number of atoms.\n" ); - painCave.isFatal = 1; - simError(); + for (i = 0; i < n_components; i++){ + if (!the_components[i]->haveNMol()){ + // we have a problem + 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(); @@ -683,21 +656,20 @@ void SimSetup::gatherInfo( void ){ } } else{ - 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" ); + 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(); } // set the status, sample, and thermal kick times - - for(i=0; ihaveSampleTime() ){ + for (i = 0; i < nInfo; i++){ + if (globals->haveSampleTime()){ info[i].sampleTime = globals->getSampleTime(); info[i].statusTime = info[i].sampleTime; info[i].thermalTime = info[i].sampleTime; @@ -707,358 +679,374 @@ void SimSetup::gatherInfo( void ){ info[i].statusTime = info[i].sampleTime; info[i].thermalTime = info[i].sampleTime; } - - if( globals->haveStatusTime() ){ + + if (globals->haveStatusTime()){ info[i].statusTime = globals->getStatusTime(); } - - if( globals->haveThermalTime() ){ + + if (globals->haveThermalTime()){ info[i].thermalTime = globals->getThermalTime(); } // check for the temperature set flag - if( globals->haveTempSet() ) info[i].setTemp = globals->getTempSet(); - + if (globals->haveTempSet()) + info[i].setTemp = globals->getTempSet(); + // get some of the tricky things that may still be in the globals - + double boxVector[3]; - if( globals->haveBox() ){ + if (globals->haveBox()){ boxVector[0] = globals->getBox(); boxVector[1] = globals->getBox(); boxVector[2] = globals->getBox(); - - info[i].setBox( boxVector ); + + info[i].setBox(boxVector); } - else if( globals->haveDensity() ){ - + else if (globals->haveDensity()){ double vol; - vol = (double)tot_nmol / globals->getDensity(); - boxVector[0] = pow( vol, ( 1.0 / 3.0 ) ); + vol = (double) tot_nmol / globals->getDensity(); + boxVector[0] = pow(vol, (1.0 / 3.0)); boxVector[1] = boxVector[0]; boxVector[2] = boxVector[0]; - - info[i].setBox( boxVector ); - } + + info[i].setBox(boxVector); + } else{ - if( !globals->haveBoxX() ){ - sprintf( painCave.errMsg, - "SimSetup error, no periodic BoxX size given.\n" ); - painCave.isFatal = 1; - simError(); + if (!globals->haveBoxX()){ + sprintf(painCave.errMsg, + "SimSetup error, no periodic BoxX size given.\n"); + painCave.isFatal = 1; + simError(); } boxVector[0] = globals->getBoxX(); - - if( !globals->haveBoxY() ){ - sprintf( painCave.errMsg, - "SimSetup error, no periodic BoxY size given.\n" ); - painCave.isFatal = 1; - simError(); + + if (!globals->haveBoxY()){ + sprintf(painCave.errMsg, + "SimSetup error, no periodic BoxY size given.\n"); + painCave.isFatal = 1; + simError(); } boxVector[1] = globals->getBoxY(); - - if( !globals->haveBoxZ() ){ - sprintf( painCave.errMsg, - "SimSetup error, no periodic BoxZ size given.\n" ); - painCave.isFatal = 1; - simError(); + + if (!globals->haveBoxZ()){ + sprintf(painCave.errMsg, + "SimSetup error, no periodic BoxZ size given.\n"); + painCave.isFatal = 1; + simError(); } boxVector[2] = globals->getBoxZ(); - - info[i].setBox( boxVector ); + + info[i].setBox(boxVector); } } + //setup seed for random number generator int seedValue; - struct timeval now_time_val; - struct timezone time_zone; - if(globals->haveSeed()){ + if (globals->haveSeed()){ seedValue = globals->getSeed(); - } + + if(seedValue / 1E9 == 0){ + sprintf(painCave.errMsg, + "Seed for sprng library should contain at least 9 digits\n" + "OOPSE will generate a seed for user\n"); + painCave.isFatal = 0; + simError(); + + //using seed generated by system instead of invalid seed set by user +#ifndef IS_MPI + seedValue = make_sprng_seed(); +#else + if (worldRank == 0){ + seedValue = make_sprng_seed(); + } + MPI_Bcast(&seedValue, 1, MPI_INT, 0, MPI_COMM_WORLD); +#endif + } + }//end of if branch of globals->haveSeed() else{ + #ifndef IS_MPI - gettimeofday(&now_time_val, &time_zone); // get the time now - seedValue = (int) now_time_val.tv_sec; // convert to epoch time + seedValue = make_sprng_seed(); #else - if(worldRank == 0){ - gettimeofday(&now_time_val, &time_zone); // get the time now - seedValue = (int) now_time_val.tv_sec; // convert to epoch time + if (worldRank == 0){ + seedValue = make_sprng_seed(); } - MPI_Bcast(&seedValue, 1, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Bcast(&seedValue, 1, MPI_INT, 0, MPI_COMM_WORLD); #endif - } + }//end of globals->haveSeed() - for(int i = 0; i < nInfo; i++){ + for (int i = 0; i < nInfo; i++){ info[i].setSeed(seedValue); } #ifdef IS_MPI - strcpy( checkPointMsg, "Succesfully gathered all information from Bass\n" ); + strcpy(checkPointMsg, "Succesfully gathered all information from Bass\n"); MPIcheckPoint(); #endif // is_mpi - } -void SimSetup::finalInfoCheck( void ){ +void SimSetup::finalInfoCheck(void){ int index; int usesDipoles; int i; - for(i=0; ihasDipole(); index++; } - + #ifdef IS_MPI int myUse = usesDipoles; - MPI_Allreduce( &myUse, &usesDipoles, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD ); + MPI_Allreduce(&myUse, &usesDipoles, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); #endif //is_mpi - + double theEcr, theEst; - - if (globals->getUseRF() ) { + + if (globals->getUseRF()){ info[i].useReactionField = 1; - - if( !globals->haveECR() ){ - sprintf( painCave.errMsg, - "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; - simError(); - double smallest; - smallest = info[i].boxL[0]; - if (info[i].boxL[1] <= smallest) smallest = info[i].boxL[1]; - if (info[i].boxL[2] <= smallest) smallest = info[i].boxL[2]; - theEcr = 0.5 * smallest; - } else { - theEcr = globals->getECR(); + + if (!globals->haveECR()){ + sprintf(painCave.errMsg, + "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; + simError(); + double smallest; + smallest = info[i].boxL[0]; + if (info[i].boxL[1] <= smallest) + smallest = info[i].boxL[1]; + if (info[i].boxL[2] <= smallest) + smallest = info[i].boxL[2]; + theEcr = 0.5 * smallest; } - - if( !globals->haveEST() ){ - sprintf( painCave.errMsg, - "SimSetup Warning: using default value of 0.05 * the " - "electrostaticCutoffRadius for the electrostaticSkinThickness\n" - ); - painCave.isFatal = 0; - simError(); - theEst = 0.05 * theEcr; - } else { - theEst= globals->getEST(); + else{ + theEcr = globals->getECR(); } - - info[i].setEcr( theEcr, theEst ); - - if(!globals->haveDielectric() ){ - sprintf( painCave.errMsg, - "SimSetup Error: You are trying to use Reaction Field without" - "setting a dielectric constant!\n" - ); - painCave.isFatal = 1; - simError(); + + if (!globals->haveEST()){ + sprintf(painCave.errMsg, + "SimSetup Warning: using default value of 0.05 * the " + "electrostaticCutoffRadius for the electrostaticSkinThickness\n"); + painCave.isFatal = 0; + simError(); + theEst = 0.05 * theEcr; } - info[i].dielectric = globals->getDielectric(); - } - else { - if (usesDipoles) { - - if( !globals->haveECR() ){ - sprintf( painCave.errMsg, - "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; - simError(); - double smallest; - smallest = info[i].boxL[0]; - if (info[i].boxL[1] <= smallest) smallest = info[i].boxL[1]; - if (info[i].boxL[2] <= smallest) smallest = info[i].boxL[2]; - theEcr = 0.5 * smallest; - } else { - theEcr = globals->getECR(); - } - - if( !globals->haveEST() ){ - sprintf( painCave.errMsg, - "SimSetup Warning: using default value of 0.05 * the " - "electrostaticCutoffRadius for the " - "electrostaticSkinThickness\n" - ); - painCave.isFatal = 0; - simError(); - theEst = 0.05 * theEcr; - } else { - theEst= globals->getEST(); - } - - info[i].setEcr( theEcr, theEst ); + else{ + theEst = globals->getEST(); } - } + + info[i].setEcr(theEcr, theEst); + + if (!globals->haveDielectric()){ + sprintf(painCave.errMsg, + "SimSetup Error: You are trying to use Reaction Field without" + "setting a dielectric constant!\n"); + painCave.isFatal = 1; + simError(); + } + info[i].dielectric = globals->getDielectric(); + } + else{ + if (usesDipoles){ + if (!globals->haveECR()){ + sprintf(painCave.errMsg, + "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; + simError(); + double smallest; + smallest = info[i].boxL[0]; + if (info[i].boxL[1] <= smallest) + smallest = info[i].boxL[1]; + if (info[i].boxL[2] <= smallest) + smallest = info[i].boxL[2]; + theEcr = 0.5 * smallest; + } + else{ + theEcr = globals->getECR(); + } + + if (!globals->haveEST()){ + sprintf(painCave.errMsg, + "SimSetup Warning: using default value of 0.05 * the " + "electrostaticCutoffRadius for the " + "electrostaticSkinThickness\n"); + painCave.isFatal = 0; + simError(); + theEst = 0.05 * theEcr; + } + else{ + theEst = globals->getEST(); + } + + info[i].setEcr(theEcr, theEst); + } + } } #ifdef IS_MPI - strcpy( checkPointMsg, "post processing checks out" ); + strcpy(checkPointMsg, "post processing checks out"); MPIcheckPoint(); #endif // is_mpi - } -void SimSetup::initSystemCoords( void ){ +void SimSetup::initSystemCoords(void){ int i; - + char* inName; - (info[0].getConfiguration())->createArrays( info[0].n_atoms ); + (info[0].getConfiguration())->createArrays(info[0].n_atoms); - for(i=0; isetCoords(); - - if( globals->haveInitialConfig() ){ - - InitializeFromFile* fileInit; -#ifdef IS_MPI // is_mpi - if( worldRank == 0 ){ + for (i = 0; i < info[0].n_atoms; i++) + info[0].atoms[i]->setCoords(); + + if (globals->haveInitialConfig()){ + InitializeFromFile* fileInit; +#ifdef IS_MPI // is_mpi + if (worldRank == 0){ #endif //is_mpi inName = globals->getInitialConfig(); double* tempDouble = new double[1000000]; - fileInit = new InitializeFromFile( inName ); + fileInit = new InitializeFromFile(inName); #ifdef IS_MPI - }else fileInit = new InitializeFromFile( NULL ); + } + else + fileInit = new InitializeFromFile(NULL); #endif - fileInit->readInit( info ); // default velocities on - + fileInit->readInit(info); // default velocities on + delete fileInit; } else{ - #ifdef IS_MPI - + // no init from bass - - sprintf( painCave.errMsg, - "Cannot intialize a parallel simulation without an initial configuration file.\n" ); + + sprintf(painCave.errMsg, + "Cannot intialize a parallel simulation without an initial configuration file.\n"); painCave.isFatal; simError(); - + #else - + initFromBass(); - - + + #endif } - + #ifdef IS_MPI - strcpy( checkPointMsg, "Successfully read in the initial configuration" ); + strcpy(checkPointMsg, "Successfully read in the initial configuration"); MPIcheckPoint(); #endif // is_mpi - } -void SimSetup::makeOutNames( void ){ - +void SimSetup::makeOutNames(void){ int k; - - for(k=0; khaveFinalConfig() ){ - strcpy( info[k].finalName, globals->getFinalConfig() ); + + if (globals->haveFinalConfig()){ + strcpy(info[k].finalName, globals->getFinalConfig()); } else{ - strcpy( info[k].finalName, inFileName ); - char* endTest; - int nameLength = strlen( info[k].finalName ); - endTest = &(info[k].finalName[nameLength - 5]); - if( !strcmp( endTest, ".bass" ) ){ - strcpy( endTest, ".eor" ); - } - else if( !strcmp( endTest, ".BASS" ) ){ - strcpy( endTest, ".eor" ); - } - else{ - endTest = &(info[k].finalName[nameLength - 4]); - if( !strcmp( endTest, ".bss" ) ){ - strcpy( endTest, ".eor" ); - } - else if( !strcmp( endTest, ".mdl" ) ){ - strcpy( endTest, ".eor" ); - } - else{ - strcat( info[k].finalName, ".eor" ); - } - } + strcpy(info[k].finalName, inFileName); + char* endTest; + int nameLength = strlen(info[k].finalName); + endTest = &(info[k].finalName[nameLength - 5]); + if (!strcmp(endTest, ".bass")){ + strcpy(endTest, ".eor"); + } + else if (!strcmp(endTest, ".BASS")){ + strcpy(endTest, ".eor"); + } + else{ + endTest = &(info[k].finalName[nameLength - 4]); + if (!strcmp(endTest, ".bss")){ + strcpy(endTest, ".eor"); + } + else if (!strcmp(endTest, ".mdl")){ + strcpy(endTest, ".eor"); + } + else{ + strcat(info[k].finalName, ".eor"); + } + } } - + // make the sample and status out names - - strcpy( info[k].sampleName, inFileName ); + + strcpy(info[k].sampleName, inFileName); char* endTest; - int nameLength = strlen( info[k].sampleName ); + int nameLength = strlen(info[k].sampleName); endTest = &(info[k].sampleName[nameLength - 5]); - if( !strcmp( endTest, ".bass" ) ){ - strcpy( endTest, ".dump" ); + if (!strcmp(endTest, ".bass")){ + strcpy(endTest, ".dump"); } - else if( !strcmp( endTest, ".BASS" ) ){ - strcpy( endTest, ".dump" ); + else if (!strcmp(endTest, ".BASS")){ + strcpy(endTest, ".dump"); } else{ - endTest = &(info[k].sampleName[nameLength - 4]); - if( !strcmp( endTest, ".bss" ) ){ - strcpy( endTest, ".dump" ); - } - else if( !strcmp( endTest, ".mdl" ) ){ - strcpy( endTest, ".dump" ); - } - else{ - strcat( info[k].sampleName, ".dump" ); - } + endTest = &(info[k].sampleName[nameLength - 4]); + if (!strcmp(endTest, ".bss")){ + strcpy(endTest, ".dump"); + } + else if (!strcmp(endTest, ".mdl")){ + strcpy(endTest, ".dump"); + } + else{ + strcat(info[k].sampleName, ".dump"); + } } - - strcpy( info[k].statusName, inFileName ); - nameLength = strlen( info[k].statusName ); + + strcpy(info[k].statusName, inFileName); + nameLength = strlen(info[k].statusName); endTest = &(info[k].statusName[nameLength - 5]); - if( !strcmp( endTest, ".bass" ) ){ - strcpy( endTest, ".stat" ); + if (!strcmp(endTest, ".bass")){ + strcpy(endTest, ".stat"); } - else if( !strcmp( endTest, ".BASS" ) ){ - strcpy( endTest, ".stat" ); + else if (!strcmp(endTest, ".BASS")){ + strcpy(endTest, ".stat"); } else{ - endTest = &(info[k].statusName[nameLength - 4]); - if( !strcmp( endTest, ".bss" ) ){ - strcpy( endTest, ".stat" ); - } - else if( !strcmp( endTest, ".mdl" ) ){ - strcpy( endTest, ".stat" ); - } - else{ - strcat( info[k].statusName, ".stat" ); - } + endTest = &(info[k].statusName[nameLength - 4]); + if (!strcmp(endTest, ".bss")){ + strcpy(endTest, ".stat"); + } + else if (!strcmp(endTest, ".mdl")){ + strcpy(endTest, ".stat"); + } + else{ + strcat(info[k].statusName, ".stat"); + } } - + #ifdef IS_MPI + } #endif // is_mpi } } -void SimSetup::sysObjectsCreation( void ){ - - int i,k; - +void SimSetup::sysObjectsCreation(void){ + int i, k; + // create the forceField createFF(); @@ -1073,161 +1061,151 @@ void SimSetup::sysObjectsCreation( void ){ #ifdef IS_MPI // divide the molecules among the processors - + mpiMolDivide(); #endif //is_mpi - + // create the atom and SRI arrays. Also initialize Molecule Stamp ID's - + makeSysArrays(); // make and initialize the molecules (all but atomic coordinates) - + makeMolecules(); - - for(k=0; kgetIdent(); } } } -void SimSetup::createFF( void ){ +void SimSetup::createFF(void){ + switch (ffCase){ + case FF_DUFF: + the_ff = new DUFF(); + break; - switch( ffCase ){ + case FF_LJ: + the_ff = new LJFF(); + break; - case FF_DUFF: - the_ff = new DUFF(); - break; + case FF_EAM: + the_ff = new EAM_FF(); + break; - case FF_LJ: - the_ff = new LJFF(); - break; - - case FF_EAM: - the_ff = new EAM_FF(); - break; - - default: - sprintf( painCave.errMsg, - "SimSetup Error. Unrecognized force field in case statement.\n"); - painCave.isFatal = 1; - simError(); + default: + sprintf(painCave.errMsg, + "SimSetup Error. Unrecognized force field in case statement.\n"); + painCave.isFatal = 1; + simError(); } #ifdef IS_MPI - strcpy( checkPointMsg, "ForceField creation successful" ); + strcpy(checkPointMsg, "ForceField creation successful"); MPIcheckPoint(); #endif // is_mpi - } -void SimSetup::compList( void ){ - +void SimSetup::compList(void){ int i; char* id; LinkedMolStamp* headStamp = new LinkedMolStamp(); LinkedMolStamp* currentStamp = NULL; - comp_stamps = new MoleculeStamp*[n_components]; - + comp_stamps = new MoleculeStamp * [n_components]; + // make an array of molecule stamps that match the components used. // also extract the used stamps out into a separate linked list - - for(i=0; igetType(); 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 ){ - + // 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 = 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(); + + currentStamp = 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 ); + + headStamp->add(currentStamp); + comp_stamps[i] = headStamp->match(id); } } #ifdef IS_MPI - strcpy( checkPointMsg, "Component stamps successfully extracted\n" ); + strcpy(checkPointMsg, "Component stamps successfully extracted\n"); MPIcheckPoint(); #endif // is_mpi - - } -void SimSetup::calcSysValues( void ){ +void SimSetup::calcSysValues(void){ int i, j, k; - - int *molMembershipArray; - + + int* molMembershipArray; + tot_atoms = 0; tot_bonds = 0; 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(); + for (i = 0; i < n_components; i++){ + tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms(); + 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; molMembershipArray = new int[tot_atoms]; - - for(i=0; idivideLabor(); // set up the local variables - + mol2proc = mpiSim->getMolToProcMap(); molCompType = mpiSim->getMolComponentType(); - + allMol = 0; localMol = 0; local_atoms = 0; @@ -1237,36 +1215,32 @@ void SimSetup::mpiMolDivide( void ){ globalAtomIndex = 0; - for( i=0; igetNAtoms(); - local_bonds += comp_stamps[i]->getNBonds(); - local_bends += comp_stamps[i]->getNBends(); - local_torsions += comp_stamps[i]->getNTorsions(); - localMol++; + for (i = 0; i < n_components; i++){ + for (j = 0; j < components_nmol[i]; j++){ + if (mol2proc[allMol] == worldRank){ + local_atoms += comp_stamps[i]->getNAtoms(); + local_bonds += comp_stamps[i]->getNBonds(); + local_bends += comp_stamps[i]->getNBends(); + local_torsions += comp_stamps[i]->getNTorsions(); + localMol++; } - for (k = 0; k < comp_stamps[i]->getNAtoms(); k++) { + for (k = 0; k < comp_stamps[i]->getNAtoms(); k++){ info[0].molMembershipArray[globalAtomIndex] = allMol; globalAtomIndex++; } - allMol++; + allMol++; } } local_SRI = local_bonds + local_bends + local_torsions; - + info[0].n_atoms = mpiSim->getMyNlocal(); - - if( local_atoms != info[0].n_atoms ){ - sprintf( painCave.errMsg, - "SimSetup error: mpiSim's localAtom (%d) and SimSetup's" - " localAtom (%d) are not equal.\n", - info[0].n_atoms, - local_atoms ); + + if (local_atoms != info[0].n_atoms){ + sprintf(painCave.errMsg, + "SimSetup error: mpiSim's localAtom (%d) and SimSetup's" + " localAtom (%d) are not equal.\n", + info[0].n_atoms, local_atoms); painCave.isFatal = 1; simError(); } @@ -1277,82 +1251,78 @@ void SimSetup::mpiMolDivide( void ){ info[0].n_SRI = local_SRI; info[0].n_mol = localMol; - strcpy( checkPointMsg, "Passed nlocal consistency check." ); + strcpy(checkPointMsg, "Passed nlocal consistency check."); MPIcheckPoint(); } - + #endif // is_mpi -void SimSetup::makeSysArrays( void ){ +void SimSetup::makeSysArrays(void){ int i, j, k, l; Atom** the_atoms; Molecule* the_molecules; Exclude** the_excludes; - - for(l=0; lgetTotNmol(); i++){ - - if(mol2proc[i] == worldRank ){ - the_molecules[molIndex].setStampID( molCompType[i] ); - the_molecules[molIndex].setMyIndex( molIndex ); - the_molecules[molIndex].setGlobalIndex( i ); - molIndex++; + for (i = 0; i < mpiSim->getTotNmol(); 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; globalAtomIndex = 0; - for(i=0; igetNAtoms(); k++) { - info[l].molMembershipArray[globalAtomIndex] = molIndex; - globalAtomIndex++; - } - molIndex++; + for (i = 0; i < n_components; i++){ + for (j = 0; j < components_nmol[i]; j++){ + the_molecules[molIndex].setStampID(i); + the_molecules[molIndex].setMyIndex(molIndex); + the_molecules[molIndex].setGlobalIndex(molIndex); + for (k = 0; k < comp_stamps[i]->getNAtoms(); k++){ + info[l].molMembershipArray[globalAtomIndex] = molIndex; + globalAtomIndex++; + } + molIndex++; } } - - + + #endif // is_mpi - if( info[l].n_SRI ){ - + if (info[l].n_SRI){ Exclude::createArray(info[l].n_SRI); - the_excludes = new Exclude*[info[l].n_SRI]; - for( int ex=0; exsetPair( 0,0 ); + the_excludes[0]->setPair(0, 0); info[l].globalExcludes = new int; info[l].globalExcludes[0] = 0; info[l].n_exclude = 0; @@ -1365,264 +1335,252 @@ void SimSetup::makeSysArrays( void ){ info[l].nGlobalExcludes = 0; info[l].excludes = the_excludes; - the_ff->setSimInfo( info ); - + the_ff->setSimInfo(info); } } -void SimSetup::makeIntegrator( void ){ - +void SimSetup::makeIntegrator(void){ int k; - NVT* myNVT = NULL; + NVT* myNVT = NULL; NPTi* myNPTi = NULL; NPTf* myNPTf = NULL; NPTim* myNPTim = NULL; NPTfm* myNPTfm = NULL; - - for(k=0; khaveZconstraints()){ - setupZConstraint(info[k]); - new ZConstraint >( &(info[k]), the_ff ); - } - else - new NVE( &(info[k]), the_ff ); - break; - - case NVT_ENS: - if (globals->haveZconstraints()){ - setupZConstraint(info[k]); - myNVT = new ZConstraint >( &(info[k]), the_ff ); - } - else - myNVT = new NVT( &(info[k]), the_ff ); + for (k = 0; k < nInfo; k++){ + switch (ensembleCase){ + case NVE_ENS: + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + new ZConstraint >(&(info[k]), the_ff); + } + else + new NVE(&(info[k]), the_ff); + break; + case NVT_ENS: + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNVT = new ZConstraint >(&(info[k]), the_ff); + } + else + myNVT = new NVT(&(info[k]), the_ff); + myNVT->setTargetTemp(globals->getTargetTemp()); - - if (globals->haveTauThermostat()) + + if (globals->haveTauThermostat()) myNVT->setTauThermostat(globals->getTauThermostat()); - - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use the NVT\n" - " ensemble, you must set tauThermostat.\n"); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use the NVT\n" + " ensemble, you must set tauThermostat.\n"); painCave.isFatal = 1; simError(); } break; - - case NPTi_ENS: - if (globals->haveZconstraints()){ - setupZConstraint(info[k]); - myNPTi = new ZConstraint >( &(info[k]), the_ff ); - } - else - myNPTi = new NPTi( &(info[k]), the_ff ); - myNPTi->setTargetTemp( globals->getTargetTemp() ); - - if (globals->haveTargetPressure()) - myNPTi->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use a constant pressure\n" - " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauThermostat() ) - myNPTi->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauBarostat() ) - myNPTi->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauBarostat.\n"); - painCave.isFatal = 1; - simError(); - } - break; - - case NPTf_ENS: - if (globals->haveZconstraints()){ - setupZConstraint(info[k]); - myNPTf = new ZConstraint >( &(info[k]), the_ff ); - } - else - myNPTf = new NPTf( &(info[k]), the_ff ); + case NPTi_ENS: + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTi = new ZConstraint >(&(info[k]), the_ff); + } + else + myNPTi = new NPTi(&(info[k]), the_ff); - myNPTf->setTargetTemp( globals->getTargetTemp()); - - if (globals->haveTargetPressure()) - myNPTf->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use a constant pressure\n" - " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauThermostat() ) - myNPTf->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauBarostat() ) - myNPTf->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauBarostat.\n"); - painCave.isFatal = 1; - simError(); - } - break; - - case NPTim_ENS: - if (globals->haveZconstraints()){ - setupZConstraint(info[k]); - myNPTim = new ZConstraint >( &(info[k]), the_ff ); - } - else - myNPTim = new NPTim( &(info[k]), the_ff ); + myNPTi->setTargetTemp(globals->getTargetTemp()); - myNPTim->setTargetTemp( globals->getTargetTemp()); - - if (globals->haveTargetPressure()) - myNPTim->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, + if (globals->haveTargetPressure()) + myNPTi->setTargetPressure(globals->getTargetPressure()); + else{ + sprintf(painCave.errMsg, "SimSetup error: If you use a constant pressure\n" " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauThermostat() ) - myNPTim->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, + painCave.isFatal = 1; + simError(); + } + + if (globals->haveTauThermostat()) + myNPTi->setTauThermostat(globals->getTauThermostat()); + else{ + sprintf(painCave.errMsg, "SimSetup error: If you use an NPT\n" " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauBarostat() ) - myNPTim->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauBarostat.\n"); - painCave.isFatal = 1; - simError(); - } - break; - - case NPTfm_ENS: - if (globals->haveZconstraints()){ - setupZConstraint(info[k]); - myNPTfm = new ZConstraint >( &(info[k]), the_ff ); - } - else - myNPTfm = new NPTfm( &(info[k]), the_ff ); + painCave.isFatal = 1; + simError(); + } - myNPTfm->setTargetTemp( globals->getTargetTemp()); + if (globals->haveTauBarostat()) + myNPTi->setTauBarostat(globals->getTauBarostat()); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use an NPT\n" + " ensemble, you must set tauBarostat.\n"); + painCave.isFatal = 1; + simError(); + } + break; - if (globals->haveTargetPressure()) - myNPTfm->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, + case NPTf_ENS: + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTf = new ZConstraint >(&(info[k]), the_ff); + } + else + myNPTf = new NPTf(&(info[k]), the_ff); + + myNPTf->setTargetTemp(globals->getTargetTemp()); + + if (globals->haveTargetPressure()) + myNPTf->setTargetPressure(globals->getTargetPressure()); + else{ + sprintf(painCave.errMsg, "SimSetup error: If you use a constant pressure\n" " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); - } + painCave.isFatal = 1; + simError(); + } - if( globals->haveTauThermostat() ) - myNPTfm->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, + if (globals->haveTauThermostat()) + myNPTf->setTauThermostat(globals->getTauThermostat()); + else{ + sprintf(painCave.errMsg, "SimSetup error: If you use an NPT\n" " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } + painCave.isFatal = 1; + simError(); + } - if( globals->haveTauBarostat() ) - myNPTfm->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, + if (globals->haveTauBarostat()) + myNPTf->setTauBarostat(globals->getTauBarostat()); + else{ + sprintf(painCave.errMsg, "SimSetup error: If you use an NPT\n" " ensemble, you must set tauBarostat.\n"); + painCave.isFatal = 1; + simError(); + } + break; + + case NPTim_ENS: + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTim = new ZConstraint >(&(info[k]), the_ff); + } + else + myNPTim = new NPTim(&(info[k]), the_ff); + + myNPTim->setTargetTemp(globals->getTargetTemp()); + + if (globals->haveTargetPressure()) + myNPTim->setTargetPressure(globals->getTargetPressure()); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use a constant pressure\n" + " ensemble, you must set targetPressure in the BASS file.\n"); + painCave.isFatal = 1; + simError(); + } + + if (globals->haveTauThermostat()) + myNPTim->setTauThermostat(globals->getTauThermostat()); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use an NPT\n" + " ensemble, you must set tauThermostat.\n"); + painCave.isFatal = 1; + simError(); + } + + if (globals->haveTauBarostat()) + myNPTim->setTauBarostat(globals->getTauBarostat()); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use an NPT\n" + " ensemble, you must set tauBarostat.\n"); + painCave.isFatal = 1; + simError(); + } + break; + + case NPTfm_ENS: + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTfm = new ZConstraint >(&(info[k]), the_ff); + } + else + myNPTfm = new NPTfm(&(info[k]), the_ff); + + myNPTfm->setTargetTemp(globals->getTargetTemp()); + + if (globals->haveTargetPressure()) + myNPTfm->setTargetPressure(globals->getTargetPressure()); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use a constant pressure\n" + " ensemble, you must set targetPressure in the BASS file.\n"); + painCave.isFatal = 1; + simError(); + } + + if (globals->haveTauThermostat()) + myNPTfm->setTauThermostat(globals->getTauThermostat()); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use an NPT\n" + " ensemble, you must set tauThermostat.\n"); + painCave.isFatal = 1; + simError(); + } + + if (globals->haveTauBarostat()) + myNPTfm->setTauBarostat(globals->getTauBarostat()); + else{ + sprintf(painCave.errMsg, + "SimSetup error: If you use an NPT\n" + " ensemble, you must set tauBarostat.\n"); + painCave.isFatal = 1; + simError(); + } + break; + + default: + sprintf(painCave.errMsg, + "SimSetup Error. Unrecognized ensemble in case statement.\n"); painCave.isFatal = 1; simError(); - } - break; - - default: - sprintf( painCave.errMsg, - "SimSetup Error. Unrecognized ensemble in case statement.\n"); - painCave.isFatal = 1; - simError(); } } } -void SimSetup::initFortran( void ){ - +void SimSetup::initFortran(void){ info[0].refreshSim(); - - if( !strcmp( info[0].mixingRule, "standard") ){ - the_ff->initForceField( LB_MIXING_RULE ); + + if (!strcmp(info[0].mixingRule, "standard")){ + the_ff->initForceField(LB_MIXING_RULE); } - else if( !strcmp( info[0].mixingRule, "explicit") ){ - the_ff->initForceField( EXPLICIT_MIXING_RULE ); + else if (!strcmp(info[0].mixingRule, "explicit")){ + the_ff->initForceField(EXPLICIT_MIXING_RULE); } else{ - sprintf( painCave.errMsg, - "SimSetup Error: unknown mixing rule -> \"%s\"\n", - info[0].mixingRule ); + sprintf(painCave.errMsg, "SimSetup Error: unknown mixing rule -> \"%s\"\n", + info[0].mixingRule); painCave.isFatal = 1; simError(); } #ifdef IS_MPI - strcpy( checkPointMsg, - "Successfully intialized the mixingRule for Fortran." ); + strcpy(checkPointMsg, "Successfully intialized the mixingRule for Fortran."); MPIcheckPoint(); #endif // is_mpi - } -void SimSetup::setupZConstraint(SimInfo& theInfo) -{ +void SimSetup::setupZConstraint(SimInfo& theInfo){ int nZConstraints; ZconStamp** zconStamp; - if(globals->haveZconstraintTime()){ - + if (globals->haveZconstraintTime()){ //add sample time of z-constraint into SimInfo's property list DoubleData* zconsTimeProp = new DoubleData(); zconsTimeProp->setID(ZCONSTIME_ID); @@ -1630,25 +1588,26 @@ void SimSetup::setupZConstraint(SimInfo& theInfo) theInfo.addProperty(zconsTimeProp); } else{ - sprintf( painCave.errMsg, - "ZConstraint error: If you use an ZConstraint\n" - " , you must set sample time.\n"); + sprintf(painCave.errMsg, + "ZConstraint error: If you use an ZConstraint\n" + " , you must set sample time.\n"); painCave.isFatal = 1; - simError(); + simError(); } //push zconsTol into siminfo, if user does not specify //value for zconsTol, a default value will be used DoubleData* zconsTol = new DoubleData(); zconsTol->setID(ZCONSTOL_ID); - if(globals->haveZconsTol()){ + if (globals->haveZconsTol()){ zconsTol->setData(globals->getZconsTol()); } else{ - double defaultZConsTol = 0.01; - sprintf( painCave.errMsg, - "ZConstraint Waring: Tolerance for z-constraint methodl is not specified\n" - " , default value %f is used.\n", defaultZConsTol); + double defaultZConsTol = 0.01; + sprintf(painCave.errMsg, + "ZConstraint Waring: Tolerance for z-constraint methodl is not specified\n" + " , default value %f is used.\n", + defaultZConsTol); painCave.isFatal = 0; simError(); @@ -1657,37 +1616,37 @@ void SimSetup::setupZConstraint(SimInfo& theInfo) theInfo.addProperty(zconsTol); //set Force Substraction Policy - StringData* zconsForcePolicy = new StringData(); + StringData* zconsForcePolicy = new StringData(); zconsForcePolicy->setID(ZCONSFORCEPOLICY_ID); - - if(globals->haveZconsForcePolicy()){ + + if (globals->haveZconsForcePolicy()){ zconsForcePolicy->setData(globals->getZconsForcePolicy()); - } + } else{ - sprintf( painCave.errMsg, - "ZConstraint Warning: User does not set force substraction policy, " - "average force substraction policy is used\n"); - painCave.isFatal = 0; - simError(); - zconsForcePolicy->setData("BYNUMBER"); + sprintf(painCave.errMsg, + "ZConstraint Warning: User does not set force substraction policy, " + "average force substraction policy is used\n"); + painCave.isFatal = 0; + simError(); + zconsForcePolicy->setData("BYNUMBER"); } - - theInfo.addProperty(zconsForcePolicy); - + + theInfo.addProperty(zconsForcePolicy); + //Determine the name of ouput file and add it into SimInfo's property list //Be careful, do not use inFileName, since it is a pointer which //point to a string at master node, and slave nodes do not contain that string - + string zconsOutput(theInfo.finalName); - + zconsOutput = zconsOutput.substr(0, zconsOutput.rfind(".")) + ".fz"; - + StringData* zconsFilename = new StringData(); zconsFilename->setID(ZCONSFILENAME_ID); zconsFilename->setData(zconsOutput); - + theInfo.addProperty(zconsFilename); - + //setup index, pos and other parameters of z-constraint molecules nZConstraints = globals->getNzConstraints(); theInfo.nZconstraints = nZConstraints; @@ -1697,8 +1656,8 @@ void SimSetup::setupZConstraint(SimInfo& theInfo) ZConsParaData* zconsParaData = new ZConsParaData(); zconsParaData->setID(ZCONSPARADATA_ID); - - for(int i = 0; i < nZConstraints; i++){ + + for (int i = 0; i < nZConstraints; i++){ tempParaItem.havingZPos = zconStamp[i]->haveZpos(); tempParaItem.zPos = zconStamp[i]->getZpos(); tempParaItem.zconsIndex = zconStamp[i]->getMolIndex(); @@ -1709,8 +1668,7 @@ void SimSetup::setupZConstraint(SimInfo& theInfo) //sort the parameters by index of molecules zconsParaData->sortByIndex(); - + //push data into siminfo, therefore, we can retrieve later theInfo.addProperty(zconsParaData); - }