QMCPACK
LocalEnergyEstimator Class Reference

Class to accumulate the local energy and components. More...

+ Inheritance diagram for LocalEnergyEstimator:
+ Collaboration diagram for LocalEnergyEstimator:

Public Member Functions

 LocalEnergyEstimator (const QMCHamiltonian &h, bool use_hdf5)
 constructor More...
 
 LocalEnergyEstimator (LocalEnergyInput &&input, const QMCHamiltonian &ham)
 Construct from LocalEnergyInput and const reference to hamiltonian. More...
 
void accumulate (const Walker_t &awalker, RealType wgt)
 accumulation per walker More...
 
void accumulate (const MCWalkerConfiguration &W, WalkerIterator first, WalkerIterator last, RealType wgt) override
 legacy accumulation function More...
 
std::string getName () const override
 
void add2Record (RecordListType &record) override
 add the local energy, variance and all the Hamiltonian components to the scalar record container More...
 
void registerObservables (std::vector< ObservableHelper > &h5dec, hdf_archive &file) override
 add descriptors of observables to utilize hdf5 More...
 
LocalEnergyEstimatorclone () override
 clone the object More...
 
void accumulate (const RefVector< MCPWalker > &walkers) override
 Accumulate the hamiltonian operator values for system This is the batched version. More...
 
bool isMainEstimator () const override
 LocalEnergyEstimator is the main estimator for VMC and DMC. More...
 
const std::string & getSubTypeStr () const override
 String representation of the derived type of the ScalarEstimator. More...
 
- Public Member Functions inherited from ScalarEstimatorBase
 ScalarEstimatorBase ()
 
virtual ~ScalarEstimatorBase ()
 
RealType average (int i=0) const
 return average of the More...
 
RealType variance (int i=0) const
 return a variance More...
 
std::pair< RealType, RealTypeoperator[] (int i) const
 retrun mean and variance More...
 
virtual int size () const
 return the size of scalars it manages More...
 
void clear ()
 clear the scalars to collect More...
 
template<typename IT >
void takeBlockAverage (IT first)
 take block average and write to a common container More...
 
template<typename IT >
void takeBlockAverage (IT first, IT first_sq)
 take block average and write to common containers for values and squared values More...
 
template<typename IT >
void addAccumulated (IT first)
 add the block accumulated scalars More...
 
virtual void add2Record (RecordNamedProperty< RealType > &record)=0
 add the content of the scalar estimator to the record More...
 

Private Types

enum  { ENERGY_INDEX, ENERGY2_INDEX, POTENTIAL_INDEX, LE_MAX }
 
using WP = WalkerProperties::Indexes
 

Private Attributes

int FirstHamiltonian
 
int SizeOfHamiltonians
 
bool UseHDF5
 
const QMCHamiltonianrefH
 
const LocalEnergyInput input_
 

Additional Inherited Members

- Public Types inherited from ScalarEstimatorBase
using RealType = QMCTraits::FullPrecRealType
 
using accumulator_type = accumulator_set< RealType >
 
using Walker_t = MCWalkerConfiguration::Walker_t
 
using MCPWalker = Walker< QMCTraits, PtclOnLatticeTraits >
 
using WalkerIterator = MCWalkerConfiguration::const_iterator
 
using RecordListType = RecordNamedProperty< RealType >
 
- Public Attributes inherited from ScalarEstimatorBase
int FirstIndex
 first index within an record of the first element handled by an object More...
 
int LastIndex
 last index within an record of the first element handled by an object More...
 
std::vector< accumulator_typescalars
 scalars to be measured More...
 
std::vector< accumulator_typescalars_saved
 scalars saved More...
 

Detailed Description

Class to accumulate the local energy and components.

Use Walker::Properties to accumulate Hamiltonian-related quantities.

Definition at line 30 of file LocalEnergyEstimator.h.

Member Typedef Documentation

◆ WP

using WP = WalkerProperties::Indexes
private

Definition at line 32 of file LocalEnergyEstimator.h.

Member Enumeration Documentation

◆ anonymous enum

Constructor & Destructor Documentation

◆ LocalEnergyEstimator() [1/2]

LocalEnergyEstimator ( const QMCHamiltonian h,
bool  use_hdf5 
)

