# | 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 "primitives/StuntDouble.hpp" |
57 | + | #include "UseTheForce/fCutoffPolicy.h" |
58 | + | #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h" |
59 | + | #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h" |
60 | + | #include "UseTheForce/DarkSide/fSwitchingFunctionType.h" |
61 | #include "UseTheForce/doForces_interface.h" | |
62 | < | #include "UseTheForce/notifyCutoffs_interface.h" |
62 | > | #include "UseTheForce/DarkSide/neighborLists_interface.h" |
63 | > | #include "UseTheForce/DarkSide/electrostatic_interface.h" |
64 | > | #include "UseTheForce/DarkSide/switcheroo_interface.h" |
65 | #include "utils/MemoryUtils.hpp" | |
66 | #include "utils/simError.h" | |
67 | #include "selection/SelectionManager.hpp" | |
68 | + | #include "io/ForceFieldOptions.hpp" |
69 | + | #include "UseTheForce/ForceField.hpp" |
70 | ||
71 | + | |
72 | #ifdef IS_MPI | |
73 | #include "UseTheForce/mpiComponentPlan.h" | |
74 | #include "UseTheForce/DarkSide/simParallel_interface.h" | |
75 | #endif | |
76 | ||
77 | namespace oopse { | |
78 | + | std::set<int> getRigidSet(int index, std::map<int, std::set<int> >& container) { |
79 | + | std::map<int, std::set<int> >::iterator i = container.find(index); |
80 | + | std::set<int> result; |
81 | + | if (i != container.end()) { |
82 | + | result = i->second; |
83 | + | } |
84 | ||
85 | < | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs, |
86 | < | ForceField* ff, Globals* simParams) : |
87 | < | forceField_(ff), simParams_(simParams), |
88 | < | ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), |
89 | < | nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), |
90 | < | nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
91 | < | nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0), |
92 | < | nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), |
93 | < | sman_(NULL), fortranInitialized_(false) { |
85 | > | return result; |
86 | > | } |
87 | > | |
88 | > | SimInfo::SimInfo(ForceField* ff, Globals* simParams) : |
89 | > | forceField_(ff), simParams_(simParams), |
90 | > | ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), |
91 | > | nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), |
92 | > | nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
93 | > | nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0), |
94 | > | nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), |
95 | > | sman_(NULL), fortranInitialized_(false), calcBoxDipole_(false), |
96 | > | useAtomicVirial_(true) { |
97 | ||
98 | < | |
99 | < | std::vector<std::pair<MoleculeStamp*, int> >::iterator i; |
100 | < | MoleculeStamp* molStamp; |
101 | < | int nMolWithSameStamp; |
102 | < | int nCutoffAtoms = 0; // number of atoms belong to cutoff groups |
103 | < | int nGroups = 0; //total cutoff groups defined in meta-data file |
104 | < | CutoffGroupStamp* cgStamp; |
105 | < | RigidBodyStamp* rbStamp; |
106 | < | int nRigidAtoms = 0; |
107 | < | |
108 | < | for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) { |
109 | < | molStamp = i->first; |
90 | < | nMolWithSameStamp = i->second; |
98 | > | MoleculeStamp* molStamp; |
99 | > | int nMolWithSameStamp; |
100 | > | int nCutoffAtoms = 0; // number of atoms belong to cutoff groups |
101 | > | int nGroups = 0; //total cutoff groups defined in meta-data file |
102 | > | CutoffGroupStamp* cgStamp; |
103 | > | RigidBodyStamp* rbStamp; |
104 | > | int nRigidAtoms = 0; |
105 | > | std::vector<Component*> components = simParams->getComponents(); |
106 | > | |
107 | > | for (std::vector<Component*>::iterator i = components.begin(); i !=components.end(); ++i) { |
108 | > | molStamp = (*i)->getMoleculeStamp(); |
109 | > | nMolWithSameStamp = (*i)->getNMol(); |
110 | ||
111 | addMoleculeStamp(molStamp, nMolWithSameStamp); | |
112 | ||
113 | //calculate atoms in molecules | |
114 | nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; | |
115 | ||
97 | – | |
116 | //calculate atoms in cutoff groups | |
117 | int nAtomsInGroups = 0; | |
118 | int nCutoffGroupsInStamp = molStamp->getNCutoffGroups(); | |
119 | ||
120 | for (int j=0; j < nCutoffGroupsInStamp; j++) { | |
121 | < | cgStamp = molStamp->getCutoffGroup(j); |
122 | < | nAtomsInGroups += cgStamp->getNMembers(); |
121 | > | cgStamp = molStamp->getCutoffGroupStamp(j); |
122 | > | nAtomsInGroups += cgStamp->getNMembers(); |
123 | } | |
124 | ||
125 | nGroups += nCutoffGroupsInStamp * nMolWithSameStamp; | |
126 | + | |
127 | nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp; | |
128 | ||
129 | //calculate atoms in rigid bodies | |
# | Line 112 | Line 131 | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, | |
131 | int nRigidBodiesInStamp = molStamp->getNRigidBodies(); | |
132 | ||
133 | for (int j=0; j < nRigidBodiesInStamp; j++) { | |
134 | < | rbStamp = molStamp->getRigidBody(j); |
135 | < | nAtomsInRigidBodies += rbStamp->getNMembers(); |
134 | > | rbStamp = molStamp->getRigidBodyStamp(j); |
135 | > | nAtomsInRigidBodies += rbStamp->getNMembers(); |
136 | } | |
137 | ||
138 | nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp; | |
139 | nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp; | |
140 | ||
141 | < | } |
141 | > | } |
142 | ||
143 | < | //every free atom (atom does not belong to cutoff groups) is a cutoff group |
144 | < | //therefore the total number of cutoff groups in the system is equal to |
145 | < | //the total number of atoms minus number of atoms belong to cutoff group defined in meta-data |
146 | < | //file plus the number of cutoff groups defined in meta-data file |
147 | < | nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; |
143 | > | //every free atom (atom does not belong to cutoff groups) is a cutoff |
144 | > | //group therefore the total number of cutoff groups in the system is |
145 | > | //equal to the total number of atoms minus number of atoms belong to |
146 | > | //cutoff group defined in meta-data file plus the number of cutoff |
147 | > | //groups defined in meta-data file |
148 | > | nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; |
149 | ||
150 | < | //every free atom (atom does not belong to rigid bodies) is an integrable object |
151 | < | //therefore the total number of integrable objects in the system is equal to |
152 | < | //the total number of atoms minus number of atoms belong to rigid body defined in meta-data |
153 | < | //file plus the number of rigid bodies defined in meta-data file |
154 | < | nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nGlobalRigidBodies_; |
150 | > | //every free atom (atom does not belong to rigid bodies) is an |
151 | > | //integrable object therefore the total number of integrable objects |
152 | > | //in the system is equal to the total number of atoms minus number of |
153 | > | //atoms belong to rigid body defined in meta-data file plus the number |
154 | > | //of rigid bodies defined in meta-data file |
155 | > | nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms |
156 | > | + nGlobalRigidBodies_; |
157 | > | |
158 | > | nGlobalMols_ = molStampIds_.size(); |
159 | > | molToProcMap_.resize(nGlobalMols_); |
160 | > | } |
161 | ||
162 | < | nGlobalMols_ = molStampIds_.size(); |
137 | < | |
138 | < | #ifdef IS_MPI |
139 | < | molToProcMap_.resize(nGlobalMols_); |
140 | < | #endif |
141 | < | |
142 | < | } |
143 | < | |
144 | < | SimInfo::~SimInfo() { |
162 | > | SimInfo::~SimInfo() { |
163 | std::map<int, Molecule*>::iterator i; | |
164 | for (i = molecules_.begin(); i != molecules_.end(); ++i) { | |
165 | < | delete i->second; |
165 | > | delete i->second; |
166 | } | |
167 | molecules_.clear(); | |
168 | < | |
151 | < | MemoryUtils::deletePointers(moleculeStamps_); |
152 | < | |
168 | > | |
169 | delete sman_; | |
170 | delete simParams_; | |
171 | delete forceField_; | |
172 | < | } |
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 164 | 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(); |
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()); |
227 | > | removeExcludePairs(mol); |
228 | > | molecules_.erase(mol->getGlobalIndex()); |
229 | ||
230 | < | delete mol; |
230 | > | delete mol; |
231 | ||
232 | < | return true; |
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 243 | 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 272 | 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 286 | 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 307 | 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 323 | 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 336 | 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 381 | 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 423 | 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 438 | Line 599 | void SimInfo::update() { | |
599 | //setup fortran force field | |
600 | /** @deprecate */ | |
601 | int isError = 0; | |
441 | – | initFortranFF( &fInfo_.SIM_uses_RF , &isError ); |
442 | – | if(isError){ |
443 | – | sprintf( painCave.errMsg, |
444 | – | "ForceField error: There was an error initializing the forceField in fortran.\n" ); |
445 | – | painCave.isFatal = 1; |
446 | – | simError(); |
447 | – | } |
448 | – | |
602 | ||
603 | setupCutoff(); | |
604 | + | |
605 | + | setupElectrostaticSummationMethod( isError ); |
606 | + | setupSwitchingFunction(); |
607 | + | setupAccumulateBoxDipole(); |
608 | ||
609 | + | if(isError){ |
610 | + | sprintf( painCave.errMsg, |
611 | + | "ForceField error: There was an error initializing the forceField in fortran.\n" ); |
612 | + | painCave.isFatal = 1; |
613 | + | simError(); |
614 | + | } |
615 | + | |
616 | calcNdf(); | |
617 | calcNdfRaw(); | |
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 465 | 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 482 | 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 | > | int useSP; |
665 | > | int useBoxDipole; |
666 | > | |
667 | > | std::string myMethod; |
668 | > | |
669 | > | // set the useRF logical |
670 | > | useRF = 0; |
671 | > | useSF = 0; |
672 | > | useSP = 0; |
673 | > | |
674 | > | |
675 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
676 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
677 | > | toUpper(myMethod); |
678 | > | if (myMethod == "REACTION_FIELD"){ |
679 | > | useRF = 1; |
680 | > | } else if (myMethod == "SHIFTED_FORCE"){ |
681 | > | useSF = 1; |
682 | > | } else if (myMethod == "SHIFTED_POTENTIAL"){ |
683 | > | useSP = 1; |
684 | > | } |
685 | > | } |
686 | > | |
687 | > | if (simParams_->haveAccumulateBoxDipole()) |
688 | > | if (simParams_->getAccumulateBoxDipole()) |
689 | > | useBoxDipole = 1; |
690 | ||
691 | + | useAtomicVirial_ = simParams_->getUseAtomicVirial(); |
692 | + | |
693 | //loop over all of the atom types | |
694 | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { | |
695 | < | useLennardJones |= (*i)->isLennardJones(); |
696 | < | useElectrostatic |= (*i)->isElectrostatic(); |
697 | < | useEAM |= (*i)->isEAM(); |
698 | < | useCharge |= (*i)->isCharge(); |
699 | < | useDirectional |= (*i)->isDirectional(); |
700 | < | useDipole |= (*i)->isDipole(); |
701 | < | useGayBerne |= (*i)->isGayBerne(); |
702 | < | useSticky |= (*i)->isSticky(); |
703 | < | useShape |= (*i)->isShape(); |
695 | > | useLennardJones |= (*i)->isLennardJones(); |
696 | > | useElectrostatic |= (*i)->isElectrostatic(); |
697 | > | useEAM |= (*i)->isEAM(); |
698 | > | useSC |= (*i)->isSC(); |
699 | > | useCharge |= (*i)->isCharge(); |
700 | > | useDirectional |= (*i)->isDirectional(); |
701 | > | useDipole |= (*i)->isDipole(); |
702 | > | useGayBerne |= (*i)->isGayBerne(); |
703 | > | useSticky |= (*i)->isSticky(); |
704 | > | useStickyPower |= (*i)->isStickyPower(); |
705 | > | useShape |= (*i)->isShape(); |
706 | } | |
707 | ||
708 | < | if (useSticky || useDipole || useGayBerne || useShape) { |
709 | < | useDirectionalAtom = 1; |
708 | > | if (useSticky || useStickyPower || useDipole || useGayBerne || useShape) { |
709 | > | useDirectionalAtom = 1; |
710 | } | |
711 | ||
712 | if (useCharge || useDipole) { | |
713 | < | useElectrostatics = 1; |
713 | > | useElectrostatics = 1; |
714 | } | |
715 | ||
716 | #ifdef IS_MPI | |
# | Line 540 | Line 737 | void SimInfo::setupSimType() { | |
737 | temp = useSticky; | |
738 | MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
739 | ||
740 | + | temp = useStickyPower; |
741 | + | MPI_Allreduce(&temp, &useStickyPower, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
742 | + | |
743 | temp = useGayBerne; | |
744 | MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
745 | ||
746 | temp = useEAM; | |
747 | MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
748 | ||
749 | + | temp = useSC; |
750 | + | MPI_Allreduce(&temp, &useSC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
751 | + | |
752 | temp = useShape; | |
753 | MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
754 | ||
# | Line 554 | Line 757 | void SimInfo::setupSimType() { | |
757 | ||
758 | temp = useRF; | |
759 | MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | |
760 | < | |
760 | > | |
761 | > | temp = useSF; |
762 | > | MPI_Allreduce(&temp, &useSF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
763 | > | |
764 | > | temp = useSP; |
765 | > | MPI_Allreduce(&temp, &useSP, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
766 | > | |
767 | > | temp = useBoxDipole; |
768 | > | MPI_Allreduce(&temp, &useBoxDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
769 | > | |
770 | > | temp = useAtomicVirial_; |
771 | > | MPI_Allreduce(&temp, &useAtomicVirial_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
772 | > | |
773 | #endif | |
774 | ||
775 | fInfo_.SIM_uses_PBC = usePBC; | |
# | Line 564 | Line 779 | void SimInfo::setupSimType() { | |
779 | fInfo_.SIM_uses_Charges = useCharge; | |
780 | fInfo_.SIM_uses_Dipoles = useDipole; | |
781 | fInfo_.SIM_uses_Sticky = useSticky; | |
782 | + | fInfo_.SIM_uses_StickyPower = useStickyPower; |
783 | fInfo_.SIM_uses_GayBerne = useGayBerne; | |
784 | fInfo_.SIM_uses_EAM = useEAM; | |
785 | + | fInfo_.SIM_uses_SC = useSC; |
786 | fInfo_.SIM_uses_Shapes = useShape; | |
787 | fInfo_.SIM_uses_FLARB = useFLARB; | |
788 | fInfo_.SIM_uses_RF = useRF; | |
789 | + | fInfo_.SIM_uses_SF = useSF; |
790 | + | fInfo_.SIM_uses_SP = useSP; |
791 | + | fInfo_.SIM_uses_BoxDipole = useBoxDipole; |
792 | + | fInfo_.SIM_uses_AtomicVirial = useAtomicVirial_; |
793 | + | } |
794 | ||
795 | < | if( fInfo_.SIM_uses_Dipoles && fInfo_.SIM_uses_RF) { |
574 | < | |
575 | < | if (simParams_->haveDielectric()) { |
576 | < | fInfo_.dielect = simParams_->getDielectric(); |
577 | < | } else { |
578 | < | sprintf(painCave.errMsg, |
579 | < | "SimSetup Error: No Dielectric constant was set.\n" |
580 | < | "\tYou are trying to use Reaction Field without" |
581 | < | "\tsetting a dielectric constant!\n"); |
582 | < | painCave.isFatal = 1; |
583 | < | simError(); |
584 | < | } |
585 | < | |
586 | < | } else { |
587 | < | fInfo_.dielect = 0.0; |
588 | < | } |
589 | < | |
590 | < | } |
591 | < | |
592 | < | void SimInfo::setupFortranSim() { |
795 | > | void SimInfo::setupFortranSim() { |
796 | int isError; | |
797 | int nExclude; | |
798 | std::vector<int> fortranGlobalGroupMembership; | |
# | Line 599 | Line 802 | void SimInfo::setupFortranSim() { | |
802 | ||
803 | //globalGroupMembership_ is filled by SimCreator | |
804 | for (int i = 0; i < nGlobalAtoms_; i++) { | |
805 | < | fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); |
805 | > | fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); |
806 | } | |
807 | ||
808 | //calculate mass ratio of cutoff group | |
809 | < | std::vector<double> mfact; |
809 | > | std::vector<RealType> mfact; |
810 | SimInfo::MoleculeIterator mi; | |
811 | Molecule* mol; | |
812 | Molecule::CutoffGroupIterator ci; | |
813 | CutoffGroup* cg; | |
814 | Molecule::AtomIterator ai; | |
815 | Atom* atom; | |
816 | < | double totalMass; |
816 | > | RealType totalMass; |
817 | ||
818 | //to avoid memory reallocation, reserve enough space for mfact | |
819 | mfact.reserve(getNCutoffGroups()); | |
820 | ||
821 | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
822 | < | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
822 | > | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
823 | ||
824 | < | totalMass = cg->getMass(); |
825 | < | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
826 | < | mfact.push_back(atom->getMass()/totalMass); |
827 | < | } |
824 | > | totalMass = cg->getMass(); |
825 | > | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
826 | > | // Check for massless groups - set mfact to 1 if true |
827 | > | if (totalMass != 0) |
828 | > | mfact.push_back(atom->getMass()/totalMass); |
829 | > | else |
830 | > | mfact.push_back( 1.0 ); |
831 | > | } |
832 | ||
833 | < | } |
833 | > | } |
834 | } | |
835 | ||
836 | //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) | |
# | Line 633 | Line 840 | void SimInfo::setupFortranSim() { | |
840 | identArray.reserve(getNAtoms()); | |
841 | ||
842 | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
843 | < | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
844 | < | identArray.push_back(atom->getIdent()); |
845 | < | } |
843 | > | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
844 | > | identArray.push_back(atom->getIdent()); |
845 | > | } |
846 | } | |
847 | ||
848 | //fill molMembershipArray | |
849 | //molMembershipArray is filled by SimCreator | |
850 | std::vector<int> molMembershipArray(nGlobalAtoms_); | |
851 | for (int i = 0; i < nGlobalAtoms_; i++) { | |
852 | < | molMembershipArray[i] = globalMolMembership_[i] + 1; |
852 | > | molMembershipArray[i] = globalMolMembership_[i] + 1; |
853 | } | |
854 | ||
855 | //setup fortran simulation | |
649 | – | //gloalExcludes and molMembershipArray should go away (They are never used) |
650 | – | //why the hell fortran need to know molecule? |
651 | – | //OOPSE = Object-Obfuscated Parallel Simulation Engine |
856 | int nGlobalExcludes = 0; | |
857 | int* globalExcludes = NULL; | |
858 | int* excludeList = exclude_.getExcludeList(); | |
859 | < | setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList , |
860 | < | &nGlobalExcludes, globalExcludes, &molMembershipArray[0], |
861 | < | &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError); |
862 | < | |
859 | > | setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], |
860 | > | &nExclude, excludeList , &nGlobalExcludes, globalExcludes, |
861 | > | &molMembershipArray[0], &mfact[0], &nCutoffGroups_, |
862 | > | &fortranGlobalGroupMembership[0], &isError); |
863 | > | |
864 | if( isError ){ | |
865 | < | |
866 | < | sprintf( painCave.errMsg, |
867 | < | "There was an error setting the simulation information in fortran.\n" ); |
868 | < | painCave.isFatal = 1; |
869 | < | painCave.severity = OOPSE_ERROR; |
870 | < | simError(); |
865 | > | |
866 | > | sprintf( painCave.errMsg, |
867 | > | "There was an error setting the simulation information in fortran.\n" ); |
868 | > | painCave.isFatal = 1; |
869 | > | painCave.severity = OOPSE_ERROR; |
870 | > | simError(); |
871 | } | |
872 | < | |
873 | < | #ifdef IS_MPI |
872 | > | |
873 | > | |
874 | sprintf( checkPointMsg, | |
875 | < | "succesfully sent the simulation information to fortran.\n"); |
876 | < | MPIcheckPoint(); |
877 | < | #endif // is_mpi |
878 | < | } |
875 | > | "succesfully sent the simulation information to fortran.\n"); |
876 | > | |
877 | > | errorCheckPoint(); |
878 | > | |
879 | > | // Setup number of neighbors in neighbor list if present |
880 | > | if (simParams_->haveNeighborListNeighbors()) { |
881 | > | int nlistNeighbors = simParams_->getNeighborListNeighbors(); |
882 | > | setNeighbors(&nlistNeighbors); |
883 | > | } |
884 | > | |
885 | ||
886 | + | } |
887 | ||
888 | < | #ifdef IS_MPI |
889 | < | void SimInfo::setupFortranParallel() { |
890 | < | |
888 | > | |
889 | > | void SimInfo::setupFortranParallel() { |
890 | > | #ifdef IS_MPI |
891 | //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex | |
892 | std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0); | |
893 | std::vector<int> localToGlobalCutoffGroupIndex; | |
# | Line 690 | Line 902 | void SimInfo::setupFortranParallel() { | |
902 | ||
903 | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
904 | ||
905 | < | //local index(index in DataStorge) of atom is important |
906 | < | for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
907 | < | localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; |
908 | < | } |
905 | > | //local index(index in DataStorge) of atom is important |
906 | > | for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
907 | > | localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; |
908 | > | } |
909 | ||
910 | < | //local index of cutoff group is trivial, it only depends on the order of travesing |
911 | < | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
912 | < | localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); |
913 | < | } |
910 | > | //local index of cutoff group is trivial, it only depends on the order of travesing |
911 | > | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
912 | > | localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); |
913 | > | } |
914 | ||
915 | } | |
916 | ||
# | Line 718 | Line 930 | void SimInfo::setupFortranParallel() { | |
930 | &localToGlobalCutoffGroupIndex[0], &isError); | |
931 | ||
932 | if (isError) { | |
933 | < | sprintf(painCave.errMsg, |
934 | < | "mpiRefresh errror: fortran didn't like something we gave it.\n"); |
935 | < | painCave.isFatal = 1; |
936 | < | simError(); |
933 | > | sprintf(painCave.errMsg, |
934 | > | "mpiRefresh errror: fortran didn't like something we gave it.\n"); |
935 | > | painCave.isFatal = 1; |
936 | > | simError(); |
937 | } | |
938 | ||
939 | sprintf(checkPointMsg, " mpiRefresh successful.\n"); | |
940 | < | MPIcheckPoint(); |
940 | > | errorCheckPoint(); |
941 | ||
730 | – | |
731 | – | } |
732 | – | |
942 | #endif | |
943 | + | } |
944 | ||
945 | < | double SimInfo::calcMaxCutoffRadius() { |
945 | > | void SimInfo::setupCutoff() { |
946 | > | |
947 | > | ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions(); |
948 | ||
949 | + | // Check the cutoff policy |
950 | + | int cp = TRADITIONAL_CUTOFF_POLICY; // Set to traditional by default |
951 | ||
952 | < | std::set<AtomType*> atomTypes; |
953 | < | std::set<AtomType*>::iterator i; |
954 | < | std::vector<double> cutoffRadius; |
952 | > | // Set LJ shifting bools to false |
953 | > | ljsp_ = false; |
954 | > | ljsf_ = false; |
955 | ||
956 | < | //get the unique atom types |
957 | < | atomTypes = getUniqueAtomTypes(); |
958 | < | |
959 | < | //query the max cutoff radius among these atom types |
960 | < | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
747 | < | cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i)); |
956 | > | std::string myPolicy; |
957 | > | if (forceFieldOptions_.haveCutoffPolicy()){ |
958 | > | myPolicy = forceFieldOptions_.getCutoffPolicy(); |
959 | > | }else if (simParams_->haveCutoffPolicy()) { |
960 | > | myPolicy = simParams_->getCutoffPolicy(); |
961 | } | |
962 | ||
963 | < | double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end())); |
964 | < | #ifdef IS_MPI |
965 | < | //pick the max cutoff radius among the processors |
966 | < | #endif |
963 | > | if (!myPolicy.empty()){ |
964 | > | toUpper(myPolicy); |
965 | > | if (myPolicy == "MIX") { |
966 | > | cp = MIX_CUTOFF_POLICY; |
967 | > | } else { |
968 | > | if (myPolicy == "MAX") { |
969 | > | cp = MAX_CUTOFF_POLICY; |
970 | > | } else { |
971 | > | if (myPolicy == "TRADITIONAL") { |
972 | > | cp = TRADITIONAL_CUTOFF_POLICY; |
973 | > | } else { |
974 | > | // throw error |
975 | > | sprintf( painCave.errMsg, |
976 | > | "SimInfo error: Unknown cutoffPolicy. (Input file specified %s .)\n\tcutoffPolicy must be one of: \"Mix\", \"Max\", or \"Traditional\".", myPolicy.c_str() ); |
977 | > | painCave.isFatal = 1; |
978 | > | simError(); |
979 | > | } |
980 | > | } |
981 | > | } |
982 | > | } |
983 | > | notifyFortranCutoffPolicy(&cp); |
984 | ||
985 | < | return maxCutoffRadius; |
986 | < | } |
985 | > | // Check the Skin Thickness for neighborlists |
986 | > | RealType skin; |
987 | > | if (simParams_->haveSkinThickness()) { |
988 | > | skin = simParams_->getSkinThickness(); |
989 | > | notifyFortranSkinThickness(&skin); |
990 | > | } |
991 | > | |
992 | > | // Check if the cutoff was set explicitly: |
993 | > | if (simParams_->haveCutoffRadius()) { |
994 | > | rcut_ = simParams_->getCutoffRadius(); |
995 | > | if (simParams_->haveSwitchingRadius()) { |
996 | > | rsw_ = simParams_->getSwitchingRadius(); |
997 | > | } else { |
998 | > | if (fInfo_.SIM_uses_Charges | |
999 | > | fInfo_.SIM_uses_Dipoles | |
1000 | > | fInfo_.SIM_uses_RF) { |
1001 | > | |
1002 | > | rsw_ = 0.85 * rcut_; |
1003 | > | sprintf(painCave.errMsg, |
1004 | > | "SimCreator Warning: No value was set for the switchingRadius.\n" |
1005 | > | "\tOOPSE will use a default value of 85 percent of the cutoffRadius.\n" |
1006 | > | "\tswitchingRadius = %f. for this simulation\n", rsw_); |
1007 | > | painCave.isFatal = 0; |
1008 | > | simError(); |
1009 | > | } else { |
1010 | > | rsw_ = rcut_; |
1011 | > | sprintf(painCave.errMsg, |
1012 | > | "SimCreator Warning: No value was set for the switchingRadius.\n" |
1013 | > | "\tOOPSE will use the same value as the cutoffRadius.\n" |
1014 | > | "\tswitchingRadius = %f. for this simulation\n", rsw_); |
1015 | > | painCave.isFatal = 0; |
1016 | > | simError(); |
1017 | > | } |
1018 | > | } |
1019 | ||
1020 | < | void SimInfo::getCutoff(double& rcut, double& rsw) { |
1021 | < | |
1022 | < | if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { |
1020 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
1021 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
1022 | > | toUpper(myMethod); |
1023 | ||
1024 | < | if (!simParams_->haveRcut()){ |
1025 | < | sprintf(painCave.errMsg, |
1024 | > | if (myMethod == "SHIFTED_POTENTIAL") { |
1025 | > | ljsp_ = true; |
1026 | > | } else if (myMethod == "SHIFTED_FORCE") { |
1027 | > | ljsf_ = true; |
1028 | > | } |
1029 | > | } |
1030 | > | notifyFortranCutoffs(&rcut_, &rsw_, &ljsp_, &ljsf_); |
1031 | > | |
1032 | > | } else { |
1033 | > | |
1034 | > | // For electrostatic atoms, we'll assume a large safe value: |
1035 | > | if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { |
1036 | > | sprintf(painCave.errMsg, |
1037 | "SimCreator Warning: No value was set for the cutoffRadius.\n" | |
1038 | "\tOOPSE will use a default value of 15.0 angstroms" | |
1039 | "\tfor the cutoffRadius.\n"); | |
1040 | < | painCave.isFatal = 0; |
1041 | < | simError(); |
1042 | < | rcut = 15.0; |
1043 | < | } else{ |
1044 | < | rcut = simParams_->getRcut(); |
1040 | > | painCave.isFatal = 0; |
1041 | > | simError(); |
1042 | > | rcut_ = 15.0; |
1043 | > | |
1044 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
1045 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
1046 | > | toUpper(myMethod); |
1047 | > | |
1048 | > | // For the time being, we're tethering the LJ shifted behavior to the |
1049 | > | // electrostaticSummationMethod keyword options |
1050 | > | if (myMethod == "SHIFTED_POTENTIAL") { |
1051 | > | ljsp_ = true; |
1052 | > | } else if (myMethod == "SHIFTED_FORCE") { |
1053 | > | ljsf_ = true; |
1054 | > | } |
1055 | > | if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") { |
1056 | > | if (simParams_->haveSwitchingRadius()){ |
1057 | > | sprintf(painCave.errMsg, |
1058 | > | "SimInfo Warning: A value was set for the switchingRadius\n" |
1059 | > | "\teven though the electrostaticSummationMethod was\n" |
1060 | > | "\tset to %s\n", myMethod.c_str()); |
1061 | > | painCave.isFatal = 1; |
1062 | > | simError(); |
1063 | > | } |
1064 | > | } |
1065 | } | |
1066 | < | |
1067 | < | if (!simParams_->haveRsw()){ |
1068 | < | sprintf(painCave.errMsg, |
1069 | < | "SimCreator Warning: No value was set for switchingRadius.\n" |
1070 | < | "\tOOPSE will use a default value of\n" |
1071 | < | "\t0.95 * cutoffRadius for the switchingRadius\n"); |
1072 | < | painCave.isFatal = 0; |
1073 | < | simError(); |
1074 | < | rsw = 0.95 * rcut; |
1075 | < | } else{ |
1076 | < | rsw = simParams_->getRsw(); |
1066 | > | |
1067 | > | if (simParams_->haveSwitchingRadius()){ |
1068 | > | rsw_ = simParams_->getSwitchingRadius(); |
1069 | > | } else { |
1070 | > | sprintf(painCave.errMsg, |
1071 | > | "SimCreator Warning: No value was set for switchingRadius.\n" |
1072 | > | "\tOOPSE will use a default value of\n" |
1073 | > | "\t0.85 * cutoffRadius for the switchingRadius\n"); |
1074 | > | painCave.isFatal = 0; |
1075 | > | simError(); |
1076 | > | rsw_ = 0.85 * rcut_; |
1077 | } | |
1078 | ||
1079 | < | } else { |
1080 | < | // if charge, dipole or reaction field is not used and the cutofff radius is not specified in |
1081 | < | //meta-data file, the maximum cutoff radius calculated from forcefiled will be used |
1079 | > | notifyFortranCutoffs(&rcut_, &rsw_, &ljsp_, &ljsf_); |
1080 | > | |
1081 | > | } else { |
1082 | > | // We didn't set rcut explicitly, and we don't have electrostatic atoms, so |
1083 | > | // We'll punt and let fortran figure out the cutoffs later. |
1084 | ||
1085 | < | if (simParams_->haveRcut()) { |
791 | < | rcut = simParams_->getRcut(); |
792 | < | } else { |
793 | < | //set cutoff radius to the maximum cutoff radius based on atom types in the whole system |
794 | < | rcut = calcMaxCutoffRadius(); |
795 | < | } |
1085 | > | notifyFortranYouAreOnYourOwn(); |
1086 | ||
1087 | < | if (simParams_->haveRsw()) { |
1088 | < | rsw = simParams_->getRsw(); |
1087 | > | } |
1088 | > | } |
1089 | > | } |
1090 | > | |
1091 | > | void SimInfo::setupElectrostaticSummationMethod( int isError ) { |
1092 | > | |
1093 | > | int errorOut; |
1094 | > | int esm = NONE; |
1095 | > | int sm = UNDAMPED; |
1096 | > | RealType alphaVal; |
1097 | > | RealType dielectric; |
1098 | > | |
1099 | > | errorOut = isError; |
1100 | > | |
1101 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
1102 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
1103 | > | toUpper(myMethod); |
1104 | > | if (myMethod == "NONE") { |
1105 | > | esm = NONE; |
1106 | > | } else { |
1107 | > | if (myMethod == "SWITCHING_FUNCTION") { |
1108 | > | esm = SWITCHING_FUNCTION; |
1109 | } else { | |
1110 | < | rsw = rcut; |
1111 | < | } |
1110 | > | if (myMethod == "SHIFTED_POTENTIAL") { |
1111 | > | esm = SHIFTED_POTENTIAL; |
1112 | > | } else { |
1113 | > | if (myMethod == "SHIFTED_FORCE") { |
1114 | > | esm = SHIFTED_FORCE; |
1115 | > | } else { |
1116 | > | if (myMethod == "REACTION_FIELD") { |
1117 | > | esm = REACTION_FIELD; |
1118 | > | dielectric = simParams_->getDielectric(); |
1119 | > | if (!simParams_->haveDielectric()) { |
1120 | > | // throw warning |
1121 | > | sprintf( painCave.errMsg, |
1122 | > | "SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n" |
1123 | > | "\tA default value of %f will be used for the dielectric.\n", dielectric); |
1124 | > | painCave.isFatal = 0; |
1125 | > | simError(); |
1126 | > | } |
1127 | > | } else { |
1128 | > | // throw error |
1129 | > | sprintf( painCave.errMsg, |
1130 | > | "SimInfo error: Unknown electrostaticSummationMethod.\n" |
1131 | > | "\t(Input file specified %s .)\n" |
1132 | > | "\telectrostaticSummationMethod must be one of: \"none\",\n" |
1133 | > | "\t\"shifted_potential\", \"shifted_force\", or \n" |
1134 | > | "\t\"reaction_field\".\n", myMethod.c_str() ); |
1135 | > | painCave.isFatal = 1; |
1136 | > | simError(); |
1137 | > | } |
1138 | > | } |
1139 | > | } |
1140 | > | } |
1141 | > | } |
1142 | > | } |
1143 | ||
1144 | + | if (simParams_->haveElectrostaticScreeningMethod()) { |
1145 | + | std::string myScreen = simParams_->getElectrostaticScreeningMethod(); |
1146 | + | toUpper(myScreen); |
1147 | + | if (myScreen == "UNDAMPED") { |
1148 | + | sm = UNDAMPED; |
1149 | + | } else { |
1150 | + | if (myScreen == "DAMPED") { |
1151 | + | sm = DAMPED; |
1152 | + | if (!simParams_->haveDampingAlpha()) { |
1153 | + | // first set a cutoff dependent alpha value |
1154 | + | // we assume alpha depends linearly with rcut from 0 to 20.5 ang |
1155 | + | alphaVal = 0.5125 - rcut_* 0.025; |
1156 | + | // for values rcut > 20.5, alpha is zero |
1157 | + | if (alphaVal < 0) alphaVal = 0; |
1158 | + | |
1159 | + | // throw warning |
1160 | + | sprintf( painCave.errMsg, |
1161 | + | "SimInfo warning: dampingAlpha was not specified in the input file.\n" |
1162 | + | "\tA default value of %f (1/ang) will be used for the cutoff of\n\t%f (ang).\n", alphaVal, rcut_); |
1163 | + | painCave.isFatal = 0; |
1164 | + | simError(); |
1165 | + | } else { |
1166 | + | alphaVal = simParams_->getDampingAlpha(); |
1167 | + | } |
1168 | + | |
1169 | + | } else { |
1170 | + | // throw error |
1171 | + | sprintf( painCave.errMsg, |
1172 | + | "SimInfo error: Unknown electrostaticScreeningMethod.\n" |
1173 | + | "\t(Input file specified %s .)\n" |
1174 | + | "\telectrostaticScreeningMethod must be one of: \"undamped\"\n" |
1175 | + | "or \"damped\".\n", myScreen.c_str() ); |
1176 | + | painCave.isFatal = 1; |
1177 | + | simError(); |
1178 | + | } |
1179 | + | } |
1180 | } | |
1181 | < | } |
1181 | > | |
1182 | > | // let's pass some summation method variables to fortran |
1183 | > | setElectrostaticSummationMethod( &esm ); |
1184 | > | setFortranElectrostaticMethod( &esm ); |
1185 | > | setScreeningMethod( &sm ); |
1186 | > | setDampingAlpha( &alphaVal ); |
1187 | > | setReactionFieldDielectric( &dielectric ); |
1188 | > | initFortranFF( &errorOut ); |
1189 | > | } |
1190 | ||
1191 | < | void SimInfo::setupCutoff() { |
1192 | < | getCutoff(rcut_, rsw_); |
808 | < | double rnblist = rcut_ + 1; // skin of neighbor list |
1191 | > | void SimInfo::setupSwitchingFunction() { |
1192 | > | int ft = CUBIC; |
1193 | ||
1194 | < | //Pass these cutoff radius etc. to fortran. This function should be called once and only once |
1195 | < | notifyFortranCutoffs(&rcut_, &rsw_, &rnblist); |
1196 | < | } |
1194 | > | if (simParams_->haveSwitchingFunctionType()) { |
1195 | > | std::string funcType = simParams_->getSwitchingFunctionType(); |
1196 | > | toUpper(funcType); |
1197 | > | if (funcType == "CUBIC") { |
1198 | > | ft = CUBIC; |
1199 | > | } else { |
1200 | > | if (funcType == "FIFTH_ORDER_POLYNOMIAL") { |
1201 | > | ft = FIFTH_ORDER_POLY; |
1202 | > | } else { |
1203 | > | // throw error |
1204 | > | sprintf( painCave.errMsg, |
1205 | > | "SimInfo error: Unknown switchingFunctionType. (Input file specified %s .)\n\tswitchingFunctionType must be one of: \"cubic\" or \"fifth_order_polynomial\".", funcType.c_str() ); |
1206 | > | painCave.isFatal = 1; |
1207 | > | simError(); |
1208 | > | } |
1209 | > | } |
1210 | > | } |
1211 | ||
1212 | < | void SimInfo::addProperty(GenericData* genData) { |
1213 | < | properties_.addProperty(genData); |
816 | < | } |
1212 | > | // send switching function notification to switcheroo |
1213 | > | setFunctionType(&ft); |
1214 | ||
1215 | < | void SimInfo::removeProperty(const std::string& propName) { |
1215 | > | } |
1216 | > | |
1217 | > | void SimInfo::setupAccumulateBoxDipole() { |
1218 | > | |
1219 | > | // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true |
1220 | > | if ( simParams_->haveAccumulateBoxDipole() ) |
1221 | > | if ( simParams_->getAccumulateBoxDipole() ) { |
1222 | > | setAccumulateBoxDipole(); |
1223 | > | calcBoxDipole_ = true; |
1224 | > | } |
1225 | > | |
1226 | > | } |
1227 | > | |
1228 | > | void SimInfo::addProperty(GenericData* genData) { |
1229 | > | properties_.addProperty(genData); |
1230 | > | } |
1231 | > | |
1232 | > | void SimInfo::removeProperty(const std::string& propName) { |
1233 | properties_.removeProperty(propName); | |
1234 | < | } |
1234 | > | } |
1235 | ||
1236 | < | void SimInfo::clearProperties() { |
1236 | > | void SimInfo::clearProperties() { |
1237 | properties_.clearProperties(); | |
1238 | < | } |
1238 | > | } |
1239 | ||
1240 | < | std::vector<std::string> SimInfo::getPropertyNames() { |
1240 | > | std::vector<std::string> SimInfo::getPropertyNames() { |
1241 | return properties_.getPropertyNames(); | |
1242 | < | } |
1242 | > | } |
1243 | ||
1244 | < | std::vector<GenericData*> SimInfo::getProperties() { |
1244 | > | std::vector<GenericData*> SimInfo::getProperties() { |
1245 | return properties_.getProperties(); | |
1246 | < | } |
1246 | > | } |
1247 | ||
1248 | < | GenericData* SimInfo::getPropertyByName(const std::string& propName) { |
1248 | > | GenericData* SimInfo::getPropertyByName(const std::string& propName) { |
1249 | return properties_.getPropertyByName(propName); | |
1250 | < | } |
1250 | > | } |
1251 | ||
1252 | < | void SimInfo::setSnapshotManager(SnapshotManager* sman) { |
1253 | < | //if (sman_ == sman_) { |
1254 | < | // return; |
1255 | < | //} |
1256 | < | |
843 | < | //delete sman_; |
1252 | > | void SimInfo::setSnapshotManager(SnapshotManager* sman) { |
1253 | > | if (sman_ == sman) { |
1254 | > | return; |
1255 | > | } |
1256 | > | delete sman_; |
1257 | sman_ = sman; | |
1258 | ||
1259 | Molecule* mol; | |
# | Line 852 | Line 1265 | void SimInfo::setSnapshotManager(SnapshotManager* sman | |
1265 | ||
1266 | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | |
1267 | ||
1268 | < | for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) { |
1269 | < | atom->setSnapshotManager(sman_); |
1270 | < | } |
1268 | > | for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) { |
1269 | > | atom->setSnapshotManager(sman_); |
1270 | > | } |
1271 | ||
1272 | < | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
1273 | < | rb->setSnapshotManager(sman_); |
1274 | < | } |
1272 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
1273 | > | rb->setSnapshotManager(sman_); |
1274 | > | } |
1275 | } | |
1276 | ||
1277 | < | } |
1277 | > | } |
1278 | ||
1279 | < | Vector3d SimInfo::getComVel(){ |
1279 | > | Vector3d SimInfo::getComVel(){ |
1280 | SimInfo::MoleculeIterator i; | |
1281 | Molecule* mol; | |
1282 | ||
1283 | Vector3d comVel(0.0); | |
1284 | < | double totalMass = 0.0; |
1284 | > | RealType totalMass = 0.0; |
1285 | ||
1286 | ||
1287 | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | |
1288 | < | double mass = mol->getMass(); |
1289 | < | totalMass += mass; |
1290 | < | comVel += mass * mol->getComVel(); |
1288 | > | RealType mass = mol->getMass(); |
1289 | > | totalMass += mass; |
1290 | > | comVel += mass * mol->getComVel(); |
1291 | } | |
1292 | ||
1293 | #ifdef IS_MPI | |
1294 | < | double tmpMass = totalMass; |
1294 | > | RealType tmpMass = totalMass; |
1295 | Vector3d tmpComVel(comVel); | |
1296 | < | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1297 | < | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1296 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1297 | > | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1298 | #endif | |
1299 | ||
1300 | comVel /= totalMass; | |
1301 | ||
1302 | return comVel; | |
1303 | < | } |
1303 | > | } |
1304 | ||
1305 | < | Vector3d SimInfo::getCom(){ |
1305 | > | Vector3d SimInfo::getCom(){ |
1306 | SimInfo::MoleculeIterator i; | |
1307 | Molecule* mol; | |
1308 | ||
1309 | Vector3d com(0.0); | |
1310 | < | double totalMass = 0.0; |
1310 | > | RealType totalMass = 0.0; |
1311 | ||
1312 | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | |
1313 | < | double mass = mol->getMass(); |
1314 | < | totalMass += mass; |
1315 | < | com += mass * mol->getCom(); |
1313 | > | RealType mass = mol->getMass(); |
1314 | > | totalMass += mass; |
1315 | > | com += mass * mol->getCom(); |
1316 | } | |
1317 | ||
1318 | #ifdef IS_MPI | |
1319 | < | double tmpMass = totalMass; |
1319 | > | RealType tmpMass = totalMass; |
1320 | Vector3d tmpCom(com); | |
1321 | < | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1322 | < | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
1321 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1322 | > | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1323 | #endif | |
1324 | ||
1325 | com /= totalMass; | |
1326 | ||
1327 | return com; | |
1328 | ||
1329 | < | } |
1329 | > | } |
1330 | ||
1331 | < | std::ostream& operator <<(std::ostream& o, SimInfo& info) { |
1331 | > | std::ostream& operator <<(std::ostream& o, SimInfo& info) { |
1332 | ||
1333 | return o; | |
1334 | < | } |
1334 | > | } |
1335 | > | |
1336 | > | |
1337 | > | /* |
1338 | > | Returns center of mass and center of mass velocity in one function call. |
1339 | > | */ |
1340 | > | |
1341 | > | void SimInfo::getComAll(Vector3d &com, Vector3d &comVel){ |
1342 | > | SimInfo::MoleculeIterator i; |
1343 | > | Molecule* mol; |
1344 | > | |
1345 | > | |
1346 | > | RealType totalMass = 0.0; |
1347 | > | |
1348 | ||
1349 | + | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1350 | + | RealType mass = mol->getMass(); |
1351 | + | totalMass += mass; |
1352 | + | com += mass * mol->getCom(); |
1353 | + | comVel += mass * mol->getComVel(); |
1354 | + | } |
1355 | + | |
1356 | + | #ifdef IS_MPI |
1357 | + | RealType tmpMass = totalMass; |
1358 | + | Vector3d tmpCom(com); |
1359 | + | Vector3d tmpComVel(comVel); |
1360 | + | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1361 | + | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1362 | + | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1363 | + | #endif |
1364 | + | |
1365 | + | com /= totalMass; |
1366 | + | comVel /= totalMass; |
1367 | + | } |
1368 | + | |
1369 | + | /* |
1370 | + | Return intertia tensor for entire system and angular momentum Vector. |
1371 | + | |
1372 | + | |
1373 | + | [ Ixx -Ixy -Ixz ] |
1374 | + | J =| -Iyx Iyy -Iyz | |
1375 | + | [ -Izx -Iyz Izz ] |
1376 | + | */ |
1377 | + | |
1378 | + | void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){ |
1379 | + | |
1380 | + | |
1381 | + | RealType xx = 0.0; |
1382 | + | RealType yy = 0.0; |
1383 | + | RealType zz = 0.0; |
1384 | + | RealType xy = 0.0; |
1385 | + | RealType xz = 0.0; |
1386 | + | RealType yz = 0.0; |
1387 | + | Vector3d com(0.0); |
1388 | + | Vector3d comVel(0.0); |
1389 | + | |
1390 | + | getComAll(com, comVel); |
1391 | + | |
1392 | + | SimInfo::MoleculeIterator i; |
1393 | + | Molecule* mol; |
1394 | + | |
1395 | + | Vector3d thisq(0.0); |
1396 | + | Vector3d thisv(0.0); |
1397 | + | |
1398 | + | RealType thisMass = 0.0; |
1399 | + | |
1400 | + | |
1401 | + | |
1402 | + | |
1403 | + | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1404 | + | |
1405 | + | thisq = mol->getCom()-com; |
1406 | + | thisv = mol->getComVel()-comVel; |
1407 | + | thisMass = mol->getMass(); |
1408 | + | // Compute moment of intertia coefficients. |
1409 | + | xx += thisq[0]*thisq[0]*thisMass; |
1410 | + | yy += thisq[1]*thisq[1]*thisMass; |
1411 | + | zz += thisq[2]*thisq[2]*thisMass; |
1412 | + | |
1413 | + | // compute products of intertia |
1414 | + | xy += thisq[0]*thisq[1]*thisMass; |
1415 | + | xz += thisq[0]*thisq[2]*thisMass; |
1416 | + | yz += thisq[1]*thisq[2]*thisMass; |
1417 | + | |
1418 | + | angularMomentum += cross( thisq, thisv ) * thisMass; |
1419 | + | |
1420 | + | } |
1421 | + | |
1422 | + | |
1423 | + | inertiaTensor(0,0) = yy + zz; |
1424 | + | inertiaTensor(0,1) = -xy; |
1425 | + | inertiaTensor(0,2) = -xz; |
1426 | + | inertiaTensor(1,0) = -xy; |
1427 | + | inertiaTensor(1,1) = xx + zz; |
1428 | + | inertiaTensor(1,2) = -yz; |
1429 | + | inertiaTensor(2,0) = -xz; |
1430 | + | inertiaTensor(2,1) = -yz; |
1431 | + | inertiaTensor(2,2) = xx + yy; |
1432 | + | |
1433 | + | #ifdef IS_MPI |
1434 | + | Mat3x3d tmpI(inertiaTensor); |
1435 | + | Vector3d tmpAngMom; |
1436 | + | MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1437 | + | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1438 | + | #endif |
1439 | + | |
1440 | + | return; |
1441 | + | } |
1442 | + | |
1443 | + | //Returns the angular momentum of the system |
1444 | + | Vector3d SimInfo::getAngularMomentum(){ |
1445 | + | |
1446 | + | Vector3d com(0.0); |
1447 | + | Vector3d comVel(0.0); |
1448 | + | Vector3d angularMomentum(0.0); |
1449 | + | |
1450 | + | getComAll(com,comVel); |
1451 | + | |
1452 | + | SimInfo::MoleculeIterator i; |
1453 | + | Molecule* mol; |
1454 | + | |
1455 | + | Vector3d thisr(0.0); |
1456 | + | Vector3d thisp(0.0); |
1457 | + | |
1458 | + | RealType thisMass; |
1459 | + | |
1460 | + | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1461 | + | thisMass = mol->getMass(); |
1462 | + | thisr = mol->getCom()-com; |
1463 | + | thisp = (mol->getComVel()-comVel)*thisMass; |
1464 | + | |
1465 | + | angularMomentum += cross( thisr, thisp ); |
1466 | + | |
1467 | + | } |
1468 | + | |
1469 | + | #ifdef IS_MPI |
1470 | + | Vector3d tmpAngMom; |
1471 | + | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1472 | + | #endif |
1473 | + | |
1474 | + | return angularMomentum; |
1475 | + | } |
1476 | + | |
1477 | + | StuntDouble* SimInfo::getIOIndexToIntegrableObject(int index) { |
1478 | + | return IOIndexToIntegrableObject.at(index); |
1479 | + | } |
1480 | + | |
1481 | + | void SimInfo::setIOIndexToIntegrableObject(const std::vector<StuntDouble*>& v) { |
1482 | + | IOIndexToIntegrableObject= v; |
1483 | + | } |
1484 | + | |
1485 | + | /* Returns the Volume of the simulation based on a ellipsoid with semi-axes |
1486 | + | based on the radius of gyration V=4/3*Pi*R_1*R_2*R_3 |
1487 | + | where R_i are related to the principle inertia moments R_i = sqrt(C*I_i/N), this reduces to |
1488 | + | V = 4/3*Pi*(C/N)^3/2*sqrt(det(I)). See S.E. Baltazar et. al. Comp. Mat. Sci. 37 (2006) 526-536. |
1489 | + | */ |
1490 | + | void SimInfo::getGyrationalVolume(RealType &volume){ |
1491 | + | Mat3x3d intTensor; |
1492 | + | RealType det; |
1493 | + | Vector3d dummyAngMom; |
1494 | + | RealType sysconstants; |
1495 | + | RealType geomCnst; |
1496 | + | |
1497 | + | geomCnst = 3.0/2.0; |
1498 | + | /* Get the inertial tensor and angular momentum for free*/ |
1499 | + | getInertiaTensor(intTensor,dummyAngMom); |
1500 | + | |
1501 | + | det = intTensor.determinant(); |
1502 | + | sysconstants = geomCnst/(RealType)nGlobalIntegrableObjects_; |
1503 | + | volume = 4.0/3.0*NumericConstant::PI*pow(sysconstants,3.0/2.0)*sqrt(det); |
1504 | + | return; |
1505 | + | } |
1506 | + | |
1507 | + | void SimInfo::getGyrationalVolume(RealType &volume, RealType &detI){ |
1508 | + | Mat3x3d intTensor; |
1509 | + | Vector3d dummyAngMom; |
1510 | + | RealType sysconstants; |
1511 | + | RealType geomCnst; |
1512 | + | |
1513 | + | geomCnst = 3.0/2.0; |
1514 | + | /* Get the inertial tensor and angular momentum for free*/ |
1515 | + | getInertiaTensor(intTensor,dummyAngMom); |
1516 | + | |
1517 | + | detI = intTensor.determinant(); |
1518 | + | sysconstants = geomCnst/(RealType)nGlobalIntegrableObjects_; |
1519 | + | volume = 4.0/3.0*NumericConstant::PI*pow(sysconstants,3.0/2.0)*sqrt(detI); |
1520 | + | return; |
1521 | + | } |
1522 | + | /* |
1523 | + | void SimInfo::setStuntDoubleFromGlobalIndex(std::vector<StuntDouble*> v) { |
1524 | + | assert( v.size() == nAtoms_ + nRigidBodies_); |
1525 | + | sdByGlobalIndex_ = v; |
1526 | + | } |
1527 | + | |
1528 | + | StuntDouble* SimInfo::getStuntDoubleFromGlobalIndex(int index) { |
1529 | + | //assert(index < nAtoms_ + nRigidBodies_); |
1530 | + | return sdByGlobalIndex_.at(index); |
1531 | + | } |
1532 | + | */ |
1533 | }//end namespace oopse | |
1534 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |