1 |
tim |
1722 |
/* |
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 |
tim |
1804 |
#include "primitives/Molecule.hpp" |
36 |
|
|
#include "UseTheForce/doForces_interface.h" |
37 |
|
|
#include "utils/simError.h" |
38 |
tim |
1722 |
namespace oopse { |
39 |
|
|
|
40 |
|
|
void ForceManager::calcForces(bool needPotential, bool needStress) { |
41 |
|
|
|
42 |
tim |
1738 |
if (!info_->isFortranInitialized()) { |
43 |
|
|
info_->update(); |
44 |
|
|
} |
45 |
tim |
1722 |
|
46 |
tim |
1738 |
preCalculation(); |
47 |
|
|
|
48 |
|
|
calcShortRangeInteraction(); |
49 |
|
|
|
50 |
tim |
1804 |
calcLongRangeInteraction(needPotential, needStress); |
51 |
tim |
1738 |
|
52 |
tim |
1804 |
postCalculation(); |
53 |
tim |
1738 |
|
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
void ForceManager::preCalculation() { |
57 |
tim |
1804 |
SimInfo::MoleculeIterator mi; |
58 |
tim |
1722 |
Molecule* mol; |
59 |
tim |
1804 |
Molecule::AtomIterator ai; |
60 |
tim |
1722 |
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 |
tim |
1738 |
} |
69 |
|
|
|
70 |
|
|
} |
71 |
tim |
1722 |
|
72 |
tim |
1738 |
void ForceManager::calcShortRangeInteraction() { |
73 |
|
|
Molecule* mol; |
74 |
|
|
RigidBody* rb; |
75 |
|
|
Bond* bond; |
76 |
|
|
Bend* bend; |
77 |
|
|
Torsion* torsion; |
78 |
tim |
1804 |
SimInfo::MoleculeIterator mi; |
79 |
|
|
Molecule::RigidBodyIterator rbIter; |
80 |
|
|
Molecule::BondIterator bondIter;; |
81 |
|
|
Molecule::BendIterator bendIter; |
82 |
|
|
Molecule::TorsionIterator torsionIter; |
83 |
tim |
1738 |
|
84 |
tim |
1722 |
//calculate short range interactions |
85 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
86 |
|
|
|
87 |
tim |
1738 |
//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 |
tim |
1722 |
|
92 |
tim |
1738 |
for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { |
93 |
tim |
1804 |
bond->calcForce(); |
94 |
tim |
1738 |
} |
95 |
|
|
|
96 |
|
|
for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { |
97 |
tim |
1804 |
bend->calcForce(); |
98 |
tim |
1738 |
} |
99 |
|
|
|
100 |
|
|
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { |
101 |
tim |
1804 |
torsion->calcForce(); |
102 |
tim |
1738 |
} |
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 |
tim |
1804 |
double* unitFrame; |
116 |
tim |
1738 |
double* rc; |
117 |
|
|
|
118 |
tim |
1722 |
//get current snapshot from SimInfo |
119 |
tim |
1804 |
curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
120 |
tim |
1722 |
|
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 |
tim |
1804 |
unitFrame = config->getArrayPointer(DataStorage::dslUnitFrame); |
128 |
tim |
1722 |
|
129 |
|
|
//calculate the center of mass of cutoff group |
130 |
tim |
1804 |
SimInfo::MoleculeIterator mi; |
131 |
tim |
1738 |
Molecule* mol; |
132 |
tim |
1804 |
Molecule::CutoffGroupIterator ci; |
133 |
tim |
1738 |
CutoffGroup* cg; |
134 |
|
|
Vector3d com; |
135 |
|
|
std::vector<Vector3d> rcGroup; |
136 |
|
|
|
137 |
tim |
1722 |
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 |
tim |
1804 |
cg->getCOM(com); |
142 |
tim |
1722 |
rcGroup.push_back(com); |
143 |
|
|
} |
144 |
|
|
}// end for (mol) |
145 |
|
|
|
146 |
tim |
1804 |
rc = rcGroup[0].getArrayPointer(); |
147 |
tim |
1738 |
} else { |
148 |
tim |
1722 |
// 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 |
tim |
1738 |
double longRangePotential = 0.0; |
154 |
|
|
Mat3x3d tau; |
155 |
|
|
short int passedCalcPot = needPotential; |
156 |
|
|
short int passedCalcStress = needStress; |
157 |
|
|
int isError = 0; |
158 |
tim |
1722 |
|
159 |
|
|
doForceLoop( pos, |
160 |
|
|
rc, |
161 |
|
|
A, |
162 |
tim |
1804 |
unitFrame, |
163 |
tim |
1722 |
frc, |
164 |
|
|
trq, |
165 |
tim |
1804 |
tau.getArrayPointer(), |
166 |
tim |
1722 |
&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 |
tim |
1804 |
curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential; |
180 |
tim |
1722 |
curSnapshot->statData[Stats::TAUXX] = tau[0]; |
181 |
|
|
curSnapshot->statData[Stats::TAUXY] = tau[1]; |
182 |
|
|
curSnapshot->statData[Stats::TAUXZ] = tau[2]; |
183 |
|
|
curSnapshot->statData[Stats::TAUYX] = tau[3]; |
184 |
|
|
curSnapshot->statData[Stats::TAUYY] = tau[4]; |
185 |
|
|
curSnapshot->statData[Stats::TAUYZ] = tau[5]; |
186 |
|
|
curSnapshot->statData[Stats::TAUZX] = tau[6]; |
187 |
|
|
curSnapshot->statData[Stats::TAUZY] = tau[7]; |
188 |
|
|
curSnapshot->statData[Stats::TAUZZ] = tau[8]; |
189 |
tim |
1738 |
} |
190 |
tim |
1722 |
|
191 |
tim |
1738 |
|
192 |
|
|
void ForceManager::postCalculation() { |
193 |
tim |
1804 |
SimInfo::MoleculeIterator mi; |
194 |
tim |
1738 |
Molecule* mol; |
195 |
tim |
1804 |
Molecule::RigidBodyIterator rbIter; |
196 |
tim |
1738 |
RigidBody* rb; |
197 |
|
|
|
198 |
tim |
1722 |
// collect the atomic forces onto rigid bodies |
199 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
200 |
tim |
1738 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
201 |
|
|
rb->calcForcesAndTorques(); |
202 |
|
|
} |
203 |
tim |
1722 |
} |
204 |
|
|
|
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
} //end namespace oopse |