ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/devel_omp/src/brains/ForceManager.cpp
Revision: 1215
Committed: Wed Jan 23 21:22:37 2008 UTC (17 years, 3 months ago) by xsun
Original Path: trunk/src/brains/ForceManager.cpp
File size: 11395 byte(s)
Log Message:
fixed printing of memory available

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 gezelter 1126
87     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 gezelter 1126
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 gezelter 246 }
99    
100 gezelter 1126 // Zero out the stress tensor
101     tau *= 0.0;
102    
103 gezelter 507 }
104 gezelter 1126
105 gezelter 507 void ForceManager::calcShortRangeInteraction() {
106 gezelter 246 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 tim 963 RealType bondPotential = 0.0;
117     RealType bendPotential = 0.0;
118     RealType torsionPotential = 0.0;
119 gezelter 246
120     //calculate short range interactions
121 gezelter 1126 for (mol = info_->beginMolecule(mi); mol != NULL;
122     mol = info_->nextMolecule(mi)) {
123 gezelter 246
124 gezelter 507 //change the positions of atoms which belong to the rigidbodies
125 gezelter 1126 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
126     rb = mol->nextRigidBody(rbIter)) {
127     rb->updateAtoms();
128 gezelter 507 }
129 gezelter 246
130 gezelter 1126 for (bond = mol->beginBond(bondIter); bond != NULL;
131     bond = mol->nextBond(bondIter)) {
132 tim 749 bond->calcForce();
133     bondPotential += bond->getPotential();
134 gezelter 507 }
135 gezelter 246
136 gezelter 1126 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 gezelter 507 }
159 gezelter 1126
160     for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
161     torsion = mol->nextTorsion(torsionIter)) {
162 tim 963 RealType angle;
163 gezelter 1126 torsion->calcForce(angle);
164 tim 963 RealType currTorsionPot = torsion->getPotential();
165 gezelter 1126 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 gezelter 246 }
183    
184 gezelter 1126 RealType shortRangePotential = bondPotential + bendPotential +
185     torsionPotential;
186 gezelter 246 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
187     curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
188 tim 665 curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
189     curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
190     curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
191    
192 gezelter 507 }
193 gezelter 1126
194     void ForceManager::calcLongRangeInteraction(bool needPotential,
195     bool needStress) {
196 gezelter 246 Snapshot* curSnapshot;
197     DataStorage* config;
198 tim 963 RealType* frc;
199     RealType* pos;
200     RealType* trq;
201     RealType* A;
202     RealType* electroFrame;
203     RealType* rc;
204 gezelter 246
205     //get current snapshot from SimInfo
206     curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
207 gezelter 1126
208 gezelter 246 //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 gezelter 1126
224 gezelter 246 if(info_->getNCutoffGroups() > 0){
225 gezelter 1126
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 gezelter 507 cg->getCOM(com);
231     rcGroup.push_back(com);
232 gezelter 246 }
233 gezelter 507 }// end for (mol)
234 gezelter 246
235 gezelter 507 rc = rcGroup[0].getArrayPointer();
236 gezelter 246 } else {
237 gezelter 1126 // center of mass of the group is the same as position of the atom
238     // if cutoff group does not exist
239 gezelter 507 rc = pos;
240 gezelter 246 }
241 gezelter 1126
242 gezelter 246 //initialize data before passing to fortran
243 tim 963 RealType longRangePotential[LR_POT_TYPES];
244     RealType lrPot = 0.0;
245 chrisfen 998 Vector3d totalDipole;
246 gezelter 246 short int passedCalcPot = needPotential;
247     short int passedCalcStress = needStress;
248     int isError = 0;
249    
250 chuckv 664 for (int i=0; i<LR_POT_TYPES;i++){
251     longRangePotential[i]=0.0; //Initialize array
252     }
253 gezelter 1126
254 xsun 1215 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 gezelter 246 if( isError ){
267 gezelter 507 sprintf( painCave.errMsg,
268     "Error returned from the fortran force calculation.\n" );
269     painCave.isFatal = 1;
270     simError();
271 gezelter 246 }
272 chuckv 664 for (int i=0; i<LR_POT_TYPES;i++){
273     lrPot += longRangePotential[i]; //Quick hack
274     }
275 gezelter 1126
276 chrisfen 998 // grab the simulation box dipole moment if specified
277     if (info_->getCalcBoxDipole()){
278     getAccumulatedBoxDipole(totalDipole.getArrayPointer());
279 gezelter 1126
280 chrisfen 998 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 gezelter 1126
285 gezelter 246 //store the tau and long range potential
286 chuckv 664 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
287 chrisfen 691 curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
288 tim 681 curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
289 gezelter 507 }
290 gezelter 246
291 gezelter 1126
292     void ForceManager::postCalculation(bool needStress) {
293 gezelter 246 SimInfo::MoleculeIterator mi;
294     Molecule* mol;
295     Molecule::RigidBodyIterator rbIter;
296     RigidBody* rb;
297 gezelter 1126 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
298 gezelter 246
299     // collect the atomic forces onto rigid bodies
300 gezelter 1126
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 gezelter 507 }
312 gezelter 1126 }
313 gezelter 246
314 gezelter 1126 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 gezelter 507 }
323 gezelter 246
324     } //end namespace oopse

Properties

Name Value
svn:executable *