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

File Contents

# Content
1 /*
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 #include "primitives/Molecule.hpp"
36 #include "UseTheForce/doForces_interface.h"
37 #include "utils/simError.h"
38 namespace oopse {
39
40 void ForceManager::calcForces(bool needPotential, bool needStress) {
41
42 if (!info_->isFortranInitialized()) {
43 info_->update();
44 }
45
46 preCalculation();
47
48 calcShortRangeInteraction();
49
50 calcLongRangeInteraction(needPotential, needStress);
51
52 postCalculation();
53
54 }
55
56 void ForceManager::preCalculation() {
57 SimInfo::MoleculeIterator mi;
58 Molecule* mol;
59 Molecule::AtomIterator ai;
60 Atom* atom;
61 Molecule::RigidBodyIterator rbIter;
62 RigidBody* rb;
63
64 // 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 atom->zeroForcesAndTorques();
69 }
70
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 }
76
77 }
78
79 void ForceManager::calcShortRangeInteraction() {
80 Molecule* mol;
81 RigidBody* rb;
82 Bond* bond;
83 Bend* bend;
84 Torsion* torsion;
85 SimInfo::MoleculeIterator mi;
86 Molecule::RigidBodyIterator rbIter;
87 Molecule::BondIterator bondIter;;
88 Molecule::BendIterator bendIter;
89 Molecule::TorsionIterator torsionIter;
90
91 //calculate short range interactions
92 for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
93
94 //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
99 for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
100 bond->calcForce();
101 }
102
103 for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
104 bend->calcForce();
105 }
106
107 for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
108 torsion->calcForce();
109 }
110
111 }
112
113 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 }
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 double* electroFrame;
130 double* rc;
131
132 //get current snapshot from SimInfo
133 curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
134
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 electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
142
143 //calculate the center of mass of cutoff group
144 SimInfo::MoleculeIterator mi;
145 Molecule* mol;
146 Molecule::CutoffGroupIterator ci;
147 CutoffGroup* cg;
148 Vector3d com;
149 std::vector<Vector3d> rcGroup;
150
151 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 cg->getCOM(com);
156 rcGroup.push_back(com);
157 }
158 }// end for (mol)
159
160 rc = rcGroup[0].getArrayPointer();
161 } else {
162 // 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 double longRangePotential = 0.0;
168 Mat3x3d tau;
169 short int passedCalcPot = needPotential;
170 short int passedCalcStress = needStress;
171 int isError = 0;
172
173 doForceLoop( pos,
174 rc,
175 A,
176 electroFrame,
177 frc,
178 trq,
179 tau.getArrayPointer(),
180 &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 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential;
194 curSnapshot->statData.setTau(tau);
195 }
196
197
198 void ForceManager::postCalculation() {
199 SimInfo::MoleculeIterator mi;
200 Molecule* mol;
201 Molecule::RigidBodyIterator rbIter;
202 RigidBody* rb;
203
204 // collect the atomic forces onto rigid bodies
205 for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
206 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
207 rb->calcForcesAndTorques();
208 }
209 }
210
211 }
212
213 } //end namespace oopse

Properties

Name Value
svn:executable *