QMCPACK
SkEstimator.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #include "SkEstimator.h"
17 #include "LongRange/StructFact.h"
19 #include "OhmmsData/AttributeSet.h"
20 
21 namespace qmcplusplus
22 {
24 {
25  sourcePtcl = &source;
26  update_mode_.set(COLLECTABLE, 1);
28  NumK = source.getSimulationCell().getKLists().numk;
29  OneOverN = 1.0 / static_cast<RealType>(source.getTotalNum());
30  Kshell = source.getSimulationCell().getKLists().kshell;
31  MaxKshell = Kshell.size() - 1;
35  Kmag.resize(MaxKshell);
36  OneOverDnk.resize(MaxKshell);
37  for (int ks = 0; ks < MaxKshell; ks++)
38  {
39  Kmag[ks] = std::sqrt(source.getSimulationCell().getKLists().ksq[Kshell[ks]]);
40  OneOverDnk[ks] = 1.0 / static_cast<RealType>(Kshell[ks + 1] - Kshell[ks]);
41  }
42  hdf5_out = true;
43 }
44 
46 
48 {
49  //sum over species
50  std::copy(P.getSK().rhok_r[0], P.getSK().rhok_r[0] + NumK, RhokTot_r.begin());
51  std::copy(P.getSK().rhok_i[0], P.getSK().rhok_i[0] + NumK, RhokTot_i.begin());
52  for (int i = 1; i < NumSpecies; ++i)
54  for (int i = 1; i < NumSpecies; ++i)
56  if (hdf5_out)
57  {
60  for (int i = my_index_; iit_r != iit_r_end; ++iit_r, ++iit_i, ++i)
61  P.Collectables[i] += OneOverN * ((*iit_r) * (*iit_r) + (*iit_i) * (*iit_i));
62  }
63  else
64  {
67  for (int i = 0; iit_r != iit_r_end; ++iit_r, ++iit_i, ++i)
68  values[i] = OneOverN * ((*iit_r) * (*iit_r) + (*iit_i) * (*iit_i));
69  }
70  return 0.0;
71 }
72 
74 {
75  if (hdf5_out)
76  {
77  my_index_ = collectables.size();
78  std::vector<RealType> tmp(NumK);
79  collectables.add(tmp.begin(), tmp.end());
80  }
81  else
82  {
83  my_index_ = plist.size();
84  for (int i = 0; i < NumK; i++)
85  {
86  std::stringstream sstr;
87  sstr << "sk_" << i;
88  int id = plist.add(sstr.str());
89  }
90  }
91 }
92 
94 {
95  my_index_ = plist.size();
96  for (int i = 0; i < NumK; i++)
97  {
98  std::stringstream sstr;
99  sstr << "sk_" << i;
100  int id = plist.add(sstr.str());
101  }
102 }
103 
105 {
106  if (!hdf5_out)
107  std::copy(values.begin(), values.end(), plist.begin() + my_index_);
108 }
109 
111 {
112  if (!hdf5_out)
113  std::copy(values.begin(), values.end(), plist.begin() + my_index_ + offset);
114 }
115 
116 
117 void SkEstimator::registerCollectables(std::vector<ObservableHelper>& h5desc, hdf_archive& file) const
118 {
119  if (hdf5_out)
120  {
121  std::vector<int> ndim(1, NumK);
122  h5desc.emplace_back(hdf_path{name_});
123  auto& h5o = h5desc.back();
124  h5o.set_dimensions(ndim, my_index_);
125 
126  hsize_t kdims[2];
127  kdims[0] = NumK;
128  kdims[1] = OHMMS_DIM;
129  std::string kpath = name_ + "/kpoints";
130  hid_t k_space = H5Screate_simple(2, kdims, NULL);
131  hid_t k_set =
132  H5Dcreate(file.getFileID(), kpath.c_str(), H5T_NATIVE_DOUBLE, k_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
133  hid_t mem_space = H5Screate_simple(2, kdims, NULL);
134  auto* ptr = &(sourcePtcl->getSimulationCell().getKLists().kpts_cart[0][0]);
135  herr_t ret = H5Dwrite(k_set, H5T_NATIVE_DOUBLE, mem_space, k_space, H5P_DEFAULT, ptr);
136  H5Dclose(k_set);
137  H5Sclose(mem_space);
138  H5Sclose(k_space);
139  file.flush();
140  }
141 }
142 
143 bool SkEstimator::put(xmlNodePtr cur)
144 {
145  OhmmsAttributeSet pAttrib;
146  std::string hdf5_flag = "no";
147  pAttrib.add(hdf5_flag, "hdf5");
148  pAttrib.put(cur);
149  if (hdf5_flag == "yes")
150  hdf5_out = true;
151  else
152  hdf5_out = false;
153  return true;
154 }
155 
156 bool SkEstimator::get(std::ostream& os) const { return true; }
157 
158 std::unique_ptr<OperatorBase> SkEstimator::makeClone(ParticleSet& qp, TrialWaveFunction& psi)
159 {
160  std::unique_ptr<SkEstimator> myclone = std::make_unique<SkEstimator>(*this);
161  myclone->hdf5_out = hdf5_out;
162  myclone->my_index_ = my_index_;
163  return myclone;
164 }
165 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
size_type size() const
return the size of the data
Definition: PooledData.h:48
Declare SkEstimator.
void addObservables(PropertySetType &plist)
Definition: SkEstimator.cpp:93
Matrix< RealType > rhok_r
2-D container for the phase
Definition: StructFact.h:51
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void setParticlePropertyList(PropertySetType &plist, int offset) override
int MaxKshell
number of kshells
Definition: SkEstimator.h:54
hid_t getFileID() const
return file_id. should be only be used for connecting to old codes when porting
Definition: hdf_archive.h:126
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
Definition: SkEstimator.cpp:45
Vector< RealType > values
Definition: SkEstimator.h:65
std::vector< RealType > OneOverDnk
1.0/degenracy for a ksell
Definition: SkEstimator.h:62
size_t getTotalNum() const
Definition: ParticleSet.h:493
Matrix< RealType > rhok_i
Definition: StructFact.h:51
int my_index_
starting index of this object
Definition: OperatorBase.h:535
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
bool put(xmlNodePtr cur) override
Read the input parameter.
std::vector< T >::iterator begin()
iterators to use std algorithms
class to handle hdf file
Definition: hdf_archive.h:51
Vectorized record engine for scalar properties.
RealType OneOverN
normalization factor
Definition: SkEstimator.h:56
#define OHMMS_DIM
Definition: config.h:64
void setObservables(PropertySetType &plist) override
Set the values evaluated by this object to plist Default implementation is to assign Value which is u...
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
int getTotalNum() const
return the number of species
Definition: SpeciesSet.h:55
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
int NumSpecies
number of species
Definition: SkEstimator.h:50
std::string name_
name of this object
Definition: OperatorBase.h:527
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
void add(T &x)
Definition: PooledData.h:88
int add(const std::string &aname)
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) override
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
Definition: SkEstimator.cpp:47
const StructFact & getSK() const
return Structure Factor
Definition: ParticleSet.h:216
ParticleSet * sourcePtcl
Definition: SkEstimator.h:48
Buffer_t Collectables
observables in addition to those registered in Properties/PropertyList
Definition: ParticleSet.h:126
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
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)
Vector< RealType > RhokTot_i
Definition: SkEstimator.h:64
std::vector< int > Kshell
kshell counters
Definition: SkEstimator.h:58
Class to represent a many-body trial wave function.
void registerCollectables(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const override
int NumK
number of kpoints
Definition: SkEstimator.h:52
SkEstimator(ParticleSet &elns)
Definition: SkEstimator.cpp:23
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
std::vector< RealType > Kmag
instantaneous structure factor
Definition: SkEstimator.h:60
void accumulate_elements(IT1 first, IT1 last, IT2 res)
std::bitset< 8 > update_mode_
set the current update mode
Definition: OperatorBase.h:521
Vector< RealType > RhokTot_r
for species index
Definition: SkEstimator.h:64
bool get(std::ostream &os) const override
write about the class
void flush()
flush a file
Definition: hdf_archive.h:146