QMCPACK
ReferencePointsInput.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) 2023 QMCPACK developers.
6 //
7 // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 // Peter W. Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //
11 // Some code refactored from: QMCHamiltonians/ReferencePoints.cpp
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 #include "ReferencePointsInput.h"
15 
16 #include <sstream>
17 
18 #include "EstimatorInput.h"
19 #include "ModernStringUtils.hpp"
20 
21 namespace qmcplusplus
22 {
23 template bool InputSection::setIfInInput<ReferencePointsInput::Coord>(ReferencePointsInput::Coord& var,
24  const std::string& tag);
25 
27 {
29  auto setIfInInput = LAMBDA_setIfInInput;
30  setIfInInput(coord_form_, "coord");
31  readRefPointsXML(cur);
32 }
33 
34 // ReferencePointsInput::ReferencePointsInput(const Points& points, const CoordForm coord_form)
35 // : points_(points), coord_form_(coord_form)
36 // {}
37 
39 {
42 
43  // read refpoints values they are some sequence of value nodes
44  std::string node_str{XMLNodeString{cur}};
45  std::vector<std::string_view> lines = split(strip(node_str), "\n");
46  for (int i = 0; i < lines.size(); i++)
47  {
48  auto stripped_line = strip(lines[i]);
49  std::vector<std::string_view> tokens = split(stripped_line, " ");
50  if (tokens.size() != OHMMS_DIM + 1)
51  {
52  std::ostringstream error;
53  error << error_tag << "reference point has 4 entries, given " << tokens.size() << ": " << lines[i];
54  throw UniformCommunicateError(error.str());
55  }
56  else
57  {
58  Point rp;
59  for (int d = 0; d < OHMMS_DIM; d++)
60  {
61  try
62  {
63  rp[d] = std::stod(std::string(tokens[d + 1].begin(), tokens[d + 1].size()));
64  }
65  catch (const std::invalid_argument& ia)
66  {
67  throw UniformCommunicateError(ia.what());
68  }
69  }
70 
71  // This must be done in constructor of ReferencePoints
72  // rp = dot(crd, rp);
73  points_[std::string(tokens[0].begin(), tokens[0].size())] = rp;
74  }
75  }
76 }
77 
79 {
80  return lookupAnyEnum(name, get<std::string>(name), lookup_input_enum_value);
81 }
82 
83 std::any makeReferencePointsInput(xmlNodePtr cur, std::string& value_label)
84 {
85  ReferencePointsInput rpi{cur};
86  value_label = "referencepoints";
87  return rpi;
88 }
89 
90 } // namespace qmcplusplus
std::any assignAnyEnum(const std::string &name) const override
Derived class overrides this to get proper assignment of scoped enum values.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::string_view strip(const string_view s)
std::any makeReferencePointsInput(xmlNodePtr cur, std::string &value_label)
factory function used by InputSection to make reference points Input
static constexpr std::string_view error_tag
#define OHMMS_DIM
Definition: config.h:64
std::string strip(const std::string &s)
Definition: string_utils.h:26
void error(char const *m)
Definition: Standard.h:204
std::vector< std::string > split(const std::string &s)
Definition: string_utils.h:57
#define LAMBDA_setIfInInput
If tag is present in input_secution set its variable.
This a subclass for runtime errors that will occur on all ranks.
void readXML(xmlNodePtr cur)
Read variable values (initialize) from XML input, call checkValid.
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 ...
ReferencePointsInput()=default
Unlike many input classes ReferencePointInputs needs a way to be constructured even if there is no in...
static const std::unordered_map< std::string, std::any > lookup_input_enum_value
mapping for enumerated options of ReferencePointsInput This data object is the basis of input enum st...
convert xmlNode contents into a std::string
std::vector< std::string_view > split(const string_view s, const string_view delimiters)
ReferencePointsInputSection input_section_