QMCPACK
MagnetizationDensityInput.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: Raymond Clay, rclay@sandia.gov, Sandia National Laboratories
8 //
9 // File created by: Raymond Clay, rclay@sandia.gov, Sandia National Laboratories
10 //////////////////////////////////////////////////////////////////////////////////////
12 
13 #include <cmath>
14 
15 #include "OhmmsData/AttributeSet.h"
17 #include "EstimatorInput.h"
18 namespace qmcplusplus
19 {
20 template bool InputSection::setIfInInput<qmcplusplus::MagnetizationDensityInput::Integrator>(
22  const std::string& tag);
23 
25 {
27  auto setIfInInput = LAMBDA_setIfInInput;
28  setIfInInput(nsamples_, "samples");
29  setIfInInput(integrator_, "integrator");
30  have_center_ = setIfInInput(center_, "center");
31  have_corner_ = setIfInInput(corner_, "corner");
32  have_grid_ = setIfInInput(grid_real_, "grid");
33  have_dr_ = setIfInInput(dr_, "dr");
34 }
35 
36 
38  const Lattice& lattice) const
39 {
40  PosType corner = 0.0;
41  //Corner and center can be taken care of by defaults. corner=0 if not specified.
42  if (have_center_)
43  corner = center_ - lattice.Center;
44  else if (have_corner_)
45  corner = corner_;
46 
48 
49  //dr or grid must be specified to perform the grid math. Input already checked before we get here.
50  if (have_dr_)
51  for (int d = 0; d < DIM; ++d)
52  grid[d] = (int)std::ceil(std::sqrt(dot(lattice.Rv[d], lattice.Rv[d])) / dr_[d]);
53  else if (have_grid_)
54  for (int d = 0; d < DIM; ++d)
55  grid[d] = (int)std::ceil(grid_real_[d]);
56 
57  size_t npoints = 1;
58  for (int d = 0; d < DIM; ++d)
59  npoints *= grid[d];
60 
62  gdims[0] = npoints / grid[0];
63  for (int d = 1; d < DIM; ++d)
64  gdims[d] = gdims[d - 1] / grid[d];
65 
66  return {corner, grid, gdims, npoints};
67 }
68 
70 {
71  return lookupAnyEnum(name, get<std::string>(name), lookup_input_enum_value);
72 }
73 
75 {
76  using namespace estimatorinput;
77  const std::string error_tag{"MagnetizationDensity input: "};
78  checkCenterCorner(*this, error_tag);
79 
80  if (has("grid") && has("dr"))
81  throw UniformCommunicateError(error_tag + " cannot define grid and dr.");
82 
83  if (has("grid"))
84  {
85  PosType thisgrid = get<PosType>("grid");
86  for (int d = 0; d < DIM; ++d)
87  {
88  if (thisgrid[d] < 1.0)
89  throw UniformCommunicateError(error_tag + " number of grid points must be >=1 in each direction");
90  }
91  }
92  else if (has("dr"))
93  {
94  //This is the most we can test without knowing the lattice.
95  //Correctness determined if dr implies grid with more than 1 point in each direction.
96  //Check is performed in calculateDerivedParameters().
97  PosType thisdr = get<PosType>("dr");
98  for (int d = 0; d < DIM; ++d)
99  {
100  if (thisdr[d] <= 0.0)
101  throw UniformCommunicateError(error_tag + " grid spacing dr must be >= 0 in each direction");
102  if (thisdr[d] >= 10.0)
103  app_log() << error_tag + " dr larger than 10.0. Make sure that this grid spacing is intended.\n";
104  }
105  }
106  else
107  throw UniformCommunicateError(error_tag + " grid or dr must be specified.");
108 
109  if (has("samples"))
110  {
111  int samps = get<int>("samples");
112  if (samps < 1)
113  throw UniformCommunicateError(error_tag + " number of samples has to be greater than 0");
114  }
115 }
116 
117 } //namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::ostream & app_log()
Definition: OutputManager.h:65
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
MakeReturn< UnaryNode< FnCeil, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t ceil(const Vector< T1, C1 > &l)
#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.
constexpr bool has(const R &this_one)
bool have_dr_
these are necessary for calculateDerivedParameters
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 ...
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
DerivedParameters calculateDerivedParameters(const Lattice &lattice) const
Derived parameters of SpinDensity.
MagnetizationDensityInputSection input_section_
std::any assignAnyEnum(const std::string &name) const override
Derived class overrides this to get proper assignment of scoped enum values.
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void checkParticularValidity() override
Do validation for a particular subtype of InputSection Called by check_valid.
void checkCenterCorner(InputSection &input_section, const std::string &error_tag)
static const std::unordered_map< std::string, std::any > lookup_input_enum_value