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