1 |
tim |
1710 |
/* |
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 |
gezelter |
1490 |
|
26 |
tim |
1710 |
/** |
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 |
tim |
1719 |
|
36 |
|
|
#include <iostream> |
37 |
gezelter |
1490 |
#include <vector> |
38 |
tim |
1719 |
#include <utility> |
39 |
gezelter |
1490 |
|
40 |
tim |
1710 |
#include "brains/fSimulation.h" |
41 |
tim |
1492 |
#include "primitives/Molecule.hpp" |
42 |
tim |
1719 |
#include "types/MoleculeStamp.hpp" |
43 |
tim |
1710 |
#include "utils/PropertyMap.hpp" |
44 |
tim |
1719 |
#include "io/Globals.hpp" |
45 |
gezelter |
1490 |
|
46 |
tim |
1710 |
namespace oopse{ |
47 |
gezelter |
1490 |
|
48 |
tim |
1710 |
/** |
49 |
|
|
* @class SimInfo SimInfo.hpp "brains/SimInfo.hpp" |
50 |
|
|
* @brief |
51 |
|
|
*/ |
52 |
|
|
class SimInfo { |
53 |
|
|
public: |
54 |
tim |
1726 |
typedef MoleculeIterator MoleculeIterator; |
55 |
tim |
1710 |
SimInfo(); |
56 |
|
|
virtual ~SimInfo(); |
57 |
gezelter |
1490 |
|
58 |
tim |
1710 |
/** |
59 |
|
|
* Adds a molecule |
60 |
|
|
* @return return true if adding successfully, return false if the molecule is already in SimInfo |
61 |
|
|
* @param mol molecule to be added |
62 |
|
|
*/ |
63 |
|
|
bool addMolecule(Molecule* mol); |
64 |
gezelter |
1490 |
|
65 |
tim |
1710 |
/** |
66 |
|
|
* Removes a molecule from SimInfo |
67 |
|
|
* @return true if removing successfully, return false if molecule is not in this SimInfo |
68 |
|
|
*/ |
69 |
|
|
bool removeMolecule(Molecule* mol); |
70 |
gezelter |
1490 |
|
71 |
tim |
1725 |
/** Returns the total number of molecules in the system. */ |
72 |
|
|
int getNGlobalMolecules() { |
73 |
|
|
|
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 |
|
|
} |
86 |
|
|
|
87 |
|
|
/** Returns the total number of atoms in the system. */ |
88 |
|
|
int getNGlobalAtoms() { |
89 |
|
|
|
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 |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/** Returns the total number of cutoff groups in the system. */ |
100 |
|
|
int getNGlobalCutoffGroups() { |
101 |
|
|
#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 |
108 |
|
|
} |
109 |
|
|
|
110 |
tim |
1710 |
/** |
111 |
tim |
1725 |
* Returns the number of local molecules. |
112 |
|
|
* @return the number of local molecules |
113 |
tim |
1710 |
*/ |
114 |
|
|
int getNMolecules() { |
115 |
|
|
return molecules_.size(); |
116 |
|
|
} |
117 |
gezelter |
1490 |
|
118 |
tim |
1725 |
/** Returns the number of local atoms */ |
119 |
tim |
1710 |
unsigned int getNAtoms() { |
120 |
|
|
return nAtoms_; |
121 |
|
|
} |
122 |
gezelter |
1490 |
|
123 |
tim |
1725 |
/** Returns the number of local bonds */ |
124 |
tim |
1710 |
unsigned int getNBonds(){ |
125 |
|
|
return nBonds_; |
126 |
|
|
} |
127 |
gezelter |
1490 |
|
128 |
tim |
1725 |
/** Returns the number of local bends */ |
129 |
tim |
1710 |
unsigned int getNBends() { |
130 |
|
|
return nBends_; |
131 |
|
|
} |
132 |
gezelter |
1490 |
|
133 |
tim |
1725 |
/** Returns the number of local torsions */ |
134 |
tim |
1710 |
unsigned int getNTorsions() { |
135 |
|
|
return nTorsions_; |
136 |
|
|
} |
137 |
gezelter |
1490 |
|
138 |
tim |
1725 |
/** Returns the number of local rigid bodies */ |
139 |
tim |
1710 |
unsigned int getNRigidBodies() { |
140 |
|
|
return nRigidBodies_; |
141 |
|
|
} |
142 |
gezelter |
1490 |
|
143 |
tim |
1725 |
/** Returns the number of local integrable objects */ |
144 |
tim |
1710 |
unsigned int getNIntegrableObjects() { |
145 |
|
|
return nIntegrableObjects_; |
146 |
|
|
} |
147 |
gezelter |
1490 |
|
148 |
tim |
1725 |
/** Returns the number of local cutoff groups */ |
149 |
tim |
1710 |
unsigned int getNCutoffGroups() { |
150 |
|
|
return nCutoffGroups_; |
151 |
|
|
} |
152 |
gezelter |
1490 |
|
153 |
tim |
1710 |
/** Returns the total number of constraints in this SimInfo */ |
154 |
|
|
unsigned int getNConstraints() { |
155 |
|
|
return nConstraints_; |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
/** |
159 |
|
|
* Returns the first molecule in this SimInfo and intialize the iterator. |
160 |
|
|
* @return the first molecule, return NULL if there is not molecule in this SimInfo |
161 |
|
|
* @param i the iterator of molecule array (user shouldn't change it) |
162 |
|
|
*/ |
163 |
tim |
1726 |
Molecule* beginMolecule(MoleculeIterator& i); |
164 |
gezelter |
1490 |
|
165 |
tim |
1710 |
/** |
166 |
|
|
* Returns the next avaliable Molecule based on the iterator. |
167 |
|
|
* @return the next avaliable molecule, return NULL if reaching the end of the array |
168 |
|
|
* @param i the iterator of molecule array |
169 |
|
|
*/ |
170 |
tim |
1726 |
Molecule* nextMolecule(MoleculeIterator& i); |
171 |
gezelter |
1490 |
|
172 |
tim |
1710 |
/** Returns the number of degrees of freedom */ |
173 |
tim |
1722 |
int getNdf() { |
174 |
tim |
1710 |
return ndf_; |
175 |
|
|
} |
176 |
gezelter |
1490 |
|
177 |
tim |
1710 |
/** Returns the number of raw degrees of freedom */ |
178 |
tim |
1722 |
int getNdfRaw() { |
179 |
tim |
1710 |
return ndfRaw_; |
180 |
|
|
} |
181 |
gezelter |
1490 |
|
182 |
tim |
1710 |
/** Returns the number of translational degrees of freedom */ |
183 |
tim |
1722 |
int getNdfTrans() { |
184 |
tim |
1710 |
return ndfTrans_; |
185 |
|
|
} |
186 |
gezelter |
1490 |
|
187 |
tim |
1710 |
/** Returns the snapshot manager. */ |
188 |
|
|
SnapshotManager* getSnapshotManager() { |
189 |
|
|
return sman_; |
190 |
|
|
} |
191 |
gezelter |
1490 |
|
192 |
tim |
1710 |
/** Sets the snapshot manager. */ |
193 |
|
|
void setSnapshotManager(SnapshotManager* sman) { |
194 |
|
|
sman_ = sman; |
195 |
|
|
} |
196 |
tim |
1712 |
|
197 |
tim |
1719 |
/** Returns the force field */ |
198 |
tim |
1712 |
ForceField* getForceField() { |
199 |
|
|
return forceField_; |
200 |
|
|
} |
201 |
tim |
1719 |
|
202 |
|
|
/** Sets the force field */ |
203 |
tim |
1712 |
void setForceField(ForceField* ff) { |
204 |
|
|
forceField_ = ff; |
205 |
|
|
} |
206 |
tim |
1719 |
|
207 |
|
|
Globals* getGlobals() { |
208 |
|
|
return globals_; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
void setGlobals(Globals* globals) { |
212 |
|
|
globals_ = globals; |
213 |
|
|
} |
214 |
|
|
|
215 |
tim |
1725 |
/** Returns the velocity of center of mass of the whole system.*/ |
216 |
|
|
Vector3d getComVel(); |
217 |
tim |
1722 |
|
218 |
tim |
1725 |
/** Returns the center of the mass of the whole system.*/ |
219 |
tim |
1722 |
Vector3d getCom(); |
220 |
|
|
|
221 |
tim |
1725 |
/** Returns the seed (used for random number generator) */ |
222 |
tim |
1722 |
int getSeed() { |
223 |
|
|
return seed_; |
224 |
|
|
} |
225 |
|
|
|
226 |
tim |
1725 |
/** Sets the seed*/ |
227 |
tim |
1722 |
void setSeed(int seed) { |
228 |
|
|
seed_ = seed; |
229 |
|
|
} |
230 |
tim |
1725 |
|
231 |
tim |
1722 |
|
232 |
tim |
1725 |
void update(); |
233 |
|
|
|
234 |
|
|
|
235 |
|
|
/** Returns the local index manager */ |
236 |
|
|
LocalIndexManager* getLocalIndexManager() { |
237 |
|
|
return localIndexMan_; |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
|
241 |
|
|
/** |
242 |
|
|
* |
243 |
|
|
*/ |
244 |
|
|
void addMoleculeStamp(MoleculeStamp* molStamp, int nmol); |
245 |
|
|
|
246 |
|
|
int getMoleculeStampId(int globalIndex) { |
247 |
|
|
//assert(globalIndex < molStampIds_.size()) |
248 |
|
|
return molStampIds_[globalIndex]; |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
/** Returns the molecule stamp */ |
252 |
|
|
MoleculeStamp* getMoleculeStamp(int id) { |
253 |
|
|
return moleculeStamps_[id]; |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
/** |
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 |
|
|
/** |
267 |
|
|
* Finds a molecule with a specified global index |
268 |
|
|
* @return a pointer point to found molecule |
269 |
|
|
* @param index |
270 |
|
|
*/ |
271 |
|
|
Molecule* getMoleculeByGlobalIndex(int index) { |
272 |
|
|
std::map<int, Molecule*> i; |
273 |
tim |
1726 |
i = molecules_.find(index); |
274 |
tim |
1725 |
|
275 |
tim |
1726 |
return i != molecules_.end() ? i->second : NULL; |
276 |
tim |
1725 |
} |
277 |
|
|
|
278 |
|
|
friend std::ostream& operator <<(ostream& o, SimInfo& info); |
279 |
|
|
|
280 |
tim |
1710 |
private: |
281 |
gezelter |
1490 |
|
282 |
tim |
1722 |
void calcNdf(); |
283 |
|
|
void calcNdfRaw(); |
284 |
|
|
void calcNdfTrans(); |
285 |
gezelter |
1490 |
|
286 |
tim |
1725 |
int* getExcludeList() { |
287 |
|
|
return exclude_.getExcludeList(); |
288 |
|
|
} |
289 |
|
|
|
290 |
tim |
1719 |
void addExcludePairs(Molecule* mol); |
291 |
|
|
void removeExcludePairs(Molecule* mol); |
292 |
|
|
|
293 |
tim |
1725 |
//degress of freedom |
294 |
|
|
int ndf_; /** number of degress of freedom */ |
295 |
tim |
1710 |
int ndfRaw_; |
296 |
tim |
1725 |
int ndfTrans_; /**< number of translation degress of freedom */ |
297 |
|
|
|
298 |
|
|
//number of local objects |
299 |
tim |
1710 |
int nAtoms_; |
300 |
|
|
int nBonds_; |
301 |
|
|
int nBends_; |
302 |
|
|
int nTorsions_; |
303 |
|
|
int nRigidBodies_; |
304 |
|
|
int nIntegrableObjects_; |
305 |
|
|
int nCutoffGroups_; |
306 |
|
|
int nConstraints_; |
307 |
gezelter |
1490 |
|
308 |
tim |
1719 |
simtype fInfo_; |
309 |
|
|
Exclude exclude_; |
310 |
tim |
1712 |
ForceField* forceField_; |
311 |
tim |
1710 |
|
312 |
tim |
1726 |
std::map<int, Molecule*> molecules_; /**< Molecule array */ |
313 |
tim |
1725 |
PropertyMap properties_; /**< Generic Property */ |
314 |
|
|
SnapshotManager* sman_; /**< SnapshotManager */ |
315 |
gezelter |
1490 |
|
316 |
tim |
1719 |
Globals* globals_; |
317 |
tim |
1722 |
|
318 |
tim |
1725 |
int seed_; /**< seed for random number generator */ |
319 |
|
|
|
320 |
|
|
LocalIndexManager localIndexMan_; |
321 |
|
|
|
322 |
|
|
// |
323 |
|
|
std::vector<int> molToProcMap_; |
324 |
|
|
std::vector<int> molStampIds_; /**< stamp id array of all molecules in the system */ |
325 |
|
|
std::vector<MoleculeStamp*> moleculeStamps_; /**< molecule stamps array */ |
326 |
|
|
|
327 |
gezelter |
1490 |
}; |
328 |
|
|
|
329 |
tim |
1710 |
} //namespace oopse |
330 |
|
|
#endif //BRAINS_SIMMODEL_HPP |