OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
FluctuatingChargeDamped.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include "FluctuatingChargeDamped.hpp"
46
48#include "utils/Constants.hpp"
49#include "utils/simError.h"
50
51namespace OpenMD {
52
53 FluctuatingChargeDamped::FluctuatingChargeDamped(SimInfo* info) :
54 FluctuatingChargePropagator(info), maxIterNum_(4), forceTolerance_(1e-6),
55 snap(info->getSnapshotManager()->getCurrentSnapshot()) {}
56
57 void FluctuatingChargeDamped::initialize() {
58 FluctuatingChargePropagator::initialize();
59 if (hasFlucQ_) {
60 if (info_->getSimParams()->haveDt()) {
61 dt_ = info_->getSimParams()->getDt();
62 dt2_ = dt_ * 0.5;
63 } else {
64 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
65 "FluctuatingChargeDamped Error: dt is not set\n");
66 painCave.isFatal = 1;
67 simError();
68 }
69
70 if (!fqParams_->haveDragCoefficient()) {
71 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
72 "If you use the FluctuatingChargeDamped\n"
73 "\tpropagator, you must set flucQ dragCoefficient .\n");
74
75 painCave.severity = OPENMD_ERROR;
76 painCave.isFatal = 1;
77 simError();
78 } else {
79 drag_ = fqParams_->getDragCoefficient();
80 }
81 }
82 }
83
84 void FluctuatingChargeDamped::moveA() {
85 if (!hasFlucQ_) return;
86
87 SimInfo::MoleculeIterator i;
88 Molecule::FluctuatingChargeIterator j;
89 Molecule* mol;
90 Atom* atom;
91 RealType cvel, cpos, cfrc, cmass;
92
93 for (mol = info_->beginMolecule(i); mol != NULL;
94 mol = info_->nextMolecule(i)) {
95 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
96 atom = mol->nextFluctuatingCharge(j)) {
97 cvel = atom->getFlucQVel();
98 cpos = atom->getFlucQPos();
99 cfrc = atom->getFlucQFrc();
100 cmass = atom->getChargeMass();
101
102 // velocity half step
103 cvel += dt2_ * cfrc / cmass;
104 // position whole step
105 cpos += dt_ * cvel;
106
107 atom->setFlucQVel(cvel);
108 atom->setFlucQPos(cpos);
109 }
110 }
111 }
112
113 void FluctuatingChargeDamped::applyConstraints() {
114 if (!hasFlucQ_) return;
115
116 SimInfo::MoleculeIterator i;
117 Molecule::FluctuatingChargeIterator j;
118 Molecule* mol;
119 Atom* atom;
120 RealType cvel, cfrc, cmass, frictionForce;
121 RealType velStep, oldFF; // used to test for convergence
122
123 for (mol = info_->beginMolecule(i); mol != NULL;
124 mol = info_->nextMolecule(i)) {
125 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
126 atom = mol->nextFluctuatingCharge(j)) {
127 // What remains contains velocity explicitly, but the velocity
128 // required is at the full step: v(t + h), while we have
129 // initially the velocity at the half step: v(t + h/2). We
130 // need to iterate to converge the friction force vector.
131
132 // this is the velocity at the half-step:
133
134 cvel = atom->getFlucQVel();
135
136 // estimate velocity at full-step using everything but
137 // friction forces:
138
139 cfrc = atom->getFlucQFrc();
140 cmass = atom->getChargeMass();
141 velStep = cvel + dt2_ * cfrc / cmass;
142
143 frictionForce = 0.0;
144
145 // iteration starts here:
146
147 for (int k = 0; k < maxIterNum_; k++) {
148 oldFF = frictionForce;
149 frictionForce = -drag_ * velStep;
150 // re-estimate velocities at full-step using friction forces:
151
152 velStep = cvel + dt2_ * (cfrc + frictionForce) / cmass;
153
154 // check for convergence
155
156 if (fabs(frictionForce - oldFF) <= forceTolerance_)
157 break; // iteration ends here
158 }
159 atom->addFlucQFrc(frictionForce);
160 }
161 }
162 fqConstraints_->applyConstraints();
163 }
164
165 void FluctuatingChargeDamped::moveB() {
166 if (!hasFlucQ_) return;
167 SimInfo::MoleculeIterator i;
168 Molecule::FluctuatingChargeIterator j;
169 Molecule* mol;
170 Atom* atom;
171 RealType cfrc, cvel, cmass;
172
173 for (mol = info_->beginMolecule(i); mol != NULL;
174 mol = info_->nextMolecule(i)) {
175 for (atom = mol->beginFluctuatingCharge(j); atom != NULL;
176 atom = mol->nextFluctuatingCharge(j)) {
177 cvel = atom->getFlucQVel();
178 cfrc = atom->getFlucQFrc();
179 cmass = atom->getChargeMass();
180
181 // velocity half step
182 cvel += (dt2_ * cfrc) / cmass;
183
184 atom->setFlucQVel(cvel);
185 }
186 }
187 }
188
189 void FluctuatingChargeDamped::updateSizes() {}
190
191 RealType FluctuatingChargeDamped::calcConservedQuantity() { return 0.0; }
192} // namespace OpenMD
abstract class for propagating fluctuating charge variables
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:93
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
Definition SimInfo.cpp:240
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
Definition SimInfo.cpp:245
void setFlucQVel(RealType cvel)
Sets the current charge velocity of this stuntDouble.
void addFlucQFrc(RealType cfrc)
Adds charge force into the current charge force of this stuntDouble.
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.
RealType getFlucQVel()
Returns the current charge velocity of this stuntDouble.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.