◆ LocalEnergyEstimator() [2/2]

LocalEnergyEstimator ( LocalEnergyInput &&  input,
const QMCHamiltonian ham 
)

Construct from LocalEnergyInput and const reference to hamiltonian.

Parameters
[in]inputcontains input parameters for LocalEnergyEstimator
[in]hamis taken as a local reference and used to size scalars data

Definition at line 28 of file LocalEnergyEstimator.cpp.

References LocalEnergyEstimator::FirstHamiltonian, LocalEnergyEstimator::LE_MAX, ScalarEstimatorBase::scalars, ScalarEstimatorBase::scalars_saved, LocalEnergyEstimator::SizeOfHamiltonians, QMCHamiltonian::sizeOfObservables(), and QMCHamiltonian::startIndex().

29  : UseHDF5(input.get_use_hdf5()), refH(h), input_(input)
30 {
31  SizeOfHamiltonians = h.sizeOfObservables();
32  FirstHamiltonian = h.startIndex();
35 }
std::vector< accumulator_type > scalars
scalars to be measured
std::vector< accumulator_type > scalars_saved
scalars saved
testing::ValidSpinDensityInput input

Member Function Documentation

◆ accumulate() [1/3]

void accumulate ( const Walker_t awalker,
RealType  wgt 
)
inline

accumulation per walker

Parameters
awalkercurrent walker
wgtweight

Weight of observables should take into account the walkers weight. For Pure DMC. In branching DMC set weights to 1.

Definition at line 64 of file LocalEnergyEstimator.h.

References LocalEnergyEstimator::FirstHamiltonian, Walker< t_traits, p_traits >::getPropertyBase(), ScalarEstimatorBase::scalars, and Walker< t_traits, p_traits >::Weight.

Referenced by LocalEnergyEstimator::accumulate(), and qmcplusplus::TEST_CASE().

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  }
std::vector< accumulator_type > scalars
scalars to be measured
QMCTraits::RealType RealType

◆ accumulate() [2/3]

void accumulate ( const MCWalkerConfiguration W,
WalkerIterator  first,
WalkerIterator  last,
RealType  wgt 
)
inlineoverridevirtual

legacy accumulation function

Implements ScalarEstimatorBase.

Definition at line 77 of file LocalEnergyEstimator.h.

References LocalEnergyEstimator::accumulate().

81  {
82  for (; first != last; ++first)
83  accumulate(**first, wgt);
84  }
void accumulate(const Walker_t &awalker, RealType wgt)
accumulation per walker

◆ accumulate() [3/3]

void accumulate ( const RefVector< MCPWalker > &  walkers)
inlineoverridevirtual

Accumulate the hamiltonian operator values for system This is the batched version.

Implements ScalarEstimatorBase.

Definition at line 95 of file LocalEnergyEstimator.h.

References LocalEnergyEstimator::accumulate(), qmcplusplus::walker, and qmcplusplus::hdf::walkers.

96  {
97  for (MCPWalker& walker : walkers)
98  accumulate(walker, 1.0);
99  }
const char walkers[]
Definition: HDFVersion.h:36
void accumulate(const Walker_t &awalker, RealType wgt)
accumulation per walker
Walker< QMCTraits, PtclOnLatticeTraits > MCPWalker

◆ add2Record()

void add2Record ( RecordListType record)
override

add the local energy, variance and all the Hamiltonian components to the scalar record container

Parameters
recordstorage of scalar records (name,value)

Definition at line 63 of file LocalEnergyEstimator.cpp.

References RecordNamedProperty< T >::add(), ScalarEstimatorBase::clear(), ScalarEstimatorBase::FirstIndex, QMCHamiltonian::getObservableName(), ScalarEstimatorBase::LastIndex, LocalEnergyEstimator::refH, RecordNamedProperty< T >::size(), and LocalEnergyEstimator::SizeOfHamiltonians.

Referenced by qmcplusplus::TEST_CASE().

64 {
65  FirstIndex = record.size();
66  record.add("LocalEnergy");
67  record.add("LocalEnergy_sq");
68  record.add("LocalPotential");
69  for (int i = 0; i < SizeOfHamiltonians; ++i)
70  record.add(refH.getObservableName(i));
71  LastIndex = record.size();
72  clear();
73 }
std::string getObservableName(int i) const
return the name of the i-th observable
int FirstIndex
first index within an record of the first element handled by an object
void clear()
clear the scalars to collect
int LastIndex
last index within an record of the first element handled by an object

