1 |
gezelter |
507 |
/* |
2 |
gezelter |
246 |
* 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 |
gezelter |
507 |
/** |
43 |
|
|
* @file ForceManager.cpp |
44 |
|
|
* @author tlin |
45 |
|
|
* @date 11/09/2004 |
46 |
|
|
* @time 10:39am |
47 |
|
|
* @version 1.0 |
48 |
|
|
*/ |
49 |
gezelter |
246 |
|
50 |
|
|
#include "brains/ForceManager.hpp" |
51 |
|
|
#include "primitives/Molecule.hpp" |
52 |
|
|
#include "UseTheForce/doForces_interface.h" |
53 |
|
|
#include "utils/simError.h" |
54 |
|
|
namespace oopse { |
55 |
|
|
|
56 |
gezelter |
507 |
void ForceManager::calcForces(bool needPotential, bool needStress) { |
57 |
gezelter |
246 |
|
58 |
|
|
if (!info_->isFortranInitialized()) { |
59 |
gezelter |
507 |
info_->update(); |
60 |
gezelter |
246 |
} |
61 |
|
|
|
62 |
|
|
preCalculation(); |
63 |
|
|
|
64 |
|
|
calcShortRangeInteraction(); |
65 |
|
|
|
66 |
|
|
calcLongRangeInteraction(needPotential, needStress); |
67 |
|
|
|
68 |
|
|
postCalculation(); |
69 |
|
|
|
70 |
gezelter |
507 |
} |
71 |
gezelter |
246 |
|
72 |
gezelter |
507 |
void ForceManager::preCalculation() { |
73 |
gezelter |
246 |
SimInfo::MoleculeIterator mi; |
74 |
|
|
Molecule* mol; |
75 |
|
|
Molecule::AtomIterator ai; |
76 |
|
|
Atom* atom; |
77 |
|
|
Molecule::RigidBodyIterator rbIter; |
78 |
|
|
RigidBody* rb; |
79 |
|
|
|
80 |
|
|
// forces are zeroed here, before any are accumulated. |
81 |
|
|
// NOTE: do not rezero the forces in Fortran. |
82 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
83 |
gezelter |
507 |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
84 |
|
|
atom->zeroForcesAndTorques(); |
85 |
|
|
} |
86 |
gezelter |
246 |
|
87 |
gezelter |
507 |
//change the positions of atoms which belong to the rigidbodies |
88 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
89 |
|
|
rb->zeroForcesAndTorques(); |
90 |
|
|
} |
91 |
gezelter |
246 |
} |
92 |
|
|
|
93 |
gezelter |
507 |
} |
94 |
gezelter |
246 |
|
95 |
gezelter |
507 |
void ForceManager::calcShortRangeInteraction() { |
96 |
gezelter |
246 |
Molecule* mol; |
97 |
|
|
RigidBody* rb; |
98 |
|
|
Bond* bond; |
99 |
|
|
Bend* bend; |
100 |
|
|
Torsion* torsion; |
101 |
|
|
SimInfo::MoleculeIterator mi; |
102 |
|
|
Molecule::RigidBodyIterator rbIter; |
103 |
|
|
Molecule::BondIterator bondIter;; |
104 |
|
|
Molecule::BendIterator bendIter; |
105 |
|
|
Molecule::TorsionIterator torsionIter; |
106 |
|
|
|
107 |
|
|
//calculate short range interactions |
108 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
109 |
|
|
|
110 |
gezelter |
507 |
//change the positions of atoms which belong to the rigidbodies |
111 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
112 |
|
|
rb->updateAtoms(); |
113 |
|
|
} |
114 |
gezelter |
246 |
|
115 |
gezelter |
507 |
for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { |
116 |
|
|
bond->calcForce(); |
117 |
|
|
} |
118 |
gezelter |
246 |
|
119 |
gezelter |
507 |
for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { |
120 |
|
|
bend->calcForce(); |
121 |
|
|
} |
122 |
gezelter |
246 |
|
123 |
gezelter |
507 |
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { |
124 |
|
|
torsion->calcForce(); |
125 |
|
|
} |
126 |
gezelter |
246 |
|
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
double shortRangePotential = 0.0; |
130 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
131 |
gezelter |
507 |
shortRangePotential += mol->getPotential(); |
132 |
gezelter |
246 |
} |
133 |
|
|
|
134 |
|
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
135 |
|
|
curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential; |
136 |
gezelter |
507 |
} |
137 |
gezelter |
246 |
|
138 |
gezelter |
507 |
void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) { |
139 |
gezelter |
246 |
Snapshot* curSnapshot; |
140 |
|
|
DataStorage* config; |
141 |
|
|
double* frc; |
142 |
|
|
double* pos; |
143 |
|
|
double* trq; |
144 |
|
|
double* A; |
145 |
|
|
double* electroFrame; |
146 |
|
|
double* rc; |
147 |
|
|
|
148 |
|
|
//get current snapshot from SimInfo |
149 |
|
|
curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
150 |
|
|
|
151 |
|
|
//get array pointers |
152 |
|
|
config = &(curSnapshot->atomData); |
153 |
|
|
frc = config->getArrayPointer(DataStorage::dslForce); |
154 |
|
|
pos = config->getArrayPointer(DataStorage::dslPosition); |
155 |
|
|
trq = config->getArrayPointer(DataStorage::dslTorque); |
156 |
|
|
A = config->getArrayPointer(DataStorage::dslAmat); |
157 |
|
|
electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); |
158 |
|
|
|
159 |
|
|
//calculate the center of mass of cutoff group |
160 |
|
|
SimInfo::MoleculeIterator mi; |
161 |
|
|
Molecule* mol; |
162 |
|
|
Molecule::CutoffGroupIterator ci; |
163 |
|
|
CutoffGroup* cg; |
164 |
|
|
Vector3d com; |
165 |
|
|
std::vector<Vector3d> rcGroup; |
166 |
|
|
|
167 |
|
|
if(info_->getNCutoffGroups() > 0){ |
168 |
|
|
|
169 |
gezelter |
507 |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
170 |
gezelter |
246 |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
171 |
gezelter |
507 |
cg->getCOM(com); |
172 |
|
|
rcGroup.push_back(com); |
173 |
gezelter |
246 |
} |
174 |
gezelter |
507 |
}// end for (mol) |
175 |
gezelter |
246 |
|
176 |
gezelter |
507 |
rc = rcGroup[0].getArrayPointer(); |
177 |
gezelter |
246 |
} else { |
178 |
gezelter |
507 |
// center of mass of the group is the same as position of the atom if cutoff group does not exist |
179 |
|
|
rc = pos; |
180 |
gezelter |
246 |
} |
181 |
|
|
|
182 |
|
|
//initialize data before passing to fortran |
183 |
|
|
double longRangePotential = 0.0; |
184 |
|
|
Mat3x3d tau; |
185 |
|
|
short int passedCalcPot = needPotential; |
186 |
|
|
short int passedCalcStress = needStress; |
187 |
|
|
int isError = 0; |
188 |
|
|
|
189 |
|
|
doForceLoop( pos, |
190 |
gezelter |
507 |
rc, |
191 |
|
|
A, |
192 |
|
|
electroFrame, |
193 |
|
|
frc, |
194 |
|
|
trq, |
195 |
|
|
tau.getArrayPointer(), |
196 |
|
|
&longRangePotential, |
197 |
|
|
&passedCalcPot, |
198 |
|
|
&passedCalcStress, |
199 |
|
|
&isError ); |
200 |
gezelter |
246 |
|
201 |
|
|
if( isError ){ |
202 |
gezelter |
507 |
sprintf( painCave.errMsg, |
203 |
|
|
"Error returned from the fortran force calculation.\n" ); |
204 |
|
|
painCave.isFatal = 1; |
205 |
|
|
simError(); |
206 |
gezelter |
246 |
} |
207 |
|
|
|
208 |
|
|
//store the tau and long range potential |
209 |
|
|
curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential; |
210 |
|
|
curSnapshot->statData.setTau(tau); |
211 |
gezelter |
507 |
} |
212 |
gezelter |
246 |
|
213 |
|
|
|
214 |
gezelter |
507 |
void ForceManager::postCalculation() { |
215 |
gezelter |
246 |
SimInfo::MoleculeIterator mi; |
216 |
|
|
Molecule* mol; |
217 |
|
|
Molecule::RigidBodyIterator rbIter; |
218 |
|
|
RigidBody* rb; |
219 |
|
|
|
220 |
|
|
// collect the atomic forces onto rigid bodies |
221 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
222 |
gezelter |
507 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
223 |
|
|
rb->calcForcesAndTorques(); |
224 |
|
|
} |
225 |
gezelter |
246 |
} |
226 |
|
|
|
227 |
gezelter |
507 |
} |
228 |
gezelter |
246 |
|
229 |
|
|
} //end namespace oopse |