QMCPACK
CSEnergyEstimator.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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
11 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12 //
13 // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
14 //////////////////////////////////////////////////////////////////////////////////////
15 
16 
17 #include "CSEnergyEstimator.h"
21 #include "Message/CommOperators.h"
23 
24 #include <array>
25 
26 namespace qmcplusplus
27 {
28 /** constructor
29  * @param h QMCHamiltonian to define the components
30  * @param hcopy number of copies of QMCHamiltonians
31  */
33 {
34  int NumObservables = h.sizeOfObservables();
35 
36  NumCopies = hcopy;
38  LastHamiltonian = FirstHamiltonian + NumObservables;
39 
40  //add names
41  h_components.push_back("LocEne");
42  h_components.push_back("LocPot");
43  for (int i = 0; i < NumObservables; ++i)
44  h_components.push_back(h.getObservableName(i));
45 
46  scalars.resize(NumCopies + h_components.size() * (NumCopies + NumCopies * (NumCopies - 1) / 2));
47  scalars_saved.resize(scalars.size());
48 }
49 
51 {
52  int NumObservables = h.sizeOfObservables();
53 
56  LastHamiltonian = FirstHamiltonian + NumObservables;
57 
58  //add names
59  h_components.push_back("LocEne");
60  h_components.push_back("LocPot");
61  for (int i = 0; i < NumObservables; ++i)
62  h_components.push_back(h.getObservableName(i));
63 
64  scalars.resize(NumCopies + h_components.size() * (NumCopies + NumCopies * (NumCopies - 1) / 2));
65  scalars_saved.resize(scalars.size());
66 }
67 
68 
70 
71 /** add the local energy, variance and all the Hamiltonian components to the scalar record container
72  *@param record storage of scalar records (name,value)
73  */
75 {
76  std::array<char, 80> aname;
77  FirstIndex = record.size();
78 
79  for (int i = 0; i < NumCopies; ++i)
80  {
81  for (int k = 0; k < h_components.size(); ++k)
82  {
83  int length = std::snprintf(aname.data(), aname.size(), "%s_%i", h_components[k].c_str(), i);
84  if (length < 0)
85  throw std::runtime_error("Error generating record name");
86  record.add(std::string(aname.data(), length));
87  }
88  }
89 
90  for (int i = 0; i < NumCopies; ++i)
91  {
92  int length = std::snprintf(aname.data(), aname.size(), "wpsi_%i", i);
93  if (length < 0)
94  throw std::runtime_error("Error generating record name");
95  record.add(std::string(aname.data(), length));
96  }
97 
98  for (int i = 0; i < NumCopies; i++)
99  {
100  for (int j = i + 1; j < NumCopies; j++)
101  {
102  for (int k = 0; k < h_components.size(); ++k)
103  {
104  int length = std::snprintf(aname.data(), aname.size(), "d%s_%d_%d", h_components[k].c_str(), i, j);
105  if (length < 0)
106  throw std::runtime_error("Error generating record name");
107  record.add(std::string(aname.data(), length));
108  }
109  }
110  }
111 
112 
113  LastIndex = record.size();
115  uweights.resize(NumCopies);
116  clear();
117 
118  //msg.add(d_data.begin(),d_data.end());
119 }
120 
121 void CSEnergyEstimator::registerObservables(std::vector<ObservableHelper>& h5dec, hdf_archive& file)
122 {
123  //NEED TO IMPLEMENT for hdf5
124 }
125 
127 {
129  std::vector<double> weightaverage(NumCopies);
130  //first copy data to tmp_dat to calculate differences
131  for (int i = 0; i < NumCopies; i++)
132  {
133  const RealType* restrict prop = awalker.getPropertyBase(i);
134  RealType* restrict prop_saved = tmp_data[i];
135  uweights[i] = prop[WP::UMBRELLAWEIGHT];
136  *prop_saved++ = prop[WP::LOCALENERGY];
137  *prop_saved++ = prop[WP::LOCALPOTENTIAL];
138  std::copy(prop + FirstHamiltonian, prop + LastHamiltonian, prop_saved);
139  }
140 
141  int ii = 0;
142  const RealType* hptr = tmp_data.data();
143  for (int i = 0; i < NumCopies; i++)
144  {
145  RealType uw = uweights[i];
146  for (int k = 0; k < tmp_data.cols(); ++k)
147  scalars[ii++](*hptr++, uw);
148  }
149 
150  for (int i = 0; i < NumCopies; i++)
151  {
152  scalars[ii++](uweights[i], 1.0);
153  }
154 
155  int ii_i(0); //index of observable ii for copy i
156  int ii_j(0); //index of observable ii for copy j
157  for (int i = 0; i < NumCopies; i++)
158  {
159  for (int j = i + 1; j < NumCopies; j++)
160  {
161  for (int k = 0; k < tmp_data.cols(); ++k)
162  {
163  ii_i = i * tmp_data.cols() + k;
164  ii_j = j * tmp_data.cols() + k;
165 
166  //reset is used here because we do no accumulating. Just overwrite.
167  scalars[ii++].reset(scalars[ii_i].mean() - scalars[ii_j].mean(), 1.0);
168  }
169  }
170  }
171 }
172 
173 } // namespace qmcplusplus
Matrix< RealType > tmp_data
temporary dat
CSEnergyEstimator * clone() override
clone the object
std::string getObservableName(int i) const
return the name of the i-th observable
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
void registerObservables(std::vector< ObservableHelper > &h5dec, hdf_archive &gid) override
add descriptors of observables to utilize hdf5
std::vector< std::string > h_components
name of hamiltonian components
std::vector< RealType > uweights
save umbrella weights
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
int FirstIndex
first index within an record of the first element handled by an object
std::vector< accumulator_type > scalars
scalars to be measured
size_type cols() const
Definition: OhmmsMatrix.h:78
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
int FirstHamiltonian
index of the starting Hamiltonian component
int add(const std::string &aname)
const CSLocalEnergyInput input_
int sizeOfObservables() const
return the size of observables
std::vector< accumulator_type > scalars_saved
scalars saved
int NumCopies
number of correlated systems
void clear()
clear the scalars to collect
Declaration of a TrialWaveFunction.
Indexes
an enum denoting index of physical properties
Declaraton of ParticleAttrib<T>
int LastHamiltonian
index of the ending Hamiltonian component
void accumulate(const Walker_t &awalker, RealType wgt)
void add2Record(RecordNamedProperty< RealType > &record) override
add the local energy, variance and all the Hamiltonian components to the scalar record container ...
FullPrecRealType * getPropertyBase()
Definition: Walker.h:277
int LastIndex
last index within an record of the first element handled by an object
ACC::value_type mean(const ACC &ac)
Definition: accumulators.h:147
A container class to represent a walker.
Definition: Walker.h:49
Declaration of QMCHamiltonian.
CSEnergyEstimator(const QMCHamiltonian &h, int hcopy=1)
constructor