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: 1881
Committed: Fri Dec 10 16:14:53 2004 UTC (19 years, 9 months ago) by tim
File size: 6385 byte(s)
Log Message:
forget to zero out the torque. Sticky and Dipole is working now

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     }
114    
115     void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) {
116     Snapshot* curSnapshot;
117     DataStorage* config;
118     double* frc;
119     double* pos;
120     double* trq;
121     double* A;
122 tim 1813 double* electroFrame;
123 tim 1738 double* rc;
124    
125 tim 1722 //get current snapshot from SimInfo
126 tim 1804 curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
127 tim 1722
128     //get array pointers
129     config = &(curSnapshot->atomData);
130     frc = config->getArrayPointer(DataStorage::dslForce);
131     pos = config->getArrayPointer(DataStorage::dslPosition);
132     trq = config->getArrayPointer(DataStorage::dslTorque);
133     A = config->getArrayPointer(DataStorage::dslAmat);
134 tim 1813 electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
135 tim 1722
136     //calculate the center of mass of cutoff group
137 tim 1804 SimInfo::MoleculeIterator mi;
138 tim 1738 Molecule* mol;
139 tim 1804 Molecule::CutoffGroupIterator ci;
140 tim 1738 CutoffGroup* cg;
141     Vector3d com;
142     std::vector<Vector3d> rcGroup;
143    
144 tim 1722 if(info_->getNCutoffGroups() > 0){
145    
146     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
147     for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
148 tim 1804 cg->getCOM(com);
149 tim 1722 rcGroup.push_back(com);
150     }
151     }// end for (mol)
152    
153 tim 1804 rc = rcGroup[0].getArrayPointer();
154 tim 1738 } else {
155 tim 1722 // center of mass of the group is the same as position of the atom if cutoff group does not exist
156     rc = pos;
157     }
158    
159     //initialize data before passing to fortran
160 tim 1738 double longRangePotential = 0.0;
161     Mat3x3d tau;
162     short int passedCalcPot = needPotential;
163     short int passedCalcStress = needStress;
164     int isError = 0;
165 tim 1722
166     doForceLoop( pos,
167     rc,
168     A,
169 tim 1813 electroFrame,
170 tim 1722 frc,
171     trq,
172 tim 1804 tau.getArrayPointer(),
173 tim 1722 &longRangePotential,
174     &passedCalcPot,
175     &passedCalcStress,
176     &isError );
177    
178     if( isError ){
179     sprintf( painCave.errMsg,
180     "Error returned from the fortran force calculation.\n" );
181     painCave.isFatal = 1;
182     simError();
183     }
184    
185     //store the tau and long range potential
186 tim 1804 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential;
187 tim 1805 curSnapshot->statData.setTau(tau);
188 tim 1738 }
189 tim 1722
190 tim 1738
191     void ForceManager::postCalculation() {
192 tim 1804 SimInfo::MoleculeIterator mi;
193 tim 1738 Molecule* mol;
194 tim 1804 Molecule::RigidBodyIterator rbIter;
195 tim 1738 RigidBody* rb;
196    
197 tim 1722 // collect the atomic forces onto rigid bodies
198     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
199 tim 1738 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
200     rb->calcForcesAndTorques();
201     }
202 tim 1722 }
203    
204     }
205    
206     } //end namespace oopse

Properties

Name Value
svn:executable *