48#include "optimization/BoxObjectiveFunction.hpp"
50#include "math/CholeskyDecomposition.hpp"
54 BoxObjectiveFunction::BoxObjectiveFunction(
SimInfo* info,
57 forceMan_(forceMan), thermo(info) {
58 shake_ =
new Shake(info_);
60 if (info_->usesFluctuatingCharges()) {
61 if (info_->getNFluctuatingCharges() > 0) {
64 bool cr = info_->getSimParams()
65 ->getFluctuatingChargeParameters()
66 ->getConstrainRegions();
67 fqConstraints_->setConstrainRegions(cr);
72 BoxObjectiveFunction::~BoxObjectiveFunction() {
77 info_->getSnapshotManager()->advance();
79 if (setCoor(x) == 0) {
80 shake_->constraintR();
81 forceMan_->calcForces();
82 if (hasFlucQ_) fqConstraints_->applyConstraints();
83 shake_->constraintF();
84 return thermo.getPotential();
87 return std::numeric_limits<RealType>::infinity();
93 info_->getSnapshotManager()->advance();
94 if (setCoor(x) == 0) {
95 shake_->constraintR();
96 forceMan_->calcForces();
97 if (hasFlucQ_) fqConstraints_->applyConstraints();
98 shake_->constraintF();
102 for (
int j = 0; j < 6; j++)
103 grad[j] = std::numeric_limits<RealType>::infinity();
109 info_->getSnapshotManager()->advance();
110 if (setCoor(x) == 0) {
111 shake_->constraintR();
112 forceMan_->calcForces();
113 if (hasFlucQ_) fqConstraints_->applyConstraints();
114 shake_->constraintF();
116 return thermo.getPotential();
120 for (
int j = 0; j < 6; j++)
121 grad[j] = std::numeric_limits<RealType>::infinity();
122 return std::numeric_limits<RealType>::infinity();
130 SimInfo::MoleculeIterator miter;
139 eta.setupVoigtTensor(x[0], x[1], x[2], x[3] / 2., x[4] / 2., x[5] / 2.);
142 if (eta.frobeniusNorm() > 0.7) {
151 while (norm > 1.0e-10) {
152 y = eta - eps * eps / 2.0;
154 norm = test.frobeniusNorm();
161 for (mol = info_->beginMolecule(miter); mol != NULL;
162 mol = info_->nextMolecule(miter)) {
163 posO = refPos_[index++];
165 delta = deformation_ * posO - posN;
169 Mat3x3d Hmat = deformation_ * refHmat_;
170 info_->getSnapshotManager()->getCurrentSnapshot()->setHmat(Hmat);
175 Mat3x3d pressureTensor;
176 Vector<RealType, 6> lstress(0.0);
184 Mat3x3d idm = deformation_.
inverse();
187 pressureTensor = thermo.getPressureTensor();
189 pressureTensor *= Constants::elasticConvert;
191 Mat3x3d tao = idm * (pressureTensor * idm);
194 lstress = tao.toVoigtTensor();
195 RealType V = thermo.getVolume();
197 for (
int j = 0; j < 6; j++) {
198 grad[j] = V * lstress[j];
203 DynamicVector<RealType> xinit(6, 0.0);
204 SimInfo::MoleculeIterator miter;
207 Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
209 V0_ = snap->getVolume();
212 for (mol = info_->beginMolecule(miter); mol != NULL;
213 mol = info_->nextMolecule(miter)) {
214 refPos_.push_back(mol->
getCom());
RealType valueAndGradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative
RealType value(const DynamicVector< RealType > &x)
method to overload to compute the objective function value in x
void gradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative of
Dynamically-sized vector class.
ForceManager is responsible for calculating both the short range (bonded) interactions and long range...
void moveCom(const Vector3d &delta)
Moves the center of this molecule.
Vector3d getCom()
Returns the current center of mass position of this molecule.
void negate()
Negates the value of this matrix in place.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Mat3x3d getHmat()
Returns the H-Matrix.
SquareMatrix3< Real > inverse() const
Sets the value of this matrix to the inverse of itself.
Real determinant() const
Returns the determinant of this matrix.
static SquareMatrix< Real, Dim > identity()
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.