OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
NgammaT.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
46
47#include "brains/SimInfo.hpp"
48#include "brains/Thermo.hpp"
49#include "integrators/IntegratorCreator.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
53
54namespace OpenMD {
55 NgammaT::NgammaT(SimInfo* info) : NPT(info) {
56 Globals* simParams = info_->getSimParams();
57 if (!simParams->haveSurfaceTension()) {
58 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
59 "If you use the NgammaT integrator, you must "
60 "set a surface tension.\n");
61 painCave.severity = OPENMD_ERROR;
62 painCave.isFatal = 1;
63 simError();
64 } else {
65 surfaceTension_ = simParams->getSurfaceTension() *
66 Constants::surfaceTensionConvert *
67 Constants::energyConvert;
68
69 // Default value of privilegedAxis is "z"
70 if (simParams->getPrivilegedAxis() == "x")
71 axis_ = 0;
72 else if (simParams->getPrivilegedAxis() == "y")
73 axis_ = 1;
74 else if (simParams->getPrivilegedAxis() == "z")
75 axis_ = 2;
76
77 // Compute complementary axes to the privileged axis
78 axis1_ = (axis_ + 1) % 3;
79 axis2_ = (axis_ + 2) % 3;
80 }
81 }
82 void NgammaT::evolveEtaA() {
83 Mat3x3d hmat = snap->getHmat();
84 RealType hz = hmat(axis_, axis_);
85 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
86 RealType sx = -hz * (press(axis1_, axis1_) -
87 targetPressure / Constants::pressureConvert);
88 RealType sy = -hz * (press(axis2_, axis2_) -
89 targetPressure / Constants::pressureConvert);
90 eta(axis1_, axis1_) -= dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
91 eta(axis2_, axis2_) -= dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
92 eta(axis_, axis_) = 0.0;
93 oldEta_ = eta;
94 }
95
96 void NgammaT::evolveEtaB() {
97 Mat3x3d hmat = snap->getHmat();
98 RealType hz = hmat(axis_, axis_);
99 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
100 prevEta_ = eta;
101 RealType sx = -hz * (press(axis1_, axis1_) -
102 targetPressure / Constants::pressureConvert);
103 RealType sy = -hz * (press(axis2_, axis2_) -
104 targetPressure / Constants::pressureConvert);
105 eta(axis_, axis_) = oldEta_(axis_, axis_) -
106 dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
107 eta(axis2_, axis2_) = oldEta_(axis2_, axis2_) -
108 dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
109 eta(axis_, axis_) = 0.0;
110 }
111
112 void NgammaT::calcVelScale() {
113 for (int i = 0; i < 3; i++) {
114 for (int j = 0; j < 3; j++) {
115 vScale_(i, j) = eta(i, j);
116
117 if (i == j) { vScale_(i, j) += thermostat.first; }
118 }
119 }
120 }
121
122 void NgammaT::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
123 sc = vScale_ * vel;
124 }
125
126 void NgammaT::getVelScaleB(Vector3d& sc, int index) {
127 sc = vScale_ * oldVel[index];
128 }
129
130 void NgammaT::getPosScale(const Vector3d& pos, const Vector3d& COM, int index,
131 Vector3d& sc) {
132 /**@todo */
133 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
134 sc = eta * rj;
135 }
136
137 void NgammaT::scaleSimBox() {
138 Mat3x3d scaleMat;
139
140 scaleMat(axis1_, axis1_) = exp(dt * eta(axis1_, axis1_));
141 scaleMat(axis2_, axis2_) = exp(dt * eta(axis2_, axis2_));
142 scaleMat(axis_, axis_) = exp(dt * eta(axis_, axis_));
143 Mat3x3d hmat = snap->getHmat();
144 hmat = hmat * scaleMat;
145 snap->setHmat(hmat);
146 }
147
148 bool NgammaT::etaConverged() {
149 int i;
150 RealType diffEta, sumEta;
151
152 sumEta = 0;
153 for (i = 0; i < 3; i++) {
154 sumEta += pow(prevEta_(i, i) - eta(i, i), 2);
155 }
156
157 diffEta = sqrt(sumEta / 3.0);
158
159 return (diffEta <= etaTolerance);
160 }
161
162 RealType NgammaT::calcConservedQuantity() {
163 thermostat = snap->getThermostat();
164 loadEta();
165
166 // We need NkBT a lot, so just set it here: This is the RAW number
167 // of integrableObjects, so no subtraction or addition of constraints or
168 // orientational degrees of freedom:
169 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
170
171 // fkBT is used because the thermostat operates on more degrees of freedom
172 // than the barostat (when there are particles with orientational degrees
173 // of freedom).
174 fkBT = info_->getNdf() * Constants::kB * targetTemp;
175
176 RealType totalEnergy = thermo.getTotalEnergy();
177
178 RealType thermostat_kinetic = fkBT * tt2 * thermostat.first *
179 thermostat.first /
180 (2.0 * Constants::energyConvert);
181
182 RealType thermostat_potential =
183 fkBT * thermostat.second / Constants::energyConvert;
184
185 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
186 RealType trEta = tmp.trace();
187
188 RealType barostat_kinetic =
189 NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
190
191 RealType barostat_potential =
192 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
193 Constants::energyConvert;
194
195 Mat3x3d hmat = snap->getHmat();
196 RealType area = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
197
198 RealType conservedQuantity =
199 totalEnergy + thermostat_kinetic + thermostat_potential +
200 barostat_kinetic + barostat_potential -
201 surfaceTension_ * area / Constants::energyConvert;
202
203 return conservedQuantity;
204 }
205
206 void NgammaT::loadEta() {
207 eta = snap->getBarostat();
208
209 // if (!eta.isDiagonal()) {
210 // snprintf( painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
211 // "NgammaT error: the diagonal elements of eta matrix are not
212 // the same or etaMat is not a diagonal matrix");
213 // painCave.isFatal = 1;
214 // simError();
215 //}
216 }
217
218 void NgammaT::saveEta() { snap->setBarostat(eta); }
219
220} // namespace OpenMD
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:93
int getNdf()
Returns the number of degrees of freedom.
Definition SimInfo.hpp:220
int getNGlobalIntegrableObjects()
Returns the total number of integrable objects (total number of rigid bodies plus the total number of...
Definition SimInfo.hpp:139
Mat3x3d getHmat()
Returns the H-Matrix.
Definition Snapshot.cpp:214
void setHmat(const Mat3x3d &m)
Sets the H-Matrix.
Definition Snapshot.cpp:217
A square matrix class.
Real trace() const
Returns the trace of this matrix.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.