8
8
9
9
#include < cmath>
10
10
11
+ namespace tinker {
12
+ namespace {
13
+ class DummyThermostat : public BasicThermostat
14
+ {
15
+ public:
16
+ void control2 (time_prec, bool ) override {}
17
+ };
18
+ }
19
+ }
20
+
11
21
namespace tinker {
12
22
void BasicThermostat::printBasic (FILE* o)
13
23
{
@@ -23,9 +33,9 @@ void BasicThermostat::printDetail(FILE* o) {}
23
33
24
34
void BasicThermostat::control1 (time_prec) {}
25
35
26
- void BasicThermostat::control2 (time_prec, bool save )
36
+ void BasicThermostat::control2 (time_prec, bool calcEkin )
27
37
{
28
- if (save ) {
38
+ if (calcEkin ) {
29
39
T_prec temp;
30
40
kinetic (temp);
31
41
}
@@ -40,10 +50,14 @@ BasicThermostat* BasicThermostat::create(ThermostatEnum te)
40
50
break ;
41
51
case ThermostatEnum::NHC:
42
52
t = new NhcDevice (5 , 5 , static_cast <double >(mdstuf::nfree), //
43
- NhcDevice::kineticAtomic, //
53
+ &eksum, NhcDevice::kineticAtomic, //
44
54
NhcDevice::scaleVelocityAtomic, //
45
55
std::string (" NHC Atomic Temperature" ));
46
56
break ;
57
+ case ThermostatEnum::m_LP2022:
58
+ case ThermostatEnum::m_NHC2006:
59
+ t = new DummyThermostat;
60
+ break ;
47
61
default :
48
62
t = new BasicThermostat;
49
63
break ;
@@ -69,7 +83,7 @@ void BussiThermostat::control2(time_prec dt, bool)
69
83
}
70
84
71
85
namespace tinker {
72
- void NhcDevice::controlImpl (time_prec dt)
86
+ void NhcDevice::controlImpl (time_prec dt, bool calcEkin )
73
87
{
74
88
const int nc = nhc_nc;
75
89
constexpr int ns = nhc_nsy;
@@ -82,7 +96,11 @@ void NhcDevice::controlImpl(time_prec dt)
82
96
double kbt = units::gasconst * bath::kelvin;
83
97
84
98
double dtc = dt / nc;
85
- double eksum0 = f_kin ();
99
+ double eksum0;
100
+ if (calcEkin or m_kin_ptr == nullptr )
101
+ eksum0 = f_kin ();
102
+ else
103
+ eksum0 = *m_kin_ptr;
86
104
double velsc0 = 1.0 ;
87
105
for (int k = 0 ; k < nc; ++k) {
88
106
for (int j = 0 ; j < ns; ++j) {
@@ -129,12 +147,13 @@ void NhcDevice::controlImpl(time_prec dt)
129
147
scale_vel (velsc0);
130
148
}
131
149
132
- NhcDevice::NhcDevice (
133
- int nhclen, int nc, double dfree, double (*kin)(), void (*scale)( double ), std::string str)
150
+ NhcDevice::NhcDevice (int nhclen, int nc, double dfree, double * kin_ptr, double (*kin)(), void (*scale)( double ),
151
+ std::string str)
134
152
: BasicThermostat()
135
153
, nnose(nhclen)
136
154
, nhc_nc(nc)
137
155
, g0(dfree)
156
+ , m_kin_ptr(kin_ptr)
138
157
, f_kin(kin)
139
158
, scale_vel(scale)
140
159
, name(str)
@@ -152,6 +171,8 @@ NhcDevice::NhcDevice(
152
171
vnh[i] = 0 ;
153
172
}
154
173
qnh[0 ] *= g0;
174
+
175
+ f_kin ();
155
176
}
156
177
157
178
void NhcDevice::printDetail (FILE* o)
@@ -172,12 +193,13 @@ void NhcDevice::printDetail(FILE* o)
172
193
173
194
void NhcDevice::control1 (time_prec dt)
174
195
{
175
- this ->controlImpl (dt);
196
+ bool calcEkin = false ;
197
+ this ->controlImpl (dt, calcEkin);
176
198
}
177
199
178
- void NhcDevice::control2 (time_prec dt, bool )
200
+ void NhcDevice::control2 (time_prec dt, bool calcEkin )
179
201
{
180
- this ->controlImpl (dt);
202
+ this ->controlImpl (dt, calcEkin );
181
203
}
182
204
183
205
double NhcDevice::kineticAtomic ()
@@ -209,16 +231,16 @@ Nhc06Thermostat::Nhc06Thermostat()
209
231
// tpart
210
232
if (atomic) {
211
233
dofT = mdstuf::nfree;
212
- m_tpart = new NhcDevice (nhclen, nc, dofT, NhcDevice::kineticAtomic,
213
- NhcDevice::scaleVelocityAtomic, " NHC Atomic Temperature" );
234
+ m_tpart = new NhcDevice (nhclen, nc, dofT, &eksum, NhcDevice::kineticAtomic, NhcDevice::scaleVelocityAtomic ,
235
+ " NHC Atomic Temperature" );
214
236
} else {
215
237
dofT = 3.0 * (rattle_dmol.nmol - 1 );
216
- m_tpart = new NhcDevice (nhclen, nc, dofT, Nhc06Thermostat::kineticRattleGroup,
238
+ m_tpart = new NhcDevice (nhclen, nc, dofT, &hc_eksum, Nhc06Thermostat::kineticRattleGroup,
217
239
Nhc06Thermostat::scaleVelocityRattleGroup, " NHC Group Temperature" );
218
240
}
219
241
220
242
// tbaro
221
- m_tbaro = new NhcDevice (nhclen, nc, dofVbar (), Nhc06Thermostat::kineticVbar,
243
+ m_tbaro = new NhcDevice (nhclen, nc, dofVbar (), nullptr , Nhc06Thermostat::kineticVbar,
222
244
Nhc06Thermostat::scaleVelocityVbar, " NHC Barostat Temperature" );
223
245
}
224
246
@@ -241,11 +263,17 @@ void Nhc06Thermostat::control1(time_prec dt)
241
263
m_tpart->control1 (dt);
242
264
}
243
265
244
- void Nhc06Thermostat::control2 (time_prec dt, bool save )
266
+ void Nhc06Thermostat::control2 (time_prec dt, bool )
245
267
{
246
- m_tpart->control2 (dt, save);
247
- if (applyBaro)
248
- m_tbaro->control2 (dt, false );
268
+ bool calcEkin;
269
+ if (applyBaro) {
270
+ calcEkin = false ; // in nhc06 barostat, ek will be calculated in the barostat
271
+ m_tpart->control2 (dt, calcEkin);
272
+ m_tbaro->control2 (dt, calcEkin);
273
+ } else {
274
+ calcEkin = true ;
275
+ m_tpart->control2 (dt, calcEkin);
276
+ }
249
277
}
250
278
251
279
double Nhc06Thermostat::kineticRattleGroup ()
0 commit comments