ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/brains/SimInfo.hpp
Revision: 1842
Committed: Fri Dec 3 20:30:07 2004 UTC (19 years, 9 months ago) by tim
File size: 18190 byte(s)
Log Message:
Change interface of SimInfo

File Contents

# User Rev Content
1 tim 1842 /*
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     /**
271     * Finds a molecule with a specified global index
272     * @return a pointer point to found molecule
273     * @param index
274     */
275     Molecule* getMoleculeByGlobalIndex(int index) {
276     MoleculeIterator i;
277     i = molecules_.find(index);
278    
279     return i != molecules_.end() ? i->second : NULL;
280     }
281    
282     /** Calculate the maximum cutoff radius based on the atom types */
283     double calcMaxCutoffRadius();
284    
285     double getRcut() {
286     return rcut_;
287     }
288    
289     double getRsw() {
290     return rsw_;
291     }
292    
293     std::string getFinalConfigFileName() {
294     return finalConfigFileName_;
295     }
296    
297     void setFinalConfigFileName(const std::string& fileName) {
298     finalConfigFileName_ = fileName;
299     }
300    
301     std::string getDumpFileName() {
302     return dumpFileName_;
303     }
304    
305     void setDumpFileName(const std::string& fileName) {
306     dumpFileName_ = fileName;
307     }
308    
309     std::string getStatFileName() {
310     return statFileName_;
311     }
312    
313     void setStatFileName(const std::string& fileName) {
314     statFileName_ = fileName;
315     }
316    
317     /**
318     * Sets GlobalGroupMembership
319     * @see #SimCreator::setGlobalIndex
320     */
321     void setGlobalGroupMembership(const std::vector<int>& globalGroupMembership) {
322     assert(globalGroupMembership.size() == nGlobalAtoms_);
323     globalGroupMembership_ = globalGroupMembership_;
324     }
325    
326     /**
327     * Sets GlobalMolMembership
328     * @see #SimCreator::setGlobalIndex
329     */
330     void setGlobalMolMembership(const std::vector<int>& globalMolMembership) {
331     assert(globalMolMembership.size() == nGlobalAtoms_);
332     globalMolMembership_ = globalMolMembership;
333     }
334    
335    
336     bool isFortranInitialized() {
337     return fortranInitialized_;
338     }
339    
340     //below functions are just forward functions
341     //To compose or to inherit is always a hot debate. In general, is-a relation need subclassing, in the
342     //the other hand, has-a relation need composing.
343     /**
344     * Adds property into property map
345     * @param genData GenericData to be added into PropertyMap
346     */
347     void addProperty(GenericData* genData);
348    
349     /**
350     * Removes property from PropertyMap by name
351     * @param propName the name of property to be removed
352     */
353     void removeProperty(const std::string& propName);
354    
355     /**
356     * clear all of the properties
357     */
358     void clearProperties();
359    
360     /**
361     * Returns all names of properties
362     * @return all names of properties
363     */
364     std::vector<std::string> getPropertyNames();
365    
366     /**
367     * Returns all of the properties in PropertyMap
368     * @return all of the properties in PropertyMap
369     */
370     std::vector<GenericData*> getProperties();
371    
372     /**
373     * Returns property
374     * @param propName name of property
375     * @return a pointer point to property with propName. If no property named propName
376     * exists, return NULL
377     */
378     GenericData* getPropertyByName(const std::string& propName);
379    
380     friend std::ostream& operator <<(std::ostream& o, SimInfo& info);
381    
382     private:
383    
384    
385     /** Returns the unique atom types of local processor in an array */
386     std::set<AtomType*> getUniqueAtomTypes();
387    
388     /** fill up the simtype struct*/
389     void setupSimType();
390    
391     /**
392     * Setup Fortran Simulation
393     * @see #setupFortranParallel
394     */
395     void setupFortranSim();
396    
397     /** Figure out the radius of cutoff, radius of switching function and pass them to fortran */
398     void setupCutoff();
399    
400     /** Calculates the number of degress of freedom in the whole system */
401     void calcNdf();
402     void calcNdfRaw();
403     void calcNdfTrans();
404    
405     void addExcludePairs(Molecule* mol);
406     void removeExcludePairs(Molecule* mol);
407    
408     /**
409     * Adds molecule stamp and the total number of the molecule with same molecule stamp in the whole
410     * system.
411     */
412     void addMoleculeStamp(MoleculeStamp* molStamp, int nmol);
413    
414     ForceField* forceField_;
415     Globals* simParams_;
416    
417     std::map<int, Molecule*> molecules_; /**< Molecule array */
418    
419     //degress of freedom
420     int ndf_; /**< number of degress of freedom (excludes constraints), ndf_ is local */
421     int ndfRaw_; /**< number of degress of freedom (includes constraints), ndfRaw_ is local */
422     int ndfTrans_; /**< number of translation degress of freedom, ndfTrans_ is local */
423     int nZconstraint_; /** number of z-constraint molecules, nZconstraint_ is global */
424    
425     //number of global objects
426     int nGlobalMols_; /**< number of molecules in the system */
427     int nGlobalAtoms_; /**< number of atoms in the system */
428     int nGlobalCutoffGroups_; /**< number of cutoff groups in this system */
429     int nGlobalIntegrableObjects_; /**< number of integrable objects in this system */
430     int nGlobalRigidBodies_; /**< number of rigid bodies in this system */
431     /**
432     * the size of globalGroupMembership_ is nGlobalAtoms. Its index is global index of an atom, and the
433     * corresponding content is the global index of cutoff group this atom belong to.
434     * It is filled by SimCreator once and only once, since it is never changed during the simulation.
435     */
436     std::vector<int> globalGroupMembership_;
437    
438     /**
439     * the size of globalGroupMembership_ is nGlobalAtoms. Its index is global index of an atom, and the
440     * corresponding content is the global index of molecule this atom belong to.
441     * It is filled by SimCreator once and only once, since it is never changed during the simulation.
442     */
443     std::vector<int> globalMolMembership_;
444    
445    
446     std::vector<int> molStampIds_; /**< stamp id array of all molecules in the system */
447     std::vector<MoleculeStamp*> moleculeStamps_; /**< molecule stamps array */
448    
449     //number of local objects
450     int nAtoms_; /**< number of atoms in local processor */
451     int nBonds_; /**< number of bonds in local processor */
452     int nBends_; /**< number of bends in local processor */
453     int nTorsions_; /**< number of torsions in local processor */
454     int nRigidBodies_; /**< number of rigid bodies in local processor */
455     int nIntegrableObjects_; /**< number of integrable objects in local processor */
456     int nCutoffGroups_; /**< number of cutoff groups in local processor */
457     int nConstraints_; /**< number of constraints in local processors */
458    
459     simtype fInfo_; /**< A dual struct shared by c++/fortran which indicates the atom types in simulation*/
460     Exclude exclude_;
461     PropertyMap properties_; /**< Generic Property */
462     SnapshotManager* sman_; /**< SnapshotManager */
463    
464     int seed_; /**< seed for random number generator */
465    
466     /**
467     * The reason to have a local index manager is that when molecule is migrating to other processors,
468     * the atoms and the rigid-bodies will release their local indices to LocalIndexManager. Combining the
469     * information of molecule migrating to current processor, Migrator class can query the LocalIndexManager
470     * to make a efficient data moving plan.
471     */
472     LocalIndexManager localIndexMan_;
473    
474     //file names
475     std::string finalConfigFileName_;
476     std::string dumpFileName_;
477     std::string statFileName_;
478    
479     double rcut_; /**< cutoff radius*/
480     double rsw_; /**< radius of switching function*/
481    
482     bool fortranInitialized_; /**< flag indicate whether fortran side is initialized */
483    
484     #ifdef IS_MPI
485     //in Parallel version, we need MolToProc
486     public:
487    
488     /**
489     * Finds the processor where a molecule resides
490     * @return the id of the processor which contains the molecule
491     * @param globalIndex global Index of the molecule
492     */
493     int getMolToProc(int globalIndex) {
494     //assert(globalIndex < molToProcMap_.size());
495     return molToProcMap_[globalIndex];
496     }
497    
498     /**
499     * Set MolToProcMap array
500     * @see #SimCreator::divideMolecules
501     */
502     void setMolToProcMap(const std::vector<int>& molToProcMap) {
503     molToProcMap_ = molToProcMap;
504     }
505    
506     private:
507    
508     void setupFortranParallel();
509    
510     /**
511     * The size of molToProcMap_ is equal to total number of molecules in the system.
512     * It maps a molecule to the processor on which it resides. it is filled by SimCreator once and only
513     * once.
514     */
515     std::vector<int> molToProcMap_;
516     #endif
517    
518     };
519    
520     } //namespace oopse
521     #endif //BRAINS_SIMMODEL_HPP
522