51 |
|
*/ |
52 |
|
class SimInfo { |
53 |
|
public: |
54 |
< |
typedef std::vector<Molecule*>::iterator MoleculeIterator; |
55 |
< |
SimInfo(); |
54 |
> |
typedef MoleculeIterator MoleculeIterator; |
55 |
> |
|
56 |
> |
/** |
57 |
> |
* Constructor of SimInfo |
58 |
> |
* @param molStampPairs MoleculeStamp Array. The first element of the pair is molecule stamp, the |
59 |
> |
* second element is the total number of molecules with the same molecule stamp in the system |
60 |
> |
* @param ff pointer of a concrete ForceField instance |
61 |
> |
* @param globals |
62 |
> |
* @note |
63 |
> |
* <p> |
64 |
> |
* The major change of SimInfo |
65 |
> |
* </p> |
66 |
> |
*/ |
67 |
> |
SimInfo(const std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs, ForceField* ff, Globals* globals); |
68 |
|
virtual ~SimInfo(); |
69 |
|
|
70 |
|
/** |
82 |
|
|
83 |
|
/** Returns the total number of molecules in the system. */ |
84 |
|
int getNGlobalMolecules() { |
85 |
< |
|
74 |
< |
#ifdef IS_MPI |
75 |
< |
int nmols; |
76 |
< |
int totNMols; |
77 |
< |
|
78 |
< |
nmols = getNMolecules(); |
79 |
< |
MPI_Allreduce(&nmols, &totNMols, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
80 |
< |
|
81 |
< |
return totNMols; |
82 |
< |
#else |
83 |
< |
return getNMolecules(); |
84 |
< |
#endif |
85 |
> |
return nGlobalMols_; |
86 |
|
} |
87 |
|
|
88 |
|
/** Returns the total number of atoms in the system. */ |
89 |
|
int getNGlobalAtoms() { |
90 |
< |
|
90 |
< |
#ifdef IS_MPI |
91 |
< |
int totNAtoms; |
92 |
< |
MPI_Allreduce(&nAtoms_, &totNAtoms, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
93 |
< |
return totNAtoms; |
94 |
< |
#else |
95 |
< |
return nAtoms_; |
96 |
< |
#endif |
90 |
> |
return nGlobalAtoms_; |
91 |
|
} |
92 |
|
|
93 |
|
/** Returns the total number of cutoff groups in the system. */ |
94 |
|
int getNGlobalCutoffGroups() { |
95 |
< |
#ifdef IS_MPI |
102 |
< |
int totNGroups; |
103 |
< |
MPI_Allreduce(&nCutoffGroups_, &totNGroups, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
104 |
< |
return totNGroups; |
105 |
< |
#else |
106 |
< |
return nCutoffGroups_; |
107 |
< |
#endif |
95 |
> |
return nGlobalCutoffGroups_; |
96 |
|
} |
97 |
|
|
98 |
|
/** |
148 |
|
* @return the first molecule, return NULL if there is not molecule in this SimInfo |
149 |
|
* @param i the iterator of molecule array (user shouldn't change it) |
150 |
|
*/ |
151 |
< |
Molecule* beginMolecule(std::vector<Molecule*>::iterator& i); |
151 |
> |
Molecule* beginMolecule(MoleculeIterator& i); |
152 |
|
|
153 |
|
/** |
154 |
|
* Returns the next avaliable Molecule based on the iterator. |
155 |
|
* @return the next avaliable molecule, return NULL if reaching the end of the array |
156 |
|
* @param i the iterator of molecule array |
157 |
|
*/ |
158 |
< |
Molecule* nextMolecule(std::vector<Molecule*>::iterator& i); |
158 |
> |
Molecule* nextMolecule(MoleculeIterator& i); |
159 |
|
|
160 |
|
/** Returns the number of degrees of freedom */ |
161 |
|
int getNdf() { |
172 |
|
return ndfTrans_; |
173 |
|
} |
174 |
|
|
175 |
+ |
//getNZconstraint and setNZconstraint ruin the coherent of SimInfo class, need refactorying |
176 |
+ |
|
177 |
+ |
/** Returns the total number of z-constraint molecules in the system */ |
178 |
+ |
int getNZconstraint() { |
179 |
+ |
return nZconstraint_; |
180 |
+ |
} |
181 |
+ |
|
182 |
+ |
/** |
183 |
+ |
* Sets the number of z-constraint molecules in the system. |
184 |
+ |
*/ |
185 |
+ |
int setNZconstraint(int nZconstraint) { |
186 |
+ |
nZconstraint_ = nZconstraint; |
187 |
+ |
} |
188 |
+ |
|
189 |
|
/** Returns the snapshot manager. */ |
190 |
|
SnapshotManager* getSnapshotManager() { |
191 |
|
return sman_; |
201 |
|
return forceField_; |
202 |
|
} |
203 |
|
|
202 |
– |
/** Sets the force field */ |
203 |
– |
void setForceField(ForceField* ff) { |
204 |
– |
forceField_ = ff; |
205 |
– |
} |
206 |
– |
|
204 |
|
Globals* getGlobals() { |
205 |
|
return globals_; |
206 |
|
} |
210 |
– |
|
211 |
– |
void setGlobals(Globals* globals) { |
212 |
– |
globals_ = globals; |
213 |
– |
} |
207 |
|
|
208 |
|
/** Returns the velocity of center of mass of the whole system.*/ |
209 |
|
Vector3d getComVel(); |
221 |
|
seed_ = seed; |
222 |
|
} |
223 |
|
|
224 |
< |
|
224 |
> |
/** main driver function to interact with fortran during the initialization and molecule migration */ |
225 |
|
void update(); |
226 |
|
|
234 |
– |
|
227 |
|
/** Returns the local index manager */ |
228 |
|
LocalIndexManager* getLocalIndexManager() { |
229 |
|
return localIndexMan_; |
230 |
|
} |
231 |
|
|
240 |
– |
|
241 |
– |
/** |
242 |
– |
* |
243 |
– |
*/ |
244 |
– |
void addMoleculeStamp(MoleculeStamp* molStamp, int nmol); |
245 |
– |
|
232 |
|
int getMoleculeStampId(int globalIndex) { |
233 |
|
//assert(globalIndex < molStampIds_.size()) |
234 |
|
return molStampIds_[globalIndex]; |
240 |
|
} |
241 |
|
|
242 |
|
/** |
257 |
– |
* Finds the processor where a molecule resides |
258 |
– |
* @return the id of the processor which contains the molecule |
259 |
– |
* @param globalIndex global Index of the molecule |
260 |
– |
*/ |
261 |
– |
int getMolToProc(int globalIndex) { |
262 |
– |
//assert(globalIndex < molToProcMap_.size()); |
263 |
– |
return molToProcMap_[globalIndex]; |
264 |
– |
} |
265 |
– |
|
266 |
– |
/** |
243 |
|
* Finds a molecule with a specified global index |
244 |
|
* @return a pointer point to found molecule |
245 |
|
* @param index |
246 |
|
*/ |
247 |
|
Molecule* getMoleculeByGlobalIndex(int index) { |
248 |
|
std::map<int, Molecule*> i; |
249 |
< |
i = globalIndexToMol_.find(index); |
249 |
> |
i = molecules_.find(index); |
250 |
|
|
251 |
< |
return i != globalIndexToMol_.end() ? i->second : NULL; |
251 |
> |
return i != molecules_.end() ? i->second : NULL; |
252 |
|
} |
253 |
|
|
254 |
+ |
/** Returns the unique atom types of local processor in an array */ |
255 |
+ |
std::set<AtomType*> SimInfo::getUniqueAtomTypes(); |
256 |
|
|
257 |
+ |
std::string getFinalConfigFileName() { |
258 |
+ |
return finalConfigFileName_; |
259 |
+ |
} |
260 |
+ |
|
261 |
+ |
void setFinalConfigFileName(const std::string& fileName) { |
262 |
+ |
finalConfigFileName_ = fileName; |
263 |
+ |
} |
264 |
+ |
|
265 |
+ |
|
266 |
+ |
std::string getDumpFileName() { |
267 |
+ |
return dumpFileName_; |
268 |
+ |
} |
269 |
+ |
|
270 |
+ |
void setDumpFileName(const std::string& fileName) { |
271 |
+ |
dumpFileName_ = fileName; |
272 |
+ |
} |
273 |
+ |
|
274 |
+ |
std::string getStatFileName() { |
275 |
+ |
return statFileName_; |
276 |
+ |
} |
277 |
+ |
|
278 |
+ |
void setStatFileName(const std::string& fileName) { |
279 |
+ |
statFileName_ = fileName; |
280 |
+ |
} |
281 |
+ |
|
282 |
+ |
int* getGlobalGroupMembershipPointer() { |
283 |
+ |
return globalGroupMembership_[0]; |
284 |
+ |
} |
285 |
+ |
|
286 |
+ |
//below functions are just forward functions |
287 |
+ |
//To compose or to inherit is always a hot debate. In general, is-a relation need subclassing, in the |
288 |
+ |
//the other hand, has-a relation need composing. |
289 |
+ |
/** |
290 |
+ |
* Adds property into property map |
291 |
+ |
* @param genData GenericData to be added into PropertyMap |
292 |
+ |
*/ |
293 |
+ |
void addProperty(GenericData* genData); |
294 |
+ |
|
295 |
+ |
/** |
296 |
+ |
* Removes property from PropertyMap by name |
297 |
+ |
* @param propName the name of property to be removed |
298 |
+ |
*/ |
299 |
+ |
void removeProperty(const std::string& propName); |
300 |
+ |
|
301 |
+ |
/** |
302 |
+ |
* clear all of the properties |
303 |
+ |
*/ |
304 |
+ |
void clearProperties(); |
305 |
+ |
|
306 |
+ |
/** |
307 |
+ |
* Returns all names of properties |
308 |
+ |
* @return all names of properties |
309 |
+ |
*/ |
310 |
+ |
std::vector<std::string> getPropertyNames(); |
311 |
+ |
|
312 |
+ |
/** |
313 |
+ |
* Returns all of the properties in PropertyMap |
314 |
+ |
* @return all of the properties in PropertyMap |
315 |
+ |
*/ |
316 |
+ |
std::vector<GenericData*> getProperties(); |
317 |
+ |
|
318 |
+ |
/** |
319 |
+ |
* Returns property |
320 |
+ |
* @param propName name of property |
321 |
+ |
* @return a pointer point to property with propName. If no property named propName |
322 |
+ |
* exists, return NULL |
323 |
+ |
*/ |
324 |
+ |
GenericData* getPropertyByName(const std::string& propName); |
325 |
+ |
|
326 |
|
friend std::ostream& operator <<(ostream& o, SimInfo& info); |
327 |
|
|
328 |
|
private: |
329 |
|
|
330 |
+ |
void setupSimType(); |
331 |
+ |
|
332 |
+ |
/** |
333 |
+ |
* Setup Fortran Simulation |
334 |
+ |
* @see #setupFortranParallel |
335 |
+ |
*/ |
336 |
+ |
void setupFortranSim(); |
337 |
+ |
|
338 |
+ |
/** Calculates the number of degress of freedom in the whole system */ |
339 |
|
void calcNdf(); |
340 |
|
void calcNdfRaw(); |
341 |
|
void calcNdfTrans(); |
342 |
|
|
287 |
– |
int* getExcludeList() { |
288 |
– |
return exclude_.getExcludeList(); |
289 |
– |
} |
290 |
– |
|
343 |
|
void addExcludePairs(Molecule* mol); |
344 |
|
void removeExcludePairs(Molecule* mol); |
345 |
|
|
346 |
+ |
/** |
347 |
+ |
* Adds molecule stamps into |
348 |
+ |
*/ |
349 |
+ |
void addMoleculeStamp(MoleculeStamp* molStamp, int nmol); |
350 |
+ |
|
351 |
+ |
std::map<int, Molecule*> molecules_; /**< Molecule array */ |
352 |
+ |
|
353 |
|
//degress of freedom |
354 |
< |
int ndf_; /** number of degress of freedom */ |
355 |
< |
int ndfRaw_; |
356 |
< |
int ndfTrans_; /**< number of translation degress of freedom */ |
354 |
> |
int ndf_; /**< number of degress of freedom (excludes constraints), ndf_ is local */ |
355 |
> |
int ndfRaw_; /**< number of degress of freedom (includes constraints), ndfRaw_ is local */ |
356 |
> |
int ndfTrans_; /**< number of translation degress of freedom, ndfTrans_ is local */ |
357 |
> |
int nZconstraint_; /** number of z-constraint molecules, nZconstraint_ is global */ |
358 |
> |
|
359 |
> |
//number of global objects |
360 |
> |
int nGlobalMols_; /**< number of molecules in the system */ |
361 |
> |
int nGlobalAtoms_; /**< number of atoms in the system */ |
362 |
> |
int nGlobalCutoffGroups_; /**< number of cutoff groups in this system */ |
363 |
|
|
364 |
+ |
/** |
365 |
+ |
* the size of globalGroupMembership_ is nGlobalAtoms. Its index is global index of an atom, and the |
366 |
+ |
* corresponding content is the global index of cutoff group this atom belong to. |
367 |
+ |
* It is filled by SimCreator once and only once, since it is never changed during the simulation. |
368 |
+ |
*/ |
369 |
+ |
std::vector<int> globalGroupMembership_; |
370 |
+ |
|
371 |
+ |
std::vector<int> molStampIds_; /**< stamp id array of all molecules in the system */ |
372 |
+ |
std::vector<MoleculeStamp*> moleculeStamps_; /**< molecule stamps array */ |
373 |
+ |
|
374 |
|
//number of local objects |
375 |
< |
int nAtoms_; |
376 |
< |
int nBonds_; |
377 |
< |
int nBends_; |
378 |
< |
int nTorsions_; |
379 |
< |
int nRigidBodies_; |
380 |
< |
int nIntegrableObjects_; |
381 |
< |
int nCutoffGroups_; |
382 |
< |
int nConstraints_; |
375 |
> |
int nAtoms_; /**< number of atoms in local processor */ |
376 |
> |
int nBonds_; /**< number of bonds in local processor */ |
377 |
> |
int nBends_; /**< number of bends in local processor */ |
378 |
> |
int nTorsions_; /**< number of torsions in local processor */ |
379 |
> |
int nRigidBodies_; /**< number of rigid bodies in local processor */ |
380 |
> |
int nIntegrableObjects_; /**< number of integrable objects in local processor */ |
381 |
> |
int nCutoffGroups_; /**< number of cutoff groups in local processor */ |
382 |
> |
int nConstraints_; /**< number of constraints in local processors */ |
383 |
|
|
384 |
< |
simtype fInfo_; |
384 |
> |
simtype fInfo_; /**< A dual struct shared by c++/fortran which indicates the atom types in simulation*/ |
385 |
|
Exclude exclude_; |
386 |
< |
ForceField* forceField_; |
312 |
< |
|
313 |
< |
std::vector<Molecule*> molecules_; /**< Molecule array */ |
386 |
> |
ForceField* forceField_; |
387 |
|
PropertyMap properties_; /**< Generic Property */ |
388 |
|
SnapshotManager* sman_; /**< SnapshotManager */ |
316 |
– |
|
389 |
|
Globals* globals_; |
318 |
– |
|
390 |
|
int seed_; /**< seed for random number generator */ |
391 |
|
|
392 |
|
LocalIndexManager localIndexMan_; |
393 |
|
|
394 |
< |
// |
395 |
< |
std::vector<int> molToProcMap_; |
396 |
< |
std::map<int, Molecule*> globalIndexToMol_; |
397 |
< |
std::vector<int> molStampIds_; /**< stamp id array of all molecules in the system */ |
398 |
< |
std::vector<MoleculeStamp*> moleculeStamps_; /**< molecule stamps array */ |
394 |
> |
std::string finalConfigFileName_; |
395 |
> |
std::string dumpFileName_; |
396 |
> |
std::string statFileName_; |
397 |
> |
|
398 |
> |
#ifdef IS_MPI |
399 |
> |
//in Parallel version, we need MolToProc |
400 |
> |
public: |
401 |
> |
|
402 |
> |
/** |
403 |
> |
* Finds the processor where a molecule resides |
404 |
> |
* @return the id of the processor which contains the molecule |
405 |
> |
* @param globalIndex global Index of the molecule |
406 |
> |
*/ |
407 |
> |
int getMolToProc(int globalIndex) { |
408 |
> |
//assert(globalIndex < molToProcMap_.size()); |
409 |
> |
return molToProcMap_[globalIndex]; |
410 |
> |
} |
411 |
|
|
412 |
+ |
int* getMolToProcMapPointer() { |
413 |
+ |
return &molToProcMap_[0]; |
414 |
+ |
} |
415 |
+ |
|
416 |
+ |
private: |
417 |
+ |
|
418 |
+ |
void setupFortranParallel(); |
419 |
+ |
|
420 |
+ |
/** |
421 |
+ |
* The size of molToProcMap_ is equal to total number of molecules in the system. |
422 |
+ |
* It maps a molecule to the processor on which it resides. it is filled by SimCreator once and only |
423 |
+ |
* once. |
424 |
+ |
*/ |
425 |
+ |
std::vector<int> molToProcMap_; |
426 |
+ |
#endif |
427 |
+ |
|
428 |
|
}; |
429 |
|
|
430 |
|
} //namespace oopse |