QMCPACK
SpinDensityInput.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // Some code refactored from: SpinDensity.cpp
10 //////////////////////////////////////////////////////////////////////////////////////
11 #include "SpinDensityInput.h"
12 
13 #include <cmath>
14 
15 #include "OhmmsData/AttributeSet.h"
17 
18 namespace qmcplusplus
19 {
20 
22 {
23  readXML(node);
24 }
25 
26 void SpinDensityInput::readXML(xmlNodePtr cur)
27 {
28  std::string write_report;
29  std::string save_memory;
30  OhmmsAttributeSet attrib;
31  attrib.add(myName_, "name");
32  attrib.add(write_report, "report");
33  attrib.add(save_memory, "save_memory");
34  attrib.put(cur);
35 
36  Tensor<Real, DIM> axes;
37 
38  int test_moves = 0;
39 
40  xmlNodePtr element = cur->xmlChildrenNode;
41  while (element != NULL)
42  {
43  std::string ename((const char*)element->name);
44  if (ename == "parameter")
45  {
46  const std::string name(getXMLAttributeValue(element, "name"));
47  if (name == "dr")
48  {
49  have_dr_ = true;
50  putContent(dr_, element);
51  }
52  else if (name == "grid")
53  {
54  have_grid_ = true;
55  putContent(grid_, element);
56  }
57  else if (name == "corner")
58  {
59  have_corner_ = true;
60  putContent(corner_, element);
61  }
62  else if (name == "center")
63  {
64  have_center_ = true;
65  putContent(center_, element);
66  }
67  else if (name == "cell")
68  {
69  have_cell_ = true;
70  putContent(axes, element);
71  }
72  else if (name == "test_moves")
73  putContent(test_moves, element);
74  }
75  element = element->next;
76  }
77 
78  if (have_dr_ && have_grid_)
79  throw UniformCommunicateError("SpinDensity input dr and grid are provided, this is ambiguous");
80  else if (!have_dr_ && !have_grid_)
81  throw UniformCommunicateError("SpinDensity input must provide dr or grid");
82 
84  throw UniformCommunicateError("SpinDensity input corner and center are provided, this is ambiguous");
85 
86  if (have_cell_)
87  {
88  cell_.set(axes);
89  if (!have_corner_ && !have_center_)
90  throw UniformCommunicateError("SpinDensity input must provide corner or center with explicitly defined cell");
91  }
92 
93  if (write_report == "yes")
94  write_report_ = true;
95  else
96  write_report_ = false;
97 
98  if (save_memory == "yes")
99  save_memory_ = true;
100  else
101  save_memory_ = false;
102 
103  // weird legacy stuff
104  // if (write_report == "yes")
105  // report(" ");
106  // if (test_moves > 0)
107  // test(test_moves, *Ptmp);
108 }
109 
111 {
112  PosType corner = 0.0;
113  if (have_center_)
114  corner = center_ - lattice.Center;
115  else if (have_corner_)
116  corner = corner_;
117 
119  if (have_dr_)
120  for (int d = 0; d < DIM; ++d)
121  grid[d] = (int)std::ceil(std::sqrt(dot(lattice.Rv[d], lattice.Rv[d])) / dr_[d]);
122  else if (have_grid_)
123  grid = grid_;
124 
125  size_t npoints = 1;
126  for (int d = 0; d < DIM; ++d)
127  npoints *= grid[d];
128 
129  TinyVector<int, DIM> gdims;
130  gdims[0] = npoints / grid[0];
131  for (int d = 1; d < DIM; ++d)
132  gdims[d] = gdims[d - 1] / grid[d];
133 
134  return {corner, grid, gdims, npoints};
135 }
136 
137 } // namespace qmcplusplus
void set(const Tensor< TT, D > &lat)
set the lattice vector from the command-line options
a class that defines a supercell in D-dimensional Euclean space.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
if(!okay) throw std xmlNodePtr node
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::string myName_
name of this Estimator
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
MakeReturn< UnaryNode< FnCeil, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t ceil(const Vector< T1, C1 > &l)
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
This a subclass for runtime errors that will occur on all ranks.
bool have_dr_
these are necessary for calculateDerivedParameters
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...
TinyVector< int, DIM > grid_
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
DerivedParameters calculateDerivedParameters(const Lattice &lattice) const
Derived parameters of SpinDensity.