NAMD
Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
Controller Class Reference

#include <Controller.h>

Inheritance diagram for Controller:
ControllerState

Classes

struct  checkpoint
 
struct  CthThreadWrapper
 

Public Member Functions

 Controller (NamdState *s)
 
virtual ~Controller (void)
 
void run (void)
 
void awaken (void)
 
void resumeAfterTraceBarrier (int)
 
BigReal getTIderivative (void) const
 
void resetMovingAverage ()
 
void stochRescaleVelocities (int)
 
double stochRescaleCoefficient ()
 

Public Attributes

BigReal accelMDdV
 
int stochRescale_count
 
BigReal stochRescaleTimefactor
 

Protected Types

enum  mc_axis_pick { MC_X = 0, MC_Y, MC_Z, MC_AXIS_TOTAL }
 

Protected Member Functions

virtual void algorithm (void)
 
void integrate (int)
 
void minimize ()
 
void receivePressure (int step, int minimize=0)
 
void calcPressure (int step, int minimize, const Tensor &virial_normal_in, const Tensor &virial_nbond_in, const Tensor &virial_slow_in, const Tensor &intVirial_normal, const Tensor &intVirial_nbond, const Tensor &intVirial_slow, const Vector &extForce_normal, const Vector &extForce_nbond, const Vector &extForce_slow)
 
void compareChecksums (int, int=0)
 
BigReal getTotalPotentialEnergy (int step)
 
void printTiming (int)
 
void printMinimizeEnergies (int)
 
void printDynamicsEnergies (int)
 
void printEnergies (int step, int minimize)
 
void printFepMessage (int)
 
void printTiMessage (int)
 
void enqueueCollections (int)
 
void correctMomentum (int step)
 
void rescaleVelocities (int)
 
void reassignVelocities (int)
 
void tcoupleVelocities (int)
 
void berendsenPressure (int)
 
void langevinPiston1 (int)
 
void langevinPiston2 (int)
 
void monteCarloPressure_prepare (int)
 
void monteCarloPressure_accept (int)
 
void multigratorPressure (int step, int callNumber)
 
void multigratorTemperature (int step, int callNumber)
 
BigReal multigatorCalcEnthalpy (BigReal potentialEnergy, int step, int minimize)
 
void rebalanceLoad (int)
 
void cycleBarrier (int, int)
 
void traceBarrier (int, int)
 
void suspend (void)
 
void terminate (void)
 
void outputExtendedSystem (int step)
 
void writeExtendedSystemLabels (ofstream_namd &file)
 
void writeExtendedSystemData (int step, ofstream_namd &file)
 
void outputFepEnergy (int step)
 
void writeFepEnergyData (int step, ofstream_namd &file)
 
void outputTiEnergy (int step)
 
BigReal computeAlchWork (const int step)
 
void writeTiEnergyData (int step, ofstream_namd &file)
 
void recvCheckpointReq (const char *key, int task, checkpoint &cp)
 
void recvCheckpointAck (checkpoint &cp)
 
void calc_accelMDG_mean_std (BigReal testV, int step_n, BigReal *Vmax, BigReal *Vmin, BigReal *Vavg, BigReal *M2, BigReal *sigmaV)
 
void calc_accelMDG_E_k (int iE, int V_n, BigReal sigma0, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, BigReal *k0, BigReal *k, BigReal *E, int *iEused, char *warn)
 
void calc_accelMDG_force_factor (BigReal k, BigReal E, BigReal testV, Tensor vir_orig, BigReal *dV, BigReal *factor, Tensor *vir)
 
void write_accelMDG_rest_file (int step_n, char type, int V_n, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, BigReal M2, BigReal E, BigReal k, bool write_topic, bool lasttime)
 
void rescaleaccelMD (int step, int minimize=0)
 
void adaptTempInit (int step)
 
void adaptTempUpdate (int step, int minimize=0)
 
void adaptTempWriteRestart (int step)
 

Protected Attributes

RequireReductionmin_reduction
 
Tensor pressure_normal
 
Tensor pressure_nbond
 
Tensor pressure_slow
 
Tensor pressure_amd
 
Tensor virial_amd
 
Tensor groupPressure_normal
 
Tensor groupPressure_nbond
 
Tensor groupPressure_slow
 
Tensor controlPressure_normal
 
Tensor controlPressure_nbond
 
Tensor controlPressure_slow
 
int nbondFreq
 
int slowFreq
 
BigReal temp_avg
 
BigReal pressure_avg
 
BigReal groupPressure_avg
 
int avg_count
 
Tensor pressure_tavg
 
Tensor groupPressure_tavg
 
int tavg_count
 
int computeChecksum
 
int marginViolations
 
int pairlistWarnings
 
BigReal min_energy
 
BigReal min_f_dot_f
 
BigReal min_f_dot_v
 
BigReal min_v_dot_v
 
int min_huge_count
 
int64_t numDegFreedom
 
int stepInFullRun
 
BigReal totalEnergy
 
BigReal electEnergy
 
BigReal electEnergySlow
 
BigReal ljEnergy
 
BigReal groLJEnergy
 
BigReal groGaussEnergy
 
BigReal goNativeEnergy
 
BigReal goNonnativeEnergy
 
BigReal goTotalEnergy
 
BigReal bondedEnergyDiff_f
 
BigReal electEnergy_f
 
BigReal electEnergySlow_f
 
BigReal ljEnergy_f
 
BigReal ljEnergy_f_left
 
BigReal exp_dE_ByRT
 
BigReal dE
 
BigReal net_dE
 
BigReal dG
 
int FepNo
 
BigReal fepSum
 
BigReal bondedEnergy_ti_1
 
BigReal bondedEnergy_ti_2
 
BigReal electEnergy_ti_1
 
BigReal electEnergySlow_ti_1
 
BigReal ljEnergy_ti_1
 
BigReal electEnergy_ti_2
 
BigReal electEnergySlow_ti_2
 
BigReal ljEnergy_ti_2
 
BigReal net_dEdl_bond_1
 
BigReal net_dEdl_bond_2
 
BigReal net_dEdl_elec_1
 
BigReal net_dEdl_elec_2
 
BigReal net_dEdl_lj_1
 
BigReal net_dEdl_lj_2
 
BigReal cumAlchWork
 
BigReal electEnergyPME_ti_1
 
BigReal electEnergyPME_ti_2
 
int TiNo
 
BigReal recent_dEdl_bond_1
 
BigReal recent_dEdl_bond_2
 
BigReal recent_dEdl_elec_1
 
BigReal recent_dEdl_elec_2
 
BigReal recent_dEdl_lj_1
 
BigReal recent_dEdl_lj_2
 
BigReal recent_alchWork
 
BigReal alchWork
 
int recent_TiNo
 
BigReal drudeBondTemp
 
BigReal drudeBondTempAvg
 
BigReal kineticEnergy
 
BigReal kineticEnergyHalfstep
 
BigReal kineticEnergyCentered
 
BigReal temperature
 
BigReal heat
 
BigReal totalEnergy0
 
BigReal smooth2_avg2
 
Tensor pressure
 
Tensor groupPressure
 
int controlNumDegFreedom
 
Tensor controlPressure
 
BigReal rescaleVelocities_sumTemps
 
int rescaleVelocities_numTemps
 
Tensor langevinPiston_origStrainRate
 
Tensor strainRate_old
 
Tensor positionRescaleFactor
 
int mc_trial [MC_AXIS_TOTAL]
 
int mc_accept [MC_AXIS_TOTAL]
 
int mc_totalTry
 
int mc_totalAccept
 
int mc_picked_axis
 
BigReal mc_totalEnergyOld
 
Lattice mc_oldLattice
 
BigReal multigratorXi
 
BigReal multigratorXiT
 
Tensor momentumSqrSum
 
std::vector< BigRealmultigratorNu
 
std::vector< BigRealmultigratorNuT
 
std::vector< BigRealmultigratorOmega
 
std::vector< BigRealmultigratorZeta
 
RequireReductionmultigratorReduction
 
int ldbSteps
 
int fflush_count
 
Randomrandom
 
SimParameters *const simParams
 
NamdState *const state
 
RequireReductionreduction
 
RequireReductionamd_reduction
 
SubmitReductionsubmit_reduction
 
NodeReductionnodeReduction
 
PressureProfileReductionppbonded
 
PressureProfileReductionppnonbonded
 
PressureProfileReductionppint
 
int pressureProfileSlabs
 
int pressureProfileCount
 
BigRealpressureProfileAverage
 
CollectionMaster *const collection
 
ControllerBroadcastsbroadcast
 
ofstream_namd xstFile
 
ofstream_namd fepFile
 
ofstream_namd tiFile
 
int checkpoint_stored
 
Lattice checkpoint_lattice
 
ControllerState checkpoint_state
 
std::map< std::string, checkpoint * > checkpoints
 
int checkpoint_task
 
Lattice origLattice
 
BigReal accelMDdVAverage
 
BigRealadaptTempPotEnergyAveNum
 
BigRealadaptTempPotEnergyAveDen
 
BigRealadaptTempPotEnergyVarNum
 
BigRealadaptTempPotEnergyAve
 
BigRealadaptTempPotEnergyVar
 
int * adaptTempPotEnergySamples
 
BigRealadaptTempBetaN
 
BigReal adaptTempT
 
BigReal adaptTempDTave
 
BigReal adaptTempDTavenum
 
BigReal adaptTempBetaMin
 
BigReal adaptTempBetaMax
 
int adaptTempBin
 
int adaptTempBins
 
BigReal adaptTempDBeta
 
BigReal adaptTempCg
 
BigReal adaptTempDt
 
Bool adaptTempAutoDt
 
BigReal adaptTempDtMin
 
BigReal adaptTempDtMax
 
ofstream_namd adaptTempRestartFile
 
RunningAverage perfstats
 
MovingAverage totalEnergyAverage
 
MovingAverage temperatureAverage
 
MovingAverage pressureAverage
 
MovingAverage groupPressureAverage
 
MovingAverage pressureAverage_xx
 
MovingAverage pressureAverage_yx
 
MovingAverage pressureAverage_yy
 
MovingAverage pressureAverage_zx
 
MovingAverage pressureAverage_zy
 
MovingAverage pressureAverage_zz
 
MovingAverage groupPressureAverage_xx
 
MovingAverage groupPressureAverage_xy
 
MovingAverage groupPressureAverage_xz
 
MovingAverage groupPressureAverage_yx
 
MovingAverage groupPressureAverage_yy
 
MovingAverage groupPressureAverage_yz
 
MovingAverage groupPressureAverage_zx
 
MovingAverage groupPressureAverage_zy
 
MovingAverage groupPressureAverage_zz
 
- Protected Attributes inherited from ControllerState
Tensor langevinPiston_strainRate
 
Tensor berendsenPressure_avg
 
Vector monteCarloMaxVolume
 
int berendsenPressure_count
 
BigReal smooth2_avg
 

Friends

class ScriptTcl
 
class Node
 
class CheckpointMsg
 

Detailed Description

Definition at line 106 of file Controller.h.

Member Enumeration Documentation

◆ mc_axis_pick

enum Controller::mc_axis_pick
protected
Enumerator
MC_X 
MC_Y 
MC_Z 
MC_AXIS_TOTAL 

Definition at line 309 of file Controller.h.

309  {
310  MC_X = 0, // for x-axis, constant ratio, or isotropic fluctuation
311  MC_Y, // for y-axis
312  MC_Z, // for z-axis or constant area fluctuations
314  };

Constructor & Destructor Documentation

◆ Controller()

Controller::Controller ( NamdState s)

Definition at line 177 of file Controller.C.

References SimParameters::accelMDOn, amd_reduction, avg_count, AVGXY, ControllerState::berendsenPressure_avg, ControllerState::berendsenPressure_count, BOLTZMANN, bondedEnergy_ti_1, bondedEnergy_ti_2, broadcast, checkpoint_stored, cumAlchWork, drudeBondTemp, drudeBondTempAvg, SimParameters::dt, electEnergy_ti_1, electEnergy_ti_2, electEnergySlow_ti_1, electEnergySlow_ti_2, groupPressure_avg, groupPressure_tavg, heat, Tensor::identity(), langevinPiston_origStrainRate, ControllerState::langevinPiston_strainRate, ljEnergy_ti_1, ljEnergy_ti_2, mc_accept, MC_AXIS_TOTAL, mc_totalAccept, mc_totalTry, mc_trial, min_reduction, Node::molecule, ControllerState::monteCarloMaxVolume, SimParameters::monteCarloMaxVolume, SimParameters::monteCarloPressureOn, MULTIGRATOR_REDUCTION_MAX_RESERVED, SimParameters::multigratorNoseHooverChainLength, multigratorNu, multigratorNuT, multigratorOmega, SimParameters::multigratorOn, multigratorReduction, SimParameters::multigratorTemperatureRelaxationTime, SimParameters::multigratorTemperatureTarget, multigratorXi, multigratorZeta, Molecule::num_deg_freedom(), PatchMap::Object(), Node::Object(), ReductionMgr::Object(), origLattice, ppbonded, ppint, ppnonbonded, pressure_avg, pressure_tavg, SimParameters::pressureProfileAtomTypes, pressureProfileAverage, pressureProfileCount, SimParameters::pressureProfileEwaldOn, SimParameters::pressureProfileFreq, SimParameters::pressureProfileOn, pressureProfileSlabs, SimParameters::pressureProfileSlabs, random, SimParameters::randomSeed, reduction, REDUCTIONS_AMD, REDUCTIONS_BASIC, REDUCTIONS_MINIMIZER, REDUCTIONS_MULTIGRATOR, REDUCTIONS_PPROF_BONDED, REDUCTIONS_PPROF_INTERNAL, REDUCTIONS_PPROF_NONBONDED, rescaleVelocities_numTemps, rescaleVelocities_sumTemps, simParams, ControllerState::smooth2_avg, Random::split(), state, stochRescale_count, SimParameters::stochRescaleFreq, SimParameters::stochRescaleOn, SimParameters::stochRescalePeriod, stochRescaleTimefactor, SimParameters::strainRate, SimParameters::strainRate2, submit_reduction, Tensor::symmetric(), tavg_count, temp_avg, totalEnergy0, SimParameters::useConstantRatio, SimParameters::useFlexibleCell, ReductionMgr::willRequire(), ReductionMgr::willSubmit(), Vector::x, XXXBIGREAL, Vector::y, and Vector::z.

177  :
179  simParams(Node::Object()->simParameters),
180  state(s),
182  startCTime(0),
183  firstCTime(CmiTimer()),
184  startWTime(0),
185  firstWTime(namdWallTimer()),
186  startBenchTime(0),
187  stepInFullRun(0),
188  ldbSteps(0),
189  fflush_count(3)
190 {
193  // for accelMD
194  if (simParams->accelMDOn) {
195  // REDUCTIONS_BASIC wil contain all potential energies and arrive first
197  // contents of amd_reduction be submitted to REDUCTIONS_AMD
199  // REDUCTIONS_AMD will contain Sequencer contributions and arrive second
201  } else {
202  amd_reduction = NULL;
203  submit_reduction = NULL;
205  // do I need to set nodeReduction as well?
206  }
207  // pressure profile reductions
210  ppbonded = ppnonbonded = ppint = NULL;
212  int ntypes = simParams->pressureProfileAtomTypes;
214  // number of partitions for pairwise interactions
215  int npairs = (ntypes * (ntypes+1))/2;
216  pressureProfileAverage = new BigReal[3*nslabs];
217  memset(pressureProfileAverage, 0, 3*nslabs*sizeof(BigReal));
218  int freq = simParams->pressureProfileFreq;
221  nslabs, npairs, "BONDED", freq);
223  nslabs, npairs, "NONBONDED", freq);
224  // internal partitions by atom type, but not in a pairwise fashion
226  nslabs, ntypes, "INTERNAL", freq);
227  } else {
228  // just doing Ewald, so only need nonbonded
230  nslabs, npairs, "NONBONDED", freq);
231  }
232  }
234  random->split(0,PatchMap::Object()->numPatches()+1);
235 
236  heat = totalEnergy0 = 0.0;
239  stochRescale_count = 0;
240  if (simParams->stochRescaleOn) {
243  }
245  // strainRate tensor is symmetric to avoid rotation
248  if ( ! simParams->useFlexibleCell ) {
249  BigReal avg = trace(langevinPiston_strainRate) / 3.;
251  } else if ( simParams->useConstantRatio ) {
252 #define AVGXY(T) T.xy = T.yx = 0; T.xx = T.yy = 0.5 * ( T.xx + T.yy );\
253  T.xz = T.zx = T.yz = T.zy = 0.5 * ( T.xz + T.yz );
255 #undef AVGXY
256  }
258 
259  // Monte Carlo pressure control
265  for(int ax = 0; ax < MC_AXIS_TOTAL; ++ax) {
266  mc_trial[ax] = 0;
267  mc_accept[ax] = 0;
268  }
269  }
270 
271  if (simParams->multigratorOn) {
272  multigratorXi = 0.0;
275  Node *node = Node::Object();
276  Molecule *molecule = node->molecule;
277  BigReal Nf = molecule->num_deg_freedom();
279  multigratorNu.resize(n);
280  multigratorNuT.resize(n);
281  multigratorZeta.resize(n);
282  multigratorOmega.resize(n);
283  for (int i=0;i < n;i++) {
284  multigratorNu[i] = 0.0;
285  multigratorZeta[i] = 0.0;
286  if (i == 0) {
287  multigratorOmega[i] = Nf*kT0*tau*tau;
288  } else {
289  multigratorOmega[i] = kT0*tau*tau;
290  }
291  }
293  } else {
294  multigratorReduction = NULL;
295  }
296  origLattice = state->lattice;
298  temp_avg = 0;
299  pressure_avg = 0;
300  groupPressure_avg = 0;
301  avg_count = 0;
302  pressure_tavg = 0;
303  groupPressure_tavg = 0;
304  tavg_count = 0;
305  checkpoint_stored = 0;
306  drudeBondTemp = 0;
307  drudeBondTempAvg = 0;
308  cumAlchWork = 0;
309 
310  bondedEnergy_ti_1 = 0;
311  bondedEnergy_ti_2 = 0;
312  ljEnergy_ti_1 = 0;
313  ljEnergy_ti_2 = 0;
314  electEnergy_ti_1 = 0;
315  electEnergy_ti_2 = 0;
318  TIderivative = 0;
319 }
static Node * Object()
Definition: Node.h:86
static NAMD_HOST_DEVICE Tensor symmetric(const Vector &v1, const Vector &v2)
Definition: Tensor.h:45
int checkpoint_stored
Definition: Controller.h:382
#define AVGXY(T)
#define XXXBIGREAL
Definition: Controller.C:76
int pressureProfileSlabs
Definition: Controller.h:361
BigReal electEnergy_ti_1
Definition: Controller.h:213
BigReal smooth2_avg
Definition: Controller.h:103
Bool monteCarloPressureOn
#define BOLTZMANN
Definition: common.h:54
Definition: Node.h:78
BigReal temp_avg
Definition: Controller.h:164
int fflush_count
Definition: Controller.h:336
int mc_accept[MC_AXIS_TOTAL]
Definition: Controller.h:316
static PatchMap * Object()
Definition: PatchMap.h:27
BigReal totalEnergy0
Definition: Controller.h:249
zVector monteCarloMaxVolume
BigReal pressure_avg
Definition: Controller.h:165
std::vector< BigReal > multigratorOmega
Definition: Controller.h:329
BigReal z
Definition: Vector.h:74
std::vector< BigReal > multigratorNuT
Definition: Controller.h:328
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:366
Tensor groupPressure_tavg
Definition: Controller.h:169
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:279
int pressureProfileSlabs
int stochRescale_count
Definition: Controller.h:278
int mc_trial[MC_AXIS_TOTAL]
Definition: Controller.h:316
Molecule stores the structural information for the system.
Definition: Molecule.h:175
void split(int iStream, int numStreams)
Definition: Random.h:77
RequireReduction * amd_reduction
Definition: Controller.h:351
static NAMD_HOST_DEVICE Tensor identity(BigReal v1=1.0)
Definition: Tensor.h:31
static double namdWallTimer()
Definition: Controller.C:57
BigReal heat
Definition: Controller.h:247
Tensor langevinPiston_strainRate
Definition: Controller.h:96
int pressureProfileCount
Definition: Controller.h:362
std::vector< BigReal > multigratorNu
Definition: Controller.h:327
NamdState *const state
Definition: Controller.h:349
PressureProfileReduction * ppint
Definition: Controller.h:360
BigReal ljEnergy_ti_1
Definition: Controller.h:215
BigReal stochRescalePeriod
Definition: Random.h:37
ControllerBroadcasts * broadcast
Definition: Controller.h:365
BigReal groupPressure_avg
Definition: Controller.h:166
BigReal drudeBondTempAvg
Definition: Controller.h:241
std::vector< BigReal > multigratorZeta
Definition: Controller.h:330
BigReal drudeBondTemp
Definition: Controller.h:240
zVector strainRate2
int computeChecksum
Definition: Controller.h:172
BigReal electEnergySlow_ti_1
Definition: Controller.h:214
int marginViolations
Definition: Controller.h:173
SubmitReduction * submit_reduction
Definition: Controller.h:352
BigReal rescaleVelocities_sumTemps
Definition: Controller.h:259
BigReal x
Definition: Vector.h:74
int berendsenPressure_count
Definition: Controller.h:102
RequireReduction * multigratorReduction
Definition: Controller.h:331
int multigratorNoseHooverChainLength
BigReal multigratorTemperatureTarget
int ldbSteps
Definition: Controller.h:334
zVector strainRate
Bool pressureProfileEwaldOn
Random * random
Definition: Controller.h:347
BigReal multigratorTemperatureRelaxationTime
static CollectionMaster * Object()
BigReal electEnergy_ti_2
Definition: Controller.h:216
int pairlistWarnings
Definition: Controller.h:174
unsigned int randomSeed
int mc_totalTry
Definition: Controller.h:317
CollectionMaster *const collection
Definition: Controller.h:364
int pressureProfileAtomTypes
BigReal * pressureProfileAverage
Definition: Controller.h:363
RequireReduction * min_reduction
Definition: Controller.h:143
BigReal stochRescaleTimefactor
Definition: Controller.h:281
BigReal cumAlchWork
Definition: Controller.h:225
Tensor pressure_tavg
Definition: Controller.h:168
int rescaleVelocities_numTemps
Definition: Controller.h:260
BigReal y
Definition: Vector.h:74
Vector monteCarloMaxVolume
Definition: Controller.h:101
Bool pressureProfileOn
PressureProfileReduction * ppnonbonded
Definition: Controller.h:359
int64_t num_deg_freedom(int isInitialReport=0) const
Definition: Molecule.h:552
RequireReduction * willRequire(int setID, int size=-1)
Definition: ReductionMgr.C:527
BigReal electEnergySlow_ti_2
Definition: Controller.h:217
SimParameters *const simParams
Definition: Controller.h:348
BigReal bondedEnergy_ti_2
Definition: Controller.h:212
int tavg_count
Definition: Controller.h:170
RequireReduction * reduction
Definition: Controller.h:350
PressureProfileReduction * ppbonded
Definition: Controller.h:358
Lattice origLattice
Definition: Controller.h:395
BigReal bondedEnergy_ti_1
Definition: Controller.h:211
Tensor langevinPiston_origStrainRate
Definition: Controller.h:291
Molecule * molecule
Definition: Node.h:179
Tensor berendsenPressure_avg
Definition: Controller.h:97
int stepInFullRun
Definition: Controller.h:187
int avg_count
Definition: Controller.h:167
BigReal multigratorXi
Definition: Controller.h:323
double BigReal
Definition: common.h:123
BigReal ljEnergy_ti_2
Definition: Controller.h:218
int mc_totalAccept
Definition: Controller.h:317

◆ ~Controller()

Controller::~Controller ( void  )
virtual

Definition at line 321 of file Controller.C.

References amd_reduction, broadcast, min_reduction, multigratorReduction, ppbonded, ppint, ppnonbonded, pressureProfileAverage, random, reduction, and submit_reduction.

322 {
323  delete broadcast;
324  delete reduction;
325  delete min_reduction;
326  delete amd_reduction;
327  delete submit_reduction;
328  delete ppbonded;
329  delete ppnonbonded;
330  delete ppint;
331  delete [] pressureProfileAverage;
332  delete random;
334 }
RequireReduction * amd_reduction
Definition: Controller.h:351
PressureProfileReduction * ppint
Definition: Controller.h:360
ControllerBroadcasts * broadcast
Definition: Controller.h:365
SubmitReduction * submit_reduction
Definition: Controller.h:352
RequireReduction * multigratorReduction
Definition: Controller.h:331
Random * random
Definition: Controller.h:347
BigReal * pressureProfileAverage
Definition: Controller.h:363
RequireReduction * min_reduction
Definition: Controller.h:143
PressureProfileReduction * ppnonbonded
Definition: Controller.h:359
RequireReduction * reduction
Definition: Controller.h:350
PressureProfileReduction * ppbonded
Definition: Controller.h:358

Member Function Documentation

◆ adaptTempInit()

void Controller::adaptTempInit ( int  step)
protected

Definition at line 2925 of file Controller.C.

References adaptTempAutoDt, SimParameters::adaptTempAutoDt, adaptTempBetaMax, adaptTempBetaMin, adaptTempBetaN, adaptTempBins, SimParameters::adaptTempBins, adaptTempCg, SimParameters::adaptTempCgamma, adaptTempDBeta, adaptTempDt, SimParameters::adaptTempDt, adaptTempDTave, adaptTempDTavenum, adaptTempDtMax, adaptTempDtMin, SimParameters::adaptTempInFile, SimParameters::adaptTempOn, adaptTempPotEnergyAve, adaptTempPotEnergyAveDen, adaptTempPotEnergyAveNum, adaptTempPotEnergySamples, adaptTempPotEnergyVar, adaptTempPotEnergyVarNum, adaptTempRestartFile, SimParameters::adaptTempRestartFile, SimParameters::adaptTempRestartFreq, adaptTempT, SimParameters::adaptTempTmax, SimParameters::adaptTempTmin, endi(), iINFO(), SimParameters::initialTemp, iout, SimParameters::langevinOn, SimParameters::langevinTemp, NAMD_backup_file(), NAMD_die(), ofstream_namd::open(), SimParameters::rescaleFreq, SimParameters::rescaleTemp, and simParams.

Referenced by adaptTempUpdate().

2925  {
2926  if (!simParams->adaptTempOn) return;
2927  iout << iINFO << "INITIALISING ADAPTIVE TEMPERING\n" << endi;
2928  adaptTempDtMin = 0;
2929  adaptTempDtMax = 0;
2930  adaptTempAutoDt = false;
2931  if (simParams->adaptTempBins == 0) {
2932  iout << iINFO << "READING ADAPTIVE TEMPERING RESTART FILE\n" << endi;
2933  std::ifstream adaptTempRead(simParams->adaptTempInFile);
2934  if (adaptTempRead) {
2935  int readInt;
2936  BigReal readReal;
2937  bool readBool;
2938  // step
2939  adaptTempRead >> readInt;
2940  // Start with min and max temperatures
2941  adaptTempRead >> adaptTempT; // KELVIN
2942  adaptTempRead >> adaptTempBetaMin; // KELVIN
2943  adaptTempRead >> adaptTempBetaMax; // KELVIN
2944  adaptTempBetaMin = 1./adaptTempBetaMin; // KELVIN^-1
2945  adaptTempBetaMax = 1./adaptTempBetaMax; // KELVIN^-1
2946  // In case file is manually edited
2948  readReal = adaptTempBetaMax;
2951  }
2952  adaptTempRead >> adaptTempBins;
2953  adaptTempRead >> adaptTempCg;
2954  adaptTempRead >> adaptTempDt;
2963  for(int j = 0; j < adaptTempBins; ++j) {
2964  adaptTempRead >> adaptTempPotEnergyAve[j];
2965  adaptTempRead >> adaptTempPotEnergyVar[j];
2966  adaptTempRead >> adaptTempPotEnergySamples[j];
2967  adaptTempRead >> adaptTempPotEnergyAveNum[j];
2968  adaptTempRead >> adaptTempPotEnergyVarNum[j];
2969  adaptTempRead >> adaptTempPotEnergyAveDen[j];
2971  }
2972  adaptTempRead.close();
2973  }
2974  else NAMD_die("Could not open ADAPTIVE TEMPERING restart file.\n");
2975  }
2976  else {
2991  if (simParams->langevinOn)
2993  else if (simParams->rescaleFreq > 0)
2995  for(int j = 0; j < adaptTempBins; ++j){
2996  adaptTempPotEnergyAveNum[j] = 0.;
2997  adaptTempPotEnergyAveDen[j] = 0.;
2999  adaptTempPotEnergyVarNum[j] = 0.;
3000  adaptTempPotEnergyVar[j] = 0.;
3001  adaptTempPotEnergyAve[j] = 0.;
3003  }
3004  }
3005  if (simParams->adaptTempAutoDt > 0.0) {
3006  adaptTempAutoDt = true;
3009  }
3010  adaptTempDTave = 0;
3011  adaptTempDTavenum = 0;
3012  iout << iINFO << "ADAPTIVE TEMPERING: TEMPERATURE RANGE: [" << 1./adaptTempBetaMax << "," << 1./adaptTempBetaMin << "] KELVIN\n";
3013  iout << iINFO << "ADAPTIVE TEMPERING: NUMBER OF BINS TO STORE POT. ENERGY: " << adaptTempBins << "\n";
3014  iout << iINFO << "ADAPTIVE TEMPERING: ADAPTIVE BIN AVERAGING PARAMETER: " << adaptTempCg << "\n";
3015  iout << iINFO << "ADAPTIVE TEMPERING: SCALING CONSTANT FOR LANGEVIN TEMPERATURE UPDATES: " << adaptTempDt << "\n";
3016  iout << iINFO << "ADAPTIVE TEMPERING: INITIAL TEMPERATURE: " << adaptTempT<< "\n";
3017  if (simParams->adaptTempRestartFreq > 0) {
3021  NAMD_die("Error opening restart file");
3022  }
3023 }
BigReal adaptTempBetaMin
Definition: Controller.h:431
BigReal adaptTempTmax
int adaptTempRestartFreq
BigReal * adaptTempBetaN
Definition: Controller.h:427
int adaptTempBins
Definition: Controller.h:434
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
BigReal adaptTempCgamma
BigReal adaptTempTmin
BigReal adaptTempT
Definition: Controller.h:428
BigReal adaptTempDt
Definition: Controller.h:437
char adaptTempInFile[NAMD_FILENAME_BUFFER_SIZE]
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal * adaptTempPotEnergyAveNum
Definition: Controller.h:421
#define iout
Definition: InfoStream.h:51
BigReal adaptTempDBeta
Definition: Controller.h:435
BigReal adaptTempDTavenum
Definition: Controller.h:430
BigReal adaptTempDTave
Definition: Controller.h:429
ofstream_namd adaptTempRestartFile
Definition: Controller.h:441
BigReal adaptTempDtMin
Definition: Controller.h:439
BigReal * adaptTempPotEnergyVar
Definition: Controller.h:425
BigReal rescaleTemp
BigReal adaptTempDtMax
Definition: Controller.h:440
char adaptTempRestartFile[NAMD_FILENAME_BUFFER_SIZE]
BigReal langevinTemp
Bool adaptTempAutoDt
Definition: Controller.h:438
void NAMD_die(const char *err_msg)
Definition: common.C:147
BigReal adaptTempDt
void NAMD_backup_file(const char *filename, const char *extension)
Definition: common.C:235
BigReal initialTemp
BigReal * adaptTempPotEnergyAveDen
Definition: Controller.h:422
BigReal * adaptTempPotEnergyVarNum
Definition: Controller.h:423
BigReal adaptTempCg
Definition: Controller.h:436
int * adaptTempPotEnergySamples
Definition: Controller.h:426
BigReal adaptTempBetaMax
Definition: Controller.h:432
SimParameters *const simParams
Definition: Controller.h:348
BigReal adaptTempAutoDt
BigReal * adaptTempPotEnergyAve
Definition: Controller.h:424
void open(const char *_fname, std::ios_base::openmode _mode=std::ios_base::out)
Definition: fstream_namd.C:11
double BigReal
Definition: common.h:123

◆ adaptTempUpdate()

void Controller::adaptTempUpdate ( int  step,
int  minimize = 0 
)
protected

Definition at line 3051 of file Controller.C.

References adaptTempAutoDt, adaptTempBetaMax, adaptTempBetaMin, adaptTempBetaN, adaptTempBin, adaptTempBins, adaptTempCg, adaptTempDBeta, SimParameters::adaptTempDebug, adaptTempDt, adaptTempDTave, adaptTempDTavenum, adaptTempDtMax, adaptTempDtMin, ControllerBroadcasts::adaptTemperature, SimParameters::adaptTempFreq, adaptTempInit(), SimParameters::adaptTempLastStep, SimParameters::adaptTempOn, SimParameters::adaptTempOutFreq, adaptTempPotEnergyAve, adaptTempPotEnergyAveDen, adaptTempPotEnergyAveNum, adaptTempPotEnergySamples, adaptTempPotEnergyVar, adaptTempPotEnergyVarNum, SimParameters::adaptTempRandom, adaptTempT, adaptTempWriteRestart(), BOLTZMANN, broadcast, endi(), SimParameters::firstTimestep, Random::gaussian(), iout, iWARN(), kineticEnergy, minimize(), SimpleBroadcastObject< T >::publish(), random, simParams, totalEnergy, and Random::uniform().

Referenced by integrate().

3052 {
3053  //Beta = 1./T
3054  if ( !simParams->adaptTempOn ) return;
3055  int j = 0;
3056  if (step == simParams->firstTimestep) {
3057  adaptTempInit(step);
3058  return;
3059  }
3060  if ( minimize || (step < simParams->adaptTempFirstStep ) ||
3061  ( simParams->adaptTempLastStep > 0 && step > simParams->adaptTempLastStep )) return;
3062  const int adaptTempOutFreq = simParams->adaptTempOutFreq;
3063  const bool adaptTempDebug = simParams->adaptTempDebug;
3064  //Calculate Current inverse temperature and bin
3065  BigReal adaptTempBeta = 1./adaptTempT;
3066  adaptTempBin = (int)floor((adaptTempBeta - adaptTempBetaMin)/adaptTempDBeta);
3067 
3068  if (adaptTempBin < 0 || adaptTempBin > adaptTempBins)
3069  iout << iWARN << " adaptTempBin out of range: adaptTempBin: " << adaptTempBin
3070  << " adaptTempBeta: " << adaptTempBeta
3071  << " adaptTempDBeta: " << adaptTempDBeta
3072  << " betaMin:" << adaptTempBetaMin
3073  << " betaMax: " << adaptTempBetaMax << "\n";
3076 
3077  BigReal potentialEnergy;
3078  BigReal potEnergyAverage;
3079  BigReal potEnergyVariance;
3080  potentialEnergy = totalEnergy-kineticEnergy;
3081 
3082  //calculate new bin average and variance using adaptive averaging
3085  adaptTempPotEnergyVarNum[adaptTempBin] = adaptTempPotEnergyVarNum[adaptTempBin]*gammaAve + potentialEnergy*potentialEnergy;
3086 
3089  potEnergyVariance -= potEnergyAverage*potEnergyAverage;
3090 
3091  adaptTempPotEnergyAve[adaptTempBin] = potEnergyAverage;
3092  adaptTempPotEnergyVar[adaptTempBin] = potEnergyVariance;
3093 
3094  // Weighted integral of <Delta E^2>_beta dbeta <= Eq 4 of JCP 132 244101
3095  // Integrals of Eqs 5 and 6 is done as piecewise assuming <Delta E^2>_beta
3096  // is constant for each bin. This is to estimate <E(beta)> where beta \in
3097  // (beta_i,beta_{i+1}) using Eq 2 of JCP 132 244101
3098  if ( ! ( step % simParams->adaptTempFreq ) ) {
3099  // If adaptTempBin not at the edge, calculate improved average:
3100  if (adaptTempBin > 0 && adaptTempBin < adaptTempBins-1) {
3101  // Get Averaging Limits:
3102  BigReal deltaBeta = 0.04*adaptTempBeta; //0.08 used in paper - make variable
3103  BigReal betaPlus;
3104  BigReal betaMinus;
3105  int nMinus =0;
3106  int nPlus = 0;
3107  if ( adaptTempBeta-adaptTempBetaMin < deltaBeta ) deltaBeta = adaptTempBeta-adaptTempBetaMin;
3108  if ( adaptTempBetaMax-adaptTempBeta < deltaBeta ) deltaBeta = adaptTempBetaMax-adaptTempBeta;
3109  betaMinus = adaptTempBeta - deltaBeta;
3110  betaPlus = adaptTempBeta + deltaBeta;
3111  BigReal betaMinus2 = betaMinus*betaMinus;
3112  BigReal betaPlus2 = betaPlus*betaPlus;
3113  nMinus = (int)floor((betaMinus-adaptTempBetaMin)/adaptTempDBeta);
3114  nPlus = (int)floor((betaPlus-adaptTempBetaMin)/adaptTempDBeta);
3115  // Variables for <E(beta)> estimate:
3116  BigReal potEnergyAve0 = 0.0;
3117  BigReal potEnergyAve1 = 0.0;
3118  // Integral terms
3119  BigReal A0 = 0;
3120  BigReal A1 = 0;
3121  BigReal A2 = 0;
3122  //A0 phi_s integral for beta_minus < beta < beta_{i+1}
3123  BigReal betaNp1 = adaptTempBetaN[adaptTempBin+1];
3124  BigReal DeltaE2Ave;
3125  BigReal DeltaE2AveSum = 0;
3126  BigReal betaj;
3127  for (j = nMinus+1; j <= adaptTempBin; ++j) {
3128  potEnergyAve0 += adaptTempPotEnergyAve[j];
3129  DeltaE2Ave = adaptTempPotEnergyVar[j];
3130  DeltaE2AveSum += DeltaE2Ave;
3131  A0 += j*DeltaE2Ave;
3132  }
3133  A0 *= adaptTempDBeta;
3134  A0 += (adaptTempBetaMin+0.5*adaptTempDBeta-betaMinus)*DeltaE2AveSum;
3135  A0 *= adaptTempDBeta;
3136  betaj = adaptTempBetaN[nMinus+1]-betaMinus;
3137  betaj *= betaj;
3138  A0 += 0.5*betaj*adaptTempPotEnergyVar[nMinus];
3139  A0 /= (betaNp1-betaMinus);
3140 
3141  //A1 phi_s integral for beta_{i+1} < beta < beta_plus
3142  DeltaE2AveSum = 0;
3143  for (j = adaptTempBin+1; j < nPlus; j++) {
3144  potEnergyAve1 += adaptTempPotEnergyAve[j];
3145  DeltaE2Ave = adaptTempPotEnergyVar[j];
3146  DeltaE2AveSum += DeltaE2Ave;
3147  A1 += j*DeltaE2Ave;
3148  }
3149  A1 *= adaptTempDBeta;
3150  A1 += (adaptTempBetaMin+0.5*adaptTempDBeta-betaPlus)*DeltaE2AveSum;
3151  A1 *= adaptTempDBeta;
3152  if ( nPlus < adaptTempBins ) {
3153  betaj = betaPlus-adaptTempBetaN[nPlus];
3154  betaj *= betaj;
3155  A1 -= 0.5*betaj*adaptTempPotEnergyVar[nPlus];
3156  }
3157  A1 /= (betaPlus-betaNp1);
3158 
3159  //A2 phi_t integral for beta_i
3160  A2 = 0.5*adaptTempDBeta*potEnergyVariance;
3161 
3162  // Now calculate a+ and a-
3163  DeltaE2Ave = A0-A1;
3164  BigReal aplus = 0;
3165  BigReal aminus = 0;
3166  if (DeltaE2Ave != 0) {
3167  aplus = (A0-A2)/(A0-A1);
3168  if (aplus < 0) {
3169  aplus = 0;
3170  }
3171  if (aplus > 1) {
3172  aplus = 1;
3173  }
3174  aminus = 1-aplus;
3175  potEnergyAve0 *= adaptTempDBeta;
3176  potEnergyAve0 += adaptTempPotEnergyAve[nMinus]*(adaptTempBetaN[nMinus+1]-betaMinus);
3177  potEnergyAve0 /= (betaNp1-betaMinus);
3178  potEnergyAve1 *= adaptTempDBeta;
3179  if ( nPlus < adaptTempBins ) {
3180  potEnergyAve1 += adaptTempPotEnergyAve[nPlus]*(betaPlus-adaptTempBetaN[nPlus]);
3181  }
3182  potEnergyAve1 /= (betaPlus-betaNp1);
3183  potEnergyAverage = aminus*potEnergyAve0;
3184  potEnergyAverage += aplus*potEnergyAve1;
3185  }
3186  if (simParams->adaptTempDebug) {
3187  iout << "ADAPTEMP DEBUG:" << "\n"
3188  << " adaptTempBin: " << adaptTempBin << "\n"
3189  << " Samples: " << adaptTempPotEnergySamples[adaptTempBin] << "\n"
3190  << " adaptTempBeta: " << adaptTempBeta << "\n"
3191  << " adaptTemp: " << adaptTempT<< "\n"
3192  << " betaMin: " << adaptTempBetaMin << "\n"
3193  << " betaMax: " << adaptTempBetaMax << "\n"
3194  << " gammaAve: " << gammaAve << "\n"
3195  << " deltaBeta: " << deltaBeta << "\n"
3196  << " betaMinus: " << betaMinus << "\n"
3197  << " betaPlus: " << betaPlus << "\n"
3198  << " nMinus: " << nMinus << "\n"
3199  << " nPlus: " << nPlus << "\n"
3200  << " A0: " << A0 << "\n"
3201  << " A1: " << A1 << "\n"
3202  << " A2: " << A2 << "\n"
3203  << " a+: " << aplus << "\n"
3204  << " a-: " << aminus << "\n"
3205  << endi;
3206  }
3207  }
3208  else {
3209  if (simParams->adaptTempDebug) {
3210  iout << "ADAPTEMP DEBUG:" << "\n"
3211  << " adaptTempBin: " << adaptTempBin << "\n"
3212  << " Samples: " << adaptTempPotEnergySamples[adaptTempBin] << "\n"
3213  << " adaptTempBeta: " << adaptTempBeta << "\n"
3214  << " adaptTemp: " << adaptTempT<< "\n"
3215  << " betaMin: " << adaptTempBetaMin << "\n"
3216  << " betaMax: " << adaptTempBetaMax << "\n"
3217  << " gammaAve: " << gammaAve << "\n"
3218  << " deltaBeta: N/A\n"
3219  << " betaMinus: N/A\n"
3220  << " betaPlus: N/A\n"
3221  << " nMinus: N/A\n"
3222  << " nPlus: N/A\n"
3223  << " A0: N/A\n"
3224  << " A1: N/A\n"
3225  << " A2: N/A\n"
3226  << " a+: N/A\n"
3227  << " a-: N/A\n"
3228  << endi;
3229  }
3230  }
3231 
3232  //dT is new temperature
3233  BigReal dT = ((potentialEnergy-potEnergyAverage)/BOLTZMANN+adaptTempT)*adaptTempDt;
3234  dT += random->gaussian()*sqrt(2.*adaptTempDt)*adaptTempT;
3235  dT += adaptTempT;
3236 
3237  // Check if dT in [adaptTempTmin,adaptTempTmax]. If not try simpler estimate of mean
3238  // This helps sampling with poor statistics in the bins surrounding adaptTempBin.
3239  if ( dT > 1./adaptTempBetaMin || dT < 1./adaptTempBetaMax ) {
3241  dT += random->gaussian()*sqrt(2.*adaptTempDt)*adaptTempT;
3242  dT += adaptTempT;
3243  // Check again, if not then keep original adaptTempTor assign random.
3244  if ( dT > 1./adaptTempBetaMin ) {
3245  if (!simParams->adaptTempRandom) {
3246  //iout << iWARN << "ADAPTEMP: " << step << " T= " << dT
3247  // << " K higher than adaptTempTmax."
3248  // << " Keeping temperature at "
3249  // << adaptTempT<< "\n"<< endi;
3250  dT = adaptTempT;
3251  }
3252  else {
3253  //iout << iWARN << "ADAPTEMP: " << step << " T= " << dT
3254  // << " K higher than adaptTempTmax."
3255  // << " Assigning random temperature in range\n" << endi;
3257  dT = 1./dT;
3258  }
3259  }
3260  else if ( dT < 1./adaptTempBetaMax ) {
3261  if (!simParams->adaptTempRandom) {
3262  //iout << iWARN << "ADAPTEMP: " << step << " T= "<< dT
3263  // << " K lower than adaptTempTmin."
3264  // << " Keeping temperature at " << adaptTempT<< "\n" << endi;
3265  dT = adaptTempT;
3266  }
3267  else {
3268  //iout << iWARN << "ADAPTEMP: " << step << " T= "<< dT
3269  // << " K lower than adaptTempTmin."
3270  // << " Assigning random temperature in range\n" << endi;
3272  dT = 1./dT;
3273  }
3274  }
3275  else if (adaptTempAutoDt) {
3276  //update temperature step size counter
3277  //FOR "TRUE" ADAPTIVE TEMPERING
3278  BigReal adaptTempTdiff = fabs(dT-adaptTempT);
3279  if (adaptTempTdiff > 0) {
3280  adaptTempDTave += adaptTempTdiff;
3282 // iout << "ADAPTEMP: adapTempTdiff = " << adaptTempTdiff << "\n";
3283  }
3284  if(adaptTempDTavenum == 100){
3285  BigReal Frac;
3287  Frac = 1./adaptTempBetaMin-1./adaptTempBetaMax;
3288  Frac = adaptTempDTave/Frac;
3289  //if average temperature jump is > 3% of temperature range,
3290  //modify jump size to match 3%
3291  iout << "ADAPTEMP: " << step << " FRAC " << Frac << "\n";
3292  if (Frac > adaptTempDtMax || Frac < adaptTempDtMin) {
3293  Frac = adaptTempDtMax/Frac;
3294  iout << "ADAPTEMP: Updating adaptTempDt to ";
3295  adaptTempDt *= Frac;
3296  iout << adaptTempDt << "\n" << endi;
3297  }
3298  adaptTempDTave = 0;
3299  adaptTempDTavenum = 0;
3300  }
3301  }
3302  }
3303  else if (adaptTempAutoDt) {
3304  //update temperature step size counter
3305  // FOR "TRUE" ADAPTIVE TEMPERING
3306  BigReal adaptTempTdiff = fabs(dT-adaptTempT);
3307  if (adaptTempTdiff > 0) {
3308  adaptTempDTave += adaptTempTdiff;
3310 // iout << "ADAPTEMP: adapTempTdiff = " << adaptTempTdiff << "\n";
3311  }
3312  if(adaptTempDTavenum == 100){
3313  BigReal Frac;
3315  Frac = 1./adaptTempBetaMin-1./adaptTempBetaMax;
3316  Frac = adaptTempDTave/Frac;
3317  //if average temperature jump is > 3% of temperature range,
3318  //modify jump size to match 3%
3319  iout << "ADAPTEMP: " << step << " FRAC " << Frac << "\n";
3320  if (Frac > adaptTempDtMax || Frac < adaptTempDtMin) {
3321  Frac = adaptTempDtMax/Frac;
3322  iout << "ADAPTEMP: Updating adaptTempDt to ";
3323  adaptTempDt *= Frac;
3324  iout << adaptTempDt << "\n" << endi;
3325  }
3326  adaptTempDTave = 0;
3327  adaptTempDTavenum = 0;
3328 
3329  }
3330 
3331  }
3332 
3333  adaptTempT = dT;
3335  }
3336  adaptTempWriteRestart(step);
3337  if ( ! (step % adaptTempOutFreq) ) {
3338  iout << "ADAPTEMP: STEP " << step
3339  << " TEMP " << adaptTempT
3340  << " ENERGY " << std::setprecision(10) << potentialEnergy
3341  << " ENERGYAVG " << std::setprecision(10) << potEnergyAverage
3342  << " ENERGYVAR " << std::setprecision(10) << potEnergyVariance;
3343  iout << "\n" << endi;
3344  }
3345 
3346 }
BigReal adaptTempBetaMin
Definition: Controller.h:431
BigReal * adaptTempBetaN
Definition: Controller.h:427
int adaptTempBins
Definition: Controller.h:434
BigReal uniform(void)
Definition: Random.h:109
#define BOLTZMANN
Definition: common.h:54
BigReal gaussian(void)
Definition: Random.h:116
BigReal adaptTempT
Definition: Controller.h:428
void adaptTempWriteRestart(int step)
Definition: Controller.C:3025
BigReal adaptTempDt
Definition: Controller.h:437
void adaptTempInit(int step)
Definition: Controller.C:2925
void minimize()
Definition: Controller.C:765
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
SimpleBroadcastObject< BigReal > adaptTemperature
Definition: Broadcasts.h:90
BigReal * adaptTempPotEnergyAveNum
Definition: Controller.h:421
#define iout
Definition: InfoStream.h:51
BigReal adaptTempDBeta
Definition: Controller.h:435
BigReal adaptTempDTavenum
Definition: Controller.h:430
BigReal adaptTempDTave
Definition: Controller.h:429
int adaptTempBin
Definition: Controller.h:433
BigReal adaptTempDtMin
Definition: Controller.h:439
ControllerBroadcasts * broadcast
Definition: Controller.h:365
BigReal * adaptTempPotEnergyVar
Definition: Controller.h:425
BigReal adaptTempDtMax
Definition: Controller.h:440
Bool adaptTempAutoDt
Definition: Controller.h:438
void publish(int tag, const T &t)
Random * random
Definition: Controller.h:347
BigReal * adaptTempPotEnergyAveDen
Definition: Controller.h:422
BigReal * adaptTempPotEnergyVarNum
Definition: Controller.h:423
BigReal adaptTempCg
Definition: Controller.h:436
int * adaptTempPotEnergySamples
Definition: Controller.h:426
BigReal totalEnergy
Definition: Controller.h:188
BigReal adaptTempBetaMax
Definition: Controller.h:432
SimParameters *const simParams
Definition: Controller.h:348
BigReal * adaptTempPotEnergyAve
Definition: Controller.h:424
BigReal kineticEnergy
Definition: Controller.h:243
double BigReal
Definition: common.h:123

◆ adaptTempWriteRestart()

void Controller::adaptTempWriteRestart ( int  step)
protected

Definition at line 3025 of file Controller.C.

References adaptTempBetaMax, adaptTempBetaMin, adaptTempBins, adaptTempCg, adaptTempDt, SimParameters::adaptTempOn, adaptTempPotEnergyAve, adaptTempPotEnergyAveDen, adaptTempPotEnergyAveNum, adaptTempPotEnergySamples, adaptTempPotEnergyVar, adaptTempPotEnergyVarNum, adaptTempRestartFile, SimParameters::adaptTempRestartFreq, adaptTempT, endi(), ofstream_namd::flush(), iout, and simParams.

Referenced by adaptTempUpdate().

3025  {
3027  adaptTempRestartFile.seekp(std::ios::beg);
3028  iout << "ADAPTEMP: WRITING RESTART FILE AT STEP " << step << "\n" << endi;
3029  adaptTempRestartFile << step << " ";
3030  // Start with min and max temperatures
3031  adaptTempRestartFile << adaptTempT<< " "; // KELVIN
3032  adaptTempRestartFile << 1./adaptTempBetaMin << " "; // KELVIN
3033  adaptTempRestartFile << 1./adaptTempBetaMax << " "; // KELVIN
3037  adaptTempRestartFile << "\n" ;
3038  for(int j = 0; j < adaptTempBins; ++j) {
3045  adaptTempRestartFile << "\n";
3046  }
3048  }
3049 }
BigReal adaptTempBetaMin
Definition: Controller.h:431
int adaptTempRestartFreq
int adaptTempBins
Definition: Controller.h:434
BigReal adaptTempT
Definition: Controller.h:428
BigReal adaptTempDt
Definition: Controller.h:437
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
ofstream_namd & flush()
Definition: fstream_namd.C:17
BigReal * adaptTempPotEnergyAveNum
Definition: Controller.h:421
#define iout
Definition: InfoStream.h:51
ofstream_namd adaptTempRestartFile
Definition: Controller.h:441
BigReal * adaptTempPotEnergyVar
Definition: Controller.h:425
BigReal * adaptTempPotEnergyAveDen
Definition: Controller.h:422
BigReal * adaptTempPotEnergyVarNum
Definition: Controller.h:423
BigReal adaptTempCg
Definition: Controller.h:436
int * adaptTempPotEnergySamples
Definition: Controller.h:426
BigReal adaptTempBetaMax
Definition: Controller.h:432
SimParameters *const simParams
Definition: Controller.h:348
BigReal * adaptTempPotEnergyAve
Definition: Controller.h:424

◆ algorithm()

void Controller::algorithm ( void  )
protectedvirtual

Definition at line 362 of file Controller.C.

References BackEnd::awaken(), broadcast, checkpoint_lattice, checkpoint_state, checkpoint_stored, checkpoints, END_OF_RUN, endi(), enqueueCollections(), EVAL_MEASURE, FILE_OUTPUT, SimParameters::firstTimestep, FORCE_OUTPUT, SimpleBroadcastObject< T >::get(), SimParameters::initialTemp, integrate(), iout, Controller::checkpoint::lattice, minimize(), NAMD_bug(), NAMD_die(), Node::Object(), outputExtendedSystem(), SCRIPT_ATOMRECV, SCRIPT_ATOMSEND, SCRIPT_ATOMSENDRECV, SCRIPT_CHECKPOINT, SCRIPT_CHECKPOINT_FREE, SCRIPT_CHECKPOINT_LOAD, SCRIPT_CHECKPOINT_STORE, SCRIPT_CHECKPOINT_SWAP, SCRIPT_CONTINUE, SCRIPT_END, SCRIPT_FORCEOUTPUT, SCRIPT_MEASURE, SCRIPT_MINIMIZE, SCRIPT_OUTPUT, SCRIPT_REINITVELS, SCRIPT_RESCALESOLUTECHARGES, SCRIPT_RESCALEVELS, SCRIPT_REVERT, SCRIPT_RUN, SimParameters::scriptArg1, ControllerBroadcasts::scriptBarrier, SimParameters::scriptIntArg1, SimParameters::scriptStringArg1, Node::sendCheckpointReq(), simParams, state, Controller::checkpoint::state, msm::swap(), and terminate().

363 {
364  int scriptTask;
365  int scriptSeq = 0;
366  BackEnd::awaken();
367  while ( (scriptTask = broadcast->scriptBarrier.get(scriptSeq++)) != SCRIPT_END) {
368 #ifdef NODEGROUP_FORCE_REGISTER
369  CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
370  PatchData *patchData = cpdata.ckLocalBranch();
371 #endif
372  switch ( scriptTask ) {
373  case SCRIPT_OUTPUT:
376  break;
377  case SCRIPT_FORCEOUTPUT:
379  break;
380  case SCRIPT_MEASURE:
382  break;
383  case SCRIPT_REINITVELS:
384  iout << "REINITIALIZING VELOCITIES AT STEP " << simParams->firstTimestep
385  << " TO " << simParams->initialTemp << " KELVIN.\n" << endi;
386  break;
387  case SCRIPT_RESCALEVELS:
388  iout << "RESCALING VELOCITIES AT STEP " << simParams->firstTimestep
389  << " BY " << simParams->scriptArg1 << "\n" << endi;
390  break;
392  // Parameter setting already reported in ScriptTcl
393  // Nothing to do!
394  break;
395  case SCRIPT_CHECKPOINT:
396  iout << "CHECKPOINTING AT STEP " << simParams->firstTimestep
397  << "\n" << endi;
398  checkpoint_stored = 1;
399  checkpoint_lattice = state->lattice;
401  break;
402  case SCRIPT_REVERT:
403  iout << "REVERTING AT STEP " << simParams->firstTimestep
404  << "\n" << endi;
405  if ( ! checkpoint_stored )
406  NAMD_die("Unable to revert, checkpoint was never called!");
407  state->lattice = checkpoint_lattice;
409  break;
411  iout << "STORING CHECKPOINT AT STEP " << simParams->firstTimestep
412  << " TO KEY " << simParams->scriptStringArg1;
413  if ( CmiNumPartitions() > 1 ) iout << " ON REPLICA " << simParams->scriptIntArg1;
414  iout << "\n" << endi;
415  if ( simParams->scriptIntArg1 == CmiMyPartition() ) {
416  if ( ! checkpoints.count(simParams->scriptStringArg1) ) {
417  checkpoints[simParams->scriptStringArg1] = new checkpoint;
418  }
419  checkpoint &cp = *checkpoints[simParams->scriptStringArg1];
420  cp.lattice = state->lattice;
421  cp.state = *(ControllerState*)this;
422  } else {
424  scriptTask, state->lattice, *(ControllerState*)this);
425  }
426  break;
428  iout << "LOADING CHECKPOINT AT STEP " << simParams->firstTimestep
429  << " FROM KEY " << simParams->scriptStringArg1;
430  if ( CmiNumPartitions() > 1 ) iout << " ON REPLICA " << simParams->scriptIntArg1;
431  iout << "\n" << endi;
432  if ( simParams->scriptIntArg1 == CmiMyPartition() ) {
433  if ( ! checkpoints.count(simParams->scriptStringArg1) ) {
434  NAMD_die("Unable to load checkpoint, requested key was never stored.");
435  }
436  checkpoint &cp = *checkpoints[simParams->scriptStringArg1];
437  state->lattice = cp.lattice;
438  *(ControllerState*)this = cp.state;
439  } else {
441  scriptTask, state->lattice, *(ControllerState*)this);
442  }
443  break;
445  iout << "SWAPPING CHECKPOINT AT STEP " << simParams->firstTimestep
446  << " FROM KEY " << simParams->scriptStringArg1;
447  if ( CmiNumPartitions() > 1 ) iout << " ON REPLICA " << simParams->scriptIntArg1;
448  iout << "\n" << endi;
449  if ( simParams->scriptIntArg1 == CmiMyPartition() ) {
450  if ( ! checkpoints.count(simParams->scriptStringArg1) ) {
451  NAMD_die("Unable to swap checkpoint, requested key was never stored.");
452  }
453  checkpoint &cp = *checkpoints[simParams->scriptStringArg1];
454  std::swap(state->lattice,cp.lattice);
455  std::swap(*(ControllerState*)this,cp.state);
456  } else {
458  scriptTask, state->lattice, *(ControllerState*)this);
459  }
460  break;
462  iout << "FREEING CHECKPOINT AT STEP " << simParams->firstTimestep
463  << " FROM KEY " << simParams->scriptStringArg1;
464  if ( CmiNumPartitions() > 1 ) iout << " ON REPLICA " << simParams->scriptIntArg1;
465  iout << "\n" << endi;
466  if ( simParams->scriptIntArg1 == CmiMyPartition() ) {
467  if ( ! checkpoints.count(simParams->scriptStringArg1) ) {
468  NAMD_die("Unable to free checkpoint, requested key was never stored.");
469  }
472  } else {
474  scriptTask, state->lattice, *(ControllerState*)this);
475  }
476  break;
477  case SCRIPT_ATOMSENDRECV:
478  case SCRIPT_ATOMSEND:
479  case SCRIPT_ATOMRECV:
480  break;
481  case SCRIPT_MINIMIZE:
482  minimize();
483  break;
484  case SCRIPT_RUN:
485  case SCRIPT_CONTINUE:
486  integrate(scriptTask);
487  break;
488  default:
489  NAMD_bug("Unknown task in Controller::algorithm");
490  }
491  BackEnd::awaken();
492  }
495  terminate();
496 }
static Node * Object()
Definition: Node.h:86
int checkpoint_stored
Definition: Controller.h:382
void enqueueCollections(int)
Definition: Controller.C:4674
char scriptStringArg1[128]
static void awaken(void)
Definition: BackEnd.C:316
std::map< std::string, checkpoint * > checkpoints
Definition: Controller.h:390
#define FILE_OUTPUT
Definition: Output.h:25
void minimize()
Definition: Controller.C:765
#define EVAL_MEASURE
Definition: Output.h:27
void integrate(int)
Definition: Controller.C:514
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
void swap(Array< T > &s, Array< T > &t)
Definition: MsmMap.h:319
NamdState *const state
Definition: Controller.h:349
Lattice checkpoint_lattice
Definition: Controller.h:383
ControllerState checkpoint_state
Definition: Controller.h:384
ControllerBroadcasts * broadcast
Definition: Controller.h:365
void NAMD_bug(const char *err_msg)
Definition: common.C:195
SimpleBroadcastObject< int > scriptBarrier
Definition: Broadcasts.h:87
BigReal scriptArg1
#define END_OF_RUN
Definition: Output.h:26
void NAMD_die(const char *err_msg)
Definition: common.C:147
void terminate(void)
Definition: Controller.C:5252
BigReal initialTemp
SimParameters *const simParams
Definition: Controller.h:348
void sendCheckpointReq(int remote, const char *key, int task, Lattice &lat, ControllerState &cs)
Definition: Node.C:1319
void outputExtendedSystem(int step)
Definition: Controller.C:5042
#define FORCE_OUTPUT
Definition: Output.h:28

◆ awaken()

void Controller::awaken ( void  )

Definition at line 354 of file Controller.C.

References Controller::CthThreadWrapper::thread.

Referenced by LdbCoordinator::awakenSequencers(), resumeAfterTraceBarrier(), and run().

354  {
355  CthAwaken(threadWrapper->thread);
356 }

◆ berendsenPressure()

void Controller::berendsenPressure ( int  step)
protected

Definition at line 1357 of file Controller.C.

References ControllerState::berendsenPressure_avg, ControllerState::berendsenPressure_count, SimParameters::berendsenPressureCompressibility, SimParameters::berendsenPressureFreq, SimParameters::berendsenPressureOn, SimParameters::berendsenPressureRelaxationTime, SimParameters::berendsenPressureTarget, broadcast, controlPressure, Tensor::diagonal(), SimParameters::dt, endi(), Tensor::identity(), iERROR(), iout, LIMIT_SCALING, ControllerBroadcasts::positionRescaleFactor, SimpleBroadcastObject< T >::publish(), Lattice::rescale(), simParams, state, Tensor::xx, Tensor::yy, and Tensor::zz.

Referenced by integrate().

1358 {
1359  if ( simParams->berendsenPressureOn ) {
1362  const int freq = simParams->berendsenPressureFreq;
1363  if ( ! (berendsenPressure_count % freq) ) {
1367  // We only use on-diagonal terms (for now)
1368  factor = Tensor::diagonal(diagonal(factor));
1370  factor *= ( ( simParams->berendsenPressureCompressibility / 3.0 ) *
1372  factor += Tensor::identity(1.0);
1373  int limited = 0;
1374  LIMIT_SCALING(factor.xx,1./1.03,1.03,limited)
1375  LIMIT_SCALING(factor.yy,1./1.03,1.03,limited)
1376  LIMIT_SCALING(factor.zz,1./1.03,1.03,limited)
1377  if ( limited ) {
1378  iout << iERROR << "Step " << step <<
1379  " cell rescaling factor limited.\n" << endi;
1380  }
1381  broadcast->positionRescaleFactor.publish(step,factor);
1382  state->lattice.rescale(factor);
1383 #ifdef NODEGROUP_FORCE_REGISTER
1384  publishedRescaleFactors.insert({step, factor});
1385 #endif
1386  }
1387  } else {
1390  }
1391 }
BigReal berendsenPressureCompressibility
NAMD_HOST_DEVICE void rescale(Tensor factor)
Definition: Lattice.h:60
Bool berendsenPressureOn
BigReal berendsenPressureRelaxationTime
Tensor controlPressure
Definition: Controller.h:255
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
int berendsenPressureFreq
#define iout
Definition: InfoStream.h:51
static NAMD_HOST_DEVICE Tensor identity(BigReal v1=1.0)
Definition: Tensor.h:31
NamdState *const state
Definition: Controller.h:349
BigReal berendsenPressureTarget
ControllerBroadcasts * broadcast
Definition: Controller.h:365
static NAMD_HOST_DEVICE Tensor diagonal(const Vector &v1)
Definition: Tensor.h:37
int berendsenPressure_count
Definition: Controller.h:102
void publish(int tag, const T &t)
BigReal xx
Definition: Tensor.h:17
SimpleBroadcastObject< Tensor > positionRescaleFactor
Definition: Broadcasts.h:71
BigReal zz
Definition: Tensor.h:19
Definition: Tensor.h:15
BigReal yy
Definition: Tensor.h:18
#define LIMIT_SCALING(VAR, MIN, MAX, FLAG)
Definition: Controller.C:1353
SimParameters *const simParams
Definition: Controller.h:348
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
Tensor berendsenPressure_avg
Definition: Controller.h:97

◆ calc_accelMDG_E_k()

void Controller::calc_accelMDG_E_k ( int  iE,
int  V_n,
BigReal  sigma0,
BigReal  Vmax,
BigReal  Vmin,
BigReal  Vavg,
BigReal  sigmaV,
BigReal k0,
BigReal k,
BigReal E,
int *  iEused,
char *  warn 
)
inlineprotected

Definition at line 2310 of file Controller.C.

Referenced by rescaleaccelMD().

2311  {
2312  switch(iE){
2313  case 2:
2314  *k0 = (1-sigma0/sigmaV) * (Vmax-Vmin) / (Vavg-Vmin);
2315  // if k0 <=0 OR k0 > 1, switch to iE=1 mode
2316  if(*k0 > 1.)
2317  *warn |= 1;
2318  else if(*k0 <= 0.)
2319  *warn |= 2;
2320  //else stay in iE=2 mode
2321  else{
2322  *E = Vmin + (Vmax-Vmin)/(*k0);
2323  *iEused = 2;
2324  break;
2325  }
2326  case 1:
2327  *E = Vmax;
2328  *k0 = (sigma0 / sigmaV) * (Vmax-Vmin) / (Vmax-Vavg);
2329  if(*k0 > 1.)
2330  *k0 = 1.;
2331  *iEused = 1;
2332  break;
2333  }
2334 
2335  *k = *k0 / (Vmax - Vmin);
2336 }

◆ calc_accelMDG_force_factor()

void Controller::calc_accelMDG_force_factor ( BigReal  k,
BigReal  E,
BigReal  testV,
Tensor  vir_orig,
BigReal dV,
BigReal factor,
Tensor vir 
)
inlineprotected

Definition at line 2339 of file Controller.C.

Referenced by rescaleaccelMD().

2340  {
2341  BigReal VE = testV - E;
2342  //if V < E, apply boost
2343  if(VE < 0){
2344  *factor = k * VE;
2345  *vir += vir_orig * (*factor);
2346  *dV += (*factor) * VE/2.;
2347  *factor += 1.;
2348  }
2349  else{
2350  *factor = 1.;
2351  }
2352 }
double BigReal
Definition: common.h:123

◆ calc_accelMDG_mean_std()

void Controller::calc_accelMDG_mean_std ( BigReal  testV,
int  step_n,
BigReal Vmax,
BigReal Vmin,
BigReal Vavg,
BigReal M2,
BigReal sigmaV 
)
inlineprotected

Definition at line 2290 of file Controller.C.

Referenced by rescaleaccelMD().

2291  {
2292  BigReal delta;
2293 
2294  if(testV > *Vmax){
2295  *Vmax = testV;
2296  }
2297  else if(testV < *Vmin){
2298  *Vmin = testV;
2299  }
2300 
2301  //mean and std calculated by Online Algorithm
2302  delta = testV - *Vavg;
2303  *Vavg += delta / (BigReal)n;
2304  *M2 += delta * (testV - (*Vavg));
2305 
2306  *sigmaV = sqrt(*M2/n);
2307 }
double BigReal
Definition: common.h:123

◆ calcPressure()

void Controller::calcPressure ( int  step,
int  minimize,
const Tensor virial_normal_in,
const Tensor virial_nbond_in,
const Tensor virial_slow_in,
const Tensor intVirial_normal,
const Tensor intVirial_nbond,
const Tensor intVirial_slow,
const Vector extForce_normal,
const Vector extForce_nbond,
const Vector extForce_slow 
)
protected

Definition at line 2102 of file Controller.C.

References Lattice::a(), SimParameters::accelMDOn, AVGXY, Lattice::b(), Lattice::c(), controlPressure, controlPressure_nbond, controlPressure_normal, controlPressure_slow, SimParameters::CUDASOAintegrate, Tensor::diagonal(), SimParameters::getCurrentLambda(), Molecule::getVirialTailCorr(), groupPressure, groupPressure_nbond, groupPressure_normal, groupPressure_slow, Tensor::identity(), SimParameters::isMultiTimeStepping(), SimParameters::LJcorrection, SimParameters::LJcorrectionAlt, minimize(), NAMD_bug(), nbondFreq, Node::Object(), Lattice::origin(), outer(), pressure, pressure_amd, pressure_nbond, pressure_normal, pressure_slow, simParams, slowFreq, state, SimParameters::useConstantRatio, SimParameters::useFlexibleCell, SimParameters::useGroupPressure, virial_amd, Lattice::volume(), Vector::x, Tensor::xx, Tensor::xy, Tensor::xz, Vector::y, Tensor::yx, Tensor::yy, Tensor::yz, Vector::z, Tensor::zx, Tensor::zy, and Tensor::zz.

Referenced by multigratorPressure(), and receivePressure().

2105  {
2106 
2107  Tensor virial_normal = virial_normal_in;
2108  Tensor virial_nbond = virial_nbond_in;
2109  Tensor virial_slow = virial_slow_in;
2110 
2111 #if 0
2112  Tensor tmp = virial_normal;
2113  fprintf(stderr, "VIRIAL_NORMAL %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf\n",
2114  tmp.xx, tmp.xy, tmp.xz, tmp.yx, tmp.yy, tmp.yz, tmp.zx, tmp.zy, tmp.zz);
2115 
2116  tmp = virial_nbond;
2117  fprintf(stderr, "VIRIAL_NBOND %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf\n",
2118  tmp.xx, tmp.xy, tmp.xz, tmp.yx, tmp.yy, tmp.yz, tmp.zx, tmp.zy, tmp.zz);
2119 
2120  tmp = virial_slow;
2121  fprintf(stderr, "VIRIAL_SLOW %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf\n",
2122  tmp.xx, tmp.xy, tmp.xz, tmp.yx, tmp.yy, tmp.yz, tmp.zx, tmp.zy, tmp.zz);
2123 
2124  tmp = intVirial_normal;
2125  fprintf(stderr, "INT_VIRIAL_NORMAL %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf\n",
2126  tmp.xx, tmp.xy, tmp.xz, tmp.yx, tmp.yy, tmp.yz, tmp.zx, tmp.zy, tmp.zz);
2127 
2128  tmp = intVirial_nbond;
2129  fprintf(stderr, "INT_VIRIAL_NBOND %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf\n",
2130  tmp.xx, tmp.xy, tmp.xz, tmp.yx, tmp.yy, tmp.yz, tmp.zx, tmp.zy, tmp.zz);
2131 
2132  tmp = intVirial_slow;
2133  fprintf(stderr, "INT_VIRIAL_SLOW %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf %1.2lf\n",
2134  tmp.xx, tmp.xy, tmp.xz, tmp.yx, tmp.yy, tmp.yz, tmp.zx, tmp.zy, tmp.zz);
2135 
2136  Vector ext = extForce_normal;
2137  fprintf(stderr, "EXT_FORCE_NORMAL %1.2lf %1.2lf %1.2lf\n",
2138  ext.x, ext.y, ext.z);
2139 
2140  ext = extForce_nbond;
2141  fprintf(stderr, "EXT_FORCE_NBOND %1.2lf %1.2lf %1.2lf\n",
2142  ext.x, ext.y, ext.z);
2143 
2144  ext = extForce_slow;
2145  fprintf(stderr, "EXT_FORCE_SLOW %1.2lf %1.2lf %1.2lf\n",
2146  ext.x, ext.y, ext.z);
2147 
2148  //fprintf(stderr, "State Lattice for timestep %d\n", step);
2149  fprintf(stderr, "LATTICE %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
2150  state->lattice.a().x, state->lattice.a().y, state->lattice.a().z,
2151  state->lattice.b().x, state->lattice.b().y, state->lattice.b().z,
2152  state->lattice.c().x, state->lattice.c().y, state->lattice.c().z);
2153 
2154  fprintf(stderr, "VOLUME %3.10lf\n", state->lattice.volume());
2155 
2156 #endif
2157 
2158 
2159  Node *node = Node::Object();
2160  Molecule *molecule = node->molecule;
2161  Lattice &lattice = state->lattice;
2162  BigReal volume;
2163 
2164  Vector extPosition = lattice.origin();
2165  virial_normal -= outer(extForce_normal,extPosition);
2166  virial_nbond -= outer(extForce_nbond,extPosition);
2167  virial_slow -= outer(extForce_slow,extPosition);
2168 
2169  if ( (volume=lattice.volume()) != 0. )
2170  {
2171 
2172  if ((simParams->LJcorrection || simParams->LJcorrectionAlt) && volume) {
2173 #ifdef MEM_OPT_VERSION
2174  NAMD_bug("LJcorrection not supported in memory optimized build.");
2175 #else
2176  // Apply tail correction to pressure
2177  BigReal alchLambda = simParams->getCurrentLambda(step);
2178  virial_normal += Tensor::identity(molecule->getVirialTailCorr(alchLambda) / volume);
2179 #endif
2180  }
2181 
2182 
2183  // kinetic energy component included in virials
2184  if(simParams->CUDASOAintegrate && step != 0 && !simParams->isMultiTimeStepping()){
2185  pressure_normal = virial_normal / volume;
2186  // groupPressure_normal = ( virial_normal - intVirial_normal ) / volume;
2187  if (simParams->accelMDOn) {
2188  pressure_amd = virial_amd / volume;
2191  }
2192 
2193  if ( minimize || ! ( step % nbondFreq ) )
2194  {
2195  pressure_nbond = virial_nbond / volume;
2196  // groupPressure_nbond = ( virial_nbond - intVirial_nbond ) / volume;
2197  }
2198 
2199  if ( minimize || ! ( step % slowFreq ) )
2200  {
2201  pressure_slow = virial_slow / volume;
2202  // groupPressure_slow = ( virial_slow - intVirial_slow ) / volume;
2203  }
2204 
2206  groupPressure = pressure - intVirial_normal / volume;
2207  // groupPressure = groupPressure_normal + groupPressure_nbond +
2208  // groupPressure_slow;
2209  }else{
2210  pressure_normal = virial_normal / volume;
2211 
2212  groupPressure_normal = ( virial_normal - intVirial_normal ) / volume;
2213  if (simParams->accelMDOn) {
2214  pressure_amd = virial_amd / volume;
2217  }
2218 
2219  if ( minimize || ! ( step % nbondFreq ) )
2220  {
2221  pressure_nbond = virial_nbond / volume;
2222  groupPressure_nbond = ( virial_nbond - intVirial_nbond ) / volume;
2223  }
2224 
2225  if ( minimize || ! ( step % slowFreq ) )
2226  {
2227  pressure_slow = virial_slow / volume;
2228  groupPressure_slow = ( virial_slow - intVirial_slow ) / volume;
2229  }
2230 
2234  }
2235  }
2236  else
2237  {
2238  pressure = Tensor();
2239  groupPressure = Tensor();
2240  }
2241 
2242  if ( simParams->useGroupPressure )
2243  {
2248  }
2249  else
2250  {
2255  }
2256 
2257  if ( simParams->useFlexibleCell ) {
2258  // use symmetric pressure to control rotation
2259  // controlPressure_normal = symmetric(controlPressure_normal);
2260  // controlPressure_nbond = symmetric(controlPressure_nbond);
2261  // controlPressure_slow = symmetric(controlPressure_slow);
2262  // controlPressure = symmetric(controlPressure);
2263  // only use on-diagonal components for now
2268  if ( simParams->useConstantRatio ) {
2269 #define AVGXY(T) T.xy = T.yx = 0; T.xx = T.yy = 0.5 * ( T.xx + T.yy );\
2270  T.xz = T.zx = T.yz = T.zy = 0.5 * ( T.xz + T.yz );
2275 #undef AVGXY
2276  }
2277  } else {
2284  controlPressure =
2285  Tensor::identity(trace(controlPressure)/3.);
2286  }
2287 }
static Node * Object()
Definition: Node.h:86
#define AVGXY(T)
BigReal zy
Definition: Tensor.h:19
Tensor controlPressure_slow
Definition: Controller.h:161
int nbondFreq
Definition: Controller.h:162
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
BigReal xz
Definition: Tensor.h:17
Tensor groupPressure_nbond
Definition: Controller.h:157
Definition: Node.h:78
Tensor controlPressure
Definition: Controller.h:255
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
void minimize()
Definition: Controller.C:765
Definition: Vector.h:72
BigReal z
Definition: Vector.h:74
BigReal yz
Definition: Tensor.h:18
Tensor pressure_amd
Definition: Controller.h:154
Molecule stores the structural information for the system.
Definition: Molecule.h:175
static NAMD_HOST_DEVICE Tensor identity(BigReal v1=1.0)
Definition: Tensor.h:31
Tensor pressure_slow
Definition: Controller.h:153
NamdState *const state
Definition: Controller.h:349
Tensor pressure
Definition: Controller.h:252
Tensor groupPressure_slow
Definition: Controller.h:158
void NAMD_bug(const char *err_msg)
Definition: common.C:195
bool isMultiTimeStepping()
BigReal yx
Definition: Tensor.h:18
static NAMD_HOST_DEVICE Tensor diagonal(const Vector &v1)
Definition: Tensor.h:37
BigReal x
Definition: Vector.h:74
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
Tensor groupPressure_normal
Definition: Controller.h:156
BigReal getVirialTailCorr(const BigReal)
Tensor virial_amd
Definition: Controller.h:155
NAMD_HOST_DEVICE Vector b() const
Definition: Lattice.h:269
BigReal xx
Definition: Tensor.h:17
BigReal zz
Definition: Tensor.h:19
BigReal getCurrentLambda(const int) const
Definition: Tensor.h:15
BigReal xy
Definition: Tensor.h:17
Tensor pressure_normal
Definition: Controller.h:151
BigReal y
Definition: Vector.h:74
Tensor groupPressure
Definition: Controller.h:253
int slowFreq
Definition: Controller.h:163
BigReal yy
Definition: Tensor.h:18
SimParameters *const simParams
Definition: Controller.h:348
Tensor controlPressure_normal
Definition: Controller.h:159
NAMD_HOST_DEVICE Vector a() const
Definition: Lattice.h:268
BigReal zx
Definition: Tensor.h:19
NAMD_HOST_DEVICE Vector origin() const
Definition: Lattice.h:278
Tensor pressure_nbond
Definition: Controller.h:152
Tensor controlPressure_nbond
Definition: Controller.h:160
double BigReal
Definition: common.h:123

◆ compareChecksums()

void Controller::compareChecksums ( int  step,
int  forgiving = 0 
)
protected

Definition at line 3349 of file Controller.C.

References computeChecksum, SimParameters::CUDASOAintegrate, endi(), SimParameters::fullElectFrequency, SimParameters::goGroPair, iERROR(), iINFO(), iout, RequireReduction::item(), NodeReduction::item(), iWARN(), marginViolations, Node::molecule, SimParameters::mollyOn, NAMD_bug(), nodeReduction, Molecule::numAtoms, Molecule::numCalcAngles, Molecule::numCalcAnisos, Molecule::numCalcBonds, Molecule::numCalcCrossterms, Molecule::numCalcDihedrals, Molecule::numCalcExclusions, Molecule::numCalcFullExclusions, Molecule::numCalcImpropers, Molecule::numCalcTholes, Node::Object(), SimParameters::outputPairlists, pairlistWarnings, SimParameters::qmForcesOn, reduction, REDUCTION_ANGLE_CHECKSUM, REDUCTION_ANISO_CHECKSUM, REDUCTION_ATOM_CHECKSUM, REDUCTION_BOND_CHECKSUM, REDUCTION_COMPUTE_CHECKSUM, REDUCTION_CROSSTERM_CHECKSUM, REDUCTION_DIHEDRAL_CHECKSUM, REDUCTION_EXCLUSION_CHECKSUM, REDUCTION_EXCLUSION_CHECKSUM_CUDA, REDUCTION_IMPROPER_CHECKSUM, REDUCTION_MARGIN_VIOLATIONS, REDUCTION_PAIRLIST_WARNINGS, REDUCTION_STRAY_CHARGE_ERRORS, REDUCTION_THOLE_CHECKSUM, simParams, and slowFreq.

Referenced by getTotalPotentialEnergy(), printDynamicsEnergies(), and printMinimizeEnergies().

3349  {
3350  Node *node = Node::Object();
3351  Molecule *molecule = node->molecule;
3352  bool cudaIntegrator = simParams->CUDASOAintegrate;
3353 
3354  // Some basic correctness checking
3355  BigReal checksum, checksum_b;
3356  char errmsg[256];
3357 
3358 #ifdef NODEGROUP_FORCE_REGISTER
3359  if(cudaIntegrator)
3361  else{
3362 #endif
3363  checksum = reduction->item(REDUCTION_ATOM_CHECKSUM);
3364 #ifdef NODEGROUP_FORCE_REGISTER
3365  }
3366 #endif
3367  if ( ((int)checksum) != molecule->numAtoms && step != 0) {
3368  sprintf(errmsg, "Bad global atom count! (%d vs %d)\n",
3369  (int)checksum, molecule->numAtoms);
3370  NAMD_bug(errmsg);
3371  }
3372  // do we ever need this if we're on a GPU-based code?
3373 #ifdef NODEGROUP_FORCE_REGISTER
3374  if(cudaIntegrator) checksum = computeChecksum; //checksum = nodeReduction->item(REDUCTION_COMPUTE_CHECKSUM);
3375  else {
3376 #endif
3378 #ifdef NODEGROUP_FORCE_REGISTER
3379  }
3380 #endif
3381 
3382  if ( ((int)checksum) && ((int)checksum) != computeChecksum ) {
3383  if ( ! computeChecksum ) {
3384  computesPartitioned = 0;
3385  } else if ( (int)checksum > computeChecksum && ! computesPartitioned ) {
3386  computesPartitioned = 1;
3387  } else {
3388  NAMD_bug("Bad global compute count!\n");
3389  }
3390  computeChecksum = ((int)checksum);
3391  }
3392 #ifdef NODEGROUP_FORCE_REGISTER
3393  if(cudaIntegrator)checksum_b = checksum = nodeReduction->item(REDUCTION_BOND_CHECKSUM);
3394  else{
3395 #endif
3396  checksum_b = checksum = reduction->item(REDUCTION_BOND_CHECKSUM);
3397 #ifdef NODEGROUP_FORCE_REGISTER
3398  }
3399 #endif
3400  if ( checksum_b && (((int)checksum) != molecule->numCalcBonds) ) {
3401  sprintf(errmsg, "Bad global bond count! (%d vs %d)\n",
3402  (int)checksum, molecule->numCalcBonds);
3403  if ( forgiving && (((int)checksum) < molecule->numCalcBonds) )
3404  iout << iWARN << errmsg << endi;
3405  else NAMD_bug(errmsg);
3406  }
3407 
3408 #ifdef NODEGROUP_FORCE_REGISTER
3409  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_ANGLE_CHECKSUM);
3410 
3411  else{
3412 #endif
3414 
3415 #ifdef NODEGROUP_FORCE_REGISTER
3416  }
3417 #endif
3418  if ( checksum_b && (((int)checksum) != molecule->numCalcAngles) ) {
3419  sprintf(errmsg, "Bad global angle count! (%d vs %d)\n",
3420  (int)checksum, molecule->numCalcAngles);
3421  if ( forgiving && (((int)checksum) < molecule->numCalcAngles) )
3422  iout << iWARN << errmsg << endi;
3423  else NAMD_bug(errmsg);
3424  }
3425 #ifdef NODEGROUP_FORCE_REGISTER
3426  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_DIHEDRAL_CHECKSUM);
3427  else {
3428 #endif
3430 #ifdef NODEGROUP_FORCE_REGISTER
3431  }
3432 #endif
3433  if ( checksum_b && (((int)checksum) != molecule->numCalcDihedrals) ) {
3434  sprintf(errmsg, "Bad global dihedral count! (%d vs %d)\n",
3435  (int)checksum, molecule->numCalcDihedrals);
3436  if ( forgiving && (((int)checksum) < molecule->numCalcDihedrals) )
3437  iout << iWARN << errmsg << endi;
3438  else NAMD_bug(errmsg);
3439  }
3440 
3441 #ifdef NODEGROUP_FORCE_REGISTER
3442  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_IMPROPER_CHECKSUM);
3443  else {
3444 #endif
3446 #ifdef NODEGROUP_FORCE_REGISTER
3447  }
3448 #endif
3449  if ( checksum_b && (((int)checksum) != molecule->numCalcImpropers) ) {
3450  sprintf(errmsg, "Bad global improper count! (%d vs %d)\n",
3451  (int)checksum, molecule->numCalcImpropers);
3452  if ( forgiving && (((int)checksum) < molecule->numCalcImpropers) )
3453  iout << iWARN << errmsg << endi;
3454  else NAMD_bug(errmsg);
3455  }
3456 
3457 #ifdef NODEGROUP_FORCE_REGISTER
3458  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_THOLE_CHECKSUM);
3459  else{
3460 #endif
3462 #ifdef NODEGROUP_FORCE_REGISTER
3463  }
3464 #endif
3465  if ( checksum_b && (((int)checksum) != molecule->numCalcTholes) ) {
3466  sprintf(errmsg, "Bad global Thole count! (%d vs %d)\n",
3467  (int)checksum, molecule->numCalcTholes);
3468  if ( forgiving && (((int)checksum) < molecule->numCalcTholes) )
3469  iout << iWARN << errmsg << endi;
3470  else NAMD_bug(errmsg);
3471  }
3472 
3473 #ifdef NODEGROUP_FORCE_REGISTER
3474  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_ANISO_CHECKSUM);
3475  else {
3476 #endif
3478 #ifdef NODEGROUP_FORCE_REGISTER
3479  }
3480 #endif
3481  if ( checksum_b && (((int)checksum) != molecule->numCalcAnisos) ) {
3482  sprintf(errmsg, "Bad global Aniso count! (%d vs %d)\n",
3483  (int)checksum, molecule->numCalcAnisos);
3484  if ( forgiving && (((int)checksum) < molecule->numCalcAnisos) )
3485  iout << iWARN << errmsg << endi;
3486  else NAMD_bug(errmsg);
3487  }
3488 
3489 #ifdef NODEGROUP_FORCE_REGISTER
3490  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_CROSSTERM_CHECKSUM);
3491  else{
3492 #endif
3494 #ifdef NODEGROUP_FORCE_REGISTER
3495  }
3496 #endif
3497  if ( checksum_b && (((int)checksum) != molecule->numCalcCrossterms) ) {
3498  sprintf(errmsg, "Bad global crossterm count! (%d vs %d)\n",
3499  (int)checksum, molecule->numCalcCrossterms);
3500  if ( forgiving && (((int)checksum) < molecule->numCalcCrossterms) )
3501  iout << iWARN << errmsg << endi;
3502  else NAMD_bug(errmsg);
3503  }
3504 
3505 #ifdef NODEGROUP_FORCE_REGISTER
3506  if(cudaIntegrator )checksum = nodeReduction->item(REDUCTION_EXCLUSION_CHECKSUM);
3507  else{
3508 #endif
3510 #ifdef NODEGROUP_FORCE_REGISTER
3511  }
3512 #endif
3513  if ( ((int64)checksum) > molecule->numCalcExclusions &&
3514  ( ! simParams->mollyOn || step % slowFreq ) ) {
3515  if ( forgiving )
3516  iout << iWARN << "High global exclusion count ("
3517  << ((int64)checksum) << " vs "
3518  << molecule->numCalcExclusions << "), possible error!\n"
3519  << iWARN << "This warning is not unusual during minimization.\n"
3520  << iWARN << "Decreasing pairlistdist or cutoff that is too close to periodic cell size may avoid this.\n" << endi;
3521  else {
3522  char errmsg[256];
3523  sprintf(errmsg, "High global exclusion count! (%lld vs %lld) System unstable or pairlistdist or cutoff too close to periodic cell size.\n",
3524  (long long)checksum, (long long)molecule->numCalcExclusions);
3525  NAMD_bug(errmsg);
3526  }
3527  }
3528 
3529  if ( ((int64)checksum) && ((int64)checksum) < molecule->numCalcExclusions &&
3531  if ( forgiving || ! simParams->fullElectFrequency ) {
3532  iout << iWARN << "Low global exclusion count! ("
3533  << ((int64)checksum) << " vs " << molecule->numCalcExclusions << ")";
3534  if ( forgiving ) {
3535  iout << "\n"
3536  << iWARN << "This warning is not unusual during minimization.\n"
3537  << iWARN << "Increasing pairlistdist or cutoff may avoid this.\n";
3538  } else {
3539  iout << " System unstable or pairlistdist or cutoff too small.\n";
3540  }
3541  iout << endi;
3542  } else {
3543  char errmsg[256];
3544  sprintf(errmsg, "Low global exclusion count! (%lld vs %lld) System unstable or pairlistdist or cutoff too small.\n",
3545  (long long)checksum, (long long)molecule->numCalcExclusions);
3546  NAMD_bug(errmsg);
3547  }
3548  }
3549 
3550 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
3551 #ifdef NODEGROUP_FORCE_REGISTER
3552  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_EXCLUSION_CHECKSUM_CUDA);
3553  else{
3554 #endif
3556 #ifdef NODEGROUP_FORCE_REGISTER
3557  }
3558 #endif
3559  if ( ((int64)checksum) > molecule->numCalcFullExclusions &&
3560  ( ! simParams->mollyOn || step % slowFreq ) ) {
3561  if ( forgiving )
3562  iout << iWARN << "High global CUDA exclusion count ("
3563  << ((int64)checksum) << " vs "
3564  << molecule->numCalcFullExclusions << "), possible error!\n"
3565  << iWARN << "This warning is not unusual during minimization.\n"
3566  << iWARN << "Decreasing pairlistdist or cutoff that is too close to periodic cell size may avoid this.\n" << endi;
3567  else {
3568  char errmsg[256];
3569  sprintf(errmsg, "High global CUDA exclusion count! (%lld vs %lld) System unstable or pairlistdist or cutoff too close to periodic cell size.\n",
3570  (long long)checksum, (long long)molecule->numCalcFullExclusions);
3571  NAMD_bug(errmsg);
3572  }
3573  }
3574 
3575  if ( ((int64)checksum) && ((int64)checksum) < molecule->numCalcFullExclusions &&
3577  if ( forgiving || ! simParams->fullElectFrequency ) {
3578  iout << iWARN << "Low global CUDA exclusion count! ("
3579  << ((int64)checksum) << " vs " << molecule->numCalcFullExclusions << ") on step " << step;
3580  if ( forgiving ) {
3581  iout << "\n"
3582  << iWARN << "This warning is not unusual during minimization.\n"
3583  << iWARN << "Increasing pairlistdist or cutoff may avoid this.\n";
3584  } else {
3585  iout << " System unstable or pairlistdist or cutoff too small.\n";
3586  }
3587  iout << endi;
3588  } else {
3589  char errmsg[256];
3590  sprintf(errmsg, "Low global CUDA exclusion count! (%lld vs %lld) System unstable or pairlistdist or cutoff too small.\n",
3591  (long long)checksum, (long long)molecule->numCalcFullExclusions);
3592  NAMD_bug(errmsg);
3593  }
3594  }
3595 #endif
3596 
3597 #ifdef NODEGROUP_FORCE_REGISTER
3598  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_MARGIN_VIOLATIONS);
3599  else{
3600 #endif
3602 #ifdef NODEGROUP_FORCE_REGISTER
3603  }
3604 #endif
3605  if ( ((int)checksum) && ! marginViolations ) {
3606  iout << iERROR << "Margin is too small for " << ((int)checksum) <<
3607  " atoms during timestep " << step << ".\n" << iERROR <<
3608  "Incorrect nonbonded forces and energies may be calculated!\n" << endi;
3609  }
3610  marginViolations += (int)checksum;
3611 
3612 #ifdef NODEGROUP_FORCE_REGISTER
3613  if(cudaIntegrator) checksum = nodeReduction->item(REDUCTION_PAIRLIST_WARNINGS);
3614  else {
3615 #endif
3617 #ifdef NODEGROUP_FORCE_REGISTER
3618  }
3619 #endif
3620  if ( simParams->outputPairlists && ((int)checksum) && ! pairlistWarnings ) {
3621  iout << iINFO <<
3622  "Pairlistdist is too small for " << ((int)checksum) <<
3623  " computes during timestep " << step << ".\n" << endi;
3624  }
3625  if ( simParams->outputPairlists ) pairlistWarnings += (int)checksum;
3626 
3627 #ifdef NODEGROUP_FORCE_REGISTER
3628  if(cudaIntegrator)checksum = nodeReduction->item(REDUCTION_STRAY_CHARGE_ERRORS);
3629  else{
3630 #endif
3632 #ifdef NODEGROUP_FORCE_REGISTER
3633  }
3634 #endif
3635  if ( checksum ) {
3636  if ( forgiving )
3637  iout << iWARN << "Stray PME grid charges ignored!\n" << endi;
3638  else NAMD_bug("Stray PME grid charges detected!\n");
3639  }
3640 }
static Node * Object()
Definition: Node.h:86
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
int numCalcBonds
Definition: Molecule.h:655
int numCalcAnisos
Definition: Molecule.h:665
Definition: Node.h:78
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:175
int numCalcCrossterms
Definition: Molecule.h:659
int64 numCalcFullExclusions
Definition: Molecule.h:661
void NAMD_bug(const char *err_msg)
Definition: common.C:195
ReductionValue & item(int index)
Definition: ReductionMgr.C:633
int computeChecksum
Definition: Controller.h:172
int marginViolations
Definition: Controller.h:173
int numCalcDihedrals
Definition: Molecule.h:657
int numCalcImpropers
Definition: Molecule.h:658
int numAtoms
Definition: Molecule.h:585
int64 numCalcExclusions
Definition: Molecule.h:660
int pairlistWarnings
Definition: Controller.h:174
BigReal item(int i) const
Definition: ReductionMgr.h:341
int slowFreq
Definition: Controller.h:163
SimParameters *const simParams
Definition: Controller.h:348
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
RequireReduction * reduction
Definition: Controller.h:350
int numCalcTholes
Definition: Molecule.h:664
NodeReduction * nodeReduction
Definition: Controller.h:354
int64_t int64
Definition: common.h:39
Molecule * molecule
Definition: Node.h:179
int numCalcAngles
Definition: Molecule.h:656
double BigReal
Definition: common.h:123

◆ computeAlchWork()

BigReal Controller::computeAlchWork ( const int  step)
protected

Definition at line 4924 of file Controller.C.

References bondedEnergy_ti_1, bondedEnergy_ti_2, electEnergy_ti_1, electEnergy_ti_2, electEnergyPME_ti_1, electEnergyPME_ti_2, electEnergySlow_ti_1, electEnergySlow_ti_2, SimParameters::getBondLambda(), SimParameters::getCurrentLambda(), SimParameters::getElecLambda(), SimParameters::getVdwLambda(), ljEnergy_ti_1, ljEnergy_ti_2, and simParams.

Referenced by printEnergies().

4924  {
4925  // alchemical scaling factors for groups 1/2 at the previous lambda
4926  const BigReal oldLambda = simParams->getCurrentLambda(step-1);
4927  const BigReal bond_lambda_1 = simParams->getBondLambda(oldLambda);
4928  const BigReal bond_lambda_2 = simParams->getBondLambda(1-oldLambda);
4929  const BigReal elec_lambda_1 = simParams->getElecLambda(oldLambda);
4930  const BigReal elec_lambda_2 = simParams->getElecLambda(1-oldLambda);
4931  const BigReal vdw_lambda_1 = simParams->getVdwLambda(oldLambda);
4932  const BigReal vdw_lambda_2 = simParams->getVdwLambda(1-oldLambda);
4933  // alchemical scaling factors for groups 1/2 at the new lambda
4934  const BigReal alchLambda = simParams->getCurrentLambda(step);
4935  const BigReal bond_lambda_12 = simParams->getBondLambda(alchLambda);
4936  const BigReal bond_lambda_22 = simParams->getBondLambda(1-alchLambda);
4937  const BigReal elec_lambda_12 = simParams->getElecLambda(alchLambda);
4938  const BigReal elec_lambda_22 = simParams->getElecLambda(1-alchLambda);
4939  const BigReal vdw_lambda_12 = simParams->getVdwLambda(alchLambda);
4940  const BigReal vdw_lambda_22 = simParams->getVdwLambda(1-alchLambda);
4941 
4942  return ((bond_lambda_12 - bond_lambda_1)*bondedEnergy_ti_1 +
4943  (elec_lambda_12 - elec_lambda_1)*
4945  (vdw_lambda_12 - vdw_lambda_1)*ljEnergy_ti_1 +
4946  (bond_lambda_22 - bond_lambda_2)*bondedEnergy_ti_2 +
4947  (elec_lambda_22 - elec_lambda_2)*
4949  (vdw_lambda_22 - vdw_lambda_2)*ljEnergy_ti_2
4950  );
4951 }
BigReal electEnergy_ti_1
Definition: Controller.h:213
BigReal getBondLambda(const BigReal) const
BigReal getElecLambda(const BigReal) const
BigReal ljEnergy_ti_1
Definition: Controller.h:215
BigReal electEnergySlow_ti_1
Definition: Controller.h:214
BigReal electEnergyPME_ti_1
Definition: Controller.h:226
BigReal electEnergy_ti_2
Definition: Controller.h:216
BigReal electEnergyPME_ti_2
Definition: Controller.h:227
BigReal getCurrentLambda(const int) const
BigReal getVdwLambda(const BigReal) const
BigReal electEnergySlow_ti_2
Definition: Controller.h:217
SimParameters *const simParams
Definition: Controller.h:348
BigReal bondedEnergy_ti_2
Definition: Controller.h:212
BigReal bondedEnergy_ti_1
Definition: Controller.h:211
double BigReal
Definition: common.h:123
BigReal ljEnergy_ti_2
Definition: Controller.h:218

◆ correctMomentum()

void Controller::correctMomentum ( int  step)
protected

Definition at line 1684 of file Controller.C.

References broadcast, SimParameters::CUDASOAintegrate, endi(), iERROR(), iout, RequireReduction::item(), NodeReduction::item(), Vector::length2(), ControllerBroadcasts::momentumCorrection, NAMD_die(), nodeReduction, SimpleBroadcastObject< T >::publish(), reduction, REDUCTION_MOMENTUM_MASS, simParams, slowFreq, Vector::x, Vector::y, and Vector::z.

Referenced by integrate().

1684  {
1685 
1686  Vector momentum;
1687  BigReal mass;
1688 #ifdef NODEGROUP_FORCE_REGISTER
1690  momentum.x = nodeReduction->item(REDUCTION_HALFSTEP_MOMENTUM_X);
1691  momentum.y = nodeReduction->item(REDUCTION_HALFSTEP_MOMENTUM_Y);
1692  momentum.z = nodeReduction->item(REDUCTION_HALFSTEP_MOMENTUM_Z);
1694  }else{
1695 #endif
1696  momentum.x = reduction->item(REDUCTION_HALFSTEP_MOMENTUM_X);
1697  momentum.y = reduction->item(REDUCTION_HALFSTEP_MOMENTUM_Y);
1698  momentum.z = reduction->item(REDUCTION_HALFSTEP_MOMENTUM_Z);
1700 #ifdef NODEGROUP_FORCE_REGISTER
1701  }
1702 #endif
1703 
1704 
1705  if ( momentum.length2() == 0. )
1706  iout << iERROR << "Momentum is exactly zero; probably a bug.\n" << endi;
1707  if ( mass == 0. )
1708  NAMD_die("Total mass is zero in Controller::correctMomentum");
1709 
1710  momentum *= (-1./mass);
1711  // What does this mean???
1712  broadcast->momentumCorrection.publish(step+slowFreq,momentum);
1713 }
SimpleBroadcastObject< Vector > momentumCorrection
Definition: Broadcasts.h:81
Definition: Vector.h:72
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
#define iout
Definition: InfoStream.h:51
ControllerBroadcasts * broadcast
Definition: Controller.h:365
ReductionValue & item(int index)
Definition: ReductionMgr.C:633
NAMD_HOST_DEVICE BigReal length2(void) const
Definition: Vector.h:206
BigReal x
Definition: Vector.h:74
void NAMD_die(const char *err_msg)
Definition: common.C:147
void publish(int tag, const T &t)
BigReal item(int i) const
Definition: ReductionMgr.h:341
BigReal y
Definition: Vector.h:74
int slowFreq
Definition: Controller.h:163
SimParameters *const simParams
Definition: Controller.h:348
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
RequireReduction * reduction
Definition: Controller.h:350
NodeReduction * nodeReduction
Definition: Controller.h:354
double BigReal
Definition: common.h:123

◆ cycleBarrier()

void Controller::cycleBarrier ( int  doBarrier,
int  step 
)
protected

Definition at line 5214 of file Controller.C.

References broadcast, and namdWallTimer().

Referenced by integrate().

5214  {
5215 #if USE_BARRIER
5216  if (doBarrier) {
5217  broadcast->cycleBarrier.publish(step,1);
5218  CkPrintf("Cycle time at sync Wall: %f CPU %f\n",
5219  namdWallTimer()-firstWTime,CmiTimer()-firstCTime);
5220  }
5221 #endif
5222 }
static double namdWallTimer()
Definition: Controller.C:57
ControllerBroadcasts * broadcast
Definition: Controller.h:365

◆ enqueueCollections()

void Controller::enqueueCollections ( int  timestep)
protected

Definition at line 4674 of file Controller.C.

References collection, Output::coordinateNeeded(), CollectionMaster::enqueueForces(), CollectionMaster::enqueuePositions(), CollectionMaster::enqueuePositionsDcdSelection(), CollectionMaster::enqueueVelocities(), Output::forceNeeded(), state, and Output::velocityNeeded().

Referenced by algorithm(), integrate(), and minimize().

4675 {
4676  int prec;
4677  int dcdIndex;
4678 
4679  std::tie(prec, dcdIndex) = Output::coordinateNeeded(timestep);
4680  if ( prec == 4 ){
4681  collection->enqueuePositionsDcdSelection(timestep,state->lattice);
4682  }
4683  else if ( prec ){
4684  collection->enqueuePositions(timestep,state->lattice);
4685  }
4686  if ( Output::velocityNeeded(timestep) )
4687  collection->enqueueVelocities(timestep);
4688  if ( Output::forceNeeded(timestep) )
4689  collection->enqueueForces(timestep);
4690 }
static int velocityNeeded(int)
Definition: Output.C:500
void enqueueVelocities(int seq)
void enqueuePositions(int seq, Lattice &lattice)
static int forceNeeded(int)
Definition: Output.C:595
void enqueuePositionsDcdSelection(int seq, Lattice &lattice)
NamdState *const state
Definition: Controller.h:349
static std::pair< int, int > coordinateNeeded(int)
Definition: Output.C:199
CollectionMaster *const collection
Definition: Controller.h:364
void enqueueForces(int seq)

◆ getTIderivative()

BigReal Controller::getTIderivative ( void  ) const
inline

Definition at line 122 of file Controller.h.

122 { return TIderivative; }

◆ getTotalPotentialEnergy()

BigReal Controller::getTotalPotentialEnergy ( int  step)
protected

Definition at line 3746 of file Controller.C.

References compareChecksums(), SimParameters::CUDASOAintegrate, electEnergy, electEnergySlow, SimParameters::getCurrentLambda(), Molecule::getEnergyTailCorr(), RequireReduction::item(), NodeReduction::item(), SimParameters::LJcorrection, ljEnergy, Node::molecule, NAMD_bug(), nbondFreq, nodeReduction, Node::Object(), reduction, REDUCTION_ANGLE_ENERGY, REDUCTION_BC_ENERGY, REDUCTION_BOND_ENERGY, REDUCTION_CROSSTERM_ENERGY, REDUCTION_DIHEDRAL_ENERGY, REDUCTION_ELECT_ENERGY, REDUCTION_ELECT_ENERGY_SLOW, REDUCTION_IMPROPER_ENERGY, REDUCTION_LJ_ENERGY, REDUCTION_MISC_ENERGY, simParams, slowFreq, state, and Lattice::volume().

Referenced by monteCarloPressure_accept(), and monteCarloPressure_prepare().

3747 {
3748  compareChecksums(step, 0);
3749 
3750  Node *node = Node::Object();
3751  Molecule *molecule = node->molecule;
3752  Lattice &lattice = state->lattice;
3753  BigReal volume = lattice.volume();
3754  // store total energy
3755  BigReal totalPotentialEnergy = 0.0;
3756  BigReal bondEnergy, angleEnergy, dihedralEnergy;
3757  BigReal improperEnergy, crosstermEnergy;
3759  BigReal miscEnergy, bcEnergy;
3760  bool cudaIntegrator = simParams->CUDASOAintegrate;
3761 
3762 #ifdef NODEGROUP_FORCE_REGISTER
3763  if(cudaIntegrator){
3764  bondEnergy = nodeReduction->item(REDUCTION_BOND_ENERGY);
3765  angleEnergy = nodeReduction->item(REDUCTION_ANGLE_ENERGY);
3766  dihedralEnergy = nodeReduction->item(REDUCTION_DIHEDRAL_ENERGY);
3767  improperEnergy = nodeReduction->item(REDUCTION_IMPROPER_ENERGY);
3768  crosstermEnergy = nodeReduction->item(REDUCTION_CROSSTERM_ENERGY);
3769  bcEnergy = nodeReduction->item(REDUCTION_BC_ENERGY);
3770  miscEnergy = nodeReduction->item(REDUCTION_MISC_ENERGY);
3771  }else{
3772 #endif
3773  bondEnergy = reduction->item(REDUCTION_BOND_ENERGY);
3774  angleEnergy = reduction->item(REDUCTION_ANGLE_ENERGY);
3775  dihedralEnergy = reduction->item(REDUCTION_DIHEDRAL_ENERGY);
3776  improperEnergy = reduction->item(REDUCTION_IMPROPER_ENERGY);
3777  crosstermEnergy = reduction->item(REDUCTION_CROSSTERM_ENERGY);
3778  bcEnergy = reduction->item(REDUCTION_BC_ENERGY);
3779  miscEnergy = reduction->item(REDUCTION_MISC_ENERGY);
3780 #ifdef NODEGROUP_FORCE_REGISTER
3781  }
3782 #endif
3783 
3784  totalPotentialEnergy += bondEnergy + angleEnergy + dihedralEnergy +
3785  improperEnergy + crosstermEnergy + miscEnergy
3786  + bcEnergy;
3787 
3788  if (! ( step % nbondFreq ))
3789  {
3790 #ifdef NODEGROUP_FORCE_REGISTER
3791  if(cudaIntegrator){
3794 
3795  }else{
3796 #endif
3799 #ifdef NODEGROUP_FORCE_REGISTER
3800  }
3801 #endif
3802  totalPotentialEnergy += electEnergy + ljEnergy;
3803  }
3804 
3805  if (! ( step % slowFreq ))
3806  {
3807 #ifdef NODEGROUP_FORCE_REGISTER
3808  if(cudaIntegrator){
3810  }else{
3811 #endif
3813 #ifdef NODEGROUP_FORCE_REGISTER
3814  }
3815 #endif
3816  totalPotentialEnergy += electEnergySlow;
3817  }
3818 
3819  if (simParams->LJcorrection && volume) {
3820 #ifdef MEM_OPT_VERSION
3821  NAMD_bug("LJcorrection not supported in memory optimized build.");
3822 #else
3823  // Apply tail correction to energy.
3824  BigReal alchLambda = simParams->getCurrentLambda(step);
3825  totalPotentialEnergy += molecule->getEnergyTailCorr(alchLambda, 0) / volume;
3826 #endif
3827  }
3828 
3829  #if 0
3830  printf("MC-data (TotalPotentialEnergy): step: %d, Pe: %d, Bond: %f, Angle: %f, Dih: %f, IMP: %f, Cross: %f\n",
3831  step, CkMyPe(), bondEnergy, angleEnergy, dihedralEnergy, improperEnergy, crosstermEnergy);
3832  printf("MC-data (TotalPotentialEnergy): step: %d, Pe: %d, LJ: %f, Real: %f, Recip: %f\n", step, CkMyPe(),
3834  printf("MC-data (TotalPotentialEnergy): step: %d, Pe: %d, MISC: %f, BC: %f, TOTAL: %f\n", step, CkMyPe(),
3835  miscEnergy, bcEnergy, totalPotentialEnergy);
3836  #endif
3837 
3838  return totalPotentialEnergy;
3839 }
static Node * Object()
Definition: Node.h:86
int nbondFreq
Definition: Controller.h:162
void compareChecksums(int, int=0)
Definition: Controller.C:3349
Definition: Node.h:78
BigReal ljEnergy
Definition: Controller.h:191
BigReal electEnergySlow
Definition: Controller.h:190
Molecule stores the structural information for the system.
Definition: Molecule.h:175
NamdState *const state
Definition: Controller.h:349
BigReal getEnergyTailCorr(const BigReal, const int)
void NAMD_bug(const char *err_msg)
Definition: common.C:195
ReductionValue & item(int index)
Definition: ReductionMgr.C:633
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
BigReal getCurrentLambda(const int) const
BigReal item(int i) const
Definition: ReductionMgr.h:341
BigReal electEnergy
Definition: Controller.h:189
int slowFreq
Definition: Controller.h:163
SimParameters *const simParams
Definition: Controller.h:348
RequireReduction * reduction
Definition: Controller.h:350
NodeReduction * nodeReduction
Definition: Controller.h:354
Molecule * molecule
Definition: Node.h:179
double BigReal
Definition: common.h:123

◆ integrate()

void Controller::integrate ( int  scriptTask)
protected

Definition at line 514 of file Controller.C.

References adaptTempUpdate(), berendsenPressure(), correctMomentum(), SimParameters::CUDASOAintegrate, cycleBarrier(), enqueueCollections(), eventEndOfTimeStep, SimParameters::firstTimestep, SimParameters::fullElectFrequency, langevinPiston1(), langevinPiston2(), multigratorPressure(), multigratorTemperature(), SimParameters::N, nbondFreq, SimParameters::nonbondedFrequency, SimParameters::numTraceSteps, Node::Object(), outputExtendedSystem(), outputFepEnergy(), outputTiEnergy(), printDynamicsEnergies(), printFepMessage(), printTiMessage(), reassignVelocities(), rebalanceLoad(), receivePressure(), rescaleaccelMD(), rescaleVelocities(), SCRIPT_RUN, simParams, slowFreq, SimParameters::statsOn, SimParameters::stepsPerCycle, stochRescaleVelocities(), tcoupleVelocities(), traceBarrier(), SimParameters::traceStartStep, and SimParameters::zeroMomentum.

Referenced by algorithm().

514  {
515  char traceNote[24];
516 
517  int step = simParams->firstTimestep;
518 
519  const int numberOfSteps = simParams->N;
520  const int stepsPerCycle = simParams->stepsPerCycle;
521 
522  const int zeroMomentum = simParams->zeroMomentum;
523 
525  const int dofull = ( simParams->fullElectFrequency ? 1 : 0 );
526  if (dofull)
528  else
530  if ( step >= numberOfSteps ) slowFreq = nbondFreq = 1;
531 
533 
534  if ( scriptTask == SCRIPT_RUN ) {
535 
536  reassignVelocities(step); // only for full-step velecities
537  rescaleaccelMD(step);
538  adaptTempUpdate(step); // Init adaptive tempering;
539 
540  receivePressure(step);
541  if ( zeroMomentum && dofull && ! (step % slowFreq) )
542  correctMomentum(step);
543  printFepMessage(step);
544  printTiMessage(step);
545  printDynamicsEnergies(step);
546  outputFepEnergy(step);
547  outputTiEnergy(step);
548  if(traceIsOn()){
549  traceUserEvent(eventEndOfTimeStep);
550  sprintf(traceNote, "s:%d", step);
551  traceUserSuppliedNote(traceNote);
552  }
553  outputExtendedSystem(step);
554  rebalanceLoad(step);
555 
556  }
557 
558  // Handling SIGINT doesn't seem to be working on Lemieux, and it
559  // sometimes causes the net-xxx versions of NAMD to segfault on exit,
560  // so disable it for now.
561  // namd_sighandler_t oldhandler = signal(SIGINT,
562  // (namd_sighandler_t)my_sigint_handler);
563  for ( ++step ; step <= numberOfSteps; ++step )
564  {
565  adaptTempUpdate(step);
566  rescaleVelocities(step);
567  tcoupleVelocities(step);
569  berendsenPressure(step);
570  langevinPiston1(step);
571  rescaleaccelMD(step);
572  enqueueCollections(step); // after lattice scaling!
573  receivePressure(step);
574  if ( zeroMomentum && dofull && ! (step % slowFreq) )
575  correctMomentum(step);
576  langevinPiston2(step);
577  reassignVelocities(step);
578 
579  multigratorTemperature(step, 1);
580  multigratorPressure(step, 1);
581  multigratorPressure(step, 2);
582  multigratorTemperature(step, 2);
583 
584  printDynamicsEnergies(step);
585  outputFepEnergy(step);
586  outputTiEnergy(step);
587  if(traceIsOn()){
588  traceUserEvent(eventEndOfTimeStep);
589  sprintf(traceNote, "s:%d", step);
590  traceUserSuppliedNote(traceNote);
591  }
592  // if (gotsigint) {
593  // iout << iINFO << "Received SIGINT; shutting down.\n" << endi;
594  // NAMD_quit();
595  // }
596  outputExtendedSystem(step);
597 #if CYCLE_BARRIER
598  cycleBarrier(!((step+1) % stepsPerCycle),step);
599 #elif PME_BARRIER
600  cycleBarrier(dofull && !(step%slowFreq),step);
601 #elif STEP_BARRIER
602  cycleBarrier(1, step);
603 #endif
604 
605  if(Node::Object()->specialTracing || simParams->statsOn){
606  int bstep = simParams->traceStartStep;
607  int estep = bstep + simParams->numTraceSteps;
608  if(step == bstep){
609  traceBarrier(1, step);
610  }
611  if(step == estep){
612  traceBarrier(0, step);
613  }
614  }
615 
616 #ifdef MEASURE_NAMD_WITH_PAPI
617  if(simParams->papiMeasure) {
618  int bstep = simParams->papiMeasureStartStep;
619  int estep = bstep + simParams->numPapiMeasureSteps;
620  if(step == bstep) {
621  papiMeasureBarrier(1, step);
622  }
623  if(step == estep) {
624  papiMeasureBarrier(0, step);
625  }
626  }
627 #endif
628 
629  rebalanceLoad(step);
630 
631 #if PME_BARRIER
632  cycleBarrier(dofull && !((step+1)%slowFreq),step); // step before PME
633 #endif
634  }
635  }else CthSuspend();
636  // signal(SIGINT, oldhandler);
637 }
static Node * Object()
Definition: Node.h:86
void enqueueCollections(int)
Definition: Controller.C:4674
void cycleBarrier(int, int)
Definition: Controller.C:5214
void rescaleVelocities(int)
Definition: Controller.C:1662
void rescaleaccelMD(int step, int minimize=0)
Definition: Controller.C:2413
int nbondFreq
Definition: Controller.h:162
int eventEndOfTimeStep
Definition: Node.C:293
void printTiMessage(int)
Definition: Controller.C:1736
void multigratorTemperature(int step, int callNumber)
Definition: Controller.C:1024
void langevinPiston1(int)
Definition: Controller.C:1395
void outputTiEnergy(int step)
Definition: Controller.C:4777
void stochRescaleVelocities(int)
Definition: Controller.C:1790
void correctMomentum(int step)
Definition: Controller.C:1684
void berendsenPressure(int)
Definition: Controller.C:1357
void langevinPiston2(int)
Definition: Controller.C:1571
void receivePressure(int step, int minimize=0)
Definition: Controller.C:1862
void reassignVelocities(int)
Definition: Controller.C:1750
void outputFepEnergy(int step)
Definition: Controller.C:4693
void printFepMessage(int)
Definition: Controller.C:1716
int slowFreq
Definition: Controller.h:163
void traceBarrier(int, int)
Definition: Controller.C:5224
void printDynamicsEnergies(int)
Definition: Controller.C:3741
void multigratorPressure(int step, int callNumber)
Definition: Controller.C:949
void tcoupleVelocities(int)
Definition: Controller.C:1768
SimParameters *const simParams
Definition: Controller.h:348
void rebalanceLoad(int)
Definition: Controller.C:5200
void outputExtendedSystem(int step)
Definition: Controller.C:5042
void adaptTempUpdate(int step, int minimize=0)
Definition: Controller.C:3051

◆ langevinPiston1()

void Controller::langevinPiston1 ( int  step)
protected

Definition at line 1395 of file Controller.C.

References BOLTZMANN, broadcast, Lattice::c(), controlNumDegFreedom, controlPressure, controlPressure_nbond, controlPressure_slow, SimParameters::CUDASOAintegrate, Tensor::diagonal(), SimParameters::dt, SimParameters::fixCellDims, SimParameters::fixCellDimX, SimParameters::fixCellDimY, SimParameters::fixCellDimZ, Random::gaussian(), Random::gaussian_vector(), Tensor::identity(), iINFO(), iout, ControllerState::langevinPiston_strainRate, SimParameters::langevinPistonBarrier, SimParameters::langevinPistonDecay, SimParameters::langevinPistonOn, SimParameters::langevinPistonPeriod, SimParameters::langevinPistonTarget, SimParameters::langevinPistonTemp, nbondFreq, ControllerBroadcasts::positionRescaleFactor, positionRescaleFactor, SimpleBroadcastObject< T >::publish(), random, Lattice::rescale(), simParams, slowFreq, state, strainRate_old, SimParameters::surfaceTensionTarget, SimParameters::useConstantArea, SimParameters::useConstantRatio, SimParameters::useFlexibleCell, Lattice::volume(), Tensor::xx, Tensor::yy, Vector::z, and Tensor::zz.

Referenced by integrate().

1396 {
1397  if ( simParams->langevinPistonOn )
1398  {
1399  Tensor &strainRate = langevinPiston_strainRate;
1400  int cellDims = simParams->useFlexibleCell ? 1 : 3;
1401  BigReal dt = simParams->dt;
1402  BigReal dt_long = slowFreq * dt;
1405  BigReal mass = controlNumDegFreedom * kT * tau * tau * cellDims;
1406 
1407 #ifdef DEBUG_PRESSURE
1408  iout << iINFO << "entering langevinPiston1, strain rate: " << strainRate << "\n";
1409 #endif
1410 
1411  if ( ! ( (step-1) % slowFreq ) )
1412  {
1413  BigReal gamma = 1 / simParams->langevinPistonDecay;
1414  BigReal f1 = exp( -0.5 * dt_long * gamma );
1415  BigReal f2 = sqrt( ( 1. - f1*f1 ) * kT / mass );
1416  strainRate *= f1;
1417  if ( simParams->useFlexibleCell ) {
1418  // We only use on-diagonal terms (for now)
1419  if ( simParams->useConstantRatio ) {
1420  BigReal r = f2 * random->gaussian();
1421  strainRate.xx += r;
1422  strainRate.yy += r;
1423  strainRate.zz += f2 * random->gaussian();
1424  } else {
1425  strainRate += f2 * Tensor::diagonal(random->gaussian_vector());
1426  }
1427  } else {
1428  strainRate += f2 * Tensor::identity(random->gaussian());
1429  }
1430 
1431 #ifdef DEBUG_PRESSURE
1432  iout << iINFO << "applying langevin, strain rate: " << strainRate << "\n";
1433 #endif
1434  }
1435 
1436  // Apply surface tension. If surfaceTensionTarget is zero, we get
1437  // the default (isotropic pressure) case.
1438 
1439  Tensor ptarget;
1440  ptarget.xx = ptarget.yy = ptarget.zz = simParams->langevinPistonTarget;
1441  if ( simParams->surfaceTensionTarget != 0. ) {
1442  ptarget.xx = ptarget.yy = simParams->langevinPistonTarget -
1443  simParams->surfaceTensionTarget / state->lattice.c().z;
1444  }
1445 
1446  strainRate += ( 0.5 * dt * cellDims * state->lattice.volume() / mass ) *
1447  ( controlPressure - ptarget );
1448 
1449  if (simParams->fixCellDims) {
1450  if (simParams->fixCellDimX) strainRate.xx = 0;
1451  if (simParams->fixCellDimY) strainRate.yy = 0;
1452  if (simParams->fixCellDimZ) strainRate.zz = 0;
1453  }
1454 
1455 
1456 #ifdef DEBUG_PRESSURE
1457  iout << iINFO << "integrating half step, strain rate: " << strainRate << "\n";
1458 #endif
1459 
1461  if ( ! ( (step-1-slowFreq/2) % slowFreq ) )
1462  {
1463  // We only use on-diagonal terms (for now)
1464  Tensor factor;
1465  if ( !simParams->useConstantArea ) {
1466  factor.xx = exp( dt_long * strainRate.xx );
1467  factor.yy = exp( dt_long * strainRate.yy );
1468  } else {
1469  factor.xx = factor.yy = 1;
1470  }
1471  factor.zz = exp( dt_long * strainRate.zz );
1472 #ifdef NODEGROUP_FORCE_REGISTER
1473  if(simParams->CUDASOAintegrate) // don't use broadcastMgr
1474  publishedRescaleFactors.insert({step, factor});
1475  else
1476  broadcast->positionRescaleFactor.publish(step,factor);
1477 #else
1478  broadcast->positionRescaleFactor.publish(step,factor);
1479 #endif
1480  state->lattice.rescale(factor);
1481 #ifdef DEBUG_PRESSURE
1482  iout << iINFO << "rescaling by: " << factor << "\n";
1483 #endif
1484  }
1485  } else { // langevinPistonBarrier
1486  if ( ! ( (step-1-slowFreq/2) % slowFreq ) )
1487  {
1488  if ( ! positionRescaleFactor.xx ) { // first pass without MTS
1489  // We only use on-diagonal terms (for now)
1490  Tensor factor;
1491  if ( !simParams->useConstantArea ) {
1492  factor.xx = exp( dt_long * strainRate.xx );
1493  factor.yy = exp( dt_long * strainRate.yy );
1494  } else {
1495  factor.xx = factor.yy = 1;
1496  }
1497  factor.zz = exp( dt_long * strainRate.zz );
1498 #ifdef NODEGROUP_FORCE_REGISTER
1499  if(simParams->CUDASOAintegrate) // don't use broadcastMgr
1500  publishedRescaleFactors.insert({step, factor});
1501  else
1502  broadcast->positionRescaleFactor.publish(step,factor);
1503 #else
1504  broadcast->positionRescaleFactor.publish(step,factor);
1505 #endif
1506  positionRescaleFactor = factor;
1507  strainRate_old = strainRate;
1508  }
1510 #ifdef DEBUG_PRESSURE
1511  iout << iINFO << "rescaling by: " << positionRescaleFactor << "\n";
1512 #endif
1513  }
1514  if ( ! ( (step-slowFreq/2) % slowFreq ) )
1515  {
1516  // We only use on-diagonal terms (for now)
1517  Tensor factor;
1518  if ( !simParams->useConstantArea ) {
1519  factor.xx = exp( (dt+dt_long) * strainRate.xx - dt * strainRate_old.xx );
1520  factor.yy = exp( (dt+dt_long) * strainRate.yy - dt * strainRate_old.yy );
1521  } else {
1522  factor.xx = factor.yy = 1;
1523  }
1524  factor.zz = exp( (dt+dt_long) * strainRate.zz - dt * strainRate_old.zz );
1525 #ifdef NODEGROUP_FORCE_REGISTER
1526  if(simParams->CUDASOAintegrate) // don't use broadcastMgr
1527  publishedRescaleFactors.insert({step+1, factor});
1528  else
1529  broadcast->positionRescaleFactor.publish(step+1,factor);
1530 #else
1531  broadcast->positionRescaleFactor.publish(step+1,factor);
1532 #endif
1533  positionRescaleFactor = factor;
1534  strainRate_old = strainRate;
1535  }
1536  }
1537 
1538  // corrections to integrator
1539  if ( ! ( step % nbondFreq ) )
1540  {
1541 #ifdef DEBUG_PRESSURE
1542  iout << iINFO << "correcting strain rate for nbond, ";
1543 #endif
1544  strainRate -= ( 0.5 * dt * cellDims * state->lattice.volume() / mass ) *
1545  ( (nbondFreq - 1) * controlPressure_nbond );
1546 #ifdef DEBUG_PRESSURE
1547  iout << "strain rate: " << strainRate << "\n";
1548 #endif
1549  }
1550  if ( ! ( step % slowFreq ) )
1551  {
1552 #ifdef DEBUG_PRESSURE
1553  iout << iINFO << "correcting strain rate for slow, ";
1554 #endif
1555  strainRate -= ( 0.5 * dt * cellDims * state->lattice.volume() / mass ) *
1556  ( (slowFreq - 1) * controlPressure_slow );
1557 #ifdef DEBUG_PRESSURE
1558  iout << "strain rate: " << strainRate << "\n";
1559 #endif
1560  }
1561  if (simParams->fixCellDims) {
1562  if (simParams->fixCellDimX) strainRate.xx = 0;
1563  if (simParams->fixCellDimY) strainRate.yy = 0;
1564  if (simParams->fixCellDimZ) strainRate.zz = 0;
1565  }
1566 
1567  }
1568 
1569 }
Vector gaussian_vector(void)
Definition: Random.h:219
NAMD_HOST_DEVICE void rescale(Tensor factor)
Definition: Lattice.h:60
Tensor controlPressure_slow
Definition: Controller.h:161
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
int nbondFreq
Definition: Controller.h:162
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
BigReal langevinPistonTemp
#define BOLTZMANN
Definition: common.h:54
BigReal gaussian(void)
Definition: Random.h:116
Tensor controlPressure
Definition: Controller.h:255
BigReal surfaceTensionTarget
BigReal z
Definition: Vector.h:74
Bool langevinPistonBarrier
#define iout
Definition: InfoStream.h:51
static NAMD_HOST_DEVICE Tensor identity(BigReal v1=1.0)
Definition: Tensor.h:31
Tensor langevinPiston_strainRate
Definition: Controller.h:96
BigReal langevinPistonDecay
NamdState *const state
Definition: Controller.h:349
ControllerBroadcasts * broadcast
Definition: Controller.h:365
static NAMD_HOST_DEVICE Tensor diagonal(const Vector &v1)
Definition: Tensor.h:37
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
void publish(int tag, const T &t)
Random * random
Definition: Controller.h:347
BigReal xx
Definition: Tensor.h:17
SimpleBroadcastObject< Tensor > positionRescaleFactor
Definition: Broadcasts.h:71
BigReal langevinPistonPeriod
BigReal zz
Definition: Tensor.h:19
Definition: Tensor.h:15
Tensor strainRate_old
Definition: Controller.h:292
int slowFreq
Definition: Controller.h:163
BigReal yy
Definition: Tensor.h:18
SimParameters *const simParams
Definition: Controller.h:348
Tensor positionRescaleFactor
Definition: Controller.h:293
BigReal langevinPistonTarget
int controlNumDegFreedom
Definition: Controller.h:254
Tensor controlPressure_nbond
Definition: Controller.h:160
double BigReal
Definition: common.h:123

◆ langevinPiston2()

void Controller::langevinPiston2 ( int  step)
protected

Definition at line 1571 of file Controller.C.

References BOLTZMANN, Lattice::c(), controlNumDegFreedom, controlPressure, controlPressure_nbond, controlPressure_slow, Tensor::diagonal(), SimParameters::dt, SimParameters::fixCellDims, SimParameters::fixCellDimX, SimParameters::fixCellDimY, SimParameters::fixCellDimZ, Random::gaussian(), Random::gaussian_vector(), Tensor::identity(), iINFO(), iout, ControllerState::langevinPiston_strainRate, SimParameters::langevinPistonDecay, SimParameters::langevinPistonOn, SimParameters::langevinPistonPeriod, SimParameters::langevinPistonTarget, SimParameters::langevinPistonTemp, nbondFreq, random, simParams, slowFreq, state, SimParameters::surfaceTensionTarget, SimParameters::useConstantRatio, SimParameters::useFlexibleCell, Lattice::volume(), Tensor::xx, Tensor::yy, Vector::z, and Tensor::zz.

Referenced by integrate().

1572 {
1573  if ( simParams->langevinPistonOn )
1574  {
1575  Tensor &strainRate = langevinPiston_strainRate;
1576  int cellDims = simParams->useFlexibleCell ? 1 : 3;
1577  BigReal dt = simParams->dt;
1578  BigReal dt_long = slowFreq * dt;
1581  BigReal mass = controlNumDegFreedom * kT * tau * tau * cellDims;
1582 
1583  // corrections to integrator
1584  if ( ! ( step % nbondFreq ) )
1585  {
1586 #ifdef DEBUG_PRESSURE
1587  iout << iINFO << "correcting strain rate for nbond, ";
1588 #endif
1589  strainRate += ( 0.5 * dt * cellDims * state->lattice.volume() / mass ) *
1590  ( (nbondFreq - 1) * controlPressure_nbond );
1591 #ifdef DEBUG_PRESSURE
1592  iout << "strain rate: " << strainRate << "\n";
1593 #endif
1594  }
1595  if ( ! ( step % slowFreq ) )
1596  {
1597 #ifdef DEBUG_PRESSURE
1598  iout << iINFO << "correcting strain rate for slow, ";
1599 #endif
1600  strainRate += ( 0.5 * dt * cellDims * state->lattice.volume() / mass ) *
1601  ( (slowFreq - 1) * controlPressure_slow );
1602 #ifdef DEBUG_PRESSURE
1603  iout << "strain rate: " << strainRate << "\n";
1604 #endif
1605  }
1606 
1607  // Apply surface tension. If surfaceTensionTarget is zero, we get
1608  // the default (isotropic pressure) case.
1609 
1610  Tensor ptarget;
1611  ptarget.xx = ptarget.yy = ptarget.zz = simParams->langevinPistonTarget;
1612  if ( simParams->surfaceTensionTarget != 0. ) {
1613  ptarget.xx = ptarget.yy = simParams->langevinPistonTarget -
1614  simParams->surfaceTensionTarget / state->lattice.c().z;
1615  }
1616 
1617  strainRate += ( 0.5 * dt * cellDims * state->lattice.volume() / mass ) *
1618  ( controlPressure - ptarget );
1619 
1620 
1621 #ifdef DEBUG_PRESSURE
1622  iout << iINFO << "integrating half step, strain rate: " << strainRate << "\n";
1623 #endif
1624 
1625  if ( ! ( step % slowFreq ) )
1626  {
1627  BigReal gamma = 1 / simParams->langevinPistonDecay;
1628  BigReal f1 = exp( -0.5 * dt_long * gamma );
1629  BigReal f2 = sqrt( ( 1. - f1*f1 ) * kT / mass );
1630  strainRate *= f1;
1631  if ( simParams->useFlexibleCell ) {
1632  // We only use on-diagonal terms (for now)
1633  if ( simParams->useConstantRatio ) {
1634  BigReal r = f2 * random->gaussian();
1635  strainRate.xx += r;
1636  strainRate.yy += r;
1637  strainRate.zz += f2 * random->gaussian();
1638  } else {
1639  strainRate += f2 * Tensor::diagonal(random->gaussian_vector());
1640  }
1641  } else {
1642  strainRate += f2 * Tensor::identity(random->gaussian());
1643  }
1644 #ifdef DEBUG_PRESSURE
1645  iout << iINFO << "applying langevin, strain rate: " << strainRate << "\n";
1646 #endif
1647  }
1648 
1649 #ifdef DEBUG_PRESSURE
1650  iout << iINFO << "exiting langevinPiston2, strain rate: " << strainRate << "\n";
1651 #endif
1652  if (simParams->fixCellDims) {
1653  if (simParams->fixCellDimX) strainRate.xx = 0;
1654  if (simParams->fixCellDimY) strainRate.yy = 0;
1655  if (simParams->fixCellDimZ) strainRate.zz = 0;
1656  }
1657  }
1658 
1659 
1660 }
Vector gaussian_vector(void)
Definition: Random.h:219
Tensor controlPressure_slow
Definition: Controller.h:161
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
int nbondFreq
Definition: Controller.h:162
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
BigReal langevinPistonTemp
#define BOLTZMANN
Definition: common.h:54
BigReal gaussian(void)
Definition: Random.h:116
Tensor controlPressure
Definition: Controller.h:255
BigReal surfaceTensionTarget
BigReal z
Definition: Vector.h:74
#define iout
Definition: InfoStream.h:51
static NAMD_HOST_DEVICE Tensor identity(BigReal v1=1.0)
Definition: Tensor.h:31
Tensor langevinPiston_strainRate
Definition: Controller.h:96
BigReal langevinPistonDecay
NamdState *const state
Definition: Controller.h:349
static NAMD_HOST_DEVICE Tensor diagonal(const Vector &v1)
Definition: Tensor.h:37
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
Random * random
Definition: Controller.h:347
BigReal xx
Definition: Tensor.h:17
BigReal langevinPistonPeriod
BigReal zz
Definition: Tensor.h:19
Definition: Tensor.h:15
int slowFreq
Definition: Controller.h:163
BigReal yy
Definition: Tensor.h:18
SimParameters *const simParams
Definition: Controller.h:348
BigReal langevinPistonTarget
int controlNumDegFreedom
Definition: Controller.h:254
Tensor controlPressure_nbond
Definition: Controller.h:160
double BigReal
Definition: common.h:123

◆ minimize()

void Controller::minimize ( )
protected

Definition at line 765 of file Controller.C.

References broadcast, CALCULATE, minpoint::dudx, endi(), enqueueCollections(), SimParameters::firstTimestep, iout, RequireReduction::item(), min_energy, min_f_dot_f, min_f_dot_v, min_huge_count, min_reduction, min_v_dot_v, ControllerBroadcasts::minimizeCoefficient, SimParameters::minLineGoal, SimParameters::minVerbose, MOVETO, SimParameters::N, nbondFreq, minpoint::noGradient, PRINT_BRACKET, SimpleBroadcastObject< T >::publish(), RequireReduction::require(), simParams, slowFreq, minpoint::u, and minpoint::x.

Referenced by adaptTempUpdate(), algorithm(), calcPressure(), printEnergies(), receivePressure(), and rescaleaccelMD().

765  {
766  // iout << "Controller::minimize() called.\n" << endi;
767 
768  const int minVerbose = simParams->minVerbose;
769  const int numberOfSteps = simParams->N;
770  int step = simParams->firstTimestep;
771  slowFreq = nbondFreq = 1;
772  BigReal linegoal = simParams->minLineGoal; // 1.0e-3
773  const BigReal goldenRatio = 0.5 * ( sqrt(5.0) - 1.0 );
774 
775  CALCULATE
776 
777  int minSeq = 0;
778 
779  // just move downhill until initial bad contacts go away or 100 steps
780  int old_min_huge_count = 2000000000;
781  int steps_at_same_min_huge_count = 0;
782  for ( int i_slow = 0; min_huge_count && i_slow < 100; ++i_slow ) {
783  if ( min_huge_count >= old_min_huge_count ) {
784  if ( ++steps_at_same_min_huge_count > 10 ) break;
785  } else {
786  old_min_huge_count = min_huge_count;
787  steps_at_same_min_huge_count = 0;
788  }
789  iout << "MINIMIZER SLOWLY MOVING " << min_huge_count << " ATOMS WITH BAD CONTACTS DOWNHILL\n" << endi;
790  broadcast->minimizeCoefficient.publish(minSeq++,1.);
791  enqueueCollections(step);
792  CALCULATE
793  }
794  if ( min_huge_count ) {
795  iout << "MINIMIZER GIVING UP ON " << min_huge_count << " ATOMS WITH BAD CONTACTS\n" << endi;
796  }
797  iout << "MINIMIZER STARTING CONJUGATE GRADIENT ALGORITHM\n" << endi;
798 
799  int atStart = 2;
800  int errorFactor = 10;
801  BigReal old_f_dot_f = min_f_dot_f;
802  broadcast->minimizeCoefficient.publish(minSeq++,0.);
803  broadcast->minimizeCoefficient.publish(minSeq++,0.); // v = f
804  int newDir = 1;
807  while ( 1 ) {
808  // line minimization
809  // bracket minimum on line
810  minpoint lo,hi,mid,last;
811  BigReal x = 0;
812  lo.x = x;
813  lo.u = min_energy;
814  lo.dudx = -1. * min_f_dot_v;
816  mid = lo;
817  last = mid;
818  if ( minVerbose ) {
819  iout << "LINE MINIMIZER: POSITION " << last.x << " ENERGY " << last.u << " GRADIENT " << last.dudx;
820  if ( last.noGradient ) iout << " HUGECOUNT " << last.noGradient;
821  iout << "\n" << endi;
822  }
823  BigReal tol = fabs( linegoal * min_f_dot_v );
824  iout << "LINE MINIMIZER REDUCING GRADIENT FROM " <<
825  fabs(min_f_dot_v) << " TO " << tol << "\n" << endi;
826  int start_with_huge = last.noGradient;
828  BigReal maxstep = 0.1 / sqrt(min_reduction->item(0));
829  x = maxstep; MOVETO(x);
830  // bracket minimum on line
831  while ( last.u < mid.u ) {
832  if ( last.dudx < mid.dudx * (5.5 - x/maxstep)/5. ) {
833  x = 6 * maxstep; break;
834  }
835  lo = mid; mid = last;
836  x += maxstep;
837  if ( x > 5.5 * maxstep ) break;
838  MOVETO(x)
839  }
840  if ( x > 5.5 * maxstep ) {
841  iout << "MINIMIZER RESTARTING CONJUGATE GRADIENT ALGORITHM DUE TO POOR PROGRESS\n" << endi;
842  broadcast->minimizeCoefficient.publish(minSeq++,0.);
843  broadcast->minimizeCoefficient.publish(minSeq++,0.); // v = f
844  newDir = 1;
845  old_f_dot_f = min_f_dot_f;
848  continue;
849  }
850  hi = last;
851 #define PRINT_BRACKET \
852  iout << "LINE MINIMIZER BRACKET: DX " \
853  << (mid.x-lo.x) << " " << (hi.x-mid.x) << \
854  " DU " << (mid.u-lo.u) << " " << (hi.u-mid.u) << " DUDX " << \
855  lo.dudx << " " << mid.dudx << " " << hi.dudx << " \n" << endi;
857  // converge on minimum on line
858  int itcnt;
859  for ( itcnt = 10; itcnt > 0; --itcnt ) {
860  int progress = 1;
861  // select new position
862  if ( mid.noGradient ) {
863  if ( ( mid.x - lo.x ) > ( hi.x - mid.x ) ) { // subdivide left side
864  x = (1.0 - goldenRatio) * lo.x + goldenRatio * mid.x;
865  MOVETO(x)
866  if ( last.u <= mid.u ) {
867  hi = mid; mid = last;
868  } else {
869  lo = last;
870  }
871  } else { // subdivide right side
872  x = (1.0 - goldenRatio) * hi.x + goldenRatio * mid.x;
873  MOVETO(x)
874  if ( last.u <= mid.u ) {
875  lo = mid; mid = last;
876  } else {
877  hi = last;
878  }
879  }
880  } else {
881  if ( mid.dudx > 0. ) { // subdivide left side
882  BigReal altxhi = 0.1 * lo.x + 0.9 * mid.x;
883  BigReal altxlo = 0.9 * lo.x + 0.1 * mid.x;
884  x = mid.dudx*(mid.x*mid.x-lo.x*lo.x) + 2*mid.x*(lo.u-mid.u);
885  BigReal xdiv = 2*(mid.dudx*(mid.x-lo.x)+(lo.u-mid.u));
886  if ( xdiv ) x /= xdiv; else x = last.x;
887  if ( x > altxhi ) x = altxhi;
888  if ( x < altxlo ) x = altxlo;
889  if ( x-last.x == 0 ) break;
890  MOVETO(x)
891  if ( last.u <= mid.u ) {
892  hi = mid; mid = last;
893  } else {
894  if ( lo.dudx < 0. && last.dudx > 0. ) progress = 0;
895  lo = last;
896  }
897  } else { // subdivide right side
898  BigReal altxlo = 0.1 * hi.x + 0.9 * mid.x;
899  BigReal altxhi = 0.9 * hi.x + 0.1 * mid.x;
900  x = mid.dudx*(mid.x*mid.x-hi.x*hi.x) + 2*mid.x*(hi.u-mid.u);
901  BigReal xdiv = 2*(mid.dudx*(mid.x-hi.x)+(hi.u-mid.u));
902  if ( xdiv ) x /= xdiv; else x = last.x;
903  if ( x < altxlo ) x = altxlo;
904  if ( x > altxhi ) x = altxhi;
905  if ( x-last.x == 0 ) break;
906  MOVETO(x)
907  if ( last.u <= mid.u ) {
908  lo = mid; mid = last;
909  } else {
910  if ( hi.dudx > 0. && last.dudx < 0. ) progress = 0;
911  hi = last;
912  }
913  }
914  }
916  if ( ! progress ) {
917  MOVETO(mid.x);
918  break;
919  }
920  if ( fabs(last.dudx) < tol ) break;
921  if ( lo.x != mid.x && (lo.u-mid.u) < tol * (mid.x-lo.x) ) break;
922  if ( mid.x != hi.x && (hi.u-mid.u) < tol * (hi.x-mid.x) ) break;
923  }
924  // new direction
925  broadcast->minimizeCoefficient.publish(minSeq++,0.);
926  BigReal c = min_f_dot_f / old_f_dot_f;
927  c = ( c > 1.5 ? 1.5 : c );
928  if ( atStart ) { c = 0; --atStart; }
929  if ( c*c*min_v_dot_v > errorFactor*min_f_dot_f ) {
930  c = 0;
931  if ( errorFactor < 100 ) errorFactor += 10;
932  }
933  if ( c == 0 ) {
934  iout << "MINIMIZER RESTARTING CONJUGATE GRADIENT ALGORITHM\n" << endi;
935  }
936  broadcast->minimizeCoefficient.publish(minSeq++,c); // v = c*v+f
937  newDir = 1;
938  old_f_dot_f = min_f_dot_f;
941  }
942 
943 }
void enqueueCollections(int)
Definition: Controller.C:4674
int nbondFreq
Definition: Controller.h:162
BigReal min_v_dot_v
Definition: Controller.h:182
BigReal noGradient
Definition: Controller.C:761
int min_huge_count
Definition: Controller.h:183
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal minLineGoal
BigReal u
Definition: Controller.C:761
#define iout
Definition: InfoStream.h:51
BigReal min_energy
Definition: Controller.h:179
#define MOVETO(X)
Definition: Controller.C:731
void require(void)
Definition: ReductionMgr.h:342
ControllerBroadcasts * broadcast
Definition: Controller.h:365
BigReal x
Definition: Controller.C:761
BigReal min_f_dot_f
Definition: Controller.h:180
void publish(int tag, const T &t)
SimpleBroadcastObject< BigReal > minimizeCoefficient
Definition: Broadcasts.h:80
BigReal dudx
Definition: Controller.C:761
RequireReduction * min_reduction
Definition: Controller.h:143
#define CALCULATE
Definition: Controller.C:724
#define PRINT_BRACKET
BigReal item(int i) const
Definition: ReductionMgr.h:341
int slowFreq
Definition: Controller.h:163
SimParameters *const simParams
Definition: Controller.h:348
double BigReal
Definition: common.h:123
BigReal min_f_dot_v
Definition: Controller.h:181

◆ monteCarloPressure_accept()

void Controller::monteCarloPressure_accept ( int  step)
protected

Calculate the MC acceptance criteria for volume change and determin if this volume change is accepted or not.

Definition at line 1121 of file Controller.C.

References BOLTZMANN, broadcast, Lattice::c(), SimParameters::CUDASOAintegrate, endi(), getTotalPotentialEnergy(), iout, iWARN(), mc_accept, mc_oldLattice, mc_picked_axis, mc_totalAccept, mc_totalEnergyOld, mc_totalTry, mc_trial, MC_X, MC_Y, MC_Z, Node::molecule, SimParameters::monteCarloAcceptanceRate, SimParameters::monteCarloAdjustmentFreq, ControllerBroadcasts::monteCarloBarostatAcceptance, ControllerState::monteCarloMaxVolume, SimParameters::monteCarloPressureFreq, SimParameters::monteCarloPressureOn, SimParameters::monteCarloPressureTarget, SimParameters::monteCarloTemp, Molecule::numMolecules, Node::Object(), SimParameters::outputEnergies, SimpleBroadcastObject< T >::publish(), random, reduction, RequireReduction::require(), simParams, state, SimParameters::surfaceTensionTarget, Random::uniform(), SimParameters::useConstantArea, SimParameters::useConstantRatio, SimParameters::useFlexibleCell, Lattice::volume(), Vector::x, Vector::y, and Vector::z.

1122 {
1124  if ( !(step % simParams->monteCarloPressureFreq) ) {
1125  Node *node = Node::Object();
1126  Molecule *molecule = node->molecule;
1127  // need to consider the fix atom case!
1128  int numAtom = molecule->numMolecules;
1129  BigReal volumeOld = mc_oldLattice.volume();
1130  BigReal volumeNew = state->lattice.volume();
1131  BigReal areaNew = (volumeNew / state->lattice.c().z);
1132  BigReal areaOld = (volumeOld / mc_oldLattice.c().z);
1134  BigReal pressureTarget = simParams->monteCarloPressureTarget;
1135  BigReal surfTensionTarget = simParams->surfaceTensionTarget;
1136 
1137  if(!simParams->CUDASOAintegrate) {
1138  // Wait here for Sequencer to finish scaling coordinates and energy/force computation
1139  reduction->require();
1140  }
1141 
1142  BigReal totalEnergyOld = mc_totalEnergyOld;
1143  BigReal totalEnergyNew = getTotalPotentialEnergy(step);
1144  BigReal weight = (totalEnergyNew - totalEnergyOld);
1145  weight += (pressureTarget * (volumeNew - volumeOld));
1146  weight -= (numAtom * kbT * log(volumeNew / volumeOld));
1147  weight -= (surfTensionTarget * (areaNew - areaOld));
1148  BigReal totalWeight = exp(-weight / kbT);
1149  int accepted = (random->uniform() < totalWeight);
1150  //accepted = 0;
1151  #if 0
1152  printf("MC-data (accept): step: %d, Pe: %d, numAtom: %d\n", step, CkMyPe(), numAtom);
1153  printf(" oldE: %f, newE: %f, deltaE: %f\n", totalEnergyOld, totalEnergyNew, totalEnergyNew - totalEnergyOld);
1154  printf(" oldV: %f, newV: %f, deltaV: %f\n", volumeOld, volumeNew, volumeNew - volumeOld);
1155  printf(" surfTen: %f, deltaA: %f \n", surfTensionTarget, areaNew - areaOld);
1156  printf(" weight: %f, accepted: %d\n\n", totalWeight, accepted);
1157  #endif
1158  if(accepted) {
1159  // what should I do if its accepted?
1160  ++mc_totalAccept;
1162  } else {
1163  // what should I do if its rejected?
1164  state->lattice = mc_oldLattice;
1165  }
1166  // update the maximum scale no matter if it's accepted or not
1167  {
1169  BigReal factor = 1.0;
1171  // safe check to make sure there is any accepted move
1172  if (accRate > 0.0) {
1173  factor = accRate / simParams->monteCarloAcceptanceRate;
1174  } else {
1175  factor = 0.5; // if no move was accepted, we scale by half
1176  }
1177  // reset the trial for picked axis
1179  BigReal maxVolume = state->lattice.volume() * 0.3;
1180  switch (mc_picked_axis) {
1181  case MC_X:
1182  monteCarloMaxVolume.x *= factor;
1183  if (monteCarloMaxVolume.x < 0.001) {
1184  iout << iWARN << "Small volume change in MC barostat!\n" << endi;
1185  iout << iWARN << "Maximum volume change is set to 0.001 A^3.\n" << endi;
1186  monteCarloMaxVolume.x = 0.001;
1187  } else if (monteCarloMaxVolume.x > maxVolume ) {
1188  iout << iWARN << "Large volume change in MC barostat!\n" << endi;
1189  iout << iWARN << "Maximum volume change is set to " << maxVolume << " A^3.\n" << endi;
1190  monteCarloMaxVolume.x = maxVolume;
1191  }
1192  break;
1193 
1194  case MC_Y:
1195  monteCarloMaxVolume.y *= factor;
1196  if (monteCarloMaxVolume.y < 0.001) {
1197  iout << iWARN << "Small volume change in MC barostat!\n" << endi;
1198  iout << iWARN << "Maximum volume change is set to 0.001 A^3.\n" << endi;
1199  monteCarloMaxVolume.y = 0.001;
1200  } else if (monteCarloMaxVolume.y > maxVolume ) {
1201  iout << iWARN << "Large volume change in MC barostat!\n" << endi;
1202  iout << iWARN << "Maximum volume change is set to " << maxVolume << " A^3.\n" << endi;
1203  monteCarloMaxVolume.y = maxVolume;
1204  }
1205  break;
1206 
1207  case MC_Z:
1208  monteCarloMaxVolume.z *= factor;
1209  if (monteCarloMaxVolume.z < 0.001) {
1210  iout << iWARN << "Small volume change in MC barostat!\n" << endi;
1211  iout << iWARN << "Maximum volume change is set to 0.001 A^3.\n" << endi;
1212  monteCarloMaxVolume.z = 0.001;
1213  } else if (monteCarloMaxVolume.z > maxVolume ) {
1214  iout << iWARN << "Large volume change in MC barostat!\n" << endi;
1215  iout << iWARN << "Maximum volume change is set to " << maxVolume << " A^3.\n" << endi;
1216  monteCarloMaxVolume.z = maxVolume;
1217  }
1218  break;
1219  }
1220  }
1221  }
1222 
1223  if ( !(step % simParams->outputEnergies) ) {
1224  BigReal acceptPerc = 100.0 * ((BigReal) mc_totalAccept /
1225  (BigReal) mc_totalTry);
1226  iout << "MC_BAROSTAT STEP: " << step << " TRIALS: " << mc_totalTry <<
1227  " ACCEPTED: " << mc_totalAccept << " %ACCEPTANCE: " << acceptPerc;
1228  if (simParams->useFlexibleCell) {
1229  if (simParams->useConstantArea) {
1230  iout << " MAX_VOLUME_Z: " << monteCarloMaxVolume.z << "\n\n";
1231  } else if (simParams->useConstantRatio) {
1232  iout << " MAX_VOLUME_XY: " << monteCarloMaxVolume.x <<
1233  " MAX_VOLUME_Z: " << monteCarloMaxVolume.z << "\n\n";
1234  } else {
1235  iout << " MAX_VOLUME_X: " << monteCarloMaxVolume.x
1236  << " MAX_VOLUME_Y: " << monteCarloMaxVolume.y
1237  << " MAX_VOLUME_Z: " << monteCarloMaxVolume.z
1238  << "\n\n";
1239  }
1240  } else {
1241  iout << " MAX_VOLUME_XYZ: " << monteCarloMaxVolume.x << "\n\n";
1242  }
1243  }
1244 
1246  #ifdef NODEGROUP_FORCE_REGISTER
1247  publishedMCAcceptance.insert({step, accepted});
1248  #endif
1249  }
1250  }
1251 }
static Node * Object()
Definition: Node.h:86
BigReal monteCarloAcceptanceRate
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
BigReal uniform(void)
Definition: Random.h:109
Bool monteCarloPressureOn
#define BOLTZMANN
Definition: common.h:54
Definition: Node.h:78
int mc_accept[MC_AXIS_TOTAL]
Definition: Controller.h:316
BigReal surfaceTensionTarget
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
int monteCarloAdjustmentFreq
#define iout
Definition: InfoStream.h:51
int mc_trial[MC_AXIS_TOTAL]
Definition: Controller.h:316
Molecule stores the structural information for the system.
Definition: Molecule.h:175
BigReal mc_totalEnergyOld
Definition: Controller.h:319
SimpleBroadcastObject< int > monteCarloBarostatAcceptance
Definition: Broadcasts.h:83
NamdState *const state
Definition: Controller.h:349
void require(void)
Definition: ReductionMgr.h:342
ControllerBroadcasts * broadcast
Definition: Controller.h:365
int mc_picked_axis
Definition: Controller.h:318
Lattice mc_oldLattice
Definition: Controller.h:320
int numMolecules
Number of molecules.
Definition: Molecule.h:617
BigReal x
Definition: Vector.h:74
int monteCarloPressureFreq
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
void publish(int tag, const T &t)
Random * random
Definition: Controller.h:347
BigReal monteCarloTemp
int mc_totalTry
Definition: Controller.h:317
BigReal y
Definition: Vector.h:74
Vector monteCarloMaxVolume
Definition: Controller.h:101
SimParameters *const simParams
Definition: Controller.h:348
RequireReduction * reduction
Definition: Controller.h:350
BigReal monteCarloPressureTarget
Molecule * molecule
Definition: Node.h:179
BigReal getTotalPotentialEnergy(int step)
Definition: Controller.C:3746
double BigReal
Definition: common.h:123
int mc_totalAccept
Definition: Controller.h:317

◆ monteCarloPressure_prepare()

void Controller::monteCarloPressure_prepare ( int  step)
protected

Perform a random walk in volume and calculate the rescale factor for lattice and atom coordinates.

Definition at line 1253 of file Controller.C.

References broadcast, SimParameters::CUDASOAintegrate, SimParameters::fixCellDims, SimParameters::fixCellDimX, SimParameters::fixCellDimY, SimParameters::fixCellDimZ, getTotalPotentialEnergy(), Tensor::identity(), mc_oldLattice, mc_picked_axis, mc_totalEnergyOld, mc_totalTry, mc_trial, MC_X, MC_Y, MC_Z, ControllerState::monteCarloMaxVolume, SimParameters::monteCarloPressureFreq, SimParameters::monteCarloPressureOn, ControllerBroadcasts::positionRescaleFactor, SimpleBroadcastObject< T >::publish(), random, reduction, RequireReduction::require(), Lattice::rescale(), simParams, state, Random::uniform(), SimParameters::useConstantArea, SimParameters::useConstantRatio, SimParameters::useFlexibleCell, Lattice::volume(), Vector::x, Tensor::xx, Vector::y, Tensor::yy, Vector::z, and Tensor::zz.

1254 {
1256  if ( !(step % simParams->monteCarloPressureFreq) ) {
1257  if(!simParams->CUDASOAintegrate) {
1258  // Wait here for Sequencer to finish energy/force computation
1259  reduction->require();
1260  }
1261  mc_oldLattice = state->lattice;
1263  Tensor factor = Tensor::identity(1.0);
1264  // pick a random deltaV and calc scaling factor
1265  {
1266  BigReal oldVolume = mc_oldLattice.volume();
1267  bool flexible = simParams->useFlexibleCell;
1268  bool constArea = simParams->useConstantArea;
1269  bool constRatio = simParams->useConstantRatio;
1270  bool constZ, constY, constX;
1271  if (simParams->fixCellDims) {
1272  constX = simParams->fixCellDimX;
1273  constY = simParams->fixCellDimY;
1274  constZ = simParams->fixCellDimZ;
1275  } else {
1276  constZ = constY = constX = false;
1277  }
1278 
1279  if(flexible) {
1280  //Anisotropic fluctuation
1281  if(constArea) {
1282  // always pick z
1283  mc_picked_axis = MC_Z;
1284  BigReal dV = monteCarloMaxVolume.z * (2.0 * random->uniform() - 1.0);
1285  factor.zz = (oldVolume + dV) / oldVolume;
1286  } else if (constRatio) {
1287  while(true) {
1288  // decide to scale x-y or scale z
1289  BigReal probAxis = 2.0 * random->uniform();
1290  if (probAxis < 1.0) {
1291  //picking x or y. We use MC_X for constant ratio
1292  mc_picked_axis = MC_X;
1293  BigReal dV = monteCarloMaxVolume.x * (2.0 * random->uniform() - 1.0);
1294  BigReal scale = sqrt((oldVolume + dV)/oldVolume);
1295  factor.xx = factor.yy = scale;
1296  break;
1297  } else if (probAxis < 2.0 && !constZ) {
1298  //picking z
1299  mc_picked_axis = MC_Z;
1300  BigReal dV = monteCarloMaxVolume.z * (2.0 * random->uniform() - 1.0);
1301  BigReal scale = (oldVolume + dV)/oldVolume;
1302  factor.zz = scale;
1303  break;
1304  }
1305  }
1306  } else {
1307  while(true) {
1308  // decide to scale x, y or z
1309  BigReal probAxis = 3.0 * random->uniform();
1310  if (probAxis < 1.0 && !constX) {
1311  // picking x
1312  mc_picked_axis = MC_X;
1313  BigReal dV = monteCarloMaxVolume.x * (2.0 * random->uniform() - 1.0);
1314  factor.xx = (oldVolume + dV) / oldVolume;
1315  break;
1316  } else if (probAxis < 2.0 && !constY) {
1317  // picking y
1318  mc_picked_axis = MC_Y;
1319  BigReal dV = monteCarloMaxVolume.y * (2.0 * random->uniform() - 1.0);
1320  factor.yy = (oldVolume + dV) / oldVolume;
1321  break;
1322  } else if (probAxis < 3.0 && !constZ) {
1323  // picking z
1324  mc_picked_axis = MC_Z;
1325  BigReal dV = monteCarloMaxVolume.z * (2.0 * random->uniform() - 1.0);
1326  factor.zz = (oldVolume + dV) / oldVolume;
1327  break;
1328  }
1329  }
1330  }
1331  } else {
1332  //Isotropic fluctuation. We use MC_X for isotropic fluctuation
1333  mc_picked_axis = MC_X;
1334  BigReal dV = monteCarloMaxVolume.x * (2.0 * random->uniform() - 1.0);
1335  BigReal scale = pow((oldVolume + dV)/oldVolume, 1.0/3.0);
1336  factor.xx = factor.yy = factor.zz = scale;
1337  }
1338  // increament the MC trial
1339  ++mc_totalTry;
1341  }
1342 
1343  broadcast->positionRescaleFactor.publish(step,factor);
1344  state->lattice.rescale(factor);
1345  #ifdef NODEGROUP_FORCE_REGISTER
1346  publishedRescaleFactors.insert({step, factor});
1347  #endif
1348  }
1349  }
1350 }
NAMD_HOST_DEVICE void rescale(Tensor factor)
Definition: Lattice.h:60
BigReal uniform(void)
Definition: Random.h:109
Bool monteCarloPressureOn
BigReal z
Definition: Vector.h:74
int mc_trial[MC_AXIS_TOTAL]
Definition: Controller.h:316
static NAMD_HOST_DEVICE Tensor identity(BigReal v1=1.0)
Definition: Tensor.h:31
BigReal mc_totalEnergyOld
Definition: Controller.h:319
NamdState *const state
Definition: Controller.h:349
void require(void)
Definition: ReductionMgr.h:342
ControllerBroadcasts * broadcast
Definition: Controller.h:365
int mc_picked_axis
Definition: Controller.h:318
Lattice mc_oldLattice
Definition: Controller.h:320
BigReal x
Definition: Vector.h:74
int monteCarloPressureFreq
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
void publish(int tag, const T &t)
Random * random
Definition: Controller.h:347
BigReal xx
Definition: Tensor.h:17
SimpleBroadcastObject< Tensor > positionRescaleFactor
Definition: Broadcasts.h:71
BigReal zz
Definition: Tensor.h:19
int mc_totalTry
Definition: Controller.h:317
Definition: Tensor.h:15
BigReal y
Definition: Vector.h:74
Vector monteCarloMaxVolume
Definition: Controller.h:101
BigReal yy
Definition: Tensor.h:18
SimParameters *const simParams
Definition: Controller.h:348
RequireReduction * reduction
Definition: Controller.h:350
BigReal getTotalPotentialEnergy(int step)
Definition: Controller.C:3746
double BigReal
Definition: common.h:123

◆ multigatorCalcEnthalpy()

BigReal Controller::multigatorCalcEnthalpy ( BigReal  potentialEnergy,
int  step,
int  minimize 
)
protected

Definition at line 1090 of file Controller.C.

References BOLTZMANN, controlNumDegFreedom, kineticEnergy, Node::molecule, SimParameters::multigratorNoseHooverChainLength, multigratorNu, multigratorOmega, SimParameters::multigratorPressureRelaxationTime, SimParameters::multigratorPressureTarget, SimParameters::multigratorTemperatureTarget, multigratorXi, multigratorZeta, numDegFreedom, Node::Object(), Node::simParameters, simParams, state, and Lattice::volume().

Referenced by printEnergies().

1090  {
1091  Node *node = Node::Object();
1092  Molecule *molecule = node->molecule;
1093  SimParameters *simParameters = node->simParameters;
1094 
1095  BigReal V = state->lattice.volume();
1099  BigReal Nf = numDegFreedom;
1101  BigReal sumZeta = 0.0;
1102  for (int i=1;i < simParams->multigratorNoseHooverChainLength;i++) {
1103  sumZeta += multigratorZeta[i];
1104  }
1105  BigReal nuOmegaSum = 0.0;
1106  for (int i=0;i < simParams->multigratorNoseHooverChainLength;i++) {
1107  nuOmegaSum += multigratorNu[i]*multigratorNu[i]/(2.0*multigratorOmega[i]);
1108  }
1109  BigReal W = (3.0*NG + 1.0)*kT0*tauV*tauV;
1110  BigReal eta = sqrt(kT0*W)*multigratorXi;
1111 
1112  BigReal enthalpy = kineticEnergy + potentialEnergy + eta*eta/(2.0*W) + P0*V + nuOmegaSum + kT0*(Nf*multigratorZeta[0] + sumZeta);
1113 
1114 // if (!(step % 100))
1115  // fprintf(stderr, "enthalpy %lf %lf %lf %lf %lf %lf %lf\n", enthalpy,
1116  // kineticEnergy, potentialEnergy, eta*eta/(2.0*W), P0*V, nuOmegaSum, kT0*(Nf*multigratorZeta[0] + sumZeta));
1117 
1118  return enthalpy;
1119 }
static Node * Object()
Definition: Node.h:86
#define BOLTZMANN
Definition: common.h:54
Definition: Node.h:78
SimParameters * simParameters
Definition: Node.h:181
BigReal multigratorPressureTarget
std::vector< BigReal > multigratorOmega
Definition: Controller.h:329
Molecule stores the structural information for the system.
Definition: Molecule.h:175
std::vector< BigReal > multigratorNu
Definition: Controller.h:327
NamdState *const state
Definition: Controller.h:349
int64_t numDegFreedom
Definition: Controller.h:186
std::vector< BigReal > multigratorZeta
Definition: Controller.h:330
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
int multigratorNoseHooverChainLength
BigReal multigratorTemperatureTarget
BigReal multigratorPressureRelaxationTime
SimParameters *const simParams
Definition: Controller.h:348
Molecule * molecule
Definition: Node.h:179
int controlNumDegFreedom
Definition: Controller.h:254
BigReal multigratorXi
Definition: Controller.h:323
BigReal kineticEnergy
Definition: Controller.h:243
double BigReal
Definition: common.h:123

◆ multigratorPressure()

void Controller::multigratorPressure ( int  step,
int  callNumber 
)
protected

Definition at line 949 of file Controller.C.

References BOLTZMANN, broadcast, calcPressure(), controlNumDegFreedom, controlPressure, SimParameters::dt, GET_TENSOR, GET_VECTOR, Tensor::identity(), RequireReduction::item(), kineticEnergy, momentumSqrSum, SimParameters::multigratorOn, SimParameters::multigratorPressureFreq, SimParameters::multigratorPressureRelaxationTime, SimParameters::multigratorPressureTarget, SimParameters::multigratorTemperatureTarget, multigratorXi, multigratorXiT, numDegFreedom, ControllerBroadcasts::positionRescaleFactor, ControllerBroadcasts::positionRescaleFactor2, SimpleBroadcastObject< T >::publish(), reduction, REDUCTION_CENTERED_KINETIC_ENERGY, RequireReduction::require(), Lattice::rescale(), simParams, state, temperature, ControllerBroadcasts::velocityRescaleTensor, ControllerBroadcasts::velocityRescaleTensor2, and Lattice::volume().

Referenced by integrate().

949  {
954  BigReal NGfac = 1.0/sqrt(3.0*NG + 1.0);
957  {
958  // Compute new scaling factors and send them to Sequencer
959  BigReal V = state->lattice.volume();
960  BigReal Pinst = trace(controlPressure)/3.0;
961  BigReal PGsum = trace(momentumSqrSum);
962  //
963  multigratorXiT = multigratorXi + 0.5*s*NGfac/kT0*( 3.0*V*(Pinst - P0) + PGsum/NG );
964  BigReal scale = exp(s*NGfac*multigratorXiT);
965  BigReal velScale = exp(-s*NGfac*(1.0 + 1.0/NG)*multigratorXiT);
966  // fprintf(stderr, "%d | T %lf P %lf V %1.3lf\n", step, temperature, Pinst*PRESSUREFACTOR, V);
967  Tensor scaleTensor = Tensor::identity(scale);
968  Tensor volScaleTensor = Tensor::identity(scale);
969  Tensor velScaleTensor = Tensor::identity(velScale);
970  state->lattice.rescale(volScaleTensor);
971  if (callNumber == 1) {
972  broadcast->positionRescaleFactor.publish(step,scaleTensor);
973  broadcast->velocityRescaleTensor.publish(step,velScaleTensor);
974  } else {
975  broadcast->positionRescaleFactor2.publish(step,scaleTensor);
976  broadcast->velocityRescaleTensor2.publish(step,velScaleTensor);
977  }
978  }
979 
980  {
981  // Wait here for Sequencer to finish scaling and force computation
982  reduction->require();
983  Tensor virial_normal;
984  Tensor virial_nbond;
985  Tensor virial_slow;
986  Tensor intVirial_normal;
987  Tensor intVirial_nbond;
988  Tensor intVirial_slow;
989  Vector extForce_normal;
990  Vector extForce_nbond;
991  Vector extForce_slow;
992  GET_TENSOR(momentumSqrSum, reduction, REDUCTION_MOMENTUM_SQUARED);
993  GET_TENSOR(virial_normal, reduction, REDUCTION_VIRIAL_NORMAL);
994  GET_TENSOR(virial_nbond, reduction, REDUCTION_VIRIAL_NBOND);
995  GET_TENSOR(virial_slow, reduction, REDUCTION_VIRIAL_SLOW);
996  GET_TENSOR(intVirial_normal, reduction, REDUCTION_INT_VIRIAL_NORMAL);
997  GET_TENSOR(intVirial_nbond, reduction, REDUCTION_INT_VIRIAL_NBOND);
998  GET_TENSOR(intVirial_slow, reduction, REDUCTION_INT_VIRIAL_SLOW);
999  GET_VECTOR(extForce_normal, reduction, REDUCTION_EXT_FORCE_NORMAL);
1000  GET_VECTOR(extForce_nbond, reduction, REDUCTION_EXT_FORCE_NBOND);
1001  GET_VECTOR(extForce_slow, reduction, REDUCTION_EXT_FORCE_SLOW);
1002  calcPressure(step, 0, virial_normal, virial_nbond, virial_slow,
1003  intVirial_normal, intVirial_nbond, intVirial_slow,
1004  extForce_normal, extForce_nbond, extForce_slow);
1005  if (callNumber == 2) {
1006  // Update temperature for the Temperature Cycle that is coming next
1009  }
1010  }
1011 
1012  {
1013  // Update pressure integrator
1014  BigReal V = state->lattice.volume();
1015  BigReal Pinst = trace(controlPressure)/3.0;
1016  BigReal PGsum = trace(momentumSqrSum);
1017  //
1018  multigratorXi = multigratorXiT + 0.5*s*NGfac/kT0*( 3.0*V*(Pinst - P0) + PGsum/NG );
1019  }
1020 
1021  }
1022 }
NAMD_HOST_DEVICE void rescale(Tensor factor)
Definition: Lattice.h:60
void calcPressure(int step, int minimize, const Tensor &virial_normal_in, const Tensor &virial_nbond_in, const Tensor &virial_slow_in, const Tensor &intVirial_normal, const Tensor &intVirial_nbond, const Tensor &intVirial_slow, const Vector &extForce_normal, const Vector &extForce_nbond, const Vector &extForce_slow)
Definition: Controller.C:2102
#define BOLTZMANN
Definition: common.h:54
Tensor controlPressure
Definition: Controller.h:255
Definition: Vector.h:72
BigReal multigratorPressureTarget
#define GET_TENSOR(O, R, A)
Definition: ReductionMgr.h:60
static NAMD_HOST_DEVICE Tensor identity(BigReal v1=1.0)
Definition: Tensor.h:31
BigReal temperature
Definition: Controller.h:246
NamdState *const state
Definition: Controller.h:349
void require(void)
Definition: ReductionMgr.h:342
ControllerBroadcasts * broadcast
Definition: Controller.h:365
int64_t numDegFreedom
Definition: Controller.h:186
SimpleBroadcastObject< Tensor > velocityRescaleTensor2
Definition: Broadcasts.h:74
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
BigReal multigratorTemperatureTarget
#define GET_VECTOR(O, R, A)
Definition: ReductionMgr.h:55
BigReal multigratorPressureRelaxationTime
void publish(int tag, const T &t)
SimpleBroadcastObject< Tensor > positionRescaleFactor
Definition: Broadcasts.h:71
Definition: Tensor.h:15
BigReal item(int i) const
Definition: ReductionMgr.h:341
int multigratorPressureFreq
SimParameters *const simParams
Definition: Controller.h:348
RequireReduction * reduction
Definition: Controller.h:350
SimpleBroadcastObject< Tensor > positionRescaleFactor2
Definition: Broadcasts.h:76
SimpleBroadcastObject< Tensor > velocityRescaleTensor
Definition: Broadcasts.h:73
int controlNumDegFreedom
Definition: Controller.h:254
BigReal multigratorXiT
Definition: Controller.h:324
BigReal multigratorXi
Definition: Controller.h:323
BigReal kineticEnergy
Definition: Controller.h:243
Tensor momentumSqrSum
Definition: Controller.h:325
double BigReal
Definition: common.h:123

◆ multigratorTemperature()

void Controller::multigratorTemperature ( int  step,
int  callNumber 
)
protected

Definition at line 1024 of file Controller.C.

References BOLTZMANN, broadcast, SimParameters::dt, GET_TENSOR, RequireReduction::item(), kineticEnergy, momentumSqrSum, MULTIGRATOR_REDUCTION_KINETIC_ENERGY, SimParameters::multigratorNoseHooverChainLength, multigratorNu, multigratorNuT, multigratorOmega, SimParameters::multigratorOn, SimParameters::multigratorPressureFreq, multigratorReduction, SimParameters::multigratorTemperatureFreq, SimParameters::multigratorTemperatureRelaxationTime, SimParameters::multigratorTemperatureTarget, multigratorZeta, numDegFreedom, SimpleBroadcastObject< T >::publish(), RequireReduction::require(), simParams, temperature, ControllerBroadcasts::velocityRescaleFactor, and ControllerBroadcasts::velocityRescaleFactor2.

Referenced by integrate().

1024  {
1029  BigReal Nf = numDegFreedom;
1031  BigReal T1, T2, v;
1032  {
1033  T1 = temperature;
1034  BigReal kTinst = BOLTZMANN * temperature;
1035  for (int i=n-1;i >= 0;i--) {
1036  if (i == 0) {
1037  BigReal NuOmega = (n > 1) ? multigratorNuT[1]/multigratorOmega[1] : 0.0;
1038  multigratorNuT[0] = exp(-0.5*t*NuOmega)*multigratorNu[0] + 0.5*Nf*t*exp(-0.25*t*NuOmega)*(kTinst - kT0);
1039  } else if (i == n-1) {
1040  multigratorNuT[n-1] = multigratorNu[n-1] + 0.5*t*(pow(multigratorNu[n-2],2.0)/multigratorOmega[n-2] - kT0);
1041  } else {
1042  BigReal NuOmega = multigratorNuT[i+1]/multigratorOmega[i+1];
1043  multigratorNuT[i] = exp(-0.5*t*NuOmega)*multigratorNu[i] +
1044  0.5*t*exp(-0.25*t*NuOmega)*(pow(multigratorNu[i-1],2.0)/multigratorOmega[i-1] - kT0);
1045  }
1046  }
1047  BigReal velScale = exp(-t*multigratorNuT[0]/multigratorOmega[0]);
1048  v = velScale;
1049  if (callNumber == 1)
1050  broadcast->velocityRescaleFactor.publish(step,velScale);
1051  else
1052  broadcast->velocityRescaleFactor2.publish(step,velScale);
1053  }
1054 
1055  {
1056  // Wait here for Sequencer to finish scaling and re-calculating kinetic energy
1060  T2 = temperature;
1061  if (callNumber == 1 && !(step % simParams->multigratorPressureFreq)) {
1062  // If this is pressure cycle, receive new momentum product
1063  GET_TENSOR(momentumSqrSum, multigratorReduction, MULTIGRATOR_REDUCTION_MOMENTUM_SQUARED);
1064  }
1065  }
1066 
1067  // fprintf(stderr, "%d | T %lf scale %lf T' %lf\n", step, T1, v, T2);
1068 
1069  {
1070  BigReal kTinst = BOLTZMANN * temperature;
1071  for (int i=0;i < n;i++) {
1072  if (i == 0) {
1073  BigReal NuOmega = (n > 1) ? multigratorNuT[1]/multigratorOmega[1] : 0.0;
1074  multigratorNu[0] = exp(-0.5*t*NuOmega)*multigratorNuT[0] + 0.5*Nf*t*exp(-0.25*t*NuOmega)*(kTinst - kT0);
1075  } else if (i == n-1) {
1076  multigratorNu[n-1] = multigratorNuT[n-1] + 0.5*t*(pow(multigratorNu[n-2],2.0)/multigratorOmega[n-2] - kT0);
1077  } else {
1078  BigReal NuOmega = multigratorNuT[i+1]/multigratorOmega[i+1];
1079  multigratorNu[i] = exp(-0.5*t*NuOmega)*multigratorNuT[i] +
1080  0.5*t*exp(-0.25*t*NuOmega)*(pow(multigratorNu[i-1],2.0)/multigratorOmega[i-1] - kT0);
1081  }
1083  }
1084  }
1085 
1086  }
1087 }
#define BOLTZMANN
Definition: common.h:54
std::vector< BigReal > multigratorOmega
Definition: Controller.h:329
std::vector< BigReal > multigratorNuT
Definition: Controller.h:328
#define GET_TENSOR(O, R, A)
Definition: ReductionMgr.h:60
BigReal temperature
Definition: Controller.h:246
std::vector< BigReal > multigratorNu
Definition: Controller.h:327
void require(void)
Definition: ReductionMgr.h:342
ControllerBroadcasts * broadcast
Definition: Controller.h:365
int64_t numDegFreedom
Definition: Controller.h:186
std::vector< BigReal > multigratorZeta
Definition: Controller.h:330
SimpleBroadcastObject< BigReal > velocityRescaleFactor2
Definition: Broadcasts.h:75
RequireReduction * multigratorReduction
Definition: Controller.h:331
int multigratorNoseHooverChainLength
BigReal multigratorTemperatureTarget
SimpleBroadcastObject< BigReal > velocityRescaleFactor
Definition: Broadcasts.h:70
void publish(int tag, const T &t)
BigReal multigratorTemperatureRelaxationTime
BigReal item(int i) const
Definition: ReductionMgr.h:341
int multigratorPressureFreq
SimParameters *const simParams
Definition: Controller.h:348
int multigratorTemperatureFreq
BigReal kineticEnergy
Definition: Controller.h:243
Tensor momentumSqrSum
Definition: Controller.h:325
double BigReal
Definition: common.h:123

◆ outputExtendedSystem()

void Controller::outputExtendedSystem ( int  step)
protected

Definition at line 5042 of file Controller.C.

References ofstream_namd::clear(), ofstream_namd::close(), END_OF_RUN, endi(), FILE_OUTPUT, SimParameters::firstTimestep, ofstream_namd::flush(), iout, ofstream_namd::is_open(), SimParameters::N, NAMD_backup_file(), NAMD_err(), NAMD_FILENAME_BUFFER_SIZE, ofstream_namd::open(), SimParameters::outputFilename, SimParameters::restartFilename, SimParameters::restartFrequency, SimParameters::restartSave, simParams, writeExtendedSystemData(), writeExtendedSystemLabels(), xstFile, SimParameters::xstFilename, and SimParameters::xstFrequency.

Referenced by algorithm(), and integrate().

5043 {
5044 
5045  if ( step >= 0 ) {
5046 
5047  // Write out eXtended System Trajectory (XST) file
5048  if ( simParams->xstFrequency &&
5049  ((step % simParams->xstFrequency) == 0) )
5050  {
5051  if ( ! xstFile.is_open() )
5052  {
5053  iout << "OPENING EXTENDED SYSTEM TRAJECTORY FILE\n" << endi;
5056  while (!xstFile) {
5057  if ( errno == EINTR ) {
5058  CkPrintf("Warning: Interrupted system call opening XST trajectory file, retrying.\n");
5059  xstFile.clear();
5061  continue;
5062  }
5063  char err_msg[257];
5064  sprintf(err_msg, "Error opening XST trajectory file %s",simParams->xstFilename);
5065  NAMD_err(err_msg);
5066  }
5067  xstFile << "# NAMD extended system trajectory file" << std::endl;
5069  }
5071  xstFile.flush();
5072  }
5073 
5074  // Write out eXtended System Configuration (XSC) files
5075  // Output a restart file
5076  if ( simParams->restartFrequency &&
5077  ((step % simParams->restartFrequency) == 0) &&
5078  (step != simParams->firstTimestep) )
5079  {
5080  iout << "WRITING EXTENDED SYSTEM TO RESTART FILE AT STEP "
5081  << step << "\n" << endi;
5082  char fname[NAMD_FILENAME_BUFFER_SIZE];
5083  const char *bsuffix = ".old";
5084  strcpy(fname, simParams->restartFilename);
5085  if ( simParams->restartSave ) {
5086  char timestepstr[20];
5087  sprintf(timestepstr,".%d",step);
5088  strcat(fname, timestepstr);
5089  bsuffix = ".BAK";
5090  }
5091  strcat(fname, ".xsc");
5092  NAMD_backup_file(fname,bsuffix);
5093  ofstream_namd xscFile(fname);
5094  while (!xscFile) {
5095  if ( errno == EINTR ) {
5096  CkPrintf("Warning: Interrupted system call opening XSC restart file, retrying.\n");
5097  xscFile.clear();
5098  xscFile.open(fname);
5099  continue;
5100  }
5101  char err_msg[257];
5102  sprintf(err_msg, "Error opening XSC restart file %s",fname);
5103  NAMD_err(err_msg);
5104  }
5105  xscFile << "# NAMD extended system configuration restart file" << std::endl;
5106  writeExtendedSystemLabels(xscFile);
5107  writeExtendedSystemData(step,xscFile);
5108  if (!xscFile) {
5109  char err_msg[257];
5110  sprintf(err_msg, "Error writing XSC restart file %s",fname);
5111  NAMD_err(err_msg);
5112  }
5113  }
5114 
5115  }
5116 
5117  // Output final coordinates
5118  if (step == FILE_OUTPUT || step == END_OF_RUN)
5119  {
5120  int realstep = ( step == FILE_OUTPUT ?
5122  iout << "WRITING EXTENDED SYSTEM TO OUTPUT FILE AT STEP "
5123  << realstep << "\n" << endi;
5124  static char fname[NAMD_FILENAME_BUFFER_SIZE];
5125  strcpy(fname, simParams->outputFilename);
5126  strcat(fname, ".xsc");
5127  NAMD_backup_file(fname);
5128  ofstream_namd xscFile(fname);
5129  while (!xscFile) {
5130  if ( errno == EINTR ) {
5131  CkPrintf("Warning: Interrupted system call opening XSC output file, retrying.\n");
5132  xscFile.clear();
5133  xscFile.open(fname);
5134  continue;
5135  }
5136  char err_msg[257];
5137  sprintf(err_msg, "Error opening XSC output file %s",fname);
5138  NAMD_err(err_msg);
5139  }
5140  xscFile << "# NAMD extended system configuration output file" << std::endl;
5141  writeExtendedSystemLabels(xscFile);
5142  writeExtendedSystemData(realstep,xscFile);
5143  if (!xscFile) {
5144  char err_msg[257];
5145  sprintf(err_msg, "Error writing XSC output file %s",fname);
5146  NAMD_err(err_msg);
5147  }
5148  }
5149 
5150  // Close trajectory file
5151  if (step == END_OF_RUN) {
5152  if ( xstFile.is_open() ) {
5153  xstFile.close();
5154  iout << "CLOSING EXTENDED SYSTEM TRAJECTORY FILE\n" << endi;
5155  }
5156  }
5157 
5158 }
void NAMD_err(const char *err_msg)
Definition: common.C:170
#define FILE_OUTPUT
Definition: Output.h:25
void writeExtendedSystemLabels(ofstream_namd &file)
Definition: Controller.C:4613
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
bool is_open() const
Definition: fstream_namd.h:30
ofstream_namd & flush()
Definition: fstream_namd.C:17
#define iout
Definition: InfoStream.h:51
#define NAMD_FILENAME_BUFFER_SIZE
Definition: common.h:45
char outputFilename[NAMD_FILENAME_BUFFER_SIZE]
ofstream_namd xstFile
Definition: Controller.h:366
void writeExtendedSystemData(int step, ofstream_namd &file)
Definition: Controller.C:4629
#define END_OF_RUN
Definition: Output.h:26
void NAMD_backup_file(const char *filename, const char *extension)
Definition: common.C:235
char restartFilename[NAMD_FILENAME_BUFFER_SIZE]
SimParameters *const simParams
Definition: Controller.h:348
char xstFilename[NAMD_FILENAME_BUFFER_SIZE]
void open(const char *_fname, std::ios_base::openmode _mode=std::ios_base::out)
Definition: fstream_namd.C:11

◆ outputFepEnergy()

void Controller::outputFepEnergy ( int  step)
protected

Definition at line 4693 of file Controller.C.

References SimParameters::alchEnsembleAvg, SimParameters::alchEquilSteps, SimParameters::alchFepOn, SimParameters::alchIDWSFreq, SimParameters::alchLambda, SimParameters::alchLambda2, SimParameters::alchLambdaIDWS, SimParameters::alchOn, SimParameters::alchOutFile, SimParameters::alchOutFreq, SimParameters::alchTemp, BOLTZMANN, bondedEnergyDiff_f, SimParameters::computeEnergies, dE, dG, electEnergy, electEnergy_f, electEnergySlow, electEnergySlow_f, endi(), exp_dE_ByRT, fepFile, FepNo, fepSum, SimParameters::firstTimestep, ofstream_namd::flush(), iout, ofstream_namd::is_open(), ljEnergy, ljEnergy_f, SimParameters::N, NAMD_backup_file(), net_dE, ofstream_namd::open(), simParams, and writeFepEnergyData().

Referenced by integrate().

4693  {
4694  if (simParams->alchOn && simParams->alchFepOn) {
4695  const int stepInRun = step - simParams->firstTimestep;
4696  const int alchEquilSteps = simParams->alchEquilSteps;
4697  const BigReal alchLambda = simParams->alchLambda;
4698  const bool alchEnsembleAvg = simParams->alchEnsembleAvg;
4699 
4700  if (alchEnsembleAvg && (stepInRun == 0 || stepInRun == alchEquilSteps)) {
4701  FepNo = 0;
4702  exp_dE_ByRT = 0.0;
4703  net_dE = 0.0;
4704  }
4708 
4709  if (alchEnsembleAvg && (simParams->alchLambdaIDWS < 0. ||
4710  (step / simParams->alchIDWSFreq) % 2 == 1 )
4711 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
4712  &&
4713  // some people rely on the ensemble averages (dE_avg and dG) in fep output for calculating the free energy changes.
4714  // in the GPU version, dE is only available every outputEnergies steps.
4715  // so I check if the step is multiples of outputEnergies here.
4716  // I am still not sure whether we should check the stepInRun or step.
4717  // JH: dE is also calculated at alchOutFreq
4718  (step % simParams->computeEnergies == 0 || step % simParams->alchOutFreq == 0)
4719 #endif
4720  ) {
4721  // with IDWS, only accumulate stats on those timesteps where target lambda is "forward"
4722  FepNo++;
4723  exp_dE_ByRT += exp(-dE/RT);
4724  net_dE += dE;
4725  }
4726 
4727  if (simParams->alchOutFreq) {
4728  if (stepInRun == 0) {
4729  if (!fepFile.is_open()) {
4732  iout << "OPENING FEP ENERGY OUTPUT FILE\n" << endi;
4733  if(alchEnsembleAvg){
4734  fepSum = 0.0;
4735  fepFile << "# STEP Elec "
4736  << "vdW dE dE_avg Temp dG\n"
4737  << "# l l+dl "
4738  << " l l+dl E(l+dl)-E(l)" << std::endl;
4739  }
4740  else{
4741  fepFile << "# STEP Elec "
4742  << "vdW dE Temp\n"
4743  << "# l l+dl "
4744  << " l l+dl E(l+dl)-E(l)" << std::endl;
4745  }
4746  }
4747  if(!step){
4748  fepFile << "#NEW FEP WINDOW: "
4749  << "LAMBDA SET TO " << alchLambda << " LAMBDA2 "
4750  << simParams->alchLambda2;
4751  if ( simParams->alchLambdaIDWS >= 0. ) {
4752  fepFile << " LAMBDA_IDWS " << simParams->alchLambdaIDWS;
4753  }
4754  fepFile << std::endl;
4755  }
4756  }
4757  if ((alchEquilSteps) && (stepInRun == alchEquilSteps)) {
4758  fepFile << "#" << alchEquilSteps << " STEPS OF EQUILIBRATION AT "
4759  << "LAMBDA " << simParams->alchLambda << " COMPLETED\n"
4760  << "#STARTING COLLECTION OF ENSEMBLE AVERAGE" << std::endl;
4761  }
4762  if ((simParams->N) && ((step%simParams->alchOutFreq) == 0)) {
4763  writeFepEnergyData(step, fepFile);
4764  fepFile.flush();
4765  }
4766  if (alchEnsembleAvg && (step == simParams->N)) {
4767  fepSum = fepSum + dG;
4768  fepFile << "#Free energy change for lambda window [ " << alchLambda
4769  << " " << simParams->alchLambda2 << " ] is " << dG
4770  << " ; net change until now is " << fepSum << std::endl;
4771  fepFile.flush();
4772  }
4773  }
4774  }
4775 }
BigReal net_dE
Definition: Controller.h:205
BigReal dG
Definition: Controller.h:206
BigReal fepSum
Definition: Controller.h:209
#define BOLTZMANN
Definition: common.h:54
BigReal ljEnergy
Definition: Controller.h:191
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal alchLambda2
BigReal electEnergySlow_f
Definition: Controller.h:200
bool is_open() const
Definition: fstream_namd.h:30
ofstream_namd & flush()
Definition: fstream_namd.C:17
#define iout
Definition: InfoStream.h:51
BigReal electEnergySlow
Definition: Controller.h:190
BigReal alchLambda
BigReal electEnergy_f
Definition: Controller.h:199
BigReal alchLambdaIDWS
BigReal bondedEnergyDiff_f
Definition: Controller.h:198
BigReal dE
Definition: Controller.h:204
char alchOutFile[NAMD_FILENAME_BUFFER_SIZE]
BigReal exp_dE_ByRT
Definition: Controller.h:203
void NAMD_backup_file(const char *filename, const char *extension)
Definition: common.C:235
BigReal alchTemp
BigReal electEnergy
Definition: Controller.h:189
BigReal ljEnergy_f
Definition: Controller.h:201
SimParameters *const simParams
Definition: Controller.h:348
ofstream_namd fepFile
Definition: Controller.h:372
void writeFepEnergyData(int step, ofstream_namd &file)
Definition: Controller.C:4982
void open(const char *_fname, std::ios_base::openmode _mode=std::ios_base::out)
Definition: fstream_namd.C:11
double BigReal
Definition: common.h:123

◆ outputTiEnergy()

void Controller::outputTiEnergy ( int  step)
protected

Definition at line 4777 of file Controller.C.

References SimParameters::alchEquilSteps, SimParameters::alchLambda, SimParameters::alchLambdaFreq, SimParameters::alchOn, SimParameters::alchOutFile, SimParameters::alchOutFreq, SimParameters::alchTemp, SimParameters::alchThermIntOn, alchWork, bondedEnergy_ti_1, bondedEnergy_ti_2, SimParameters::computeEnergies, electEnergy_ti_1, electEnergy_ti_2, electEnergyPME_ti_1, electEnergyPME_ti_2, electEnergySlow_ti_1, electEnergySlow_ti_2, endi(), SimParameters::firstTimestep, ofstream_namd::flush(), FORMAT(), SimParameters::getBondLambda(), SimParameters::getCurrentLambda2(), SimParameters::getElecLambda(), SimParameters::getLambdaDelta(), SimParameters::getVdwLambda(), iout, ofstream_namd::is_open(), ljEnergy_ti_1, ljEnergy_ti_2, NAMD_backup_file(), net_dEdl_bond_1, net_dEdl_bond_2, net_dEdl_elec_1, net_dEdl_elec_2, net_dEdl_lj_1, net_dEdl_lj_2, ofstream_namd::open(), recent_alchWork, recent_dEdl_bond_1, recent_dEdl_bond_2, recent_dEdl_elec_1, recent_dEdl_elec_2, recent_dEdl_lj_1, recent_dEdl_lj_2, recent_TiNo, simParams, tiFile, TiNo, and writeTiEnergyData().

Referenced by integrate().

4777  {
4779  const int stepInRun = step - simParams->firstTimestep;
4780  const int alchEquilSteps = simParams->alchEquilSteps;
4781  const int alchLambdaFreq = simParams->alchLambdaFreq;
4782 
4783  if (stepInRun == 0 || stepInRun == alchEquilSteps) {
4784  TiNo = 0;
4785  net_dEdl_bond_1 = 0;
4786  net_dEdl_bond_2 = 0;
4787  net_dEdl_elec_1 = 0;
4788  net_dEdl_elec_2 = 0;
4789  net_dEdl_lj_1 = 0;
4790  net_dEdl_lj_2 = 0;
4791  }
4792  // The energies are only computed if they are required to output in CUDA build.
4793  // In the case when step % simParams->computeEnergies != 0 the energies are 0.
4794  // All output terms in writeTiEnergyData use TiNo and recent_TiNo as denominators,
4795  // so the TiNo and recent_TiNo should NOT be increased.
4796 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
4797  if (step % simParams->computeEnergies == 0) {
4798 #endif
4799  TiNo++;
4808  // Compute global dE / dLambda for lambda-dynamics
4809  computeTIderivative();
4810 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
4811  }
4812 #endif
4813 
4814  // Don't accumulate block averages (you'll get a divide by zero!) or even
4815  // open the TI output if alchOutFreq is zero.
4816  if (simParams->alchOutFreq) {
4817  if (stepInRun == 0 || stepInRun == alchEquilSteps
4818  || (! ((step - 1) % simParams->alchOutFreq))) {
4819  // output of instantaneous dU/dl now replaced with running average
4820  // over last alchOutFreq steps (except for step 0)
4821  recent_TiNo = 0;
4822  recent_dEdl_bond_1 = 0;
4823  recent_dEdl_bond_2 = 0;
4824  recent_dEdl_elec_1 = 0;
4825  recent_dEdl_elec_2 = 0;
4826  recent_dEdl_lj_1 = 0;
4827  recent_dEdl_lj_2 = 0;
4828  recent_alchWork = 0;
4829  }
4830 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
4831  if (step % simParams->computeEnergies == 0) {
4832 #endif
4833  recent_TiNo++;
4837  + electEnergyPME_ti_1);
4839  + electEnergyPME_ti_2);
4843 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
4844  }
4845 #endif
4846 
4847  if (stepInRun == 0) {
4848  if (!tiFile.is_open()) {
4851  /* BKR - This has been rather drastically updated to better match
4852  stdout. This was necessary for several reasons:
4853  1) PME global scaling is obsolete (now removed)
4854  2) scaling of bonded terms was added
4855  3) alchemical work is now accumulated when switching is active
4856  */
4857  iout << "OPENING TI ENERGY OUTPUT FILE\n" << endi;
4858  tiFile << "#TITITLE: TS";
4859  tiFile << FORMAT("BOND1");
4860  tiFile << FORMAT("AVGBOND1");
4861  tiFile << FORMAT("ELECT1");
4862  tiFile << FORMAT("AVGELECT1");
4863  tiFile << " ";
4864  tiFile << FORMAT("VDW1");
4865  tiFile << FORMAT("AVGVDW1");
4866  tiFile << FORMAT("BOND2");
4867  tiFile << FORMAT("AVGBOND2");
4868  tiFile << FORMAT("ELECT2");
4869  tiFile << " ";
4870  tiFile << FORMAT("AVGELECT2");
4871  tiFile << FORMAT("VDW2");
4872  tiFile << FORMAT("AVGVDW2");
4873  if (alchLambdaFreq > 0) {
4874  tiFile << FORMAT("ALCHWORK");
4875  tiFile << FORMAT("CUMALCHWORK");
4876  }
4877  tiFile << std::endl;
4878  }
4879 
4880  if (alchLambdaFreq > 0) {
4881  tiFile << "#ALCHEMICAL SWITCHING ACTIVE "
4882  << simParams->alchLambda << " --> " << simParams->getCurrentLambda2(step)
4883  << "\n#LAMBDA SCHEDULE: "
4884  << "dL: " << simParams->getLambdaDelta()
4885  << " Freq: " << alchLambdaFreq;
4886  }
4887  else {
4888  const BigReal alchLambda = simParams->alchLambda;
4889  const BigReal bond_lambda_1 = simParams->getBondLambda(alchLambda);
4890  const BigReal bond_lambda_2 = simParams->getBondLambda(1-alchLambda);
4891  const BigReal elec_lambda_1 = simParams->getElecLambda(alchLambda);
4892  const BigReal elec_lambda_2 = simParams->getElecLambda(1-alchLambda);
4893  const BigReal vdw_lambda_1 = simParams->getVdwLambda(alchLambda);
4894  const BigReal vdw_lambda_2 = simParams->getVdwLambda(1-alchLambda);
4895  tiFile << "#NEW TI WINDOW: "
4896  << "LAMBDA " << alchLambda
4897  << "\n#PARTITION 1 SCALING: BOND " << bond_lambda_1
4898  << " VDW " << vdw_lambda_1 << " ELEC " << elec_lambda_1
4899  << "\n#PARTITION 2 SCALING: BOND " << bond_lambda_2
4900  << " VDW " << vdw_lambda_2 << " ELEC " << elec_lambda_2;
4901  }
4902  tiFile << "\n#CONSTANT TEMPERATURE: " << simParams->alchTemp << " K"
4903  << std::endl;
4904  }
4905 
4906  if ((alchEquilSteps) && (stepInRun == alchEquilSteps)) {
4907  tiFile << "#" << alchEquilSteps << " STEPS OF EQUILIBRATION AT "
4908  << "LAMBDA " << simParams->alchLambda << " COMPLETED\n"
4909  << "#STARTING COLLECTION OF ENSEMBLE AVERAGE" << std::endl;
4910  }
4911  if ((step%simParams->alchOutFreq) == 0) {
4912  writeTiEnergyData(step, tiFile);
4913  tiFile.flush();
4914  }
4915  }
4916  }
4917 }
ofstream_namd tiFile
Definition: Controller.h:376
BigReal electEnergy_ti_1
Definition: Controller.h:213
BigReal net_dEdl_lj_2
Definition: Controller.h:224
BigReal getBondLambda(const BigReal) const
BigReal net_dEdl_lj_1
Definition: Controller.h:223
BigReal net_dEdl_bond_2
Definition: Controller.h:220
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
bool is_open() const
Definition: fstream_namd.h:30
ofstream_namd & flush()
Definition: fstream_namd.C:17
BigReal recent_alchWork
Definition: Controller.h:235
#define iout
Definition: InfoStream.h:51
BigReal getElecLambda(const BigReal) const
BigReal recent_dEdl_bond_2
Definition: Controller.h:230
BigReal alchLambda
BigReal alchWork
Definition: Controller.h:236
BigReal ljEnergy_ti_1
Definition: Controller.h:215
BigReal recent_dEdl_elec_2
Definition: Controller.h:232
BigReal recent_dEdl_elec_1
Definition: Controller.h:231
int recent_TiNo
Definition: Controller.h:237
BigReal electEnergySlow_ti_1
Definition: Controller.h:214
static char * FORMAT(BigReal X, int decimal=4)
Definition: Controller.C:1830
BigReal electEnergyPME_ti_1
Definition: Controller.h:226
char alchOutFile[NAMD_FILENAME_BUFFER_SIZE]
void NAMD_backup_file(const char *filename, const char *extension)
Definition: common.C:235
BigReal electEnergy_ti_2
Definition: Controller.h:216
BigReal net_dEdl_elec_1
Definition: Controller.h:221
BigReal alchTemp
BigReal recent_dEdl_lj_1
Definition: Controller.h:233
BigReal electEnergyPME_ti_2
Definition: Controller.h:227
BigReal getCurrentLambda2(const int) const
BigReal getLambdaDelta(void) const
BigReal getVdwLambda(const BigReal) const
BigReal electEnergySlow_ti_2
Definition: Controller.h:217
SimParameters *const simParams
Definition: Controller.h:348
BigReal net_dEdl_elec_2
Definition: Controller.h:222
BigReal recent_dEdl_lj_2
Definition: Controller.h:234
BigReal bondedEnergy_ti_2
Definition: Controller.h:212
void writeTiEnergyData(int step, ofstream_namd &file)
Definition: Controller.C:5018
void open(const char *_fname, std::ios_base::openmode _mode=std::ios_base::out)
Definition: fstream_namd.C:11
BigReal net_dEdl_bond_1
Definition: Controller.h:219
BigReal bondedEnergy_ti_1
Definition: Controller.h:211
double BigReal
Definition: common.h:123
BigReal ljEnergy_ti_2
Definition: Controller.h:218
BigReal recent_dEdl_bond_1
Definition: Controller.h:229

◆ printDynamicsEnergies()

void Controller::printDynamicsEnergies ( int  step)
protected

Definition at line 3741 of file Controller.C.

References compareChecksums(), and printEnergies().

Referenced by integrate().

3741  {
3742  compareChecksums(step);
3743  printEnergies(step,0);
3744 }
void compareChecksums(int, int=0)
Definition: Controller.C:3349
void printEnergies(int step, int minimize)
Definition: Controller.C:3842

◆ printEnergies()

void Controller::printEnergies ( int  step,
int  minimize 
)
protected

Definition at line 3842 of file Controller.C.

References Lattice::a(), Lattice::a_p(), MovingAverage::addSample(), SimParameters::alchEquilSteps, SimParameters::alchFepOn, SimParameters::alchLambdaFreq, SimParameters::alchOn, SimParameters::alchThermIntOn, alchWork, MovingAverage::average(), avg_count, Lattice::b(), Lattice::b_p(), bondedEnergy_ti_1, bondedEnergy_ti_2, bondedEnergyDiff_f, Lattice::c(), Lattice::c_p(), CALLBACKDATA, CALLBACKLIST, computeAlchWork(), SimParameters::computeEnergies, SimParameters::CUDASOAintegrate, cumAlchWork, drudeBondTemp, drudeBondTempAvg, SimParameters::drudeOn, SimParameters::dt, IMDEnergies::Eangle, IMDEnergies::Ebond, IMDEnergies::Edihe, IMDEnergies::Eelec, IMDEnergies::Eimpr, electEnergy, electEnergy_f, electEnergy_ti_1, electEnergy_ti_2, electEnergyPME_ti_1, electEnergyPME_ti_2, electEnergySlow, electEnergySlow_f, electEnergySlow_ti_1, electEnergySlow_ti_2, endi(), IMDEnergies::Epot, ETITLE(), IMDEnergies::Etot, IMDEnergies::Evdw, FEPTITLE2(), fflush_count, SimParameters::firstLdbStep, SimParameters::firstTimestep, FORMAT(), IMDOutput::gather_energies(), GET_VECTOR, SimParameters::getCurrentLambda(), SimParameters::getCurrentLambda2(), PressureProfileReduction::getData(), Molecule::getEnergyTailCorr(), Node::getScript(), SimParameters::goForcesOn, SimParameters::goGroPair, goNativeEnergy, goNonnativeEnergy, goTotalEnergy, groGaussEnergy, groLJEnergy, groupPressure, groupPressure_avg, groupPressure_tavg, groupPressureAverage, groupPressureAverage_xx, groupPressureAverage_xy, groupPressureAverage_xz, groupPressureAverage_yx, groupPressureAverage_yy, groupPressureAverage_yz, groupPressureAverage_zx, groupPressureAverage_zy, groupPressureAverage_zz, heat, iERROR(), iINFO(), Node::imd, SimParameters::IMDfreq, SimParameters::IMDon, iout, RequireReduction::item(), NodeReduction::item(), iWARN(), kineticEnergy, kineticEnergyCentered, kineticEnergyHalfstep, SimParameters::LJcorrection, SimParameters::LJcorrectionAlt, ljEnergy, ljEnergy_f, ljEnergy_ti_1, ljEnergy_ti_2, marginViolations, memusage_MB(), SimParameters::mergeCrossterms, minimize(), Node::molecule, multigatorCalcEnthalpy(), SimParameters::multigratorOn, SimParameters::N, NAMD_bug(), namdWallTimer(), nbondFreq, nodeReduction, SimParameters::nsPerDayOn, Node::Object(), Lattice::origin(), SimParameters::outputEnergies, SimParameters::outputEnergiesPrecision, SimParameters::outputMomenta, SimParameters::outputPairlists, SimParameters::outputPressure, SimParameters::pairInteractionOn, pairlistWarnings, SimParameters::PMEOn, ppbonded, ppint, ppnonbonded, pressure, pressure_avg, pressure_tavg, pressureAverage, pressureAverage_xx, pressureAverage_yx, pressureAverage_yy, pressureAverage_zx, pressureAverage_zy, pressureAverage_zz, PRESSUREFACTOR, pressureProfileAverage, pressureProfileCount, SimParameters::pressureProfileFreq, pressureProfileSlabs, printTiming(), SimParameters::qmForcesOn, reduction, REDUCTION_ANGLE_ENERGY, REDUCTION_BC_ENERGY, REDUCTION_BOND_ENERGY, REDUCTION_BONDED_ENERGY_F, REDUCTION_BONDED_ENERGY_TI_1, REDUCTION_BONDED_ENERGY_TI_2, REDUCTION_CROSSTERM_ENERGY, REDUCTION_DIHEDRAL_ENERGY, REDUCTION_ELECT_ENERGY, REDUCTION_ELECT_ENERGY_F, REDUCTION_ELECT_ENERGY_PME_TI_1, REDUCTION_ELECT_ENERGY_PME_TI_2, REDUCTION_ELECT_ENERGY_SLOW, REDUCTION_ELECT_ENERGY_SLOW_F, REDUCTION_ELECT_ENERGY_SLOW_TI_1, REDUCTION_ELECT_ENERGY_SLOW_TI_2, REDUCTION_ELECT_ENERGY_TI_1, REDUCTION_ELECT_ENERGY_TI_2, REDUCTION_GO_NATIVE_ENERGY, REDUCTION_GO_NONNATIVE_ENERGY, REDUCTION_GRO_GAUSS_ENERGY, REDUCTION_GRO_LJ_ENERGY, REDUCTION_IMPROPER_ENERGY, REDUCTION_LJ_ENERGY, REDUCTION_LJ_ENERGY_F, REDUCTION_LJ_ENERGY_TI_1, REDUCTION_LJ_ENERGY_TI_2, REDUCTION_MISC_ENERGY, simParams, slowFreq, ControllerState::smooth2_avg, state, stepInFullRun, SimParameters::stochRescaleHeat, SimParameters::stochRescaleOn, IMDEnergies::T, tavg_count, temp_avg, temperature, temperatureAverage, TITITLE(), totalEnergy, totalEnergy0, totalEnergyAverage, IMDEnergies::tstep, Lattice::volume(), Vector::x, Tensor::xx, XXXBIGREAL, Tensor::xy, Tensor::xz, Vector::y, Tensor::yx, Tensor::yy, Tensor::yz, Vector::z, Tensor::zx, Tensor::zy, and Tensor::zz.

Referenced by printDynamicsEnergies(), and printMinimizeEnergies().

3843 {
3844  Node *node = Node::Object();
3845  Molecule *molecule = node->molecule;
3846  Lattice &lattice = state->lattice;
3847  bool cudaIntegrator = simParams->CUDASOAintegrate;
3848 
3849  // Drude model ANISO energy is added into BOND energy
3850  // and THOLE energy is added into ELECT energy
3851 
3852  BigReal bondEnergy;
3853  BigReal angleEnergy;
3854  BigReal dihedralEnergy;
3855  BigReal improperEnergy;
3856  BigReal crosstermEnergy;
3857  BigReal boundaryEnergy;
3858  BigReal miscEnergy;
3859  BigReal potentialEnergy;
3860  BigReal flatEnergy;
3861  BigReal smoothEnergy;
3862  BigReal work;
3863 
3864  Vector momentum;
3865  Vector angularMomentum;
3866  BigReal volume = lattice.volume();
3867 #ifdef NODEGROUP_FORCE_REGISTER
3868  if(cudaIntegrator){
3869  bondEnergy = nodeReduction->item(REDUCTION_BOND_ENERGY);
3870  angleEnergy = nodeReduction->item(REDUCTION_ANGLE_ENERGY);
3871  dihedralEnergy = nodeReduction->item(REDUCTION_DIHEDRAL_ENERGY);
3872  improperEnergy = nodeReduction->item(REDUCTION_IMPROPER_ENERGY);
3873  crosstermEnergy = nodeReduction->item(REDUCTION_CROSSTERM_ENERGY);
3874  boundaryEnergy = nodeReduction->item(REDUCTION_BC_ENERGY);
3875  miscEnergy = nodeReduction->item(REDUCTION_MISC_ENERGY);
3876  }else{
3877 #endif
3878  bondEnergy = reduction->item(REDUCTION_BOND_ENERGY);
3879  angleEnergy = reduction->item(REDUCTION_ANGLE_ENERGY);
3880  dihedralEnergy = reduction->item(REDUCTION_DIHEDRAL_ENERGY);
3881  improperEnergy = reduction->item(REDUCTION_IMPROPER_ENERGY);
3882  crosstermEnergy = reduction->item(REDUCTION_CROSSTERM_ENERGY);
3883  boundaryEnergy = reduction->item(REDUCTION_BC_ENERGY);
3884  miscEnergy = reduction->item(REDUCTION_MISC_ENERGY);
3885 #ifdef NODEGROUP_FORCE_REGISTER
3886  }
3887 #endif
3888 
3889  if ( minimize || ! ( step % nbondFreq ) )
3890  {
3891 #ifdef NODEGROUP_FORCE_REGISTER
3892  if(cudaIntegrator){
3895 
3896  // JLai
3899 
3903 
3904  //fepb
3908 
3915  }else{
3916 #endif
3919 
3920  // JLai
3923 
3927 
3928  //fepb
3932 
3939 #ifdef NODEGROUP_FORCE_REGISTER
3940  }
3941 #endif
3942 //fepe
3943  }
3944 
3945  if ( minimize || ! ( step % slowFreq ) )
3946  {
3947 #ifdef NODEGROUP_FORCE_REGISTER
3948  if(cudaIntegrator){
3950  //fepb
3952 
3957  }else{
3958 #endif
3960  //fepb
3962 
3967 #ifdef NODEGROUP_FORCE_REGISTER
3968  }
3969 #endif
3970 //fepe
3971  }
3972 
3973  if ((simParams->LJcorrection || simParams->LJcorrectionAlt) && volume) {
3974 #ifdef MEM_OPT_VERSION
3975  NAMD_bug("LJcorrection not supported in memory optimized build.");
3976 #else
3977  // Apply tail correction to energy.
3978  BigReal alchLambda = simParams->getCurrentLambda(step);
3979  ljEnergy += molecule->getEnergyTailCorr(alchLambda, 0) / volume;
3980 
3981  if (simParams->alchOn) {
3982  if (simParams->alchFepOn) {
3983  BigReal alchLambda2 = simParams->getCurrentLambda2(step);
3984  ljEnergy_f += molecule->getEnergyTailCorr(alchLambda2, 0) / volume;
3985  } else if (simParams->alchThermIntOn) {
3986  ljEnergy_ti_1 += molecule->getEnergyTailCorr(1.0, 1) / volume;
3987  ljEnergy_ti_2 += molecule->getEnergyTailCorr(0.0, 1) / volume;
3988  }
3989  }
3990 #endif
3991  }
3992 
3993 //fepb BKR - Compute alchemical work if using dynamic lambda. This is here so
3994 // that the cumulative work can be given during a callback.
3995  if (simParams->alchLambdaFreq > 0) {
3996  if (step <=
3998  cumAlchWork = 0.0;
3999  }
4000  alchWork = computeAlchWork(step);
4001  cumAlchWork += alchWork;
4002  }
4003 //fepe
4004 #ifdef NODEGROUP_FORCE_REGISTER
4005  if(cudaIntegrator){
4006  momentum.x = nodeReduction->item(REDUCTION_MOMENTUM_X);
4007  momentum.y = nodeReduction->item(REDUCTION_MOMENTUM_Y);
4008  momentum.z = nodeReduction->item(REDUCTION_MOMENTUM_Z);
4009  angularMomentum.x = nodeReduction->item(REDUCTION_ANGULAR_MOMENTUM_X);
4010  angularMomentum.y = nodeReduction->item(REDUCTION_ANGULAR_MOMENTUM_Y);
4011  angularMomentum.z = nodeReduction->item(REDUCTION_ANGULAR_MOMENTUM_Z);
4012  }else{
4013 #endif
4014  momentum.x = reduction->item(REDUCTION_MOMENTUM_X);
4015  momentum.y = reduction->item(REDUCTION_MOMENTUM_Y);
4016  momentum.z = reduction->item(REDUCTION_MOMENTUM_Z);
4017  angularMomentum.x = reduction->item(REDUCTION_ANGULAR_MOMENTUM_X);
4018  angularMomentum.y = reduction->item(REDUCTION_ANGULAR_MOMENTUM_Y);
4019  angularMomentum.z = reduction->item(REDUCTION_ANGULAR_MOMENTUM_Z);
4020 #ifdef NODEGROUP_FORCE_REGISTER
4021  }
4022 #endif
4023 
4024  // Ported by JLai
4025  potentialEnergy = (bondEnergy + angleEnergy + dihedralEnergy
4026  + improperEnergy + electEnergy + electEnergySlow + ljEnergy
4027  + crosstermEnergy + boundaryEnergy + miscEnergy + goTotalEnergy
4029  // End of port
4030  totalEnergy = potentialEnergy + kineticEnergy;
4031  if ( ! cudaIntegrator) {
4032  flatEnergy = (totalEnergy
4034  if ( !(step%slowFreq) ) {
4035  // only adjust based on most accurate energies
4037  if ( smooth2_avg == XXXBIGREAL ) smooth2_avg = s;
4038  if ( step != simParams->firstTimestep ) {
4039  smooth2_avg *= 0.9375;
4040  smooth2_avg += 0.0625 * s;
4041  }
4042  }
4043  smoothEnergy = (flatEnergy + smooth2_avg
4045  }
4046 
4047  // Reset values for accumulated heat and work.
4048  if (step <= simParams->firstTimestep &&
4050  heat = 0.0;
4052  }
4053  if ( simParams->outputMomenta && ! minimize &&
4054  ! ( step % simParams->outputMomenta ) )
4055  {
4056  iout << "MOMENTUM: " << step
4057  << " P: " << momentum
4058  << " L: " << angularMomentum
4059  << "\n" << endi;
4060  }
4061 
4062  if ( simParams->outputPressure ) {
4063  if ( ! cudaIntegrator ) {
4066  }
4067  tavg_count += 1;
4068  if ( minimize || ! ( step % simParams->outputPressure ) ) {
4069  if (cudaIntegrator) {
4070  // tensors are valid for outputPressure step
4071  // update averages, then copy into tensor for output
4105  iout << "PRESSURE: " << step << " "
4106  << PRESSUREFACTOR * pressure << "\n"
4107  << "GPRESSURE: " << step << " "
4108  << PRESSUREFACTOR * groupPressure << "\n";
4109  // tavg_count makes output behaves the same as for standard case
4110  // but is no longer part of the average
4111  if ( tavg_count > 1 ) iout << "PRESSAVG: " << step << " "
4112  << (PRESSUREFACTOR) * pressure_tavg << "\n"
4113  << "GPRESSAVG: " << step << " "
4114  << (PRESSUREFACTOR) * groupPressure_tavg << "\n";
4115  iout << endi;
4116  tavg_count = 0;
4117  }
4118  else {
4119  iout << "PRESSURE: " << step << " "
4120  << PRESSUREFACTOR * pressure << "\n"
4121  << "GPRESSURE: " << step << " "
4122  << PRESSUREFACTOR * groupPressure << "\n";
4123  if ( tavg_count > 1 ) iout << "PRESSAVG: " << step << " "
4124  << (PRESSUREFACTOR/tavg_count) * pressure_tavg << "\n"
4125  << "GPRESSAVG: " << step << " "
4127  iout << endi;
4128  pressure_tavg = 0;
4129  groupPressure_tavg = 0;
4130  tavg_count = 0;
4131  }
4132  }
4133  }
4134 
4135  // pressure profile reductions
4136  if (pressureProfileSlabs) {
4137  const int freq = simParams->pressureProfileFreq;
4138  const int arraysize = 3*pressureProfileSlabs;
4139 
4140  BigReal *total = new BigReal[arraysize];
4141  memset(total, 0, arraysize*sizeof(BigReal));
4142  const int first = simParams->firstTimestep;
4143 
4144  if (ppbonded) ppbonded->getData(first, step, lattice, total);
4145  if (ppnonbonded) ppnonbonded->getData(first, step, lattice, total);
4146  if (ppint) ppint->getData(first, step, lattice, total);
4147  for (int i=0; i<arraysize; i++) pressureProfileAverage[i] += total[i];
4149 
4150  if (!(step % freq)) {
4151  // convert NAMD internal virial to pressure in units of bar
4153 
4154  iout << "PRESSUREPROFILE: " << step << " ";
4155  if (step == first) {
4156  // output pressure profile for this step
4157  for (int i=0; i<arraysize; i++) {
4158  iout << total[i] * scalefac << " ";
4159  }
4160  } else {
4161  // output pressure profile averaged over the last count steps.
4162  scalefac /= pressureProfileCount;
4163  for (int i=0; i<arraysize; i++)
4164  iout << pressureProfileAverage[i]*scalefac << " ";
4165  }
4166  iout << "\n" << endi;
4167 
4168  // Clear the average for the next block
4169  memset(pressureProfileAverage, 0, arraysize*sizeof(BigReal));
4171  }
4172  delete [] total;
4173  }
4174 
4175  if ( step != simParams->firstTimestep || stepInFullRun == 0 ) { // skip repeated first step
4176  if ( stepInFullRun % simParams->firstLdbStep == 0 ) {
4177  int benchPhase = stepInFullRun / simParams->firstLdbStep;
4178  if ( benchPhase > 0 && benchPhase < 10 ) {
4179 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
4180  if ( simParams->computeEnergies < 60 ) {
4181  iout << iWARN << "Energy evaluation is expensive, increase computeEnergies to improve performance.\n";
4182  iout << iWARN << "If computeEnergies is not defined, its value defaults to the same as outputEnergies, and increasing outputEnergies would be helpful to improve the performance.\n";
4183  }
4184 #endif
4185  iout << iINFO;
4186  if ( benchPhase < 4 ) iout << "Initial time: ";
4187  else iout << "Benchmark time: ";
4188  iout << CkNumPes() << " CPUs ";
4189 
4190  {
4191  BigReal wallPerStep =
4192  (namdWallTimer() - startBenchTime) / simParams->firstLdbStep;
4193  BigReal ns = simParams->dt / 1000000.0;
4194  BigReal days = 1.0 / (24.0 * 60.0 * 60.0);
4195 
4196  if (simParams->nsPerDayOn) {
4197  BigReal nsPerDay = ns / (wallPerStep * days);
4198  iout << wallPerStep << " s/step " << nsPerDay << " ns/day ";
4199  }
4200  else {
4201  BigReal daysPerNano = wallPerStep * days / ns;
4202  iout << wallPerStep << " s/step " << daysPerNano << " days/ns ";
4203  }
4204  iout << memusage_MB() << " MB memory\n" << endi;
4205  }
4206 
4207  }
4208  startBenchTime = namdWallTimer();
4209  }
4210  ++stepInFullRun;
4211  }
4212 
4213  printTiming(step);
4214 
4215  Vector pairVDWForce, pairElectForce;
4216  if ( simParams->pairInteractionOn ){
4217 #ifdef NODEGROUP_FORCE_REGISTER
4218  if(cudaIntegrator){
4219  GET_VECTOR(pairVDWForce,nodeReduction,REDUCTION_PAIR_VDW_FORCE);
4220  GET_VECTOR(pairElectForce,nodeReduction,REDUCTION_PAIR_ELECT_FORCE);
4221  }else{
4222 #endif
4223  GET_VECTOR(pairVDWForce,reduction,REDUCTION_PAIR_VDW_FORCE);
4224  GET_VECTOR(pairElectForce,reduction,REDUCTION_PAIR_ELECT_FORCE);
4225 #ifdef NODEGROUP_FORCE_REGISTER
4226  }
4227 #endif
4228  }
4229 
4230  // Compute cumulative nonequilibrium work (including shadow work).
4232  work = totalEnergy - totalEnergy0 - heat;
4233  }
4234 
4235  // callback to Tcl with whatever we can
4236 #ifdef NAMD_TCL
4237 #define CALLBACKDATA(LABEL,VALUE) \
4238  labels << (LABEL) << " "; values << (VALUE) << " ";
4239 #define CALLBACKLIST(LABEL,VALUE) \
4240  labels << (LABEL) << " "; values << "{" << (VALUE) << "} ";
4241  if (step == simParams->N && node->getScript() && node->getScript()->doCallback()) {
4242 
4243  std::ostringstream labels, values;
4244 #if CMK_BLUEGENEL
4245  // the normal version below gives a compiler error
4246  values.precision(16);
4247 #else
4248  values << std::setprecision(16);
4249 #endif
4250  CALLBACKDATA("TS",step);
4251  CALLBACKDATA("BOND",bondEnergy);
4252  CALLBACKDATA("ANGLE",angleEnergy);
4253  CALLBACKDATA("DIHED",dihedralEnergy);
4254  CALLBACKDATA("CROSS",crosstermEnergy);
4255  CALLBACKDATA("IMPRP",improperEnergy);
4257  CALLBACKDATA("VDW",ljEnergy);
4258  CALLBACKDATA("BOUNDARY",boundaryEnergy);
4259  CALLBACKDATA("MISC",miscEnergy);
4260  CALLBACKDATA("POTENTIAL",potentialEnergy);
4261  CALLBACKDATA("KINETIC",kineticEnergy);
4262  CALLBACKDATA("TOTAL",totalEnergy);
4263  CALLBACKDATA("TEMP",temperature);
4264  CALLBACKLIST("PRESSURE",pressure*PRESSUREFACTOR);
4266  CALLBACKDATA("VOLUME",lattice.volume());
4267  CALLBACKLIST("CELL_A",lattice.a());
4268  CALLBACKLIST("CELL_B",lattice.b());
4269  CALLBACKLIST("CELL_C",lattice.c());
4270  CALLBACKLIST("CELL_O",lattice.origin());
4271  labels << "PERIODIC "; values << "{" << lattice.a_p() << " "
4272  << lattice.b_p() << " " << lattice.c_p() << "} ";
4273  if (simParams->drudeOn) {
4274  CALLBACKDATA("DRUDEBOND",drudeBondTemp);
4275  }
4276  if ( simParams->pairInteractionOn ) {
4277  CALLBACKLIST("VDW_FORCE",pairVDWForce);
4278  CALLBACKLIST("ELECT_FORCE",pairElectForce);
4279  }
4281  CALLBACKLIST("HEAT",heat);
4282  CALLBACKLIST("WORK",work);
4283  }
4284  if (simParams->alchOn) {
4285  if (simParams->alchThermIntOn) {
4286  CALLBACKLIST("BOND1", bondedEnergy_ti_1);
4289  CALLBACKLIST("VDW1", ljEnergy_ti_1);
4290  CALLBACKLIST("BOND2", bondedEnergy_ti_2);
4293  CALLBACKLIST("VDW2", ljEnergy_ti_2);
4294  if (simParams->alchLambdaFreq > 0) {
4295  CALLBACKLIST("CUMALCHWORK", cumAlchWork);
4296  }
4297  } else if (simParams->alchFepOn) {
4298  CALLBACKLIST("BOND2", bondEnergy + angleEnergy + dihedralEnergy +
4299  improperEnergy + bondedEnergyDiff_f);
4301  CALLBACKLIST("VDW2", ljEnergy_f);
4302  }
4303  }
4304 
4305  labels << '\0'; values << '\0'; // insane but makes Linux work
4306  state->callback_labelstring = labels.str();
4307  state->callback_valuestring = values.str();
4308  // node->getScript()->doCallback(labelstring.c_str(),valuestring.c_str());
4309  }
4310 #undef CALLBACKDATA
4311 #endif
4312 
4313  if ( ! cudaIntegrator) {
4315  temp_avg += temperature;
4316  pressure_avg += trace(pressure)/3.;
4317  groupPressure_avg += trace(groupPressure)/3.;
4318  avg_count += 1;
4319  }
4320 
4322  ! (step % simParams->outputPairlists) ) {
4323  iout << iINFO << pairlistWarnings <<
4324  " pairlist warnings in past " << simParams->outputPairlists <<
4325  " steps.\n" << endi;
4326  pairlistWarnings = 0;
4327  }
4328 
4329  BigReal enthalpy;
4330  if (simParams->multigratorOn && ((step % simParams->computeEnergies) == 0)) {
4331  enthalpy = multigatorCalcEnthalpy(potentialEnergy, step, minimize);
4332  }
4333 
4334  // XXX
4335  // Important note: in CPU-only/GPU-offload modes
4336  // printEnergies is called EVERY STEP.
4337  // Reduction averages are summed above and then later are output
4338  // divided by count. Sums and counter are reset after printing.
4339  // XXX
4340  // NO CALCULATIONS OR REDUCTIONS BEYOND THIS POINT!!!
4341  if ( ! minimize && step % simParams->outputEnergies ) return;
4342 
4343  if (cudaIntegrator) {
4346  pressureAverage.addSample((1./3)*trace(pressure));
4348  }
4349 
4350  // ONLY OUTPUT SHOULD OCCUR BELOW THIS LINE!!!
4351 
4352  if (simParams->IMDon && !(step % simParams->IMDfreq)) {
4353  IMDEnergies energies;
4354  energies.tstep = step;
4355  energies.T = temp_avg/avg_count;
4356  energies.Etot = totalEnergy;
4357  energies.Epot = potentialEnergy;
4358  energies.Evdw = ljEnergy;
4359  energies.Eelec = electEnergy + electEnergySlow;
4360  energies.Ebond = bondEnergy;
4361  energies.Eangle = angleEnergy;
4362  energies.Edihe = dihedralEnergy + crosstermEnergy;
4363  energies.Eimpr = improperEnergy;
4364  Node::Object()->imd->gather_energies(&energies);
4365  }
4366 
4367  if ( marginViolations ) {
4368  iout << iERROR << marginViolations <<
4369  " margin violations detected since previous energy output.\n" << endi;
4370  }
4371  marginViolations = 0;
4372 
4373  int precision = simParams->outputEnergiesPrecision;
4374  if ( (step % (10 * (minimize?1:simParams->outputEnergies) ) ) == 0 )
4375  {
4376  iout << "ETITLE: TS";
4377  iout << FORMAT("BOND", precision);
4378  iout << FORMAT("ANGLE", precision);
4379  iout << FORMAT("DIHED", precision);
4380  if ( ! simParams->mergeCrossterms ) iout << FORMAT("CROSS", precision);
4381  iout << FORMAT("IMPRP", precision);
4382  iout << " ";
4383  iout << FORMAT("ELECT", precision);
4384  iout << FORMAT("VDW", precision);
4385  iout << FORMAT("BOUNDARY", precision);
4386  iout << FORMAT("MISC", precision);
4387  iout << FORMAT("KINETIC", precision);
4388  iout << " ";
4389  iout << FORMAT("TOTAL", precision);
4390  iout << FORMAT("TEMP", precision);
4391  iout << FORMAT("POTENTIAL", precision);
4392  if (cudaIntegrator) {
4393  iout << FORMAT("TOTALAVG", precision);
4394  }
4395  else {
4396  // iout << FORMAT("TOTAL2", precision);
4397  iout << FORMAT("TOTAL3", precision);
4398  }
4399  iout << FORMAT("TEMPAVG", precision);
4400  if ( volume != 0. ) {
4401  iout << " ";
4402  iout << FORMAT("PRESSURE", precision);
4403  iout << FORMAT("GPRESSURE", precision);
4404  iout << FORMAT("VOLUME", precision);
4405  iout << FORMAT("PRESSAVG", precision);
4406  iout << FORMAT("GPRESSAVG", precision);
4407  }
4409  iout << " ";
4410  iout << FORMAT("HEAT", precision);
4411  iout << FORMAT("WORK", precision);
4412  }
4413  if (simParams->drudeOn) {
4414  iout << " ";
4415  iout << FORMAT("DRUDEBOND", precision);
4416  iout << FORMAT("DRBONDAVG", precision);
4417  }
4418  // Ported by JLai
4419  if (simParams->goGroPair) {
4420  iout << " ";
4421  iout << FORMAT("GRO_PAIR_LJ", precision);
4422  iout << FORMAT("GRO_PAIR_GAUSS", precision);
4423  }
4424 
4425  if (simParams->goForcesOn) {
4426  iout << " ";
4427  iout << FORMAT("NATIVE", precision);
4428  iout << FORMAT("NONNATIVE", precision);
4429  //iout << FORMAT("REL_NATIVE", precision);
4430  //iout << FORMAT("REL_NONNATIVE", precision);
4431  iout << FORMAT("GOTOTAL", precision);
4432  //iout << FORMAT("GOAVG", precision);
4433  }
4434  // End of port -- JLai
4435 
4436  if (simParams->alchOn) {
4437  if (simParams->alchThermIntOn) {
4438  iout << "\nTITITLE: TS";
4439  iout << FORMAT("BOND1", precision);
4440  iout << FORMAT("ELECT1", precision);
4441  iout << FORMAT("VDW1", precision);
4442  iout << FORMAT("BOND2", precision);
4443  iout << " ";
4444  iout << FORMAT("ELECT2", precision);
4445  iout << FORMAT("VDW2", precision);
4446  if (simParams->alchLambdaFreq > 0) {
4447  iout << FORMAT("LAMBDA", precision);
4448  iout << FORMAT("ALCHWORK", precision);
4449  iout << FORMAT("CUMALCHWORK", precision);
4450  }
4451  } else if (simParams->alchFepOn) {
4452  iout << "\nFEPTITLE: TS";
4453  iout << FORMAT("BOND2", precision);
4454  iout << FORMAT("ELECT2", precision);
4455  iout << FORMAT("VDW2", precision);
4456  if (simParams->alchLambdaFreq > 0) {
4457  iout << FORMAT("LAMBDA", precision);
4458  }
4459  }
4460  }
4461 
4462  iout << "\n\n" << endi;
4463 
4464  if (simParams->qmForcesOn) {
4465  iout << "QMETITLE: TS";
4466  iout << FORMAT("QMID", precision);
4467  iout << FORMAT("ENERGY", precision);
4468  if (simParams->PMEOn) iout << FORMAT("PMECORRENERGY", precision);
4469  iout << "\n\n" << endi;
4470  }
4471 
4472  }
4473 
4474  // N.B. HP's aCC compiler merges FORMAT calls in the same expression.
4475  // Need separate statements because data returned in static array.
4476  iout << ETITLE(step);
4477  iout << FORMAT(bondEnergy, precision);
4478  iout << FORMAT(angleEnergy, precision);
4479  if ( simParams->mergeCrossterms ) {
4480  iout << FORMAT(dihedralEnergy+crosstermEnergy, precision);
4481  } else {
4482  iout << FORMAT(dihedralEnergy, precision);
4483  iout << FORMAT(crosstermEnergy, precision);
4484  }
4485  iout << FORMAT(improperEnergy, precision);
4486  iout << " ";
4487  iout << FORMAT(electEnergy+electEnergySlow, precision);
4488  iout << FORMAT(ljEnergy, precision);
4489  iout << FORMAT(boundaryEnergy, precision);
4490  iout << FORMAT(miscEnergy, precision);
4491  iout << FORMAT(kineticEnergy, precision);
4492  iout << " ";
4493  iout << FORMAT(totalEnergy, precision);
4494  iout << FORMAT(temperature, precision);
4495  iout << FORMAT(potentialEnergy, precision);
4496  if (cudaIntegrator) {
4497  iout << FORMAT(totalEnergyAverage.average(), precision);
4498  iout << FORMAT(temperatureAverage.average(), precision);
4499  }
4500  else {
4501  // iout << FORMAT(flatEnergy, precision);
4502  iout << FORMAT(smoothEnergy, precision);
4503  iout << FORMAT(temp_avg/avg_count, precision);
4504  }
4505  if ( volume != 0. )
4506  {
4507  iout << " ";
4508  iout << FORMAT(trace(pressure)*PRESSUREFACTOR/3., precision);
4509  iout << FORMAT(trace(groupPressure)*PRESSUREFACTOR/3., precision);
4510  iout << FORMAT(volume, precision);
4511  if (cudaIntegrator) {
4514  }
4515  else {
4518  }
4519  }
4521  iout << " ";
4522  iout << FORMAT(heat, precision);
4523  iout << FORMAT(work, precision);
4524  }
4525  if (simParams->drudeOn) {
4526  iout << " ";
4527  iout << FORMAT(drudeBondTemp, precision);
4528  iout << FORMAT(drudeBondTempAvg/avg_count, precision);
4529  }
4530  // Ported by JLai
4531  if (simParams->goGroPair) {
4532  iout << " ";
4533  iout << FORMAT(groLJEnergy, precision);
4534  iout << FORMAT(groGaussEnergy, precision);
4535  }
4536 
4537  if (simParams->goForcesOn) {
4538  iout << " ";
4539  iout << FORMAT(goNativeEnergy, precision);
4540  iout << FORMAT(goNonnativeEnergy, precision);
4541  //iout << FORMAT(relgoNativeEnergy, precision);
4542  //iout << FORMAT(relgoNonnativeEnergy, precision);
4543  iout << FORMAT(goTotalEnergy, precision);
4544  //iout << FORMAT("not implemented", precision);
4545  } // End of port -- JLai
4546 
4547  if (simParams->alchOn) {
4548  if (simParams->alchThermIntOn) {
4549  iout << "\n";
4550  iout << TITITLE(step);
4551  iout << FORMAT(bondedEnergy_ti_1, precision);
4553  electEnergyPME_ti_1, precision);
4554  iout << FORMAT(ljEnergy_ti_1, precision);
4555  iout << FORMAT(bondedEnergy_ti_2, precision);
4556  iout << " ";
4558  electEnergyPME_ti_2, precision);
4559  iout << FORMAT(ljEnergy_ti_2, precision);
4560  if (simParams->alchLambdaFreq > 0) {
4561  iout << FORMAT(simParams->getCurrentLambda(step), precision);
4562  iout << FORMAT(alchWork, precision);
4563  iout << FORMAT(cumAlchWork, precision);
4564  }
4565  } else if (simParams->alchFepOn) {
4566  iout << "\n";
4567  iout << FEPTITLE2(step);
4568  iout << FORMAT(bondEnergy + angleEnergy + dihedralEnergy
4569  + improperEnergy + bondedEnergyDiff_f, precision);
4570  iout << FORMAT(electEnergy_f + electEnergySlow_f, precision);
4571  iout << FORMAT(ljEnergy_f, precision);
4572  if (simParams->alchLambdaFreq > 0) {
4573  iout << FORMAT(simParams->getCurrentLambda(step), precision);
4574  }
4575  }
4576  }
4577 
4578  iout << "\n\n" << endi;
4579 
4580 #if(CMK_CCS_AVAILABLE && CMK_WEB_MODE)
4581  char webout[80];
4582  sprintf(webout,"%d %d %d %d",(int)totalEnergy,
4583  (int)(potentialEnergy),
4584  (int)kineticEnergy,(int)temperature);
4585  CApplicationDepositNode0Data(webout);
4586 #endif
4587 
4589  iout << "PAIR INTERACTION:";
4590  iout << " STEP: " << step;
4591  iout << " VDW_FORCE: ";
4592  iout << FORMAT(pairVDWForce.x, precision);
4593  iout << FORMAT(pairVDWForce.y, precision);
4594  iout << FORMAT(pairVDWForce.z, precision);
4595  iout << " ELECT_FORCE: ";
4596  iout << FORMAT(pairElectForce.x, precision);
4597  iout << FORMAT(pairElectForce.y, precision);
4598  iout << FORMAT(pairElectForce.z, precision);
4599  iout << "\n" << endi;
4600  }
4601  drudeBondTempAvg = 0;
4602  temp_avg = 0;
4603  pressure_avg = 0;
4604  groupPressure_avg = 0;
4605  avg_count = 0;
4606 
4607  if ( fflush_count ) {
4608  --fflush_count;
4609  fflush(stdout);
4610  }
4611 }
static Node * Object()
Definition: Node.h:86
MovingAverage groupPressureAverage_xx
Definition: Controller.h:459
BigReal zy
Definition: Tensor.h:19
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
#define XXXBIGREAL
Definition: Controller.C:76
int pressureProfileSlabs
Definition: Controller.h:361
BigReal electEnergy_ti_1
Definition: Controller.h:213
#define CALLBACKDATA(LABEL, VALUE)
BigReal smooth2_avg
Definition: Controller.h:103
int nbondFreq
Definition: Controller.h:162
MovingAverage groupPressureAverage_yx
Definition: Controller.h:462
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
BigReal xz
Definition: Tensor.h:17
BigReal goNativeEnergy
Definition: Controller.h:194
NAMD_HOST_DEVICE int c_p() const
Definition: Lattice.h:291
Definition: Node.h:78
BigReal temp_avg
Definition: Controller.h:164
MovingAverage pressureAverage_xx
Definition: Controller.h:453
IMDOutput * imd
Definition: Node.h:186
int fflush_count
Definition: Controller.h:336
MovingAverage groupPressureAverage_yy
Definition: Controller.h:463
BigReal ljEnergy
Definition: Controller.h:191
MovingAverage groupPressureAverage_zx
Definition: Controller.h:465
void minimize()
Definition: Controller.C:765
BigReal totalEnergy0
Definition: Controller.h:249
Definition: Vector.h:72
#define PRESSUREFACTOR
Definition: common.h:56
BigReal pressure_avg
Definition: Controller.h:165
MovingAverage pressureAverage_zx
Definition: Controller.h:456
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
float Eelec
Definition: imd.h:32
BigReal electEnergySlow_f
Definition: Controller.h:200
BigReal yz
Definition: Tensor.h:18
MovingAverage totalEnergyAverage
Definition: Controller.h:447
static char * FEPTITLE2(int X)
Definition: Controller.C:93
MovingAverage temperatureAverage
Definition: Controller.h:448
MovingAverage groupPressureAverage_yz
Definition: Controller.h:464
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
Tensor groupPressure_tavg
Definition: Controller.h:169
#define iout
Definition: InfoStream.h:51
BigReal electEnergySlow
Definition: Controller.h:190
Bool pairInteractionOn
Molecule stores the structural information for the system.
Definition: Molecule.h:175
NAMD_HOST_DEVICE int b_p() const
Definition: Lattice.h:290
MovingAverage groupPressureAverage_xy
Definition: Controller.h:460
MovingAverage pressureAverage_yy
Definition: Controller.h:455
static double namdWallTimer()
Definition: Controller.C:57
void gather_energies(IMDEnergies *energies)
Definition: IMDOutput.C:24
float Eimpr
Definition: imd.h:36
BigReal heat
Definition: Controller.h:247
MovingAverage pressureAverage_zz
Definition: Controller.h:458
float Etot
Definition: imd.h:29
BigReal alchWork
Definition: Controller.h:236
BigReal electEnergy_f
Definition: Controller.h:199
double memusage_MB()
Definition: memusage.h:13
BigReal temperature
Definition: Controller.h:246
int pressureProfileCount
Definition: Controller.h:362
NamdState *const state
Definition: Controller.h:349
PressureProfileReduction * ppint
Definition: Controller.h:360
BigReal ljEnergy_ti_1
Definition: Controller.h:215
Tensor pressure
Definition: Controller.h:252
BigReal computeAlchWork(const int step)
Definition: Controller.C:4924
float Edihe
Definition: imd.h:35
BigReal getEnergyTailCorr(const BigReal, const int)
BigReal groupPressure_avg
Definition: Controller.h:166
BigReal drudeBondTempAvg
Definition: Controller.h:241
void NAMD_bug(const char *err_msg)
Definition: common.C:195
BigReal drudeBondTemp
Definition: Controller.h:240
BigReal bondedEnergyDiff_f
Definition: Controller.h:198
float Eangle
Definition: imd.h:34
BigReal yx
Definition: Tensor.h:18
ReductionValue & item(int index)
Definition: ReductionMgr.C:633
static char * ETITLE(int X)
Definition: Controller.C:1855
MovingAverage groupPressureAverage_xz
Definition: Controller.h:461
BigReal kineticEnergyCentered
Definition: Controller.h:245
MovingAverage groupPressureAverage_zy
Definition: Controller.h:466
void printTiming(int)
Definition: Controller.C:3642
MovingAverage pressureAverage_zy
Definition: Controller.h:457
BigReal electEnergySlow_ti_1
Definition: Controller.h:214
int marginViolations
Definition: Controller.h:173
BigReal groLJEnergy
Definition: Controller.h:192
static char * FORMAT(BigReal X, int decimal=4)
Definition: Controller.C:1830
BigReal x
Definition: Vector.h:74
BigReal goTotalEnergy
Definition: Controller.h:196
float T
Definition: imd.h:28
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
NAMD_HOST_DEVICE int a_p() const
Definition: Lattice.h:289
BigReal electEnergyPME_ti_1
Definition: Controller.h:226
#define GET_VECTOR(O, R, A)
Definition: ReductionMgr.h:55
BigReal groGaussEnergy
Definition: Controller.h:193
int32 tstep
Definition: imd.h:27
float Epot
Definition: imd.h:30
NAMD_HOST_DEVICE Vector b() const
Definition: Lattice.h:269
void getData(int firsttimestep, int step, const Lattice &lattice, BigReal *total)
Definition: Controller.C:136
void addSample(double x)
Definition: Controller.h:63
BigReal xx
Definition: Tensor.h:17
MovingAverage groupPressureAverage_zz
Definition: Controller.h:467
float Evdw
Definition: imd.h:31
float Ebond
Definition: imd.h:33
BigReal multigatorCalcEnthalpy(BigReal potentialEnergy, int step, int minimize)
Definition: Controller.C:1090
BigReal electEnergy_ti_2
Definition: Controller.h:216
BigReal zz
Definition: Tensor.h:19
MovingAverage pressureAverage_yx
Definition: Controller.h:454
int pairlistWarnings
Definition: Controller.h:174
BigReal * pressureProfileAverage
Definition: Controller.h:363
MovingAverage pressureAverage
Definition: Controller.h:449
BigReal electEnergyPME_ti_2
Definition: Controller.h:227
BigReal getCurrentLambda2(const int) const
BigReal cumAlchWork
Definition: Controller.h:225
BigReal getCurrentLambda(const int) const
BigReal xy
Definition: Tensor.h:17
BigReal item(int i) const
Definition: ReductionMgr.h:341
Tensor pressure_tavg
Definition: Controller.h:168
BigReal y
Definition: Vector.h:74
BigReal electEnergy
Definition: Controller.h:189
double average() const
Definition: Controller.h:80
Tensor groupPressure
Definition: Controller.h:253
ScriptTcl * getScript()
Definition: Node.C:1599
BigReal ljEnergy_f
Definition: Controller.h:201
int slowFreq
Definition: Controller.h:163
PressureProfileReduction * ppnonbonded
Definition: Controller.h:359
BigReal yy
Definition: Tensor.h:18
MovingAverage groupPressureAverage
Definition: Controller.h:450
BigReal totalEnergy
Definition: Controller.h:188
BigReal kineticEnergyHalfstep
Definition: Controller.h:244
BigReal electEnergySlow_ti_2
Definition: Controller.h:217
static char * TITITLE(int X)
Definition: Controller.C:100
SimParameters *const simParams
Definition: Controller.h:348
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
#define CALLBACKLIST(LABEL, VALUE)
BigReal bondedEnergy_ti_2
Definition: Controller.h:212
int tavg_count
Definition: Controller.h:170
RequireReduction * reduction
Definition: Controller.h:350
PressureProfileReduction * ppbonded
Definition: Controller.h:358
NAMD_HOST_DEVICE Vector a() const
Definition: Lattice.h:268
NodeReduction * nodeReduction
Definition: Controller.h:354
BigReal zx
Definition: Tensor.h:19
BigReal bondedEnergy_ti_1
Definition: Controller.h:211
BigReal goNonnativeEnergy
Definition: Controller.h:195
Molecule * molecule
Definition: Node.h:179
NAMD_HOST_DEVICE Vector origin() const
Definition: Lattice.h:278
int stepInFullRun
Definition: Controller.h:187
int outputEnergiesPrecision
int avg_count
Definition: Controller.h:167
BigReal kineticEnergy
Definition: Controller.h:243
double BigReal
Definition: common.h:123
BigReal ljEnergy_ti_2
Definition: Controller.h:218

◆ printFepMessage()

void Controller::printFepMessage ( int  step)
protected

Definition at line 1716 of file Controller.C.

References SimParameters::alchEquilSteps, SimParameters::alchFepOn, SimParameters::alchLambda, SimParameters::alchLambda2, SimParameters::alchLambdaFreq, SimParameters::alchLambdaIDWS, SimParameters::alchOn, SimParameters::alchTemp, endi(), iout, and simParams.

Referenced by integrate().

1717 {
1719  && !simParams->alchLambdaFreq) {
1720  const BigReal alchLambda = simParams->alchLambda;
1721  const BigReal alchLambda2 = simParams->alchLambda2;
1722  const BigReal alchLambdaIDWS = simParams->alchLambdaIDWS;
1723  const BigReal alchTemp = simParams->alchTemp;
1724  const int alchEquilSteps = simParams->alchEquilSteps;
1725  iout << "FEP: RESETTING FOR NEW FEP WINDOW "
1726  << "LAMBDA SET TO " << alchLambda << " LAMBDA2 " << alchLambda2;
1727  if ( alchLambdaIDWS >= 0. ) {
1728  iout << " LAMBDA_IDWS " << alchLambdaIDWS;
1729  }
1730  iout << "\nFEP: WINDOW TO HAVE " << alchEquilSteps
1731  << " STEPS OF EQUILIBRATION PRIOR TO FEP DATA COLLECTION.\n"
1732  << "FEP: USING CONSTANT TEMPERATURE OF " << alchTemp
1733  << " K FOR FEP CALCULATION\n" << endi;
1734  }
1735 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal alchLambda2
#define iout
Definition: InfoStream.h:51
BigReal alchLambda
BigReal alchLambdaIDWS
BigReal alchTemp
SimParameters *const simParams
Definition: Controller.h:348
double BigReal
Definition: common.h:123

◆ printMinimizeEnergies()

void Controller::printMinimizeEnergies ( int  step)
protected

Definition at line 3712 of file Controller.C.

References compareChecksums(), RequireReduction::item(), min_energy, min_f_dot_f, min_f_dot_v, min_huge_count, min_v_dot_v, Node::molecule, Node::Object(), printEnergies(), receivePressure(), reduction, REDUCTION_MIN_F_DOT_F, REDUCTION_MIN_F_DOT_V, REDUCTION_MIN_HUGE_COUNT, REDUCTION_MIN_V_DOT_V, rescaleaccelMD(), and totalEnergy.

3712  {
3713 
3714  rescaleaccelMD(step,1);
3715  receivePressure(step,1);
3716 
3717  Node *node = Node::Object();
3718  Molecule *molecule = node->molecule;
3719  compareChecksums(step,1);
3720 
3721  printEnergies(step,1);
3722 
3728 
3729 #ifdef DEBUG_MINIMIZE
3730  printf("%s, line %d\n", __FILE__, __LINE__);
3731  printf("Step %d:\n", step);
3732  printf(" min_energy = %f\n", min_energy);
3733  printf(" min_f_dot_f = %f\n", min_f_dot_f);
3734  printf(" min_f_dot_v = %f\n", min_f_dot_v);
3735  printf(" min_v_dot_v = %f\n", min_v_dot_v);
3736  printf(" min_huge_count = %d\n", min_huge_count);
3737  printf("\n");
3738 #endif
3739 }
static Node * Object()
Definition: Node.h:86
void rescaleaccelMD(int step, int minimize=0)
Definition: Controller.C:2413
BigReal min_v_dot_v
Definition: Controller.h:182
void compareChecksums(int, int=0)
Definition: Controller.C:3349
Definition: Node.h:78
int min_huge_count
Definition: Controller.h:183
Molecule stores the structural information for the system.
Definition: Molecule.h:175
BigReal min_energy
Definition: Controller.h:179
void receivePressure(int step, int minimize=0)
Definition: Controller.C:1862
BigReal min_f_dot_f
Definition: Controller.h:180
void printEnergies(int step, int minimize)
Definition: Controller.C:3842
BigReal item(int i) const
Definition: ReductionMgr.h:341
BigReal totalEnergy
Definition: Controller.h:188
RequireReduction * reduction
Definition: Controller.h:350
Molecule * molecule
Definition: Node.h:179
BigReal min_f_dot_v
Definition: Controller.h:181

◆ printTiMessage()

void Controller::printTiMessage ( int  step)
protected

Definition at line 1736 of file Controller.C.

References SimParameters::alchEquilSteps, SimParameters::alchLambda, SimParameters::alchLambdaFreq, SimParameters::alchOn, SimParameters::alchThermIntOn, endi(), iout, and simParams.

Referenced by integrate().

1737 {
1739  && !simParams->alchLambdaFreq) {
1740  const BigReal alchLambda = simParams->alchLambda;
1741  const int alchEquilSteps = simParams->alchEquilSteps;
1742  iout << "TI: RESETTING FOR NEW WINDOW "
1743  << "LAMBDA SET TO " << alchLambda
1744  << "\nTI: WINDOW TO HAVE " << alchEquilSteps
1745  << " STEPS OF EQUILIBRATION PRIOR TO TI DATA COLLECTION.\n" << endi;
1746  }
1747 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
BigReal alchLambda
SimParameters *const simParams
Definition: Controller.h:348
double BigReal
Definition: common.h:123

◆ printTiming()

void Controller::printTiming ( int  step)
protected

Definition at line 3642 of file Controller.C.

References RunningAverage::add_sample(), RunningAverage::average(), SimParameters::benchmarkTime, SimParameters::computeEnergies, SimParameters::dt, endi(), fflush_count, SimParameters::firstTimestep, iout, iWARN(), memusage_MB(), SimParameters::N, NAMD_quit(), namdWallTimer(), SimParameters::nsPerDayOn, SimParameters::outputPerformance, SimParameters::outputTiming, perfstats, simParams, and RunningAverage::standard_deviation().

Referenced by printEnergies().

3642  {
3643 
3644  if ( simParams->outputTiming && ! ( step % simParams->outputTiming ) )
3645  {
3646  const double endWTime = namdWallTimer() - firstWTime;
3647  const double endCTime = CmiTimer() - firstCTime;
3648 
3649  // fflush about once per minute
3650  if ( (((int)endWTime)>>6) != (((int)startWTime)>>6 ) ) fflush_count = 2;
3651 
3652  const double elapsedW =
3653  (endWTime - startWTime) / simParams->outputTiming;
3654  const double elapsedC =
3655  (endCTime - startCTime) / simParams->outputTiming;
3656 
3657  const double remainingW = elapsedW * (simParams->N - step);
3658  const double remainingW_hours = remainingW / 3600;
3659 
3660  startWTime = endWTime;
3661  startCTime = endCTime;
3662 
3663 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
3664  if ( simParams->computeEnergies < 60 &&
3665  step < (simParams->firstTimestep + 10 * simParams->outputTiming) ) {
3666  iout << iWARN << "Energy evaluation is expensive, increase computeEnergies to improve performance.\n" << endi;
3667  iout << iWARN << "If computeEnergies is not defined, its value defaults to the same as outputEnergies, and increasing outputEnergies would be helpful to improve the performance.\n" << endi;
3668  }
3669 #endif
3670  if ( step >= (simParams->firstTimestep + simParams->outputTiming) ) {
3671  if (simParams->nsPerDayOn) {
3672  BigReal ns = simParams->dt / 1000000.0;
3673  BigReal days = 1.0 / (24.0 * 60.0 * 60.0);
3674  BigReal nsPerDay = ns / (elapsedW * days);
3675  CmiPrintf("TIMING: %d CPU: %g, %g/step Wall: %g, %g/step"
3676  ", %g ns/days"
3677  ", %g hours remaining, %f MB of memory in use.\n",
3678  step, endCTime, elapsedC, endWTime, elapsedW,
3679  nsPerDay,
3680  remainingW_hours, memusage_MB());
3681  }
3682  else {
3683  CmiPrintf("TIMING: %d CPU: %g, %g/step Wall: %g, %g/step"
3684  ", %g hours remaining, %f MB of memory in use.\n",
3685  step, endCTime, elapsedC, endWTime, elapsedW,
3686  remainingW_hours, memusage_MB());
3687  }
3689  // calculate running average and sample variance of
3690  // the measured time per step (elapsedW)
3691  perfstats.add_sample(elapsedW);
3692  double t_avg = perfstats.average();
3693  double t_std = perfstats.standard_deviation();
3694  // convert t_avg to average number of nanoseconds simulated per day
3695  double ns_per_day = (simParams->dt / t_avg) * (60 * 60 * 24 * 1e-6);
3696  CmiPrintf("PERFORMANCE: %d averaging %g ns/day, %g sec/step with"
3697  " standard deviation %g\n", step, ns_per_day, t_avg, t_std);
3698  }
3699  if ( fflush_count ) { --fflush_count; fflush(stdout); }
3700  double benchmarkTime = (double) simParams->benchmarkTime;
3701  if (benchmarkTime > 0 && benchmarkTime <= endWTime) {
3702  // terminate NAMD benchmark
3703  char s[100];
3704  sprintf(s, "Exceeded benchmark time limit %g seconds",
3705  benchmarkTime);
3706  NAMD_quit(s);
3707  }
3708  }
3709  }
3710 }
void NAMD_quit(const char *err_msg)
Definition: common.C:125
int fflush_count
Definition: Controller.h:336
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
Bool outputPerformance
#define iout
Definition: InfoStream.h:51
RunningAverage perfstats
Definition: Controller.h:444
static double namdWallTimer()
Definition: Controller.C:57
double memusage_MB()
Definition: memusage.h:13
double standard_deviation() const
Definition: Controller.h:39
void add_sample(double x)
Definition: Controller.h:29
SimParameters *const simParams
Definition: Controller.h:348
double average() const
Definition: Controller.h:35
double BigReal
Definition: common.h:123

◆ reassignVelocities()

void Controller::reassignVelocities ( int  step)
protected

Definition at line 1750 of file Controller.C.

References endi(), iout, SimParameters::reassignFreq, SimParameters::reassignHold, SimParameters::reassignIncr, SimParameters::reassignTemp, and simParams.

Referenced by integrate().

1751 {
1752  const int reassignFreq = simParams->reassignFreq;
1753  if ( ( reassignFreq > 0 ) && ! ( step % reassignFreq ) ) {
1754  BigReal newTemp = simParams->reassignTemp;
1755  newTemp += ( step / reassignFreq ) * simParams->reassignIncr;
1756  if ( simParams->reassignIncr > 0.0 ) {
1757  if ( newTemp > simParams->reassignHold && simParams->reassignHold > 0.0 )
1758  newTemp = simParams->reassignHold;
1759  } else {
1760  if ( newTemp < simParams->reassignHold )
1761  newTemp = simParams->reassignHold;
1762  }
1763  iout << "REASSIGNING VELOCITIES AT STEP " << step
1764  << " TO " << newTemp << " KELVIN.\n" << endi;
1765  }
1766 }
BigReal reassignTemp
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
BigReal reassignIncr
SimParameters *const simParams
Definition: Controller.h:348
BigReal reassignHold
double BigReal
Definition: common.h:123

◆ rebalanceLoad()

void Controller::rebalanceLoad ( int  step)
protected

Definition at line 5200 of file Controller.C.

References fflush_count, LdbCoordinator::getNumStepsToRun(), ldbSteps, namdWallTimer(), Node::Object(), LdbCoordinator::Object(), Node::outputPatchComputeMaps(), and LdbCoordinator::rebalance().

Referenced by integrate().

5201 {
5202  if ( ! ldbSteps ) {
5204  }
5205  if ( ! --ldbSteps ) {
5206  startBenchTime -= namdWallTimer();
5207  Node::Object()->outputPatchComputeMaps("before_ldb", step);
5209  startBenchTime += namdWallTimer();
5210  fflush_count = 3;
5211  }
5212 }
static Node * Object()
Definition: Node.h:86
int fflush_count
Definition: Controller.h:336
void outputPatchComputeMaps(const char *filename, int tag)
Definition: Node.C:1560
static double namdWallTimer()
Definition: Controller.C:57
void rebalance(Sequencer *seq, PatchID id)
static LdbCoordinator * Object()
int ldbSteps
Definition: Controller.h:334
int getNumStepsToRun(void)

◆ receivePressure()

void Controller::receivePressure ( int  step,
int  minimize = 0 
)
protected

Definition at line 1862 of file Controller.C.

References SimParameters::accelMDDebugOn, SimParameters::accelMDOn, SimParameters::accelMDOutFreq, BOLTZMANN, calcPressure(), SimParameters::comMove, controlNumDegFreedom, controlPressure, controlPressure_nbond, controlPressure_normal, controlPressure_slow, SimParameters::CUDASOAintegrate, drudeBondTemp, SimParameters::drudeOn, endi(), SimParameters::fixCellDims, SimParameters::fixCellDimX, SimParameters::fixCellDimY, SimParameters::fixCellDimZ, SimParameters::fixedAtomsOn, GET_TENSOR, GET_VECTOR, groupPressure, groupPressure_nbond, groupPressure_normal, groupPressure_slow, iINFO(), iout, RequireReduction::item(), NodeReduction::item(), kineticEnergy, kineticEnergyCentered, kineticEnergyHalfstep, SimParameters::langevinOn, minimize(), Node::molecule, momentumSqrSum, nodeReduction, Molecule::num_deg_freedom(), Molecule::num_fixed_atoms(), Molecule::num_fixed_groups(), Molecule::num_group_deg_freedom(), Molecule::numAtoms, Molecule::numConstraints, numDegFreedom, Molecule::numDrudeAtoms, Molecule::numFepInitial, Molecule::numFixedAtoms, Molecule::numFixedGroups, Molecule::numFixedRigidBonds, Molecule::numHydrogenGroups, Molecule::numLonepairs, Molecule::numRigidBonds, Node::Object(), SimParameters::pairInteractionOn, pressure, pressure_amd, pressure_nbond, pressure_normal, pressure_slow, PRESSUREFACTOR, reduction, REDUCTION_CENTERED_KINETIC_ENERGY, REDUCTION_DRUDEBOND_CENTERED_KINETIC_ENERGY, REDUCTION_DRUDECOM_CENTERED_KINETIC_ENERGY, REDUCTION_HALFSTEP_KINETIC_ENERGY, REDUCTION_INT_CENTERED_KINETIC_ENERGY, REDUCTION_INT_HALFSTEP_KINETIC_ENERGY, RequireReduction::require(), simParams, state, temperature, and SimParameters::useGroupPressure.

Referenced by integrate(), and printMinimizeEnergies().

1863 {
1864  Node *node = Node::Object();
1865  Molecule *molecule = node->molecule;
1866  Lattice &lattice = state->lattice;
1867  bool cudaIntegrator = simParams->CUDASOAintegrate;
1868 
1869  if(!cudaIntegrator) reduction->require();
1870 
1871  Tensor virial_normal;
1872  Tensor virial_nbond;
1873  Tensor virial_slow;
1874 #ifdef ALTVIRIAL
1875  Tensor altVirial_normal;
1876  Tensor altVirial_nbond;
1877  Tensor altVirial_slow;
1878 #endif
1879  Tensor intVirial_normal;
1880  Tensor intVirial_nbond;
1881  Tensor intVirial_slow;
1882  Vector extForce_normal;
1883  Vector extForce_nbond;
1884  Vector extForce_slow;
1885 
1886 #if 1
1887  numDegFreedom = molecule->num_deg_freedom();
1888  int64_t numGroupDegFreedom = molecule->num_group_deg_freedom();
1889  int numFixedGroups = molecule->num_fixed_groups();
1890  int numFixedAtoms = molecule->num_fixed_atoms();
1891 #endif
1892 #if 0
1893  int numAtoms = molecule->numAtoms;
1894  numDegFreedom = 3 * numAtoms;
1895  int numGroupDegFreedom = 3 * molecule->numHydrogenGroups;
1896  int numFixedAtoms =
1897  ( simParams->fixedAtomsOn ? molecule->numFixedAtoms : 0 );
1898  int numLonepairs = molecule->numLonepairs;
1899  int numFixedGroups = ( numFixedAtoms ? molecule->numFixedGroups : 0 );
1900  if ( numFixedAtoms ) numDegFreedom -= 3 * numFixedAtoms;
1901  if (numLonepairs) numDegFreedom -= 3 * numLonepairs;
1902  if ( numFixedGroups ) numGroupDegFreedom -= 3 * numFixedGroups;
1903  if ( ! ( numFixedAtoms || molecule->numConstraints
1904  || simParams->comMove || simParams->langevinOn ) ) {
1905  numDegFreedom -= 3;
1906  numGroupDegFreedom -= 3;
1907  }
1909  // this doesn't attempt to deal with fixed atoms or constraints
1910  numDegFreedom = 3 * molecule->numFepInitial;
1911  }
1912  int numRigidBonds = molecule->numRigidBonds;
1913  int numFixedRigidBonds =
1914  ( simParams->fixedAtomsOn ? molecule->numFixedRigidBonds : 0 );
1915 
1916  // numLonepairs is subtracted here because all lonepairs have a rigid bond
1917  // to oxygen, but all of the LP degrees of freedom are dealt with above
1918  numDegFreedom -= ( numRigidBonds - numFixedRigidBonds - numLonepairs);
1919 #endif
1920  BigReal groupKineticEnergyHalfstep, groupKineticEnergyCentered;
1921 #ifdef NODEGROUP_FORCE_REGISTER
1922  if(cudaIntegrator){
1925  groupKineticEnergyHalfstep = kineticEnergyHalfstep -
1927  groupKineticEnergyCentered = kineticEnergyCentered -
1929  }else{
1930 #endif
1933  groupKineticEnergyHalfstep = kineticEnergyHalfstep -
1935  groupKineticEnergyCentered = kineticEnergyCentered -
1937 #ifdef NODEGROUP_FORCE_REGISTER
1938  }
1939 #endif
1940 
1941 
1942 
1943  BigReal atomTempHalfstep = 2.0 * kineticEnergyHalfstep
1944  / ( numDegFreedom * BOLTZMANN );
1945  BigReal atomTempCentered = 2.0 * kineticEnergyCentered
1946  / ( numDegFreedom * BOLTZMANN );
1947  BigReal groupTempHalfstep = 2.0 * groupKineticEnergyHalfstep
1948  / ( numGroupDegFreedom * BOLTZMANN );
1949  BigReal groupTempCentered = 2.0 * groupKineticEnergyCentered
1950  / ( numGroupDegFreedom * BOLTZMANN );
1951 
1952  /* test code for comparing different temperatures
1953  iout << "TEMPTEST: " << step << " " <<
1954  atomTempHalfstep << " " <<
1955  atomTempCentered << " " <<
1956  groupTempHalfstep << " " <<
1957  groupTempCentered << "\n" << endi;
1958  iout << "Number of degrees of freedom: " << numDegFreedom << " " <<
1959  numGroupDegFreedom << "\n" << endi;
1960  */
1961 #ifdef NODEGROUP_FORCE_REGISTER
1962  if(cudaIntegrator){
1963  GET_TENSOR(momentumSqrSum, nodeReduction,REDUCTION_MOMENTUM_SQUARED);
1964 
1965  GET_TENSOR(virial_normal,nodeReduction,REDUCTION_VIRIAL_NORMAL);
1966  GET_TENSOR(virial_nbond, nodeReduction,REDUCTION_VIRIAL_NBOND);
1967  GET_TENSOR(virial_slow, nodeReduction,REDUCTION_VIRIAL_SLOW);
1968  }else{
1969 #endif
1970  GET_TENSOR(momentumSqrSum, reduction,REDUCTION_MOMENTUM_SQUARED);
1971 
1972  GET_TENSOR(virial_normal, reduction,REDUCTION_VIRIAL_NORMAL);
1973  GET_TENSOR(virial_nbond, reduction,REDUCTION_VIRIAL_NBOND);
1974  GET_TENSOR(virial_slow, reduction,REDUCTION_VIRIAL_SLOW);
1975 #ifdef NODEGROUP_FORCE_REGISTER
1976  }
1977 #endif
1978 
1979 #ifdef ALTVIRIAL
1980 #ifdef NODEGROUP_FORCE_REGISTER
1981  if(cudaIntegrator){
1982  GET_TENSOR(altVirial_normal,nodeReduction,REDUCTION_ALT_VIRIAL_NORMAL);
1983  GET_TENSOR(altVirial_nbond, nodeReduction,REDUCTION_ALT_VIRIAL_NBOND);
1984  GET_TENSOR(altVirial_slow, nodeReduction,REDUCTION_ALT_VIRIAL_SLOW);
1985  }else{
1986 #endif
1987  GET_TENSOR(altVirial_normal, reduction,REDUCTION_ALT_VIRIAL_NORMAL);
1988  GET_TENSOR(altVirial_nbond, reduction,REDUCTION_ALT_VIRIAL_NBOND);
1989  GET_TENSOR(altVirial_slow, reduction,REDUCTION_ALT_VIRIAL_SLOW);
1990 #ifdef NODEGROUP_FORCE_REGISTER
1991  }
1992 #endif
1993 #endif
1994 
1995 #ifdef NODEGROUP_FORCE_REGISTER
1996  if(cudaIntegrator){
1997  GET_TENSOR(intVirial_normal,nodeReduction,REDUCTION_INT_VIRIAL_NORMAL);
1998  GET_TENSOR(intVirial_nbond, nodeReduction,REDUCTION_INT_VIRIAL_NBOND);
1999  GET_TENSOR(intVirial_slow, nodeReduction,REDUCTION_INT_VIRIAL_SLOW);
2000 
2001  GET_VECTOR(extForce_normal,nodeReduction,REDUCTION_EXT_FORCE_NORMAL);
2002  GET_VECTOR(extForce_nbond,nodeReduction,REDUCTION_EXT_FORCE_NBOND);
2003  GET_VECTOR(extForce_slow,nodeReduction,REDUCTION_EXT_FORCE_SLOW);
2004  }else{
2005 #endif
2006  GET_TENSOR(intVirial_normal, reduction,REDUCTION_INT_VIRIAL_NORMAL);
2007  GET_TENSOR(intVirial_nbond, reduction,REDUCTION_INT_VIRIAL_NBOND);
2008  GET_TENSOR(intVirial_slow, reduction,REDUCTION_INT_VIRIAL_SLOW);
2009 
2010  GET_VECTOR(extForce_normal, reduction,REDUCTION_EXT_FORCE_NORMAL);
2011  GET_VECTOR(extForce_nbond, reduction,REDUCTION_EXT_FORCE_NBOND);
2012  GET_VECTOR(extForce_slow, reduction,REDUCTION_EXT_FORCE_SLOW);
2013 #ifdef NODEGROUP_FORCE_REGISTER
2014  }
2015 #endif
2016 
2017  // APH NOTE: These four lines are now done in calcPressure()
2018  // Vector extPosition = lattice.origin();
2019  // virial_normal -= outer(extForce_normal,extPosition);
2020  // virial_nbond -= outer(extForce_nbond,extPosition);
2021  // virial_slow -= outer(extForce_slow,extPosition);
2022 
2025 
2026  if (simParams->drudeOn) {
2027  BigReal drudeComKE, drudeBondKE;
2028 #ifdef NODEGROUP_FORCE_REGISTER
2029  if(cudaIntegrator){
2030  drudeComKE
2032  drudeBondKE
2034  }else{
2035 #endif
2036  drudeComKE
2038  drudeBondKE
2040 #ifdef NODEGROUP_FORCE_REGISTER
2041  }
2042 #endif
2043  int g_bond = 3 * molecule->numDrudeAtoms;
2044  int g_com = numDegFreedom - g_bond;
2045  temperature = 2.0 * drudeComKE / (g_com * BOLTZMANN);
2046  drudeBondTemp = (g_bond!=0 ? (2.*drudeBondKE/(g_bond*BOLTZMANN)) : 0.);
2047  }
2048 
2049  // Calculate number of degrees of freedom (controlNumDegFreedom)
2050  if ( simParams->useGroupPressure )
2051  {
2052  controlNumDegFreedom = molecule->numHydrogenGroups - numFixedGroups;
2053  if ( ! ( numFixedAtoms || molecule->numConstraints
2054  || simParams->comMove || simParams->langevinOn ) ) {
2055  controlNumDegFreedom -= 1;
2056  }
2057  }
2058  else
2059  {
2061  }
2062  if (simParams->fixCellDims) {
2066  }
2067 
2068  // Calculate pressure tensors using virials
2069  calcPressure(step, minimize,
2070  virial_normal, virial_nbond, virial_slow,
2071  intVirial_normal, intVirial_nbond, intVirial_slow,
2072  extForce_normal, extForce_nbond, extForce_slow);
2073 
2074 #ifdef DEBUG_PRESSURE
2075  iout << iINFO << "Control pressure = " << controlPressure <<
2076  " = " << controlPressure_normal << " + " <<
2077  controlPressure_nbond << " + " << controlPressure_slow << "\n" << endi;
2078 #endif
2080  iout << " PRESS " << trace(pressure)*PRESSUREFACTOR/3. << "\n"
2081  << " PNORMAL " << trace(pressure_normal)*PRESSUREFACTOR/3. << "\n"
2082  << " PNBOND " << trace(pressure_nbond)*PRESSUREFACTOR/3. << "\n"
2083  << " PSLOW " << trace(pressure_slow)*PRESSUREFACTOR/3. << "\n"
2084  << " PAMD " << trace(pressure_amd)*PRESSUREFACTOR/3. << "\n"
2085  << " GPRESS " << trace(groupPressure)*PRESSUREFACTOR/3. << "\n"
2086  << " GPNORMAL " << trace(groupPressure_normal)*PRESSUREFACTOR/3. << "\n"
2087  << " GPNBOND " << trace(groupPressure_nbond)*PRESSUREFACTOR/3. << "\n"
2088  << " GPSLOW " << trace(groupPressure_slow)*PRESSUREFACTOR/3. << "\n"
2089  << endi;
2090  }
2091 }
static Node * Object()
Definition: Node.h:86
int numFixedGroups
Definition: Molecule.h:637
Tensor controlPressure_slow
Definition: Controller.h:161
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
Tensor groupPressure_nbond
Definition: Controller.h:157
void calcPressure(int step, int minimize, const Tensor &virial_normal_in, const Tensor &virial_nbond_in, const Tensor &virial_slow_in, const Tensor &intVirial_normal, const Tensor &intVirial_nbond, const Tensor &intVirial_slow, const Vector &extForce_normal, const Vector &extForce_nbond, const Vector &extForce_slow)
Definition: Controller.C:2102
#define BOLTZMANN
Definition: common.h:54
Definition: Node.h:78
int numHydrogenGroups
Definition: Molecule.h:633
Tensor controlPressure
Definition: Controller.h:255
void minimize()
Definition: Controller.C:765
Definition: Vector.h:72
#define PRESSUREFACTOR
Definition: common.h:56
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
Tensor pressure_amd
Definition: Controller.h:154
#define GET_TENSOR(O, R, A)
Definition: ReductionMgr.h:60
Bool pairInteractionOn
Molecule stores the structural information for the system.
Definition: Molecule.h:175
Tensor pressure_slow
Definition: Controller.h:153
BigReal temperature
Definition: Controller.h:246
NamdState *const state
Definition: Controller.h:349
Tensor pressure
Definition: Controller.h:252
void require(void)
Definition: ReductionMgr.h:342
Tensor groupPressure_slow
Definition: Controller.h:158
int numLonepairs
Number of lone pairs.
Definition: Molecule.h:609
int64_t numDegFreedom
Definition: Controller.h:186
BigReal drudeBondTemp
Definition: Controller.h:240
ReductionValue & item(int index)
Definition: ReductionMgr.C:633
int numFixedRigidBonds
Definition: Molecule.h:639
int numFepInitial
Definition: Molecule.h:641
BigReal kineticEnergyCentered
Definition: Controller.h:245
int numFixedAtoms
Definition: Molecule.h:630
int num_fixed_atoms() const
Definition: Molecule.h:526
int numAtoms
Definition: Molecule.h:585
#define GET_VECTOR(O, R, A)
Definition: ReductionMgr.h:55
Tensor groupPressure_normal
Definition: Controller.h:156
int numConstraints
Definition: Molecule.h:622
int num_fixed_groups() const
Definition: Molecule.h:532
Definition: Tensor.h:15
Tensor pressure_normal
Definition: Controller.h:151
BigReal item(int i) const
Definition: ReductionMgr.h:341
Tensor groupPressure
Definition: Controller.h:253
int64_t num_deg_freedom(int isInitialReport=0) const
Definition: Molecule.h:552
BigReal kineticEnergyHalfstep
Definition: Controller.h:244
SimParameters *const simParams
Definition: Controller.h:348
Tensor controlPressure_normal
Definition: Controller.h:159
int64_t num_group_deg_freedom() const
Definition: Molecule.h:539
int numDrudeAtoms
Number of Drude particles.
Definition: Molecule.h:610
RequireReduction * reduction
Definition: Controller.h:350
NodeReduction * nodeReduction
Definition: Controller.h:354
int numRigidBonds
Definition: Molecule.h:638
Molecule * molecule
Definition: Node.h:179
int controlNumDegFreedom
Definition: Controller.h:254
Tensor pressure_nbond
Definition: Controller.h:152
Tensor controlPressure_nbond
Definition: Controller.h:160
BigReal kineticEnergy
Definition: Controller.h:243
Tensor momentumSqrSum
Definition: Controller.h:325
double BigReal
Definition: common.h:123

◆ recvCheckpointAck()

void Controller::recvCheckpointAck ( checkpoint cp)
protected

Definition at line 5191 of file Controller.C.

References checkpoint_task, Controller::checkpoint::lattice, SCRIPT_CHECKPOINT_LOAD, SCRIPT_CHECKPOINT_SWAP, state, and Controller::checkpoint::state.

Referenced by Node::recvCheckpointAck().

5191  { // initiating replica
5193  state->lattice = cp.lattice;
5194  *(ControllerState*)this = cp.state;
5195  }
5196  CkpvAccess(_qd)->process();
5197 }
NamdState *const state
Definition: Controller.h:349
int checkpoint_task
Definition: Controller.h:391

◆ recvCheckpointReq()

void Controller::recvCheckpointReq ( const char *  key,
int  task,
checkpoint cp 
)
protected

Definition at line 5161 of file Controller.C.

References checkpoints, NAMD_die(), SCRIPT_CHECKPOINT_FREE, SCRIPT_CHECKPOINT_LOAD, SCRIPT_CHECKPOINT_STORE, SCRIPT_CHECKPOINT_SWAP, and msm::swap().

Referenced by Node::recvCheckpointReq().

5161  { // responding replica
5162  switch ( task ) {
5164  if ( ! checkpoints.count(key) ) {
5165  checkpoints[key] = new checkpoint;
5166  }
5167  *checkpoints[key] = cp;
5168  break;
5170  if ( ! checkpoints.count(key) ) {
5171  NAMD_die("Unable to load checkpoint, requested key was never stored.");
5172  }
5173  cp = *checkpoints[key];
5174  break;
5176  if ( ! checkpoints.count(key) ) {
5177  NAMD_die("Unable to swap checkpoint, requested key was never stored.");
5178  }
5179  std::swap(cp,*checkpoints[key]);
5180  break;
5182  if ( ! checkpoints.count(key) ) {
5183  NAMD_die("Unable to free checkpoint, requested key was never stored.");
5184  }
5185  delete checkpoints[key];
5186  checkpoints.erase(key);
5187  break;
5188  }
5189 }
std::map< std::string, checkpoint * > checkpoints
Definition: Controller.h:390
void swap(Array< T > &s, Array< T > &t)
Definition: MsmMap.h:319
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ rescaleaccelMD()

void Controller::rescaleaccelMD ( int  step,
int  minimize = 0 
)
protected

Definition at line 2413 of file Controller.C.

References SimParameters::accelMDalpha, SimParameters::accelMDDebugOn, SimParameters::accelMDdihe, SimParameters::accelMDdual, accelMDdV, accelMDdVAverage, SimParameters::accelMDE, SimParameters::accelMDFirstStep, SimParameters::accelMDG, SimParameters::accelMDGcMDPrepSteps, SimParameters::accelMDGcMDSteps, SimParameters::accelMDGEquiPrepSteps, SimParameters::accelMDGEquiSteps, SimParameters::accelMDGiE, SimParameters::accelMDGresetVaftercmd, SimParameters::accelMDGRestart, SimParameters::accelMDGRestartFile, SimParameters::accelMDGSigma0D, SimParameters::accelMDGSigma0P, SimParameters::accelMDGStatWindow, SimParameters::accelMDLastStep, SimParameters::accelMDOn, SimParameters::accelMDOutFreq, ControllerBroadcasts::accelMDRescaleFactor, SimParameters::accelMDTalpha, SimParameters::accelMDTE, amd_reduction, broadcast, calc_accelMDG_E_k(), calc_accelMDG_force_factor(), calc_accelMDG_mean_std(), electEnergy, electEnergySlow, endi(), SimParameters::firstTimestep, GET_TENSOR, goNativeEnergy, goNonnativeEnergy, goTotalEnergy, groGaussEnergy, groLJEnergy, iout, SubmitReduction::item(), RequireReduction::item(), iWARN(), SimParameters::LJcorrection, SimParameters::LJcorrectionAlt, ljEnergy, minimize(), Node::molecule, SimParameters::N, NAMD_die(), nbondFreq, Node::Object(), PRESSUREFACTOR, SimpleBroadcastObject< T >::publish(), REDUCTION_ANGLE_ENERGY, REDUCTION_BC_ENERGY, REDUCTION_BOND_ENERGY, REDUCTION_CROSSTERM_ENERGY, REDUCTION_DIHEDRAL_ENERGY, REDUCTION_ELECT_ENERGY, REDUCTION_ELECT_ENERGY_SLOW, REDUCTION_GO_NATIVE_ENERGY, REDUCTION_GO_NONNATIVE_ENERGY, REDUCTION_GRO_GAUSS_ENERGY, REDUCTION_GRO_LJ_ENERGY, REDUCTION_IMPROPER_ENERGY, REDUCTION_LJ_ENERGY, REDUCTION_MAX_RESERVED, REDUCTION_MISC_ENERGY, RequireReduction::require(), SimParameters::restartFrequency, simParams, slowFreq, state, SubmitReduction::submit(), submit_reduction, Molecule::tail_corr_ener, virial_amd, Lattice::volume(), and write_accelMDG_rest_file().

Referenced by integrate(), and printMinimizeEnergies().

2414 {
2415  if ( !simParams->accelMDOn ) return;
2416 
2418 
2419  // copy all to submit_reduction
2420  for ( int i=0; i<REDUCTION_MAX_RESERVED; ++i ) {
2422  }
2424 
2425  if (step == simParams->firstTimestep) {
2426  accelMDdVAverage = 0;
2427  accelMDdV = 0;
2428  }
2429 // if ( minimize || ((step < simParams->accelMDFirstStep ) || (step > simParams->accelMDLastStep ))) return;
2430  if ( minimize || (step < simParams->accelMDFirstStep ) || ( simParams->accelMDLastStep > 0 && step > simParams->accelMDLastStep )) return;
2431 
2432  Node *node = Node::Object();
2433  Molecule *molecule = node->molecule;
2434  Lattice &lattice = state->lattice;
2435 
2436  const BigReal accelMDE = simParams->accelMDE;
2437  const BigReal accelMDalpha = simParams->accelMDalpha;
2438  const BigReal accelMDTE = simParams->accelMDTE;
2439  const BigReal accelMDTalpha = simParams->accelMDTalpha;
2440  const int accelMDOutFreq = simParams->accelMDOutFreq;
2441 
2442  //GaMD
2443  static BigReal VmaxP, VminP, VavgP, M2P=0, sigmaVP;
2444  static BigReal VmaxD, VminD, VavgD, M2D=0, sigmaVD;
2445  static BigReal k0P, kP, EP;
2446  static BigReal k0D, kD, ED;
2447  static int V_n = 1, iEusedD, iEusedP;
2448  static char warnD, warnP;
2449  static int restfreq;
2450 
2453  const int ntcmd = simParams->accelMDFirstStep + simParams->accelMDGcMDSteps;
2454  const int ntebprep = ntcmd + simParams->accelMDGEquiPrepSteps;
2455  const int nteb = ntcmd + simParams->accelMDGEquiSteps;
2456  const int ntave = simParams->accelMDGStatWindow;
2457 
2458  BigReal volume;
2459  BigReal bondEnergy;
2460  BigReal angleEnergy;
2461  BigReal dihedralEnergy;
2462  BigReal improperEnergy;
2463  BigReal crosstermEnergy;
2464  BigReal boundaryEnergy;
2465  BigReal miscEnergy;
2466  BigReal amd_electEnergy;
2467  BigReal amd_ljEnergy;
2468  BigReal amd_ljEnergy_Corr = 0.;
2469  BigReal amd_electEnergySlow;
2470  BigReal amd_groLJEnergy;
2471  BigReal amd_groGaussEnergy;
2472  BigReal amd_goTotalEnergy;
2473  BigReal potentialEnergy;
2474  BigReal factor_dihe = 1;
2475  BigReal factor_tot = 1;
2476  BigReal testV;
2477  BigReal dV = 0.;
2478  Vector accelMDfactor;
2479  Tensor vir; //auto initialized to 0
2480  Tensor vir_dihe;
2481  Tensor vir_normal;
2482  Tensor vir_nbond;
2483  Tensor vir_slow;
2484 
2485  volume = lattice.volume();
2486 
2487  bondEnergy = amd_reduction->item(REDUCTION_BOND_ENERGY);
2488  angleEnergy = amd_reduction->item(REDUCTION_ANGLE_ENERGY);
2489  dihedralEnergy = amd_reduction->item(REDUCTION_DIHEDRAL_ENERGY);
2490  improperEnergy = amd_reduction->item(REDUCTION_IMPROPER_ENERGY);
2491  crosstermEnergy = amd_reduction->item(REDUCTION_CROSSTERM_ENERGY);
2492  boundaryEnergy = amd_reduction->item(REDUCTION_BC_ENERGY);
2493  miscEnergy = amd_reduction->item(REDUCTION_MISC_ENERGY);
2494 
2495  GET_TENSOR(vir_dihe,amd_reduction,REDUCTION_VIRIAL_AMD_DIHE);
2496  GET_TENSOR(vir_normal,amd_reduction,REDUCTION_VIRIAL_NORMAL);
2497  GET_TENSOR(vir_nbond,amd_reduction,REDUCTION_VIRIAL_NBOND);
2498  GET_TENSOR(vir_slow,amd_reduction,REDUCTION_VIRIAL_SLOW);
2499 
2500  if ( !( step % nbondFreq ) ) {
2501  amd_electEnergy = amd_reduction->item(REDUCTION_ELECT_ENERGY);
2502  amd_ljEnergy = amd_reduction->item(REDUCTION_LJ_ENERGY);
2503  amd_groLJEnergy = amd_reduction->item(REDUCTION_GRO_LJ_ENERGY);
2504  amd_groGaussEnergy = amd_reduction->item(REDUCTION_GRO_GAUSS_ENERGY);
2507  amd_goTotalEnergy = goNativeEnergy + goNonnativeEnergy;
2508  } else {
2509  amd_electEnergy = electEnergy;
2510  amd_ljEnergy = ljEnergy;
2511  amd_groLJEnergy = groLJEnergy;
2512  amd_groGaussEnergy = groGaussEnergy;
2513  amd_goTotalEnergy = goTotalEnergy;
2514  }
2515 
2516  if( (simParams->LJcorrection || simParams->LJcorrectionAlt) && volume ) {
2517  // Obtain tail correction (copied from printEnergies())
2518  // This value is only printed for sanity check
2519  // accelMD currently does not 'boost' tail correction
2520  amd_ljEnergy_Corr = molecule->tail_corr_ener / volume;
2521  }
2522 
2523  if ( !( step % slowFreq ) ) {
2524  amd_electEnergySlow = amd_reduction->item(REDUCTION_ELECT_ENERGY_SLOW);
2525  } else {
2526  amd_electEnergySlow = electEnergySlow;
2527  }
2528 
2529  potentialEnergy = bondEnergy + angleEnergy + dihedralEnergy +
2530  improperEnergy + amd_electEnergy + amd_electEnergySlow + amd_ljEnergy +
2531  crosstermEnergy + boundaryEnergy + miscEnergy +
2532  amd_goTotalEnergy + amd_groLJEnergy + amd_groGaussEnergy;
2533 
2534  //GaMD
2535  if(simParams->accelMDG){
2536  // if first time running accelMDG module
2537  if(step == firststep) {
2538  iEusedD = iEusedP = simParams->accelMDGiE;
2539  warnD = warnP = '\0';
2540 
2541  //restart file reading
2543  FILE *rest = fopen(simParams->accelMDGRestartFile, "r");
2544  char line[256];
2545  int dihe_n=0, tot_n=0;
2546  if(!rest){
2547  sprintf(line, "Cannot open accelMDG restart file: %s", simParams->accelMDGRestartFile);
2548  NAMD_die(line);
2549  }
2550 
2551  while(fgets(line, 256, rest)){
2552  if(line[0] == 'D'){
2553  dihe_n = sscanf(line+1, " %d %la %la %la %la %la %la %la",
2554  &V_n, &VmaxD, &VminD, &VavgD, &sigmaVD, &M2D, &ED, &kD);
2555  }
2556  else if(line[0] == 'T'){
2557  tot_n = sscanf(line+1, " %d %la %la %la %la %la %la %la",
2558  &V_n, &VmaxP, &VminP, &VavgP, &sigmaVP, &M2P, &EP, &kP);
2559  }
2560  }
2561 
2562  fclose(rest);
2563 
2564  V_n++;
2565 
2566  //check dihe settings
2568  if(dihe_n !=8)
2569  NAMD_die("Invalid dihedral potential energy format in accelMDG restart file");
2570  k0D = kD * (VmaxD - VminD);
2571  iout << "GAUSSIAN ACCELERATED MD READ FROM RESTART FILE: DIHED"
2572  << " Vmax " << VmaxD << " Vmin " << VminD
2573  << " Vavg " << VavgD << " sigmaV " << sigmaVD
2574  << " E " << ED << " k " << kD
2575  << "\n" << endi;
2576  }
2577 
2578  //check tot settings
2580  if(tot_n !=8)
2581  NAMD_die("Invalid total potential energy format in accelMDG restart file");
2582  k0P = kP * (VmaxP - VminP);
2583  iout << "GAUSSIAN ACCELERATED MD READ FROM RESTART FILE: TOTAL"
2584  << " Vmax " << VmaxP << " Vmin " << VminP
2585  << " Vavg " << VavgP << " sigmaV " << sigmaVP
2586  << " E " << EP << " k " << kP
2587  << "\n" << endi;
2588  }
2589 
2590  iEusedD = (ED == VmaxD) ? 1 : 2;
2591  iEusedP = (EP == VmaxP) ? 1 : 2;
2592  }
2593  //local restfreq follows NAMD restartfreq (default: 500)
2595  }
2596 
2597  //for dihedral potential
2599  testV = dihedralEnergy + crosstermEnergy;
2600 
2601  //write restart file every restartfreq steps
2602  if(step > firststep && step % restfreq == 0)
2603  write_accelMDG_rest_file(step, 'D', V_n, VmaxD, VminD, VavgD, sigmaVD, M2D, ED, kD,
2604  true, false);
2605  //write restart file at the end of the simulation
2606  if( simParams->accelMDLastStep > 0 ){
2607  if( step == simParams->accelMDLastStep )
2608  write_accelMDG_rest_file(step, 'D', V_n, VmaxD, VminD, VavgD, sigmaVD, M2D, ED, kD,
2609  true, true);
2610  }
2611  else if(step == simParams->N)
2612  write_accelMDG_rest_file(step, 'D', V_n, VmaxD, VminD, VavgD, sigmaVD, M2D, ED, kD,
2613  true, true);
2614 
2615  //conventional MD
2616  if(step < ntcmd){
2617  //very first step
2618  if(step == firststep && !simParams->accelMDGRestart){
2619  //initialize stat
2620  VmaxD = VminD = VavgD = testV;
2621  M2D = sigmaVD = 0.;
2622  }
2623  //first step after cmdprep
2624  else if(step == ntcmdprep && ntcmdprep != 0){
2625  //reset stat
2626  VmaxD = VminD = VavgD = testV;
2627  M2D = sigmaVD = 0.;
2628  iout << "GAUSSIAN ACCELERATED MD: RESET DIHEDRAL POTENTIAL STATISTICS\n" << endi;
2629  }
2630  //every ntave steps
2631  else if(ntave > 0 && step % ntave == 0){
2632  //update Vmax Vmin
2633  if(testV > VmaxD) VmaxD = testV;
2634  if(testV < VminD) VminD = testV;
2635  //reset avg and std
2636  VavgD = testV;
2637  M2D = sigmaVD = 0.;
2638  iout << "GAUSSIAN ACCELERATED MD: RESET DIHEDRAL POTENTIAL AVG AND STD\n" << endi;
2639  }
2640  //normal steps
2641  else
2642  calc_accelMDG_mean_std(testV, V_n,
2643  &VmaxD, &VminD, &VavgD, &M2D, &sigmaVD) ;
2644 
2645  //last cmd step
2646  if(step == ntcmd - 1){
2648  VmaxD, VminD, VavgD, sigmaVD, &k0D, &kD, &ED, &iEusedD, &warnD);
2649  }
2650  }
2651  //equilibration
2652  else if(step < nteb){
2653  calc_accelMDG_force_factor(kD, ED, testV, vir_dihe,
2654  &dV, &factor_dihe, &vir);
2655 
2656  //first step after cmd
2657  if(step == ntcmd && simParams->accelMDGresetVaftercmd){
2658  //reset stat
2659  VmaxD = VminD = VavgD = testV;
2660  M2D = sigmaVD = 0.;
2661  iout << "GAUSSIAN ACCELERATED MD: RESET DIHEDRAL POTENTIAL STATISTICS\n" << endi;
2662  }
2663  //every ntave steps
2664  else if(ntave > 0 && step % ntave == 0){
2665  //update Vmax Vmin
2666  if(testV > VmaxD) VmaxD = testV;
2667  if(testV < VminD) VminD = testV;
2668  //reset avg and std
2669  VavgD = testV;
2670  M2D = sigmaVD = 0.;
2671  iout << "GAUSSIAN ACCELERATED MD: RESET DIHEDRAL POTENTIAL AVG AND STD\n" << endi;
2672  }
2673  else
2674  calc_accelMDG_mean_std(testV, V_n,
2675  &VmaxD, &VminD, &VavgD, &M2D, &sigmaVD) ;
2676 
2677  //steps after ebprep
2678  if(step >= ntebprep)
2679  if((ntave > 0 && step % ntave == 0) || ntave <= 0)
2681  VmaxD, VminD, VavgD, sigmaVD, &k0D, &kD, &ED, &iEusedD, &warnD);
2682  }
2683  //production
2684  else{
2685  calc_accelMDG_force_factor(kD, ED, testV, vir_dihe,
2686  &dV, &factor_dihe, &vir);
2687  }
2688 
2689  }
2690  //for total potential
2692  Tensor vir_tot = vir_normal + vir_nbond + vir_slow;
2693  testV = potentialEnergy;
2694  if(simParams->accelMDdual){
2695  testV -= dihedralEnergy + crosstermEnergy;
2696  vir_tot -= vir_dihe;
2697  }
2698 
2699  //write restart file every restartfreq steps
2700  if(step > firststep && step % restfreq == 0)
2701  write_accelMDG_rest_file(step, 'T', V_n, VmaxP, VminP, VavgP, sigmaVP, M2P, EP, kP,
2702  !simParams->accelMDdual, false);
2703  //write restart file at the end of simulation
2704  if( simParams->accelMDLastStep > 0 ){
2705  if( step == simParams->accelMDLastStep )
2706  write_accelMDG_rest_file(step, 'T', V_n, VmaxP, VminP, VavgP, sigmaVP, M2P, EP, kP,
2707  !simParams->accelMDdual, true);
2708  }
2709  else if(step == simParams->N)
2710  write_accelMDG_rest_file(step, 'T', V_n, VmaxP, VminP, VavgP, sigmaVP, M2P, EP, kP,
2711  !simParams->accelMDdual, true);
2712 
2713  //conventional MD
2714  if(step < ntcmd){
2715  //very first step
2716  if(step == firststep && !simParams->accelMDGRestart){
2717  //initialize stat
2718  VmaxP = VminP = VavgP = testV;
2719  M2P = sigmaVP = 0.;
2720  }
2721  //first step after cmdprep
2722  else if(step == ntcmdprep && ntcmdprep != 0){
2723  //reset stat
2724  VmaxP = VminP = VavgP = testV;
2725  M2P = sigmaVP = 0.;
2726  iout << "GAUSSIAN ACCELERATED MD: RESET TOTAL POTENTIAL STATISTICS\n" << endi;
2727  }
2728  //every ntave steps
2729  else if(ntave > 0 && step % ntave == 0){
2730  //update Vmax Vmin
2731  if(testV > VmaxP) VmaxP = testV;
2732  if(testV < VminP) VminP = testV;
2733  //reset avg and std
2734  VavgP = testV;
2735  M2P = sigmaVP = 0.;
2736  iout << "GAUSSIAN ACCELERATED MD: RESET TOTAL POTENTIAL AVG AND STD\n" << endi;
2737  }
2738  //normal steps
2739  else
2740  calc_accelMDG_mean_std(testV, V_n,
2741  &VmaxP, &VminP, &VavgP, &M2P, &sigmaVP);
2742  //last cmd step
2743  if(step == ntcmd - 1){
2745  VmaxP, VminP, VavgP, sigmaVP, &k0P, &kP, &EP, &iEusedP, &warnP);
2746  }
2747  }
2748  //equilibration
2749  else if(step < nteb){
2750  calc_accelMDG_force_factor(kP, EP, testV, vir_tot,
2751  &dV, &factor_tot, &vir);
2752 
2753  //first step after cmd
2754  if(step == ntcmd && simParams->accelMDGresetVaftercmd){
2755  //reset stat
2756  VmaxP = VminP = VavgP = testV;
2757  M2P = sigmaVP = 0.;
2758  iout << "GAUSSIAN ACCELERATED MD: RESET TOTAL POTENTIAL STATISTICS\n" << endi;
2759  }
2760  //every ntave steps
2761  else if(ntave > 0 && step % ntave == 0){
2762  //update Vmax Vmin
2763  if(testV > VmaxP) VmaxP = testV;
2764  if(testV < VminP) VminP = testV;
2765  //reset avg and std
2766  VavgP = testV;
2767  M2P = sigmaVP = 0.;
2768  iout << "GAUSSIAN ACCELERATED MD: RESET TOTAL POTENTIAL AVG AND STD\n" << endi;
2769  }
2770  else
2771  calc_accelMDG_mean_std(testV, V_n,
2772  &VmaxP, &VminP, &VavgP, &M2P, &sigmaVP);
2773 
2774  //steps after ebprep
2775  if(step >= ntebprep)
2776  if((ntave > 0 && step % ntave == 0) || ntave <= 0)
2778  VmaxP, VminP, VavgP, sigmaVP, &k0P, &kP, &EP, &iEusedP, &warnP);
2779  }
2780  //production
2781  else{
2782  calc_accelMDG_force_factor(kP, EP, testV, vir_tot,
2783  &dV, &factor_tot, &vir);
2784  }
2785 
2786  }
2787  accelMDdVAverage += dV;
2788 
2789  //first step after ntcmdprep
2790  if((ntcmdprep > 0 && step == ntcmdprep) ||
2791  (step < nteb && ntave > 0 && step % ntave == 0) ||
2792  (simParams->accelMDGresetVaftercmd && step == ntcmd)){
2793  V_n = 1;
2794  }
2795 
2796  if(step < nteb)
2797  V_n++;
2798 
2799  }
2800  //aMD
2801  else{
2802  if (simParams->accelMDdihe) {
2803 
2804  testV = dihedralEnergy + crosstermEnergy;
2805  if ( testV < accelMDE ) {
2806  factor_dihe = accelMDalpha/(accelMDalpha + accelMDE - testV);
2807  factor_dihe *= factor_dihe;
2808  vir = vir_dihe * (factor_dihe - 1.0);
2809  dV = (accelMDE - testV)*(accelMDE - testV)/(accelMDalpha + accelMDE - testV);
2810  accelMDdVAverage += dV;
2811  }
2812 
2813  } else if (simParams->accelMDdual) {
2814 
2815  testV = dihedralEnergy + crosstermEnergy;
2816  if ( testV < accelMDE ) {
2817  factor_dihe = accelMDalpha/(accelMDalpha + accelMDE - testV);
2818  factor_dihe *= factor_dihe;
2819  vir = vir_dihe * (factor_dihe - 1.0) ;
2820  dV = (accelMDE - testV)*(accelMDE - testV)/(accelMDalpha + accelMDE - testV);
2821  }
2822 
2823  testV = potentialEnergy - dihedralEnergy - crosstermEnergy;
2824  if ( testV < accelMDTE ) {
2825  factor_tot = accelMDTalpha/(accelMDTalpha + accelMDTE - testV);
2826  factor_tot *= factor_tot;
2827  vir += (vir_normal - vir_dihe + vir_nbond + vir_slow) * (factor_tot - 1.0);
2828  dV += (accelMDTE - testV)*(accelMDTE - testV)/(accelMDTalpha + accelMDTE - testV);
2829  }
2830  accelMDdVAverage += dV;
2831 
2832  } else {
2833 
2834  testV = potentialEnergy;
2835  if ( testV < accelMDE ) {
2836  factor_tot = accelMDalpha/(accelMDalpha + accelMDE - testV);
2837  factor_tot *= factor_tot;
2838  vir = (vir_normal + vir_nbond + vir_slow) * (factor_tot - 1.0);
2839  dV = (accelMDE - testV)*(accelMDE - testV)/(accelMDalpha + accelMDE - testV);
2840  accelMDdVAverage += dV;
2841  }
2842  }
2843  }
2844 
2845  accelMDfactor[0]=factor_dihe;
2846  accelMDfactor[1]=factor_tot;
2847  accelMDfactor[2]=1;
2848  broadcast->accelMDRescaleFactor.publish(step,accelMDfactor);
2849  virial_amd = vir;
2850  accelMDdV = dV;
2851 
2852  if ( factor_tot < 0.001 ) {
2853  iout << iWARN << "accelMD is using a very high boost potential, simulation may become unstable!"
2854  << "\n" << endi;
2855  }
2856 
2857  if ( ! (step % accelMDOutFreq) ) {
2858  if ( !(step == simParams->firstTimestep) ) {
2859  accelMDdVAverage = accelMDdVAverage/accelMDOutFreq;
2860  }
2861  iout << "ACCELERATED MD: STEP " << step
2862  << " dV " << dV
2863  << " dVAVG " << accelMDdVAverage
2864  << " BOND " << bondEnergy
2865  << " ANGLE " << angleEnergy
2866  << " DIHED " << dihedralEnergy+crosstermEnergy
2867  << " IMPRP " << improperEnergy
2868  << " ELECT " << amd_electEnergy+amd_electEnergySlow
2869  << " VDW " << amd_ljEnergy
2870  << " POTENTIAL " << potentialEnergy;
2871  if(amd_ljEnergy_Corr)
2872  iout << " LJcorr " << amd_ljEnergy_Corr;
2873  iout << "\n" << endi;
2874  if(simParams->accelMDG){
2876  iout << "GAUSSIAN ACCELERATED MD: DIHED iE " << iEusedD
2877  << " Vmax " << VmaxD << " Vmin " << VminD
2878  << " Vavg " << VavgD << " sigmaV " << sigmaVD
2879  << " E " << ED << " k0 " << k0D << " k " << kD
2880  << "\n" << endi;
2881  if(warnD & 1)
2882  iout << "GAUSSIAN ACCELERATED MD: DIHED !!! WARNING: k0 > 1, "
2883  << "SWITCHED TO iE = 1 MODE !!!\n" << endi;
2884  if(warnD & 2)
2885  iout << "GAUSSIAN ACCELERATED MD: DIHED !!! WARNING: k0 <= 0, "
2886  << "SWITCHED TO iE = 1 MODE !!!\n" << endi;
2888  iout << "GAUSSIAN ACCELERATED MD: TOTAL iE " << iEusedP
2889  << " Vmax " << VmaxP << " Vmin " << VminP
2890  << " Vavg " << VavgP << " sigmaV " << sigmaVP
2891  << " E " << EP << " k0 " << k0P << " k " << kP
2892  << "\n" << endi;
2893  if(warnP & 1)
2894  iout << "GAUSSIAN ACCELERATED MD: TOTAL !!! WARNING: k0 > 1, "
2895  << "SWITCHED TO iE = 1 MODE !!!\n" << endi;
2896  if(warnP & 2)
2897  iout << "GAUSSIAN ACCELERATED MD: TOTAL !!! WARNING: k0 <= 0, "
2898  << "SWITCHED TO iE = 1 MODE !!!\n" << endi;
2899  warnD = warnP = '\0';
2900  }
2901 
2902  accelMDdVAverage = 0;
2903 
2904  if (simParams->accelMDDebugOn) {
2905  Tensor p_normal;
2906  Tensor p_nbond;
2907  Tensor p_slow;
2908  Tensor p;
2909  if ( volume != 0. ) {
2910  p_normal = vir_normal/volume;
2911  p_nbond = vir_nbond/volume;
2912  p_slow = vir_slow/volume;
2913  p = vir/volume;
2914  }
2915  iout << " accelMD Scaling Factor: " << accelMDfactor << "\n"
2916  << " accelMD PNORMAL " << trace(p_normal)*PRESSUREFACTOR/3. << "\n"
2917  << " accelMD PNBOND " << trace(p_nbond)*PRESSUREFACTOR/3. << "\n"
2918  << " accelMD PSLOW " << trace(p_slow)*PRESSUREFACTOR/3. << "\n"
2919  << " accelMD PAMD " << trace(p)*PRESSUREFACTOR/3. << "\n"
2920  << endi;
2921  }
2922  }
2923 }
static Node * Object()
Definition: Node.h:86
Bool accelMDGresetVaftercmd
int nbondFreq
Definition: Controller.h:162
BigReal accelMDE
void write_accelMDG_rest_file(int step_n, char type, int V_n, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, BigReal M2, BigReal E, BigReal k, bool write_topic, bool lasttime)
Definition: Controller.C:2355
BigReal goNativeEnergy
Definition: Controller.h:194
BigReal accelMDLastStep
Definition: Node.h:78
BigReal ljEnergy
Definition: Controller.h:191
void calc_accelMDG_mean_std(BigReal testV, int step_n, BigReal *Vmax, BigReal *Vmin, BigReal *Vavg, BigReal *M2, BigReal *sigmaV)
Definition: Controller.C:2290
void minimize()
Definition: Controller.C:765
Definition: Vector.h:72
#define PRESSUREFACTOR
Definition: common.h:56
int accelMDGEquiPrepSteps
BigReal & item(int i)
Definition: ReductionMgr.h:313
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal accelMDTE
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
BigReal accelMDalpha
#define GET_TENSOR(O, R, A)
Definition: ReductionMgr.h:60
BigReal tail_corr_ener
Definition: Molecule.h:498
BigReal electEnergySlow
Definition: Controller.h:190
Molecule stores the structural information for the system.
Definition: Molecule.h:175
RequireReduction * amd_reduction
Definition: Controller.h:351
BigReal accelMDTalpha
NamdState *const state
Definition: Controller.h:349
void require(void)
Definition: ReductionMgr.h:342
ControllerBroadcasts * broadcast
Definition: Controller.h:365
int accelMDGcMDPrepSteps
BigReal accelMDFirstStep
BigReal accelMDdV
Definition: Controller.h:117
SubmitReduction * submit_reduction
Definition: Controller.h:352
BigReal groLJEnergy
Definition: Controller.h:192
BigReal goTotalEnergy
Definition: Controller.h:196
NAMD_HOST_DEVICE BigReal volume(void) const
Definition: Lattice.h:293
BigReal groGaussEnergy
Definition: Controller.h:193
void NAMD_die(const char *err_msg)
Definition: common.C:147
Tensor virial_amd
Definition: Controller.h:155
void publish(int tag, const T &t)
SimpleBroadcastObject< Vector > accelMDRescaleFactor
Definition: Broadcasts.h:89
BigReal accelMDdVAverage
Definition: Controller.h:415
BigReal accelMDGSigma0P
char accelMDGRestartFile[NAMD_FILENAME_BUFFER_SIZE]
void calc_accelMDG_force_factor(BigReal k, BigReal E, BigReal testV, Tensor vir_orig, BigReal *dV, BigReal *factor, Tensor *vir)
Definition: Controller.C:2339
Definition: Tensor.h:15
BigReal item(int i) const
Definition: ReductionMgr.h:341
BigReal electEnergy
Definition: Controller.h:189
void calc_accelMDG_E_k(int iE, int V_n, BigReal sigma0, BigReal Vmax, BigReal Vmin, BigReal Vavg, BigReal sigmaV, BigReal *k0, BigReal *k, BigReal *E, int *iEused, char *warn)
Definition: Controller.C:2310
int slowFreq
Definition: Controller.h:163
SimParameters *const simParams
Definition: Controller.h:348
void submit(void)
Definition: ReductionMgr.h:324
BigReal accelMDGSigma0D
BigReal goNonnativeEnergy
Definition: Controller.h:195
Molecule * molecule
Definition: Node.h:179
double BigReal
Definition: common.h:123

◆ rescaleVelocities()

void Controller::rescaleVelocities ( int  step)
protected

Definition at line 1662 of file Controller.C.

References SimParameters::adaptTempFirstStep, SimParameters::adaptTempLastStep, SimParameters::adaptTempOn, SimParameters::adaptTempRescale, adaptTempT, broadcast, SimpleBroadcastObject< T >::publish(), SimParameters::rescaleFreq, SimParameters::rescaleTemp, rescaleVelocities_numTemps, rescaleVelocities_sumTemps, simParams, temperature, and ControllerBroadcasts::velocityRescaleFactor.

Referenced by integrate().

1663 {
1664  const int rescaleFreq = simParams->rescaleFreq;
1665  if ( rescaleFreq > 0 ) {
1667  if ( rescaleVelocities_numTemps == rescaleFreq ) {
1669  BigReal rescaleTemp = simParams->rescaleTemp;
1671  (!(simParams->adaptTempLastStep > 0) || step < simParams->adaptTempLastStep )) {
1672  rescaleTemp = adaptTempT;
1673  }
1674  BigReal factor = sqrt(rescaleTemp/avgTemp);
1675  broadcast->velocityRescaleFactor.publish(step,factor);
1676  //iout << "RESCALING VELOCITIES AT STEP " << step
1677  // << " FROM AVERAGE TEMPERATURE OF " << avgTemp
1678  // << " TO " << rescaleTemp << " KELVIN.\n" << endi;
1680  }
1681  }
1682 }
BigReal adaptTempT
Definition: Controller.h:428
BigReal temperature
Definition: Controller.h:246
ControllerBroadcasts * broadcast
Definition: Controller.h:365
BigReal rescaleTemp
BigReal rescaleVelocities_sumTemps
Definition: Controller.h:259
SimpleBroadcastObject< BigReal > velocityRescaleFactor
Definition: Broadcasts.h:70
void publish(int tag, const T &t)
int rescaleVelocities_numTemps
Definition: Controller.h:260
SimParameters *const simParams
Definition: Controller.h:348
double BigReal
Definition: common.h:123

◆ resetMovingAverage()

void Controller::resetMovingAverage ( )

Definition at line 639 of file Controller.C.

References groupPressureAverage, SimParameters::movingAverageWindowSize, pressureAverage, MovingAverage::reset(), simParams, temperatureAverage, and totalEnergyAverage.

639  {
640  const int size = simParams->movingAverageWindowSize;
643  pressureAverage.reset(size);
645 }
void reset(int mws=20)
Definition: Controller.h:56
int movingAverageWindowSize
MovingAverage totalEnergyAverage
Definition: Controller.h:447
MovingAverage temperatureAverage
Definition: Controller.h:448
MovingAverage pressureAverage
Definition: Controller.h:449
MovingAverage groupPressureAverage
Definition: Controller.h:450
SimParameters *const simParams
Definition: Controller.h:348

◆ resumeAfterTraceBarrier()

void Controller::resumeAfterTraceBarrier ( int  step)

Definition at line 5231 of file Controller.C.

References awaken(), broadcast, namdWallTimer(), SimpleBroadcastObject< T >::publish(), and ControllerBroadcasts::traceBarrier.

Referenced by Node::resumeAfterTraceBarrier().

5231  {
5232  broadcast->traceBarrier.publish(step,1);
5233  CkPrintf("Cycle time at trace sync (end) Wall at step %d: %f CPU %f\n", step, namdWallTimer()-firstWTime,CmiTimer()-firstCTime);
5234  awaken();
5235 }
SimpleBroadcastObject< int > traceBarrier
Definition: Broadcasts.h:88
static double namdWallTimer()
Definition: Controller.C:57
ControllerBroadcasts * broadcast
Definition: Controller.h:365
void awaken(void)
Definition: Controller.C:354
void publish(int tag, const T &t)

◆ run()

void Controller::run ( void  )

Definition at line 341 of file Controller.C.

References awaken(), CTRL_STK_SZ, DebugM, and Controller::CthThreadWrapper::thread.

Referenced by NamdState::runController().

342 {
343  // create a Thread and invoke it
344  DebugM(4, "Starting thread in controller on this=" << this << "\n");
345  threadWrapper = new CthThreadWrapper;
346  threadWrapper->thread = CthCreate((CthVoidFn)&(threadRun),(void*)(this),CTRL_STK_SZ);
347  CthSetStrategyDefault(threadWrapper->thread);
348 #if CMK_BLUEGENE_CHARM
349  BgAttach(thread);
350 #endif
351  awaken();
352 }
#define DebugM(x, y)
Definition: Debug.h:75
#define CTRL_STK_SZ
Definition: Thread.h:12
void awaken(void)
Definition: Controller.C:354

◆ stochRescaleCoefficient()

double Controller::stochRescaleCoefficient ( )

Calculate new coefficient for stochastic velocity rescaling and update heat.

Definition at line 1806 of file Controller.C.

References BOLTZMANN, Random::gaussian(), heat, numDegFreedom, random, simParams, SimParameters::stochRescaleTemp, stochRescaleTimefactor, Random::sum_of_squared_gaussians(), and temperature.

Referenced by stochRescaleVelocities().

1806  {
1807  const double stochRescaleTemp = simParams->stochRescaleTemp;
1808  double coefficient = 1;
1809  if ( temperature > 0 ) {
1810  double R1 = random->gaussian();
1811  // double gammaShape = 0.5*(numDegFreedom - 1);
1812  // R2sum is the sum of (numDegFreedom - 1) squared normal variables,
1813  // which is chi-squared distributed.
1814  // This is in turn a special case of the Gamma distribution,
1815  // which converges to a normal distribution in the limit of a
1816  // large shape parameter.
1817  // double R2sum = 2*(gammaShape+sqrt(gammaShape)*random->gaussian())+R1*R1;
1818  double R2sum = random->sum_of_squared_gaussians(numDegFreedom-1);
1819  double tempfactor = stochRescaleTemp/(temperature*numDegFreedom);
1820 
1821  coefficient = sqrt(stochRescaleTimefactor +
1822  (1 - stochRescaleTimefactor)*tempfactor*R2sum +
1823  2*R1*sqrt(tempfactor*(1 - stochRescaleTimefactor)*
1825  }
1826  heat += 0.5*numDegFreedom*BOLTZMANN*temperature*(coefficient*coefficient-1);
1827  return coefficient;
1828 }
#define BOLTZMANN
Definition: common.h:54
BigReal gaussian(void)
Definition: Random.h:116
BigReal sum_of_squared_gaussians(int64_t num_gaussians)
Return the sum of i.i.d. squared Gaussians.
Definition: Random.h:189
BigReal heat
Definition: Controller.h:247
BigReal temperature
Definition: Controller.h:246
int64_t numDegFreedom
Definition: Controller.h:186
Random * random
Definition: Controller.h:347
BigReal stochRescaleTimefactor
Definition: Controller.h:281
SimParameters *const simParams
Definition: Controller.h:348
BigReal stochRescaleTemp

◆ stochRescaleVelocities()

void Controller::stochRescaleVelocities ( int  step)

The Controller routine for stochastic velocity rescaling uses the most recent temperature reduction to calculate the velocity rescaling coefficient that is then broadcast to all patches.

Generate and broadcast the scale factor for stochastic velocity rescaling.

Stochastic velocity rescaling couples the system to a heat bath by globally scaling the velocites by a single factor. This factor is chosen based on the instantaneous and bath temperatures, a user-defined time scale, and a stochastic component linked to the number of degrees of freedom in the system. All of this information is combined here and sent to the Sequencer for the actual rescaling.

Parameters
stepthe current timestep

Definition at line 1790 of file Controller.C.

References broadcast, SimpleBroadcastObject< T >::publish(), simParams, stochRescale_count, ControllerBroadcasts::stochRescaleCoefficient, stochRescaleCoefficient(), SimParameters::stochRescaleFreq, and SimParameters::stochRescaleOn.

Referenced by integrate().

1791 {
1792  if ( simParams->stochRescaleOn ) {
1795  double coefficient = stochRescaleCoefficient();
1796  broadcast->stochRescaleCoefficient.publish(step,coefficient);
1797  stochRescale_count = 0;
1798  }
1799  }
1800 }
double stochRescaleCoefficient()
Definition: Controller.C:1806
int stochRescale_count
Definition: Controller.h:278
SimpleBroadcastObject< BigReal > stochRescaleCoefficient
Definition: Broadcasts.h:79
ControllerBroadcasts * broadcast
Definition: Controller.h:365
void publish(int tag, const T &t)
SimParameters *const simParams
Definition: Controller.h:348

◆ suspend()

void Controller::suspend ( void  )
protected

Definition at line 358 of file Controller.C.

358  {
359  CthSuspend();
360 }

◆ tcoupleVelocities()

void Controller::tcoupleVelocities ( int  step)
protected

Definition at line 1768 of file Controller.C.

References broadcast, SimpleBroadcastObject< T >::publish(), simParams, ControllerBroadcasts::tcoupleCoefficient, SimParameters::tCoupleOn, SimParameters::tCoupleTemp, and temperature.

Referenced by integrate().

1769 {
1770  if ( simParams->tCoupleOn )
1771  {
1772  const BigReal tCoupleTemp = simParams->tCoupleTemp;
1773  BigReal coefficient = 1.;
1774  if ( temperature > 0. ) coefficient = tCoupleTemp/temperature - 1.;
1775  broadcast->tcoupleCoefficient.publish(step,coefficient);
1776  }
1777 }
SimpleBroadcastObject< BigReal > tcoupleCoefficient
Definition: Broadcasts.h:78
BigReal temperature
Definition: Controller.h:246
ControllerBroadcasts * broadcast
Definition: Controller.h:365
void publish(int tag, const T &t)
BigReal tCoupleTemp
SimParameters *const simParams
Definition: Controller.h:348
double BigReal
Definition: common.h:123

◆ terminate()

void Controller::terminate ( void  )
protected

Definition at line 5252 of file Controller.C.

References BackEnd::awaken(), and Controller::CthThreadWrapper::thread.

Referenced by algorithm().

5252  {
5253  BackEnd::awaken();
5254  CthFree(threadWrapper->thread);
5255  delete threadWrapper;
5256  CthSuspend();
5257 }
static void awaken(void)
Definition: BackEnd.C:316

◆ traceBarrier()

void Controller::traceBarrier ( int  turnOnTrace,
int  step 
)
protected

Definition at line 5224 of file Controller.C.

References namdWallTimer().

Referenced by integrate().

5224  {
5225  CkPrintf("Cycle time at trace sync (begin) Wall at step %d: %f CPU %f\n", step, namdWallTimer()-firstWTime,CmiTimer()-firstCTime);
5226  CProxy_Node nd(CkpvAccess(BOCclass_group).node);
5227  nd.traceBarrier(turnOnTrace, step);
5228  CthSuspend();
5229 }
static double namdWallTimer()
Definition: Controller.C:57

◆ write_accelMDG_rest_file()

void Controller::write_accelMDG_rest_file ( int  step_n,
char  type,
int  V_n,
BigReal  Vmax,
BigReal  Vmin,
BigReal  Vavg,
BigReal  sigmaV,
BigReal  M2,
BigReal  E,
BigReal  k,
bool  write_topic,
bool  lasttime 
)
protected

Definition at line 2355 of file Controller.C.

References endi(), iout, iWARN(), NAMD_backup_file(), and simParams.

Referenced by rescaleaccelMD().

2355  {
2356  FILE *rest;
2357  char timestepstr[20];
2358  char *filename;
2359  int baselen;
2360  char *restart_name;
2361  const char *bsuffix;
2362 
2363  if(lasttime || simParams->restartFrequency == 0){
2364  filename = simParams->outputFilename;
2365  bsuffix = ".BAK";
2366  }
2367  else{
2368  filename = simParams->restartFilename;
2369  bsuffix = ".old";
2370  }
2371 
2372  baselen = strlen(filename);
2373  restart_name = new char[baselen+26];
2374 
2375  strcpy(restart_name, filename);
2376  if ( simParams->restartSave && !lasttime) {
2377  sprintf(timestepstr,".%d",step_n);
2378  strcat(restart_name, timestepstr);
2379  bsuffix = ".BAK";
2380  }
2381  strcat(restart_name, ".gamd");
2382 
2383  if(write_topic){
2384  NAMD_backup_file(restart_name,bsuffix);
2385 
2386  rest = fopen(restart_name, "w");
2387  if(rest){
2388  fprintf(rest, "# NAMD accelMDG restart file\n"
2389  "# D/T Vn Vmax Vmin Vavg sigmaV M2 E k\n"
2390  "%c %d %.17lg %.17lg %.17lg %.17lg %.17le %.17lg %.17lg\n",
2391  type, V_n-1, Vmax, Vmin, Vavg, sigmaV, M2, E, k);
2392  fclose(rest);
2393  iout << "GAUSSIAN ACCELERATED MD RESTART DATA WRITTEN TO " << restart_name << "\n" << endi;
2394  }
2395  else
2396  iout << iWARN << "Cannot write accelMDG restart file\n" << endi;
2397  }
2398  else{
2399  rest = fopen(restart_name, "a");
2400  if(rest){
2401  fprintf(rest, "%c %d %.17lg %.17lg %.17lg %.17lg %.17le %.17lg %.17lg\n",
2402  type, V_n-1, Vmax, Vmin, Vavg, sigmaV, M2, E, k);
2403  fclose(rest);
2404  }
2405  else
2406  iout << iWARN << "Cannot write accelMDG restart file\n" << endi;
2407  }
2408 
2409  delete[] restart_name;
2410 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
char outputFilename[NAMD_FILENAME_BUFFER_SIZE]
void NAMD_backup_file(const char *filename, const char *extension)
Definition: common.C:235
char restartFilename[NAMD_FILENAME_BUFFER_SIZE]
SimParameters *const simParams
Definition: Controller.h:348

◆ writeExtendedSystemData()

void Controller::writeExtendedSystemData ( int  step,
ofstream_namd file 
)
protected

Definition at line 4629 of file Controller.C.

References Lattice::a(), Lattice::a_p(), Lattice::b(), Lattice::b_p(), Lattice::c(), Lattice::c_p(), ControllerState::langevinPiston_strainRate, SimParameters::langevinPistonOn, ControllerState::monteCarloMaxVolume, SimParameters::monteCarloPressureOn, Lattice::origin(), simParams, state, SimParameters::useConstantRatio, SimParameters::useFlexibleCell, Vector::x, Vector::y, and Vector::z.

Referenced by outputExtendedSystem().

4629  {
4630  Lattice &lattice = state->lattice;
4631  file.precision(12);
4632  file << step;
4633  if ( lattice.a_p() ) file << " " << lattice.a().x << " " << lattice.a().y << " " << lattice.a().z;
4634  if ( lattice.b_p() ) file << " " << lattice.b().x << " " << lattice.b().y << " " << lattice.b().z;
4635  if ( lattice.c_p() ) file << " " << lattice.c().x << " " << lattice.c().y << " " << lattice.c().z;
4636  file << " " << lattice.origin().x << " " << lattice.origin().y << " " << lattice.origin().z;
4637  if ( simParams->langevinPistonOn ) {
4638  Vector strainRate = diagonal(langevinPiston_strainRate);
4639  Vector strainRate2 = off_diagonal(langevinPiston_strainRate);
4640  file << " " << strainRate.x;
4641  file << " " << strainRate.y;
4642  file << " " << strainRate.z;
4643  file << " " << strainRate2.x;
4644  file << " " << strainRate2.y;
4645  file << " " << strainRate2.z;
4646  }
4648  // We could print the elements as they are, but it would be meaningless,
4649  // because for constant ratio and isotropic fluctuations, we only operate
4650  // on x element.
4651  if (!simParams->useFlexibleCell) {
4652  // isotropic fluctuations: use x element for v_x, v_y, and v_z
4653  file << " " << monteCarloMaxVolume.x;
4654  file << " " << monteCarloMaxVolume.x;
4655  file << " " << monteCarloMaxVolume.x;
4656  } else {
4657  // we have flexible cell
4658  if (simParams->useConstantRatio) {
4659  // use x element for v_x and v_y
4660  file << " " << monteCarloMaxVolume.x;
4661  file << " " << monteCarloMaxVolume.x;
4662  file << " " << monteCarloMaxVolume.z;
4663  } else {
4664  // constant area or just flexible in each axis dimension
4665  file << " " << monteCarloMaxVolume.x;
4666  file << " " << monteCarloMaxVolume.y;
4667  file << " " << monteCarloMaxVolume.z;
4668  }
4669  }
4670  }
4671  file << std::endl;
4672 }
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
Bool monteCarloPressureOn
NAMD_HOST_DEVICE int c_p() const
Definition: Lattice.h:291
Definition: Vector.h:72
BigReal z
Definition: Vector.h:74
NAMD_HOST_DEVICE int b_p() const
Definition: Lattice.h:290
Tensor langevinPiston_strainRate
Definition: Controller.h:96
NamdState *const state
Definition: Controller.h:349
BigReal x
Definition: Vector.h:74
NAMD_HOST_DEVICE int a_p() const
Definition: Lattice.h:289
NAMD_HOST_DEVICE Vector b() const
Definition: Lattice.h:269
BigReal y
Definition: Vector.h:74
Vector monteCarloMaxVolume
Definition: Controller.h:101
SimParameters *const simParams
Definition: Controller.h:348
NAMD_HOST_DEVICE Vector a() const
Definition: Lattice.h:268
NAMD_HOST_DEVICE Vector origin() const
Definition: Lattice.h:278

◆ writeExtendedSystemLabels()

void Controller::writeExtendedSystemLabels ( ofstream_namd file)
protected

Definition at line 4613 of file Controller.C.

References Lattice::a_p(), Lattice::b_p(), Lattice::c_p(), SimParameters::langevinPistonOn, SimParameters::monteCarloPressureOn, simParams, and state.

Referenced by outputExtendedSystem().

4613  {
4614  Lattice &lattice = state->lattice;
4615  file << "#$LABELS step";
4616  if ( lattice.a_p() ) file << " a_x a_y a_z";
4617  if ( lattice.b_p() ) file << " b_x b_y b_z";
4618  if ( lattice.c_p() ) file << " c_x c_y c_z";
4619  file << " o_x o_y o_z";
4620  if ( simParams->langevinPistonOn ) {
4621  file << " s_x s_y s_z s_u s_v s_w";
4622  }
4624  file << " v_x v_y v_z";
4625  }
4626  file << std::endl;
4627 }
Bool monteCarloPressureOn
NAMD_HOST_DEVICE int c_p() const
Definition: Lattice.h:291
NAMD_HOST_DEVICE int b_p() const
Definition: Lattice.h:290
NamdState *const state
Definition: Controller.h:349
NAMD_HOST_DEVICE int a_p() const
Definition: Lattice.h:289
SimParameters *const simParams
Definition: Controller.h:348

◆ writeFepEnergyData()

void Controller::writeFepEnergyData ( int  step,
ofstream_namd file 
)
protected

Definition at line 4982 of file Controller.C.

References SimParameters::alchEnsembleAvg, SimParameters::alchIDWSFreq, SimParameters::alchLambda, SimParameters::alchLambdaIDWS, SimParameters::alchTemp, BOLTZMANN, dE, dG, electEnergy, electEnergy_f, electEnergySlow, electEnergySlow_f, exp_dE_ByRT, fepFile, FepNo, FEPTITLE(), FEPTITLE_BACK(), SimParameters::firstTimestep, FORMAT(), ljEnergy, ljEnergy_f, net_dE, simParams, and temperature.

Referenced by outputFepEnergy().

4982  {
4986 
4987  const bool alchEnsembleAvg = simParams->alchEnsembleAvg;
4988  const int stepInRun = step - simParams->firstTimestep;
4989  const BigReal alchLambda = simParams->alchLambda;
4990 
4991  if(stepInRun){
4992  if ( simParams->alchLambdaIDWS >= 0. &&
4993  (step / simParams->alchIDWSFreq) % 2 == 0 ) {
4994  // IDWS is active and we are on a "backward" timestep
4995  fepFile << FEPTITLE_BACK(step);
4996  } else {
4997  // "forward" timestep
4998  fepFile << FEPTITLE(step);
4999  }
5000  fepFile << FORMAT(eeng);
5001  fepFile << FORMAT(eeng_f);
5002  fepFile << FORMAT(ljEnergy);
5004  fepFile << FORMAT(dE);
5005  if(alchEnsembleAvg){
5006  BigReal dE_avg = net_dE / FepNo;
5007  fepFile << FORMAT(dE_avg);
5008  }
5010  if(alchEnsembleAvg){
5011  dG = -(RT * log(exp_dE_ByRT / FepNo));
5012  fepFile << FORMAT(dG);
5013  }
5014  fepFile << std::endl;
5015  }
5016 }
BigReal net_dE
Definition: Controller.h:205
BigReal dG
Definition: Controller.h:206
#define BOLTZMANN
Definition: common.h:54
BigReal ljEnergy
Definition: Controller.h:191
BigReal electEnergySlow_f
Definition: Controller.h:200
static char * FEPTITLE(int X)
Definition: Controller.C:79
BigReal electEnergySlow
Definition: Controller.h:190
BigReal alchLambda
BigReal electEnergy_f
Definition: Controller.h:199
BigReal temperature
Definition: Controller.h:246
BigReal alchLambdaIDWS
static char * FORMAT(BigReal X, int decimal=4)
Definition: Controller.C:1830
static char * FEPTITLE_BACK(int X)
Definition: Controller.C:86
BigReal dE
Definition: Controller.h:204
BigReal exp_dE_ByRT
Definition: Controller.h:203
BigReal alchTemp
BigReal electEnergy
Definition: Controller.h:189
BigReal ljEnergy_f
Definition: Controller.h:201
SimParameters *const simParams
Definition: Controller.h:348
ofstream_namd fepFile
Definition: Controller.h:372
double BigReal
Definition: common.h:123

◆ writeTiEnergyData()

void Controller::writeTiEnergyData ( int  step,
ofstream_namd file 
)
protected

Definition at line 5018 of file Controller.C.

References SimParameters::alchLambdaFreq, cumAlchWork, FORMAT(), net_dEdl_bond_1, net_dEdl_bond_2, net_dEdl_elec_1, net_dEdl_elec_2, net_dEdl_lj_1, net_dEdl_lj_2, recent_alchWork, recent_dEdl_bond_1, recent_dEdl_bond_2, recent_dEdl_elec_1, recent_dEdl_elec_2, recent_dEdl_lj_1, recent_dEdl_lj_2, recent_TiNo, simParams, tiFile, TiNo, and TITITLE().

Referenced by outputTiEnergy().

5018  {
5019  tiFile << TITITLE(step);
5024  tiFile << " ";
5030  tiFile << " ";
5034  if (simParams->alchLambdaFreq > 0) {
5037  }
5038  tiFile << std::endl;
5039 }
ofstream_namd tiFile
Definition: Controller.h:376
BigReal net_dEdl_lj_2
Definition: Controller.h:224
BigReal net_dEdl_lj_1
Definition: Controller.h:223
BigReal net_dEdl_bond_2
Definition: Controller.h:220
BigReal recent_alchWork
Definition: Controller.h:235
BigReal recent_dEdl_bond_2
Definition: Controller.h:230
BigReal recent_dEdl_elec_2
Definition: Controller.h:232
BigReal recent_dEdl_elec_1
Definition: Controller.h:231
int recent_TiNo
Definition: Controller.h:237
static char * FORMAT(BigReal X, int decimal=4)
Definition: Controller.C:1830
BigReal net_dEdl_elec_1
Definition: Controller.h:221
BigReal recent_dEdl_lj_1
Definition: Controller.h:233
BigReal cumAlchWork
Definition: Controller.h:225
static char * TITITLE(int X)
Definition: Controller.C:100
SimParameters *const simParams
Definition: Controller.h:348
BigReal net_dEdl_elec_2
Definition: Controller.h:222
BigReal recent_dEdl_lj_2
Definition: Controller.h:234
BigReal net_dEdl_bond_1
Definition: Controller.h:219
BigReal recent_dEdl_bond_1
Definition: Controller.h:229

Friends And Related Function Documentation

◆ CheckpointMsg

friend class CheckpointMsg
friend

Definition at line 138 of file Controller.h.

◆ Node

friend class Node
friend

Definition at line 137 of file Controller.h.

◆ ScriptTcl

friend class ScriptTcl
friend

Definition at line 136 of file Controller.h.

Member Data Documentation

◆ accelMDdV

BigReal Controller::accelMDdV

Definition at line 117 of file Controller.h.

Referenced by rescaleaccelMD(), and colvarproxy_namd::update_accelMD_info().

◆ accelMDdVAverage

BigReal Controller::accelMDdVAverage
protected

Definition at line 415 of file Controller.h.

Referenced by rescaleaccelMD().

◆ adaptTempAutoDt

Bool Controller::adaptTempAutoDt
protected

Definition at line 438 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempUpdate().

◆ adaptTempBetaMax

BigReal Controller::adaptTempBetaMax
protected

Definition at line 432 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempBetaMin

BigReal Controller::adaptTempBetaMin
protected

Definition at line 431 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempBetaN

BigReal* Controller::adaptTempBetaN
protected

Definition at line 427 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempUpdate().

◆ adaptTempBin

int Controller::adaptTempBin
protected

Definition at line 433 of file Controller.h.

Referenced by adaptTempUpdate().

◆ adaptTempBins

int Controller::adaptTempBins
protected

Definition at line 434 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempCg

BigReal Controller::adaptTempCg
protected

Definition at line 436 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempDBeta

BigReal Controller::adaptTempDBeta
protected

Definition at line 435 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempUpdate().

◆ adaptTempDt

BigReal Controller::adaptTempDt
protected

Definition at line 437 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempDTave

BigReal Controller::adaptTempDTave
protected

Definition at line 429 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempUpdate().

◆ adaptTempDTavenum

BigReal Controller::adaptTempDTavenum
protected

Definition at line 430 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempUpdate().

◆ adaptTempDtMax

BigReal Controller::adaptTempDtMax
protected

Definition at line 440 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempUpdate().

◆ adaptTempDtMin

BigReal Controller::adaptTempDtMin
protected

Definition at line 439 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempUpdate().

◆ adaptTempPotEnergyAve

BigReal* Controller::adaptTempPotEnergyAve
protected

Definition at line 424 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempPotEnergyAveDen

BigReal* Controller::adaptTempPotEnergyAveDen
protected

Definition at line 422 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempPotEnergyAveNum

BigReal* Controller::adaptTempPotEnergyAveNum
protected

Definition at line 421 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempPotEnergySamples

int* Controller::adaptTempPotEnergySamples
protected

Definition at line 426 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempPotEnergyVar

BigReal* Controller::adaptTempPotEnergyVar
protected

Definition at line 425 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempPotEnergyVarNum

BigReal* Controller::adaptTempPotEnergyVarNum
protected

Definition at line 423 of file Controller.h.

Referenced by adaptTempInit(), adaptTempUpdate(), and adaptTempWriteRestart().

◆ adaptTempRestartFile

ofstream_namd Controller::adaptTempRestartFile
protected

Definition at line 441 of file Controller.h.

Referenced by adaptTempInit(), and adaptTempWriteRestart().

◆ adaptTempT

BigReal Controller::adaptTempT
protected

◆ alchWork

BigReal Controller::alchWork
protected

Definition at line 236 of file Controller.h.

Referenced by outputTiEnergy(), and printEnergies().

◆ amd_reduction

RequireReduction* Controller::amd_reduction
protected

Definition at line 351 of file Controller.h.

Referenced by Controller(), rescaleaccelMD(), and ~Controller().

◆ avg_count

int Controller::avg_count
protected

Definition at line 167 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ bondedEnergy_ti_1

BigReal Controller::bondedEnergy_ti_1
protected

Definition at line 211 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ bondedEnergy_ti_2

BigReal Controller::bondedEnergy_ti_2
protected

Definition at line 212 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ bondedEnergyDiff_f

BigReal Controller::bondedEnergyDiff_f
protected

Definition at line 198 of file Controller.h.

Referenced by outputFepEnergy(), and printEnergies().

◆ broadcast

ControllerBroadcasts* Controller::broadcast
protected

◆ checkpoint_lattice

Lattice Controller::checkpoint_lattice
protected

Definition at line 383 of file Controller.h.

Referenced by algorithm().

◆ checkpoint_state

ControllerState Controller::checkpoint_state
protected

Definition at line 384 of file Controller.h.

Referenced by algorithm().

◆ checkpoint_stored

int Controller::checkpoint_stored
protected

Definition at line 382 of file Controller.h.

Referenced by algorithm(), and Controller().

◆ checkpoint_task

int Controller::checkpoint_task
protected

Definition at line 391 of file Controller.h.

Referenced by recvCheckpointAck().

◆ checkpoints

std::map<std::string,checkpoint*> Controller::checkpoints
protected

Definition at line 390 of file Controller.h.

Referenced by algorithm(), and recvCheckpointReq().

◆ collection

CollectionMaster* const Controller::collection
protected

Definition at line 364 of file Controller.h.

Referenced by enqueueCollections().

◆ computeChecksum

int Controller::computeChecksum
protected

Definition at line 172 of file Controller.h.

Referenced by compareChecksums().

◆ controlNumDegFreedom

int Controller::controlNumDegFreedom
protected

◆ controlPressure

Tensor Controller::controlPressure
protected

◆ controlPressure_nbond

Tensor Controller::controlPressure_nbond
protected

Definition at line 160 of file Controller.h.

Referenced by calcPressure(), langevinPiston1(), langevinPiston2(), and receivePressure().

◆ controlPressure_normal

Tensor Controller::controlPressure_normal
protected

Definition at line 159 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ controlPressure_slow

Tensor Controller::controlPressure_slow
protected

Definition at line 161 of file Controller.h.

Referenced by calcPressure(), langevinPiston1(), langevinPiston2(), and receivePressure().

◆ cumAlchWork

BigReal Controller::cumAlchWork
protected

Definition at line 225 of file Controller.h.

Referenced by Controller(), printEnergies(), and writeTiEnergyData().

◆ dE

BigReal Controller::dE
protected

Definition at line 204 of file Controller.h.

Referenced by outputFepEnergy(), and writeFepEnergyData().

◆ dG

BigReal Controller::dG
protected

Definition at line 206 of file Controller.h.

Referenced by outputFepEnergy(), and writeFepEnergyData().

◆ drudeBondTemp

BigReal Controller::drudeBondTemp
protected

Definition at line 240 of file Controller.h.

Referenced by Controller(), printEnergies(), and receivePressure().

◆ drudeBondTempAvg

BigReal Controller::drudeBondTempAvg
protected

Definition at line 241 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ electEnergy

BigReal Controller::electEnergy
protected

◆ electEnergy_f

BigReal Controller::electEnergy_f
protected

Definition at line 199 of file Controller.h.

Referenced by outputFepEnergy(), printEnergies(), and writeFepEnergyData().

◆ electEnergy_ti_1

BigReal Controller::electEnergy_ti_1
protected

Definition at line 213 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ electEnergy_ti_2

BigReal Controller::electEnergy_ti_2
protected

Definition at line 216 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ electEnergyPME_ti_1

BigReal Controller::electEnergyPME_ti_1
protected

Definition at line 226 of file Controller.h.

Referenced by computeAlchWork(), outputTiEnergy(), and printEnergies().

◆ electEnergyPME_ti_2

BigReal Controller::electEnergyPME_ti_2
protected

Definition at line 227 of file Controller.h.

Referenced by computeAlchWork(), outputTiEnergy(), and printEnergies().

◆ electEnergySlow

BigReal Controller::electEnergySlow
protected

◆ electEnergySlow_f

BigReal Controller::electEnergySlow_f
protected

Definition at line 200 of file Controller.h.

Referenced by outputFepEnergy(), printEnergies(), and writeFepEnergyData().

◆ electEnergySlow_ti_1

BigReal Controller::electEnergySlow_ti_1
protected

Definition at line 214 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ electEnergySlow_ti_2

BigReal Controller::electEnergySlow_ti_2
protected

Definition at line 217 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ exp_dE_ByRT

BigReal Controller::exp_dE_ByRT
protected

Definition at line 203 of file Controller.h.

Referenced by outputFepEnergy(), and writeFepEnergyData().

◆ fepFile

ofstream_namd Controller::fepFile
protected

Definition at line 372 of file Controller.h.

Referenced by outputFepEnergy(), and writeFepEnergyData().

◆ FepNo

int Controller::FepNo
protected

Definition at line 207 of file Controller.h.

Referenced by outputFepEnergy(), and writeFepEnergyData().

◆ fepSum

BigReal Controller::fepSum
protected

Definition at line 209 of file Controller.h.

Referenced by outputFepEnergy().

◆ fflush_count

int Controller::fflush_count
protected

Definition at line 336 of file Controller.h.

Referenced by printEnergies(), printTiming(), and rebalanceLoad().

◆ goNativeEnergy

BigReal Controller::goNativeEnergy
protected

Definition at line 194 of file Controller.h.

Referenced by printEnergies(), and rescaleaccelMD().

◆ goNonnativeEnergy

BigReal Controller::goNonnativeEnergy
protected

Definition at line 195 of file Controller.h.

Referenced by printEnergies(), and rescaleaccelMD().

◆ goTotalEnergy

BigReal Controller::goTotalEnergy
protected

Definition at line 196 of file Controller.h.

Referenced by printEnergies(), and rescaleaccelMD().

◆ groGaussEnergy

BigReal Controller::groGaussEnergy
protected

Definition at line 193 of file Controller.h.

Referenced by printEnergies(), and rescaleaccelMD().

◆ groLJEnergy

BigReal Controller::groLJEnergy
protected

Definition at line 192 of file Controller.h.

Referenced by printEnergies(), and rescaleaccelMD().

◆ groupPressure

Tensor Controller::groupPressure
protected

Definition at line 253 of file Controller.h.

Referenced by calcPressure(), printEnergies(), and receivePressure().

◆ groupPressure_avg

BigReal Controller::groupPressure_avg
protected

Definition at line 166 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ groupPressure_nbond

Tensor Controller::groupPressure_nbond
protected

Definition at line 157 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ groupPressure_normal

Tensor Controller::groupPressure_normal
protected

Definition at line 156 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ groupPressure_slow

Tensor Controller::groupPressure_slow
protected

Definition at line 158 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ groupPressure_tavg

Tensor Controller::groupPressure_tavg
protected

Definition at line 169 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ groupPressureAverage

MovingAverage Controller::groupPressureAverage
protected

Definition at line 450 of file Controller.h.

Referenced by printEnergies(), and resetMovingAverage().

◆ groupPressureAverage_xx

MovingAverage Controller::groupPressureAverage_xx
protected

Definition at line 459 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_xy

MovingAverage Controller::groupPressureAverage_xy
protected

Definition at line 460 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_xz

MovingAverage Controller::groupPressureAverage_xz
protected

Definition at line 461 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_yx

MovingAverage Controller::groupPressureAverage_yx
protected

Definition at line 462 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_yy

MovingAverage Controller::groupPressureAverage_yy
protected

Definition at line 463 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_yz

MovingAverage Controller::groupPressureAverage_yz
protected

Definition at line 464 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_zx

MovingAverage Controller::groupPressureAverage_zx
protected

Definition at line 465 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_zy

MovingAverage Controller::groupPressureAverage_zy
protected

Definition at line 466 of file Controller.h.

Referenced by printEnergies().

◆ groupPressureAverage_zz

MovingAverage Controller::groupPressureAverage_zz
protected

Definition at line 467 of file Controller.h.

Referenced by printEnergies().

◆ heat

BigReal Controller::heat
protected

heat exchanged with the thermostat since firstTimestep

Definition at line 247 of file Controller.h.

Referenced by Controller(), printEnergies(), and stochRescaleCoefficient().

◆ kineticEnergy

BigReal Controller::kineticEnergy
protected

◆ kineticEnergyCentered

BigReal Controller::kineticEnergyCentered
protected

Definition at line 245 of file Controller.h.

Referenced by printEnergies(), and receivePressure().

◆ kineticEnergyHalfstep

BigReal Controller::kineticEnergyHalfstep
protected

Definition at line 244 of file Controller.h.

Referenced by printEnergies(), and receivePressure().

◆ langevinPiston_origStrainRate

Tensor Controller::langevinPiston_origStrainRate
protected

Definition at line 291 of file Controller.h.

Referenced by Controller().

◆ ldbSteps

int Controller::ldbSteps
protected

Definition at line 334 of file Controller.h.

Referenced by rebalanceLoad().

◆ ljEnergy

BigReal Controller::ljEnergy
protected

◆ ljEnergy_f

BigReal Controller::ljEnergy_f
protected

Definition at line 201 of file Controller.h.

Referenced by outputFepEnergy(), printEnergies(), and writeFepEnergyData().

◆ ljEnergy_f_left

BigReal Controller::ljEnergy_f_left
protected

Definition at line 202 of file Controller.h.

◆ ljEnergy_ti_1

BigReal Controller::ljEnergy_ti_1
protected

Definition at line 215 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ ljEnergy_ti_2

BigReal Controller::ljEnergy_ti_2
protected

Definition at line 218 of file Controller.h.

Referenced by computeAlchWork(), Controller(), outputTiEnergy(), and printEnergies().

◆ marginViolations

int Controller::marginViolations
protected

Definition at line 173 of file Controller.h.

Referenced by compareChecksums(), and printEnergies().

◆ mc_accept

int Controller::mc_accept[MC_AXIS_TOTAL]
protected

Definition at line 316 of file Controller.h.

Referenced by Controller(), and monteCarloPressure_accept().

◆ mc_oldLattice

Lattice Controller::mc_oldLattice
protected

Definition at line 320 of file Controller.h.

Referenced by monteCarloPressure_accept(), and monteCarloPressure_prepare().

◆ mc_picked_axis

int Controller::mc_picked_axis
protected

Definition at line 318 of file Controller.h.

Referenced by monteCarloPressure_accept(), and monteCarloPressure_prepare().

◆ mc_totalAccept

int Controller::mc_totalAccept
protected

Definition at line 317 of file Controller.h.

Referenced by Controller(), and monteCarloPressure_accept().

◆ mc_totalEnergyOld

BigReal Controller::mc_totalEnergyOld
protected

Definition at line 319 of file Controller.h.

Referenced by monteCarloPressure_accept(), and monteCarloPressure_prepare().

◆ mc_totalTry

int Controller::mc_totalTry
protected

Definition at line 317 of file Controller.h.

Referenced by Controller(), monteCarloPressure_accept(), and monteCarloPressure_prepare().

◆ mc_trial

int Controller::mc_trial[MC_AXIS_TOTAL]
protected

Definition at line 316 of file Controller.h.

Referenced by Controller(), monteCarloPressure_accept(), and monteCarloPressure_prepare().

◆ min_energy

BigReal Controller::min_energy
protected

Definition at line 179 of file Controller.h.

Referenced by minimize(), and printMinimizeEnergies().

◆ min_f_dot_f

BigReal Controller::min_f_dot_f
protected

Definition at line 180 of file Controller.h.

Referenced by minimize(), and printMinimizeEnergies().

◆ min_f_dot_v

BigReal Controller::min_f_dot_v
protected

Definition at line 181 of file Controller.h.

Referenced by minimize(), and printMinimizeEnergies().

◆ min_huge_count

int Controller::min_huge_count
protected

Definition at line 183 of file Controller.h.

Referenced by minimize(), and printMinimizeEnergies().

◆ min_reduction

RequireReduction* Controller::min_reduction
protected

Definition at line 143 of file Controller.h.

Referenced by Controller(), minimize(), and ~Controller().

◆ min_v_dot_v

BigReal Controller::min_v_dot_v
protected

Definition at line 182 of file Controller.h.

Referenced by minimize(), and printMinimizeEnergies().

◆ momentumSqrSum

Tensor Controller::momentumSqrSum
protected

Definition at line 325 of file Controller.h.

Referenced by multigratorPressure(), multigratorTemperature(), and receivePressure().

◆ multigratorNu

std::vector<BigReal> Controller::multigratorNu
protected

Definition at line 327 of file Controller.h.

Referenced by Controller(), multigatorCalcEnthalpy(), and multigratorTemperature().

◆ multigratorNuT

std::vector<BigReal> Controller::multigratorNuT
protected

Definition at line 328 of file Controller.h.

Referenced by Controller(), and multigratorTemperature().

◆ multigratorOmega

std::vector<BigReal> Controller::multigratorOmega
protected

Definition at line 329 of file Controller.h.

Referenced by Controller(), multigatorCalcEnthalpy(), and multigratorTemperature().

◆ multigratorReduction

RequireReduction* Controller::multigratorReduction
protected

Definition at line 331 of file Controller.h.

Referenced by Controller(), multigratorTemperature(), and ~Controller().

◆ multigratorXi

BigReal Controller::multigratorXi
protected

Definition at line 323 of file Controller.h.

Referenced by Controller(), multigatorCalcEnthalpy(), and multigratorPressure().

◆ multigratorXiT

BigReal Controller::multigratorXiT
protected

Definition at line 324 of file Controller.h.

Referenced by multigratorPressure().

◆ multigratorZeta

std::vector<BigReal> Controller::multigratorZeta
protected

Definition at line 330 of file Controller.h.

Referenced by Controller(), multigatorCalcEnthalpy(), and multigratorTemperature().

◆ nbondFreq

int Controller::nbondFreq
protected

◆ net_dE

BigReal Controller::net_dE
protected

Definition at line 205 of file Controller.h.

Referenced by outputFepEnergy(), and writeFepEnergyData().

◆ net_dEdl_bond_1

BigReal Controller::net_dEdl_bond_1
protected

Definition at line 219 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ net_dEdl_bond_2

BigReal Controller::net_dEdl_bond_2
protected

Definition at line 220 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ net_dEdl_elec_1

BigReal Controller::net_dEdl_elec_1
protected

Definition at line 221 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ net_dEdl_elec_2

BigReal Controller::net_dEdl_elec_2
protected

Definition at line 222 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ net_dEdl_lj_1

BigReal Controller::net_dEdl_lj_1
protected

Definition at line 223 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ net_dEdl_lj_2

BigReal Controller::net_dEdl_lj_2
protected

Definition at line 224 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ nodeReduction

NodeReduction* Controller::nodeReduction
protected

◆ numDegFreedom

int64_t Controller::numDegFreedom
protected

◆ origLattice

Lattice Controller::origLattice
protected

Definition at line 395 of file Controller.h.

Referenced by Controller().

◆ pairlistWarnings

int Controller::pairlistWarnings
protected

Definition at line 174 of file Controller.h.

Referenced by compareChecksums(), and printEnergies().

◆ perfstats

RunningAverage Controller::perfstats
protected

Definition at line 444 of file Controller.h.

Referenced by printTiming().

◆ positionRescaleFactor

Tensor Controller::positionRescaleFactor
protected

Definition at line 293 of file Controller.h.

Referenced by langevinPiston1().

◆ ppbonded

PressureProfileReduction* Controller::ppbonded
protected

Definition at line 358 of file Controller.h.

Referenced by Controller(), printEnergies(), and ~Controller().

◆ ppint

PressureProfileReduction* Controller::ppint
protected

Definition at line 360 of file Controller.h.

Referenced by Controller(), printEnergies(), and ~Controller().

◆ ppnonbonded

PressureProfileReduction* Controller::ppnonbonded
protected

Definition at line 359 of file Controller.h.

Referenced by Controller(), printEnergies(), and ~Controller().

◆ pressure

Tensor Controller::pressure
protected

Definition at line 252 of file Controller.h.

Referenced by calcPressure(), printEnergies(), and receivePressure().

◆ pressure_amd

Tensor Controller::pressure_amd
protected

Definition at line 154 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ pressure_avg

BigReal Controller::pressure_avg
protected

Definition at line 165 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ pressure_nbond

Tensor Controller::pressure_nbond
protected

Definition at line 152 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ pressure_normal

Tensor Controller::pressure_normal
protected

Definition at line 151 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ pressure_slow

Tensor Controller::pressure_slow
protected

Definition at line 153 of file Controller.h.

Referenced by calcPressure(), and receivePressure().

◆ pressure_tavg

Tensor Controller::pressure_tavg
protected

Definition at line 168 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ pressureAverage

MovingAverage Controller::pressureAverage
protected

Definition at line 449 of file Controller.h.

Referenced by printEnergies(), and resetMovingAverage().

◆ pressureAverage_xx

MovingAverage Controller::pressureAverage_xx
protected

Definition at line 453 of file Controller.h.

Referenced by printEnergies().

◆ pressureAverage_yx

MovingAverage Controller::pressureAverage_yx
protected

Definition at line 454 of file Controller.h.

Referenced by printEnergies().

◆ pressureAverage_yy

MovingAverage Controller::pressureAverage_yy
protected

Definition at line 455 of file Controller.h.

Referenced by printEnergies().

◆ pressureAverage_zx

MovingAverage Controller::pressureAverage_zx
protected

Definition at line 456 of file Controller.h.

Referenced by printEnergies().

◆ pressureAverage_zy

MovingAverage Controller::pressureAverage_zy
protected

Definition at line 457 of file Controller.h.

Referenced by printEnergies().

◆ pressureAverage_zz

MovingAverage Controller::pressureAverage_zz
protected

Definition at line 458 of file Controller.h.

Referenced by printEnergies().

◆ pressureProfileAverage

BigReal* Controller::pressureProfileAverage
protected

Definition at line 363 of file Controller.h.

Referenced by Controller(), printEnergies(), and ~Controller().

◆ pressureProfileCount

int Controller::pressureProfileCount
protected

Definition at line 362 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ pressureProfileSlabs

int Controller::pressureProfileSlabs
protected

Definition at line 361 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ random

Random* Controller::random
protected

◆ recent_alchWork

BigReal Controller::recent_alchWork
protected

Definition at line 235 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ recent_dEdl_bond_1

BigReal Controller::recent_dEdl_bond_1
protected

Definition at line 229 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ recent_dEdl_bond_2

BigReal Controller::recent_dEdl_bond_2
protected

Definition at line 230 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ recent_dEdl_elec_1

BigReal Controller::recent_dEdl_elec_1
protected

Definition at line 231 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ recent_dEdl_elec_2

BigReal Controller::recent_dEdl_elec_2
protected

Definition at line 232 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ recent_dEdl_lj_1

BigReal Controller::recent_dEdl_lj_1
protected

Definition at line 233 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ recent_dEdl_lj_2

BigReal Controller::recent_dEdl_lj_2
protected

Definition at line 234 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ recent_TiNo

int Controller::recent_TiNo
protected

Definition at line 237 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ reduction

RequireReduction* Controller::reduction
protected

◆ rescaleVelocities_numTemps

int Controller::rescaleVelocities_numTemps
protected

Definition at line 260 of file Controller.h.

Referenced by Controller(), and rescaleVelocities().

◆ rescaleVelocities_sumTemps

BigReal Controller::rescaleVelocities_sumTemps
protected

Definition at line 259 of file Controller.h.

Referenced by Controller(), and rescaleVelocities().

◆ simParams

SimParameters* const Controller::simParams
protected

◆ slowFreq

int Controller::slowFreq
protected

◆ smooth2_avg2

BigReal Controller::smooth2_avg2
protected

Definition at line 251 of file Controller.h.

◆ state

NamdState* const Controller::state
protected

◆ stepInFullRun

int Controller::stepInFullRun
protected

Definition at line 187 of file Controller.h.

Referenced by printEnergies().

◆ stochRescale_count

int Controller::stochRescale_count

Count time steps until next stochastic velocity rescaling.

Definition at line 278 of file Controller.h.

Referenced by Controller(), and stochRescaleVelocities().

◆ stochRescaleTimefactor

BigReal Controller::stochRescaleTimefactor

The timefactor for stochastic velocity rescaling depends on fixed configuration parameters, so can be precomputed.

Definition at line 281 of file Controller.h.

Referenced by Controller(), and stochRescaleCoefficient().

◆ strainRate_old

Tensor Controller::strainRate_old
protected

Definition at line 292 of file Controller.h.

Referenced by langevinPiston1().

◆ submit_reduction

SubmitReduction* Controller::submit_reduction
protected

Definition at line 352 of file Controller.h.

Referenced by Controller(), rescaleaccelMD(), and ~Controller().

◆ tavg_count

int Controller::tavg_count
protected

Definition at line 170 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ temp_avg

BigReal Controller::temp_avg
protected

Definition at line 164 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ temperature

BigReal Controller::temperature
protected

◆ temperatureAverage

MovingAverage Controller::temperatureAverage
protected

Definition at line 448 of file Controller.h.

Referenced by printEnergies(), and resetMovingAverage().

◆ tiFile

ofstream_namd Controller::tiFile
protected

Definition at line 376 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ TiNo

int Controller::TiNo
protected

Definition at line 228 of file Controller.h.

Referenced by outputTiEnergy(), and writeTiEnergyData().

◆ totalEnergy

BigReal Controller::totalEnergy
protected

Definition at line 188 of file Controller.h.

Referenced by adaptTempUpdate(), printEnergies(), and printMinimizeEnergies().

◆ totalEnergy0

BigReal Controller::totalEnergy0
protected

totalEnergy at firstTimestep

Definition at line 249 of file Controller.h.

Referenced by Controller(), and printEnergies().

◆ totalEnergyAverage

MovingAverage Controller::totalEnergyAverage
protected

Definition at line 447 of file Controller.h.

Referenced by printEnergies(), and resetMovingAverage().

◆ virial_amd

Tensor Controller::virial_amd
protected

Definition at line 155 of file Controller.h.

Referenced by calcPressure(), and rescaleaccelMD().

◆ xstFile

ofstream_namd Controller::xstFile
protected

Definition at line 366 of file Controller.h.

Referenced by outputExtendedSystem().


The documentation for this class was generated from the following files: