ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/brains/SimInfo.hpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/brains/SimInfo.hpp (file contents):
Revision 1725 by tim, Wed Nov 10 22:01:06 2004 UTC vs.
Revision 1738 by tim, Sat Nov 13 05:08:12 2004 UTC

# Line 47 | Line 47 | namespace oopse{
47  
48   /**
49   * @class SimInfo SimInfo.hpp "brains/SimInfo.hpp"
50 < * @brief
50 > * @brief As one of the heavy weight class of OOPSE, SimInfo
51 > * One of the major changes in SimInfo class is the data struct. It only maintains a list of molecules.
52 > * And the Molecule class will maintain all of the concrete objects (atoms, bond, bend, torsions, rigid bodies,
53 > * cutoff groups, constrains).
54 > * Another major change is the index. No matter single version or parallel version,  atoms and
55 > * rigid bodies have both global index and local index. Local index is not important to molecule as well as
56 > * cutoff group.
57   */
58   class SimInfo {
59      public:
60 <        typedef std::vector<Molecule*>::iterator MoleculeIterator;
61 <        SimInfo();
60 >        typedef std::map<int, Molecule*>::iterator  MoleculeIterator;
61 >
62 >        /**
63 >         * Constructor of SimInfo
64 >         * @param molStampPairs MoleculeStamp Array. The first element of the pair is molecule stamp, the
65 >         * second element is the total number of molecules with the same molecule stamp in the system
66 >         * @param ff pointer of a concrete ForceField instance
67 >         * @param globals
68 >         * @note
69 >         */
70 >        SimInfo(const std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs, ForceField* ff, Globals* globals);
71          virtual ~SimInfo();
72  
73          /**
# Line 70 | Line 85 | class SimInfo {
85  
86          /** Returns the total number of molecules in the system. */
87          int getNGlobalMolecules() {
88 <
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
88 >            return nGlobalMols_;
89          }
90  
91          /** Returns the total number of atoms in the system. */
92          int getNGlobalAtoms() {
93 <
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
93 >            return nGlobalAtoms_;
94          }
95  
96          /** Returns the total number of cutoff groups in the system. */
97          int getNGlobalCutoffGroups() {
98 < #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
98 >            return nGlobalCutoffGroups_;
99          }
100          
101          /**
# Line 160 | Line 151 | class SimInfo {
151           * @return the first molecule, return NULL if there is not molecule in this SimInfo
152           * @param i the iterator of molecule array (user shouldn't change it)
153           */
154 <        Molecule* beginMolecule(std::vector<Molecule*>::iterator& i);
154 >        Molecule* beginMolecule(MoleculeIterator& i);
155  
156          /**
157            * Returns the next avaliable Molecule based on the iterator.
158            * @return the next avaliable molecule, return NULL if reaching the end of the array
159            * @param i the iterator of molecule array
160            */
161 <        Molecule* nextMolecule(std::vector<Molecule*>::iterator& i);
161 >        Molecule* nextMolecule(MoleculeIterator& i);
162  
163          /** Returns the number of degrees of freedom */
164          int getNdf() {
# Line 184 | Line 175 | class SimInfo {
175              return ndfTrans_;
176          }
177  
178 +        //getNZconstraint and setNZconstraint ruin the coherent of SimInfo class, need refactorying
179 +        
180 +        /** Returns the total number of z-constraint molecules in the system */
181 +        int getNZconstraint() {
182 +            return nZconstraint_;
183 +        }
184 +
185 +        /**
186 +         * Sets the number of z-constraint molecules in the system.
187 +         */
188 +        int setNZconstraint(int nZconstraint) {
189 +            nZconstraint_ = nZconstraint;
190 +        }
191 +        
192          /** Returns the snapshot manager. */
193          SnapshotManager* getSnapshotManager() {
194              return sman_;
# Line 199 | Line 204 | class SimInfo {
204              return forceField_;
205          }
206  
202        /** Sets the force field */
203        void setForceField(ForceField* ff) {
204            forceField_ = ff;
205        }
206
207          Globals* getGlobals() {
208              return globals_;
209          }
210        
211        void setGlobals(Globals* globals) {
212            globals_ = globals;
213        }
210  
211          /** Returns the velocity of center of mass of the whole system.*/
212          Vector3d getComVel();
# Line 228 | Line 224 | class SimInfo {
224              seed_ = seed;
225          }
226  
227 <        
227 >        /** main driver function to interact with fortran during the initialization and molecule migration */
228          void update();
229  
234
230          /** Returns the local index manager */
231          LocalIndexManager* getLocalIndexManager() {
232 <            return localIndexMan_;
232 >            return &localIndexMan_;
233          }
234  
240
241        /**
242         *
243         */
244        void addMoleculeStamp(MoleculeStamp* molStamp, int nmol);
245
235          int getMoleculeStampId(int globalIndex) {
236              //assert(globalIndex < molStampIds_.size())
237              return molStampIds_[globalIndex];
# Line 254 | Line 243 | class SimInfo {
243          }
244          
245          /**
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        /**
246           * Finds a molecule with a specified global index
247           * @return a pointer point to found molecule
248           * @param index
249           */
250          Molecule* getMoleculeByGlobalIndex(int index) {
251              std::map<int, Molecule*> i;
252 <            i = globalIndexToMol_.find(index);
252 >            i = molecules_.find(index);
253  
254 <            return i != globalIndexToMol_.end() ? i->second : NULL;
254 >            return i != molecules_.end() ? i->second : NULL;
255          }
256  
257 +        /** Calculate the maximum cutoff radius based on the atom types */
258 +        double calcMaxCutoffRadius();
259  
260 +        double getRcut() {
261 +            return rcut_;
262 +        }
263 +
264 +        double getRsw() {
265 +            return rsw_;
266 +        }
267 +        
268 +        std::string getFinalConfigFileName() {
269 +            return finalConfigFileName_;
270 +        }
271 +        
272 +        void setFinalConfigFileName(const std::string& fileName) {
273 +            finalConfigFileName_ = fileName;
274 +        }
275 +
276 +        std::string getDumpFileName() {
277 +            return dumpFileName_;
278 +        }
279 +        
280 +        void setDumpFileName(const std::string& fileName) {
281 +            dumpFileName_ = fileName;
282 +        }
283 +
284 +        std::string getStatFileName() {
285 +            return statFileName_;
286 +        }
287 +        
288 +        void setStatFileName(const std::string& fileName) {
289 +            statFileName_ = fileName;
290 +        }
291 +
292 +        /**
293 +         * Returns the pointer of internal globalGroupMembership_ array. This array will be filled by SimCreator class
294 +         * @see #SimCreator::setGlobalIndex
295 +         */  
296 +        int* getGlobalGroupMembershipPointer() {
297 +            return globalGroupMembership_[0];
298 +        }
299 +
300 +        /**
301 +         * Returns the pointer of internal globalMolMembership_ array. This array will be filled by SimCreator class
302 +         * @see #SimCreator::setGlobalIndex
303 +         */        
304 +        int* getGlobalMolMembershipPointer() {
305 +            return globalMolMembership_[0];
306 +        }
307 +
308 +
309 +        bool isFortranInitialized() {
310 +            return fortranInitialized_;
311 +        }
312 +        
313 +        //below functions are just forward functions
314 +        //To compose or to inherit is always a hot debate. In general, is-a relation need subclassing, in the
315 +        //the other hand, has-a relation need composing.
316 +        /**
317 +         * Adds property into property map
318 +         * @param genData GenericData to be added into PropertyMap
319 +         */
320 +        void addProperty(GenericData* genData);
321 +
322 +        /**
323 +         * Removes property from PropertyMap by name
324 +         * @param propName the name of property to be removed
325 +         */
326 +        void removeProperty(const std::string& propName);
327 +
328 +        /**
329 +         * clear all of the properties
330 +         */
331 +        void clearProperties();
332 +
333 +        /**
334 +         * Returns all names of properties
335 +         * @return all names of properties
336 +         */
337 +        std::vector<std::string> getPropertyNames();
338 +
339 +        /**
340 +         * Returns all of the properties in PropertyMap
341 +         * @return all of the properties in PropertyMap
342 +         */      
343 +        std::vector<GenericData*> getProperties();
344 +
345 +        /**
346 +         * Returns property
347 +         * @param propName name of property
348 +         * @return a pointer point to property with propName. If no property named propName
349 +         * exists, return NULL
350 +         */      
351 +        GenericData* getPropertyByName(const std::string& propName);
352 +                
353          friend std::ostream& operator <<(ostream& o, SimInfo& info);
354          
355      private:
356  
357 +        
358 +        /** Returns the unique atom types of local processor in an array */
359 +        std::set<AtomType*> SimInfo::getUniqueAtomTypes();
360 +
361 +        /** fill up the simtype struct*/
362 +        void setupSimType();
363 +
364 +        /**
365 +         * Setup Fortran Simulation
366 +         * @see #setupFortranParallel
367 +         */
368 +        void setupFortranSim();
369 +
370 +        /** Figure out the radius of cutoff, radius of switching function and pass them to fortran */
371 +        void setupCutoff();
372 +
373 +        /** Calculates the number of degress of freedom in the whole system */
374          void calcNdf();
375          void calcNdfRaw();
376          void calcNdfTrans();
377  
287        int* getExcludeList() {
288            return exclude_.getExcludeList();
289        }
290
378          void addExcludePairs(Molecule* mol);
379          void removeExcludePairs(Molecule* mol);
380  
381 +        /**
382 +         * Adds molecule stamp and the total number of the molecule with same molecule stamp in the whole
383 +         * system.
384 +         */
385 +        void addMoleculeStamp(MoleculeStamp* molStamp, int nmol);
386 +
387 +        std::map<int, Molecule*>  molecules_; /**< Molecule array */
388 +        
389          //degress of freedom
390 <        int ndf_;           /** number of degress of freedom */
391 <        int ndfRaw_;
392 <        int ndfTrans_; /**< number of translation degress of freedom */
390 >        int ndf_;           /**< number of degress of freedom (excludes constraints),  ndf_ is local */
391 >        int ndfRaw_;    /**< number of degress of freedom (includes constraints),  ndfRaw_ is local */
392 >        int ndfTrans_; /**< number of translation degress of freedom, ndfTrans_ is local */
393 >        int nZconstraint_; /** number of  z-constraint molecules, nZconstraint_ is global */
394 >        
395 >        //number of global objects
396 >        int nGlobalMols_;       /**< number of molecules in the system */
397 >        int nGlobalAtoms_;   /**< number of atoms in the system */
398 >        int nGlobalCutoffGroups_; /**< number of cutoff groups in this system */
399  
400 +        /**
401 +         * the size of globalGroupMembership_  is nGlobalAtoms. Its index is  global index of an atom, and the
402 +         * corresponding content is the global index of cutoff group this atom belong to.
403 +         * It is filled by SimCreator once and only once, since it is never changed during the simulation.
404 +         */
405 +        std::vector<int> globalGroupMembership_;
406 +
407 +        /**
408 +         * the size of globalGroupMembership_  is nGlobalAtoms. Its index is  global index of an atom, and the
409 +         * corresponding content is the global index of molecule this atom belong to.
410 +         * It is filled by SimCreator once and only once, since it is never changed during the simulation.
411 +         */
412 +        std::vector<int> globalMolMembership_;        
413 +
414 +        
415 +        std::vector<int> molStampIds_;                                /**< stamp id array of all molecules in the system */
416 +        std::vector<MoleculeStamp*> moleculeStamps_;      /**< molecule stamps array */        
417 +        
418          //number of local objects
419 <        int nAtoms_;
420 <        int nBonds_;
421 <        int nBends_;
422 <        int nTorsions_;
423 <        int nRigidBodies_;
424 <        int nIntegrableObjects_;
425 <        int nCutoffGroups_;
426 <        int nConstraints_;
419 >        int nAtoms_;                        /**< number of atoms in local processor */
420 >        int nBonds_;                        /**< number of bonds in local processor */
421 >        int nBends_;                        /**< number of bends in local processor */
422 >        int nTorsions_;                    /**< number of torsions in local processor */
423 >        int nRigidBodies_;              /**< number of rigid bodies in local processor */
424 >        int nIntegrableObjects_;    /**< number of integrable objects in local processor */
425 >        int nCutoffGroups_;             /**< number of cutoff groups in local processor */
426 >        int nConstraints_;              /**< number of constraints in local processors */
427  
428 <        simtype fInfo_;
428 >        simtype fInfo_; /**< A dual struct shared by c++/fortran which indicates the atom types in simulation*/
429          Exclude exclude_;
430 <        ForceField* forceField_;
312 <        
313 <        std::vector<Molecule*> molecules_; /**< Molecule array */
430 >        ForceField* forceField_;            
431          PropertyMap properties_;                  /**< Generic Property */
432          SnapshotManager* sman_;               /**< SnapshotManager */
316
433          Globals* globals_;
318
434          int seed_; /**< seed for random number generator */
435  
436 +        /**
437 +         * The reason to have a local index manager is that when molecule is migrating to other processors,
438 +         * the atoms and the rigid-bodies will release their local indices to LocalIndexManager. Combining the
439 +         * information of molecule migrating to current processor, Migrator class can query  the LocalIndexManager
440 +         * to make a efficient data moving plan.
441 +         */        
442          LocalIndexManager localIndexMan_;
443  
444 <        //
445 <        std::vector<int> molToProcMap_;
446 <        std::map<int, Molecule*> globalIndexToMol_;
447 <        std::vector<int> molStampIds_;                                /**< stamp id array of all molecules in the system */
327 <        std::vector<MoleculeStamp*> moleculeStamps_; /**< molecule stamps array */      
444 >        //file names
445 >        std::string finalConfigFileName_;
446 >        std::string dumpFileName_;
447 >        std::string statFileName_;
448  
449 +        double rcut_;       /**< cutoff radius*/
450 +        double rsw_;        /**< radius of switching function*/
451 +
452 +        bool fortranInitialized_; /**< flag indicate whether fortran side is initialized */
453 +        
454 + #ifdef IS_MPI
455 +    //in Parallel version, we need MolToProc
456 +    public:
457 +                
458 +        /**
459 +         * Finds the processor where a molecule resides
460 +         * @return the id of the processor which contains the molecule
461 +         * @param globalIndex global Index of the molecule
462 +         */
463 +        int getMolToProc(int globalIndex) {
464 +            //assert(globalIndex < molToProcMap_.size());
465 +            return molToProcMap_[globalIndex];
466 +        }
467 +
468 +        /**
469 +         * Returns the pointer of internal molToProcMap array. This array will be filled by SimCreator class
470 +         * @see #SimCreator::divideMolecules
471 +         */
472 +        int* getMolToProcMapPointer() {
473 +            return &molToProcMap_[0];
474 +        }
475 +        
476 +    private:
477 +
478 +        void setupFortranParallel();
479 +        
480 +        /**
481 +         * The size of molToProcMap_ is equal to total number of molecules in the system.
482 +         *  It maps a molecule to the processor on which it resides. it is filled by SimCreator once and only
483 +         * once.
484 +         */        
485 +        std::vector<int> molToProcMap_;
486 + #endif
487 +
488   };
489  
490   } //namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines