--- trunk/OOPSE/libmdtools/SimSetup.cpp 2003/03/21 17:42:12 378 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2003/07/22 16:41:08 644 @@ -12,6 +12,20 @@ #include "mpiSimulation.hpp" #endif +// some defines for ensemble and Forcefield cases + +#define NVE_ENS 0 +#define NVT_ENS 1 +#define NPTi_ENS 2 +#define NPTf_ENS 3 +#define NPTim_ENS 4 +#define NPTfm_ENS 5 + + +#define FF_DUFF 0 +#define FF_LJ 1 + + SimSetup::SimSetup(){ stamps = new MakeStamps(); globals = new Globals(); @@ -64,383 +78,791 @@ void SimSetup::createSim( void ){ void SimSetup::createSim( void ){ - MakeStamps *the_stamps; - Globals* the_globals; - int i, j; + int i, j, k, globalAtomIndex; + + // gather all of the information from the Bass file + + gatherInfo(); - // get the stamps and globals; - the_stamps = stamps; - the_globals = globals; + // creation of complex system objects - // set the easy ones first - simnfo->target_temp = the_globals->getTargetTemp(); - simnfo->dt = the_globals->getDt(); - simnfo->run_time = the_globals->getRunTime(); + sysObjectsCreation(); - // get the ones we know are there, yet still may need some work. - n_components = the_globals->getNComponents(); - strcpy( force_field, the_globals->getForceField() ); - strcpy( ensemble, the_globals->getEnsemble() ); - strcpy( simnfo->ensemble, ensemble ); + // check on the post processing info + + finalInfoCheck(); - strcpy( simnfo->mixingRule, the_globals->getMixingRule() ); - simnfo->usePBC = the_globals->getPBC(); - + // initialize the system coordinates + initSystemCoords(); + - if( !strcmp( force_field, "TraPPE" ) ) the_ff = new TraPPEFF(); - else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF(); - else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF(); - else if( !strcmp( force_field, "LJ" ) ) the_ff = new LJ_FF(); - else{ - sprintf( painCave.errMsg, - "SimSetup Error. Unrecognized force field -> %s\n", - force_field ); - painCave.isFatal = 1; - simError(); - } + // make the output filenames + makeOutNames(); + + // make the integrator + + makeIntegrator(); + #ifdef IS_MPI - strcpy( checkPointMsg, "ForceField creation successful" ); - MPIcheckPoint(); -#endif // is_mpi + mpiSim->mpiRefresh(); +#endif + // initialize the Fortran + + initFortran(); + + + +} + + +void SimSetup::makeMolecules( void ){ + + int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset; + molInit molInfo; + DirectionalAtom* dAtom; + LinkedAssign* extras; + LinkedAssign* current_extra; + AtomStamp* currentAtom; + BondStamp* currentBond; + BendStamp* currentBend; + TorsionStamp* currentTorsion; + + bond_pair* theBonds; + bend_set* theBends; + torsion_set* theTorsions; + + //init the forceField paramters - // get the components and calculate the tot_nMol and indvidual n_mol - the_components = the_globals->getComponents(); - components_nmol = new int[n_components]; - comp_stamps = new MoleculeStamp*[n_components]; + the_ff->readParams(); - if( !the_globals->haveNMol() ){ - // we don't have the total number of molecules, so we assume it is - // given in each component + + // init the atoms - tot_nmol = 0; - for( i=0; in_mol; i++){ + + stampID = the_molecules[i].getStampID(); - 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(); - } + 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; - tot_nmol += the_components[i]->getNMol(); - components_nmol[i] = the_components[i]->getNMol(); - } - } - 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" ); - painCave.isFatal = 1; - simError(); + molInfo.myAtoms = &the_atoms[atomOffset]; + molInfo.myExcludes = &the_excludes[excludeOffset]; + 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 - // tot_nmol = the_globals->getNMol(); + for(j=0; jgetAtom( j ); + if( currentAtom->haveOrientation() ){ + + dAtom = new DirectionalAtom(j + atomOffset); + info->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); + } + molInfo.myAtoms[j]->setType( currentAtom->getType() ); - // //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(); + + 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; - // make an array of molecule stamps that match the components used. - // also extract the used stamps out into a separate linked list + exI = theBonds[j].a; + exJ = theBonds[j].b; - 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; i exJ ){ + tempEx = exI; + exI = exJ; + exJ = tempEx; + } +#ifdef IS_MPI + tempEx = exI; + exI = the_atoms[tempEx]->getGlobalIndex() + 1; + tempEx = exJ; + exJ = the_atoms[tempEx]->getGlobalIndex() + 1; + + the_excludes[j+excludeOffset]->setPair( exI, exJ ); +#else // isn't MPI - id = the_components[i]->getType(); - comp_stamps[i] = NULL; - - // check to make sure the component isn't already in the list + the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) ); +#endif //is_mpi + } + excludeOffset += molInfo.nBonds; - comp_stamps[i] = headStamp->match( id ); - if( comp_stamps[i] == NULL ){ + //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; + } - 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(); + // 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 = the_atoms[tempEx]->getGlobalIndex() + 1; + tempEx = exJ; + exJ = the_atoms[tempEx]->getGlobalIndex() + 1; - headStamp->add( currentStamp ); - comp_stamps[i] = headStamp->match( id ); + the_excludes[j+excludeOffset]->setPair( exI, exJ ); +#else // isn't MPI + the_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; + } #ifdef IS_MPI - strcpy( checkPointMsg, "Component stamps successfully extracted\n" ); - MPIcheckPoint(); -#endif // is_mpi - + tempEx = exI; + exI = the_atoms[tempEx]->getGlobalIndex() + 1; + tempEx = exJ; + exJ = the_atoms[tempEx]->getGlobalIndex() + 1; + + the_excludes[j+excludeOffset]->setPair( exI, exJ ); +#else // isn't MPI + the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) ); +#endif //is_mpi + } + excludeOffset += molInfo.nTorsions; - - - // caclulate the number of atoms, bonds, bends and torsions - - 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(); - tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); - } + // send the arrays off to the forceField for init. - tot_SRI = tot_bonds + tot_bends + tot_torsions; + 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 ); - simnfo->n_atoms = tot_atoms; - simnfo->n_bonds = tot_bonds; - simnfo->n_bends = tot_bends; - simnfo->n_torsions = tot_torsions; - simnfo->n_SRI = tot_SRI; - simnfo->n_mol = tot_nmol; - -#ifdef IS_MPI + the_molecules[i].initialize( molInfo ); - // divide the molecules among processors here. - - mpiSim = new mpiSimulation( simnfo ); - - - globalIndex = mpiSim->divideLabor(); - - - - // set up the local variables - - int localMol, allMol; - int local_atoms, local_bonds, local_bends, local_torsions, local_SRI; - - allMol = 0; - localMol = 0; - local_atoms = 0; - local_bonds = 0; - local_bends = 0; - local_torsions = 0; - for( i=0; igetMyMolStart() <= allMol && - allMol <= mpiSim->getMyMolEnd() ){ - - 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++; - } - allMol++; - } + atomOffset += molInfo.nAtoms; + delete[] theBonds; + delete[] theBends; + delete[] theTorsions; } - local_SRI = local_bonds + local_bends + local_torsions; - - simnfo->n_atoms = mpiSim->getMyNlocal(); - - if( local_atoms != simnfo->n_atoms ){ - sprintf( painCave.errMsg, - "SimSetup error: mpiSim's localAtom (%d) and SimSetup's" - " localAtom (%d) are note equal.\n", - simnfo->n_atoms, - local_atoms ); - painCave.isFatal = 1; - simError(); - } - - simnfo->n_bonds = local_bonds; - simnfo->n_bends = local_bends; - simnfo->n_torsions = local_torsions; - simnfo->n_SRI = local_SRI; - simnfo->n_mol = localMol; - - strcpy( checkPointMsg, "Passed nlocal consistency check." ); +#ifdef IS_MPI + sprintf( checkPointMsg, "all molecules initialized succesfully" ); MPIcheckPoint(); - - #endif // is_mpi - - // create the atom and short range interaction arrays + // clean up the forcefield + the_ff->calcRcut(); + the_ff->cleanMe(); - Atom::createArrays(simnfo->n_atoms); - the_atoms = new Atom*[simnfo->n_atoms]; - the_molecules = new Molecule[simnfo->n_mol]; +} +void SimSetup::initFromBass( void ){ - if( simnfo->n_SRI ){ - the_sris = new SRI*[simnfo->n_SRI]; - the_excludes = new int[2 * simnfo->n_SRI]; - simnfo->globalExcludes = new int; - simnfo->n_exclude = tot_SRI; - } - else{ - - the_excludes = new int[2]; - the_excludes[0] = 0; - the_excludes[1] = 0; - simnfo->globalExcludes = new int; - simnfo->globalExcludes[0] = 0; + int i, j, k; + int n_cells; + double cellx, celly, cellz; + double temp1, temp2, temp3; + int n_per_extra; + int n_extra; + int have_extra, done; - simnfo->n_exclude = 1; - } + temp1 = (double)tot_nmol / 4.0; + temp2 = pow( temp1, ( 1.0 / 3.0 ) ); + temp3 = ceil( temp2 ); - // set the arrays into the SimInfo object + have_extra =0; + if( temp2 < temp3 ){ // we have a non-complete lattice + have_extra =1; - simnfo->atoms = the_atoms; - simnfo->sr_interactions = the_sris; - simnfo->nGlobalExcludes = 0; - simnfo->excludes = the_excludes; + n_cells = (int)temp3 - 1; + cellx = info->boxL[0] / temp3; + celly = info->boxL[1] / temp3; + cellz = info->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 ); - - // get some of the tricky things that may still be in the globals - - if( simnfo->n_dipoles ){ - - if( !the_globals->haveRRF() ){ + if( n_per_extra > 4){ sprintf( painCave.errMsg, - "SimSetup Error, system has dipoles, but no rRF was set.\n"); + "SimSetup error. There has been an error in constructing" + " the non-complete lattice.\n" ); painCave.isFatal = 1; simError(); } - if( !the_globals->haveDielectric() ){ + } + else{ + n_cells = (int)temp3; + cellx = info->boxL[0] / temp3; + celly = info->boxL[1] / temp3; + cellz = info->boxL[2] / 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 ); + } + } + } + + 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, + k * cellz + 0.5 * cellz ); + done = ( current_mol >= tot_nmol ); + } + } + } + } + } + + + for( i=0; in_atoms; i++ ){ + info->atoms[i]->set_vx( 0.0 ); + info->atoms[i]->set_vy( 0.0 ); + info->atoms[i]->set_vz( 0.0 ); + } +} + +void SimSetup::makeElement( double x, double y, double z ){ + + int k; + AtomStamp* current_atom; + DirectionalAtom* dAtom; + double rotMat[3][3]; + + for( k=0; kgetNAtoms(); k++ ){ + + current_atom = comp_stamps[current_comp]->getAtom( k ); + if( !current_atom->havePosition() ){ sprintf( painCave.errMsg, - "SimSetup Error, system has dipoles, but no" - " dielectric was set.\n" ); + "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(); } - simnfo->rRF = the_globals->getRRF(); - simnfo->dielectric = the_globals->getDielectric(); + 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; + + rotMat[1][0] = 0.0; + rotMat[1][1] = 1.0; + rotMat[1][2] = 0.0; + + rotMat[2][0] = 0.0; + rotMat[2][1] = 0.0; + rotMat[2][2] = 1.0; + + dAtom->setA( rotMat ); + } + + current_atom_ndx++; } -#ifdef IS_MPI - strcpy( checkPointMsg, "rRf and dielectric check out" ); - MPIcheckPoint(); -#endif // is_mpi + current_mol++; + current_comp_mol++; + + if( current_comp_mol >= components_nmol[current_comp] ){ + + current_comp_mol = 0; + current_comp++; + } +} + + +void SimSetup::gatherInfo( void ){ + int i,j,k; + + ensembleCase = -1; + ffCase = -1; + + // get the stamps and globals; + stamps = stamps; + globals = globals; + + // set the easy ones first + info->target_temp = globals->getTargetTemp(); + info->dt = globals->getDt(); + info->run_time = globals->getRunTime(); + n_components = globals->getNComponents(); + + + // get the forceField + + strcpy( force_field, globals->getForceField() ); + + if( !strcasecmp( force_field, "DUFF" )) ffCase = FF_DUFF; + else if( !strcasecmp( force_field, "LJ" )) ffCase = FF_LJ; + else{ + sprintf( painCave.errMsg, + "SimSetup Error. Unrecognized force field -> %s\n", + force_field ); + painCave.isFatal = 1; + simError(); + } + + // get the ensemble + + 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") ) + 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{ + 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; + } + strcpy( info->ensemble, ensemble ); + + // get the mixing rule + + strcpy( info->mixingRule, globals->getMixingRule() ); + info->usePBC = globals->getPBC(); + - if( the_globals->haveBox() ){ - simnfo->box_x = the_globals->getBox(); - simnfo->box_y = the_globals->getBox(); - simnfo->box_z = the_globals->getBox(); + // 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() ){ + // 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(); + } + + tot_nmol += the_components[i]->getNMol(); + components_nmol[i] = the_components[i]->getNMol(); + } } - else if( the_globals->haveDensity() ){ + 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" ); + painCave.isFatal = 1; + simError(); + } + // set the status, sample, and thermal kick times + + if( globals->haveSampleTime() ){ + info->sampleTime = globals->getSampleTime(); + info->statusTime = info->sampleTime; + info->thermalTime = info->sampleTime; + } + else{ + info->sampleTime = globals->getRunTime(); + info->statusTime = info->sampleTime; + info->thermalTime = info->sampleTime; + } + + if( globals->haveStatusTime() ){ + info->statusTime = globals->getStatusTime(); + } + + if( globals->haveThermalTime() ){ + info->thermalTime = globals->getThermalTime(); + } + + // check for the temperature set flag + + if( globals->haveTempSet() ) info->setTemp = globals->getTempSet(); + + // get some of the tricky things that may still be in the globals + + double boxVector[3]; + if( globals->haveBox() ){ + boxVector[0] = globals->getBox(); + boxVector[1] = globals->getBox(); + boxVector[2] = globals->getBox(); + + info->setBox( boxVector ); + } + else if( globals->haveDensity() ){ + double vol; - vol = (double)tot_nmol / the_globals->getDensity(); - simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) ); - simnfo->box_y = simnfo->box_x; - simnfo->box_z = simnfo->box_x; + vol = (double)tot_nmol / globals->getDensity(); + boxVector[0] = pow( vol, ( 1.0 / 3.0 ) ); + boxVector[1] = boxVector[0]; + boxVector[2] = boxVector[0]; + + info->setBox( boxVector ); } else{ - if( !the_globals->haveBoxX() ){ + if( !globals->haveBoxX() ){ sprintf( painCave.errMsg, "SimSetup error, no periodic BoxX size given.\n" ); painCave.isFatal = 1; simError(); } - simnfo->box_x = the_globals->getBoxX(); + boxVector[0] = globals->getBoxX(); - if( !the_globals->haveBoxY() ){ + if( !globals->haveBoxY() ){ sprintf( painCave.errMsg, "SimSetup error, no periodic BoxY size given.\n" ); painCave.isFatal = 1; simError(); } - simnfo->box_y = the_globals->getBoxY(); + boxVector[1] = globals->getBoxY(); - if( !the_globals->haveBoxZ() ){ + if( !globals->haveBoxZ() ){ sprintf( painCave.errMsg, "SimSetup error, no periodic BoxZ size given.\n" ); painCave.isFatal = 1; simError(); } - simnfo->box_z = the_globals->getBoxZ(); + boxVector[2] = globals->getBoxZ(); + + info->setBox( boxVector ); } + + #ifdef IS_MPI - strcpy( checkPointMsg, "Box size set up" ); + strcpy( checkPointMsg, "Succesfully gathered all information from Bass\n" ); MPIcheckPoint(); #endif // is_mpi +} - // initialize the arrays - the_ff->setSimInfo( simnfo ); +void SimSetup::finalInfoCheck( void ){ + int index; + int usesDipoles; + - makeAtoms(); - simnfo->identArray = new int[simnfo->n_atoms]; - for(i=0; in_atoms; i++){ - simnfo->identArray[i] = the_atoms[i]->getIdent(); - } + // check electrostatic parameters - if( tot_bonds ){ - makeBonds(); + index = 0; + usesDipoles = 0; + while( (index < info->n_atoms) && !usesDipoles ){ + usesDipoles = ((info->atoms)[index])->hasDipole(); + index++; } + +#ifdef IS_MPI + int myUse = usesDipoles; + MPI_Allreduce( &myUse, &usesDipoles, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD ); +#endif //is_mpi - if( tot_bends ){ - makeBends(); - } + double theEcr, theEst; - if( tot_torsions ){ - makeTorsions(); - } + if (globals->getUseRF() ) { + info->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->boxL[0]; + if (info->boxL[1] <= smallest) smallest = info->boxL[1]; + if (info->boxL[2] <= smallest) smallest = info->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->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->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->boxL[0]; + if (info->boxL[1] <= smallest) smallest = info->boxL[1]; + if (info->boxL[2] <= smallest) smallest = info->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->setEcr( theEcr, theEst ); + } + } +#ifdef IS_MPI + strcpy( checkPointMsg, "post processing checks out" ); + MPIcheckPoint(); +#endif // is_mpi +} - if( the_globals->haveInitialConfig() ){ +void SimSetup::initSystemCoords( void ){ + + if( globals->haveInitialConfig() ){ InitializeFromFile* fileInit; #ifdef IS_MPI // is_mpi if( worldRank == 0 ){ #endif //is_mpi - fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); + fileInit = new InitializeFromFile( globals->getInitialConfig() ); #ifdef IS_MPI }else fileInit = new InitializeFromFile( NULL ); #endif - fileInit->read_xyz( simnfo ); // default velocities on + fileInit->readInit( info ); // default velocities on delete fileInit; } @@ -468,24 +890,23 @@ void SimSetup::createSim( void ){ MPIcheckPoint(); #endif // is_mpi +} - - - - +void SimSetup::makeOutNames( void ){ + #ifdef IS_MPI if( worldRank == 0 ){ #endif // is_mpi - if( the_globals->haveFinalConfig() ){ - strcpy( simnfo->finalName, the_globals->getFinalConfig() ); + if( globals->haveFinalConfig() ){ + strcpy( info->finalName, globals->getFinalConfig() ); } else{ - strcpy( simnfo->finalName, inFileName ); + strcpy( info->finalName, inFileName ); char* endTest; - int nameLength = strlen( simnfo->finalName ); - endTest = &(simnfo->finalName[nameLength - 5]); + int nameLength = strlen( info->finalName ); + endTest = &(info->finalName[nameLength - 5]); if( !strcmp( endTest, ".bass" ) ){ strcpy( endTest, ".eor" ); } @@ -493,7 +914,7 @@ void SimSetup::createSim( void ){ strcpy( endTest, ".eor" ); } else{ - endTest = &(simnfo->finalName[nameLength - 4]); + endTest = &(info->finalName[nameLength - 4]); if( !strcmp( endTest, ".bss" ) ){ strcpy( endTest, ".eor" ); } @@ -501,17 +922,17 @@ void SimSetup::createSim( void ){ strcpy( endTest, ".eor" ); } else{ - strcat( simnfo->finalName, ".eor" ); + strcat( info->finalName, ".eor" ); } } } // make the sample and status out names - strcpy( simnfo->sampleName, inFileName ); + strcpy( info->sampleName, inFileName ); char* endTest; - int nameLength = strlen( simnfo->sampleName ); - endTest = &(simnfo->sampleName[nameLength - 5]); + int nameLength = strlen( info->sampleName ); + endTest = &(info->sampleName[nameLength - 5]); if( !strcmp( endTest, ".bass" ) ){ strcpy( endTest, ".dump" ); } @@ -519,7 +940,7 @@ void SimSetup::createSim( void ){ strcpy( endTest, ".dump" ); } else{ - endTest = &(simnfo->sampleName[nameLength - 4]); + endTest = &(info->sampleName[nameLength - 4]); if( !strcmp( endTest, ".bss" ) ){ strcpy( endTest, ".dump" ); } @@ -527,13 +948,13 @@ void SimSetup::createSim( void ){ strcpy( endTest, ".dump" ); } else{ - strcat( simnfo->sampleName, ".dump" ); + strcat( info->sampleName, ".dump" ); } } - strcpy( simnfo->statusName, inFileName ); - nameLength = strlen( simnfo->statusName ); - endTest = &(simnfo->statusName[nameLength - 5]); + strcpy( info->statusName, inFileName ); + nameLength = strlen( info->statusName ); + endTest = &(info->statusName[nameLength - 5]); if( !strcmp( endTest, ".bass" ) ){ strcpy( endTest, ".stat" ); } @@ -541,7 +962,7 @@ void SimSetup::createSim( void ){ strcpy( endTest, ".stat" ); } else{ - endTest = &(simnfo->statusName[nameLength - 4]); + endTest = &(info->statusName[nameLength - 4]); if( !strcmp( endTest, ".bss" ) ){ strcpy( endTest, ".stat" ); } @@ -549,610 +970,517 @@ void SimSetup::createSim( void ){ strcpy( endTest, ".stat" ); } else{ - strcat( simnfo->statusName, ".stat" ); + strcat( info->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; - simnfo->thermalTime = simnfo->sampleTime; - } - else{ - simnfo->sampleTime = the_globals->getRunTime(); - simnfo->statusTime = simnfo->sampleTime; - simnfo->thermalTime = simnfo->sampleTime; - } + +} + + +void SimSetup::sysObjectsCreation( void ){ + + int i; + + // create the forceField - if( the_globals->haveStatusTime() ){ - simnfo->statusTime = the_globals->getStatusTime(); - } + createFF(); - if( the_globals->haveThermalTime() ){ - simnfo->thermalTime = the_globals->getThermalTime(); - } + // extract componentList - // check for the temperature set flag + compList(); - if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet(); + // calc the number of atoms, bond, bends, and torsions + calcSysValues(); -// // make the longe range forces and the integrator +#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(); -// new AllLong( simnfo ); + // make and initialize the molecules (all but atomic coordinates) + + makeMolecules(); + info->identArray = new int[info->n_atoms]; + for(i=0; in_atoms; i++){ + info->identArray[i] = the_atoms[i]->getIdent(); + } + - if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo, the_ff ); - if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo, the_ff ); - if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo, the_ff ); - if( !strcmp( force_field, "LJ" ) ) new Verlet( *simnfo, the_ff ); +} - // initialize the Fortran - - simnfo->refreshSim(); - - if( !strcmp( simnfo->mixingRule, "standard") ){ - the_ff->initForceField( LB_MIXING_RULE ); - } - else if( !strcmp( simnfo->mixingRule, "explicit") ){ - the_ff->initForceField( EXPLICIT_MIXING_RULE ); - } - else{ +void SimSetup::createFF( void ){ + + switch( ffCase ){ + + case FF_DUFF: + the_ff = new DUFF(); + break; + + case FF_LJ: + the_ff = new LJFF(); + break; + + default: sprintf( painCave.errMsg, - "SimSetup Error: unknown mixing rule -> \"%s\"\n", - simnfo->mixingRule ); + "SimSetup Error. Unrecognized force field in case statement.\n"); painCave.isFatal = 1; simError(); } - #ifdef IS_MPI - strcpy( checkPointMsg, - "Successfully intialized the mixingRule for Fortran." ); + strcpy( checkPointMsg, "ForceField creation successful" ); MPIcheckPoint(); #endif // is_mpi + } -void SimSetup::makeAtoms( void ){ - int i, j, k, index; - double ux, uy, uz, uSqr, u; - AtomStamp* current_atom; +void SimSetup::compList( void ){ - DirectionalAtom* dAtom; - int molIndex, molStart, molEnd, nMemb, lMolIndex; + int i; - lMolIndex = 0; - molIndex = 0; - index = 0; - for( i=0; igetMyMolStart() <= molIndex && - molIndex <= mpiSim->getMyMolEnd() ){ -#endif // is_mpi + info->nComponents = n_components; + info->componentsNmol = components_nmol; + info->compStamps = comp_stamps; + info->headStamp = new LinkedMolStamp(); + + char* id; + LinkedMolStamp* headStamp = info->headStamp; + LinkedMolStamp* currentStamp = NULL; + for( i=0; igetNAtoms(); - for( k=0; kgetNAtoms(); k++ ){ - - current_atom = comp_stamps[i]->getAtom( k ); - if( current_atom->haveOrientation() ){ - - dAtom = new DirectionalAtom(index); - 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 ); - } - else{ - the_atoms[index] = new GeneralAtom(index); - } - the_atoms[index]->setType( current_atom->getType() ); - the_atoms[index]->setIndex( index ); - - // increment the index and repeat; - index++; - } - - molEnd = index -1; - the_molecules[lMolIndex].setNMembers( nMemb ); - the_molecules[lMolIndex].setStartAtom( molStart ); - the_molecules[lMolIndex].setEndAtom( molEnd ); - the_molecules[lMolIndex].setStampID( i ); - lMolIndex++; + id = the_components[i]->getType(); + comp_stamps[i] = NULL; + + // check to make sure the component isn't already in the list -#ifdef IS_MPI + 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(); } -#endif //is_mpi - molIndex++; + headStamp->add( currentStamp ); + comp_stamps[i] = headStamp->match( id ); } } #ifdef IS_MPI - for( i=0; igetMyNlocal(); i++ ) the_atoms[i]->setGlobalIndex( globalIndex[i] ); - - delete[] globalIndex; + strcpy( checkPointMsg, "Component stamps successfully extracted\n" ); + MPIcheckPoint(); +#endif // is_mpi - mpiSim->mpiRefresh(); -#endif //IS_MPI - - the_ff->initializeAtoms(); + } -void SimSetup::makeBonds( void ){ +void SimSetup::calcSysValues( void ){ + int i, j, k; - int i, j, k, index, offset, molIndex, exI, exJ, tempEx; - bond_pair* the_bonds; - BondStamp* current_bond; - the_bonds = new bond_pair[tot_bonds]; - index = 0; - offset = 0; - molIndex = 0; - + 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(); + tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); + } - for( j=0; jgetMyMolStart() <= molIndex && - molIndex <= mpiSim->getMyMolEnd() ){ -#endif // is_mpi - - for( k=0; kgetNBonds(); k++ ){ - - current_bond = comp_stamps[i]->getBond( k ); - the_bonds[index].a = current_bond->getA() + offset; - the_bonds[index].b = current_bond->getB() + offset; + info->n_atoms = tot_atoms; + info->n_bonds = tot_bonds; + info->n_bends = tot_bends; + info->n_torsions = tot_torsions; + info->n_SRI = tot_SRI; + info->n_mol = tot_nmol; + + info->molMembershipArray = new int[tot_atoms]; +} - exI = the_bonds[index].a; - exJ = the_bonds[index].b; - // exclude_I must always be the smaller of the pair - if( exI > exJ ){ - tempEx = exI; - exI = exJ; - exJ = tempEx; - } - - #ifdef IS_MPI - the_excludes[index*2] = - the_atoms[exI]->getGlobalIndex() + 1; - the_excludes[index*2 + 1] = - the_atoms[exJ]->getGlobalIndex() + 1; +void SimSetup::mpiMolDivide( void ){ + + int i, j, k; + int localMol, allMol; + int local_atoms, local_bonds, local_bends, local_torsions, local_SRI; -#else // isn't MPI - - the_excludes[index*2] = exI + 1; - the_excludes[index*2 + 1] = exJ + 1; - // fortran index from 1 (hence the +1 in the indexing) -#endif //is_mpi - - // increment the index and repeat; - index++; - } - offset += comp_stamps[i]->getNAtoms(); - -#ifdef IS_MPI - } -#endif //is_mpi - - molIndex++; - } - } + mpiSim = new mpiSimulation( info ); + + globalIndex = mpiSim->divideLabor(); - the_ff->initializeBonds( the_bonds ); -} - -void SimSetup::makeBends( void ){ - - int i, j, k, index, offset, molIndex, exI, exJ, tempEx; - bend_set* the_bends; - BendStamp* current_bend; - LinkedAssign* extras; - LinkedAssign* current_extra; + // set up the local variables + mol2proc = mpiSim->getMolToProcMap(); + molCompType = mpiSim->getMolComponentType(); + + allMol = 0; + localMol = 0; + local_atoms = 0; + local_bonds = 0; + local_bends = 0; + local_torsions = 0; + globalAtomIndex = 0; - the_bends = new bend_set[tot_bends]; - index = 0; - offset = 0; - molIndex = 0; + for( i=0; igetMyMolStart() <= molIndex && - molIndex <= mpiSim->getMyMolEnd() ){ -#endif // is_mpi - - for( k=0; kgetNBends(); k++ ){ - - current_bend = comp_stamps[i]->getBend( k ); - the_bends[index].a = current_bend->getA() + offset; - the_bends[index].b = current_bend->getB() + offset; - the_bends[index].c = current_bend->getC() + offset; - - if( current_bend->haveExtras() ){ - - extras = current_bend->getExtras(); - current_extra = extras; - - while( current_extra != NULL ){ - if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){ - - switch( current_extra->getType() ){ - - case 0: - the_bends[index].ghost = - current_extra->getInt() + offset; - the_bends[index].isGhost = 1; - break; - - case 1: - the_bends[index].ghost = - (int)current_extra->getDouble() + offset; - the_bends[index].isGhost = 1; - break; - - default: - sprintf( painCave.errMsg, - "SimSetup Error: ghostVectorSource was neiter a " - "double nor an int.\n" - "-->Bend[%d] in %s\n", - k, comp_stamps[i]->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(), - k, comp_stamps[i]->getID() ); - painCave.isFatal = 1; - simError(); - } - - current_extra = current_extra->getNext(); - } - } - - if( !the_bends[index].isGhost ){ - - exI = the_bends[index].a; - exJ = the_bends[index].c; - } - else{ - - exI = the_bends[index].a; - exJ = the_bends[index].b; - } - - // exclude_I must always be the smaller of the pair - if( exI > exJ ){ - tempEx = exI; - exI = exJ; - exJ = tempEx; - } - - -#ifdef IS_MPI - - the_excludes[(index + tot_bonds)*2] = - the_atoms[exI]->getGlobalIndex() + 1; - the_excludes[(index + tot_bonds)*2 + 1] = - the_atoms[exJ]->getGlobalIndex() + 1; - -#else // isn't MPI - - the_excludes[(index + tot_bonds)*2] = exI + 1; - the_excludes[(index + tot_bonds)*2 + 1] = exJ + 1; - // fortran index from 1 (hence the +1 in the indexing) -#endif //is_mpi - - - // increment the index and repeat; - index++; - } - offset += comp_stamps[i]->getNAtoms(); + + if( mol2proc[allMol] == worldRank ){ -#ifdef IS_MPI + 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++) { + info->molMembershipArray[globalAtomIndex] = allMol; + globalAtomIndex++; } -#endif //is_mpi - molIndex++; + allMol++; } } + local_SRI = local_bonds + local_bends + local_torsions; + + info->n_atoms = mpiSim->getMyNlocal(); + + if( local_atoms != info->n_atoms ){ + sprintf( painCave.errMsg, + "SimSetup error: mpiSim's localAtom (%d) and SimSetup's" + " localAtom (%d) are not equal.\n", + info->n_atoms, + local_atoms ); + painCave.isFatal = 1; + simError(); + } -#ifdef IS_MPI - sprintf( checkPointMsg, - "Successfully created the bends list.\n" ); + info->n_bonds = local_bonds; + info->n_bends = local_bends; + info->n_torsions = local_torsions; + info->n_SRI = local_SRI; + info->n_mol = localMol; + + strcpy( checkPointMsg, "Passed nlocal consistency check." ); MPIcheckPoint(); -#endif // is_mpi +} +#endif // is_mpi - the_ff->initializeBends( the_bends ); -} -void SimSetup::makeTorsions( void ){ +void SimSetup::makeSysArrays( void ){ + int i, j, k; - int i, j, k, index, offset, molIndex, exI, exJ, tempEx; - torsion_set* the_torsions; - TorsionStamp* current_torsion; - the_torsions = new torsion_set[tot_torsions]; - index = 0; - offset = 0; - molIndex = 0; - for( i=0; in_atoms); + the_atoms = new Atom*[info->n_atoms]; + the_molecules = new Molecule[info->n_mol]; + int molIndex; -#ifdef IS_MPI - if( mpiSim->getMyMolStart() <= molIndex && - molIndex <= mpiSim->getMyMolEnd() ){ -#endif // is_mpi + // initialize the molecule's stampID's - for( k=0; kgetNTorsions(); k++ ){ +#ifdef IS_MPI + - current_torsion = comp_stamps[i]->getTorsion( k ); - the_torsions[index].a = current_torsion->getA() + offset; - the_torsions[index].b = current_torsion->getB() + offset; - the_torsions[index].c = current_torsion->getC() + offset; - the_torsions[index].d = current_torsion->getD() + offset; + molIndex = 0; + for(i=0; igetTotNmol(); i++){ + + if(mol2proc[i] == worldRank ){ + the_molecules[molIndex].setStampID( molCompType[i] ); + the_molecules[molIndex].setMyIndex( molIndex ); + the_molecules[molIndex].setGlobalIndex( i ); + molIndex++; + } + } - exI = the_torsions[index].a; - exJ = the_torsions[index].d; - - - // exclude_I must always be the smaller of the pair - if( exI > exJ ){ - tempEx = exI; - exI = exJ; - exJ = tempEx; - } - - -#ifdef IS_MPI - - the_excludes[(index + tot_bonds + tot_bends)*2] = - the_atoms[exI]->getGlobalIndex() + 1; - the_excludes[(index + tot_bonds + tot_bends)*2 + 1] = - the_atoms[exJ]->getGlobalIndex() + 1; - -#else // isn't MPI - - the_excludes[(index + tot_bonds + tot_bends)*2] = exI + 1; - the_excludes[(index + tot_bonds + tot_bends)*2 + 1] = exJ + 1; - // fortran indexes from 1 (hence the +1 in the indexing) -#endif //is_mpi - - - // increment the index and repeat; - index++; +#else // is_mpi + + molIndex = 0; + globalAtomIndex = 0; + for(i=0; igetNAtoms(); k++) { + info->molMembershipArray[globalAtomIndex] = molIndex; + globalAtomIndex++; } - offset += comp_stamps[i]->getNAtoms(); - -#ifdef IS_MPI - } -#endif //is_mpi - molIndex++; } } + - the_ff->initializeTorsions( the_torsions ); -} +#endif // is_mpi -void SimSetup::initFromBass( void ){ - int i, j, k; - int n_cells; - double cellx, celly, cellz; - double temp1, temp2, temp3; - int n_per_extra; - int n_extra; - int have_extra, done; - - 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; - - n_cells = (int)temp3 - 1; - cellx = simnfo->box_x / temp3; - celly = simnfo->box_y / temp3; - cellz = simnfo->box_z / 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 ); - - 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(); - } + if( info->n_SRI ){ + + Exclude::createArray(info->n_SRI); + the_excludes = new Exclude*[info->n_SRI]; + for( int ex=0; exn_SRI; ex++) the_excludes[ex] = new Exclude(ex); + info->globalExcludes = new int; + info->n_exclude = info->n_SRI; } else{ - n_cells = (int)temp3; - cellx = simnfo->box_x / temp3; - celly = simnfo->box_y / temp3; - cellz = simnfo->box_z / temp3; + + Exclude::createArray( 1 ); + the_excludes = new Exclude*; + the_excludes[0] = new Exclude(0); + the_excludes[0]->setPair( 0,0 ); + info->globalExcludes = new int; + info->globalExcludes[0] = 0; + info->n_exclude = 0; } - current_mol = 0; - current_comp_mol = 0; - current_comp = 0; - current_atom_ndx = 0; + // set the arrays into the SimInfo object - for( i=0; i < n_cells ; i++ ){ - for( j=0; j < n_cells; j++ ){ - for( k=0; k < n_cells; k++ ){ + info->atoms = the_atoms; + info->molecules = the_molecules; + info->nGlobalExcludes = 0; + info->excludes = the_excludes; - makeElement( i * cellx, - j * celly, - k * cellz ); + the_ff->setSimInfo( info ); - 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 ); +void SimSetup::makeIntegrator( void ){ - makeElement( i * cellx + 0.5 * cellx, - j * celly, - k * cellz + 0.5 * cellz ); - } - } - } + NVT* myNVT = NULL; + NPTi* myNPTi = NULL; + NPTf* myNPTf = NULL; + NPTim* myNPTim = NULL; + NPTfm* myNPTfm = NULL; - if( have_extra ){ - done = 0; + switch( ensembleCase ){ - int start_ndx; - for( i=0; i < (n_cells+1) && !done; i++ ){ - for( j=0; j < (n_cells+1) && !done; j++ ){ + case NVE_ENS: + new NVE( info, the_ff ); + break; - if( i < n_cells ){ + case NVT_ENS: + myNVT = new NVT( info, the_ff ); + myNVT->setTargetTemp(globals->getTargetTemp()); - if( j < n_cells ){ - start_ndx = n_cells; - } - else start_ndx = 0; - } - else start_ndx = 0; + if (globals->haveTauThermostat()) + myNVT->setTauThermostat(globals->getTauThermostat()); - for( k=start_ndx; k < (n_cells+1) && !done; k++ ){ + else { + sprintf( painCave.errMsg, + "SimSetup error: If you use the NVT\n" + " ensemble, you must set tauThermostat.\n"); + painCave.isFatal = 1; + simError(); + } + break; - makeElement( i * cellx, - j * celly, - k * cellz ); - done = ( current_mol >= tot_nmol ); + case NPTi_ENS: + myNPTi = new NPTi( info, the_ff ); + myNPTi->setTargetTemp( globals->getTargetTemp() ); - 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 (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( !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( 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: + myNPTf = new NPTf( info, the_ff ); + myNPTf->setTargetTemp( globals->getTargetTemp()); - for( i=0; in_atoms; i++ ){ - simnfo->atoms[i]->set_vx( 0.0 ); - simnfo->atoms[i]->set_vy( 0.0 ); - simnfo->atoms[i]->set_vz( 0.0 ); - } -} + 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(); + } -void SimSetup::makeElement( double x, double y, double z ){ + 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(); + } - int k; - AtomStamp* current_atom; - DirectionalAtom* dAtom; - double rotMat[3][3]; + 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: + myNPTim = new NPTim( info, the_ff ); + myNPTim->setTargetTemp( globals->getTargetTemp()); - for( k=0; kgetNAtoms(); k++ ){ + 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(); + } - current_atom = comp_stamps[current_comp]->getAtom( k ); - if( !current_atom->havePosition() ){ + if( globals->haveTauBarostat() ) + myNPTim->setTauBarostat( globals->getTauBarostat() ); + else{ 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() ); + "SimSetup error: If you use an NPT\n" + " ensemble, you must set tauBarostat.\n"); painCave.isFatal = 1; simError(); } + break; - 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() ); + case NPTfm_ENS: + myNPTfm = new NPTfm( info, the_ff ); + myNPTfm->setTargetTemp( globals->getTargetTemp()); - if( the_atoms[current_atom_ndx]->isDirectional() ){ + 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(); + } - dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx]; + 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; - rotMat[0][0] = 1.0; - rotMat[0][1] = 0.0; - rotMat[0][2] = 0.0; + default: + sprintf( painCave.errMsg, + "SimSetup Error. Unrecognized ensemble in case statement.\n"); + painCave.isFatal = 1; + simError(); + } - rotMat[1][0] = 0.0; - rotMat[1][1] = 1.0; - rotMat[1][2] = 0.0; +} - rotMat[2][0] = 0.0; - rotMat[2][1] = 0.0; - rotMat[2][2] = 1.0; +void SimSetup::initFortran( void ){ - dAtom->setA( rotMat ); - } - - current_atom_ndx++; + info->refreshSim(); + + if( !strcmp( info->mixingRule, "standard") ){ + the_ff->initForceField( LB_MIXING_RULE ); } + else if( !strcmp( info->mixingRule, "explicit") ){ + the_ff->initForceField( EXPLICIT_MIXING_RULE ); + } + else{ + sprintf( painCave.errMsg, + "SimSetup Error: unknown mixing rule -> \"%s\"\n", + info->mixingRule ); + painCave.isFatal = 1; + simError(); + } - current_mol++; - current_comp_mol++; - if( current_comp_mol >= components_nmol[current_comp] ){ +#ifdef IS_MPI + strcpy( checkPointMsg, + "Successfully intialized the mixingRule for Fortran." ); + MPIcheckPoint(); +#endif // is_mpi - current_comp_mol = 0; - current_comp++; - } }