ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/brains/ForceManager.cpp
Revision: 1901
Committed: Tue Jan 4 22:18:36 2005 UTC (19 years, 8 months ago) by tim
File size: 6728 byte(s)
Log Message:
constraints in progress

File Contents

# User Rev Content
1 tim 1722 /*
2     * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project
3     *
4     * Contact: oopse@oopse.org
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU Lesser General Public License
8     * as published by the Free Software Foundation; either version 2.1
9     * of the License, or (at your option) any later version.
10     * All we ask is that proper credit is given for our work, which includes
11     * - but is not limited to - adding the above copyright notice to the beginning
12     * of your source code files, and to any copyright notice that you may distribute
13     * with programs based on this work.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU Lesser General Public License for more details.
19     *
20     * You should have received a copy of the GNU Lesser General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23     *
24     */
25    
26     /**
27     * @file ForceManager.cpp
28     * @author tlin
29     * @date 11/09/2004
30     * @time 10:39am
31     * @version 1.0
32     */
33    
34     #include "brains/ForceManager.hpp"
35 tim 1804 #include "primitives/Molecule.hpp"
36     #include "UseTheForce/doForces_interface.h"
37     #include "utils/simError.h"
38 tim 1722 namespace oopse {
39    
40     void ForceManager::calcForces(bool needPotential, bool needStress) {
41    
42 tim 1738 if (!info_->isFortranInitialized()) {
43     info_->update();
44     }
45 tim 1722
46 tim 1738 preCalculation();
47    
48     calcShortRangeInteraction();
49    
50 tim 1804 calcLongRangeInteraction(needPotential, needStress);
51 tim 1738
52 tim 1804 postCalculation();
53 tim 1738
54     }
55    
56     void ForceManager::preCalculation() {
57 tim 1804 SimInfo::MoleculeIterator mi;
58 tim 1722 Molecule* mol;
59 tim 1804 Molecule::AtomIterator ai;
60 tim 1722 Atom* atom;
61 tim 1881 Molecule::RigidBodyIterator rbIter;
62     RigidBody* rb;
63    
64 tim 1722 // forces are zeroed here, before any are accumulated.
65     // NOTE: do not rezero the forces in Fortran.
66     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
67     for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
68 tim 1881 atom->zeroForcesAndTorques();
69 tim 1722 }
70 tim 1881
71     //change the positions of atoms which belong to the rigidbodies
72     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
73     rb->zeroForcesAndTorques();
74     }
75 tim 1738 }
76    
77     }
78 tim 1722
79 tim 1738 void ForceManager::calcShortRangeInteraction() {
80     Molecule* mol;
81     RigidBody* rb;
82     Bond* bond;
83     Bend* bend;
84     Torsion* torsion;
85 tim 1804 SimInfo::MoleculeIterator mi;
86     Molecule::RigidBodyIterator rbIter;
87     Molecule::BondIterator bondIter;;
88     Molecule::BendIterator bendIter;
89     Molecule::TorsionIterator torsionIter;
90 tim 1738
91 tim 1722 //calculate short range interactions
92     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
93    
94 tim 1738 //change the positions of atoms which belong to the rigidbodies
95     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
96     rb->updateAtoms();
97     }
98 tim 1722
99 tim 1738 for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
100 tim 1804 bond->calcForce();
101 tim 1738 }
102    
103     for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
104 tim 1804 bend->calcForce();
105 tim 1738 }
106    
107     for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
108 tim 1804 torsion->calcForce();
109 tim 1738 }
110    
111     }
112    
113 tim 1901 double shortRangePotential = 0.0;
114     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
115     shortRangePotential += mol->getPotential();
116     }
117    
118     Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
119     curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential;
120 tim 1738 }
121    
122     void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) {
123     Snapshot* curSnapshot;
124     DataStorage* config;
125     double* frc;
126     double* pos;
127     double* trq;
128     double* A;
129 tim 1813 double* electroFrame;
130 tim 1738 double* rc;
131    
132 tim 1722 //get current snapshot from SimInfo
133 tim 1804 curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
134 tim 1722
135     //get array pointers
136     config = &(curSnapshot->atomData);
137     frc = config->getArrayPointer(DataStorage::dslForce);
138     pos = config->getArrayPointer(DataStorage::dslPosition);
139     trq = config->getArrayPointer(DataStorage::dslTorque);
140     A = config->getArrayPointer(DataStorage::dslAmat);
141 tim 1813 electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
142 tim 1722
143     //calculate the center of mass of cutoff group
144 tim 1804 SimInfo::MoleculeIterator mi;
145 tim 1738 Molecule* mol;
146 tim 1804 Molecule::CutoffGroupIterator ci;
147 tim 1738 CutoffGroup* cg;
148     Vector3d com;
149     std::vector<Vector3d> rcGroup;
150    
151 tim 1722 if(info_->getNCutoffGroups() > 0){
152    
153     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
154     for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
155 tim 1804 cg->getCOM(com);
156 tim 1722 rcGroup.push_back(com);
157     }
158     }// end for (mol)
159    
160 tim 1804 rc = rcGroup[0].getArrayPointer();
161 tim 1738 } else {
162 tim 1722 // center of mass of the group is the same as position of the atom if cutoff group does not exist
163     rc = pos;
164     }
165    
166     //initialize data before passing to fortran
167 tim 1738 double longRangePotential = 0.0;
168     Mat3x3d tau;
169     short int passedCalcPot = needPotential;
170     short int passedCalcStress = needStress;
171     int isError = 0;
172 tim 1722
173     doForceLoop( pos,
174     rc,
175     A,
176 tim 1813 electroFrame,
177 tim 1722 frc,
178     trq,
179 tim 1804 tau.getArrayPointer(),
180 tim 1722 &longRangePotential,
181     &passedCalcPot,
182     &passedCalcStress,
183     &isError );
184    
185     if( isError ){
186     sprintf( painCave.errMsg,
187     "Error returned from the fortran force calculation.\n" );
188     painCave.isFatal = 1;
189     simError();
190     }
191    
192     //store the tau and long range potential
193 tim 1804 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential;
194 tim 1805 curSnapshot->statData.setTau(tau);
195 tim 1738 }
196 tim 1722
197 tim 1738
198     void ForceManager::postCalculation() {
199 tim 1804 SimInfo::MoleculeIterator mi;
200 tim 1738 Molecule* mol;
201 tim 1804 Molecule::RigidBodyIterator rbIter;
202 tim 1738 RigidBody* rb;
203    
204 tim 1722 // collect the atomic forces onto rigid bodies
205     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
206 tim 1738 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
207     rb->calcForcesAndTorques();
208     }
209 tim 1722 }
210    
211     }
212    
213     } //end namespace oopse

Properties

Name Value
svn:executable *