ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/brains/SimInfo.cpp
Revision: 1725
Committed: Wed Nov 10 22:01:06 2004 UTC (19 years, 7 months ago) by tim
File size: 8934 byte(s)
Log Message:
another painful day
(1) SimCreator, SimInfo, mpiSimulation
(2) DumpReader, DumpWriter (InitializeFrom File will be removed)
(3) ForceField (at least LJ) and BondType, BendType, TorsionType
(4)Integrator
(5)oopse.cpp
(6)visitors & Dump2XYZ
(7)SimpleBuilder
(8)Constraint & ZConstraint

File Contents

# User Rev Content
1 tim 1710 /*
2     * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project
3     *
4     * Contact: oopse@oopse.org
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU Lesser General Public License
8     * as published by the Free Software Foundation; either version 2.1
9     * of the License, or (at your option) any later version.
10     * All we ask is that proper credit is given for our work, which includes
11     * - but is not limited to - adding the above copyright notice to the beginning
12     * of your source code files, and to any copyright notice that you may distribute
13     * with programs based on this work.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU Lesser General Public License for more details.
19     *
20     * You should have received a copy of the GNU Lesser General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23     *
24     */
25 gezelter 1490
26 tim 1710 /**
27     * @file SimInfo.cpp
28     * @author tlin
29     * @date 11/02/2004
30     * @version 1.0
31     */
32 gezelter 1490
33 tim 1710 #include <algorithm>
34    
35 tim 1492 #include "brains/SimInfo.hpp"
36 tim 1710 #include "utils/MemoryUtils.hpp"
37 gezelter 1490
38 tim 1710 namespace oopse {
39 gezelter 1490
40 tim 1710 SimInfo::SimInfo() : nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0),
41     nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), sman_(NULL){
42 gezelter 1490
43     }
44    
45 tim 1710 SimInfo::~SimInfo() {
46     MemoryUtils::deleteVectorOfPointer(molecules_);
47     delete sman_;
48 gezelter 1490
49     }
50    
51    
52 tim 1710 bool SimInfo::addMolecule(Molecule* mol) {
53     std::vector<Molecule*>::iterator i;
54     i = std::find(molecules_.begin(), molecules_.end(), mol);
55     if (i != molecules_.end() ) {
56     molecules_.push_back(mol);
57 gezelter 1490
58 tim 1710 nAtoms_ += mol->getNAtoms();
59     nBonds_ += mol->getNBonds();
60     nBends_ += mol->getNBends();
61     nTorsions_ += mol->getNTorsions();
62     nRigidBodies_ += mol->getNRigidBodies();
63     nIntegrableObjects_ += mol->getNIntegrableObjects();
64     nCutoffGroups_ += mol->getNCutoffGroups();
65     nConstraints_ += mol->getNConstraints();
66 gezelter 1490
67 tim 1725 globalIndexToMol_.insert(make_pair(mol->getGlobalIndex(), mol));
68 tim 1710 return true;
69     } else {
70     return false;
71 gezelter 1490 }
72     }
73    
74 tim 1710 bool SimInfo::removeMolecule(Molecule* mol) {
75     std::vector<Molecule*>::iterator i;
76     i = std::find(molecules_.begin(), molecules_.end(), mol);
77 gezelter 1490
78 tim 1710 if (i != molecules_.end() ) {
79     molecules_.push_back(mol);
80     nAtoms_ -= mol->getNAtoms();
81     nBonds_ -= mol->getNBonds();
82     nBends_ -= mol->getNBends();
83     nTorsions_ -= mol->getNTorsions();
84     nRigidBodies_ -= mol->getNRigidBodies();
85     nIntegrableObjects_ -= mol->getNIntegrableObjects();
86     nCutoffGroups_ -= mol->getNCutoffGroups();
87     nConstraints_ -= mol->getNConstraints();
88 gezelter 1490
89 tim 1725 globalIndexToMol_.erase(mol->getGlobalIndex());
90 tim 1710 return true;
91     } else {
92     return false;
93 gezelter 1490 }
94    
95    
96 tim 1710 }
97 gezelter 1490
98 tim 1710
99     Molecule* SimInfo::beginMolecule(std::vector<Molecule*>::iterator& i) {
100     i = molecules_.begin();
101     return i == molecules_.end() ? NULL : *i;
102     }
103 gezelter 1490
104 tim 1710 Molecule* SimInfo::nextMolecule(std::vector<Molecule*>::iterator& i) {
105     ++i;
106     return i == molecules_.end() ? NULL : *i;
107 gezelter 1490 }
108    
109    
110 tim 1722 void SimInfo::calcNdf() {
111 tim 1710 int ndf_local;
112     std::vector<Molecule*>::iterator i;
113     std::vector<StuntDouble*>::iterator j;
114     Molecule* mol;
115     StuntDouble* integrableObject;
116 gezelter 1490
117 tim 1710 ndf_local = 0;
118 gezelter 1490
119 tim 1710 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
120     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
121     integrableObject = mol->nextIntegrableObject(j)) {
122 gezelter 1490
123 tim 1710 ndf_local += 3;
124 gezelter 1490
125 tim 1710 if (integrableObject->isDirectional()) {
126     if (integrableObject->isLinear()) {
127     ndf_local += 2;
128     } else {
129     ndf_local += 3;
130     }
131     }
132    
133     }//end for (integrableObject)
134     }// end for (mol)
135 gezelter 1490
136 tim 1710 // n_constraints is local, so subtract them on each processor
137     ndf_local -= nConstraints_;
138 gezelter 1490
139     #ifdef IS_MPI
140 tim 1710 MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
141 gezelter 1490 #else
142 tim 1710 ndf_ = ndf_local;
143 gezelter 1490 #endif
144    
145 tim 1710 // nZconstraints is global, as are the 3 COM translations for the
146     // entire system:
147     ndf_ = ndf_ - 3 - nZconstraints;
148 gezelter 1490
149     }
150    
151 tim 1722 void SimInfo::calcNdfRaw() {
152 tim 1710 int ndfRaw_local;
153 gezelter 1490
154 tim 1710 std::vector<Molecule*>::iterator i;
155     std::vector<StuntDouble*>::iterator j;
156     Molecule* mol;
157     StuntDouble* integrableObject;
158 gezelter 1490
159 tim 1710 // Raw degrees of freedom that we have to set
160     ndfRaw_local = 0;
161 gezelter 1490
162 tim 1710 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
163     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
164     integrableObject = mol->nextIntegrableObject(j)) {
165 gezelter 1490
166 tim 1710 ndfRaw_local += 3;
167 gezelter 1490
168 tim 1710 if (integrableObject->isDirectional()) {
169     if (integrableObject->isLinear()) {
170     ndfRaw_local += 2;
171     } else {
172     ndfRaw_local += 3;
173     }
174     }
175    
176     }
177     }
178    
179 gezelter 1490 #ifdef IS_MPI
180 tim 1710 MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
181 gezelter 1490 #else
182 tim 1710 ndfRaw_ = ndfRaw_local;
183 gezelter 1490 #endif
184     }
185    
186 tim 1722 void SimInfo::calcNdfTrans() {
187 tim 1710 int ndfTrans_local;
188 gezelter 1490
189 tim 1710 ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
190 gezelter 1490
191    
192     #ifdef IS_MPI
193 tim 1710 MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
194 gezelter 1490 #else
195 tim 1710 ndfTrans_ = ndfTrans_local;
196 gezelter 1490 #endif
197    
198 tim 1710 ndfTrans_ = ndfTrans_ - 3 - nZconstraints;
199 gezelter 1490
200     }
201    
202 tim 1719 void SimInfo::addExcludePairs(Molecule* mol) {
203     std::vector<Bond*>::iterator bondIter;
204     std::vector<Bend*>::iterator bendIter;
205     std::vector<Torsion*>::iterator torsionIter;
206     Bond* bond;
207     Bend* bend;
208     Torsion* torsion;
209     int a;
210     int b;
211     int c;
212     int d;
213    
214     for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
215     a = bond->getAtomA()->getGlobalIndex();
216     b = bond->getAtomB()->getGlobalIndex();
217     exclude_.addPair(a, b);
218     }
219 gezelter 1490
220 tim 1719 for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
221     a = bend->getAtomA()->getGlobalIndex();
222     b = bend->getAtomB()->getGlobalIndex();
223     c = bend->getAtomC()->getGlobalIndex();
224    
225     exclude_.addPair(a, b);
226     exclude_.addPair(a, c);
227     exclude_.addPair(b, c);
228     }
229    
230     for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextBond(torsionIter)) {
231     a = torsion->getAtomA()->getGlobalIndex();
232     b = torsion->getAtomB()->getGlobalIndex();
233     c = torsion->getAtomC()->getGlobalIndex();
234     d = torsion->getAtomD()->getGlobalIndex();
235    
236     exclude_.addPair(a, b);
237     exclude_.addPair(a, c);
238     exclude_.addPair(a, d);
239     exclude_.addPair(b, c);
240     exclude_.addPair(b, d);
241     exclude_.addPair(c, d);
242     }
243    
244    
245     }
246    
247     void SimInfo::removeExcludePairs(Molecule* mol) {
248     std::vector<Bond*>::iterator bondIter;
249     std::vector<Bend*>::iterator bendIter;
250     std::vector<Torsion*>::iterator torsionIter;
251     Bond* bond;
252     Bend* bend;
253     Torsion* torsion;
254     int a;
255     int b;
256     int c;
257     int d;
258    
259     for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
260     a = bond->getAtomA()->getGlobalIndex();
261     b = bond->getAtomB()->getGlobalIndex();
262     exclude_.removePair(a, b);
263     }
264    
265     for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
266     a = bend->getAtomA()->getGlobalIndex();
267     b = bend->getAtomB()->getGlobalIndex();
268     c = bend->getAtomC()->getGlobalIndex();
269    
270     exclude_.removePair(a, b);
271     exclude_.removePair(a, c);
272     exclude_.removePair(b, c);
273     }
274    
275     for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextBond(torsionIter)) {
276     a = torsion->getAtomA()->getGlobalIndex();
277     b = torsion->getAtomB()->getGlobalIndex();
278     c = torsion->getAtomC()->getGlobalIndex();
279     d = torsion->getAtomD()->getGlobalIndex();
280    
281     exclude_.removePair(a, b);
282     exclude_.removePair(a, c);
283     exclude_.removePair(a, d);
284     exclude_.removePair(b, c);
285     exclude_.removePair(b, d);
286     exclude_.removePair(c, d);
287     }
288    
289     }
290    
291    
292 tim 1725 void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) {
293     int curStampId;
294    
295     //index from 0
296     curStampId = molStampIds_.size();
297    
298     moleculeStamps_.push_back(molStamp);
299     molStampIds_.insert(molStampIds_.end(), nmol, curStampId)
300     }
301    
302     std::ostream& operator <<(ostream& o, SimInfo& info) {
303    
304     return o;
305     }
306    
307 tim 1710 }//end namespace oopse