45 |
|
namespace OpenMD{ |
46 |
|
|
47 |
|
PotentialEnergyObjectiveFunction::PotentialEnergyObjectiveFunction(SimInfo* info, ForceManager* forceMan) |
48 |
< |
: info_(info), forceMan_(forceMan), thermo(info) { |
48 |
> |
: info_(info), forceMan_(forceMan), thermo(info) { |
49 |
> |
shake_ = new Shake(info_); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
RealType PotentialEnergyObjectiveFunction::value(const DynamicVector<RealType>& x) { |
55 |
|
setCoor(x); |
56 |
+ |
shake_->constraintR(); |
57 |
|
forceMan_->calcForces(); |
58 |
+ |
shake_->constraintF(); |
59 |
|
return thermo.getPotential(); |
60 |
|
} |
61 |
|
|
62 |
|
void PotentialEnergyObjectiveFunction::gradient(DynamicVector<RealType>& grad, const DynamicVector<RealType>& x) { |
63 |
|
|
64 |
< |
setCoor(x); |
65 |
< |
forceMan_->calcForces(); |
66 |
< |
getGrad(grad); |
64 |
> |
setCoor(x); |
65 |
> |
shake_->constraintR(); |
66 |
> |
forceMan_->calcForces(); |
67 |
> |
shake_->constraintF(); |
68 |
> |
getGrad(grad); |
69 |
|
} |
70 |
|
|
71 |
|
RealType PotentialEnergyObjectiveFunction::valueAndGradient(DynamicVector<RealType>& grad, |
72 |
|
const DynamicVector<RealType>& x) { |
73 |
< |
|
74 |
< |
setCoor(x); |
75 |
< |
forceMan_->calcForces(); |
73 |
> |
setCoor(x); |
74 |
> |
shake_->constraintR(); |
75 |
> |
forceMan_->calcForces(); |
76 |
> |
shake_->constraintF(); |
77 |
|
getGrad(grad); |
78 |
|
return thermo.getPotential(); |
79 |
|
} |
105 |
|
eulerAngle[2] = x[index++]; |
106 |
|
|
107 |
|
integrableObject->setEuler(eulerAngle); |
108 |
< |
} |
108 |
> |
|
109 |
> |
if (integrableObject->isRigidBody()) { |
110 |
> |
RigidBody* rb = static_cast<RigidBody*>(integrableObject); |
111 |
> |
rb->updateAtoms(); |
112 |
> |
} |
113 |
> |
} |
114 |
|
} |
115 |
|
} |
116 |
|
} |
130 |
|
integrableObject != NULL; |
131 |
|
integrableObject = mol->nextIntegrableObject(j)) { |
132 |
|
myGrad = integrableObject->getGrad(); |
133 |
< |
for (size_t k = 0; k < myGrad.size(); ++k) { |
133 |
> |
|
134 |
> |
for (size_t k = 0; k < myGrad.size(); ++k) { |
135 |
|
grad[index++] = myGrad[k]; |
136 |
|
} |
137 |
|
} |