OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
NPTsz.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
48#include "integrators/NPTsz.hpp"
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
59 /**
60 * There is no known conserved quantity for the NPTsz integrator,
61 * but we still compute the equivalent quantity from a fully
62 * flexible constant pressure integrator.
63 */
64
65 NPTsz::NPTsz(SimInfo* info) : NPTf(info) {
66 Globals* simParams = info_->getSimParams();
67
68 // Default value of privilegedAxis is "z"
69 if (simParams->getPrivilegedAxis() == "x")
70 axis_ = 0;
71 else if (simParams->getPrivilegedAxis() == "y")
72 axis_ = 1;
73 else if (simParams->getPrivilegedAxis() == "z")
74 axis_ = 2;
75
76 // Compute complementary axes to the privileged axis
77 axis1_ = (axis_ + 1) % 3;
78 axis2_ = (axis_ + 2) % 3;
79 }
80
81 RealType NPTsz::calcConservedQuantity() {
82 thermostat = snap->getThermostat();
83 loadEta();
84
85 // We need NkBT a lot, so just set it here: This is the RAW number
86 // of integrableObjects, so no subtraction or addition of
87 // constraints or orientational degrees of freedom:
88 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
89
90 // fkBT is used because the thermostat operates on more degrees of
91 // freedom than the barostat (when there are particles with
92 // orientational degrees of freedom).
93 fkBT = info_->getNdf() * Constants::kB * targetTemp;
94
95 RealType conservedQuantity;
96 RealType totalEnergy;
97 RealType thermostat_kinetic;
98 RealType thermostat_potential;
99 RealType barostat_kinetic;
100 RealType barostat_potential;
101 RealType trEta;
102
103 totalEnergy = thermo.getTotalEnergy();
104
105 thermostat_kinetic = fkBT * tt2 * thermostat.first * thermostat.first /
106 (2.0 * Constants::energyConvert);
107
108 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
109
110 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
111 trEta = tmp.trace();
112
113 barostat_kinetic = NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
114
115 barostat_potential =
116 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
117 Constants::energyConvert;
118
119 conservedQuantity = totalEnergy + thermostat_kinetic +
120 thermostat_potential + barostat_kinetic +
121 barostat_potential;
122
123 return conservedQuantity;
124 }
125
126 void NPTsz::scaleSimBox() {
127 int i, j;
128 Mat3x3d scaleMat;
129 RealType scaleFactor;
130 RealType bigScale, smallScale;
131 Mat3x3d hm;
132 Mat3x3d hmnew;
133
134 // Scale the box after all the positions have been moved:
135
136 // Use a taylor expansion for eta products:
137 // Hmat = Hmat . exp(dt * etaMat)
138 // Hmat = Hmat . ( Ident + dt * etaMat + dt^2 * etaMat*etaMat / 2)
139
140 bigScale = 1.0;
141 smallScale = 1.0;
142
143 for (i = 0; i < 3; i++) {
144 for (j = 0; j < 3; j++) {
145 scaleMat(i, j) = 0.0;
146 if (i == j) { scaleMat(i, j) = 1.0; }
147 }
148 }
149
150 // scale x & y together:
151 scaleFactor =
152 0.5 * (exp(dt * eta(axis1_, axis1_)) + exp(dt * eta(axis2_, axis2_)));
153 scaleMat(axis1_, axis1_) = scaleFactor;
154 scaleMat(axis2_, axis2_) = scaleFactor;
155
156 bigScale = scaleFactor;
157 smallScale = scaleFactor;
158
159 // scale z separately
160 scaleFactor = exp(dt * eta(axis_, axis_));
161 scaleMat(axis_, axis_) = scaleFactor;
162 if (scaleFactor > bigScale) bigScale = scaleFactor;
163 if (scaleFactor < smallScale) smallScale = scaleFactor;
164
165 if ((bigScale > 1.1) || (smallScale < 0.9)) {
166 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
167 "NPTsz: Attempting a Box scaling of more than 10 percent.\n"
168 "\tCheck your tauBarostat, as it is probably too small!\n\n"
169 "\tscaleMat = [%lf\t%lf\t%lf]\n"
170 "\t [%lf\t%lf\t%lf]\n"
171 "\t [%lf\t%lf\t%lf]\n",
172 scaleMat(0, 0), scaleMat(0, 1), scaleMat(0, 2), scaleMat(1, 0),
173 scaleMat(1, 1), scaleMat(1, 2), scaleMat(2, 0), scaleMat(2, 1),
174 scaleMat(2, 2));
175 painCave.severity = OPENMD_ERROR;
176 painCave.isFatal = 1;
177 simError();
178 } else {
179 Mat3x3d hmat = snap->getHmat();
180 hmat = hmat * scaleMat;
181 snap->setHmat(hmat);
182 }
183 }
184
185 void NPTsz::loadEta() { eta = snap->getBarostat(); }
186} // namespace OpenMD
NPTsz(SimInfo *info)
There is no known conserved quantity for the NPTsz integrator, but we still compute the equivalent qu...
Definition NPTsz.cpp:65
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
int getNdf()
Returns the number of degrees of freedom.
Definition SimInfo.hpp:223
int getNGlobalIntegrableObjects()
Returns the total number of integrable objects (total number of rigid bodies plus the total number of...
Definition SimInfo.hpp:142
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.