ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/ForceManager.cpp
Revision: 1535
Committed: Fri Dec 31 18:31:56 2010 UTC (14 years, 4 months ago) by gezelter
File size: 12433 byte(s)
Log Message:
Well, it compiles and builds, but still has a bus error at runtime.

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. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 * [4] Vardeman & Gezelter, in progress (2009).
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 __OPENMD_C
54 #include "UseTheForce/DarkSide/fInteractionMap.h"
55 #include "utils/simError.h"
56 #include "primitives/Bond.hpp"
57 #include "primitives/Bend.hpp"
58 #include "primitives/Torsion.hpp"
59 #include "primitives/Inversion.hpp"
60
61 namespace OpenMD {
62
63 ForceManager::ForceManager(SimInfo * info) : info_(info),
64 NBforcesInitialized_(false) {
65 }
66
67 void ForceManager::calcForces() {
68
69
70 if (!info_->isFortranInitialized()) {
71 info_->update();
72 nbiMan_->setSimInfo(info_);
73 nbiMan_->initialize();
74 info_->setupFortran();
75 }
76
77 preCalculation();
78
79 calcShortRangeInteraction();
80
81 calcLongRangeInteraction();
82
83 postCalculation();
84
85 }
86
87 void ForceManager::preCalculation() {
88 SimInfo::MoleculeIterator mi;
89 Molecule* mol;
90 Molecule::AtomIterator ai;
91 Atom* atom;
92 Molecule::RigidBodyIterator rbIter;
93 RigidBody* rb;
94
95 // forces are zeroed here, before any are accumulated.
96 // NOTE: do not rezero the forces in Fortran.
97
98 for (mol = info_->beginMolecule(mi); mol != NULL;
99 mol = info_->nextMolecule(mi)) {
100 for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
101 atom->zeroForcesAndTorques();
102 }
103
104 //change the positions of atoms which belong to the rigidbodies
105 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
106 rb = mol->nextRigidBody(rbIter)) {
107 rb->zeroForcesAndTorques();
108 }
109
110 }
111
112 // Zero out the stress tensor
113 tau *= 0.0;
114
115 }
116
117 void ForceManager::calcShortRangeInteraction() {
118 Molecule* mol;
119 RigidBody* rb;
120 Bond* bond;
121 Bend* bend;
122 Torsion* torsion;
123 Inversion* inversion;
124 SimInfo::MoleculeIterator mi;
125 Molecule::RigidBodyIterator rbIter;
126 Molecule::BondIterator bondIter;;
127 Molecule::BendIterator bendIter;
128 Molecule::TorsionIterator torsionIter;
129 Molecule::InversionIterator inversionIter;
130 RealType bondPotential = 0.0;
131 RealType bendPotential = 0.0;
132 RealType torsionPotential = 0.0;
133 RealType inversionPotential = 0.0;
134
135 //calculate short range interactions
136 for (mol = info_->beginMolecule(mi); mol != NULL;
137 mol = info_->nextMolecule(mi)) {
138
139 //change the positions of atoms which belong to the rigidbodies
140 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
141 rb = mol->nextRigidBody(rbIter)) {
142 rb->updateAtoms();
143 }
144
145 for (bond = mol->beginBond(bondIter); bond != NULL;
146 bond = mol->nextBond(bondIter)) {
147 bond->calcForce();
148 bondPotential += bond->getPotential();
149 }
150
151 for (bend = mol->beginBend(bendIter); bend != NULL;
152 bend = mol->nextBend(bendIter)) {
153
154 RealType angle;
155 bend->calcForce(angle);
156 RealType currBendPot = bend->getPotential();
157
158 bendPotential += bend->getPotential();
159 std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend);
160 if (i == bendDataSets.end()) {
161 BendDataSet dataSet;
162 dataSet.prev.angle = dataSet.curr.angle = angle;
163 dataSet.prev.potential = dataSet.curr.potential = currBendPot;
164 dataSet.deltaV = 0.0;
165 bendDataSets.insert(std::map<Bend*, BendDataSet>::value_type(bend, dataSet));
166 }else {
167 i->second.prev.angle = i->second.curr.angle;
168 i->second.prev.potential = i->second.curr.potential;
169 i->second.curr.angle = angle;
170 i->second.curr.potential = currBendPot;
171 i->second.deltaV = fabs(i->second.curr.potential -
172 i->second.prev.potential);
173 }
174 }
175
176 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
177 torsion = mol->nextTorsion(torsionIter)) {
178 RealType angle;
179 torsion->calcForce(angle);
180 RealType currTorsionPot = torsion->getPotential();
181 torsionPotential += torsion->getPotential();
182 std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
183 if (i == torsionDataSets.end()) {
184 TorsionDataSet dataSet;
185 dataSet.prev.angle = dataSet.curr.angle = angle;
186 dataSet.prev.potential = dataSet.curr.potential = currTorsionPot;
187 dataSet.deltaV = 0.0;
188 torsionDataSets.insert(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet));
189 }else {
190 i->second.prev.angle = i->second.curr.angle;
191 i->second.prev.potential = i->second.curr.potential;
192 i->second.curr.angle = angle;
193 i->second.curr.potential = currTorsionPot;
194 i->second.deltaV = fabs(i->second.curr.potential -
195 i->second.prev.potential);
196 }
197 }
198
199 for (inversion = mol->beginInversion(inversionIter);
200 inversion != NULL;
201 inversion = mol->nextInversion(inversionIter)) {
202 RealType angle;
203 inversion->calcForce(angle);
204 RealType currInversionPot = inversion->getPotential();
205 inversionPotential += inversion->getPotential();
206 std::map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
207 if (i == inversionDataSets.end()) {
208 InversionDataSet dataSet;
209 dataSet.prev.angle = dataSet.curr.angle = angle;
210 dataSet.prev.potential = dataSet.curr.potential = currInversionPot;
211 dataSet.deltaV = 0.0;
212 inversionDataSets.insert(std::map<Inversion*, InversionDataSet>::value_type(inversion, dataSet));
213 }else {
214 i->second.prev.angle = i->second.curr.angle;
215 i->second.prev.potential = i->second.curr.potential;
216 i->second.curr.angle = angle;
217 i->second.curr.potential = currInversionPot;
218 i->second.deltaV = fabs(i->second.curr.potential -
219 i->second.prev.potential);
220 }
221 }
222 }
223
224 RealType shortRangePotential = bondPotential + bendPotential +
225 torsionPotential + inversionPotential;
226 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
227 curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
228 curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
229 curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
230 curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
231 curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;
232
233 }
234
235 void ForceManager::calcLongRangeInteraction() {
236 Snapshot* curSnapshot;
237 DataStorage* config;
238 RealType* frc;
239 RealType* pos;
240 RealType* trq;
241 RealType* A;
242 RealType* electroFrame;
243 RealType* rc;
244 RealType* particlePot;
245
246 //get current snapshot from SimInfo
247 curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
248
249 //get array pointers
250 config = &(curSnapshot->atomData);
251 frc = config->getArrayPointer(DataStorage::dslForce);
252 pos = config->getArrayPointer(DataStorage::dslPosition);
253 trq = config->getArrayPointer(DataStorage::dslTorque);
254 A = config->getArrayPointer(DataStorage::dslAmat);
255 electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
256 particlePot = config->getArrayPointer(DataStorage::dslParticlePot);
257
258 //calculate the center of mass of cutoff group
259 SimInfo::MoleculeIterator mi;
260 Molecule* mol;
261 Molecule::CutoffGroupIterator ci;
262 CutoffGroup* cg;
263 Vector3d com;
264 std::vector<Vector3d> rcGroup;
265
266 if(info_->getNCutoffGroups() > 0){
267
268 for (mol = info_->beginMolecule(mi); mol != NULL;
269 mol = info_->nextMolecule(mi)) {
270 for(cg = mol->beginCutoffGroup(ci); cg != NULL;
271 cg = mol->nextCutoffGroup(ci)) {
272 cg->getCOM(com);
273 rcGroup.push_back(com);
274 }
275 }// end for (mol)
276
277 rc = rcGroup[0].getArrayPointer();
278 } else {
279 // center of mass of the group is the same as position of the atom
280 // if cutoff group does not exist
281 rc = pos;
282 }
283
284 //initialize data before passing to fortran
285 RealType longRangePotential[LR_POT_TYPES];
286 RealType lrPot = 0.0;
287 int isError = 0;
288
289 for (int i=0; i<LR_POT_TYPES;i++){
290 longRangePotential[i]=0.0; //Initialize array
291 }
292
293 doForceLoop(pos,
294 rc,
295 A,
296 electroFrame,
297 frc,
298 trq,
299 tau.getArrayPointer(),
300 longRangePotential,
301 particlePot,
302 &isError );
303
304 if( isError ){
305 sprintf( painCave.errMsg,
306 "Error returned from the fortran force calculation.\n" );
307 painCave.isFatal = 1;
308 simError();
309 }
310 for (int i=0; i<LR_POT_TYPES;i++){
311 lrPot += longRangePotential[i]; //Quick hack
312 }
313
314 //store the tau and long range potential
315 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
316 curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
317 curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
318 }
319
320
321 void ForceManager::postCalculation() {
322 SimInfo::MoleculeIterator mi;
323 Molecule* mol;
324 Molecule::RigidBodyIterator rbIter;
325 RigidBody* rb;
326 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
327
328 // collect the atomic forces onto rigid bodies
329
330 for (mol = info_->beginMolecule(mi); mol != NULL;
331 mol = info_->nextMolecule(mi)) {
332 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
333 rb = mol->nextRigidBody(rbIter)) {
334 Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial();
335 tau += rbTau;
336 }
337 }
338
339 #ifdef IS_MPI
340 Mat3x3d tmpTau(tau);
341 MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(),
342 9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
343 #endif
344 curSnapshot->statData.setTau(tau);
345 }
346
347 } //end namespace OpenMD

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date