QMCPACK
OneBodyDensityMatricesInput::OneBodyDensityMatricesInputSection Class Reference
+ Inheritance diagram for OneBodyDensityMatricesInput::OneBodyDensityMatricesInputSection:
+ Collaboration diagram for OneBodyDensityMatricesInput::OneBodyDensityMatricesInputSection:

Public Member Functions

 OneBodyDensityMatricesInputSection ()
 parse time definition of input parameters More...
 
 OneBodyDensityMatricesInputSection (const OneBodyDensityMatricesInputSection &)=default
 
void checkParticularValidity () override
 do parse time checks of input More...
 
std::any assignAnyEnum (const std::string &name) const override
 Derived class overrides this to get proper assignment of scoped enum values. More...
 
- Public Member Functions inherited from InputSection
 InputSection ()=default
 
 InputSection (const InputSection &other)=default
 
InputSectionoperator= (const InputSection &other)=default
 
bool has (const std::string &name) const
 
template<typename T >
get (const std::string &name) const
 
template<typename T >
bool setIfInInput (T &var, const std::string &tag)
 set var if input section has read the tag More...
 
void readXML (xmlNodePtr cur)
 Read variable values (initialize) from XML input, call checkValid. More...
 
void init (const std::unordered_map< std::string, std::any > &init_values)
 

Additional Inherited Members

- Public Types inherited from InputSection
using Real = QMCTraits::FullPrecRealType
 
using Position = typename QMCTypes< Real, OHMMS_DIM >::PosType
 
- Static Public Member Functions inherited from InputSection
template<typename ENUM_T >
static std::string reverseLookupInputEnumMap (ENUM_T enum_val, const std::unordered_map< std::string, std::any > &enum_map)
 Get string represtation of enum class type value from enum_val. More...
 
- Protected Types inherited from InputSection
using DelegateHandler = std::function< std::any(xmlNodePtr cur, std::string &value_name)>
 Function that returns Input class as std::any. More...
 
- Protected Member Functions inherited from InputSection
void readAttributes (xmlNodePtr cur, const std::string &element_name, const std::vector< std::string > &do_not_consume)
 reads attributes for both the root node and parameter/child nodes that aren't delegated. More...
 
void registerDelegate (const std::string &tag, DelegateHandler delegate_handler)
 register factory function for delegate input More...
 
virtual void setFromStreamCustom (const std::string &ename, const std::string &name, std::istringstream &svalue)
 Derived class can overrides this to do custom parsing of the element values for Custom elements These can have a name attribute only. More...
 
void report () const
 
void report (std::ostream &out) const
 
- Static Protected Member Functions inherited from InputSection
static std::any lookupAnyEnum (const std::string &enum_name, const std::string &enum_value, const std::unordered_map< std::string, std::any > &enum_map)
 Assign any enum helper for InputSection derived class assumes enum lookup table of this form: inline static const std::unordered_map<std::string, std::any> lookup_input_enum_value{{"integrator-uniform_grid", Integrator::UNIFORM_GRID}, {"integrator-uniform", Integrator::UNIFORM}, {"integrator-density", Integrator::DENSITY}, {"evaluator-loop", Evaluator::LOOP}, {"evaluator-matrix", Evaluator::MATRIX}};. More...
 
- Protected Attributes inherited from InputSection
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. More...
 
std::vector< std::string > section_name_alternates
 For historical reasons some sections must recognize several different names. Assign them to this variable in your subtype. More...
 
std::unordered_set< std::string > attributes
 
std::unordered_set< std::string > parameters
 
std::unordered_set< std::string > delegates
 
std::unordered_set< std::string > required
 
std::unordered_set< std::string > multiple
 
std::unordered_set< std::string > strings
 
std::unordered_set< std::string > multi_strings
 
std::unordered_set< std::string > multi_reals
 
std::unordered_set< std::string > bools
 
std::unordered_set< std::string > integers
 
std::unordered_set< std::string > reals
 
std::unordered_set< std::string > positions
 
std::unordered_set< std::string > custom
 
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 and values need only be known to IS subtypes More...
 
std::unordered_map< std::string, std::any > default_values
 
std::unordered_map< std::string, std::function< std::any(xmlNodePtr cur, std::string &value_key)> > delegate_factories_
 
std::unordered_map< std::string, std::any > values_
 

Detailed Description

Definition at line 66 of file OneBodyDensityMatricesInput.h.

Constructor & Destructor Documentation

◆ OneBodyDensityMatricesInputSection() [1/2]

parse time definition of input parameters

Definition at line 70 of file OneBodyDensityMatricesInput.h.

References InputSection::attributes, InputSection::bools, InputSection::enums, InputSection::integers, InputSection::multi_strings, InputSection::parameters, InputSection::positions, InputSection::reals, InputSection::required, InputSection::section_name, and InputSection::strings.

