OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
NPTi.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 "NPTi.hpp"
46
47#include "brains/SimInfo.hpp"
48#include "brains/Thermo.hpp"
49#include "integrators/NPT.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
53
54namespace OpenMD {
55
56 // Basic isotropic thermostating and barostating via the Melchionna
57 // modification of the Hoover algorithm:
58 //
59 // Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
60 // Molec. Phys., 78, 533.
61 //
62 // and
63 //
64 // Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
65
66 NPTi::NPTi(SimInfo* info) : NPT(info) {}
67
68 void NPTi::evolveEtaA() {
69 eta += dt2 * (instaVol * (instaPress - targetPressure) /
70 (Constants::pressureConvert * NkBT * tb2));
71 oldEta = eta;
72 }
73
74 void NPTi::evolveEtaB() {
75 prevEta = eta;
76 eta = oldEta + dt2 * (instaVol * (instaPress - targetPressure) /
77 (Constants::pressureConvert * NkBT * tb2));
78 }
79
80 void NPTi::calcVelScale() { vScale = thermostat.first + eta; }
81
82 void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
83 sc = vel * vScale;
84 }
85
86 void NPTi::getVelScaleB(Vector3d& sc, int index) {
87 sc = oldVel[index] * vScale;
88 }
89
90 void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM, int index,
91 Vector3d& sc) {
92 /**@todo*/
93 sc = (oldPos[index] + pos) / (RealType)2.0 - COM;
94 sc *= eta;
95 }
96
97 void NPTi::scaleSimBox() {
98 RealType scaleFactor;
99
100 scaleFactor = exp(dt * eta);
101
102 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
103 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
104 "NPTi error: Attempting a Box scaling of more than 10 percent"
105 " check your tauBarostat, as it is probably too small!\n"
106 " eta = %lf, scaleFactor = %lf\n",
107 eta, scaleFactor);
108 painCave.isFatal = 1;
109 simError();
110 } else {
111 Mat3x3d hmat = snap->getHmat();
112 hmat *= scaleFactor;
113 snap->setHmat(hmat);
114 }
115 }
116
117 bool NPTi::etaConverged() { return (fabs(prevEta - eta) <= etaTolerance); }
118
119 RealType NPTi::calcConservedQuantity() {
120 thermostat = snap->getThermostat();
121 loadEta();
122 // We need NkBT a lot, so just set it here: This is the RAW number
123 // of integrableObjects, so no subtraction or addition of constraints or
124 // orientational degrees of freedom:
125 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
126
127 // fkBT is used because the thermostat operates on more degrees of freedom
128 // than the barostat (when there are particles with orientational degrees
129 // of freedom).
130 fkBT = info_->getNdf() * Constants::kB * targetTemp;
131
132 RealType conservedQuantity;
133 RealType Energy;
134 RealType thermostat_kinetic;
135 RealType thermostat_potential;
136 RealType barostat_kinetic;
137 RealType barostat_potential;
138
139 Energy = thermo.getTotalEnergy();
140
141 thermostat_kinetic = fkBT * tt2 * thermostat.first * thermostat.first /
142 (2.0 * Constants::energyConvert);
143
144 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
145
146 barostat_kinetic =
147 3.0 * NkBT * tb2 * eta * eta / (2.0 * Constants::energyConvert);
148
149 barostat_potential =
150 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
151 Constants::energyConvert;
152
153 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
154 barostat_kinetic + barostat_potential;
155
156 return conservedQuantity;
157 }
158
159 void NPTi::loadEta() {
160 Mat3x3d etaMat = snap->getBarostat();
161 eta = etaMat(0, 0);
162 // if (fabs(etaMat(1,1) - eta) >= OpenMD::epsilon || fabs(etaMat(1,1) - eta)
163 // >= OpenMD::epsilon || !etaMat.isDiagonal()) {
164 // snprintf( painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
165 // "NPTi error: the diagonal elements of eta matrix are not the
166 // same or etaMat is not a diagonal matrix");
167 // painCave.isFatal = 1;
168 // simError();
169 //}
170 }
171
172 void NPTi::saveEta() {
173 Mat3x3d etaMat(0.0);
174 etaMat(0, 0) = eta;
175 etaMat(1, 1) = eta;
176 etaMat(2, 2) = eta;
177 snap->setBarostat(etaMat);
178 }
179} // 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
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.