ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/brains/SimInfo.cpp
Revision: 2082
Committed: Mon Mar 7 22:39:33 2005 UTC (19 years, 4 months ago) by tim
File size: 28679 byte(s)
Log Message:
Fixing a bug in BitSet.cpp

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Acknowledgement of the program authors must be made in any
10 * publication of scientific results based in part on use of the
11 * program. An acceptable form of acknowledgement is citation of
12 * the article in which the program was described (Matthew
13 * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 * Parallel Simulation Engine for Molecular Dynamics,"
16 * J. Comput. Chem. 26, pp. 252-271 (2005))
17 *
18 * 2. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 3. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * This software is provided "AS IS," without a warranty of any
27 * kind. All express or implied conditions, representations and
28 * warranties, including any implied warranty of merchantability,
29 * fitness for a particular purpose or non-infringement, are hereby
30 * excluded. The University of Notre Dame and its licensors shall not
31 * be liable for any damages suffered by licensee as a result of
32 * using, modifying or distributing the software or its
33 * derivatives. In no event will the University of Notre Dame or its
34 * licensors be liable for any lost revenue, profit or data, or for
35 * direct, indirect, special, consequential, incidental or punitive
36 * damages, however caused and regardless of the theory of liability,
37 * arising out of the use of or inability to use software, even if the
38 * University of Notre Dame has been advised of the possibility of
39 * such damages.
40 */
41
42 /**
43 * @file SimInfo.cpp
44 * @author tlin
45 * @date 11/02/2004
46 * @version 1.0
47 */
48
49 #include <algorithm>
50 #include <set>
51
52 #include "brains/SimInfo.hpp"
53 #include "math/Vector3.hpp"
54 #include "primitives/Molecule.hpp"
55 #include "UseTheForce/doForces_interface.h"
56 #include "UseTheForce/notifyCutoffs_interface.h"
57 #include "utils/MemoryUtils.hpp"
58 #include "utils/simError.h"
59 #include "selection/SelectionManager.hpp"
60
61 #ifdef IS_MPI
62 #include "UseTheForce/mpiComponentPlan.h"
63 #include "UseTheForce/DarkSide/simParallel_interface.h"
64 #endif
65
66 namespace oopse {
67
68 SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
69 ForceField* ff, Globals* simParams) :
70 forceField_(ff), simParams_(simParams),
71 ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
72 nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
73 nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
74 nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0),
75 nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0),
76 sman_(NULL), fortranInitialized_(false), selectMan_(NULL) {
77
78
79 std::vector<std::pair<MoleculeStamp*, int> >::iterator i;
80 MoleculeStamp* molStamp;
81 int nMolWithSameStamp;
82 int nCutoffAtoms = 0; // number of atoms belong to cutoff groups
83 int nGroups = 0; //total cutoff groups defined in meta-data file
84 CutoffGroupStamp* cgStamp;
85 RigidBodyStamp* rbStamp;
86 int nRigidAtoms = 0;
87
88 for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) {
89 molStamp = i->first;
90 nMolWithSameStamp = i->second;
91
92 addMoleculeStamp(molStamp, nMolWithSameStamp);
93
94 //calculate atoms in molecules
95 nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;
96
97
98 //calculate atoms in cutoff groups
99 int nAtomsInGroups = 0;
100 int nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
101
102 for (int j=0; j < nCutoffGroupsInStamp; j++) {
103 cgStamp = molStamp->getCutoffGroup(j);
104 nAtomsInGroups += cgStamp->getNMembers();
105 }
106
107 nGroups += nCutoffGroupsInStamp * nMolWithSameStamp;
108 nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp;
109
110 //calculate atoms in rigid bodies
111 int nAtomsInRigidBodies = 0;
112 int nRigidBodiesInStamp = molStamp->getNRigidBodies();
113
114 for (int j=0; j < nRigidBodiesInStamp; j++) {
115 rbStamp = molStamp->getRigidBody(j);
116 nAtomsInRigidBodies += rbStamp->getNMembers();
117 }
118
119 nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp;
120 nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp;
121
122 }
123
124 //every free atom (atom does not belong to cutoff groups) is a cutoff group
125 //therefore the total number of cutoff groups in the system is equal to
126 //the total number of atoms minus number of atoms belong to cutoff group defined in meta-data
127 //file plus the number of cutoff groups defined in meta-data file
128 nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
129
130 //every free atom (atom does not belong to rigid bodies) is an integrable object
131 //therefore the total number of integrable objects in the system is equal to
132 //the total number of atoms minus number of atoms belong to rigid body defined in meta-data
133 //file plus the number of rigid bodies defined in meta-data file
134 nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nGlobalRigidBodies_;
135
136 nGlobalMols_ = molStampIds_.size();
137
138 #ifdef IS_MPI
139 molToProcMap_.resize(nGlobalMols_);
140 #endif
141
142 selectMan_ = new SelectionManager(this);
143 selectMan_->selectAll();
144 }
145
146 SimInfo::~SimInfo() {
147 std::map<int, Molecule*>::iterator i;
148 for (i = molecules_.begin(); i != molecules_.end(); ++i) {
149 delete i->second;
150 }
151 molecules_.clear();
152
153 MemoryUtils::deletePointers(moleculeStamps_);
154
155 delete sman_;
156 delete simParams_;
157 delete forceField_;
158 delete selectMan_;
159 }
160
161 int SimInfo::getNGlobalConstraints() {
162 int nGlobalConstraints;
163 #ifdef IS_MPI
164 MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM,
165 MPI_COMM_WORLD);
166 #else
167 nGlobalConstraints = nConstraints_;
168 #endif
169 return nGlobalConstraints;
170 }
171
172 bool SimInfo::addMolecule(Molecule* mol) {
173 MoleculeIterator i;
174
175 i = molecules_.find(mol->getGlobalIndex());
176 if (i == molecules_.end() ) {
177
178 molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol));
179
180 nAtoms_ += mol->getNAtoms();
181 nBonds_ += mol->getNBonds();
182 nBends_ += mol->getNBends();
183 nTorsions_ += mol->getNTorsions();
184 nRigidBodies_ += mol->getNRigidBodies();
185 nIntegrableObjects_ += mol->getNIntegrableObjects();
186 nCutoffGroups_ += mol->getNCutoffGroups();
187 nConstraints_ += mol->getNConstraintPairs();
188
189 addExcludePairs(mol);
190
191 return true;
192 } else {
193 return false;
194 }
195 }
196
197 bool SimInfo::removeMolecule(Molecule* mol) {
198 MoleculeIterator i;
199 i = molecules_.find(mol->getGlobalIndex());
200
201 if (i != molecules_.end() ) {
202
203 assert(mol == i->second);
204
205 nAtoms_ -= mol->getNAtoms();
206 nBonds_ -= mol->getNBonds();
207 nBends_ -= mol->getNBends();
208 nTorsions_ -= mol->getNTorsions();
209 nRigidBodies_ -= mol->getNRigidBodies();
210 nIntegrableObjects_ -= mol->getNIntegrableObjects();
211 nCutoffGroups_ -= mol->getNCutoffGroups();
212 nConstraints_ -= mol->getNConstraintPairs();
213
214 removeExcludePairs(mol);
215 molecules_.erase(mol->getGlobalIndex());
216
217 delete mol;
218
219 return true;
220 } else {
221 return false;
222 }
223
224
225 }
226
227
228 Molecule* SimInfo::beginMolecule(MoleculeIterator& i) {
229 i = molecules_.begin();
230 return i == molecules_.end() ? NULL : i->second;
231 }
232
233 Molecule* SimInfo::nextMolecule(MoleculeIterator& i) {
234 ++i;
235 return i == molecules_.end() ? NULL : i->second;
236 }
237
238
239 void SimInfo::calcNdf() {
240 int ndf_local;
241 MoleculeIterator i;
242 std::vector<StuntDouble*>::iterator j;
243 Molecule* mol;
244 StuntDouble* integrableObject;
245
246 ndf_local = 0;
247
248 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
249 for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
250 integrableObject = mol->nextIntegrableObject(j)) {
251
252 ndf_local += 3;
253
254 if (integrableObject->isDirectional()) {
255 if (integrableObject->isLinear()) {
256 ndf_local += 2;
257 } else {
258 ndf_local += 3;
259 }
260 }
261
262 }//end for (integrableObject)
263 }// end for (mol)
264
265 // n_constraints is local, so subtract them on each processor
266 ndf_local -= nConstraints_;
267
268 #ifdef IS_MPI
269 MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
270 #else
271 ndf_ = ndf_local;
272 #endif
273
274 // nZconstraints_ is global, as are the 3 COM translations for the
275 // entire system:
276 ndf_ = ndf_ - 3 - nZconstraint_;
277
278 }
279
280 void SimInfo::calcNdfRaw() {
281 int ndfRaw_local;
282
283 MoleculeIterator i;
284 std::vector<StuntDouble*>::iterator j;
285 Molecule* mol;
286 StuntDouble* integrableObject;
287
288 // Raw degrees of freedom that we have to set
289 ndfRaw_local = 0;
290
291 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
292 for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
293 integrableObject = mol->nextIntegrableObject(j)) {
294
295 ndfRaw_local += 3;
296
297 if (integrableObject->isDirectional()) {
298 if (integrableObject->isLinear()) {
299 ndfRaw_local += 2;
300 } else {
301 ndfRaw_local += 3;
302 }
303 }
304
305 }
306 }
307
308 #ifdef IS_MPI
309 MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
310 #else
311 ndfRaw_ = ndfRaw_local;
312 #endif
313 }
314
315 void SimInfo::calcNdfTrans() {
316 int ndfTrans_local;
317
318 ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
319
320
321 #ifdef IS_MPI
322 MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
323 #else
324 ndfTrans_ = ndfTrans_local;
325 #endif
326
327 ndfTrans_ = ndfTrans_ - 3 - nZconstraint_;
328
329 }
330
331 void SimInfo::addExcludePairs(Molecule* mol) {
332 std::vector<Bond*>::iterator bondIter;
333 std::vector<Bend*>::iterator bendIter;
334 std::vector<Torsion*>::iterator torsionIter;
335 Bond* bond;
336 Bend* bend;
337 Torsion* torsion;
338 int a;
339 int b;
340 int c;
341 int d;
342
343 for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
344 a = bond->getAtomA()->getGlobalIndex();
345 b = bond->getAtomB()->getGlobalIndex();
346 exclude_.addPair(a, b);
347 }
348
349 for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
350 a = bend->getAtomA()->getGlobalIndex();
351 b = bend->getAtomB()->getGlobalIndex();
352 c = bend->getAtomC()->getGlobalIndex();
353
354 exclude_.addPair(a, b);
355 exclude_.addPair(a, c);
356 exclude_.addPair(b, c);
357 }
358
359 for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
360 a = torsion->getAtomA()->getGlobalIndex();
361 b = torsion->getAtomB()->getGlobalIndex();
362 c = torsion->getAtomC()->getGlobalIndex();
363 d = torsion->getAtomD()->getGlobalIndex();
364
365 exclude_.addPair(a, b);
366 exclude_.addPair(a, c);
367 exclude_.addPair(a, d);
368 exclude_.addPair(b, c);
369 exclude_.addPair(b, d);
370 exclude_.addPair(c, d);
371 }
372
373
374 }
375
376 void SimInfo::removeExcludePairs(Molecule* mol) {
377 std::vector<Bond*>::iterator bondIter;
378 std::vector<Bend*>::iterator bendIter;
379 std::vector<Torsion*>::iterator torsionIter;
380 Bond* bond;
381 Bend* bend;
382 Torsion* torsion;
383 int a;
384 int b;
385 int c;
386 int d;
387
388 for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
389 a = bond->getAtomA()->getGlobalIndex();
390 b = bond->getAtomB()->getGlobalIndex();
391 exclude_.removePair(a, b);
392 }
393
394 for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
395 a = bend->getAtomA()->getGlobalIndex();
396 b = bend->getAtomB()->getGlobalIndex();
397 c = bend->getAtomC()->getGlobalIndex();
398
399 exclude_.removePair(a, b);
400 exclude_.removePair(a, c);
401 exclude_.removePair(b, c);
402 }
403
404 for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
405 a = torsion->getAtomA()->getGlobalIndex();
406 b = torsion->getAtomB()->getGlobalIndex();
407 c = torsion->getAtomC()->getGlobalIndex();
408 d = torsion->getAtomD()->getGlobalIndex();
409
410 exclude_.removePair(a, b);
411 exclude_.removePair(a, c);
412 exclude_.removePair(a, d);
413 exclude_.removePair(b, c);
414 exclude_.removePair(b, d);
415 exclude_.removePair(c, d);
416 }
417
418 }
419
420
421 void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) {
422 int curStampId;
423
424 //index from 0
425 curStampId = moleculeStamps_.size();
426
427 moleculeStamps_.push_back(molStamp);
428 molStampIds_.insert(molStampIds_.end(), nmol, curStampId);
429 }
430
431 void SimInfo::update() {
432
433 setupSimType();
434
435 #ifdef IS_MPI
436 setupFortranParallel();
437 #endif
438
439 setupFortranSim();
440
441 //setup fortran force field
442 /** @deprecate */
443 int isError = 0;
444 initFortranFF( &fInfo_.SIM_uses_RF , &isError );
445 if(isError){
446 sprintf( painCave.errMsg,
447 "ForceField error: There was an error initializing the forceField in fortran.\n" );
448 painCave.isFatal = 1;
449 simError();
450 }
451
452
453 setupCutoff();
454
455 calcNdf();
456 calcNdfRaw();
457 calcNdfTrans();
458
459 fortranInitialized_ = true;
460 }
461
462 std::set<AtomType*> SimInfo::getUniqueAtomTypes() {
463 SimInfo::MoleculeIterator mi;
464 Molecule* mol;
465 Molecule::AtomIterator ai;
466 Atom* atom;
467 std::set<AtomType*> atomTypes;
468
469 for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
470
471 for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
472 atomTypes.insert(atom->getAtomType());
473 }
474
475 }
476
477 return atomTypes;
478 }
479
480 void SimInfo::setupSimType() {
481 std::set<AtomType*>::iterator i;
482 std::set<AtomType*> atomTypes;
483 atomTypes = getUniqueAtomTypes();
484
485 int useLennardJones = 0;
486 int useElectrostatic = 0;
487 int useEAM = 0;
488 int useCharge = 0;
489 int useDirectional = 0;
490 int useDipole = 0;
491 int useGayBerne = 0;
492 int useSticky = 0;
493 int useShape = 0;
494 int useFLARB = 0; //it is not in AtomType yet
495 int useDirectionalAtom = 0;
496 int useElectrostatics = 0;
497 //usePBC and useRF are from simParams
498 int usePBC = simParams_->getPBC();
499 int useRF = simParams_->getUseRF();
500
501 //loop over all of the atom types
502 for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
503 useLennardJones |= (*i)->isLennardJones();
504 useElectrostatic |= (*i)->isElectrostatic();
505 useEAM |= (*i)->isEAM();
506 useCharge |= (*i)->isCharge();
507 useDirectional |= (*i)->isDirectional();
508 useDipole |= (*i)->isDipole();
509 useGayBerne |= (*i)->isGayBerne();
510 useSticky |= (*i)->isSticky();
511 useShape |= (*i)->isShape();
512 }
513
514 if (useSticky || useDipole || useGayBerne || useShape) {
515 useDirectionalAtom = 1;
516 }
517
518 if (useCharge || useDipole) {
519 useElectrostatics = 1;
520 }
521
522 #ifdef IS_MPI
523 int temp;
524
525 temp = usePBC;
526 MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
527
528 temp = useDirectionalAtom;
529 MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
530
531 temp = useLennardJones;
532 MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
533
534 temp = useElectrostatics;
535 MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
536
537 temp = useCharge;
538 MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
539
540 temp = useDipole;
541 MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
542
543 temp = useSticky;
544 MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
545
546 temp = useGayBerne;
547 MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
548
549 temp = useEAM;
550 MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
551
552 temp = useShape;
553 MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
554
555 temp = useFLARB;
556 MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
557
558 temp = useRF;
559 MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
560
561 #endif
562
563 fInfo_.SIM_uses_PBC = usePBC;
564 fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom;
565 fInfo_.SIM_uses_LennardJones = useLennardJones;
566 fInfo_.SIM_uses_Electrostatics = useElectrostatics;
567 fInfo_.SIM_uses_Charges = useCharge;
568 fInfo_.SIM_uses_Dipoles = useDipole;
569 fInfo_.SIM_uses_Sticky = useSticky;
570 fInfo_.SIM_uses_GayBerne = useGayBerne;
571 fInfo_.SIM_uses_EAM = useEAM;
572 fInfo_.SIM_uses_Shapes = useShape;
573 fInfo_.SIM_uses_FLARB = useFLARB;
574 fInfo_.SIM_uses_RF = useRF;
575
576 if( fInfo_.SIM_uses_Dipoles && fInfo_.SIM_uses_RF) {
577
578 if (simParams_->haveDielectric()) {
579 fInfo_.dielect = simParams_->getDielectric();
580 } else {
581 sprintf(painCave.errMsg,
582 "SimSetup Error: No Dielectric constant was set.\n"
583 "\tYou are trying to use Reaction Field without"
584 "\tsetting a dielectric constant!\n");
585 painCave.isFatal = 1;
586 simError();
587 }
588
589 } else {
590 fInfo_.dielect = 0.0;
591 }
592
593 }
594
595 void SimInfo::setupFortranSim() {
596 int isError;
597 int nExclude;
598 std::vector<int> fortranGlobalGroupMembership;
599
600 nExclude = exclude_.getSize();
601 isError = 0;
602
603 //globalGroupMembership_ is filled by SimCreator
604 for (int i = 0; i < nGlobalAtoms_; i++) {
605 fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
606 }
607
608 //calculate mass ratio of cutoff group
609 std::vector<double> mfact;
610 SimInfo::MoleculeIterator mi;
611 Molecule* mol;
612 Molecule::CutoffGroupIterator ci;
613 CutoffGroup* cg;
614 Molecule::AtomIterator ai;
615 Atom* atom;
616 double totalMass;
617
618 //to avoid memory reallocation, reserve enough space for mfact
619 mfact.reserve(getNCutoffGroups());
620
621 for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
622 for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
623
624 totalMass = cg->getMass();
625 for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
626 mfact.push_back(atom->getMass()/totalMass);
627 }
628
629 }
630 }
631
632 //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!)
633 std::vector<int> identArray;
634
635 //to avoid memory reallocation, reserve enough space identArray
636 identArray.reserve(getNAtoms());
637
638 for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
639 for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
640 identArray.push_back(atom->getIdent());
641 }
642 }
643
644 //fill molMembershipArray
645 //molMembershipArray is filled by SimCreator
646 std::vector<int> molMembershipArray(nGlobalAtoms_);
647 for (int i = 0; i < nGlobalAtoms_; i++) {
648 molMembershipArray[i] = globalMolMembership_[i] + 1;
649 }
650
651 //setup fortran simulation
652 //gloalExcludes and molMembershipArray should go away (They are never used)
653 //why the hell fortran need to know molecule?
654 //OOPSE = Object-Obfuscated Parallel Simulation Engine
655 int nGlobalExcludes = 0;
656 int* globalExcludes = NULL;
657 int* excludeList = exclude_.getExcludeList();
658 setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList ,
659 &nGlobalExcludes, globalExcludes, &molMembershipArray[0],
660 &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError);
661
662 if( isError ){
663
664 sprintf( painCave.errMsg,
665 "There was an error setting the simulation information in fortran.\n" );
666 painCave.isFatal = 1;
667 painCave.severity = OOPSE_ERROR;
668 simError();
669 }
670
671 #ifdef IS_MPI
672 sprintf( checkPointMsg,
673 "succesfully sent the simulation information to fortran.\n");
674 MPIcheckPoint();
675 #endif // is_mpi
676 }
677
678
679 #ifdef IS_MPI
680 void SimInfo::setupFortranParallel() {
681
682 //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex
683 std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0);
684 std::vector<int> localToGlobalCutoffGroupIndex;
685 SimInfo::MoleculeIterator mi;
686 Molecule::AtomIterator ai;
687 Molecule::CutoffGroupIterator ci;
688 Molecule* mol;
689 Atom* atom;
690 CutoffGroup* cg;
691 mpiSimData parallelData;
692 int isError;
693
694 for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
695
696 //local index(index in DataStorge) of atom is important
697 for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
698 localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1;
699 }
700
701 //local index of cutoff group is trivial, it only depends on the order of travesing
702 for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
703 localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1);
704 }
705
706 }
707
708 //fill up mpiSimData struct
709 parallelData.nMolGlobal = getNGlobalMolecules();
710 parallelData.nMolLocal = getNMolecules();
711 parallelData.nAtomsGlobal = getNGlobalAtoms();
712 parallelData.nAtomsLocal = getNAtoms();
713 parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
714 parallelData.nGroupsLocal = getNCutoffGroups();
715 parallelData.myNode = worldRank;
716 MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
717
718 //pass mpiSimData struct and index arrays to fortran
719 setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
720 &localToGlobalAtomIndex[0], &(parallelData.nGroupsLocal),
721 &localToGlobalCutoffGroupIndex[0], &isError);
722
723 if (isError) {
724 sprintf(painCave.errMsg,
725 "mpiRefresh errror: fortran didn't like something we gave it.\n");
726 painCave.isFatal = 1;
727 simError();
728 }
729
730 sprintf(checkPointMsg, " mpiRefresh successful.\n");
731 MPIcheckPoint();
732
733
734 }
735
736 #endif
737
738 double SimInfo::calcMaxCutoffRadius() {
739
740
741 std::set<AtomType*> atomTypes;
742 std::set<AtomType*>::iterator i;
743 std::vector<double> cutoffRadius;
744
745 //get the unique atom types
746 atomTypes = getUniqueAtomTypes();
747
748 //query the max cutoff radius among these atom types
749 for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
750 cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i));
751 }
752
753 double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end()));
754 #ifdef IS_MPI
755 //pick the max cutoff radius among the processors
756 #endif
757
758 return maxCutoffRadius;
759 }
760
761 void SimInfo::getCutoff(double& rcut, double& rsw) {
762
763 if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
764
765 if (!simParams_->haveRcut()){
766 sprintf(painCave.errMsg,
767 "SimCreator Warning: No value was set for the cutoffRadius.\n"
768 "\tOOPSE will use a default value of 15.0 angstroms"
769 "\tfor the cutoffRadius.\n");
770 painCave.isFatal = 0;
771 simError();
772 rcut = 15.0;
773 } else{
774 rcut = simParams_->getRcut();
775 }
776
777 if (!simParams_->haveRsw()){
778 sprintf(painCave.errMsg,
779 "SimCreator Warning: No value was set for switchingRadius.\n"
780 "\tOOPSE will use a default value of\n"
781 "\t0.95 * cutoffRadius for the switchingRadius\n");
782 painCave.isFatal = 0;
783 simError();
784 rsw = 0.95 * rcut;
785 } else{
786 rsw = simParams_->getRsw();
787 }
788
789 } else {
790 // if charge, dipole or reaction field is not used and the cutofff radius is not specified in
791 //meta-data file, the maximum cutoff radius calculated from forcefiled will be used
792
793 if (simParams_->haveRcut()) {
794 rcut = simParams_->getRcut();
795 } else {
796 //set cutoff radius to the maximum cutoff radius based on atom types in the whole system
797 rcut = calcMaxCutoffRadius();
798 }
799
800 if (simParams_->haveRsw()) {
801 rsw = simParams_->getRsw();
802 } else {
803 rsw = rcut;
804 }
805
806 }
807 }
808
809 void SimInfo::setupCutoff() {
810 getCutoff(rcut_, rsw_);
811 double rnblist = rcut_ + 1; // skin of neighbor list
812
813 //Pass these cutoff radius etc. to fortran. This function should be called once and only once
814 notifyFortranCutoffs(&rcut_, &rsw_, &rnblist);
815 }
816
817 void SimInfo::addProperty(GenericData* genData) {
818 properties_.addProperty(genData);
819 }
820
821 void SimInfo::removeProperty(const std::string& propName) {
822 properties_.removeProperty(propName);
823 }
824
825 void SimInfo::clearProperties() {
826 properties_.clearProperties();
827 }
828
829 std::vector<std::string> SimInfo::getPropertyNames() {
830 return properties_.getPropertyNames();
831 }
832
833 std::vector<GenericData*> SimInfo::getProperties() {
834 return properties_.getProperties();
835 }
836
837 GenericData* SimInfo::getPropertyByName(const std::string& propName) {
838 return properties_.getPropertyByName(propName);
839 }
840
841 void SimInfo::setSnapshotManager(SnapshotManager* sman) {
842 //if (sman_ == sman_) {
843 // return;
844 //}
845
846 //delete sman_;
847 sman_ = sman;
848
849 Molecule* mol;
850 RigidBody* rb;
851 Atom* atom;
852 SimInfo::MoleculeIterator mi;
853 Molecule::RigidBodyIterator rbIter;
854 Molecule::AtomIterator atomIter;;
855
856 for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
857
858 for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) {
859 atom->setSnapshotManager(sman_);
860 }
861
862 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
863 rb->setSnapshotManager(sman_);
864 }
865 }
866
867 }
868
869 Vector3d SimInfo::getComVel(){
870 SimInfo::MoleculeIterator i;
871 Molecule* mol;
872
873 Vector3d comVel(0.0);
874 double totalMass = 0.0;
875
876
877 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
878 double mass = mol->getMass();
879 totalMass += mass;
880 comVel += mass * mol->getComVel();
881 }
882
883 #ifdef IS_MPI
884 double tmpMass = totalMass;
885 Vector3d tmpComVel(comVel);
886 MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
887 MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
888 #endif
889
890 comVel /= totalMass;
891
892 return comVel;
893 }
894
895 Vector3d SimInfo::getCom(){
896 SimInfo::MoleculeIterator i;
897 Molecule* mol;
898
899 Vector3d com(0.0);
900 double totalMass = 0.0;
901
902 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
903 double mass = mol->getMass();
904 totalMass += mass;
905 com += mass * mol->getCom();
906 }
907
908 #ifdef IS_MPI
909 double tmpMass = totalMass;
910 Vector3d tmpCom(com);
911 MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
912 MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
913 #endif
914
915 com /= totalMass;
916
917 return com;
918
919 }
920
921 std::ostream& operator <<(std::ostream& o, SimInfo& info) {
922
923 return o;
924 }
925
926 }//end namespace oopse
927