| 35 |
|
* |
| 36 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
| 37 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
| 38 |
< |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
| 39 |
< |
* [4] Vardeman & Gezelter, in progress (2009). |
| 38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 42 |
|
|
| 43 |
|
#include "constraints/Rattle.hpp" |
| 45 |
|
#include "utils/simError.h" |
| 46 |
|
namespace OpenMD { |
| 47 |
|
|
| 48 |
< |
Rattle::Rattle(SimInfo* info) : info_(info), maxConsIteration_(10), consTolerance_(1.0e-6) { |
| 48 |
> |
Rattle::Rattle(SimInfo* info) : info_(info), maxConsIteration_(10), |
| 49 |
> |
consTolerance_(1.0e-6), doRattle_(false), |
| 50 |
> |
currConstraintTime_(0.0) { |
| 51 |
|
|
| 52 |
< |
if (info_->getSimParams()->haveDt()) { |
| 53 |
< |
dt_ = info_->getSimParams()->getDt(); |
| 52 |
> |
if (info_->getNGlobalConstraints() > 0) |
| 53 |
> |
doRattle_ = true; |
| 54 |
> |
|
| 55 |
> |
Globals* simParams = info_->getSimParams(); |
| 56 |
> |
|
| 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() { |
| 88 |
< |
if (info_->getNConstraints() > 0) { |
| 89 |
< |
doConstraint(&Rattle::constraintPairA); |
| 64 |
< |
} |
| 88 |
> |
if (!doRattle_) return; |
| 89 |
> |
doConstraint(&Rattle::constraintPairA); |
| 90 |
|
} |
| 91 |
|
void Rattle::constraintB() { |
| 92 |
< |
if (info_->getNConstraints() > 0) { |
| 93 |
< |
doConstraint(&Rattle::constraintPairB); |
| 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) { |
| 115 |
+ |
if (!doRattle_) return; |
| 116 |
+ |
|
| 117 |
|
Molecule* mol; |
| 118 |
|
SimInfo::MoleculeIterator mi; |
| 119 |
|
ConstraintElem* consElem; |
| 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(); |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
int Rattle::constraintPairA(ConstraintPair* consPair){ |
| 205 |
+ |
|
| 206 |
|
ConstraintElem* consElem1 = consPair->getConsElem1(); |
| 207 |
|
ConstraintElem* consElem2 = consPair->getConsElem2(); |
| 208 |
|
|
| 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 |