ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/brains/ForceManager.cpp
Revision: 1245
Committed: Tue May 27 16:39:06 2008 UTC (16 years, 11 months ago) by chuckv
File size: 11528 byte(s)
Log Message:
Checking in changes for Hefland moment calculations

File Contents

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

Properties

Name Value
svn:executable *