ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/brains/SimInfo.cpp
Revision: 1722
Committed: Tue Nov 9 23:11:39 2004 UTC (19 years, 7 months ago) by tim
File size: 8479 byte(s)
Log Message:
adding ForceManager

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