ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/ForceManager.cpp
(Generate patch)

Comparing:
trunk/src/brains/ForceManager.cpp (file contents), Revision 664 by chuckv, Wed Oct 12 21:57:16 2005 UTC vs.
branches/development/src/brains/ForceManager.cpp (file contents), Revision 1535 by gezelter, Fri Dec 31 18:31:56 2010 UTC

# Line 6 | Line 6
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
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
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.
# Line 37 | Line 28
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   /**
# Line 50 | Line 50
50   #include "brains/ForceManager.hpp"
51   #include "primitives/Molecule.hpp"
52   #include "UseTheForce/doForces_interface.h"
53 < #define __C
53 > #define __OPENMD_C
54   #include "UseTheForce/DarkSide/fInteractionMap.h"
55   #include "utils/simError.h"
56 < namespace oopse {
56 > #include "primitives/Bond.hpp"
57 > #include "primitives/Bend.hpp"
58 > #include "primitives/Torsion.hpp"
59 > #include "primitives/Inversion.hpp"
60  
61 <  void ForceManager::calcForces(bool needPotential, bool needStress) {
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 <
76 >    
77      preCalculation();
78      
79      calcShortRangeInteraction();
80  
81 <    calcLongRangeInteraction(needPotential, needStress);
81 >    calcLongRangeInteraction();
82  
83      postCalculation();
84 <        
84 >    
85    }
86 <
86 >  
87    void ForceManager::preCalculation() {
88      SimInfo::MoleculeIterator mi;
89      Molecule* mol;
# Line 81 | Line 94 | namespace oopse {
94      
95      // forces are zeroed here, before any are accumulated.
96      // NOTE: do not rezero the forces in Fortran.
97 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
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 <        
103 >          
104        //change the positions of atoms which belong to the rigidbodies
105 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
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 <
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; mol = info_->nextMolecule(mi)) {
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; rb = mol->nextRigidBody(rbIter)) {
141 <        rb->updateAtoms();
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; bond = mol->nextBond(bondIter)) {
146 <        bond->calcForce();
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; bend = mol->nextBend(bendIter)) {
152 <        bend->calcForce();
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 (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
200 <        torsion->calcForce();
201 <      }
202 <
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 <    double  shortRangePotential = 0.0;
225 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
133 <      shortRangePotential += mol->getPotential();
134 <    }
135 <
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(bool needPotential, bool needStress) {
234 >  
235 >  void ForceManager::calcLongRangeInteraction() {
236      Snapshot* curSnapshot;
237      DataStorage* config;
238 <    double* frc;
239 <    double* pos;
240 <    double* trq;
241 <    double* A;
242 <    double* electroFrame;
243 <    double* rc;
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 <
248 >    
249      //get array pointers
250      config = &(curSnapshot->atomData);
251      frc = config->getArrayPointer(DataStorage::dslForce);
# Line 157 | Line 253 | namespace oopse {
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;
# Line 165 | Line 262 | namespace oopse {
262      CutoffGroup* cg;
263      Vector3d com;
264      std::vector<Vector3d> rcGroup;
265 <
265 >    
266      if(info_->getNCutoffGroups() > 0){
267 <
268 <      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
269 <        for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
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          }
# Line 177 | Line 276 | namespace oopse {
276        
277        rc = rcGroup[0].getArrayPointer();
278      } else {
279 <      // center of mass of the group is the same as position of the atom  if cutoff group does not exist
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      }
183  
184    //initialize data before passing to fortran
185    double longRangePotential[LR_POT_TYPES];
186    double lrPot = 0.0;
283      
284 <    Mat3x3d tau;
285 <    short int passedCalcPot = needPotential;
286 <    short int passedCalcStress = needStress;
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 <
294 <
295 <    doForceLoop( pos,
296 <                 rc,
297 <                 A,
298 <                 electroFrame,
299 <                 frc,
300 <                 trq,
301 <                 tau.getArrayPointer(),
302 <                 longRangePotential,
303 <                 &passedCalcPot,
208 <                 &passedCalcStress,
209 <                 &isError );
210 <
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" );
# Line 217 | Line 310 | namespace oopse {
310      for (int i=0; i<LR_POT_TYPES;i++){
311        lrPot += longRangePotential[i]; //Quick hack
312      }
313 <
313 >        
314      //store the tau and long range potential    
315      curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
316 <    //  curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential;
317 <    curSnapshot->statData.setTau(tau);
316 >    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
317 >    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
318    }
319  
320 <
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 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
330 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
331 <        rb->calcForcesAndTorques();
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 <
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 oopse
347 > } //end namespace OpenMD

Comparing:
trunk/src/brains/ForceManager.cpp (property svn:keywords), Revision 664 by chuckv, Wed Oct 12 21:57:16 2005 UTC vs.
branches/development/src/brains/ForceManager.cpp (property svn:keywords), Revision 1535 by gezelter, Fri Dec 31 18:31:56 2010 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines