QMCPACK
Listener.hpp
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: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef QMCPLUSPLUS_LISTENER_HPP
13 #define QMCPLUSPLUS_LISTENER_HPP
14 /** \file
15  * Listener types that allow Estimators to register with QMCHamiltonian to have "trace" values from
16  * operators reported.
17  * This is aims to be lightweight and minimal but still use much of the trace manager based
18  * implementation of observables that rely on per particle Hamiltonian values.
19  */
20 
21 #include <functional>
22 
24 
25 #include "OhmmsPETE/OhmmsMatrix.h"
26 #include "OhmmsPETE/OhmmsVector.h"
27 
28 namespace qmcplusplus
29 {
30 
31 /** An object of this type is a listener expecting a callback to the report function with a vector of values,
32  * the convention being 1 per particle, called once per walker per component.
33  * The name is primarily for debugging purposes, if have decided against having the QMCHamiltonian use it to estable
34  * routing. Instead the register functions in the QMCHamiltonian are specfic to the sort of value that the listener wants
35  * to listen to.
36  */
37 template<typename T>
39 {
40 public:
41  /** "Callback" function type for an operator to report a vector of values to a listener
42  * \param[in] walker_index a numeric walker id, could be important to listener
43  * \param[in] name of operator reporting, could be important to listener
44  * \param[in] values vector of values, per particle by convention. Also by convention
45  * the receiver should not assume the reference values have any persistence
46  * beyond the scope of the callback.
47  */
48  using ReportingFunction =
49  std::function<void(const int walker_index, const std::string& name, const Vector<T>& values)>;
50  /** constructor that should appear in the code
51  * \param[in] name intended to be strictly information
52  * \param[in] report_func intended to be a lambda callback function that will be used to report.
53  */
54  ListenerVector(const std::string& name, ReportingFunction report_func) : report(report_func), name_(name) {}
56  const std::string& get_name() const { return name_; }
57 
58 private:
59  const std::string name_;
60 };
61 
62 /** Convenience container for common optional element to mw_eval.._impl.
63  * This allows the per_particle and reduced mw_eval_... to share the same
64  * implementation method.
65  *
66  * member naming is such that on usage:
67  * ListenerOption listeners
68  * ...
69  * if (listeners)
70  * for (const ListenerVector<Real>& listener : listeners->electron_values)
71  * listener.report(iw, O_leader.getName(), ve_sample);
72  *
73  * see NonLocalECPotential for example of usage.
74  */
75 template<typename T>
77 {
78  ListenerOption(const std::vector<ListenerVector<T>>& le, const std::vector<ListenerVector<T>>& li)
79  : electron_values(le), ion_values(li)
80  {}
81  const std::vector<ListenerVector<T>>& electron_values;
82  const std::vector<ListenerVector<T>>& ion_values;
83 };
84 
85 } // namespace qmcplusplus
86 
87 
88 #endif
const std::string & get_name() const
Definition: Listener.hpp:56
const std::vector< ListenerVector< T > > & ion_values
Definition: Listener.hpp:82
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
const std::vector< ListenerVector< T > > & electron_values
Definition: Listener.hpp:81
An object of this type is a listener expecting a callback to the report function with a vector of val...
Definition: Listener.hpp:38
ListenerVector(const std::string &name, ReportingFunction report_func)
constructor that should appear in the code
Definition: Listener.hpp:54
ReportingFunction report
Definition: Listener.hpp:55
std::function< void(const int walker_index, const std::string &name, const Vector< T > &values)> ReportingFunction
"Callback" function type for an operator to report a vector of values to a listener ...
Definition: Listener.hpp:49
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
ListenerOption(const std::vector< ListenerVector< T >> &le, const std::vector< ListenerVector< T >> &li)
Definition: Listener.hpp:78
Convenience container for common optional element to mw_eval.._impl.
Definition: Listener.hpp:76
const std::string name_
Definition: Listener.hpp:59