QMCPACK
LocalEnergyEstimator.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2022 QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 // Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #ifndef QMCPLUSPLUS_LOCALENERGYESTIMATOR_H
17 #define QMCPLUSPLUS_LOCALENERGYESTIMATOR_H
22 #include "ScalarEstimatorInputs.h"
23 
24 namespace qmcplusplus
25 {
26 /** Class to accumulate the local energy and components
27  *
28  * Use Walker::Properties to accumulate Hamiltonian-related quantities.
29  */
31 {
33  enum
34  {
39  };
40 
43  bool UseHDF5;
46 
47 public:
48  /** constructor
49  * @param[in] h QMCHamiltonian to define the components
50  * @param[in] use_hdf5 record local energy values in hdf5?
51  */
52  LocalEnergyEstimator(const QMCHamiltonian& h, bool use_hdf5);
53  /** Construct from LocalEnergyInput and const reference to hamiltonian.
54  * @param[in] input contains input parameters for LocalEnergyEstimator
55  * @param[in] ham is taken as a local reference and used to size scalars data
56  */
58  /** accumulation per walker
59  * @param awalker current walker
60  * @param wgt weight
61  *
62  * Weight of observables should take into account the walkers weight. For Pure DMC. In branching DMC set weights to 1.
63  */
64  inline void accumulate(const Walker_t& awalker, RealType wgt)
65  {
66  const RealType* restrict ePtr = awalker.getPropertyBase();
67  RealType wwght = wgt * awalker.Weight;
68  scalars[0](ePtr[WP::LOCALENERGY], wwght);
69  scalars[1](ePtr[WP::LOCALENERGY] * ePtr[WP::LOCALENERGY], wwght);
70  scalars[2](ePtr[WP::LOCALPOTENTIAL], wwght);
71  for (int target = 3, source = FirstHamiltonian; target < scalars.size(); ++target, ++source)
72  scalars[target](ePtr[source], wwght);
73  }
74 
75  /** legacy accumulation function
76  */
77  inline void accumulate(const MCWalkerConfiguration& W,
78  WalkerIterator first,
79  WalkerIterator last,
80  RealType wgt) override
81  {
82  for (; first != last; ++first)
83  accumulate(**first, wgt);
84  }
85 
86  std::string getName() const override { return "LocalEnergyEstimator"; }
87 
88  void add2Record(RecordListType& record) override;
89  void registerObservables(std::vector<ObservableHelper>& h5dec, hdf_archive& file) override;
90  LocalEnergyEstimator* clone() override;
91 
92  /** Accumulate the hamiltonian operator values for system
93  * This is the batched version
94  */
95  inline void accumulate(const RefVector<MCPWalker>& walkers) override
96  {
97  for (MCPWalker& walker : walkers)
98  accumulate(walker, 1.0);
99  }
100 
101  /// LocalEnergyEstimator is the main estimator for VMC and DMC
102  bool isMainEstimator() const override { return true; }
103  const std::string& getSubTypeStr() const override { return input_.get_type(); }
104 };
105 } // namespace qmcplusplus
106 #endif
This file contains the input classes for the supported "main estimator" classes derived from ScalarEs...
A set of walkers that are to be advanced by Metropolis Monte Carlo.
void registerObservables(std::vector< ObservableHelper > &h5dec, hdf_archive &file) override
add descriptors of observables to utilize hdf5
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::string getName() const override
Collection of Local Energy Operators.
class to handle hdf file
Definition: hdf_archive.h:51
Class to accumulate the local energy and components.
const std::string & get_type() const
const char walkers[]
Definition: HDFVersion.h:36
QMCTraits::FullPrecRealType RealType
std::vector< accumulator_type > scalars
scalars to be measured
void accumulate(const MCWalkerConfiguration &W, WalkerIterator first, WalkerIterator last, RealType wgt) override
legacy accumulation function
Declaration of ObservableHelper and other helper class for observables.
bool isMainEstimator() const override
LocalEnergyEstimator is the main estimator for VMC and DMC.
void accumulate(const Walker_t &awalker, RealType wgt)
accumulation per walker
LocalEnergyEstimator * clone() override
clone the object
RecordNamedProperty< RealType > RecordListType
const std::string & getSubTypeStr() const override
String representation of the derived type of the ScalarEstimator.
std::vector< std::reference_wrapper< T > > RefVector
void add2Record(RecordListType &record) override
add the local energy, variance and all the Hamiltonian components to the scalar record container ...
Indexes
an enum denoting index of physical properties
FullPrecRealType Weight
Weight of the walker.
Definition: Walker.h:102
MCWalkerConfiguration::const_iterator WalkerIterator
void accumulate(const RefVector< MCPWalker > &walkers) override
Accumulate the hamiltonian operator values for system This is the batched version.
Abstract class for an estimator of a scalar operator.
FullPrecRealType * getPropertyBase()
Definition: Walker.h:277
A container class to represent a walker.
Definition: Walker.h:49
LocalEnergyEstimator(const QMCHamiltonian &h, bool use_hdf5)
constructor
Declaration of QMCHamiltonian.