QMCPACK
SpaceGridInput.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: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // Some code refactored from: SpaceGrid.h & SpaceGrid.cpp
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef QMCPLUSPLUS_SPACEGRID_INPUT_H
13 #define QMCPLUSPLUS_SPACEGRID_INPUT_H
14 
15 #include <set>
16 #include <unordered_map>
17 
18 #include <Configuration.h>
19 #include "InputSection.h"
20 #include "EstimatorInput.h"
21 #include "ParseGridInput.hpp" //for AxisGrid
22 
23 namespace qmcplusplus
24 {
25 namespace testing
26 {
27 template<typename T>
28 class EnergyDensityTests;
29 }
30 
31 class SpaceGrid;
32 
34 {
35 public:
37  using Real = double;
38 
39  enum class CoordForm
40  {
41  CARTESIAN = 0,
43  SPHERICAL
44  };
45 
46  inline static const std::unordered_map<std::string, std::any> lookup_input_enum_value{{"coord-cartesian",
48  {"coord-cylindrical",
50  {"coord-spherical",
52 
53  using LabelSet = std::vector<std::string_view>;
54  // legal labels for each coordinate type. These are effectively enums
55  inline static const LabelSet ax_cartesian{"x", "y", "z"};
56  inline static const LabelSet ax_cylindrical{"r", "phi", "z"};
57  inline static const LabelSet ax_spherical{"r", "phi", "theta"};
58  inline static const std::unordered_map<CoordForm, LabelSet> axes_label_sets{{CoordForm::CARTESIAN, ax_cartesian},
61 
63  {
65  {
66  public:
68  {
69  section_name = "axis";
70  attributes = {"label", "grid", "p1", "p2", "scale"};
71  strings = {"label", "p1", "p2"};
72  custom = {"grid"}, reals = {"scale"};
73  required = {"label", "p1"};
74  }
75  void setFromStreamCustom(const std::string& ename, const std::string& name, std::istringstream& svalue) override;
77  };
78 
79  public:
80  SpaceGridAxisInput(xmlNodePtr cur);
81  SpaceGridAxisInput(const SpaceGridAxisInput& sgai) = default;
82 
83  static std::any makeAxis(xmlNodePtr cur, std::string& value_label)
84  {
85  SpaceGridAxisInput space_grid_axis{cur};
86 
87  value_label = "axis";
88  return space_grid_axis;
89  }
90 
92 
93  std::string get_label() const { return label_; }
94  Real get_scale() const { return scale_; }
95  std::string get_p1() const { return p1_; }
96  std::string get_p2() const { return p2_; }
97  AxisGrid<Real> get_grid() const { return grid_; }
98 
99  private:
101  std::string label_ = "";
102  Real scale_ = 1.0;
103  std::string p1_ = "";
104  std::string p2_ = "zero";
106  };
107 
109  {
111  {
112  public:
114  {
115  section_name = "origin";
116  attributes = {"p1", "p2", "fraction"};
117  required = {"p1"};
118  strings = {"p1", "p2"};
119  reals = {"fraction"};
120  }
122  };
123 
124  public:
125  SpaceGridOriginInput(xmlNodePtr cur);
126 
127  static std::any makeOrigin(xmlNodePtr cur, std::string& value_label)
128  {
129  SpaceGridOriginInput space_grid_origin{cur};
130  value_label = "origin";
131  return space_grid_origin;
132  }
133  const std::string& get_p1() const { return p1_; }
134  const std::string& get_p2() const { return p2_; }
135  const Real get_fraction() const { return fraction_; }
136  private:
138  std::string p1_{"zero"};
139  std::string p2_{""};
141  };
142 
144  {
145  public:
147  {
148  section_name = "SpaceGrid";
149  attributes = {"coord"};
150  enums = {"coord"};
151  delegates = {"origin", "axis"};
152  multiple = {"axis"};
155  }
156  std::any assignAnyEnum(const std::string& name) const override;
157  void checkParticularValidity() override;
158  SpaceGridInputSection(const SpaceGridInputSection& sgis) = default;
159  };
160 
161  SpaceGridInput(xmlNodePtr cur);
162  SpaceGridInput(const SpaceGridInput& sgi) = default;
163 
166  const std::array<std::string, OHMMS_DIM>& get_axis_p1s() const { return axis_p1s_; }
167  const std::array<std::string, OHMMS_DIM>& get_axis_p2s() const { return axis_p2s_; }
168 
169  const std::array<Real, OHMMS_DIM>& get_axis_scales() const { return axis_scales_; }
170  const std::array<std::string, OHMMS_DIM>& get_axis_labels() const { return axis_labels_; }
171  const std::array<AxisGrid<Real>, OHMMS_DIM>& get_axis_grids() const { return axis_grids_; }
172  const std::string& get_origin_p1() const { return origin_p1_; }
173  const std::string& get_origin_p2() const { return origin_p2_; }
175  /** axes_label_set accessor, avoids a bunch of switch statements
176  * at must be used because std::unordered_map::operator[] can't return a const reference
177  */
179 
180 private:
181  void checkAxes(std::vector<std::any>& axes);
182  void checkGrids();
183 
186  // origin in optional so this is required.
187  std::string origin_p1_{"zero"};
188  std::string origin_p2_{""};
190  std::array<std::string, OHMMS_DIM> axis_labels_;
191  std::array<std::string, OHMMS_DIM> axis_p1s_;
192  std::array<std::string, OHMMS_DIM> axis_p2s_;
193  std::array<Real, OHMMS_DIM> axis_scales_;
194  std::array<AxisGrid<Real>, OHMMS_DIM> axis_grids_;
195 };
196 
197 /** factory function for a SpaceGridInput
198  * \param[in] input node for SpaceGridInput
199  * \param[out] value label returned to caller
200  */
201 std::any makeSpaceGridInput(xmlNodePtr, std::string& value_label);
202 
203 } // namespace qmcplusplus
204 #endif
std::array< std::string, OHMMS_DIM > axis_labels_
std::unordered_set< std::string > strings
Definition: InputSection.h:67
std::unordered_set< std::string > reals
Definition: InputSection.h:72
void checkAxes(std::vector< std::any > &axes)
CoordForm get_coord_form() const
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
SpaceGridInputSection input_section_
const LabelSet & get_axes_label_set() const
axes_label_set accessor, avoids a bunch of switch statements at must be used because std::unordered_m...
const std::string & get_origin_p1() const
void setFromStreamCustom(const std::string &ename, const std::string &name, std::istringstream &svalue) override
Derived class can overrides this to do custom parsing of the element values for Custom elements These...
static const std::unordered_map< std::string, std::any > lookup_input_enum_value
std::array< std::string, OHMMS_DIM > axis_p1s_
std::any makeSpaceGridInput(xmlNodePtr cur, std::string &value_label)
factory function for a SpaceGridInput
static std::any makeAxis(xmlNodePtr cur, std::string &value_label)
#define OHMMS_DIM
Definition: config.h:64
const SpaceGridAxisInputSection & get_input()
std::unordered_set< std::string > custom
Definition: InputSection.h:74
std::array< AxisGrid< Real >, OHMMS_DIM > axis_grids_
const std::array< AxisGrid< Real >, OHMMS_DIM > & get_axis_grids() const
std::unordered_set< std::string > delegates
Definition: InputSection.h:64
const std::array< std::string, OHMMS_DIM > & get_axis_labels() const
std::any assignAnyEnum(const std::string &name) const override
Derived class overrides this to get proper assignment of scoped enum values.
std::unordered_set< std::string > attributes
Definition: InputSection.h:62
std::array< std::string, OHMMS_DIM > axis_p2s_
std::vector< std::string_view > LabelSet
static const LabelSet ax_cylindrical
static const std::unordered_map< CoordForm, LabelSet > axes_label_sets
const std::string & get_origin_p2() const
void checkParticularValidity() override
Do validation for a particular subtype of InputSection Called by check_valid.
static std::any makeOrigin(xmlNodePtr cur, std::string &value_label)
The AxisGrid data structure and the ParseGridInput factor parsing in a manner usable in acustom handl...
std::unordered_set< std::string > required
Definition: InputSection.h:65
static const LabelSet ax_spherical
const std::array< Real, OHMMS_DIM > & get_axis_scales() const
std::array< Real, OHMMS_DIM > axis_scales_
const std::array< std::string, OHMMS_DIM > & get_axis_p1s() const
static const LabelSet ax_cartesian
std::unordered_set< std::string > multiple
Definition: InputSection.h:66
Input section provides basic parsing and a uniform method of access to the raw parsed input...
Definition: InputSection.h:37
void registerDelegate(const std::string &tag, DelegateHandler delegate_handler)
register factory function for delegate input
std::string section_name
"Name" of the input section, you must define this in the subtype and the ename, name, type, or method must match.
Definition: InputSection.h:57
const std::array< std::string, OHMMS_DIM > & get_axis_p2s() const
std::unordered_set< std::string > enums
list of enum inputs which allow a finite set of strings to map to enum values The enum class types an...
Definition: InputSection.h:78