QMCPACK
EstimatorManagerInput.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) 2024 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File refactored from: EstimatorManagerNew.cpp
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "EstimatorManagerInput.h"
14 #include <algorithm>
15 #include "ModernStringUtils.hpp"
16 
17 namespace qmcplusplus
18 {
20 
21 EstimatorManagerInput::EstimatorManagerInput(std::initializer_list<EstimatorManagerInput> emil)
22 {
23  // \todo the following code fusing two vectors can be written in more consice way with std::back_inserter. See history.
24  // Right now needs to use a clumsy way to make intel classic compiler 19.1.x happy when using gcc 9 on some OS distros.
25  size_t est_offset = 0;
26  size_t scalar_est_offset = 0;
27  for (const EstimatorManagerInput& emi : emil)
28  {
29  est_offset += emi.estimator_inputs_.size();
30  scalar_est_offset += emi.scalar_estimator_inputs_.size();
31  }
32  estimator_inputs_.resize(est_offset);
33  scalar_estimator_inputs_.resize(scalar_est_offset);
34 
35  est_offset = 0;
36  scalar_est_offset = 0;
37  for (const EstimatorManagerInput& emi : emil)
38  {
39  std::copy(emi.estimator_inputs_.begin(), emi.estimator_inputs_.end(), estimator_inputs_.begin() + est_offset);
40  est_offset += emi.estimator_inputs_.size();
42  scalar_estimator_inputs_.begin() + scalar_est_offset);
43  scalar_est_offset += emi.scalar_estimator_inputs_.size();
44  }
45 }
46 
47 void EstimatorManagerInput::readXML(xmlNodePtr cur)
48 {
49  const std::string error_tag{"EstimatorManager input:"};
50  std::string cur_name{lowerCase(castXMLCharToChar(cur->name))};
51  xmlNodePtr child;
52  if (cur_name == "estimators")
53  child = cur->xmlChildrenNode;
54  else
55  child = cur; // the case when 'estimator's are not encapsulated by a 'estimators' node
56  while (child != NULL)
57  {
58  std::string cname{lowerCase(castXMLCharToChar(child->name))};
59  if (cname == "estimator")
60  {
61  std::string atype(lowerCase(getXMLAttributeValue(child, "type")));
62  std::string aname(lowerCase(getXMLAttributeValue(child, "name")));
63  if (atype.empty() && !aname.empty())
64  atype = aname;
65  if (aname.empty() && !atype.empty())
66  aname = atype;
67  if (atype == "localenergy" || atype == "elocal")
68  appendScalarEstimatorInput<LocalEnergyInput>(child);
69  else if (atype == "cslocalenergy")
70  {
71  appendScalarEstimatorInput<CSLocalEnergyInput>(child);
72  app_warning() << "CSLocalEnergyEstimator support is at best experimental with batch drivers" << std::endl;
73  }
74  else if (atype == "rmc")
75  {
76  appendScalarEstimatorInput<RMCLocalEnergyInput>(child);
77  app_warning() << "RMCLocalEnergyEstimator support is at best experimental with batch drivers" << std::endl;
78  }
79  else if (atype == "onebodydensitymatrices")
80  appendEstimatorInput<OneBodyDensityMatricesInput>(child);
81  else if (atype == "spindensity")
82  appendEstimatorInput<SpinDensityInput>(child);
83  else if (atype == "momentumdistribution")
84  appendEstimatorInput<MomentumDistributionInput>(child);
85  else if (atype == "selfhealingoverlap")
86  appendEstimatorInput<SelfHealingOverlapInput>(child);
87  else if (atype == "perparticlehamiltonianlogger")
88  appendEstimatorInput<PerParticleHamiltonianLoggerInput>(child);
89  else if (atype == "magnetizationdensity")
90  appendEstimatorInput<MagnetizationDensityInput>(child);
91  else
92  throw UniformCommunicateError(error_tag + "unparsable <estimator> node, name: " + aname + " type: " + atype +
93  " in Estimators input.");
94  }
95  else if (cname != "text")
96  {
97  std::string atype(lowerCase(getXMLAttributeValue(child, "type")));
98  std::string aname(lowerCase(getXMLAttributeValue(child, "name")));
99  throw UniformCommunicateError(error_tag + "<estimators> can only contain <estimator> nodes");
100  }
101 
102  if (cur_name == "estimators")
103  child = child->next;
104  else
105  {
106  app_summary() << "<estimator> nodes not contained in <estimators>...</estimators> is a deprecated input xml idiom"
107  << std::endl;
108  break;
109  }
110  }
111 }
112 
115 
116 
117 } // namespace qmcplusplus
std::ostream & app_warning()
Definition: OutputManager.h:69
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
declares the list supported estimator input types and declares the input type for EstimatorManagerNew...
std::ostream & app_summary()
Definition: OutputManager.h:63
void readXML(xmlNodePtr cur)
read <estimators> node or (<estimator> node for legacy support) This can be done multiple times with ...
EstimatorManagerInput emi(estimators_doc.getRoot())
void append(const EstimatorInput &ei)
typed appending of already parsed inputs.
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
EstimatorInputs estimator_inputs_
this is a vector of variants for typesafe access to the estimator inputs
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
This a subclass for runtime errors that will occur on all ranks.
ScalarEstimatorInputs scalar_estimator_inputs_
std::string lowerCase(const std::string_view s)
++17
std::variant< std::monostate, MomentumDistributionInput, SpinDensityInput, OneBodyDensityMatricesInput, SelfHealingOverlapInput, MagnetizationDensityInput, PerParticleHamiltonianLoggerInput > EstimatorInput
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...
Input type for EstimatorManagerNew Parses Estimators level of input and and delegates child estimator...
std::variant< std::monostate, LocalEnergyInput, CSLocalEnergyInput, RMCLocalEnergyInput > ScalarEstimatorInput