ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/brains/ForceManager.cpp
Revision: 1126
Committed: Fri Apr 6 21:53:43 2007 UTC (18 years ago) by gezelter
File size: 11269 byte(s)
Log Message:
Massive update to do virials (both atomic and cutoff-group) correctly.
The rigid body constraint contributions had been missing and this was
masked by the use of cutoff groups...

File Contents

# Content
1 /*
2 * 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 /**
43 * @file ForceManager.cpp
44 * @author tlin
45 * @date 11/09/2004
46 * @time 10:39am
47 * @version 1.0
48 */
49
50 #include "brains/ForceManager.hpp"
51 #include "primitives/Molecule.hpp"
52 #include "UseTheForce/doForces_interface.h"
53 #define __C
54 #include "UseTheForce/DarkSide/fInteractionMap.h"
55 #include "utils/simError.h"
56 #include "primitives/Bend.hpp"
57 #include "primitives/Bend.hpp"
58 namespace oopse {
59
60 void ForceManager::calcForces(bool needPotential, bool needStress) {
61
62 if (!info_->isFortranInitialized()) {
63 info_->update();
64 }
65
66 preCalculation();
67
68 calcShortRangeInteraction();
69
70 calcLongRangeInteraction(needPotential, needStress);
71
72 postCalculation(needStress);
73
74 }
75
76 void ForceManager::preCalculation() {
77 SimInfo::MoleculeIterator mi;
78 Molecule* mol;
79 Molecule::AtomIterator ai;
80 Atom* atom;
81 Molecule::RigidBodyIterator rbIter;
82 RigidBody* rb;
83
84 // forces are zeroed here, before any are accumulated.
85 // NOTE: do not rezero the forces in Fortran.
86
87 for (mol = info_->beginMolecule(mi); mol != NULL;
88 mol = info_->nextMolecule(mi)) {
89 for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
90 atom->zeroForcesAndTorques();
91 }
92
93 //change the positions of atoms which belong to the rigidbodies
94 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
95 rb = mol->nextRigidBody(rbIter)) {
96 rb->zeroForcesAndTorques();
97 }
98 }
99
100 // Zero out the stress tensor
101 tau *= 0.0;
102
103 }
104
105 void ForceManager::calcShortRangeInteraction() {
106 Molecule* mol;
107 RigidBody* rb;
108 Bond* bond;
109 Bend* bend;
110 Torsion* torsion;
111 SimInfo::MoleculeIterator mi;
112 Molecule::RigidBodyIterator rbIter;
113 Molecule::BondIterator bondIter;;
114 Molecule::BendIterator bendIter;
115 Molecule::TorsionIterator torsionIter;
116 RealType bondPotential = 0.0;
117 RealType bendPotential = 0.0;
118 RealType torsionPotential = 0.0;
119
120 //calculate short range interactions
121 for (mol = info_->beginMolecule(mi); mol != NULL;
122 mol = info_->nextMolecule(mi)) {
123
124 //change the positions of atoms which belong to the rigidbodies
125 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
126 rb = mol->nextRigidBody(rbIter)) {
127 rb->updateAtoms();
128 }
129
130 for (bond = mol->beginBond(bondIter); bond != NULL;
131 bond = mol->nextBond(bondIter)) {
132 bond->calcForce();
133 bondPotential += bond->getPotential();
134 }
135
136 for (bend = mol->beginBend(bendIter); bend != NULL;
137 bend = mol->nextBend(bendIter)) {
138
139 RealType angle;
140 bend->calcForce(angle);
141 RealType currBendPot = bend->getPotential();
142 bendPotential += bend->getPotential();
143 std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend);
144 if (i == bendDataSets.end()) {
145 BendDataSet dataSet;
146 dataSet.prev.angle = dataSet.curr.angle = angle;
147 dataSet.prev.potential = dataSet.curr.potential = currBendPot;
148 dataSet.deltaV = 0.0;
149 bendDataSets.insert(std::map<Bend*, BendDataSet>::value_type(bend, dataSet));
150 }else {
151 i->second.prev.angle = i->second.curr.angle;
152 i->second.prev.potential = i->second.curr.potential;
153 i->second.curr.angle = angle;
154 i->second.curr.potential = currBendPot;
155 i->second.deltaV = fabs(i->second.curr.potential -
156 i->second.prev.potential);
157 }
158 }
159
160 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
161 torsion = mol->nextTorsion(torsionIter)) {
162 RealType angle;
163 torsion->calcForce(angle);
164 RealType currTorsionPot = torsion->getPotential();
165 torsionPotential += torsion->getPotential();
166 std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
167 if (i == torsionDataSets.end()) {
168 TorsionDataSet dataSet;
169 dataSet.prev.angle = dataSet.curr.angle = angle;
170 dataSet.prev.potential = dataSet.curr.potential = currTorsionPot;
171 dataSet.deltaV = 0.0;
172 torsionDataSets.insert(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet));
173 }else {
174 i->second.prev.angle = i->second.curr.angle;
175 i->second.prev.potential = i->second.curr.potential;
176 i->second.curr.angle = angle;
177 i->second.curr.potential = currTorsionPot;
178 i->second.deltaV = fabs(i->second.curr.potential -
179 i->second.prev.potential);
180 }
181 }
182 }
183
184 RealType shortRangePotential = bondPotential + bendPotential +
185 torsionPotential;
186 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
187 curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
188 curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
189 curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
190 curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
191
192 }
193
194 void ForceManager::calcLongRangeInteraction(bool needPotential,
195 bool needStress) {
196 Snapshot* curSnapshot;
197 DataStorage* config;
198 RealType* frc;
199 RealType* pos;
200 RealType* trq;
201 RealType* A;
202 RealType* electroFrame;
203 RealType* rc;
204
205 //get current snapshot from SimInfo
206 curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
207
208 //get array pointers
209 config = &(curSnapshot->atomData);
210 frc = config->getArrayPointer(DataStorage::dslForce);
211 pos = config->getArrayPointer(DataStorage::dslPosition);
212 trq = config->getArrayPointer(DataStorage::dslTorque);
213 A = config->getArrayPointer(DataStorage::dslAmat);
214 electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
215
216 //calculate the center of mass of cutoff group
217 SimInfo::MoleculeIterator mi;
218 Molecule* mol;
219 Molecule::CutoffGroupIterator ci;
220 CutoffGroup* cg;
221 Vector3d com;
222 std::vector<Vector3d> rcGroup;
223
224 if(info_->getNCutoffGroups() > 0){
225
226 for (mol = info_->beginMolecule(mi); mol != NULL;
227 mol = info_->nextMolecule(mi)) {
228 for(cg = mol->beginCutoffGroup(ci); cg != NULL;
229 cg = mol->nextCutoffGroup(ci)) {
230 cg->getCOM(com);
231 rcGroup.push_back(com);
232 }
233 }// end for (mol)
234
235 rc = rcGroup[0].getArrayPointer();
236 } else {
237 // center of mass of the group is the same as position of the atom
238 // if cutoff group does not exist
239 rc = pos;
240 }
241
242 //initialize data before passing to fortran
243 RealType longRangePotential[LR_POT_TYPES];
244 RealType lrPot = 0.0;
245 Vector3d totalDipole;
246 short int passedCalcPot = needPotential;
247 short int passedCalcStress = needStress;
248 int isError = 0;
249
250 for (int i=0; i<LR_POT_TYPES;i++){
251 longRangePotential[i]=0.0; //Initialize array
252 }
253
254 doForceLoop( pos,
255 rc,
256 A,
257 electroFrame,
258 frc,
259 trq,
260 tau.getArrayPointer(),
261 longRangePotential,
262 &passedCalcPot,
263 &passedCalcStress,
264 &isError );
265
266 if( isError ){
267 sprintf( painCave.errMsg,
268 "Error returned from the fortran force calculation.\n" );
269 painCave.isFatal = 1;
270 simError();
271 }
272 for (int i=0; i<LR_POT_TYPES;i++){
273 lrPot += longRangePotential[i]; //Quick hack
274 }
275
276 // grab the simulation box dipole moment if specified
277 if (info_->getCalcBoxDipole()){
278 getAccumulatedBoxDipole(totalDipole.getArrayPointer());
279
280 curSnapshot->statData[Stats::BOX_DIPOLE_X] = totalDipole(0);
281 curSnapshot->statData[Stats::BOX_DIPOLE_Y] = totalDipole(1);
282 curSnapshot->statData[Stats::BOX_DIPOLE_Z] = totalDipole(2);
283 }
284
285 //store the tau and long range potential
286 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
287 curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
288 curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
289 }
290
291
292 void ForceManager::postCalculation(bool needStress) {
293 SimInfo::MoleculeIterator mi;
294 Molecule* mol;
295 Molecule::RigidBodyIterator rbIter;
296 RigidBody* rb;
297 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
298
299 // collect the atomic forces onto rigid bodies
300
301 for (mol = info_->beginMolecule(mi); mol != NULL;
302 mol = info_->nextMolecule(mi)) {
303 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
304 rb = mol->nextRigidBody(rbIter)) {
305 if (needStress) {
306 Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial();
307 tau += rbTau;
308 } else{
309 rb->calcForcesAndTorques();
310 }
311 }
312 }
313
314 if (needStress) {
315 #ifdef IS_MPI
316 Mat3x3d tmpTau(tau);
317 MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(),
318 9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
319 #endif
320 curSnapshot->statData.setTau(tau);
321 }
322 }
323
324 } //end namespace oopse

Properties

Name Value
svn:executable *