OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
NPAT.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/NPAT.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 NPAT::NPAT(SimInfo* info) : NPT(info) {
60 Globals* simParams = info_->getSimParams();
61
62 // Default value of privilegedAxis is "z"
63 if (simParams->getPrivilegedAxis() == "x")
64 axis_ = 0;
65 else if (simParams->getPrivilegedAxis() == "y")
66 axis_ = 1;
67 else if (simParams->getPrivilegedAxis() == "z")
68 axis_ = 2;
69 }
70
71 void NPAT::evolveEtaA() {
72 eta(axis_, axis_) +=
73 dt2 * instaVol *
74 (press(axis_, axis_) - targetPressure / Constants::pressureConvert) /
75 (NkBT * tb2);
76 oldEta_ = eta;
77 }
78
79 void NPAT::evolveEtaB() {
80 prevEta_ = eta;
81 eta(axis_, axis_) = oldEta_(axis_, axis_) +
82 dt2 * instaVol *
83 (press(axis_, axis_) -
84 targetPressure / Constants::pressureConvert) /
85 (NkBT * tb2);
86 }
87
88 void NPAT::calcVelScale() {
89 for (int i = 0; i < 3; i++) {
90 for (int j = 0; j < 3; j++) {
91 vScale_(i, j) = eta(i, j);
92
93 if (i == j) { vScale_(i, j) += thermostat.first; }
94 }
95 }
96 }
97
98 void NPAT::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
99 sc = vScale_ * vel;
100 }
101
102 void NPAT::getVelScaleB(Vector3d& sc, int index) {
103 sc = vScale_ * oldVel[index];
104 }
105
106 void NPAT::getPosScale(const Vector3d& pos, const Vector3d& COM, int index,
107 Vector3d& sc) {
108 /**@todo */
109 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
110 sc = eta * rj;
111 }
112
113 void NPAT::scaleSimBox() {
114 Mat3x3d scaleMat;
115
116 for (int i = 0; i < 3; i++) {
117 for (int j = 0; j < 3; j++) {
118 scaleMat(i, j) = 0.0;
119 if (i == j) { scaleMat(i, j) = 1.0; }
120 }
121 }
122
123 scaleMat(axis_, axis_) = exp(dt * eta(axis_, axis_));
124 Mat3x3d hmat = snap->getHmat();
125 hmat = hmat * scaleMat;
126 snap->setHmat(hmat);
127 }
128
129 bool NPAT::etaConverged() {
130 int i;
131 RealType diffEta, sumEta;
132
133 sumEta = 0;
134 for (i = 0; i < 3; i++) {
135 sumEta += pow(prevEta_(i, i) - eta(i, i), 2);
136 }
137
138 diffEta = sqrt(sumEta / 3.0);
139
140 return (diffEta <= etaTolerance);
141 }
142
143 RealType NPAT::calcConservedQuantity() {
144 thermostat = snap->getThermostat();
145 loadEta();
146
147 // We need NkBT a lot, so just set it here: This is the RAW number
148 // of integrableObjects, so no subtraction or addition of constraints or
149 // orientational degrees of freedom:
150 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
151
152 // fkBT is used because the thermostat operates on more degrees of freedom
153 // than the barostat (when there are particles with orientational degrees
154 // of freedom).
155 fkBT = info_->getNdf() * Constants::kB * targetTemp;
156
157 RealType conservedQuantity;
158 RealType totalEnergy;
159 RealType thermostat_kinetic;
160 RealType thermostat_potential;
161 RealType barostat_kinetic;
162 RealType barostat_potential;
163 RealType trEta;
164
165 totalEnergy = thermo.getTotalEnergy();
166
167 thermostat_kinetic = fkBT * tt2 * thermostat.first * thermostat.first /
168 (2.0 * Constants::energyConvert);
169
170 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
171
172 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
173 trEta = tmp.trace();
174
175 barostat_kinetic = NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
176
177 barostat_potential =
178 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
179 Constants::energyConvert;
180
181 conservedQuantity = totalEnergy + thermostat_kinetic +
182 thermostat_potential + barostat_kinetic +
183 barostat_potential;
184
185 return conservedQuantity;
186 }
187
188 void NPAT::loadEta() {
189 eta = snap->getBarostat();
190
191 // if (!eta.isDiagonal()) {
192 // snprintf( painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
193 // "NPAT error: the diagonal elements of eta matrix are not the
194 // same or etaMat is not a diagonal matrix");
195 // painCave.isFatal = 1;
196 // simError();
197 //}
198 }
199
200 void NPAT::saveEta() { snap->setBarostat(eta); }
201
202} // 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.