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