71  {
72  // clang-format off
73  section_name = "OneBodyDensityMatrices";
74  attributes = {"name", "type"};
75  parameters = {"basis", "energy_matrix", "integrator", "evaluator", "scale",
76  "corner", "center", "points", "samples", "warmup", "timestep",
77  "use_drift", "check_overlap", "check_derivatives", "acceptance_ratio", "rstats",
78  "normalized", "volumed_normed"};
79  bools = {"energy_matrix", "use_drift", "normalized", "volume_normed",
80  "check_overlap", "check_derivatives", "rstats", "acceptance_ratio"};
81  enums = {"integrator", "evaluator"};
82  strings = {"name", "type"};
83  multi_strings = {"basis"};
84  integers = {"points", "samples"};
85  reals = {"scale", "timestep"};
86  positions = {"center", "corner"};
87  required = {"name", "basis"};
88  // I'd much rather see the default defined in simple native c++ as below
89  // clang-format on
90  }
std::unordered_set< std::string > strings
Definition: InputSection.h:67
std::unordered_set< std::string > reals
Definition: InputSection.h:72
std::unordered_set< std::string > parameters
Definition: InputSection.h:63
std::unordered_set< std::string > positions
Definition: InputSection.h:73
std::unordered_set< std::string > integers
Definition: InputSection.h:71
std::unordered_set< std::string > attributes
Definition: InputSection.h:62
std::unordered_set< std::string > required
Definition: InputSection.h:65
std::unordered_set< std::string > multi_strings
Definition: InputSection.h:68
std::unordered_set< std::string > bools
Definition: InputSection.h:70
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
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

◆ OneBodyDensityMatricesInputSection() [2/2]

Member Function Documentation

◆ assignAnyEnum()

std::any assignAnyEnum ( const std::string &  tag) const
overridevirtual

Derived class overrides this to get proper assignment of scoped enum values.

In most cases all you'll need it to define the map and write: std::any DerivedInputSection::assignAnyEnum(const std::string& name) const { return lookupAnyEnum(name, get<std::string>(name), derived_input_lookup_enum); }

See test_InputSection.cpp and OneBodyDensityMatricesInput You really should do this if your input class has a finite set of string values for an input example: OneBodyDensityMatricesInput

can't be bothered then just define your enum option as a string.

Reimplemented from InputSection.

Definition at line 77 of file OneBodyDensityMatricesInput.cpp.

References OneBodyDensityMatricesInput::lookup_input_enum_value, and InputSection::lookupAnyEnum().

78 {
79  return lookupAnyEnum(name, get<std::string>(name), lookup_input_enum_value);
80 }
static std::any lookupAnyEnum(const std::string &enum_name, const std::string &enum_value, const std::unordered_map< std::string, std::any > &enum_map)
Assign any enum helper for InputSection derived class assumes enum lookup table of this form: inline ...
static const std::unordered_map< std::string, std::any > lookup_input_enum_value
mapping for enumerated options of OneBodyDensityMatrices This data object is the basis of input enum ...

◆ checkParticularValidity()

void checkParticularValidity ( )
overridevirtual

do parse time checks of input

Reimplemented from InputSection.

Definition at line 47 of file OneBodyDensityMatricesInput.cpp.

References qmcplusplus::estimatorinput::checkCenterCorner(), qmcplusplus::Units::charge::e, and InputSection::has().

48 {
49  using namespace estimatorinput;
50  const std::string error_tag{"OneBodyDensityMatrices input: "};
51  checkCenterCorner(*this, error_tag);
52  if (has("scale"))
53  {
54  Real scale = get<Real>("scale");
55  if (scale > 1.0 + 1e-10)
56  throw UniformCommunicateError(error_tag + "scale must be less than one");
57  else if (scale < 0.0 - 1e-10)
58  throw UniformCommunicateError(error_tag + "scale must be greater than zero");
59  }
60  std::vector<std::string> basis_sets = get<std::vector<std::string>>("basis");
61  if (basis_sets.size() == 0 || basis_sets[0].size() == 0)
62  throw UniformCommunicateError(error_tag + "basis must have at least one sposet");
63  // An example of how to do specific validation of input.
64  if (get<std::string>("integrator") != "density")
65  {
66  if (has("acceptance_ratio") && get<bool>("acceptance_ratio") == true)
67  throw UniformCommunicateError(error_tag + "acceptance_ratio can only be true for density integrator");
68  }
69  if (get<std::string>("integrator") == "uniform_grid")
70  {
71  if (has("samples"))
72  throw UniformCommunicateError(error_tag +
73  "samples are set from points for uniform_grid integrator and are invalid input");
74  }
75 }
QMCTraits::FullPrecRealType Real
Definition: InputSection.h:40
bool has(const std::string &name) const
Definition: InputSection.h:87
void checkCenterCorner(InputSection &input_section, const std::string &error_tag)

The documentation for this class was generated from the following files: