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