QMCPACK
GridExternalPotential.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: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Kevin Ryczko, kryczko@uottawa.ca, University of Ottawa
9 // Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //
11 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #include "GridExternalPotential.h"
16 #include "OhmmsData/AttributeSet.h"
17 
18 
19 namespace qmcplusplus
20 {
22 {
25 }
26 
27 bool GridExternalPotential::put(xmlNodePtr cur)
28 {
29  using std::sqrt;
30 
31 
32  OhmmsAttributeSet attrib;
33 
34  /*
35  Future update must include differing grid sizes in the x, y, and z directions.
36 
37  Everything is the same size for now.
38  */
39 
40  Ugrid grid;
41  grid.start = -2.0;
42  grid.end = 2.0;
43  grid.num = 11;
44  BCtype_d BC;
45  BC.lCode = NATURAL;
46  BC.rCode = NATURAL;
47  std::string file_name;
48  std::string dataset_name;
49  bool pbc;
50 
51  attrib.add(grid.start, "start");
52  attrib.add(grid.end, "end");
53  attrib.add(grid.num, "num");
54  attrib.add(file_name, "file_name");
55  attrib.add(dataset_name, "dataset_name");
56  attrib.add(pbc, "pbc");
57  attrib.put(cur);
58 
59  double delta = (grid.end - grid.start) / (grid.num - 1);
60 
61 
62  if (pbc)
63  {
64  BC.lCode = PERIODIC;
65  BC.rCode = PERIODIC;
66  delta = (grid.end - grid.start) / (grid.num);
67  }
68 
69  Array<double, 3> data(grid.num, grid.num, grid.num);
70 
71  hdf_archive hin;
72  bool read_okay = hin.open(file_name, H5F_ACC_RDONLY);
73  if (!read_okay)
74  {
75  app_log() << "Failed to open HDF5 file: " << file_name << "." << std::endl;
76  }
77  else
78  {
79  app_log() << " ==============================\n"
80  << " Information of grid:\n"
81  << " Grid start: " << grid.start << std::endl
82  << " Grid end: " << grid.end << std::endl
83  << " Grid num: " << grid.num << std::endl
84  << " Grid delta: " << delta << std::endl
85  << " Grid file_name: " << file_name << std::endl
86  << " Grid dataset_name: " << dataset_name << std::endl
87  << " Periodic: " << pbc << std::endl
88  << " ==============================\n";
89  }
90 
91  hin.read(data, dataset_name);
92 
93  spline_data_.reset(create_UBspline_3d_d(grid, grid, grid, BC, BC, BC, data.data()), destroy_Bspline);
94 
95  return true;
96 }
97 
98 
99 bool GridExternalPotential::get(std::ostream& os) const
100 {
101  os << "External grid potential" << std::endl;
102  return true;
103 }
104 
105 
106 std::unique_ptr<OperatorBase> GridExternalPotential::makeClone(ParticleSet& P, TrialWaveFunction& psi)
107 {
108  return std::make_unique<GridExternalPotential>(*this);
109 }
110 
111 
113 {
114 #if !defined(REMOVE_TRACEMANAGER)
116  value_ = evaluate_sp(P);
117  else
118  {
119 #endif
120  value_ = 0.0;
121  for (int i = 0; i < P.getTotalNum(); ++i)
122  {
123  PosType r = P.R[i];
124  P.getLattice().applyMinimumImage(r);
125  double val = 0.0;
126  eval_UBspline_3d_d(spline_data_.get(), r[0], r[1], r[2], &val);
127 
128  value_ += val;
129  }
130 #if !defined(REMOVE_TRACEMANAGER)
131  }
132 #endif
133  return value_;
134 }
135 
137 {
138  return evaluate(P);
139 }
140 
141 #if !defined(REMOVE_TRACEMANAGER)
143 
145 {
148  v_sample_ = tm.checkout_real<1>(name_, ps_);
149 }
150 
152 {
154  delete v_sample_;
155 }
156 
158 {
159  Array<TraceReal, 1>& V_samp = *v_sample_;
160  value_ = 0.0;
161  for (int i = 0; i < P.getTotalNum(); ++i)
162  {
163  PosType r = P.R[i];
164  RealType v1 = dot(r, r);
165  V_samp(i) = v1;
166  value_ += v1;
167  }
168  return value_;
169 }
170 #endif
171 
172 } // namespace qmcplusplus
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool streaming_array(const std::string &name)
Definition: TraceManager.h:249
QTBase::RealType RealType
Definition: Configuration.h:58
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
size_t getTotalNum() const
Definition: ParticleSet.h:493
Array< TraceReal, 1 > * v_sample_
single particle trace sample array
std::ostream & app_log()
Definition: OutputManager.h:65
bool get(std::ostream &os) const override
write about the class
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
Type_t * data()
Definition: OhmmsArray.h:87
class to handle hdf file
Definition: hdf_archive.h:51
TraceRequest request_
whether traces are being collected
Definition: OperatorBase.h:531
std::string name_
name of this object
Definition: OperatorBase.h:527
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
void oneBodyQuantumDomain(const ParticleSet &P)
set quantum domain for one-body operator
ParticlePos R
Position.
Definition: ParticleSet.h:79
void setEnergyDomain(EnergyDomains edomain)
Set the Energy Domain.
std::unique_ptr< OperatorBase > makeClone(ParticleSet &P, TrialWaveFunction &psi) final
void checkoutParticleQuantities(TraceManager &tm) override
Array< TraceReal, D > * checkout_real(const std::string &name, int n1=1, int n2=0, int n3=0, int n4=0)
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
bool put(xmlNodePtr cur) override
Read the input parameter.
Class to represent a many-body trial wave function.
Return_t value_
current value
Definition: OperatorBase.h:524
void contribute_array(const std::string &name, bool default_quantity=false)
Definition: TraceManager.h:198
const auto & getLattice() const
Definition: ParticleSet.h:251
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:306
std::shared_ptr< UBspline_3d_d > spline_data_
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