ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/brains/ForceManager.cpp
Revision: 1927
Committed: Wed Jan 12 17:14:35 2005 UTC (21 years, 4 months ago) by tim
File size: 7657 byte(s)
Log Message:
change license

File Contents

# User Rev Content
1 tim 1927 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 tim 1722 *
4 tim 1927 * 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 tim 1722 */
41    
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 tim 1804 #include "primitives/Molecule.hpp"
52     #include "UseTheForce/doForces_interface.h"
53     #include "utils/simError.h"
54 tim 1722 namespace oopse {
55    
56     void ForceManager::calcForces(bool needPotential, bool needStress) {
57    
58 tim 1738 if (!info_->isFortranInitialized()) {
59     info_->update();
60     }
61 tim 1722
62 tim 1738 preCalculation();
63    
64     calcShortRangeInteraction();
65    
66 tim 1804 calcLongRangeInteraction(needPotential, needStress);
67 tim 1738
68 tim 1804 postCalculation();
69 tim 1738
70     }
71    
72     void ForceManager::preCalculation() {
73 tim 1804 SimInfo::MoleculeIterator mi;
74 tim 1722 Molecule* mol;
75 tim 1804 Molecule::AtomIterator ai;
76 tim 1722 Atom* atom;
77 tim 1881 Molecule::RigidBodyIterator rbIter;
78     RigidBody* rb;
79    
80 tim 1722 // forces are zeroed here, before any are accumulated.
81     // NOTE: do not rezero the forces in Fortran.
82     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
83     for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
84 tim 1881 atom->zeroForcesAndTorques();
85 tim 1722 }
86 tim 1881
87     //change the positions of atoms which belong to the rigidbodies
88     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
89     rb->zeroForcesAndTorques();
90     }
91 tim 1738 }
92    
93     }
94 tim 1722
95 tim 1738 void ForceManager::calcShortRangeInteraction() {
96     Molecule* mol;
97     RigidBody* rb;
98     Bond* bond;
99     Bend* bend;
100     Torsion* torsion;
101 tim 1804 SimInfo::MoleculeIterator mi;
102     Molecule::RigidBodyIterator rbIter;
103     Molecule::BondIterator bondIter;;
104     Molecule::BendIterator bendIter;
105     Molecule::TorsionIterator torsionIter;
106 tim 1738
107 tim 1722 //calculate short range interactions
108     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
109    
110 tim 1738 //change the positions of atoms which belong to the rigidbodies
111     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
112     rb->updateAtoms();
113     }
114 tim 1722
115 tim 1738 for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
116 tim 1804 bond->calcForce();
117 tim 1738 }
118    
119     for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
120 tim 1804 bend->calcForce();
121 tim 1738 }
122    
123     for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
124 tim 1804 torsion->calcForce();
125 tim 1738 }
126    
127     }
128    
129 tim 1901 double shortRangePotential = 0.0;
130     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
131     shortRangePotential += mol->getPotential();
132     }
133    
134     Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
135     curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
136 tim 1738 }
137    
138     void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) {
139     Snapshot* curSnapshot;
140     DataStorage* config;
141     double* frc;
142     double* pos;
143     double* trq;
144     double* A;
145 tim 1813 double* electroFrame;
146 tim 1738 double* rc;
147    
148 tim 1722 //get current snapshot from SimInfo
149 tim 1804 curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
150 tim 1722
151     //get array pointers
152     config = &(curSnapshot->atomData);
153     frc = config->getArrayPointer(DataStorage::dslForce);
154     pos = config->getArrayPointer(DataStorage::dslPosition);
155     trq = config->getArrayPointer(DataStorage::dslTorque);
156     A = config->getArrayPointer(DataStorage::dslAmat);
157 tim 1813 electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
158 tim 1722
159     //calculate the center of mass of cutoff group
160 tim 1804 SimInfo::MoleculeIterator mi;
161 tim 1738 Molecule* mol;
162 tim 1804 Molecule::CutoffGroupIterator ci;
163 tim 1738 CutoffGroup* cg;
164     Vector3d com;
165     std::vector<Vector3d> rcGroup;
166    
167 tim 1722 if(info_->getNCutoffGroups() > 0){
168    
169     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
170     for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
171 tim 1804 cg->getCOM(com);
172 tim 1722 rcGroup.push_back(com);
173     }
174     }// end for (mol)
175    
176 tim 1804 rc = rcGroup[0].getArrayPointer();
177 tim 1738 } else {
178 tim 1722 // center of mass of the group is the same as position of the atom if cutoff group does not exist
179     rc = pos;
180     }
181    
182     //initialize data before passing to fortran
183 tim 1738 double longRangePotential = 0.0;
184     Mat3x3d tau;
185     short int passedCalcPot = needPotential;
186     short int passedCalcStress = needStress;
187     int isError = 0;
188 tim 1722
189     doForceLoop( pos,
190     rc,
191     A,
192 tim 1813 electroFrame,
193 tim 1722 frc,
194     trq,
195 tim 1804 tau.getArrayPointer(),
196 tim 1722 &longRangePotential,
197     &passedCalcPot,
198     &passedCalcStress,
199     &isError );
200    
201     if( isError ){
202     sprintf( painCave.errMsg,
203     "Error returned from the fortran force calculation.\n" );
204     painCave.isFatal = 1;
205     simError();
206     }
207    
208     //store the tau and long range potential
209 tim 1804 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential;
210 tim 1805 curSnapshot->statData.setTau(tau);
211 tim 1738 }
212 tim 1722
213 tim 1738
214     void ForceManager::postCalculation() {
215 tim 1804 SimInfo::MoleculeIterator mi;
216 tim 1738 Molecule* mol;
217 tim 1804 Molecule::RigidBodyIterator rbIter;
218 tim 1738 RigidBody* rb;
219    
220 tim 1722 // collect the atomic forces onto rigid bodies
221     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
222 tim 1738 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
223     rb->calcForcesAndTorques();
224     }
225 tim 1722 }
226    
227     }
228    
229     } //end namespace oopse

Properties

Name Value
svn:executable *