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: 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

# 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 }
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 double* electroFrame;
123 double* rc;
124
125 //get current snapshot from SimInfo
126 curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
127
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 electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame);
135
136 //calculate the center of mass of cutoff group
137 SimInfo::MoleculeIterator mi;
138 Molecule* mol;
139 Molecule::CutoffGroupIterator ci;
140 CutoffGroup* cg;
141 Vector3d com;
142 std::vector<Vector3d> rcGroup;
143
144 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 cg->getCOM(com);
149 rcGroup.push_back(com);
150 }
151 }// end for (mol)
152
153 rc = rcGroup[0].getArrayPointer();
154 } else {
155 // 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 double longRangePotential = 0.0;
161 Mat3x3d tau;
162 short int passedCalcPot = needPotential;
163 short int passedCalcStress = needStress;
164 int isError = 0;
165
166 doForceLoop( pos,
167 rc,
168 A,
169 electroFrame,
170 frc,
171 trq,
172 tau.getArrayPointer(),
173 &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 curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential;
187 curSnapshot->statData.setTau(tau);
188 }
189
190
191 void ForceManager::postCalculation() {
192 SimInfo::MoleculeIterator mi;
193 Molecule* mol;
194 Molecule::RigidBodyIterator rbIter;
195 RigidBody* rb;
196
197 // collect the atomic forces onto rigid bodies
198 for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
199 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
200 rb->calcForcesAndTorques();
201 }
202 }
203
204 }
205
206 } //end namespace oopse

Properties

Name Value
svn:executable *