QMCPACK
ParameterSet.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) 2021 QMCPACK developers.
6 //
7 // File developed by: D. Das, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
11 //
12 // Refactored from: ParameterSet.h
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 #include "ParameterSet.h"
16 #include <vector>
17 #include <libxml/xmlmemory.h>
18 #include <libxml/tree.h>
19 #include "ModernStringUtils.hpp"
20 #include "libxmldefs.h"
21 
22 bool ParameterSet::put(xmlNodePtr cur)
23 {
24  using namespace qmcplusplus;
25  if (cur == NULL)
26  return true; //handle empty node
27  cur = cur->xmlChildrenNode;
28  bool something = false;
29  while (cur != NULL)
30  {
31  std::string cname(lowerCase(castXMLCharToChar(cur->name)));
32  if (auto it_tag = m_param.find(cname); it_tag == m_param.end())
33  {
34  if (cname == myName)
35  {
36  std::string aname(lowerCase(getXMLAttributeValue(cur, "name")));
37  if (!aname.empty())
38  {
39  if (auto it = m_param.find(aname); it != m_param.end())
40  {
41  something = true;
42  it->second->put(cur);
43  }
44  }
45  }
46  }
47  else
48  {
49  something = true;
50  it_tag->second->put(cur);
51  }
52  cur = cur->next;
53  }
54  return something;
55 }
56 
57 template<class PDT>
58 void ParameterSet::add(PDT& aparam, const std::string& aname_in, std::vector<PDT> candidate_values, TagStatus status)
59 {
60  using namespace qmcplusplus;
61  std::string aname(lowerCase(aname_in));
62  if (auto it = m_param.find(aname); it == m_param.end())
63  {
64  m_param[aname] = std::make_unique<OhmmsParameter<PDT>>(aparam, aname, std::move(candidate_values), status);
65  }
66 }
67 
68 template<class PDT>
69 void ParameterSet::setValue(const std::string& aname_in, PDT aval)
70 {
71  using namespace qmcplusplus;
72  std::string aname(lowerCase(aname_in));
73  if (auto it = m_param.find(aname); it != m_param.end())
74  {
75  (dynamic_cast<OhmmsParameter<PDT>&>(*it->second)).setValue(aval);
76  }
77 }
78 
79 template void ParameterSet::add(std::string&, const std::string&, std::vector<std::string>, TagStatus);
81  const std::string&,
82  std::vector<qmcplusplus::astring>,
83  TagStatus);
84 template void ParameterSet::add<int>(int&, const std::string&, std::vector<int>, TagStatus);
85 template void ParameterSet::add<bool>(bool&, const std::string&, std::vector<bool>, TagStatus);
86 template void ParameterSet::add<double>(double&, const std::string&, std::vector<double>, TagStatus);
87 template void ParameterSet::add<float>(float&, const std::string&, std::vector<float>, TagStatus);
88 template void ParameterSet::add<std::complex<double>>(std::complex<double>&,
89  const std::string&,
90  std::vector<std::complex<double>>,
91  TagStatus);
92 template void ParameterSet::add<std::complex<float>>(std::complex<float>&,
93  const std::string&,
94  std::vector<std::complex<float>>,
95  TagStatus);
96 
97 template void ParameterSet::add<qmcplusplus::TinyVector<int, 3u>>(qmcplusplus::TinyVector<int, 3u>&,
98  const std::string&,
99  std::vector<qmcplusplus::TinyVector<int, 3u>>,
100  TagStatus);
101 
102 template void ParameterSet::setValue<int>(const std::string& aname_in, int aval);
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::string myName
the name of the node, corresponds to the xml tag
std::map< std::string, std::unique_ptr< OhmmsElementBase > > m_param
Definition: ParameterSet.h:31
A collection of put/get functions to read from or write to a xmlNode defined in libxml2.
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
void setValue(const std::string &aname_in, PDT aval)
std::string lowerCase(const std::string_view s)
++17
char * castXMLCharToChar(xmlChar *c)
assign a value from a node. Use specialization for classes.
Definition: libxmldefs.h:62
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
TagStatus
generic class for parameter xmlNode