45 |
|
#include "utils/simError.h" |
46 |
|
namespace OpenMD { |
47 |
|
|
48 |
< |
Rattle::Rattle(SimInfo* info) : info_(info), maxConsIteration_(10), consTolerance_(1.0e-6), doRattle_(false) { |
48 |
> |
Rattle::Rattle(SimInfo* info) : info_(info), maxConsIteration_(10), |
49 |
> |
consTolerance_(1.0e-6), doRattle_(false), |
50 |
> |
currConstraintTime_(0.0) { |
51 |
|
|
52 |
< |
if (info_->getNConstraints() > 0) |
52 |
> |
if (info_->getNGlobalConstraints() > 0) |
53 |
|
doRattle_ = true; |
54 |
|
|
55 |
+ |
Globals* simParams = info_->getSimParams(); |
56 |
|
|
57 |
< |
if (info_->getSimParams()->haveDt()) { |
58 |
< |
dt_ = info_->getSimParams()->getDt(); |
57 |
> |
if (simParams->haveDt()) { |
58 |
> |
dt_ = simParams->getDt(); |
59 |
|
} else { |
60 |
|
sprintf(painCave.errMsg, |
61 |
< |
"Integrator Error: dt is not set\n"); |
61 |
> |
"Rattle Error: dt is not set\n"); |
62 |
|
painCave.isFatal = 1; |
63 |
|
simError(); |
64 |
|
} |
65 |
< |
|
65 |
> |
|
66 |
|
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
67 |
+ |
if (simParams->haveConstraintTime()){ |
68 |
+ |
constraintTime_ = simParams->getConstraintTime(); |
69 |
+ |
} else { |
70 |
+ |
constraintTime_ = simParams->getStatusTime(); |
71 |
+ |
} |
72 |
+ |
|
73 |
+ |
constraintOutputFile_ = getPrefix(info_->getFinalConfigFileName()) + |
74 |
+ |
".constraintForces"; |
75 |
+ |
|
76 |
+ |
// create ConstraintWriter |
77 |
+ |
constraintWriter_ = new ConstraintWriter(info_, |
78 |
+ |
constraintOutputFile_.c_str()); |
79 |
+ |
|
80 |
+ |
if (!constraintWriter_){ |
81 |
+ |
sprintf(painCave.errMsg, "Failed to create ConstraintWriter\n"); |
82 |
+ |
painCave.isFatal = 1; |
83 |
+ |
simError(); |
84 |
+ |
} |
85 |
|
} |
86 |
|
|
87 |
|
void Rattle::constraintA() { |
91 |
|
void Rattle::constraintB() { |
92 |
|
if (!doRattle_) return; |
93 |
|
doConstraint(&Rattle::constraintPairB); |
94 |
+ |
|
95 |
+ |
if (currentSnapshot_->getTime() >= currConstraintTime_){ |
96 |
+ |
Molecule* mol; |
97 |
+ |
SimInfo::MoleculeIterator mi; |
98 |
+ |
ConstraintPair* consPair; |
99 |
+ |
Molecule::ConstraintPairIterator cpi; |
100 |
+ |
std::list<ConstraintPair*> constraints; |
101 |
+ |
for (mol = info_->beginMolecule(mi); mol != NULL; |
102 |
+ |
mol = info_->nextMolecule(mi)) { |
103 |
+ |
for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; |
104 |
+ |
consPair = mol->nextConstraintPair(cpi)) { |
105 |
+ |
|
106 |
+ |
constraints.push_back(consPair); |
107 |
+ |
} |
108 |
+ |
} |
109 |
+ |
constraintWriter_->writeConstraintForces(constraints); |
110 |
+ |
currConstraintTime_ += constraintTime_; |
111 |
+ |
} |
112 |
|
} |
113 |
|
|
114 |
|
void Rattle::doConstraint(ConstraintPairFuncPtr func) { |
121 |
|
ConstraintPair* consPair; |
122 |
|
Molecule::ConstraintPairIterator cpi; |
123 |
|
|
124 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
125 |
< |
for (consElem = mol->beginConstraintElem(cei); consElem != NULL; consElem = mol->nextConstraintElem(cei)) { |
124 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
125 |
> |
mol = info_->nextMolecule(mi)) { |
126 |
> |
for (consElem = mol->beginConstraintElem(cei); consElem != NULL; |
127 |
> |
consElem = mol->nextConstraintElem(cei)) { |
128 |
|
consElem->setMoved(true); |
129 |
|
consElem->setMoving(false); |
130 |
|
} |
138 |
|
|
139 |
|
//loop over every constraint pair |
140 |
|
|
141 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
142 |
< |
for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) { |
141 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
142 |
> |
mol = info_->nextMolecule(mi)) { |
143 |
> |
for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; |
144 |
> |
consPair = mol->nextConstraintPair(cpi)) { |
145 |
|
|
146 |
|
|
147 |
|
//dispatch constraint algorithm |
151 |
|
switch(exeStatus){ |
152 |
|
case consFail: |
153 |
|
sprintf(painCave.errMsg, |
154 |
< |
"Constraint failure in Rattle::constrainA, Constraint Fail\n"); |
154 |
> |
"Constraint failure in Rattle::constrainA, " |
155 |
> |
"Constraint Fail\n"); |
156 |
|
painCave.isFatal = 1; |
157 |
|
simError(); |
158 |
|
|
159 |
|
break; |
160 |
|
case consSuccess: |
161 |
< |
//constrain the pair by moving two elements |
161 |
> |
// constrain the pair by moving two elements |
162 |
|
done = false; |
163 |
|
consPair->getConsElem1()->setMoving(true); |
164 |
|
consPair->getConsElem2()->setMoving(true); |
165 |
|
break; |
166 |
|
case consAlready: |
167 |
< |
//current pair is already constrained, do not need to move the elements |
167 |
> |
// current pair is already constrained, do not need to |
168 |
> |
// move the elements |
169 |
|
break; |
170 |
|
default: |
171 |
< |
sprintf(painCave.errMsg, "ConstraintAlgorithm::doConstrain() Error: unrecognized status"); |
171 |
> |
sprintf(painCave.errMsg, "ConstraintAlgorithm::doConstraint() " |
172 |
> |
"Error: unrecognized status"); |
173 |
|
painCave.isFatal = 1; |
174 |
|
simError(); |
175 |
|
break; |
179 |
|
}//end for(iter->first()) |
180 |
|
|
181 |
|
|
182 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
183 |
< |
for (consElem = mol->beginConstraintElem(cei); consElem != NULL; consElem = mol->nextConstraintElem(cei)) { |
182 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
183 |
> |
mol = info_->nextMolecule(mi)) { |
184 |
> |
for (consElem = mol->beginConstraintElem(cei); consElem != NULL; |
185 |
> |
consElem = mol->nextConstraintElem(cei)) { |
186 |
|
consElem->setMoved(consElem->getMoving()); |
187 |
|
consElem->setMoving(false); |
188 |
|
} |
193 |
|
|
194 |
|
if (!done){ |
195 |
|
sprintf(painCave.errMsg, |
196 |
< |
"Constraint failure in Rattle::constrainA, too many iterations: %d\n", |
196 |
> |
"Constraint failure in Rattle::constrainA, " |
197 |
> |
"too many iterations: %d\n", |
198 |
|
iteration); |
199 |
|
painCave.isFatal = 1; |
200 |
|
simError(); |
263 |
|
Vector3d velB = consElem2->getVel(); |
264 |
|
velB -= rmb * delta; |
265 |
|
consElem2->setVel(velB); |
266 |
< |
|
266 |
> |
|
267 |
> |
// report the constraint force back to the constraint pair: |
268 |
> |
consPair->setConstraintForce(gab); |
269 |
|
return consSuccess; |
270 |
|
} |
271 |
|
else |
307 |
|
velB -= rmb * delta; |
308 |
|
consElem2->setVel(velB); |
309 |
|
|
310 |
+ |
// report the constraint force back to the constraint pair: |
311 |
+ |
consPair->setConstraintForce(gab); |
312 |
|
return consSuccess; |
313 |
|
} |
314 |
|
else |