48#include "flucq/FluctuatingChargeObjectiveFunction.hpp"
56 FluctuatingChargeObjectiveFunction::FluctuatingChargeObjectiveFunction(
60 forceMan_(forceMan), fqConstraints_(fqConstraints), thermo(info) {}
65 forceMan_->calcForces();
66 fqConstraints_->applyConstraints();
67 return thermo.getPotential();
73 forceMan_->calcForces();
74 fqConstraints_->applyConstraints();
81 forceMan_->calcForces();
82 fqConstraints_->applyConstraints();
84 return thermo.getPotential();
87 void FluctuatingChargeObjectiveFunction::setCoor(
89 SimInfo::MoleculeIterator i;
90 Molecule::FluctuatingChargeIterator j;
98 index = displacements_[myrank_];
105 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
106 atom = mol->nextFluctuatingCharge(j)) {
112 void FluctuatingChargeObjectiveFunction::getGrad(
114 SimInfo::MoleculeIterator i;
115 Molecule::FluctuatingChargeIterator j;
122 index = displacements_[myrank_];
127 for (mol = info_->beginMolecule(i); mol != NULL;
128 mol = info_->nextMolecule(i)) {
129 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
130 atom = mol->nextFluctuatingCharge(j)) {
136 MPI_Allreduce(MPI_IN_PLACE, &grad[0], nFlucQ_, MPI_REALTYPE, MPI_SUM,
142 FluctuatingChargeObjectiveFunction::setInitialCoords() {
144 MPI_Comm_size(MPI_COMM_WORLD, &nproc_);
145 MPI_Comm_rank(MPI_COMM_WORLD, &myrank_);
146 std::vector<int> flucqOnProc_(nproc_, 0);
148 displacements_.clear();
149 displacements_.resize(nproc_, 0);
152 SimInfo::MoleculeIterator i;
153 Molecule::FluctuatingChargeIterator j;
159 for (mol = info_->beginMolecule(i); mol != NULL;
160 mol = info_->nextMolecule(i)) {
161 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
162 atom = mol->nextFluctuatingCharge(j)) {
168 MPI_Allgather(&nFlucQ_, 1, MPI_INT, &flucqOnProc_[0], 1, MPI_INT,
172 for (
int iproc = 0; iproc < nproc_; iproc++) {
173 nFlucQ_ += flucqOnProc_[iproc];
176 displacements_[0] = 0;
177 for (
int iproc = 1; iproc < nproc_; iproc++) {
178 displacements_[iproc] =
179 displacements_[iproc - 1] + flucqOnProc_[iproc - 1];
183 DynamicVector<RealType> initCoords(nFlucQ_);
187 index = displacements_[myrank_];
192 for (mol = info_->beginMolecule(i); mol != NULL;
193 mol = info_->nextMolecule(i)) {
194 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
195 atom = mol->nextFluctuatingCharge(j)) {
201 MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, &initCoords[0],
202 &flucqOnProc_[0], &displacements_[0], MPI_REALTYPE,
Dynamically-sized vector class.
void setZero()
zero out the vector
virtual RealType value(const DynamicVector< RealType > &x)
method to overload to compute the objective function value in x
virtual void gradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative of
virtual RealType valueAndGradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative
ForceManager is responsible for calculating both the short range (bonded) interactions and long range...
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
void setFlucQPos(RealType charge)
Sets the current fluctuating charge of this stuntDouble.
RealType getFlucQFrc()
Returns the current charge force of this stuntDouble.
RealType getFlucQPos()
Returns the current fluctuating charge of this stuntDouble.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.