1 |
tim |
1699 |
/* |
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 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* @file SimModel.cpp |
28 |
|
|
* @author tlin |
29 |
|
|
* @date 11/02/2004 |
30 |
|
|
* @version 1.0 |
31 |
|
|
*/ |
32 |
|
|
|
33 |
|
|
#include <algorithm> |
34 |
|
|
|
35 |
|
|
#include "brains/SimModel.hpp" |
36 |
|
|
#include "utils/MemoryUtils.hpp" |
37 |
|
|
|
38 |
|
|
namespace oopse { |
39 |
|
|
|
40 |
|
|
SimModel::SimModel() : nAtom_(0), nBond_(0), nBend_(0), nTorsion_(0), nRigidBody_(0), |
41 |
|
|
nIntegrableObjects_(0), nCutoffGroup_(0), nConstraints_(0), sman_(NULL){ |
42 |
|
|
|
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
SimModel::~SimModel() { |
46 |
|
|
MemoryUtils::deleteVectorOfPointer(molecules_); |
47 |
|
|
delete sman_; |
48 |
|
|
|
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
bool SimModel::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 |
|
|
|
58 |
|
|
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 |
|
|
|
67 |
|
|
return true; |
68 |
|
|
} else { |
69 |
|
|
return false; |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
bool SimModel::removeMolecule(Molecule* mol) { |
74 |
|
|
std::vector<Molecule*>::iterator i; |
75 |
|
|
i = std::find(molecules_.begin(), molecules_.end(), mol); |
76 |
|
|
|
77 |
|
|
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 |
|
|
|
88 |
|
|
return true; |
89 |
|
|
} else { |
90 |
|
|
return false; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
Molecule* SimModel::beginMolecule(std::vector<Molecule*>::iterator& i) { |
98 |
|
|
i = molecules_.begin(); |
99 |
|
|
return i == molecules_.end() ? NULL : *i; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
Molecule* SimModel::nextMolecule(std::vector<Molecule*>::iterator& i) { |
103 |
|
|
++i; |
104 |
|
|
return i == molecules_.end() ? NULL : *i; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
|
108 |
|
|
void SimModel::calcNDF() { |
109 |
|
|
int ndf_local; |
110 |
|
|
std::vector<Molecule*>::iterator i; |
111 |
|
|
std::vector<StuntDouble*>::iterator j; |
112 |
|
|
Molecule* mol; |
113 |
|
|
StuntDouble* integrableObject; |
114 |
|
|
|
115 |
|
|
ndf_local = 0; |
116 |
|
|
|
117 |
|
|
for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
118 |
|
|
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
119 |
|
|
integrableObject = mol->nextIntegrableObject(j)) { |
120 |
|
|
|
121 |
|
|
ndf_local += 3; |
122 |
|
|
|
123 |
|
|
if (integrableObject->isDirectional()) { |
124 |
|
|
if (integrableObject->isLinear()) { |
125 |
|
|
ndf_local += 2; |
126 |
|
|
} else { |
127 |
|
|
ndf_local += 3; |
128 |
|
|
} |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
} |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
// n_constraints is local, so subtract them on each processor: |
135 |
|
|
|
136 |
|
|
ndf_local -= nConstraints_; |
137 |
|
|
|
138 |
|
|
#ifdef IS_MPI |
139 |
|
|
MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
140 |
|
|
#else |
141 |
|
|
ndf_ = ndf_local; |
142 |
|
|
#endif |
143 |
|
|
|
144 |
|
|
// nZconstraints is global, as are the 3 COM translations for the |
145 |
|
|
// entire system: |
146 |
|
|
|
147 |
|
|
ndf_ = ndf_ - 3 - nZconstraints; |
148 |
|
|
|
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
void SimModel::calcNDFRaw() { |
152 |
|
|
int ndfRaw_local; |
153 |
|
|
|
154 |
|
|
std::vector<Molecule*>::iterator i; |
155 |
|
|
std::vector<StuntDouble*>::iterator j; |
156 |
|
|
Molecule* mol; |
157 |
|
|
StuntDouble* integrableObject; |
158 |
|
|
|
159 |
|
|
// Raw degrees of freedom that we have to set |
160 |
|
|
ndfRaw_local = 0; |
161 |
|
|
|
162 |
|
|
for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
163 |
|
|
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
164 |
|
|
integrableObject = mol->nextIntegrableObject(j)) { |
165 |
|
|
|
166 |
|
|
ndfRaw_local += 3; |
167 |
|
|
|
168 |
|
|
if (integrableObject->isDirectional()) { |
169 |
|
|
if (integrableObject->isLinear()) { |
170 |
|
|
ndfRaw_local += 2; |
171 |
|
|
} else { |
172 |
|
|
ndfRaw_local += 3; |
173 |
|
|
} |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
} |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
#ifdef IS_MPI |
180 |
|
|
MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
181 |
|
|
#else |
182 |
|
|
ndfRaw_ = ndfRaw_local; |
183 |
|
|
#endif |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
void SimModel::calcNDFTrans() { |
187 |
|
|
int ndfTrans_local; |
188 |
|
|
|
189 |
|
|
ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; |
190 |
|
|
|
191 |
|
|
|
192 |
|
|
#ifdef IS_MPI |
193 |
|
|
MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
194 |
|
|
#else |
195 |
|
|
ndfTrans_ = ndfTrans_local; |
196 |
|
|
#endif |
197 |
|
|
|
198 |
|
|
ndfTrans_ = ndfTrans_ - 3 - nZconstraints; |
199 |
|
|
|
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
|
203 |
|
|
}//end namespace oopse |