ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/brains/ForceManager.cpp
Revision: 3126
Committed: Fri Apr 6 21:53:43 2007 UTC (17 years, 5 months 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

# User Rev Content
1 gezelter 2204 /*
2 gezelter 1930 * 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 2204 /**
43     * @file ForceManager.cpp
44     * @author tlin
45     * @date 11/09/2004
46     * @time 10:39am
47     * @version 1.0
48     */
49 gezelter 1930
50     #include "brains/ForceManager.hpp"
51     #include "primitives/Molecule.hpp"
52     #include "UseTheForce/doForces_interface.h"
53 chuckv 2363 #define __C
54     #include "UseTheForce/DarkSide/fInteractionMap.h"
55 gezelter 1930 #include "utils/simError.h"
56 tim 2448 #include "primitives/Bend.hpp"
57     #include "primitives/Bend.hpp"
58 gezelter 1930 namespace oopse {
59    
60 gezelter 2204 void ForceManager::calcForces(bool needPotential, bool needStress) {
61 gezelter 3126
62 gezelter 1930 if (!info_->isFortranInitialized()) {
63 gezelter 2204 info_->update();
64 gezelter 1930 }
65 gezelter 3126
66 gezelter 1930 preCalculation();
67    
68     calcShortRangeInteraction();
69    
70     calcLongRangeInteraction(needPotential, needStress);
71    
72 gezelter 3126 postCalculation(needStress);
73 tim 2448
74 gezelter 2204 }
75 gezelter 3126
76 gezelter 2204 void ForceManager::preCalculation() {
77 gezelter 1930 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 3126
87     for (mol = info_->beginMolecule(mi); mol != NULL;
88     mol = info_->nextMolecule(mi)) {
89 gezelter 2204 for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
90     atom->zeroForcesAndTorques();
91     }
92 gezelter 3126
93 gezelter 2204 //change the positions of atoms which belong to the rigidbodies
94 gezelter 3126 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
95     rb = mol->nextRigidBody(rbIter)) {
96 gezelter 2204 rb->zeroForcesAndTorques();
97     }
98 gezelter 1930 }
99    
100 gezelter 3126 // Zero out the stress tensor
101     tau *= 0.0;
102    
103 gezelter 2204 }
104 gezelter 3126
105 gezelter 2204 void ForceManager::calcShortRangeInteraction() {
106 gezelter 1930 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 2759 RealType bondPotential = 0.0;
117     RealType bendPotential = 0.0;
118     RealType torsionPotential = 0.0;
119 gezelter 1930
120     //calculate short range interactions
121 gezelter 3126 for (mol = info_->beginMolecule(mi); mol != NULL;
122     mol = info_->nextMolecule(mi)) {
123 gezelter 1930
124 gezelter 2204 //change the positions of atoms which belong to the rigidbodies
125 gezelter 3126 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
126     rb = mol->nextRigidBody(rbIter)) {
127     rb->updateAtoms();
128 gezelter 2204 }
129 gezelter 1930
130 gezelter 3126 for (bond = mol->beginBond(bondIter); bond != NULL;
131     bond = mol->nextBond(bondIter)) {
132 tim 2448 bond->calcForce();
133     bondPotential += bond->getPotential();
134 gezelter 2204 }
135 gezelter 1930
136 gezelter 3126 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 2204 }
159 gezelter 3126
160     for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
161     torsion = mol->nextTorsion(torsionIter)) {
162 tim 2759 RealType angle;
163 gezelter 3126 torsion->calcForce(angle);
164 tim 2759 RealType currTorsionPot = torsion->getPotential();
165 gezelter 3126 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 1930 }
183    
184 gezelter 3126 RealType shortRangePotential = bondPotential + bendPotential +
185     torsionPotential;
186 gezelter 1930 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
187     curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
188 tim 2364 curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
189     curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
190     curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
191    
192 gezelter 2204 }
193 gezelter 3126
194     void ForceManager::calcLongRangeInteraction(bool needPotential,
195     bool needStress) {
196 gezelter 1930 Snapshot* curSnapshot;
197     DataStorage* config;
198 tim 2759 RealType* frc;
199     RealType* pos;
200     RealType* trq;
201     RealType* A;
202     RealType* electroFrame;
203     RealType* rc;
204 gezelter 1930
205     //get current snapshot from SimInfo
206     curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
207 gezelter 3126
208 gezelter 1930 //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 3126
224 gezelter 1930 if(info_->getNCutoffGroups() > 0){
225 gezelter 3126
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 2204 cg->getCOM(com);
231     rcGroup.push_back(com);
232 gezelter 1930 }
233 gezelter 2204 }// end for (mol)
234 gezelter 1930
235 gezelter 2204 rc = rcGroup[0].getArrayPointer();
236 gezelter 1930 } else {
237 gezelter 3126 // center of mass of the group is the same as position of the atom
238     // if cutoff group does not exist
239 gezelter 2204 rc = pos;
240 gezelter 1930 }
241 gezelter 3126
242 gezelter 1930 //initialize data before passing to fortran
243 tim 2759 RealType longRangePotential[LR_POT_TYPES];
244     RealType lrPot = 0.0;
245 chrisfen 2917 Vector3d totalDipole;
246 gezelter 1930 short int passedCalcPot = needPotential;
247     short int passedCalcStress = needStress;
248     int isError = 0;
249    
250 chuckv 2363 for (int i=0; i<LR_POT_TYPES;i++){
251     longRangePotential[i]=0.0; //Initialize array
252     }
253 gezelter 3126
254 gezelter 1930 doForceLoop( pos,
255 gezelter 2204 rc,
256     A,
257     electroFrame,
258     frc,
259     trq,
260     tau.getArrayPointer(),
261 chuckv 2363 longRangePotential,
262 gezelter 2204 &passedCalcPot,
263     &passedCalcStress,
264     &isError );
265 gezelter 1930
266     if( isError ){
267 gezelter 2204 sprintf( painCave.errMsg,
268     "Error returned from the fortran force calculation.\n" );
269     painCave.isFatal = 1;
270     simError();
271 gezelter 1930 }
272 chuckv 2363 for (int i=0; i<LR_POT_TYPES;i++){
273     lrPot += longRangePotential[i]; //Quick hack
274     }
275 gezelter 3126
276 chrisfen 2917 // grab the simulation box dipole moment if specified
277     if (info_->getCalcBoxDipole()){
278     getAccumulatedBoxDipole(totalDipole.getArrayPointer());
279 gezelter 3126
280 chrisfen 2917 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 3126
285 gezelter 1930 //store the tau and long range potential
286 chuckv 2363 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
287 chrisfen 2390 curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
288 tim 2380 curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
289 gezelter 2204 }
290 gezelter 1930
291 gezelter 3126
292     void ForceManager::postCalculation(bool needStress) {
293 gezelter 1930 SimInfo::MoleculeIterator mi;
294     Molecule* mol;
295     Molecule::RigidBodyIterator rbIter;
296     RigidBody* rb;
297 gezelter 3126 Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
298 gezelter 1930
299     // collect the atomic forces onto rigid bodies
300 gezelter 3126
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 2204 }
312 gezelter 3126 }
313 gezelter 1930
314 gezelter 3126 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 2204 }
323 gezelter 1930
324     } //end namespace oopse

Properties

Name Value
svn:executable *