QMCPACK
RMCLocalEnergyEstimator.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: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef QMCPLUSPLUS_RMCLOCALENERGYESTIMATOR_H
16 #define QMCPLUSPLUS_RMCLOCALENERGYESTIMATOR_H
19 #include "Particle/Reptile.h"
21 #include "ScalarEstimatorInputs.h"
22 namespace qmcplusplus
23 {
24 /** Class to accumulate the local energy and components
25  *
26  * Use Walker::Properties to accumulate Hamiltonian-related quantities.
27  */
29 {
34  int NObs;
36 
37  // This is just to allow compilation batched version does not support RMC at this time.
39 public:
40  /** constructor
41  * @param h QMCHamiltonian to define the components
42  */
44  /** Construct from LocalEnergyInput and const reference to hamiltonian.
45  * \param[in] RMCLocalEnergyEstimatorInput contains input parameters for RMCLocalEnergyEstimator
46  * \param[in] is taken as a local reference and used to size scalars data and to get obs output names
47  */
49 
50  /** accumulation per walker
51  * @param awalker current walker
52  * @param wgt weight
53  *
54  * Weight of observables should take into account the walkers weight. For Pure DMC. In branching DMC set weights to 1.
55  */
56  inline void accumulate(const Walker_t& awalker, RealType wgt) {}
57 
58  inline void accumulate(const RefVector<MCPWalker>& walkers) override
59  {
60  throw std::runtime_error("RMC not supported by Unified Driver interfaces");
61  }
62  inline void accumulate(const MCWalkerConfiguration& W,
63  WalkerIterator first,
64  WalkerIterator last,
65  RealType wgt) override
66  {
67  //WalkerIterator tail=first+W.activeBead+W.direction;
68  //WalkerIterator head=first+W.activeBead;
69  //if(tail>=last)
70  // tail-=last-first;
71  //else if(tail<first)
72  // tail+=last-first;
73  Walker_t& head = W.reptile->getHead();
74  Walker_t& tail = W.reptile->getTail();
75  Walker_t& center = W.reptile->getCenter();
76  // mixed estimator stuff
77  const RealType* restrict ePtr = head.getPropertyBase();
78  const RealType* restrict lPtr = tail.getPropertyBase();
79  const RealType* restrict cPtr = center.getPropertyBase();
80  // RealType wwght= head.Weight;
81  RealType wwght = 0.5;
82  //app_log()<<"~~~~~For head: Energy:"<<ePtr[LOCALENERGY]<< std::endl;
83  scalars[0](0.5 * (ePtr[WP::LOCALENERGY] + lPtr[WP::LOCALENERGY]), wwght);
84  scalars[1](0.5 * (ePtr[WP::LOCALENERGY] * ePtr[WP::LOCALENERGY] + lPtr[WP::LOCALENERGY] * lPtr[WP::LOCALENERGY]),
85  wwght);
86  scalars[2](cPtr[WP::LOCALENERGY], wwght);
87  scalars[3](cPtr[WP::LOCALENERGY] * cPtr[WP::LOCALENERGY], wwght);
88  scalars[4](ePtr[WP::LOCALENERGY] * lPtr[WP::LOCALENERGY], wwght);
89  scalars[5](0.5 * (ePtr[WP::LOCALPOTENTIAL] + lPtr[WP::LOCALPOTENTIAL]), wwght);
90  scalars[6](cPtr[WP::LOCALPOTENTIAL], wwght);
91 
92  for (int target = RMCSpecificTerms, source = FirstHamiltonian; source < FirstHamiltonian + SizeOfHamiltonians;
93  ++target, ++source)
94  {
95  wwght = 0.5;
96  scalars[target](lPtr[source], wwght);
97  scalars[target](ePtr[source], wwght);
98  }
99  for (int target = RMCSpecificTerms + SizeOfHamiltonians, source = FirstHamiltonian;
100  source < FirstHamiltonian + SizeOfHamiltonians; ++target, ++source)
101  {
102  wwght = 1;
103  scalars[target](cPtr[source], wwght);
104  }
105  // scalars[target](lPtr[source],wwght);
106  // int stride(0);
107  // int bds(last-first);
108  // if(bds%2>0)//odd
109  // {
110  // int odd=(bds+1)/2;
111  // stride=odd/NObs;
112  // }
113  // else
114  // {
115  // int odd=bds/2;
116  // stride=odd/NObs;
117  // }
118  //
119  // int indx(4+SizeOfHamiltonians);
120  // for(int j=0; j < NObs; j++)
121  // {
122  // tail+= -W.direction*stride;
123  // head+= W.direction*stride;
124  // if(tail>=last)
125  // tail-=last-first;
126  // else if(tail<first)
127  // tail+=last-first;
128  // if(head>=last)
129  // head-=last-first;
130  // else if(head<first)
131  // head+=last-first;
132  // const RealType* lPtr = tail.getPropertyBase();
133  // const RealType* ePtr = head.getPropertyBase();
134  // for(int target=0, source=FirstHamiltonian; target<SizeOfHamiltonians; ++target, ++source, indx++)
135  // {
136  // scalars[indx](lPtr[source]);
137  // scalars[indx](ePtr[source]);
138  // }
139  // }
140  // int maxage(0);
141  // while(first!=last)
142  // {
143  // maxage= std::max(maxage,(*first)->Age);
144  // first++;
145  // }
146  // scalars[3](maxage);
147  // for(; first != last; ++first) std::accumulate(**first,wgt);*/
148  }
149 
150  std::string getName() const override { return "RMCLocalEnergyEstimator"; }
151 
152  void add2Record(RecordListType& record) override;
153  void registerObservables(std::vector<ObservableHelper>& h5dec, hdf_archive& file) override {}
154  RMCLocalEnergyEstimator* clone() override;
155  const std::string& getSubTypeStr() const override { return input_.get_type(); }
156  /// RMCLocalEnergyEstimator is the main estimator type for RMC driver
157  bool isMainEstimator() const override { return true; }
158 
159 private:
161 };
162 } // namespace qmcplusplus
163 #endif
void accumulate(const Walker_t &awalker, RealType wgt)
accumulation per walker
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.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Walker_t & getTail()
Definition: Reptile.h:98
Class to accumulate the local energy and components.
Collection of Local Energy Operators.
bool isMainEstimator() const override
RMCLocalEnergyEstimator is the main estimator type for RMC driver.
class to handle hdf file
Definition: hdf_archive.h:51
const std::string & get_type() const
const char walkers[]
Definition: HDFVersion.h:36
Walker_t & getCenter()
Definition: Reptile.h:100
QMCTraits::FullPrecRealType RealType
std::vector< accumulator_type > scalars
scalars to be measured
const std::string & getSubTypeStr() const override
String representation of the derived type of the ScalarEstimator.
RecordNamedProperty< RealType > RecordListType
void resizeBasedOnHamiltonian(const QMCHamiltonian &ham)
RMCLocalEnergyEstimator(QMCHamiltonian &ham, int nobs=2)
constructor
void accumulate(const RefVector< MCPWalker > &walkers) override
a virtual function to accumulate observables or collectables
RMCLocalEnergyEstimator * clone() override
clone the object
std::vector< std::reference_wrapper< T > > RefVector
void registerObservables(std::vector< ObservableHelper > &h5dec, hdf_archive &file) override
add descriptors of observables to utilize hdf5
Indexes
an enum denoting index of physical properties
void add2Record(RecordListType &record) override
add the local energy, variance and all the Hamiltonian components to the scalar record container ...
MCWalkerConfiguration::const_iterator WalkerIterator
Walker_t & getHead()
Definition: Reptile.h:97
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
void accumulate(const MCWalkerConfiguration &W, WalkerIterator first, WalkerIterator last, RealType wgt) override
a virtual function to accumulate observables or collectables
Declaration of QMCHamiltonian.