◆ clone()

LocalEnergyEstimator * clone ( )
overridevirtual

clone the object

Implements ScalarEstimatorBase.

Definition at line 37 of file LocalEnergyEstimator.cpp.

References LocalEnergyEstimator::LocalEnergyEstimator().

Referenced by qmcplusplus::TEST_CASE().

37 { return new LocalEnergyEstimator(*this); }
LocalEnergyEstimator(const QMCHamiltonian &h, bool use_hdf5)
constructor

◆ getName()

std::string getName ( ) const
inlineoverridevirtual

Implements ScalarEstimatorBase.

Definition at line 86 of file LocalEnergyEstimator.h.

Referenced by qmcplusplus::TEST_CASE().

86 { return "LocalEnergyEstimator"; }

◆ getSubTypeStr()

const std::string& getSubTypeStr ( ) const
inlineoverridevirtual

String representation of the derived type of the ScalarEstimator.

Implements ScalarEstimatorBase.

Definition at line 103 of file LocalEnergyEstimator.h.

References LocalEnergyInput::get_type(), and LocalEnergyEstimator::input_.

103 { return input_.get_type(); }
const std::string & get_type() const

◆ isMainEstimator()

bool isMainEstimator ( ) const
inlineoverridevirtual

LocalEnergyEstimator is the main estimator for VMC and DMC.

Reimplemented from ScalarEstimatorBase.

Definition at line 102 of file LocalEnergyEstimator.h.

102 { return true; }

◆ registerObservables()

void registerObservables ( std::vector< ObservableHelper > &  h5dec,
hdf_archive file 
)
overridevirtual

add descriptors of observables to utilize hdf5

Parameters
h5descdescriptor of a data stored in a h5 group
filefile to which each statistical data will be stored

Implements ScalarEstimatorBase.

Definition at line 39 of file LocalEnergyEstimator.cpp.

References ScalarEstimatorBase::FirstIndex, qmcplusplus::lower_bound(), LocalEnergyEstimator::refH, QMCHamiltonian::registerObservables(), qmcplusplus::Units::time::s, and LocalEnergyEstimator::UseHDF5.

Referenced by qmcplusplus::TEST_CASE().

40 {
41  if (!UseHDF5)
42  return;
43  int loc = h5desc.size();
44  //add LocalEnergy and LocalPotential
45  using namespace std::string_literals;
46  h5desc.push_back({{"LocalEnergy"s}});
47  h5desc.push_back({{"LocalEnergy_sq"s}});
48  h5desc.push_back({{"LocalPotential"s}});
49  std::vector<int> onedim(1, 1);
50  h5desc[loc++].set_dimensions(onedim, FirstIndex);
51  h5desc[loc++].set_dimensions(onedim, FirstIndex + 1);
52  h5desc[loc++].set_dimensions(onedim, FirstIndex + 2);
53  //hamiltonian adds more
54  refH.registerObservables(h5desc, file);
55  int correction = FirstIndex + 3;
56  for (int i = loc; i < h5desc.size(); ++i)
57  h5desc[i].lower_bound += correction;
58 }
int FirstIndex
first index within an record of the first element handled by an object
TinyVector< T, 3 > lower_bound(const TinyVector< T, 3 > &a, const TinyVector< T, 3 > &b)
helper function to determine the lower bound of a domain (need to move up)
void registerObservables(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const
register obsevables so that their averages can be dumped to hdf5

Member Data Documentation

◆ FirstHamiltonian

int FirstHamiltonian
private

◆ input_

const LocalEnergyInput input_
private

Definition at line 45 of file LocalEnergyEstimator.h.

Referenced by LocalEnergyEstimator::getSubTypeStr().

◆ refH

◆ SizeOfHamiltonians

int SizeOfHamiltonians
private

◆ UseHDF5

bool UseHDF5
private

Definition at line 43 of file LocalEnergyEstimator.h.

Referenced by LocalEnergyEstimator::registerObservables().


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