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.cpp |
28 |
* @author tlin |
29 |
* @date 11/02/2004 |
30 |
* @version 1.0 |
31 |
*/ |
32 |
|
33 |
#include <algorithm> |
34 |
|
35 |
#include "brains/SimInfo.hpp" |
36 |
#include "utils/MemoryUtils.hpp" |
37 |
|
38 |
namespace oopse { |
39 |
|
40 |
SimInfo::SimInfo() : nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0), |
41 |
nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), sman_(NULL){ |
42 |
|
43 |
} |
44 |
|
45 |
SimInfo::~SimInfo() { |
46 |
MemoryUtils::deleteVectorOfPointer(molecules_); |
47 |
delete sman_; |
48 |
|
49 |
} |
50 |
|
51 |
|
52 |
bool SimInfo::addMolecule(Molecule* mol) { |
53 |
std::vector<Molecule*>::iterator i; |
54 |
i = std::find(molecules_.begin(), molecules_.end(), mol); |
55 |
if (i != molecules_.end() ) { |
56 |
molecules_.push_back(mol); |
57 |
|
58 |
nAtoms_ += mol->getNAtoms(); |
59 |
nBonds_ += mol->getNBonds(); |
60 |
nBends_ += mol->getNBends(); |
61 |
nTorsions_ += mol->getNTorsions(); |
62 |
nRigidBodies_ += mol->getNRigidBodies(); |
63 |
nIntegrableObjects_ += mol->getNIntegrableObjects(); |
64 |
nCutoffGroups_ += mol->getNCutoffGroups(); |
65 |
nConstraints_ += mol->getNConstraints(); |
66 |
|
67 |
globalIndexToMol_.insert(make_pair(mol->getGlobalIndex(), mol)); |
68 |
return true; |
69 |
} else { |
70 |
return false; |
71 |
} |
72 |
} |
73 |
|
74 |
bool SimInfo::removeMolecule(Molecule* mol) { |
75 |
std::vector<Molecule*>::iterator i; |
76 |
i = std::find(molecules_.begin(), molecules_.end(), mol); |
77 |
|
78 |
if (i != molecules_.end() ) { |
79 |
molecules_.push_back(mol); |
80 |
nAtoms_ -= mol->getNAtoms(); |
81 |
nBonds_ -= mol->getNBonds(); |
82 |
nBends_ -= mol->getNBends(); |
83 |
nTorsions_ -= mol->getNTorsions(); |
84 |
nRigidBodies_ -= mol->getNRigidBodies(); |
85 |
nIntegrableObjects_ -= mol->getNIntegrableObjects(); |
86 |
nCutoffGroups_ -= mol->getNCutoffGroups(); |
87 |
nConstraints_ -= mol->getNConstraints(); |
88 |
|
89 |
globalIndexToMol_.erase(mol->getGlobalIndex()); |
90 |
return true; |
91 |
} else { |
92 |
return false; |
93 |
} |
94 |
|
95 |
|
96 |
} |
97 |
|
98 |
|
99 |
Molecule* SimInfo::beginMolecule(std::vector<Molecule*>::iterator& i) { |
100 |
i = molecules_.begin(); |
101 |
return i == molecules_.end() ? NULL : *i; |
102 |
} |
103 |
|
104 |
Molecule* SimInfo::nextMolecule(std::vector<Molecule*>::iterator& i) { |
105 |
++i; |
106 |
return i == molecules_.end() ? NULL : *i; |
107 |
} |
108 |
|
109 |
|
110 |
void SimInfo::calcNdf() { |
111 |
int ndf_local; |
112 |
std::vector<Molecule*>::iterator i; |
113 |
std::vector<StuntDouble*>::iterator j; |
114 |
Molecule* mol; |
115 |
StuntDouble* integrableObject; |
116 |
|
117 |
ndf_local = 0; |
118 |
|
119 |
for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
120 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
121 |
integrableObject = mol->nextIntegrableObject(j)) { |
122 |
|
123 |
ndf_local += 3; |
124 |
|
125 |
if (integrableObject->isDirectional()) { |
126 |
if (integrableObject->isLinear()) { |
127 |
ndf_local += 2; |
128 |
} else { |
129 |
ndf_local += 3; |
130 |
} |
131 |
} |
132 |
|
133 |
}//end for (integrableObject) |
134 |
}// end for (mol) |
135 |
|
136 |
// n_constraints is local, so subtract them on each processor |
137 |
ndf_local -= nConstraints_; |
138 |
|
139 |
#ifdef IS_MPI |
140 |
MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
141 |
#else |
142 |
ndf_ = ndf_local; |
143 |
#endif |
144 |
|
145 |
// nZconstraints is global, as are the 3 COM translations for the |
146 |
// entire system: |
147 |
ndf_ = ndf_ - 3 - nZconstraints; |
148 |
|
149 |
} |
150 |
|
151 |
void SimInfo::calcNdfRaw() { |
152 |
int ndfRaw_local; |
153 |
|
154 |
std::vector<Molecule*>::iterator i; |
155 |
std::vector<StuntDouble*>::iterator j; |
156 |
Molecule* mol; |
157 |
StuntDouble* integrableObject; |
158 |
|
159 |
// Raw degrees of freedom that we have to set |
160 |
ndfRaw_local = 0; |
161 |
|
162 |
for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
163 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
164 |
integrableObject = mol->nextIntegrableObject(j)) { |
165 |
|
166 |
ndfRaw_local += 3; |
167 |
|
168 |
if (integrableObject->isDirectional()) { |
169 |
if (integrableObject->isLinear()) { |
170 |
ndfRaw_local += 2; |
171 |
} else { |
172 |
ndfRaw_local += 3; |
173 |
} |
174 |
} |
175 |
|
176 |
} |
177 |
} |
178 |
|
179 |
#ifdef IS_MPI |
180 |
MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
181 |
#else |
182 |
ndfRaw_ = ndfRaw_local; |
183 |
#endif |
184 |
} |
185 |
|
186 |
void SimInfo::calcNdfTrans() { |
187 |
int ndfTrans_local; |
188 |
|
189 |
ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; |
190 |
|
191 |
|
192 |
#ifdef IS_MPI |
193 |
MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
194 |
#else |
195 |
ndfTrans_ = ndfTrans_local; |
196 |
#endif |
197 |
|
198 |
ndfTrans_ = ndfTrans_ - 3 - nZconstraints; |
199 |
|
200 |
} |
201 |
|
202 |
void SimInfo::addExcludePairs(Molecule* mol) { |
203 |
std::vector<Bond*>::iterator bondIter; |
204 |
std::vector<Bend*>::iterator bendIter; |
205 |
std::vector<Torsion*>::iterator torsionIter; |
206 |
Bond* bond; |
207 |
Bend* bend; |
208 |
Torsion* torsion; |
209 |
int a; |
210 |
int b; |
211 |
int c; |
212 |
int d; |
213 |
|
214 |
for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { |
215 |
a = bond->getAtomA()->getGlobalIndex(); |
216 |
b = bond->getAtomB()->getGlobalIndex(); |
217 |
exclude_.addPair(a, b); |
218 |
} |
219 |
|
220 |
for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { |
221 |
a = bend->getAtomA()->getGlobalIndex(); |
222 |
b = bend->getAtomB()->getGlobalIndex(); |
223 |
c = bend->getAtomC()->getGlobalIndex(); |
224 |
|
225 |
exclude_.addPair(a, b); |
226 |
exclude_.addPair(a, c); |
227 |
exclude_.addPair(b, c); |
228 |
} |
229 |
|
230 |
for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextBond(torsionIter)) { |
231 |
a = torsion->getAtomA()->getGlobalIndex(); |
232 |
b = torsion->getAtomB()->getGlobalIndex(); |
233 |
c = torsion->getAtomC()->getGlobalIndex(); |
234 |
d = torsion->getAtomD()->getGlobalIndex(); |
235 |
|
236 |
exclude_.addPair(a, b); |
237 |
exclude_.addPair(a, c); |
238 |
exclude_.addPair(a, d); |
239 |
exclude_.addPair(b, c); |
240 |
exclude_.addPair(b, d); |
241 |
exclude_.addPair(c, d); |
242 |
} |
243 |
|
244 |
|
245 |
} |
246 |
|
247 |
void SimInfo::removeExcludePairs(Molecule* mol) { |
248 |
std::vector<Bond*>::iterator bondIter; |
249 |
std::vector<Bend*>::iterator bendIter; |
250 |
std::vector<Torsion*>::iterator torsionIter; |
251 |
Bond* bond; |
252 |
Bend* bend; |
253 |
Torsion* torsion; |
254 |
int a; |
255 |
int b; |
256 |
int c; |
257 |
int d; |
258 |
|
259 |
for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { |
260 |
a = bond->getAtomA()->getGlobalIndex(); |
261 |
b = bond->getAtomB()->getGlobalIndex(); |
262 |
exclude_.removePair(a, b); |
263 |
} |
264 |
|
265 |
for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { |
266 |
a = bend->getAtomA()->getGlobalIndex(); |
267 |
b = bend->getAtomB()->getGlobalIndex(); |
268 |
c = bend->getAtomC()->getGlobalIndex(); |
269 |
|
270 |
exclude_.removePair(a, b); |
271 |
exclude_.removePair(a, c); |
272 |
exclude_.removePair(b, c); |
273 |
} |
274 |
|
275 |
for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextBond(torsionIter)) { |
276 |
a = torsion->getAtomA()->getGlobalIndex(); |
277 |
b = torsion->getAtomB()->getGlobalIndex(); |
278 |
c = torsion->getAtomC()->getGlobalIndex(); |
279 |
d = torsion->getAtomD()->getGlobalIndex(); |
280 |
|
281 |
exclude_.removePair(a, b); |
282 |
exclude_.removePair(a, c); |
283 |
exclude_.removePair(a, d); |
284 |
exclude_.removePair(b, c); |
285 |
exclude_.removePair(b, d); |
286 |
exclude_.removePair(c, d); |
287 |
} |
288 |
|
289 |
} |
290 |
|
291 |
|
292 |
void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) { |
293 |
int curStampId; |
294 |
|
295 |
//index from 0 |
296 |
curStampId = molStampIds_.size(); |
297 |
|
298 |
moleculeStamps_.push_back(molStamp); |
299 |
molStampIds_.insert(molStampIds_.end(), nmol, curStampId) |
300 |
} |
301 |
|
302 |
std::ostream& operator <<(ostream& o, SimInfo& info) { |
303 |
|
304 |
return o; |
305 |
} |
306 |
|
307 |
}//end namespace oopse |