| 1 |
tim |
1703 |
/* |
| 2 |
|
|
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
| 3 |
|
|
* |
| 4 |
|
|
* Contact: oopse@oopse.org |
| 5 |
|
|
* |
| 6 |
|
|
* This program is free software; you can redistribute it and/or |
| 7 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
| 8 |
|
|
* as published by the Free Software Foundation; either version 2.1 |
| 9 |
|
|
* of the License, or (at your option) any later version. |
| 10 |
|
|
* All we ask is that proper credit is given for our work, which includes |
| 11 |
|
|
* - but is not limited to - adding the above copyright notice to the beginning |
| 12 |
|
|
* of your source code files, and to any copyright notice that you may distribute |
| 13 |
|
|
* with programs based on this work. |
| 14 |
|
|
* |
| 15 |
|
|
* This program is distributed in the hope that it will be useful, |
| 16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
|
|
* GNU Lesser General Public License for more details. |
| 19 |
|
|
* |
| 20 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
| 21 |
|
|
* along with this program; if not, write to the Free Software |
| 22 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 |
|
|
* |
| 24 |
|
|
*/ |
| 25 |
|
|
|
| 26 |
|
|
/** |
| 27 |
|
|
* @file SimCreator.cpp |
| 28 |
|
|
* @author tlin |
| 29 |
|
|
* @date 11/03/2004 |
| 30 |
|
|
* @time 13:51am |
| 31 |
|
|
* @version 1.0 |
| 32 |
|
|
*/ |
| 33 |
|
|
|
| 34 |
|
|
#include "brains/SimCreator.hpp" |
| 35 |
|
|
namespace oopse { |
| 36 |
|
|
|
| 37 |
tim |
1712 |
void SimSetup::parseFile(char* mdfile, MakeStamps* stamps, Globals* globals){ |
| 38 |
|
|
#ifdef IS_MPI |
| 39 |
|
|
if (worldRank == 0){ |
| 40 |
|
|
#endif // is_mpi |
| 41 |
|
|
|
| 42 |
|
|
|
| 43 |
|
|
globals->initalize(); |
| 44 |
|
|
set_interface_stamps(stamps, globals); |
| 45 |
|
|
|
| 46 |
|
|
#ifdef IS_MPI |
| 47 |
|
|
mpiEventInit(); |
| 48 |
|
|
#endif |
| 49 |
|
|
|
| 50 |
|
|
yacc_BASS(mdfile); |
| 51 |
|
|
|
| 52 |
|
|
#ifdef IS_MPI |
| 53 |
|
|
throwMPIEvent(NULL); |
| 54 |
|
|
} |
| 55 |
|
|
else{ |
| 56 |
|
|
set_interface_stamps(stamps, globals); |
| 57 |
|
|
mpiEventInit(); |
| 58 |
|
|
MPIcheckPoint(); |
| 59 |
|
|
mpiEventLoop(); |
| 60 |
|
|
} |
| 61 |
|
|
#endif |
| 62 |
|
|
|
| 63 |
tim |
1703 |
} |
| 64 |
|
|
|
| 65 |
tim |
1712 |
|
| 66 |
tim |
1719 |
SimInfo* SimCreator::createSim(const std::string& mdfile) { |
| 67 |
|
|
MakeStamps* stamps = new MakeStamps(); |
| 68 |
tim |
1712 |
|
| 69 |
|
|
Globals* globals = new Globals(); |
| 70 |
|
|
|
| 71 |
|
|
//parse meta-data file |
| 72 |
|
|
parseFile(mdfile, stamps, globals); |
| 73 |
|
|
|
| 74 |
|
|
//create the force field |
| 75 |
tim |
1713 |
ForceFiled* ff = ForceFieldFactory::getInstance()->createForceField(globals->getForceField()); |
| 76 |
tim |
1712 |
|
| 77 |
tim |
1719 |
//create SimInfo |
| 78 |
|
|
SimInfo* info = new SimInfo(); |
| 79 |
|
|
info->setGlobals(globals); |
| 80 |
|
|
info->setForceField(ff); |
| 81 |
|
|
|
| 82 |
|
|
//extract the molecule stamps and add them into SimInfo |
| 83 |
|
|
compList(stamps, info); |
| 84 |
tim |
1712 |
|
| 85 |
tim |
1719 |
//gather parameters (SimCreator only retrieves the parameters which will be used to create |
| 86 |
|
|
// the simulation) |
| 87 |
|
|
gatherParameters(info); |
| 88 |
tim |
1712 |
|
| 89 |
|
|
//divide the molecules and determine the global index of molecules |
| 90 |
tim |
1719 |
|
| 91 |
tim |
1712 |
//create the molecules |
| 92 |
tim |
1719 |
createMolecules(info); |
| 93 |
tim |
1712 |
|
| 94 |
|
|
//allocate memory for DataStorage(circular reference, need to break it) |
| 95 |
tim |
1719 |
info->setSnapshotManager(new SimSnapshotManager(info); |
| 96 |
tim |
1712 |
|
| 97 |
|
|
//load initial coordinates |
| 98 |
tim |
1719 |
DumpReader reader(info->getInitFilename()); |
| 99 |
|
|
int nframes = reader->getNframes(); |
| 100 |
|
|
|
| 101 |
|
|
if (nframes > 0) { |
| 102 |
|
|
reader.readFrame(info, nframes - 1); |
| 103 |
|
|
} else { |
| 104 |
|
|
//invalid initial coordinate file |
| 105 |
|
|
|
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
tim |
1712 |
|
| 109 |
|
|
//initialize fortran |
| 110 |
tim |
1719 |
|
| 111 |
|
|
return info; |
| 112 |
tim |
1712 |
} |
| 113 |
|
|
|
| 114 |
|
|
void SimCreator::gatherParameters(SimModel* model) { |
| 115 |
|
|
model->addProperty(new StringGenericData("Ensemble", globals->getForceFiled())); |
| 116 |
|
|
model->addProperty(new DoubleGenericData("dt"), globals->getDt()); |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
|
#ifdef IS_MPI |
| 120 |
tim |
1713 |
void SimCreator::mpiMolDivide(){ |
| 121 |
|
|
|
| 122 |
|
|
mpiSim = new mpiSimulation(info); |
| 123 |
tim |
1712 |
|
| 124 |
tim |
1713 |
mpiSim->divideLabor(); |
| 125 |
tim |
1712 |
|
| 126 |
tim |
1713 |
strcpy(checkPointMsg, "Passed nlocal consistency check."); |
| 127 |
|
|
MPIcheckPoint(); |
| 128 |
tim |
1712 |
} |
| 129 |
tim |
1713 |
#endif |
| 130 |
tim |
1712 |
|
| 131 |
tim |
1719 |
Molecule* SimCreator::createMolecules(SimInfo* info) { |
| 132 |
tim |
1713 |
|
| 133 |
|
|
|
| 134 |
|
|
|
| 135 |
tim |
1719 |
for (i = 0; i < mpiSim->getNMolGlobal(); i++){ |
| 136 |
|
|
if (mol2proc[i] == worldRank){ |
| 137 |
tim |
1713 |
|
| 138 |
tim |
1719 |
Molecule* mol = MoleculeCreator.createMolecule(molStamp, stampID, globalIndex); |
| 139 |
|
|
|
| 140 |
|
|
info->addMolecule(mol); |
| 141 |
|
|
} |
| 142 |
|
|
} |
| 143 |
|
|
|
| 144 |
tim |
1713 |
} |
| 145 |
|
|
|
| 146 |
tim |
1719 |
|
| 147 |
|
|
void SimSetup::compList(MakeStamps* stamps,SimInfo* info) { |
| 148 |
|
|
int i; |
| 149 |
|
|
char* id; |
| 150 |
|
|
MoleculeStamp* currentStamp; |
| 151 |
|
|
Component* the_components = info->getGlobals()->getComponents(); |
| 152 |
|
|
int n_components = info->getGlobals()->getNComponents(); |
| 153 |
|
|
|
| 154 |
|
|
if (!globals->haveNMol()){ |
| 155 |
|
|
// we don't have the total number of molecules, so we assume it is |
| 156 |
|
|
// given in each component |
| 157 |
|
|
|
| 158 |
|
|
for (i = 0; i < n_components; i++){ |
| 159 |
|
|
if (!the_components[i]->haveNMol()){ |
| 160 |
|
|
// we have a problem |
| 161 |
|
|
sprintf(painCave.errMsg, |
| 162 |
|
|
"SimSetup Error. No global NMol or component NMol given.\n" |
| 163 |
|
|
"\tCannot calculate the number of atoms.\n"); |
| 164 |
|
|
painCave.isFatal = 1; |
| 165 |
|
|
simError(); |
| 166 |
|
|
} |
| 167 |
|
|
|
| 168 |
|
|
id = the_components[i]->getType(); |
| 169 |
|
|
currentStamp = stamps->extractMolStamp(id); |
| 170 |
|
|
if (currentStamp == NULL){ |
| 171 |
|
|
sprintf(painCave.errMsg, |
| 172 |
|
|
"SimSetup error: Component \"%s\" was not found in the " |
| 173 |
|
|
"list of declared molecules\n", |
| 174 |
|
|
id); |
| 175 |
|
|
painCave.isFatal = 1; |
| 176 |
|
|
simError(); |
| 177 |
|
|
} |
| 178 |
|
|
|
| 179 |
|
|
info.moleculeStamps.push_back(make_pair(currentStamp, the_components[i]->getNMol())); |
| 180 |
|
|
|
| 181 |
|
|
} //end for (i = 0; i < n_components; i++) |
| 182 |
|
|
|
| 183 |
|
|
} else{ |
| 184 |
|
|
sprintf(painCave.errMsg, |
| 185 |
|
|
"SimSetup error.\n" |
| 186 |
|
|
"\tSorry, the ability to specify total" |
| 187 |
|
|
" nMols and then give molfractions in the components\n" |
| 188 |
|
|
"\tis not currently supported." |
| 189 |
|
|
" Please give nMol in the components.\n"); |
| 190 |
|
|
painCave.isFatal = 1; |
| 191 |
|
|
simError(); |
| 192 |
|
|
} |
| 193 |
|
|
|
| 194 |
|
|
#ifdef IS_MPI |
| 195 |
|
|
strcpy(checkPointMsg, "Component stamps successfully extracted\n"); |
| 196 |
|
|
MPIcheckPoint(); |
| 197 |
|
|
#endif // is_mpi |
| 198 |
|
|
} |
| 199 |
|
|
|
| 200 |
|
|
|
| 201 |
tim |
1703 |
} //end namespace oopse |