56 |
|
namespace OpenMD { |
57 |
|
|
58 |
|
FluctuatingChargePropagator::FluctuatingChargePropagator(SimInfo* info) : |
59 |
< |
info_(info), hasFlucQ_(false), forceMan_(NULL) { |
59 |
> |
info_(info), hasFlucQ_(false), forceMan_(NULL), initialized_(false) { |
60 |
|
|
61 |
|
Globals* simParams = info_->getSimParams(); |
62 |
|
fqParams_ = simParams->getFluctuatingChargeParameters(); |
63 |
– |
fqConstraints_ = new FluctuatingChargeConstraints(info_); |
64 |
– |
fqConstraints_->setConstrainRegions( fqParams_->getConstrainRegions() ); |
63 |
|
} |
64 |
|
|
65 |
|
FluctuatingChargePropagator::~FluctuatingChargePropagator() { |
68 |
– |
if (fqConstraints_ != NULL) delete fqConstraints_; |
66 |
|
} |
67 |
|
|
68 |
|
void FluctuatingChargePropagator::setForceManager(ForceManager* forceMan) { |
70 |
|
} |
71 |
|
|
72 |
|
void FluctuatingChargePropagator::initialize() { |
76 |
– |
|
73 |
|
if (info_->usesFluctuatingCharges()) { |
74 |
|
if (info_->getNFluctuatingCharges() > 0) { |
75 |
|
hasFlucQ_ = true; |
76 |
+ |
fqConstraints_ = new FluctuatingChargeConstraints(info_); |
77 |
+ |
fqConstraints_->setConstrainRegions(fqParams_->getConstrainRegions()); |
78 |
|
} |
79 |
|
} |
80 |
+ |
|
81 |
+ |
if (!hasFlucQ_) { |
82 |
+ |
initialized_ = true; |
83 |
+ |
return; |
84 |
+ |
} |
85 |
|
|
83 |
– |
if (!hasFlucQ_) return; |
84 |
– |
|
86 |
|
SimInfo::MoleculeIterator i; |
87 |
|
Molecule::FluctuatingChargeIterator j; |
88 |
|
Molecule* mol; |
89 |
|
Atom* atom; |
90 |
|
|
91 |
< |
for (mol = info_->beginMolecule(i); mol != NULL; |
92 |
< |
mol = info_->nextMolecule(i)) { |
93 |
< |
for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
94 |
< |
atom = mol->nextFluctuatingCharge(j)) { |
95 |
< |
atom->setFlucQPos(0.0); |
96 |
< |
atom->setFlucQVel(0.0); |
97 |
< |
} |
98 |
< |
} |
91 |
> |
// For single-minima flucq, this ensures a net neutral system, but |
92 |
> |
// for multiple minima, this is no longer the right thing to do: |
93 |
> |
// |
94 |
> |
// for (mol = info_->beginMolecule(i); mol != NULL; |
95 |
> |
// mol = info_->nextMolecule(i)) { |
96 |
> |
// for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
97 |
> |
// atom = mol->nextFluctuatingCharge(j)) { |
98 |
> |
// atom->setFlucQPos(0.0); |
99 |
> |
// atom->setFlucQVel(0.0); |
100 |
> |
// } |
101 |
> |
// } |
102 |
|
|
103 |
|
FluctuatingChargeObjectiveFunction flucQobjf(info_, forceMan_, |
104 |
|
fqConstraints_); |
113 |
|
|
114 |
|
DumpStatusFunction dsf(info_); // we want a dump file written |
115 |
|
// every iteration |
112 |
– |
|
116 |
|
minim->minimize(problem, endCriteria); |
117 |
+ |
cerr << "back from minim\n"; |
118 |
+ |
initialized_ = true; |
119 |
|
} |
120 |
|
|
121 |
|
void FluctuatingChargePropagator::applyConstraints() { |
122 |
+ |
if (!initialized_) initialize(); |
123 |
|
if (!hasFlucQ_) return; |
124 |
|
fqConstraints_->applyConstraints(); |
125 |
|
} |