48 |
|
#include "optimization/StatusFunction.hpp" |
49 |
|
#include "optimization/OptimizationFactory.hpp" |
50 |
|
|
51 |
– |
|
52 |
– |
|
51 |
|
#ifdef IS_MPI |
52 |
|
#include <mpi.h> |
53 |
|
#endif |
55 |
|
using namespace QuantLib; |
56 |
|
namespace OpenMD { |
57 |
|
|
58 |
< |
FluctuatingChargePropagator::FluctuatingChargePropagator(SimInfo* info, |
59 |
< |
ForceManager* fm) : |
62 |
< |
info_(info), forceMan_(fm), hasFlucQ_(false) { |
58 |
> |
FluctuatingChargePropagator::FluctuatingChargePropagator(SimInfo* info) : |
59 |
> |
info_(info), hasFlucQ_(false), forceMan_(NULL) { |
60 |
|
|
61 |
+ |
Globals* simParams = info_->getSimParams(); |
62 |
+ |
fqParams_ = simParams->getFluctuatingChargeParameters(); |
63 |
+ |
} |
64 |
+ |
|
65 |
+ |
void FluctuatingChargePropagator::setForceManager(ForceManager* forceMan) { |
66 |
+ |
forceMan_ = forceMan; |
67 |
+ |
} |
68 |
+ |
|
69 |
+ |
void FluctuatingChargePropagator::initialize() { |
70 |
+ |
|
71 |
|
if (info_->usesFluctuatingCharges()) { |
72 |
|
if (info_->getNFluctuatingCharges() > 0) { |
66 |
– |
|
73 |
|
hasFlucQ_ = true; |
74 |
< |
Globals* simParams = info_->getSimParams(); |
69 |
< |
fqParams_ = simParams->getFluctuatingChargeParameters(); |
70 |
< |
fqConstraints_ = new FluctuatingChargeConstraints(info_); |
71 |
< |
|
74 |
> |
fqConstraints_ = new FluctuatingChargeConstraints(info_); |
75 |
|
} |
76 |
|
} |
74 |
– |
} |
77 |
|
|
76 |
– |
void FluctuatingChargePropagator::initialize() { |
77 |
– |
|
78 |
|
if (!hasFlucQ_) return; |
79 |
|
|
80 |
|
SimInfo::MoleculeIterator i; |
90 |
|
atom->setFlucQVel(0.0); |
91 |
|
} |
92 |
|
} |
93 |
– |
|
94 |
– |
std::cerr << "doing a minimization\n"; |
93 |
|
|
94 |
|
fqConstraints_ = new FluctuatingChargeConstraints(info_); |
95 |
|
FluctuatingChargeObjectiveFunction flucQobjf(info_, forceMan_, fqConstraints_); |
98 |
|
EndCriteria endCriteria(1000, 100, 1e-5, 1e-5, 1e-5); |
99 |
|
OptimizationMethod* minim = OptimizationFactory::getInstance()->createOptimization("SD", info_); |
100 |
|
|
101 |
< |
DumpStatusFunction dsf(info_); // we want a dump file written every iteration |
101 |
> |
DumpStatusFunction dsf(info_); // we want a dump file written every iteration |
102 |
|
|
103 |
|
minim->minimize(problem, endCriteria); |
106 |
– |
cerr << "Finished minimization\n"; |
107 |
– |
for (mol = info_->beginMolecule(i); mol != NULL; |
108 |
– |
mol = info_->nextMolecule(i)) { |
109 |
– |
for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
110 |
– |
atom = mol->nextFluctuatingCharge(j)) { |
111 |
– |
cerr << atom->getType() << "\tQ Pos: " << atom->getFlucQPos() << "\n"; |
112 |
– |
} |
113 |
– |
} |
114 |
– |
// std::cerr << "after minim\n"; |
115 |
– |
// for (mol = info_->beginMolecule(i); mol != NULL; |
116 |
– |
// mol = info_->nextMolecule(i)) { |
117 |
– |
// for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
118 |
– |
// atom = mol->nextFluctuatingCharge(j)) { |
119 |
– |
// cerr << "q = " << atom->getFlucQPos(0.0) << "\n"; |
120 |
– |
// } |
121 |
– |
// } |
122 |
– |
|
123 |
– |
|
104 |
|
} |
105 |
|
|
126 |
– |
|
106 |
|
void FluctuatingChargePropagator::applyConstraints() { |
107 |
|
if (!hasFlucQ_) return; |
129 |
– |
|
108 |
|
fqConstraints_->applyConstraints(); |
109 |
|
} |
110 |
|
} |