88
99#include < cmath>
1010
11+ namespace tinker {
12+ namespace {
13+ class DummyThermostat : public BasicThermostat
14+ {
15+ public:
16+ void control2 (time_prec, bool ) override {}
17+ };
18+ }
19+ }
20+
1121namespace tinker {
1222void BasicThermostat::printBasic (FILE * o)
1323{
@@ -23,9 +33,9 @@ void BasicThermostat::printDetail(FILE* o) {}
2333
2434void BasicThermostat::control1 (time_prec) {}
2535
26- void BasicThermostat::control2 (time_prec, bool save )
36+ void BasicThermostat::control2 (time_prec, bool calcEkin )
2737{
28- if (save ) {
38+ if (calcEkin ) {
2939 T_prec temp;
3040 kinetic (temp);
3141 }
@@ -40,10 +50,14 @@ BasicThermostat* BasicThermostat::create(ThermostatEnum te)
4050 break ;
4151 case ThermostatEnum::NHC :
4252 t = new NhcDevice (5 , 5 , static_cast <double >(mdstuf::nfree), //
43- NhcDevice::kineticAtomic, //
53+ &eksum, NhcDevice::kineticAtomic, //
4454 NhcDevice::scaleVelocityAtomic, //
4555 std::string (" NHC Atomic Temperature" ));
4656 break ;
57+ case ThermostatEnum::m_LP2022:
58+ case ThermostatEnum::m_NHC2006:
59+ t = new DummyThermostat;
60+ break ;
4761 default :
4862 t = new BasicThermostat;
4963 break ;
@@ -69,7 +83,7 @@ void BussiThermostat::control2(time_prec dt, bool)
6983}
7084
7185namespace tinker {
72- void NhcDevice::controlImpl (time_prec dt)
86+ void NhcDevice::controlImpl (time_prec dt, bool calcEkin )
7387{
7488 const int nc = nhc_nc;
7589 constexpr int ns = nhc_nsy;
@@ -82,7 +96,11 @@ void NhcDevice::controlImpl(time_prec dt)
8296 double kbt = units::gasconst * bath::kelvin;
8397
8498 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;
86104 double velsc0 = 1.0 ;
87105 for (int k = 0 ; k < nc; ++k) {
88106 for (int j = 0 ; j < ns; ++j) {
@@ -129,12 +147,13 @@ void NhcDevice::controlImpl(time_prec dt)
129147 scale_vel (velsc0);
130148}
131149
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)
134152 : BasicThermostat()
135153 , nnose(nhclen)
136154 , nhc_nc(nc)
137155 , g0(dfree)
156+ , m_kin_ptr(kin_ptr)
138157 , f_kin(kin)
139158 , scale_vel(scale)
140159 , name(str)
@@ -152,6 +171,8 @@ NhcDevice::NhcDevice(
152171 vnh[i] = 0 ;
153172 }
154173 qnh[0 ] *= g0;
174+
175+ f_kin ();
155176}
156177
157178void NhcDevice::printDetail (FILE * o)
@@ -172,12 +193,13 @@ void NhcDevice::printDetail(FILE* o)
172193
173194void NhcDevice::control1 (time_prec dt)
174195{
175- this ->controlImpl (dt);
196+ bool calcEkin = false ;
197+ this ->controlImpl (dt, calcEkin);
176198}
177199
178- void NhcDevice::control2 (time_prec dt, bool )
200+ void NhcDevice::control2 (time_prec dt, bool calcEkin )
179201{
180- this ->controlImpl (dt);
202+ this ->controlImpl (dt, calcEkin );
181203}
182204
183205double NhcDevice::kineticAtomic ()
@@ -209,16 +231,16 @@ Nhc06Thermostat::Nhc06Thermostat()
209231 // tpart
210232 if (atomic) {
211233 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" );
214236 } else {
215237 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,
217239 Nhc06Thermostat::scaleVelocityRattleGroup, " NHC Group Temperature" );
218240 }
219241
220242 // tbaro
221- m_tbaro = new NhcDevice (nhclen, nc, dofVbar (), Nhc06Thermostat::kineticVbar,
243+ m_tbaro = new NhcDevice (nhclen, nc, dofVbar (), nullptr , Nhc06Thermostat::kineticVbar,
222244 Nhc06Thermostat::scaleVelocityVbar, " NHC Barostat Temperature" );
223245}
224246
@@ -241,11 +263,17 @@ void Nhc06Thermostat::control1(time_prec dt)
241263 m_tpart->control1 (dt);
242264}
243265
244- void Nhc06Thermostat::control2 (time_prec dt, bool save )
266+ void Nhc06Thermostat::control2 (time_prec dt, bool )
245267{
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+ }
249277}
250278
251279double Nhc06Thermostat::kineticRattleGroup ()
0 commit comments