ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/brains/SimInfo.hpp
Revision: 1903
Committed: Thu Jan 6 00:16:07 2005 UTC (19 years, 7 months ago) by tim
File size: 18524 byte(s)
Log Message:
simpleBuilder in progress

File Contents

# Content
1 /*
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 SimInfo.hpp
28 * @author tlin
29 * @date 11/02/2004
30 * @version 1.0
31 */
32
33 #ifndef BRAINS_SIMMODEL_HPP
34 #define BRAINS_SIMMODEL_HPP
35
36 #include <iostream>
37 #include <set>
38 #include <utility>
39 #include <vector>
40
41 #include "brains/Exclude.hpp"
42 #include "io/Globals.hpp"
43 #include "math/Vector3.hpp"
44 #include "types/MoleculeStamp.hpp"
45 #include "UseTheForce/ForceField.hpp"
46 #include "utils/PropertyMap.hpp"
47 #include "utils/LocalIndexManager.hpp"
48
49 //another nonsense macro declaration
50 #define __C
51 #include "brains/fSimulation.h"
52
53 namespace oopse{
54
55 //forward decalration
56 class SnapshotManager;
57 class Molecule;
58
59 /**
60 * @class SimInfo SimInfo.hpp "brains/SimInfo.hpp"
61 * @brief As one of the heavy weight class of OOPSE, SimInfo
62 * One of the major changes in SimInfo class is the data struct. It only maintains a list of molecules.
63 * And the Molecule class will maintain all of the concrete objects (atoms, bond, bend, torsions, rigid bodies,
64 * cutoff groups, constrains).
65 * Another major change is the index. No matter single version or parallel version, atoms and
66 * rigid bodies have both global index and local index. Local index is not important to molecule as well as
67 * cutoff group.
68 */
69 class SimInfo {
70 public:
71 typedef std::map<int, Molecule*>::iterator MoleculeIterator;
72
73 /**
74 * Constructor of SimInfo
75 * @param molStampPairs MoleculeStamp Array. The first element of the pair is molecule stamp, the
76 * second element is the total number of molecules with the same molecule stamp in the system
77 * @param ff pointer of a concrete ForceField instance
78 * @param simParams
79 * @note
80 */
81 SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs, ForceField* ff, Globals* simParams);
82 virtual ~SimInfo();
83
84 /**
85 * Adds a molecule
86 * @return return true if adding successfully, return false if the molecule is already in SimInfo
87 * @param mol molecule to be added
88 */
89 bool addMolecule(Molecule* mol);
90
91 /**
92 * Removes a molecule from SimInfo
93 * @return true if removing successfully, return false if molecule is not in this SimInfo
94 */
95 bool removeMolecule(Molecule* mol);
96
97 /** Returns the total number of molecules in the system. */
98 int getNGlobalMolecules() {
99 return nGlobalMols_;
100 }
101
102 /** Returns the total number of atoms in the system. */
103 int getNGlobalAtoms() {
104 return nGlobalAtoms_;
105 }
106
107 /** Returns the total number of cutoff groups in the system. */
108 int getNGlobalCutoffGroups() {
109 return nGlobalCutoffGroups_;
110 }
111
112 /**
113 * Returns the total number of integrable objects (total number of rigid bodies plus the total number
114 * of atoms which do not belong to the rigid bodies) in the system
115 */
116 int getNGlobalIntegrableObjects() {
117 return nGlobalIntegrableObjects_;
118 }
119
120 /**
121 * Returns the total number of integrable objects (total number of rigid bodies plus the total number
122 * of atoms which do not belong to the rigid bodies) in the system
123 */
124 int getNGlobalRigidBodies() {
125 return nGlobalRigidBodies_;
126 }
127
128 /**
129 * Returns the number of local molecules.
130 * @return the number of local molecules
131 */
132 int getNMolecules() {
133 return molecules_.size();
134 }
135
136 /** Returns the number of local atoms */
137 unsigned int getNAtoms() {
138 return nAtoms_;
139 }
140
141 /** Returns the number of local bonds */
142 unsigned int getNBonds(){
143 return nBonds_;
144 }
145
146 /** Returns the number of local bends */
147 unsigned int getNBends() {
148 return nBends_;
149 }
150
151 /** Returns the number of local torsions */
152 unsigned int getNTorsions() {
153 return nTorsions_;
154 }
155
156 /** Returns the number of local rigid bodies */
157 unsigned int getNRigidBodies() {
158 return nRigidBodies_;
159 }
160
161 /** Returns the number of local integrable objects */
162 unsigned int getNIntegrableObjects() {
163 return nIntegrableObjects_;
164 }
165
166 /** Returns the number of local cutoff groups */
167 unsigned int getNCutoffGroups() {
168 return nCutoffGroups_;
169 }
170
171 /** Returns the total number of constraints in this SimInfo */
172 unsigned int getNConstraints() {
173 return nConstraints_;
174 }
175
176 /**
177 * Returns the first molecule in this SimInfo and intialize the iterator.
178 * @return the first molecule, return NULL if there is not molecule in this SimInfo
179 * @param i the iterator of molecule array (user shouldn't change it)
180 */
181 Molecule* beginMolecule(MoleculeIterator& i);
182
183 /**
184 * Returns the next avaliable Molecule based on the iterator.
185 * @return the next avaliable molecule, return NULL if reaching the end of the array
186 * @param i the iterator of molecule array
187 */
188 Molecule* nextMolecule(MoleculeIterator& i);
189
190 /** Returns the number of degrees of freedom */
191 int getNdf() {
192 return ndf_;
193 }
194
195 /** Returns the number of raw degrees of freedom */
196 int getNdfRaw() {
197 return ndfRaw_;
198 }
199
200 /** Returns the number of translational degrees of freedom */
201 int getNdfTrans() {
202 return ndfTrans_;
203 }
204
205 //getNZconstraint and setNZconstraint ruin the coherent of SimInfo class, need refactorying
206
207 /** Returns the total number of z-constraint molecules in the system */
208 int getNZconstraint() {
209 return nZconstraint_;
210 }
211
212 /**
213 * Sets the number of z-constraint molecules in the system.
214 */
215 void setNZconstraint(int nZconstraint) {
216 nZconstraint_ = nZconstraint;
217 }
218
219 /** Returns the snapshot manager. */
220 SnapshotManager* getSnapshotManager() {
221 return sman_;
222 }
223
224 /** Sets the snapshot manager. */
225 void setSnapshotManager(SnapshotManager* sman);
226
227 /** Returns the force field */
228 ForceField* getForceField() {
229 return forceField_;
230 }
231
232 Globals* getSimParams() {
233 return simParams_;
234 }
235
236 /** Returns the velocity of center of mass of the whole system.*/
237 Vector3d getComVel();
238
239 /** Returns the center of the mass of the whole system.*/
240 Vector3d getCom();
241
242 /** Returns the seed (used for random number generator) */
243 int getSeed() {
244 return seed_;
245 }
246
247 /** Sets the seed*/
248 void setSeed(int seed) {
249 seed_ = seed;
250 }
251
252 /** main driver function to interact with fortran during the initialization and molecule migration */
253 void update();
254
255 /** Returns the local index manager */
256 LocalIndexManager* getLocalIndexManager() {
257 return &localIndexMan_;
258 }
259
260 int getMoleculeStampId(int globalIndex) {
261 //assert(globalIndex < molStampIds_.size())
262 return molStampIds_[globalIndex];
263 }
264
265 /** Returns the molecule stamp */
266 MoleculeStamp* getMoleculeStamp(int id) {
267 return moleculeStamps_[id];
268 }
269
270 /** Return the total number of the molecule stamps */
271 int getNMoleculeStamp() {
272 return moleculeStamps_.size();
273 }
274 /**
275 * Finds a molecule with a specified global index
276 * @return a pointer point to found molecule
277 * @param index
278 */
279 Molecule* getMoleculeByGlobalIndex(int index) {
280 MoleculeIterator i;
281 i = molecules_.find(index);
282
283 return i != molecules_.end() ? i->second : NULL;
284 }
285
286 /** Calculate the maximum cutoff radius based on the atom types */
287 double calcMaxCutoffRadius();
288
289 double getRcut() {
290 return rcut_;
291 }
292
293 double getRsw() {
294 return rsw_;
295 }
296
297 std::string getFinalConfigFileName() {
298 return finalConfigFileName_;
299 }
300
301 void setFinalConfigFileName(const std::string& fileName) {
302 finalConfigFileName_ = fileName;
303 }
304
305 std::string getDumpFileName() {
306 return dumpFileName_;
307 }
308
309 void setDumpFileName(const std::string& fileName) {
310 dumpFileName_ = fileName;
311 }
312
313 std::string getStatFileName() {
314 return statFileName_;
315 }
316
317 void setStatFileName(const std::string& fileName) {
318 statFileName_ = fileName;
319 }
320
321 /**
322 * Sets GlobalGroupMembership
323 * @see #SimCreator::setGlobalIndex
324 */
325 void setGlobalGroupMembership(const std::vector<int>& globalGroupMembership) {
326 assert(globalGroupMembership.size() == nGlobalAtoms_);
327 globalGroupMembership_ = globalGroupMembership;
328 }
329
330 /**
331 * Sets GlobalMolMembership
332 * @see #SimCreator::setGlobalIndex
333 */
334 void setGlobalMolMembership(const std::vector<int>& globalMolMembership) {
335 assert(globalMolMembership.size() == nGlobalAtoms_);
336 globalMolMembership_ = globalMolMembership;
337 }
338
339
340 bool isFortranInitialized() {
341 return fortranInitialized_;
342 }
343
344 //below functions are just forward functions
345 //To compose or to inherit is always a hot debate. In general, is-a relation need subclassing, in the
346 //the other hand, has-a relation need composing.
347 /**
348 * Adds property into property map
349 * @param genData GenericData to be added into PropertyMap
350 */
351 void addProperty(GenericData* genData);
352
353 /**
354 * Removes property from PropertyMap by name
355 * @param propName the name of property to be removed
356 */
357 void removeProperty(const std::string& propName);
358
359 /**
360 * clear all of the properties
361 */
362 void clearProperties();
363
364 /**
365 * Returns all names of properties
366 * @return all names of properties
367 */
368 std::vector<std::string> getPropertyNames();
369
370 /**
371 * Returns all of the properties in PropertyMap
372 * @return all of the properties in PropertyMap
373 */
374 std::vector<GenericData*> getProperties();
375
376 /**
377 * Returns property
378 * @param propName name of property
379 * @return a pointer point to property with propName. If no property named propName
380 * exists, return NULL
381 */
382 GenericData* getPropertyByName(const std::string& propName);
383
384 /**
385 * add all exclude pairs of a molecule into exclude list.
386 */
387 void addExcludePairs(Molecule* mol);
388
389 /**
390 * remove all exclude pairs which belong to a molecule from exclude list
391 */
392
393 void removeExcludePairs(Molecule* mol);
394
395 friend std::ostream& operator <<(std::ostream& o, SimInfo& info);
396
397 private:
398
399
400 /** Returns the unique atom types of local processor in an array */
401 std::set<AtomType*> getUniqueAtomTypes();
402
403 /** fill up the simtype struct*/
404 void setupSimType();
405
406 /**
407 * Setup Fortran Simulation
408 * @see #setupFortranParallel
409 */
410 void setupFortranSim();
411
412 /** Figure out the radius of cutoff, radius of switching function and pass them to fortran */
413 void setupCutoff();
414
415 /** Calculates the number of degress of freedom in the whole system */
416 void calcNdf();
417 void calcNdfRaw();
418 void calcNdfTrans();
419
420 /**
421 * Adds molecule stamp and the total number of the molecule with same molecule stamp in the whole
422 * system.
423 */
424 void addMoleculeStamp(MoleculeStamp* molStamp, int nmol);
425
426 ForceField* forceField_;
427 Globals* simParams_;
428
429 std::map<int, Molecule*> molecules_; /**< Molecule array */
430
431 //degress of freedom
432 int ndf_; /**< number of degress of freedom (excludes constraints), ndf_ is local */
433 int ndfRaw_; /**< number of degress of freedom (includes constraints), ndfRaw_ is local */
434 int ndfTrans_; /**< number of translation degress of freedom, ndfTrans_ is local */
435 int nZconstraint_; /** number of z-constraint molecules, nZconstraint_ is global */
436
437 //number of global objects
438 int nGlobalMols_; /**< number of molecules in the system */
439 int nGlobalAtoms_; /**< number of atoms in the system */
440 int nGlobalCutoffGroups_; /**< number of cutoff groups in this system */
441 int nGlobalIntegrableObjects_; /**< number of integrable objects in this system */
442 int nGlobalRigidBodies_; /**< number of rigid bodies in this system */
443 /**
444 * the size of globalGroupMembership_ is nGlobalAtoms. Its index is global index of an atom, and the
445 * corresponding content is the global index of cutoff group this atom belong to.
446 * It is filled by SimCreator once and only once, since it never changed during the simulation.
447 */
448 std::vector<int> globalGroupMembership_;
449
450 /**
451 * the size of globalGroupMembership_ is nGlobalAtoms. Its index is global index of an atom, and the
452 * corresponding content is the global index of molecule this atom belong to.
453 * It is filled by SimCreator once and only once, since it is never changed during the simulation.
454 */
455 std::vector<int> globalMolMembership_;
456
457
458 std::vector<int> molStampIds_; /**< stamp id array of all molecules in the system */
459 std::vector<MoleculeStamp*> moleculeStamps_; /**< molecule stamps array */
460
461 //number of local objects
462 int nAtoms_; /**< number of atoms in local processor */
463 int nBonds_; /**< number of bonds in local processor */
464 int nBends_; /**< number of bends in local processor */
465 int nTorsions_; /**< number of torsions in local processor */
466 int nRigidBodies_; /**< number of rigid bodies in local processor */
467 int nIntegrableObjects_; /**< number of integrable objects in local processor */
468 int nCutoffGroups_; /**< number of cutoff groups in local processor */
469 int nConstraints_; /**< number of constraints in local processors */
470
471 simtype fInfo_; /**< A dual struct shared by c++/fortran which indicates the atom types in simulation*/
472 Exclude exclude_;
473 PropertyMap properties_; /**< Generic Property */
474 SnapshotManager* sman_; /**< SnapshotManager */
475
476 int seed_; /**< seed for random number generator */
477
478 /**
479 * The reason to have a local index manager is that when molecule is migrating to other processors,
480 * the atoms and the rigid-bodies will release their local indices to LocalIndexManager. Combining the
481 * information of molecule migrating to current processor, Migrator class can query the LocalIndexManager
482 * to make a efficient data moving plan.
483 */
484 LocalIndexManager localIndexMan_;
485
486 //file names
487 std::string finalConfigFileName_;
488 std::string dumpFileName_;
489 std::string statFileName_;
490
491 double rcut_; /**< cutoff radius*/
492 double rsw_; /**< radius of switching function*/
493
494 bool fortranInitialized_; /**< flag indicate whether fortran side is initialized */
495
496 #ifdef IS_MPI
497 //in Parallel version, we need MolToProc
498 public:
499
500 /**
501 * Finds the processor where a molecule resides
502 * @return the id of the processor which contains the molecule
503 * @param globalIndex global Index of the molecule
504 */
505 int getMolToProc(int globalIndex) {
506 //assert(globalIndex < molToProcMap_.size());
507 return molToProcMap_[globalIndex];
508 }
509
510 /**
511 * Set MolToProcMap array
512 * @see #SimCreator::divideMolecules
513 */
514 void setMolToProcMap(const std::vector<int>& molToProcMap) {
515 molToProcMap_ = molToProcMap;
516 }
517
518 private:
519
520 void setupFortranParallel();
521
522 /**
523 * The size of molToProcMap_ is equal to total number of molecules in the system.
524 * It maps a molecule to the processor on which it resides. it is filled by SimCreator once and only
525 * once.
526 */
527 std::vector<int> molToProcMap_;
528 #endif
529
530 };
531
532 } //namespace oopse
533 #endif //BRAINS_SIMMODEL_HPP
534