# | Line 1 | Line 1 | |
---|---|---|
1 | < | /* |
1 | > | /* |
2 | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | |
3 | * | |
4 | * The University of Notre Dame grants you ("Licensee") a | |
# | Line 48 | Line 48 | |
48 | ||
49 | #include <algorithm> | |
50 | #include <set> | |
51 | + | #include <map> |
52 | ||
53 | #include "brains/SimInfo.hpp" | |
54 | #include "math/Vector3.hpp" | |
55 | #include "primitives/Molecule.hpp" | |
56 | + | #include "UseTheForce/fCutoffPolicy.h" |
57 | + | #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h" |
58 | + | #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h" |
59 | + | #include "UseTheForce/DarkSide/fSwitchingFunctionType.h" |
60 | #include "UseTheForce/doForces_interface.h" | |
61 | < | #include "UseTheForce/notifyCutoffs_interface.h" |
61 | > | #include "UseTheForce/DarkSide/electrostatic_interface.h" |
62 | > | #include "UseTheForce/DarkSide/switcheroo_interface.h" |
63 | #include "utils/MemoryUtils.hpp" | |
64 | #include "utils/simError.h" | |
65 | #include "selection/SelectionManager.hpp" | |
66 | + | #include "io/ForceFieldOptions.hpp" |
67 | + | #include "UseTheForce/ForceField.hpp" |
68 | ||
69 | #ifdef IS_MPI | |
70 | #include "UseTheForce/mpiComponentPlan.h" | |
# | Line 64 | Line 72 | namespace oopse { | |
72 | #endif | |
73 | ||
74 | namespace oopse { | |
75 | + | std::set<int> getRigidSet(int index, std::map<int, std::set<int> >& container) { |
76 | + | std::map<int, std::set<int> >::iterator i = container.find(index); |
77 | + | std::set<int> result; |
78 | + | if (i != container.end()) { |
79 | + | result = i->second; |
80 | + | } |
81 | ||
82 | < | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs, |
83 | < | ForceField* ff, Globals* simParams) : |
84 | < | forceField_(ff), simParams_(simParams), |
85 | < | ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), |
86 | < | nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), |
87 | < | nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
88 | < | nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0), |
89 | < | nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), |
90 | < | sman_(NULL), fortranInitialized_(false), selectMan_(NULL) { |
82 | > | return result; |
83 | > | } |
84 | > | |
85 | > | SimInfo::SimInfo(ForceField* ff, Globals* simParams) : |
86 | > | forceField_(ff), simParams_(simParams), |
87 | > | ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), |
88 | > | nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), |
89 | > | nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
90 | > | nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0), |
91 | > | nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), |
92 | > | sman_(NULL), fortranInitialized_(false) { |
93 | ||
94 | < | |
95 | < | std::vector<std::pair<MoleculeStamp*, int> >::iterator i; |
96 | < | MoleculeStamp* molStamp; |
97 | < | int nMolWithSameStamp; |
98 | < | int nCutoffAtoms = 0; // number of atoms belong to cutoff groups |
99 | < | int nGroups = 0; //total cutoff groups defined in meta-data file |
100 | < | CutoffGroupStamp* cgStamp; |
101 | < | RigidBodyStamp* rbStamp; |
102 | < | int nRigidAtoms = 0; |
103 | < | |
104 | < | for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) { |
105 | < | molStamp = i->first; |
90 | < | nMolWithSameStamp = i->second; |
94 | > | MoleculeStamp* molStamp; |
95 | > | int nMolWithSameStamp; |
96 | > | int nCutoffAtoms = 0; // number of atoms belong to cutoff groups |
97 | > | int nGroups = 0; //total cutoff groups defined in meta-data file |
98 | > | CutoffGroupStamp* cgStamp; |
99 | > | RigidBodyStamp* rbStamp; |
100 | > | int nRigidAtoms = 0; |
101 | > | std::vector<Component*> components = simParams->getComponents(); |
102 | > | |
103 | > | for (std::vector<Component*>::iterator i = components.begin(); i !=components.end(); ++i) { |
104 | > | molStamp = (*i)->getMoleculeStamp(); |
105 | > | nMolWithSameStamp = (*i)->getNMol(); |
106 | ||
107 | addMoleculeStamp(molStamp, nMolWithSameStamp); | |
108 | ||
109 | //calculate atoms in molecules | |
110 | nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; | |
111 | ||
97 | – | |
112 | //calculate atoms in cutoff groups | |
113 | int nAtomsInGroups = 0; | |
114 | int nCutoffGroupsInStamp = molStamp->getNCutoffGroups(); | |
115 | ||
116 | for (int j=0; j < nCutoffGroupsInStamp; j++) { | |
117 | < | cgStamp = molStamp->getCutoffGroup(j); |
118 | < | nAtomsInGroups += cgStamp->getNMembers(); |
117 | > | cgStamp = molStamp->getCutoffGroupStamp(j); |
118 | > | nAtomsInGroups += cgStamp->getNMembers(); |
119 | } | |
120 | ||
121 | nGroups += nCutoffGroupsInStamp * nMolWithSameStamp; | |
122 | + | |
123 | nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp; | |
124 | ||
125 | //calculate atoms in rigid bodies | |
# | Line 112 | Line 127 | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, | |
127 | int nRigidBodiesInStamp = molStamp->getNRigidBodies(); | |
128 | ||
129 | for (int j=0; j < nRigidBodiesInStamp; j++) { | |
130 | < | rbStamp = molStamp->getRigidBody(j); |
131 | < | nAtomsInRigidBodies += rbStamp->getNMembers(); |
130 | > | rbStamp = molStamp->getRigidBodyStamp(j); |
131 | > | nAtomsInRigidBodies += rbStamp->getNMembers(); |
132 | } | |
133 | ||
134 | nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp; | |
135 | nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp; | |
136 | ||
137 | < | } |
137 | > | } |
138 | ||
139 | < | //every free atom (atom does not belong to cutoff groups) is a cutoff group |
140 | < | //therefore the total number of cutoff groups in the system is equal to |
141 | < | //the total number of atoms minus number of atoms belong to cutoff group defined in meta-data |
142 | < | //file plus the number of cutoff groups defined in meta-data file |
143 | < | nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; |
139 | > | //every free atom (atom does not belong to cutoff groups) is a cutoff |
140 | > | //group therefore the total number of cutoff groups in the system is |
141 | > | //equal to the total number of atoms minus number of atoms belong to |
142 | > | //cutoff group defined in meta-data file plus the number of cutoff |
143 | > | //groups defined in meta-data file |
144 | > | nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; |
145 | ||
146 | < | //every free atom (atom does not belong to rigid bodies) is an integrable object |
147 | < | //therefore the total number of integrable objects in the system is equal to |
148 | < | //the total number of atoms minus number of atoms belong to rigid body defined in meta-data |
149 | < | //file plus the number of rigid bodies defined in meta-data file |
150 | < | nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nGlobalRigidBodies_; |
146 | > | //every free atom (atom does not belong to rigid bodies) is an |
147 | > | //integrable object therefore the total number of integrable objects |
148 | > | //in the system is equal to the total number of atoms minus number of |
149 | > | //atoms belong to rigid body defined in meta-data file plus the number |
150 | > | //of rigid bodies defined in meta-data file |
151 | > | nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms |
152 | > | + nGlobalRigidBodies_; |
153 | > | |
154 | > | nGlobalMols_ = molStampIds_.size(); |
155 | ||
136 | – | nGlobalMols_ = molStampIds_.size(); |
137 | – | |
156 | #ifdef IS_MPI | |
157 | < | molToProcMap_.resize(nGlobalMols_); |
157 | > | molToProcMap_.resize(nGlobalMols_); |
158 | #endif | |
159 | ||
160 | < | selectMan_ = new SelectionManager(this); |
143 | < | selectMan_->selectAll(); |
144 | < | } |
160 | > | } |
161 | ||
162 | < | SimInfo::~SimInfo() { |
163 | < | //MemoryUtils::deleteVectorOfPointer(molecules_); |
164 | < | |
165 | < | MemoryUtils::deleteVectorOfPointer(moleculeStamps_); |
166 | < | |
162 | > | SimInfo::~SimInfo() { |
163 | > | std::map<int, Molecule*>::iterator i; |
164 | > | for (i = molecules_.begin(); i != molecules_.end(); ++i) { |
165 | > | delete i->second; |
166 | > | } |
167 | > | molecules_.clear(); |
168 | > | |
169 | delete sman_; | |
170 | delete simParams_; | |
171 | delete forceField_; | |
172 | < | delete selectMan_; |
155 | < | } |
172 | > | } |
173 | ||
174 | < | int SimInfo::getNGlobalConstraints() { |
174 | > | int SimInfo::getNGlobalConstraints() { |
175 | int nGlobalConstraints; | |
176 | #ifdef IS_MPI | |
177 | MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM, | |
# | Line 163 | Line 180 | int SimInfo::getNGlobalConstraints() { | |
180 | nGlobalConstraints = nConstraints_; | |
181 | #endif | |
182 | return nGlobalConstraints; | |
183 | < | } |
183 | > | } |
184 | ||
185 | < | bool SimInfo::addMolecule(Molecule* mol) { |
185 | > | bool SimInfo::addMolecule(Molecule* mol) { |
186 | MoleculeIterator i; | |
187 | ||
188 | i = molecules_.find(mol->getGlobalIndex()); | |
189 | if (i == molecules_.end() ) { | |
190 | ||
191 | < | molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol)); |
191 | > | molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol)); |
192 | ||
193 | < | nAtoms_ += mol->getNAtoms(); |
194 | < | nBonds_ += mol->getNBonds(); |
195 | < | nBends_ += mol->getNBends(); |
196 | < | nTorsions_ += mol->getNTorsions(); |
197 | < | nRigidBodies_ += mol->getNRigidBodies(); |
198 | < | nIntegrableObjects_ += mol->getNIntegrableObjects(); |
199 | < | nCutoffGroups_ += mol->getNCutoffGroups(); |
200 | < | nConstraints_ += mol->getNConstraintPairs(); |
193 | > | nAtoms_ += mol->getNAtoms(); |
194 | > | nBonds_ += mol->getNBonds(); |
195 | > | nBends_ += mol->getNBends(); |
196 | > | nTorsions_ += mol->getNTorsions(); |
197 | > | nRigidBodies_ += mol->getNRigidBodies(); |
198 | > | nIntegrableObjects_ += mol->getNIntegrableObjects(); |
199 | > | nCutoffGroups_ += mol->getNCutoffGroups(); |
200 | > | nConstraints_ += mol->getNConstraintPairs(); |
201 | ||
202 | < | addExcludePairs(mol); |
202 | > | addExcludePairs(mol); |
203 | ||
204 | < | return true; |
204 | > | return true; |
205 | } else { | |
206 | < | return false; |
206 | > | return false; |
207 | } | |
208 | < | } |
208 | > | } |
209 | ||
210 | < | bool SimInfo::removeMolecule(Molecule* mol) { |
210 | > | bool SimInfo::removeMolecule(Molecule* mol) { |
211 | MoleculeIterator i; | |
212 | i = molecules_.find(mol->getGlobalIndex()); | |
213 | ||
214 | if (i != molecules_.end() ) { | |
215 | ||
216 | < | assert(mol == i->second); |
216 | > | assert(mol == i->second); |
217 | ||
218 | < | nAtoms_ -= mol->getNAtoms(); |
219 | < | nBonds_ -= mol->getNBonds(); |
220 | < | nBends_ -= mol->getNBends(); |
221 | < | nTorsions_ -= mol->getNTorsions(); |
222 | < | nRigidBodies_ -= mol->getNRigidBodies(); |
223 | < | nIntegrableObjects_ -= mol->getNIntegrableObjects(); |
224 | < | nCutoffGroups_ -= mol->getNCutoffGroups(); |
225 | < | nConstraints_ -= mol->getNConstraintPairs(); |
226 | < | |
227 | < | removeExcludePairs(mol); |
228 | < | molecules_.erase(mol->getGlobalIndex()); |
229 | < | |
230 | < | delete mol; |
231 | < | |
232 | < | return true; |
218 | > | nAtoms_ -= mol->getNAtoms(); |
219 | > | nBonds_ -= mol->getNBonds(); |
220 | > | nBends_ -= mol->getNBends(); |
221 | > | nTorsions_ -= mol->getNTorsions(); |
222 | > | nRigidBodies_ -= mol->getNRigidBodies(); |
223 | > | nIntegrableObjects_ -= mol->getNIntegrableObjects(); |
224 | > | nCutoffGroups_ -= mol->getNCutoffGroups(); |
225 | > | nConstraints_ -= mol->getNConstraintPairs(); |
226 | > | |
227 | > | removeExcludePairs(mol); |
228 | > | molecules_.erase(mol->getGlobalIndex()); |
229 | > | |
230 | > | delete mol; |
231 | > | |
232 | > | return true; |
233 | } else { | |
234 | < | return false; |
234 | > | return false; |
235 | } | |
236 | ||
237 | ||
238 | < | } |
238 | > | } |
239 | ||
240 | ||
241 | < | Molecule* SimInfo::beginMolecule(MoleculeIterator& i) { |
241 | > | Molecule* SimInfo::beginMolecule(MoleculeIterator& i) { |
242 | i = molecules_.begin(); | |
243 | return i == molecules_.end() ? NULL : i->second; | |
244 | < | } |
244 | > | } |
245 | ||
246 | < | Molecule* SimInfo::nextMolecule(MoleculeIterator& i) { |
246 | > | Molecule* SimInfo::nextMolecule(MoleculeIterator& i) { |
247 | ++i; | |
248 | return i == molecules_.end() ? NULL : i->second; | |
249 | < | } |
249 | > | } |
250 | ||
251 | ||
252 | < | void SimInfo::calcNdf() { |
252 | > | void SimInfo::calcNdf() { |
253 | int ndf_local; | |
254 | MoleculeIterator i; | |
255 | std::vector<StuntDouble*>::iterator j; | |
# | Line 242 | Line 259 | void SimInfo::calcNdf() { | |
259 | ndf_local = 0; | |
260 | ||
261 | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | |
262 | < | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
263 | < | integrableObject = mol->nextIntegrableObject(j)) { |
262 | > | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
263 | > | integrableObject = mol->nextIntegrableObject(j)) { |
264 | ||
265 | < | ndf_local += 3; |
265 | > | ndf_local += 3; |
266 | ||
267 | < | if (integrableObject->isDirectional()) { |
268 | < | if (integrableObject->isLinear()) { |
269 | < | ndf_local += 2; |
270 | < | } else { |
271 | < | ndf_local += 3; |
272 | < | } |
273 | < | } |
267 | > | if (integrableObject->isDirectional()) { |
268 | > | if (integrableObject->isLinear()) { |
269 | > | ndf_local += 2; |
270 | > | } else { |
271 | > | ndf_local += 3; |
272 | > | } |
273 | > | } |
274 | ||
275 | < | }//end for (integrableObject) |
276 | < | }// end for (mol) |
275 | > | } |
276 | > | } |
277 | ||
278 | // n_constraints is local, so subtract them on each processor | |
279 | ndf_local -= nConstraints_; | |
# | Line 271 | Line 288 | void SimInfo::calcNdf() { | |
288 | // entire system: | |
289 | ndf_ = ndf_ - 3 - nZconstraint_; | |
290 | ||
291 | < | } |
291 | > | } |
292 | ||
293 | < | void SimInfo::calcNdfRaw() { |
293 | > | int SimInfo::getFdf() { |
294 | > | #ifdef IS_MPI |
295 | > | MPI_Allreduce(&fdf_local,&fdf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
296 | > | #else |
297 | > | fdf_ = fdf_local; |
298 | > | #endif |
299 | > | return fdf_; |
300 | > | } |
301 | > | |
302 | > | void SimInfo::calcNdfRaw() { |
303 | int ndfRaw_local; | |
304 | ||
305 | MoleculeIterator i; | |
# | Line 285 | Line 311 | void SimInfo::calcNdfRaw() { | |
311 | ndfRaw_local = 0; | |
312 | ||
313 | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | |
314 | < | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
315 | < | integrableObject = mol->nextIntegrableObject(j)) { |
314 | > | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
315 | > | integrableObject = mol->nextIntegrableObject(j)) { |
316 | ||
317 | < | ndfRaw_local += 3; |
317 | > | ndfRaw_local += 3; |
318 | ||
319 | < | if (integrableObject->isDirectional()) { |
320 | < | if (integrableObject->isLinear()) { |
321 | < | ndfRaw_local += 2; |
322 | < | } else { |
323 | < | ndfRaw_local += 3; |
324 | < | } |
325 | < | } |
319 | > | if (integrableObject->isDirectional()) { |
320 | > | if (integrableObject->isLinear()) { |
321 | > | ndfRaw_local += 2; |
322 | > | } else { |
323 | > | ndfRaw_local += 3; |
324 | > | } |
325 | > | } |
326 | ||
327 | < | } |
327 | > | } |
328 | } | |
329 | ||
330 | #ifdef IS_MPI | |
# | Line 306 | Line 332 | void SimInfo::calcNdfRaw() { | |
332 | #else | |
333 | ndfRaw_ = ndfRaw_local; | |
334 | #endif | |
335 | < | } |
335 | > | } |
336 | ||
337 | < | void SimInfo::calcNdfTrans() { |
337 | > | void SimInfo::calcNdfTrans() { |
338 | int ndfTrans_local; | |
339 | ||
340 | ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; | |
# | Line 322 | Line 348 | void SimInfo::calcNdfTrans() { | |
348 | ||
349 | ndfTrans_ = ndfTrans_ - 3 - nZconstraint_; | |
350 | ||
351 | < | } |
351 | > | } |
352 | ||
353 | < | void SimInfo::addExcludePairs(Molecule* mol) { |
353 | > | void SimInfo::addExcludePairs(Molecule* mol) { |
354 | std::vector<Bond*>::iterator bondIter; | |
355 | std::vector<Bend*>::iterator bendIter; | |
356 | std::vector<Torsion*>::iterator torsionIter; | |
# | Line 335 | Line 361 | void SimInfo::addExcludePairs(Molecule* mol) { | |
361 | int b; | |
362 | int c; | |
363 | int d; | |
364 | + | |
365 | + | std::map<int, std::set<int> > atomGroups; |
366 | + | |
367 | + | Molecule::RigidBodyIterator rbIter; |
368 | + | RigidBody* rb; |
369 | + | Molecule::IntegrableObjectIterator ii; |
370 | + | StuntDouble* integrableObject; |
371 | ||
372 | + | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
373 | + | integrableObject = mol->nextIntegrableObject(ii)) { |
374 | + | |
375 | + | if (integrableObject->isRigidBody()) { |
376 | + | rb = static_cast<RigidBody*>(integrableObject); |
377 | + | std::vector<Atom*> atoms = rb->getAtoms(); |
378 | + | std::set<int> rigidAtoms; |
379 | + | for (int i = 0; i < atoms.size(); ++i) { |
380 | + | rigidAtoms.insert(atoms[i]->getGlobalIndex()); |
381 | + | } |
382 | + | for (int i = 0; i < atoms.size(); ++i) { |
383 | + | atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); |
384 | + | } |
385 | + | } else { |
386 | + | std::set<int> oneAtomSet; |
387 | + | oneAtomSet.insert(integrableObject->getGlobalIndex()); |
388 | + | atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); |
389 | + | } |
390 | + | } |
391 | + | |
392 | + | |
393 | + | |
394 | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | |
395 | < | a = bond->getAtomA()->getGlobalIndex(); |
396 | < | b = bond->getAtomB()->getGlobalIndex(); |
397 | < | exclude_.addPair(a, b); |
395 | > | a = bond->getAtomA()->getGlobalIndex(); |
396 | > | b = bond->getAtomB()->getGlobalIndex(); |
397 | > | exclude_.addPair(a, b); |
398 | } | |
399 | ||
400 | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | |
401 | < | a = bend->getAtomA()->getGlobalIndex(); |
402 | < | b = bend->getAtomB()->getGlobalIndex(); |
403 | < | c = bend->getAtomC()->getGlobalIndex(); |
401 | > | a = bend->getAtomA()->getGlobalIndex(); |
402 | > | b = bend->getAtomB()->getGlobalIndex(); |
403 | > | c = bend->getAtomC()->getGlobalIndex(); |
404 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
405 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
406 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
407 | ||
408 | < | exclude_.addPair(a, b); |
409 | < | exclude_.addPair(a, c); |
410 | < | exclude_.addPair(b, c); |
408 | > | exclude_.addPairs(rigidSetA, rigidSetB); |
409 | > | exclude_.addPairs(rigidSetA, rigidSetC); |
410 | > | exclude_.addPairs(rigidSetB, rigidSetC); |
411 | > | |
412 | > | //exclude_.addPair(a, b); |
413 | > | //exclude_.addPair(a, c); |
414 | > | //exclude_.addPair(b, c); |
415 | } | |
416 | ||
417 | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | |
418 | < | a = torsion->getAtomA()->getGlobalIndex(); |
419 | < | b = torsion->getAtomB()->getGlobalIndex(); |
420 | < | c = torsion->getAtomC()->getGlobalIndex(); |
421 | < | d = torsion->getAtomD()->getGlobalIndex(); |
418 | > | a = torsion->getAtomA()->getGlobalIndex(); |
419 | > | b = torsion->getAtomB()->getGlobalIndex(); |
420 | > | c = torsion->getAtomC()->getGlobalIndex(); |
421 | > | d = torsion->getAtomD()->getGlobalIndex(); |
422 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
423 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
424 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
425 | > | std::set<int> rigidSetD = getRigidSet(d, atomGroups); |
426 | ||
427 | < | exclude_.addPair(a, b); |
428 | < | exclude_.addPair(a, c); |
429 | < | exclude_.addPair(a, d); |
430 | < | exclude_.addPair(b, c); |
431 | < | exclude_.addPair(b, d); |
432 | < | exclude_.addPair(c, d); |
427 | > | exclude_.addPairs(rigidSetA, rigidSetB); |
428 | > | exclude_.addPairs(rigidSetA, rigidSetC); |
429 | > | exclude_.addPairs(rigidSetA, rigidSetD); |
430 | > | exclude_.addPairs(rigidSetB, rigidSetC); |
431 | > | exclude_.addPairs(rigidSetB, rigidSetD); |
432 | > | exclude_.addPairs(rigidSetC, rigidSetD); |
433 | > | |
434 | > | /* |
435 | > | exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetB.begin(), rigidSetB.end()); |
436 | > | exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetC.begin(), rigidSetC.end()); |
437 | > | exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetD.begin(), rigidSetD.end()); |
438 | > | exclude_.addPairs(rigidSetB.begin(), rigidSetB.end(), rigidSetC.begin(), rigidSetC.end()); |
439 | > | exclude_.addPairs(rigidSetB.begin(), rigidSetB.end(), rigidSetD.begin(), rigidSetD.end()); |
440 | > | exclude_.addPairs(rigidSetC.begin(), rigidSetC.end(), rigidSetD.begin(), rigidSetD.end()); |
441 | > | |
442 | > | |
443 | > | exclude_.addPair(a, b); |
444 | > | exclude_.addPair(a, c); |
445 | > | exclude_.addPair(a, d); |
446 | > | exclude_.addPair(b, c); |
447 | > | exclude_.addPair(b, d); |
448 | > | exclude_.addPair(c, d); |
449 | > | */ |
450 | } | |
451 | ||
452 | < | |
453 | < | } |
452 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
453 | > | std::vector<Atom*> atoms = rb->getAtoms(); |
454 | > | for (int i = 0; i < atoms.size() -1 ; ++i) { |
455 | > | for (int j = i + 1; j < atoms.size(); ++j) { |
456 | > | a = atoms[i]->getGlobalIndex(); |
457 | > | b = atoms[j]->getGlobalIndex(); |
458 | > | exclude_.addPair(a, b); |
459 | > | } |
460 | > | } |
461 | > | } |
462 | ||
463 | < | void SimInfo::removeExcludePairs(Molecule* mol) { |
463 | > | } |
464 | > | |
465 | > | void SimInfo::removeExcludePairs(Molecule* mol) { |
466 | std::vector<Bond*>::iterator bondIter; | |
467 | std::vector<Bend*>::iterator bendIter; | |
468 | std::vector<Torsion*>::iterator torsionIter; | |
# | Line 380 | Line 473 | void SimInfo::removeExcludePairs(Molecule* mol) { | |
473 | int b; | |
474 | int c; | |
475 | int d; | |
476 | + | |
477 | + | std::map<int, std::set<int> > atomGroups; |
478 | + | |
479 | + | Molecule::RigidBodyIterator rbIter; |
480 | + | RigidBody* rb; |
481 | + | Molecule::IntegrableObjectIterator ii; |
482 | + | StuntDouble* integrableObject; |
483 | ||
484 | + | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
485 | + | integrableObject = mol->nextIntegrableObject(ii)) { |
486 | + | |
487 | + | if (integrableObject->isRigidBody()) { |
488 | + | rb = static_cast<RigidBody*>(integrableObject); |
489 | + | std::vector<Atom*> atoms = rb->getAtoms(); |
490 | + | std::set<int> rigidAtoms; |
491 | + | for (int i = 0; i < atoms.size(); ++i) { |
492 | + | rigidAtoms.insert(atoms[i]->getGlobalIndex()); |
493 | + | } |
494 | + | for (int i = 0; i < atoms.size(); ++i) { |
495 | + | atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); |
496 | + | } |
497 | + | } else { |
498 | + | std::set<int> oneAtomSet; |
499 | + | oneAtomSet.insert(integrableObject->getGlobalIndex()); |
500 | + | atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); |
501 | + | } |
502 | + | } |
503 | + | |
504 | + | |
505 | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | |
506 | < | a = bond->getAtomA()->getGlobalIndex(); |
507 | < | b = bond->getAtomB()->getGlobalIndex(); |
508 | < | exclude_.removePair(a, b); |
506 | > | a = bond->getAtomA()->getGlobalIndex(); |
507 | > | b = bond->getAtomB()->getGlobalIndex(); |
508 | > | exclude_.removePair(a, b); |
509 | } | |
510 | ||
511 | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | |
512 | < | a = bend->getAtomA()->getGlobalIndex(); |
513 | < | b = bend->getAtomB()->getGlobalIndex(); |
514 | < | c = bend->getAtomC()->getGlobalIndex(); |
512 | > | a = bend->getAtomA()->getGlobalIndex(); |
513 | > | b = bend->getAtomB()->getGlobalIndex(); |
514 | > | c = bend->getAtomC()->getGlobalIndex(); |
515 | ||
516 | < | exclude_.removePair(a, b); |
517 | < | exclude_.removePair(a, c); |
518 | < | exclude_.removePair(b, c); |
516 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
517 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
518 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
519 | > | |
520 | > | exclude_.removePairs(rigidSetA, rigidSetB); |
521 | > | exclude_.removePairs(rigidSetA, rigidSetC); |
522 | > | exclude_.removePairs(rigidSetB, rigidSetC); |
523 | > | |
524 | > | //exclude_.removePair(a, b); |
525 | > | //exclude_.removePair(a, c); |
526 | > | //exclude_.removePair(b, c); |
527 | } | |
528 | ||
529 | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | |
530 | < | a = torsion->getAtomA()->getGlobalIndex(); |
531 | < | b = torsion->getAtomB()->getGlobalIndex(); |
532 | < | c = torsion->getAtomC()->getGlobalIndex(); |
533 | < | d = torsion->getAtomD()->getGlobalIndex(); |
530 | > | a = torsion->getAtomA()->getGlobalIndex(); |
531 | > | b = torsion->getAtomB()->getGlobalIndex(); |
532 | > | c = torsion->getAtomC()->getGlobalIndex(); |
533 | > | d = torsion->getAtomD()->getGlobalIndex(); |
534 | ||
535 | < | exclude_.removePair(a, b); |
536 | < | exclude_.removePair(a, c); |
537 | < | exclude_.removePair(a, d); |
538 | < | exclude_.removePair(b, c); |
539 | < | exclude_.removePair(b, d); |
540 | < | exclude_.removePair(c, d); |
535 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
536 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
537 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
538 | > | std::set<int> rigidSetD = getRigidSet(d, atomGroups); |
539 | > | |
540 | > | exclude_.removePairs(rigidSetA, rigidSetB); |
541 | > | exclude_.removePairs(rigidSetA, rigidSetC); |
542 | > | exclude_.removePairs(rigidSetA, rigidSetD); |
543 | > | exclude_.removePairs(rigidSetB, rigidSetC); |
544 | > | exclude_.removePairs(rigidSetB, rigidSetD); |
545 | > | exclude_.removePairs(rigidSetC, rigidSetD); |
546 | > | |
547 | > | /* |
548 | > | exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetB.begin(), rigidSetB.end()); |
549 | > | exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetC.begin(), rigidSetC.end()); |
550 | > | exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetD.begin(), rigidSetD.end()); |
551 | > | exclude_.removePairs(rigidSetB.begin(), rigidSetB.end(), rigidSetC.begin(), rigidSetC.end()); |
552 | > | exclude_.removePairs(rigidSetB.begin(), rigidSetB.end(), rigidSetD.begin(), rigidSetD.end()); |
553 | > | exclude_.removePairs(rigidSetC.begin(), rigidSetC.end(), rigidSetD.begin(), rigidSetD.end()); |
554 | > | |
555 | > | |
556 | > | exclude_.removePair(a, b); |
557 | > | exclude_.removePair(a, c); |
558 | > | exclude_.removePair(a, d); |
559 | > | exclude_.removePair(b, c); |
560 | > | exclude_.removePair(b, d); |
561 | > | exclude_.removePair(c, d); |
562 | > | */ |
563 | } | |
564 | ||
565 | < | } |
565 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
566 | > | std::vector<Atom*> atoms = rb->getAtoms(); |
567 | > | for (int i = 0; i < atoms.size() -1 ; ++i) { |
568 | > | for (int j = i + 1; j < atoms.size(); ++j) { |
569 | > | a = atoms[i]->getGlobalIndex(); |
570 | > | b = atoms[j]->getGlobalIndex(); |
571 | > | exclude_.removePair(a, b); |
572 | > | } |
573 | > | } |
574 | > | } |
575 | ||
576 | + | } |
577 | ||
578 | < | void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) { |
578 | > | |
579 | > | void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) { |
580 | int curStampId; | |
581 | ||
582 | //index from 0 | |
# | Line 422 | Line 584 | void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp | |
584 | ||
585 | moleculeStamps_.push_back(molStamp); | |
586 | molStampIds_.insert(molStampIds_.end(), nmol, curStampId); | |
587 | < | } |
587 | > | } |
588 | ||
589 | < | void SimInfo::update() { |
589 | > | void SimInfo::update() { |
590 | ||
591 | setupSimType(); | |
592 | ||
# | Line 437 | Line 599 | void SimInfo::update() { | |
599 | //setup fortran force field | |
600 | /** @deprecate */ | |
601 | int isError = 0; | |
602 | < | initFortranFF( &fInfo_.SIM_uses_RF , &isError ); |
602 | > | |
603 | > | setupElectrostaticSummationMethod( isError ); |
604 | > | setupSwitchingFunction(); |
605 | > | |
606 | if(isError){ | |
607 | < | sprintf( painCave.errMsg, |
608 | < | "ForceField error: There was an error initializing the forceField in fortran.\n" ); |
609 | < | painCave.isFatal = 1; |
610 | < | simError(); |
607 | > | sprintf( painCave.errMsg, |
608 | > | "ForceField error: There was an error initializing the forceField in fortran.\n" ); |
609 | > | painCave.isFatal = 1; |
610 | > | simError(); |
611 | } | |
612 | ||
613 | ||
# | Line 453 | Line 618 | void SimInfo::update() { | |
618 | calcNdfTrans(); | |
619 | ||
620 | fortranInitialized_ = true; | |
621 | < | } |
621 | > | } |
622 | ||
623 | < | std::set<AtomType*> SimInfo::getUniqueAtomTypes() { |
623 | > | std::set<AtomType*> SimInfo::getUniqueAtomTypes() { |
624 | SimInfo::MoleculeIterator mi; | |
625 | Molecule* mol; | |
626 | Molecule::AtomIterator ai; | |
# | Line 464 | Line 629 | std::set<AtomType*> SimInfo::getUniqueAtomTypes() { | |
629 | ||
630 | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
631 | ||
632 | < | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
633 | < | atomTypes.insert(atom->getAtomType()); |
634 | < | } |
632 | > | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
633 | > | atomTypes.insert(atom->getAtomType()); |
634 | > | } |
635 | ||
636 | } | |
637 | ||
638 | return atomTypes; | |
639 | < | } |
639 | > | } |
640 | ||
641 | < | void SimInfo::setupSimType() { |
641 | > | void SimInfo::setupSimType() { |
642 | std::set<AtomType*>::iterator i; | |
643 | std::set<AtomType*> atomTypes; | |
644 | atomTypes = getUniqueAtomTypes(); | |
# | Line 481 | Line 646 | void SimInfo::setupSimType() { | |
646 | int useLennardJones = 0; | |
647 | int useElectrostatic = 0; | |
648 | int useEAM = 0; | |
649 | + | int useSC = 0; |
650 | int useCharge = 0; | |
651 | int useDirectional = 0; | |
652 | int useDipole = 0; | |
653 | int useGayBerne = 0; | |
654 | int useSticky = 0; | |
655 | + | int useStickyPower = 0; |
656 | int useShape = 0; | |
657 | int useFLARB = 0; //it is not in AtomType yet | |
658 | int useDirectionalAtom = 0; | |
659 | int useElectrostatics = 0; | |
660 | //usePBC and useRF are from simParams | |
661 | < | int usePBC = simParams_->getPBC(); |
662 | < | int useRF = simParams_->getUseRF(); |
661 | > | int usePBC = simParams_->getUsePeriodicBoundaryConditions(); |
662 | > | int useRF; |
663 | > | int useSF; |
664 | > | std::string myMethod; |
665 | ||
666 | + | // set the useRF logical |
667 | + | useRF = 0; |
668 | + | useSF = 0; |
669 | + | |
670 | + | |
671 | + | if (simParams_->haveElectrostaticSummationMethod()) { |
672 | + | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
673 | + | toUpper(myMethod); |
674 | + | if (myMethod == "REACTION_FIELD") { |
675 | + | useRF=1; |
676 | + | } else { |
677 | + | if (myMethod == "SHIFTED_FORCE") { |
678 | + | useSF = 1; |
679 | + | } |
680 | + | } |
681 | + | } |
682 | + | |
683 | //loop over all of the atom types | |
684 | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { | |
685 | < | useLennardJones |= (*i)->isLennardJones(); |
686 | < | useElectrostatic |= (*i)->isElectrostatic(); |
687 | < | useEAM |= (*i)->isEAM(); |
688 | < | useCharge |= (*i)->isCharge(); |
689 | < | useDirectional |= (*i)->isDirectional(); |
690 | < | useDipole |= (*i)->isDipole(); |
691 | < | useGayBerne |= (*i)->isGayBerne(); |
692 | < | useSticky |= (*i)->isSticky(); |
693 | < | useShape |= (*i)->isShape(); |
685 | > | useLennardJones |= (*i)->isLennardJones(); |
686 | > | useElectrostatic |= (*i)->isElectrostatic(); |
687 | > | useEAM |= (*i)->isEAM(); |
688 | > | useSC |= (*i)->isSC(); |
689 | > | useCharge |= (*i)->isCharge(); |
690 | > | useDirectional |= (*i)->isDirectional(); |
691 | > | useDipole |= (*i)->isDipole(); |
692 | > | useGayBerne |= (*i)->isGayBerne(); |
693 | > | useSticky |= (*i)->isSticky(); |
694 | > | useStickyPower |= (*i)->isStickyPower(); |
695 | > | useShape |= (*i)->isShape(); |
696 | } | |
697 | ||
698 | < | if (useSticky || useDipole || useGayBerne || useShape) { |
699 | < | useDirectionalAtom = 1; |
698 | > | if (useSticky || useStickyPower || useDipole || useGayBerne || useShape) { |
699 | > | useDirectionalAtom = 1; |
700 | } | |
701 | ||
702 | if (useCharge || useDipole) { | |
703 | < | useElectrostatics = 1; |
703 | > | useElectrostatics = 1; |
704 | } | |
705 | ||
706 | #ifdef IS_MPI | |
# | Line 539 | Line 727 | void SimInfo::setupSimType() { | |
727 | temp = useSticky; | |
728 | MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
729 | ||
730 | + | temp = useStickyPower; |
731 | + | MPI_Allreduce(&temp, &useStickyPower, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
732 | + | |
733 | temp = useGayBerne; | |
734 | MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
735 | ||
736 | temp = useEAM; | |
737 | MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
738 | ||
739 | + | temp = useSC; |
740 | + | MPI_Allreduce(&temp, &useSC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
741 | + | |
742 | temp = useShape; | |
743 | MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
744 | ||
# | Line 553 | Line 747 | void SimInfo::setupSimType() { | |
747 | ||
748 | temp = useRF; | |
749 | MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
750 | < | |
750 | > | |
751 | > | temp = useSF; |
752 | > | MPI_Allreduce(&temp, &useSF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
753 | > | |
754 | #endif | |
755 | ||
756 | fInfo_.SIM_uses_PBC = usePBC; | |
# | Line 563 | Line 760 | void SimInfo::setupSimType() { | |
760 | fInfo_.SIM_uses_Charges = useCharge; | |
761 | fInfo_.SIM_uses_Dipoles = useDipole; | |
762 | fInfo_.SIM_uses_Sticky = useSticky; | |
763 | + | fInfo_.SIM_uses_StickyPower = useStickyPower; |
764 | fInfo_.SIM_uses_GayBerne = useGayBerne; | |
765 | fInfo_.SIM_uses_EAM = useEAM; | |
766 | + | fInfo_.SIM_uses_SC = useSC; |
767 | fInfo_.SIM_uses_Shapes = useShape; | |
768 | fInfo_.SIM_uses_FLARB = useFLARB; | |
769 | fInfo_.SIM_uses_RF = useRF; | |
770 | + | fInfo_.SIM_uses_SF = useSF; |
771 | ||
772 | < | if( fInfo_.SIM_uses_Dipoles && fInfo_.SIM_uses_RF) { |
773 | < | |
774 | < | if (simParams_->haveDielectric()) { |
775 | < | fInfo_.dielect = simParams_->getDielectric(); |
776 | < | } else { |
777 | < | sprintf(painCave.errMsg, |
778 | < | "SimSetup Error: No Dielectric constant was set.\n" |
779 | < | "\tYou are trying to use Reaction Field without" |
780 | < | "\tsetting a dielectric constant!\n"); |
781 | < | painCave.isFatal = 1; |
782 | < | simError(); |
783 | < | } |
584 | < | |
585 | < | } else { |
586 | < | fInfo_.dielect = 0.0; |
772 | > | if( myMethod == "REACTION_FIELD") { |
773 | > | |
774 | > | if (simParams_->haveDielectric()) { |
775 | > | fInfo_.dielect = simParams_->getDielectric(); |
776 | > | } else { |
777 | > | sprintf(painCave.errMsg, |
778 | > | "SimSetup Error: No Dielectric constant was set.\n" |
779 | > | "\tYou are trying to use Reaction Field without" |
780 | > | "\tsetting a dielectric constant!\n"); |
781 | > | painCave.isFatal = 1; |
782 | > | simError(); |
783 | > | } |
784 | } | |
785 | ||
786 | < | } |
786 | > | } |
787 | ||
788 | < | void SimInfo::setupFortranSim() { |
788 | > | void SimInfo::setupFortranSim() { |
789 | int isError; | |
790 | int nExclude; | |
791 | std::vector<int> fortranGlobalGroupMembership; | |
# | Line 598 | Line 795 | void SimInfo::setupFortranSim() { | |
795 | ||
796 | //globalGroupMembership_ is filled by SimCreator | |
797 | for (int i = 0; i < nGlobalAtoms_; i++) { | |
798 | < | fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); |
798 | > | fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); |
799 | } | |
800 | ||
801 | //calculate mass ratio of cutoff group | |
# | Line 615 | Line 812 | void SimInfo::setupFortranSim() { | |
812 | mfact.reserve(getNCutoffGroups()); | |
813 | ||
814 | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
815 | < | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
815 | > | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
816 | ||
817 | < | totalMass = cg->getMass(); |
818 | < | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
819 | < | mfact.push_back(atom->getMass()/totalMass); |
820 | < | } |
817 | > | totalMass = cg->getMass(); |
818 | > | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
819 | > | // Check for massless groups - set mfact to 1 if true |
820 | > | if (totalMass != 0) |
821 | > | mfact.push_back(atom->getMass()/totalMass); |
822 | > | else |
823 | > | mfact.push_back( 1.0 ); |
824 | > | } |
825 | ||
826 | < | } |
826 | > | } |
827 | } | |
828 | ||
829 | //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) | |
# | Line 632 | Line 833 | void SimInfo::setupFortranSim() { | |
833 | identArray.reserve(getNAtoms()); | |
834 | ||
835 | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
836 | < | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
837 | < | identArray.push_back(atom->getIdent()); |
838 | < | } |
836 | > | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
837 | > | identArray.push_back(atom->getIdent()); |
838 | > | } |
839 | } | |
840 | ||
841 | //fill molMembershipArray | |
842 | //molMembershipArray is filled by SimCreator | |
843 | std::vector<int> molMembershipArray(nGlobalAtoms_); | |
844 | for (int i = 0; i < nGlobalAtoms_; i++) { | |
845 | < | molMembershipArray[i] = globalMolMembership_[i] + 1; |
845 | > | molMembershipArray[i] = globalMolMembership_[i] + 1; |
846 | } | |
847 | ||
848 | //setup fortran simulation | |
648 | – | //gloalExcludes and molMembershipArray should go away (They are never used) |
649 | – | //why the hell fortran need to know molecule? |
650 | – | //OOPSE = Object-Obfuscated Parallel Simulation Engine |
849 | int nGlobalExcludes = 0; | |
850 | int* globalExcludes = NULL; | |
851 | int* excludeList = exclude_.getExcludeList(); | |
852 | setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList , | |
853 | < | &nGlobalExcludes, globalExcludes, &molMembershipArray[0], |
854 | < | &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError); |
853 | > | &nGlobalExcludes, globalExcludes, &molMembershipArray[0], |
854 | > | &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError); |
855 | ||
856 | if( isError ){ | |
857 | ||
858 | < | sprintf( painCave.errMsg, |
859 | < | "There was an error setting the simulation information in fortran.\n" ); |
860 | < | painCave.isFatal = 1; |
861 | < | painCave.severity = OOPSE_ERROR; |
862 | < | simError(); |
858 | > | sprintf( painCave.errMsg, |
859 | > | "There was an error setting the simulation information in fortran.\n" ); |
860 | > | painCave.isFatal = 1; |
861 | > | painCave.severity = OOPSE_ERROR; |
862 | > | simError(); |
863 | } | |
864 | ||
865 | #ifdef IS_MPI | |
866 | sprintf( checkPointMsg, | |
867 | < | "succesfully sent the simulation information to fortran.\n"); |
867 | > | "succesfully sent the simulation information to fortran.\n"); |
868 | MPIcheckPoint(); | |
869 | #endif // is_mpi | |
870 | < | } |
870 | > | } |
871 | ||
872 | ||
873 | #ifdef IS_MPI | |
874 | < | void SimInfo::setupFortranParallel() { |
874 | > | void SimInfo::setupFortranParallel() { |
875 | ||
876 | //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex | |
877 | std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0); | |
# | Line 689 | Line 887 | void SimInfo::setupFortranParallel() { | |
887 | ||
888 | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
889 | ||
890 | < | //local index(index in DataStorge) of atom is important |
891 | < | for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
892 | < | localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; |
893 | < | } |
890 | > | //local index(index in DataStorge) of atom is important |
891 | > | for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
892 | > | localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; |
893 | > | } |
894 | ||
895 | < | //local index of cutoff group is trivial, it only depends on the order of travesing |
896 | < | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
897 | < | localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); |
898 | < | } |
895 | > | //local index of cutoff group is trivial, it only depends on the order of travesing |
896 | > | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
897 | > | localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); |
898 | > | } |
899 | ||
900 | } | |
901 | ||
# | Line 717 | Line 915 | void SimInfo::setupFortranParallel() { | |
915 | &localToGlobalCutoffGroupIndex[0], &isError); | |
916 | ||
917 | if (isError) { | |
918 | < | sprintf(painCave.errMsg, |
919 | < | "mpiRefresh errror: fortran didn't like something we gave it.\n"); |
920 | < | painCave.isFatal = 1; |
921 | < | simError(); |
918 | > | sprintf(painCave.errMsg, |
919 | > | "mpiRefresh errror: fortran didn't like something we gave it.\n"); |
920 | > | painCave.isFatal = 1; |
921 | > | simError(); |
922 | } | |
923 | ||
924 | sprintf(checkPointMsg, " mpiRefresh successful.\n"); | |
925 | MPIcheckPoint(); | |
926 | ||
927 | ||
928 | < | } |
928 | > | } |
929 | ||
930 | #endif | |
931 | ||
932 | < | double SimInfo::calcMaxCutoffRadius() { |
932 | > | void SimInfo::setupCutoff() { |
933 | > | |
934 | > | ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions(); |
935 | ||
936 | + | // Check the cutoff policy |
937 | + | int cp = TRADITIONAL_CUTOFF_POLICY; // Set to traditional by default |
938 | ||
939 | < | std::set<AtomType*> atomTypes; |
940 | < | std::set<AtomType*>::iterator i; |
941 | < | std::vector<double> cutoffRadius; |
942 | < | |
943 | < | //get the unique atom types |
742 | < | atomTypes = getUniqueAtomTypes(); |
743 | < | |
744 | < | //query the max cutoff radius among these atom types |
745 | < | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
746 | < | cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i)); |
939 | > | std::string myPolicy; |
940 | > | if (forceFieldOptions_.haveCutoffPolicy()){ |
941 | > | myPolicy = forceFieldOptions_.getCutoffPolicy(); |
942 | > | }else if (simParams_->haveCutoffPolicy()) { |
943 | > | myPolicy = simParams_->getCutoffPolicy(); |
944 | } | |
945 | ||
946 | < | double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end())); |
947 | < | #ifdef IS_MPI |
948 | < | //pick the max cutoff radius among the processors |
949 | < | #endif |
946 | > | if (!myPolicy.empty()){ |
947 | > | toUpper(myPolicy); |
948 | > | if (myPolicy == "MIX") { |
949 | > | cp = MIX_CUTOFF_POLICY; |
950 | > | } else { |
951 | > | if (myPolicy == "MAX") { |
952 | > | cp = MAX_CUTOFF_POLICY; |
953 | > | } else { |
954 | > | if (myPolicy == "TRADITIONAL") { |
955 | > | cp = TRADITIONAL_CUTOFF_POLICY; |
956 | > | } else { |
957 | > | // throw error |
958 | > | sprintf( painCave.errMsg, |
959 | > | "SimInfo error: Unknown cutoffPolicy. (Input file specified %s .)\n\tcutoffPolicy must be one of: \"Mix\", \"Max\", or \"Traditional\".", myPolicy.c_str() ); |
960 | > | painCave.isFatal = 1; |
961 | > | simError(); |
962 | > | } |
963 | > | } |
964 | > | } |
965 | > | } |
966 | > | notifyFortranCutoffPolicy(&cp); |
967 | ||
968 | < | return maxCutoffRadius; |
969 | < | } |
970 | < | |
971 | < | void SimInfo::getCutoff(double& rcut, double& rsw) { |
972 | < | |
973 | < | if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { |
968 | > | // Check the Skin Thickness for neighborlists |
969 | > | double skin; |
970 | > | if (simParams_->haveSkinThickness()) { |
971 | > | skin = simParams_->getSkinThickness(); |
972 | > | notifyFortranSkinThickness(&skin); |
973 | > | } |
974 | ||
975 | < | if (!simParams_->haveRcut()){ |
976 | < | sprintf(painCave.errMsg, |
975 | > | // Check if the cutoff was set explicitly: |
976 | > | if (simParams_->haveCutoffRadius()) { |
977 | > | rcut_ = simParams_->getCutoffRadius(); |
978 | > | if (simParams_->haveSwitchingRadius()) { |
979 | > | rsw_ = simParams_->getSwitchingRadius(); |
980 | > | } else { |
981 | > | if (fInfo_.SIM_uses_Charges | |
982 | > | fInfo_.SIM_uses_Dipoles | |
983 | > | fInfo_.SIM_uses_RF) { |
984 | > | |
985 | > | rsw_ = 0.85 * rcut_; |
986 | > | sprintf(painCave.errMsg, |
987 | > | "SimCreator Warning: No value was set for the switchingRadius.\n" |
988 | > | "\tOOPSE will use a default value of 85 percent of the cutoffRadius.\n" |
989 | > | "\tswitchingRadius = %f. for this simulation\n", rsw_); |
990 | > | painCave.isFatal = 0; |
991 | > | simError(); |
992 | > | } else { |
993 | > | rsw_ = rcut_; |
994 | > | sprintf(painCave.errMsg, |
995 | > | "SimCreator Warning: No value was set for the switchingRadius.\n" |
996 | > | "\tOOPSE will use the same value as the cutoffRadius.\n" |
997 | > | "\tswitchingRadius = %f. for this simulation\n", rsw_); |
998 | > | painCave.isFatal = 0; |
999 | > | simError(); |
1000 | > | } |
1001 | > | } |
1002 | > | |
1003 | > | notifyFortranCutoffs(&rcut_, &rsw_); |
1004 | > | |
1005 | > | } else { |
1006 | > | |
1007 | > | // For electrostatic atoms, we'll assume a large safe value: |
1008 | > | if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { |
1009 | > | sprintf(painCave.errMsg, |
1010 | "SimCreator Warning: No value was set for the cutoffRadius.\n" | |
1011 | "\tOOPSE will use a default value of 15.0 angstroms" | |
1012 | "\tfor the cutoffRadius.\n"); | |
1013 | < | painCave.isFatal = 0; |
1014 | < | simError(); |
1015 | < | rcut = 15.0; |
1016 | < | } else{ |
1017 | < | rcut = simParams_->getRcut(); |
1013 | > | painCave.isFatal = 0; |
1014 | > | simError(); |
1015 | > | rcut_ = 15.0; |
1016 | > | |
1017 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
1018 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
1019 | > | toUpper(myMethod); |
1020 | > | if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") { |
1021 | > | if (simParams_->haveSwitchingRadius()){ |
1022 | > | sprintf(painCave.errMsg, |
1023 | > | "SimInfo Warning: A value was set for the switchingRadius\n" |
1024 | > | "\teven though the electrostaticSummationMethod was\n" |
1025 | > | "\tset to %s\n", myMethod.c_str()); |
1026 | > | painCave.isFatal = 1; |
1027 | > | simError(); |
1028 | > | } |
1029 | > | } |
1030 | } | |
1031 | < | |
1032 | < | if (!simParams_->haveRsw()){ |
1033 | < | sprintf(painCave.errMsg, |
1034 | < | "SimCreator Warning: No value was set for switchingRadius.\n" |
1035 | < | "\tOOPSE will use a default value of\n" |
1036 | < | "\t0.95 * cutoffRadius for the switchingRadius\n"); |
1037 | < | painCave.isFatal = 0; |
1038 | < | simError(); |
1039 | < | rsw = 0.95 * rcut; |
1040 | < | } else{ |
1041 | < | rsw = simParams_->getRsw(); |
1031 | > | |
1032 | > | if (simParams_->haveSwitchingRadius()){ |
1033 | > | rsw_ = simParams_->getSwitchingRadius(); |
1034 | > | } else { |
1035 | > | sprintf(painCave.errMsg, |
1036 | > | "SimCreator Warning: No value was set for switchingRadius.\n" |
1037 | > | "\tOOPSE will use a default value of\n" |
1038 | > | "\t0.85 * cutoffRadius for the switchingRadius\n"); |
1039 | > | painCave.isFatal = 0; |
1040 | > | simError(); |
1041 | > | rsw_ = 0.85 * rcut_; |
1042 | } | |
1043 | < | |
1044 | < | } else { |
1045 | < | // if charge, dipole or reaction field is not used and the cutofff radius is not specified in |
1046 | < | //meta-data file, the maximum cutoff radius calculated from forcefiled will be used |
1043 | > | notifyFortranCutoffs(&rcut_, &rsw_); |
1044 | > | } else { |
1045 | > | // We didn't set rcut explicitly, and we don't have electrostatic atoms, so |
1046 | > | // We'll punt and let fortran figure out the cutoffs later. |
1047 | ||
1048 | < | if (simParams_->haveRcut()) { |
790 | < | rcut = simParams_->getRcut(); |
791 | < | } else { |
792 | < | //set cutoff radius to the maximum cutoff radius based on atom types in the whole system |
793 | < | rcut = calcMaxCutoffRadius(); |
794 | < | } |
1048 | > | notifyFortranYouAreOnYourOwn(); |
1049 | ||
1050 | < | if (simParams_->haveRsw()) { |
797 | < | rsw = simParams_->getRsw(); |
798 | < | } else { |
799 | < | rsw = rcut; |
800 | < | } |
801 | < | |
1050 | > | } |
1051 | } | |
1052 | < | } |
1052 | > | } |
1053 | ||
1054 | < | void SimInfo::setupCutoff() { |
1055 | < | getCutoff(rcut_, rsw_); |
1056 | < | double rnblist = rcut_ + 1; // skin of neighbor list |
1054 | > | void SimInfo::setupElectrostaticSummationMethod( int isError ) { |
1055 | > | |
1056 | > | int errorOut; |
1057 | > | int esm = NONE; |
1058 | > | int sm = UNDAMPED; |
1059 | > | double alphaVal; |
1060 | > | double dielectric; |
1061 | ||
1062 | < | //Pass these cutoff radius etc. to fortran. This function should be called once and only once |
1063 | < | notifyFortranCutoffs(&rcut_, &rsw_, &rnblist); |
1064 | < | } |
1062 | > | errorOut = isError; |
1063 | > | alphaVal = simParams_->getDampingAlpha(); |
1064 | > | dielectric = simParams_->getDielectric(); |
1065 | ||
1066 | < | void SimInfo::addProperty(GenericData* genData) { |
1067 | < | properties_.addProperty(genData); |
1068 | < | } |
1069 | < | |
1070 | < | void SimInfo::removeProperty(const std::string& propName) { |
1071 | < | properties_.removeProperty(propName); |
1072 | < | } |
1073 | < | |
1074 | < | void SimInfo::clearProperties() { |
1075 | < | properties_.clearProperties(); |
1076 | < | } |
1077 | < | |
1078 | < | std::vector<std::string> SimInfo::getPropertyNames() { |
1079 | < | return properties_.getPropertyNames(); |
1080 | < | } |
1081 | < | |
1082 | < | std::vector<GenericData*> SimInfo::getProperties() { |
1083 | < | return properties_.getProperties(); |
1084 | < | } |
1085 | < | |
1086 | < | GenericData* SimInfo::getPropertyByName(const std::string& propName) { |
1087 | < | return properties_.getPropertyByName(propName); |
1088 | < | } |
1066 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
1067 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
1068 | > | toUpper(myMethod); |
1069 | > | if (myMethod == "NONE") { |
1070 | > | esm = NONE; |
1071 | > | } else { |
1072 | > | if (myMethod == "SWITCHING_FUNCTION") { |
1073 | > | esm = SWITCHING_FUNCTION; |
1074 | > | } else { |
1075 | > | if (myMethod == "SHIFTED_POTENTIAL") { |
1076 | > | esm = SHIFTED_POTENTIAL; |
1077 | > | } else { |
1078 | > | if (myMethod == "SHIFTED_FORCE") { |
1079 | > | esm = SHIFTED_FORCE; |
1080 | > | } else { |
1081 | > | if (myMethod == "REACTION_FIELD") { |
1082 | > | esm = REACTION_FIELD; |
1083 | > | } else { |
1084 | > | // throw error |
1085 | > | sprintf( painCave.errMsg, |
1086 | > | "SimInfo error: Unknown electrostaticSummationMethod.\n" |
1087 | > | "\t(Input file specified %s .)\n" |
1088 | > | "\telectrostaticSummationMethod must be one of: \"none\",\n" |
1089 | > | "\t\"shifted_potential\", \"shifted_force\", or \n" |
1090 | > | "\t\"reaction_field\".\n", myMethod.c_str() ); |
1091 | > | painCave.isFatal = 1; |
1092 | > | simError(); |
1093 | > | } |
1094 | > | } |
1095 | > | } |
1096 | > | } |
1097 | > | } |
1098 | > | } |
1099 | > | |
1100 | > | if (simParams_->haveElectrostaticScreeningMethod()) { |
1101 | > | std::string myScreen = simParams_->getElectrostaticScreeningMethod(); |
1102 | > | toUpper(myScreen); |
1103 | > | if (myScreen == "UNDAMPED") { |
1104 | > | sm = UNDAMPED; |
1105 | > | } else { |
1106 | > | if (myScreen == "DAMPED") { |
1107 | > | sm = DAMPED; |
1108 | > | if (!simParams_->haveDampingAlpha()) { |
1109 | > | //throw error |
1110 | > | sprintf( painCave.errMsg, |
1111 | > | "SimInfo warning: dampingAlpha was not specified in the input file.\n" |
1112 | > | "\tA default value of %f (1/ang) will be used.\n", alphaVal); |
1113 | > | painCave.isFatal = 0; |
1114 | > | simError(); |
1115 | > | } |
1116 | > | } else { |
1117 | > | // throw error |
1118 | > | sprintf( painCave.errMsg, |
1119 | > | "SimInfo error: Unknown electrostaticScreeningMethod.\n" |
1120 | > | "\t(Input file specified %s .)\n" |
1121 | > | "\telectrostaticScreeningMethod must be one of: \"undamped\"\n" |
1122 | > | "or \"damped\".\n", myScreen.c_str() ); |
1123 | > | painCave.isFatal = 1; |
1124 | > | simError(); |
1125 | > | } |
1126 | > | } |
1127 | > | } |
1128 | > | |
1129 | > | // let's pass some summation method variables to fortran |
1130 | > | setElectrostaticSummationMethod( &esm ); |
1131 | > | setFortranElectrostaticMethod( &esm ); |
1132 | > | setScreeningMethod( &sm ); |
1133 | > | setDampingAlpha( &alphaVal ); |
1134 | > | setReactionFieldDielectric( &dielectric ); |
1135 | > | initFortranFF( &errorOut ); |
1136 | > | } |
1137 | ||
1138 | < | void SimInfo::setSnapshotManager(SnapshotManager* sman) { |
1138 | > | void SimInfo::setupSwitchingFunction() { |
1139 | > | int ft = CUBIC; |
1140 | > | |
1141 | > | if (simParams_->haveSwitchingFunctionType()) { |
1142 | > | std::string funcType = simParams_->getSwitchingFunctionType(); |
1143 | > | toUpper(funcType); |
1144 | > | if (funcType == "CUBIC") { |
1145 | > | ft = CUBIC; |
1146 | > | } else { |
1147 | > | if (funcType == "FIFTH_ORDER_POLYNOMIAL") { |
1148 | > | ft = FIFTH_ORDER_POLY; |
1149 | > | } else { |
1150 | > | // throw error |
1151 | > | sprintf( painCave.errMsg, |
1152 | > | "SimInfo error: Unknown switchingFunctionType. (Input file specified %s .)\n\tswitchingFunctionType must be one of: \"cubic\" or \"fifth_order_polynomial\".", funcType.c_str() ); |
1153 | > | painCave.isFatal = 1; |
1154 | > | simError(); |
1155 | > | } |
1156 | > | } |
1157 | > | } |
1158 | > | |
1159 | > | // send switching function notification to switcheroo |
1160 | > | setFunctionType(&ft); |
1161 | > | |
1162 | > | } |
1163 | > | |
1164 | > | void SimInfo::addProperty(GenericData* genData) { |
1165 | > | properties_.addProperty(genData); |
1166 | > | } |
1167 | > | |
1168 | > | void SimInfo::removeProperty(const std::string& propName) { |
1169 | > | properties_.removeProperty(propName); |
1170 | > | } |
1171 | > | |
1172 | > | void SimInfo::clearProperties() { |
1173 | > | properties_.clearProperties(); |
1174 | > | } |
1175 | > | |
1176 | > | std::vector<std::string> SimInfo::getPropertyNames() { |
1177 | > | return properties_.getPropertyNames(); |
1178 | > | } |
1179 | > | |
1180 | > | std::vector<GenericData*> SimInfo::getProperties() { |
1181 | > | return properties_.getProperties(); |
1182 | > | } |
1183 | > | |
1184 | > | GenericData* SimInfo::getPropertyByName(const std::string& propName) { |
1185 | > | return properties_.getPropertyByName(propName); |
1186 | > | } |
1187 | > | |
1188 | > | void SimInfo::setSnapshotManager(SnapshotManager* sman) { |
1189 | > | if (sman_ == sman) { |
1190 | > | return; |
1191 | > | } |
1192 | > | delete sman_; |
1193 | sman_ = sman; | |
1194 | ||
1195 | Molecule* mol; | |
# | Line 846 | Line 1201 | void SimInfo::setSnapshotManager(SnapshotManager* sman | |
1201 | ||
1202 | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
1203 | ||
1204 | < | for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) { |
1205 | < | atom->setSnapshotManager(sman_); |
1206 | < | } |
1204 | > | for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) { |
1205 | > | atom->setSnapshotManager(sman_); |
1206 | > | } |
1207 | ||
1208 | < | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
1209 | < | rb->setSnapshotManager(sman_); |
1210 | < | } |
1208 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
1209 | > | rb->setSnapshotManager(sman_); |
1210 | > | } |
1211 | } | |
1212 | ||
1213 | < | } |
1213 | > | } |
1214 | ||
1215 | < | Vector3d SimInfo::getComVel(){ |
1215 | > | Vector3d SimInfo::getComVel(){ |
1216 | SimInfo::MoleculeIterator i; | |
1217 | Molecule* mol; | |
1218 | ||
# | Line 866 | Line 1221 | Vector3d SimInfo::getComVel(){ | |
1221 | ||
1222 | ||
1223 | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | |
1224 | < | double mass = mol->getMass(); |
1225 | < | totalMass += mass; |
1226 | < | comVel += mass * mol->getComVel(); |
1224 | > | double mass = mol->getMass(); |
1225 | > | totalMass += mass; |
1226 | > | comVel += mass * mol->getComVel(); |
1227 | } | |
1228 | ||
1229 | #ifdef IS_MPI | |
# | Line 881 | Line 1236 | Vector3d SimInfo::getComVel(){ | |
1236 | comVel /= totalMass; | |
1237 | ||
1238 | return comVel; | |
1239 | < | } |
1239 | > | } |
1240 | ||
1241 | < | Vector3d SimInfo::getCom(){ |
1241 | > | Vector3d SimInfo::getCom(){ |
1242 | SimInfo::MoleculeIterator i; | |
1243 | Molecule* mol; | |
1244 | ||
# | Line 891 | Line 1246 | Vector3d SimInfo::getCom(){ | |
1246 | double totalMass = 0.0; | |
1247 | ||
1248 | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | |
1249 | < | double mass = mol->getMass(); |
1250 | < | totalMass += mass; |
1251 | < | com += mass * mol->getCom(); |
1249 | > | double mass = mol->getMass(); |
1250 | > | totalMass += mass; |
1251 | > | com += mass * mol->getCom(); |
1252 | } | |
1253 | ||
1254 | #ifdef IS_MPI | |
# | Line 907 | Line 1262 | Vector3d SimInfo::getCom(){ | |
1262 | ||
1263 | return com; | |
1264 | ||
1265 | < | } |
1265 | > | } |
1266 | ||
1267 | < | std::ostream& operator <<(std::ostream& o, SimInfo& info) { |
1267 | > | std::ostream& operator <<(std::ostream& o, SimInfo& info) { |
1268 | ||
1269 | return o; | |
1270 | < | } |
1270 | > | } |
1271 | > | |
1272 | > | |
1273 | > | /* |
1274 | > | Returns center of mass and center of mass velocity in one function call. |
1275 | > | */ |
1276 | > | |
1277 | > | void SimInfo::getComAll(Vector3d &com, Vector3d &comVel){ |
1278 | > | SimInfo::MoleculeIterator i; |
1279 | > | Molecule* mol; |
1280 | > | |
1281 | > | |
1282 | > | double totalMass = 0.0; |
1283 | > | |
1284 | ||
1285 | + | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1286 | + | double mass = mol->getMass(); |
1287 | + | totalMass += mass; |
1288 | + | com += mass * mol->getCom(); |
1289 | + | comVel += mass * mol->getComVel(); |
1290 | + | } |
1291 | + | |
1292 | + | #ifdef IS_MPI |
1293 | + | double tmpMass = totalMass; |
1294 | + | Vector3d tmpCom(com); |
1295 | + | Vector3d tmpComVel(comVel); |
1296 | + | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1297 | + | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1298 | + | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1299 | + | #endif |
1300 | + | |
1301 | + | com /= totalMass; |
1302 | + | comVel /= totalMass; |
1303 | + | } |
1304 | + | |
1305 | + | /* |
1306 | + | Return intertia tensor for entire system and angular momentum Vector. |
1307 | + | |
1308 | + | |
1309 | + | [ Ixx -Ixy -Ixz ] |
1310 | + | J =| -Iyx Iyy -Iyz | |
1311 | + | [ -Izx -Iyz Izz ] |
1312 | + | */ |
1313 | + | |
1314 | + | void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){ |
1315 | + | |
1316 | + | |
1317 | + | double xx = 0.0; |
1318 | + | double yy = 0.0; |
1319 | + | double zz = 0.0; |
1320 | + | double xy = 0.0; |
1321 | + | double xz = 0.0; |
1322 | + | double yz = 0.0; |
1323 | + | Vector3d com(0.0); |
1324 | + | Vector3d comVel(0.0); |
1325 | + | |
1326 | + | getComAll(com, comVel); |
1327 | + | |
1328 | + | SimInfo::MoleculeIterator i; |
1329 | + | Molecule* mol; |
1330 | + | |
1331 | + | Vector3d thisq(0.0); |
1332 | + | Vector3d thisv(0.0); |
1333 | + | |
1334 | + | double thisMass = 0.0; |
1335 | + | |
1336 | + | |
1337 | + | |
1338 | + | |
1339 | + | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1340 | + | |
1341 | + | thisq = mol->getCom()-com; |
1342 | + | thisv = mol->getComVel()-comVel; |
1343 | + | thisMass = mol->getMass(); |
1344 | + | // Compute moment of intertia coefficients. |
1345 | + | xx += thisq[0]*thisq[0]*thisMass; |
1346 | + | yy += thisq[1]*thisq[1]*thisMass; |
1347 | + | zz += thisq[2]*thisq[2]*thisMass; |
1348 | + | |
1349 | + | // compute products of intertia |
1350 | + | xy += thisq[0]*thisq[1]*thisMass; |
1351 | + | xz += thisq[0]*thisq[2]*thisMass; |
1352 | + | yz += thisq[1]*thisq[2]*thisMass; |
1353 | + | |
1354 | + | angularMomentum += cross( thisq, thisv ) * thisMass; |
1355 | + | |
1356 | + | } |
1357 | + | |
1358 | + | |
1359 | + | inertiaTensor(0,0) = yy + zz; |
1360 | + | inertiaTensor(0,1) = -xy; |
1361 | + | inertiaTensor(0,2) = -xz; |
1362 | + | inertiaTensor(1,0) = -xy; |
1363 | + | inertiaTensor(1,1) = xx + zz; |
1364 | + | inertiaTensor(1,2) = -yz; |
1365 | + | inertiaTensor(2,0) = -xz; |
1366 | + | inertiaTensor(2,1) = -yz; |
1367 | + | inertiaTensor(2,2) = xx + yy; |
1368 | + | |
1369 | + | #ifdef IS_MPI |
1370 | + | Mat3x3d tmpI(inertiaTensor); |
1371 | + | Vector3d tmpAngMom; |
1372 | + | MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1373 | + | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1374 | + | #endif |
1375 | + | |
1376 | + | return; |
1377 | + | } |
1378 | + | |
1379 | + | //Returns the angular momentum of the system |
1380 | + | Vector3d SimInfo::getAngularMomentum(){ |
1381 | + | |
1382 | + | Vector3d com(0.0); |
1383 | + | Vector3d comVel(0.0); |
1384 | + | Vector3d angularMomentum(0.0); |
1385 | + | |
1386 | + | getComAll(com,comVel); |
1387 | + | |
1388 | + | SimInfo::MoleculeIterator i; |
1389 | + | Molecule* mol; |
1390 | + | |
1391 | + | Vector3d thisr(0.0); |
1392 | + | Vector3d thisp(0.0); |
1393 | + | |
1394 | + | double thisMass; |
1395 | + | |
1396 | + | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1397 | + | thisMass = mol->getMass(); |
1398 | + | thisr = mol->getCom()-com; |
1399 | + | thisp = (mol->getComVel()-comVel)*thisMass; |
1400 | + | |
1401 | + | angularMomentum += cross( thisr, thisp ); |
1402 | + | |
1403 | + | } |
1404 | + | |
1405 | + | #ifdef IS_MPI |
1406 | + | Vector3d tmpAngMom; |
1407 | + | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1408 | + | #endif |
1409 | + | |
1410 | + | return angularMomentum; |
1411 | + | } |
1412 | + | |
1413 | + | |
1414 | }//end namespace oopse | |
1415 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |