QMCPACK
LocalEnergyEstimator.cpp
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) 2016 Jeongnim Kim and 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 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #include "LocalEnergyEstimator.h"
17 
18 namespace qmcplusplus
19 {
20 LocalEnergyEstimator::LocalEnergyEstimator(const QMCHamiltonian& h, bool use_hdf5) : UseHDF5(use_hdf5), refH(h)
21 {
26 }
27 
29  : UseHDF5(input.get_use_hdf5()), refH(h), input_(input)
30 {
35 }
36 
38 
39 void LocalEnergyEstimator::registerObservables(std::vector<ObservableHelper>& h5desc, hdf_archive& file)
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 }
59 
60 /** add the local energy, variance and all the Hamiltonian components to the scalar record container
61  * @param record storage of scalar records (name,value)
62  */
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 }
74 
75 } // namespace qmcplusplus
std::string getObservableName(int i) const
return the name of the i-th observable
void registerObservables(std::vector< ObservableHelper > &h5dec, hdf_archive &file) override
add descriptors of observables to utilize hdf5
int startIndex() const
retrun the starting index
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Collection of Local Energy Operators.
class to handle hdf file
Definition: hdf_archive.h:51
Class to accumulate the local energy and components.
int FirstIndex
first index within an record of the first element handled by an object
std::vector< accumulator_type > scalars
scalars to be measured
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)
LocalEnergyEstimator * clone() override
clone the object
int add(const std::string &aname)
int sizeOfObservables() const
return the size of observables
std::vector< accumulator_type > scalars_saved
scalars saved
void clear()
clear the scalars to collect
void registerObservables(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const
register obsevables so that their averages can be dumped to hdf5
void add2Record(RecordListType &record) override
add the local energy, variance and all the Hamiltonian components to the scalar record container ...
int LastIndex
last index within an record of the first element handled by an object
LocalEnergyEstimator(const QMCHamiltonian &h, bool use_hdf5)
constructor