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 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
branches/development/src/brains/ForceManager.cpp (file contents), Revision 1469 by gezelter, Mon Jul 19 14:07:59 2010 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# 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 < /**
43 <  * @file ForceManager.cpp
44 <  * @author tlin
45 <  * @date 11/09/2004
46 <  * @time 10:39am
47 <  * @version 1.0
48 <  */
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 < 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) {
62 <
61 > namespace OpenMD {
62 >  
63 >  ForceManager::ForceManager(SimInfo * info) : info_(info),
64 >                                               NBforcesInitialized_(false) {
65 >    std::cerr << __PRETTY_FUNCTION__ << "\n";
66 >    lj_ = new LJ(info_->getForceField());
67 >  }
68 >
69 >  void ForceManager::calcForces() {
70 >    
71 >    std::cerr << __PRETTY_FUNCTION__ << "\n";
72      if (!info_->isFortranInitialized()) {
73 <        info_->update();
73 >      info_->update();
74      }
75 +    
76 +    if (!NBforcesInitialized_) {
77 +      lj_->initialize();    
78 +    }
79  
80      preCalculation();
81      
82      calcShortRangeInteraction();
83  
84 <    calcLongRangeInteraction(needPotential, needStress);
84 >    calcLongRangeInteraction();
85  
86      postCalculation();
87 <        
88 < }
89 <
90 < void ForceManager::preCalculation() {
87 >    
88 >  }
89 >  
90 >  void ForceManager::preCalculation() {
91      SimInfo::MoleculeIterator mi;
92      Molecule* mol;
93      Molecule::AtomIterator ai;
# Line 79 | Line 97 | void ForceManager::preCalculation() {
97      
98      // forces are zeroed here, before any are accumulated.
99      // NOTE: do not rezero the forces in Fortran.
100 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
101 <        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
102 <            atom->zeroForcesAndTorques();
103 <        }
104 <        
105 <        //change the positions of atoms which belong to the rigidbodies
106 <        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
107 <            rb->zeroForcesAndTorques();
108 <        }        
100 >    
101 >    for (mol = info_->beginMolecule(mi); mol != NULL;
102 >         mol = info_->nextMolecule(mi)) {
103 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
104 >        atom->zeroForcesAndTorques();
105 >      }
106 >          
107 >      //change the positions of atoms which belong to the rigidbodies
108 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
109 >           rb = mol->nextRigidBody(rbIter)) {
110 >        rb->zeroForcesAndTorques();
111 >      }        
112 >          
113      }
114      
115 < }
116 <
117 < void ForceManager::calcShortRangeInteraction() {
115 >    // Zero out the stress tensor
116 >    tau *= 0.0;
117 >    
118 >  }
119 >  
120 >  void ForceManager::calcShortRangeInteraction() {
121      Molecule* mol;
122      RigidBody* rb;
123      Bond* bond;
124      Bend* bend;
125      Torsion* torsion;
126 +    Inversion* inversion;
127      SimInfo::MoleculeIterator mi;
128      Molecule::RigidBodyIterator rbIter;
129      Molecule::BondIterator bondIter;;
130      Molecule::BendIterator  bendIter;
131      Molecule::TorsionIterator  torsionIter;
132 +    Molecule::InversionIterator  inversionIter;
133 +    RealType bondPotential = 0.0;
134 +    RealType bendPotential = 0.0;
135 +    RealType torsionPotential = 0.0;
136 +    RealType inversionPotential = 0.0;
137  
138      //calculate short range interactions    
139 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
139 >    for (mol = info_->beginMolecule(mi); mol != NULL;
140 >         mol = info_->nextMolecule(mi)) {
141  
142 <        //change the positions of atoms which belong to the rigidbodies
143 <        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
144 <            rb->updateAtoms();
145 <        }
142 >      //change the positions of atoms which belong to the rigidbodies
143 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
144 >           rb = mol->nextRigidBody(rbIter)) {
145 >        rb->updateAtoms();
146 >      }
147  
148 <        for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
149 <            bond->calcForce();
150 <        }
148 >      for (bond = mol->beginBond(bondIter); bond != NULL;
149 >           bond = mol->nextBond(bondIter)) {
150 >        bond->calcForce();
151 >        bondPotential += bond->getPotential();
152 >      }
153  
154 <        for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
155 <            bend->calcForce();
154 >      for (bend = mol->beginBend(bendIter); bend != NULL;
155 >           bend = mol->nextBend(bendIter)) {
156 >        
157 >        RealType angle;
158 >        bend->calcForce(angle);
159 >        RealType currBendPot = bend->getPotential();          
160 >        
161 >        bendPotential += bend->getPotential();
162 >        std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend);
163 >        if (i == bendDataSets.end()) {
164 >          BendDataSet dataSet;
165 >          dataSet.prev.angle = dataSet.curr.angle = angle;
166 >          dataSet.prev.potential = dataSet.curr.potential = currBendPot;
167 >          dataSet.deltaV = 0.0;
168 >          bendDataSets.insert(std::map<Bend*, BendDataSet>::value_type(bend, dataSet));
169 >        }else {
170 >          i->second.prev.angle = i->second.curr.angle;
171 >          i->second.prev.potential = i->second.curr.potential;
172 >          i->second.curr.angle = angle;
173 >          i->second.curr.potential = currBendPot;
174 >          i->second.deltaV =  fabs(i->second.curr.potential -  
175 >                                   i->second.prev.potential);
176          }
177 +      }
178 +      
179 +      for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
180 +           torsion = mol->nextTorsion(torsionIter)) {
181 +        RealType angle;
182 +        torsion->calcForce(angle);
183 +        RealType currTorsionPot = torsion->getPotential();
184 +        torsionPotential += torsion->getPotential();
185 +        std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
186 +        if (i == torsionDataSets.end()) {
187 +          TorsionDataSet dataSet;
188 +          dataSet.prev.angle = dataSet.curr.angle = angle;
189 +          dataSet.prev.potential = dataSet.curr.potential = currTorsionPot;
190 +          dataSet.deltaV = 0.0;
191 +          torsionDataSets.insert(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet));
192 +        }else {
193 +          i->second.prev.angle = i->second.curr.angle;
194 +          i->second.prev.potential = i->second.curr.potential;
195 +          i->second.curr.angle = angle;
196 +          i->second.curr.potential = currTorsionPot;
197 +          i->second.deltaV =  fabs(i->second.curr.potential -  
198 +                                   i->second.prev.potential);
199 +        }      
200 +      }      
201  
202 <        for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
203 <            torsion->calcForce();
204 <        }
205 <
202 >      for (inversion = mol->beginInversion(inversionIter);
203 >           inversion != NULL;
204 >           inversion = mol->nextInversion(inversionIter)) {
205 >        RealType angle;
206 >        inversion->calcForce(angle);
207 >        RealType currInversionPot = inversion->getPotential();
208 >        inversionPotential += inversion->getPotential();
209 >        std::map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
210 >        if (i == inversionDataSets.end()) {
211 >          InversionDataSet dataSet;
212 >          dataSet.prev.angle = dataSet.curr.angle = angle;
213 >          dataSet.prev.potential = dataSet.curr.potential = currInversionPot;
214 >          dataSet.deltaV = 0.0;
215 >          inversionDataSets.insert(std::map<Inversion*, InversionDataSet>::value_type(inversion, dataSet));
216 >        }else {
217 >          i->second.prev.angle = i->second.curr.angle;
218 >          i->second.prev.potential = i->second.curr.potential;
219 >          i->second.curr.angle = angle;
220 >          i->second.curr.potential = currInversionPot;
221 >          i->second.deltaV =  fabs(i->second.curr.potential -  
222 >                                   i->second.prev.potential);
223 >        }      
224 >      }      
225      }
226      
227 <    double  shortRangePotential = 0.0;
228 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
131 <        shortRangePotential += mol->getPotential();
132 <    }
133 <
227 >    RealType  shortRangePotential = bondPotential + bendPotential +
228 >      torsionPotential +  inversionPotential;    
229      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
230      curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
231 < }
232 <
233 < void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) {
231 >    curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential;
232 >    curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential;
233 >    curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential;
234 >    curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential;
235 >    
236 >  }
237 >  
238 >  void ForceManager::calcLongRangeInteraction() {
239      Snapshot* curSnapshot;
240      DataStorage* config;
241 <    double* frc;
242 <    double* pos;
243 <    double* trq;
244 <    double* A;
245 <    double* electroFrame;
246 <    double* rc;
241 >    RealType* frc;
242 >    RealType* pos;
243 >    RealType* trq;
244 >    RealType* A;
245 >    RealType* electroFrame;
246 >    RealType* rc;
247 >    RealType* particlePot;
248      
249      //get current snapshot from SimInfo
250      curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
251 <
251 >    
252      //get array pointers
253      config = &(curSnapshot->atomData);
254      frc = config->getArrayPointer(DataStorage::dslForce);
# Line 155 | Line 256 | void ForceManager::calcLongRangeInteraction(bool needP
256      trq = config->getArrayPointer(DataStorage::dslTorque);
257      A   = config->getArrayPointer(DataStorage::dslAmat);
258      electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
259 +    particlePot = config->getArrayPointer(DataStorage::dslParticlePot);
260  
261      //calculate the center of mass of cutoff group
262      SimInfo::MoleculeIterator mi;
# Line 165 | Line 267 | void ForceManager::calcLongRangeInteraction(bool needP
267      std::vector<Vector3d> rcGroup;
268      
269      if(info_->getNCutoffGroups() > 0){
270 <
271 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
272 <        for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
273 <            cg->getCOM(com);
274 <            rcGroup.push_back(com);
270 >      
271 >      for (mol = info_->beginMolecule(mi); mol != NULL;
272 >           mol = info_->nextMolecule(mi)) {
273 >        for(cg = mol->beginCutoffGroup(ci); cg != NULL;
274 >            cg = mol->nextCutoffGroup(ci)) {
275 >          cg->getCOM(com);
276 >          rcGroup.push_back(com);
277          }
278 <    }// end for (mol)
278 >      }// end for (mol)
279        
280 <        rc = rcGroup[0].getArrayPointer();
280 >      rc = rcGroup[0].getArrayPointer();
281      } else {
282 <        // center of mass of the group is the same as position of the atom  if cutoff group does not exist
283 <        rc = pos;
282 >      // center of mass of the group is the same as position of the atom  
283 >      // if cutoff group does not exist
284 >      rc = pos;
285      }
286 <  
286 >    
287      //initialize data before passing to fortran
288 <    double longRangePotential = 0.0;
289 <    Mat3x3d tau;
290 <    short int passedCalcPot = needPotential;
186 <    short int passedCalcStress = needStress;
288 >    RealType longRangePotential[LR_POT_TYPES];
289 >    RealType lrPot = 0.0;
290 >    Vector3d totalDipole;
291      int isError = 0;
292  
293 <    doForceLoop( pos,
294 <            rc,
295 <            A,
296 <            electroFrame,
297 <            frc,
298 <            trq,
299 <            tau.getArrayPointer(),
300 <            &longRangePotential,
301 <            &passedCalcPot,
302 <            &passedCalcStress,
303 <            &isError );
304 <
293 >    for (int i=0; i<LR_POT_TYPES;i++){
294 >      longRangePotential[i]=0.0; //Initialize array
295 >    }
296 >    
297 >    doForceLoop(pos,
298 >                rc,
299 >                A,
300 >                electroFrame,
301 >                frc,
302 >                trq,
303 >                tau.getArrayPointer(),
304 >                longRangePotential,
305 >                particlePot,
306 >                &isError );
307 >    
308      if( isError ){
309 <        sprintf( painCave.errMsg,
310 <             "Error returned from the fortran force calculation.\n" );
311 <        painCave.isFatal = 1;
312 <        simError();
309 >      sprintf( painCave.errMsg,
310 >               "Error returned from the fortran force calculation.\n" );
311 >      painCave.isFatal = 1;
312 >      simError();
313      }
314 <
314 >    for (int i=0; i<LR_POT_TYPES;i++){
315 >      lrPot += longRangePotential[i]; //Quick hack
316 >    }
317 >    
318 >    // grab the simulation box dipole moment if specified
319 >    if (info_->getCalcBoxDipole()){
320 >      getAccumulatedBoxDipole(totalDipole.getArrayPointer());
321 >      
322 >      curSnapshot->statData[Stats::BOX_DIPOLE_X] = totalDipole(0);
323 >      curSnapshot->statData[Stats::BOX_DIPOLE_Y] = totalDipole(1);
324 >      curSnapshot->statData[Stats::BOX_DIPOLE_Z] = totalDipole(2);
325 >    }
326 >    
327      //store the tau and long range potential    
328 <    curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential;
329 <    curSnapshot->statData.setTau(tau);
330 < }
328 >    curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
329 >    curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT];
330 >    curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT];
331 >  }
332  
333 <
334 < void ForceManager::postCalculation() {
333 >  
334 >  void ForceManager::postCalculation() {
335      SimInfo::MoleculeIterator mi;
336      Molecule* mol;
337      Molecule::RigidBodyIterator rbIter;
338      RigidBody* rb;
339 +    Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
340      
341      // collect the atomic forces onto rigid bodies
342 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
343 <        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
344 <            rb->calcForcesAndTorques();
345 <        }
342 >    
343 >    for (mol = info_->beginMolecule(mi); mol != NULL;
344 >         mol = info_->nextMolecule(mi)) {
345 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
346 >           rb = mol->nextRigidBody(rbIter)) {
347 >        Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial();
348 >        tau += rbTau;
349 >      }
350      }
351 +    
352 + #ifdef IS_MPI
353 +    Mat3x3d tmpTau(tau);
354 +    MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(),
355 +                  9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
356 + #endif
357 +    curSnapshot->statData.setTau(tau);
358 +  }
359  
360 < }
228 <
229 < } //end namespace oopse
360 > } //end namespace OpenMD

Comparing:
trunk/src/brains/ForceManager.cpp (property svn:keywords), Revision 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
branches/development/src/brains/ForceManager.cpp (property svn:keywords), Revision 1469 by gezelter, Mon Jul 19 14:07:59 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines