OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
49
50#include "brains/SimInfo.hpp"
51#include "brains/Thermo.hpp"
52#include "integrators/IntegratorCreator.hpp"
54#include "utils/Constants.hpp"
55#include "utils/simError.h"
56
57namespace OpenMD {
58 NgammaT::NgammaT(SimInfo* info) : NPT(info) {
59 Globals* simParams = info_->getSimParams();
60 if (!simParams->haveSurfaceTension()) {
61 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
62 "If you use the NgammaT integrator, you must "
63 "set a surface tension.\n");
64 painCave.severity = OPENMD_ERROR;
65 painCave.isFatal = 1;
66 simError();
67 } else {
68 surfaceTension_ = simParams->getSurfaceTension() *
69 Constants::surfaceTensionConvert *
70 Constants::energyConvert;
71
72 // Default value of privilegedAxis is "z"
73 if (simParams->getPrivilegedAxis() == "x")
74 axis_ = 0;
75 else if (simParams->getPrivilegedAxis() == "y")
76 axis_ = 1;
77 else if (simParams->getPrivilegedAxis() == "z")
78 axis_ = 2;
79
80 // Compute complementary axes to the privileged axis
81 axis1_ = (axis_ + 1) % 3;
82 axis2_ = (axis_ + 2) % 3;
83 }
84 }
85 void NgammaT::evolveEtaA() {
86 Mat3x3d hmat = snap->getHmat();
87 RealType hz = hmat(axis_, axis_);
88 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
89 RealType sx = -hz * (press(axis1_, axis1_) -
90 targetPressure / Constants::pressureConvert);
91 RealType sy = -hz * (press(axis2_, axis2_) -
92 targetPressure / Constants::pressureConvert);
93 eta(axis1_, axis1_) -= dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
94 eta(axis2_, axis2_) -= dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
95 eta(axis_, axis_) = 0.0;
96 oldEta_ = eta;
97 }
98
99 void NgammaT::evolveEtaB() {
100 Mat3x3d hmat = snap->getHmat();
101 RealType hz = hmat(axis_, axis_);
102 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
103 prevEta_ = eta;
104 RealType sx = -hz * (press(axis1_, axis1_) -
105 targetPressure / Constants::pressureConvert);
106 RealType sy = -hz * (press(axis2_, axis2_) -
107 targetPressure / Constants::pressureConvert);
108 eta(axis_, axis_) = oldEta_(axis_, axis_) -
109 dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
110 eta(axis2_, axis2_) = oldEta_(axis2_, axis2_) -
111 dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
112 eta(axis_, axis_) = 0.0;
113 }
114
115 void NgammaT::calcVelScale() {
116 for (int i = 0; i < 3; i++) {
117 for (int j = 0; j < 3; j++) {
118 vScale_(i, j) = eta(i, j);
119
120 if (i == j) { vScale_(i, j) += thermostat.first; }
121 }
122 }
123 }
124
125 void NgammaT::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
126 sc = vScale_ * vel;
127 }
128
129 void NgammaT::getVelScaleB(Vector3d& sc, int index) {
130 sc = vScale_ * oldVel[index];
131 }
132
133 void NgammaT::getPosScale(const Vector3d& pos, const Vector3d& COM, int index,
134 Vector3d& sc) {
135 /**@todo */
136 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
137 sc = eta * rj;
138 }
139
140 void NgammaT::scaleSimBox() {
141 Mat3x3d scaleMat;
142
143 scaleMat(axis1_, axis1_) = exp(dt * eta(axis1_, axis1_));
144 scaleMat(axis2_, axis2_) = exp(dt * eta(axis2_, axis2_));
145 scaleMat(axis_, axis_) = exp(dt * eta(axis_, axis_));
146 Mat3x3d hmat = snap->getHmat();
147 hmat = hmat * scaleMat;
148 snap->setHmat(hmat);
149 }
150
151 bool NgammaT::etaConverged() {
152 int i;
153 RealType diffEta, sumEta;
154
155 sumEta = 0;
156 for (i = 0; i < 3; i++) {
157 sumEta += pow(prevEta_(i, i) - eta(i, i), 2);
158 }
159
160 diffEta = sqrt(sumEta / 3.0);
161
162 return (diffEta <= etaTolerance);
163 }
164
165 RealType NgammaT::calcConservedQuantity() {
166 thermostat = snap->getThermostat();
167 loadEta();
168
169 // We need NkBT a lot, so just set it here: This is the RAW number
170 // of integrableObjects, so no subtraction or addition of constraints or
171 // orientational degrees of freedom:
172 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
173
174 // fkBT is used because the thermostat operates on more degrees of freedom
175 // than the barostat (when there are particles with orientational degrees
176 // of freedom).
177 fkBT = info_->getNdf() * Constants::kB * targetTemp;
178
179 RealType totalEnergy = thermo.getTotalEnergy();
180
181 RealType thermostat_kinetic = fkBT * tt2 * thermostat.first *
182 thermostat.first /
183 (2.0 * Constants::energyConvert);
184
185 RealType thermostat_potential =
186 fkBT * thermostat.second / Constants::energyConvert;
187
188 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
189 RealType trEta = tmp.trace();
190
191 RealType barostat_kinetic =
192 NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
193
194 RealType barostat_potential =
195 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
196 Constants::energyConvert;
197
198 Mat3x3d hmat = snap->getHmat();
199 RealType area = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
200
201 RealType conservedQuantity =
202 totalEnergy + thermostat_kinetic + thermostat_potential +
203 barostat_kinetic + barostat_potential -
204 surfaceTension_ * area / Constants::energyConvert;
205
206 return conservedQuantity;
207 }
208
209 void NgammaT::loadEta() {
210 eta = snap->getBarostat();
211
212 // if (!eta.isDiagonal()) {
213 // snprintf( painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
214 // "NgammaT error: the diagonal elements of eta matrix are not
215 // the same or etaMat is not a diagonal matrix");
216 // painCave.isFatal = 1;
217 // simError();
218 //}
219 }
220
221 void NgammaT::saveEta() { snap->setBarostat(eta); }
222
223} // namespace OpenMD
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.