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: 1726
Committed: Wed Nov 10 22:50:03 2004 UTC (19 years, 7 months ago) by tim
File size: 8796 byte(s)
Log Message:
more work on SimInfo

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