QMCPACK
StaticStructureFactor.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: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #include "StaticStructureFactor.h"
15 #include "OhmmsData/AttributeSet.h"
16 #include "LongRange/KContainer.h"
17 #include "LongRange/StructFact.h"
18 
19 namespace qmcplusplus
20 {
22 {
23  if (P.getLattice().SuperCellEnum == SUPERCELL_OPEN)
24  APP_ABORT("StaticStructureFactor is incompatible with open boundary conditions");
25 
26  // get particle information
27  SpeciesSet& species = P.getSpeciesSet();
28  nspecies = species.size();
29  for (int s = 0; s < nspecies; ++s)
30  species_name.push_back(species.speciesName[s]);
31  reset();
32 }
33 
34 
36 {
37  name_ = "StaticStructureFactor";
38  update_mode_.set(COLLECTABLE, 1);
39  ecut = -1.0;
40  nkpoints = -1;
41 }
42 
43 
44 std::unique_ptr<OperatorBase> StaticStructureFactor::makeClone(ParticleSet& P, TrialWaveFunction& Psi)
45 {
46  return std::make_unique<StaticStructureFactor>(*this);
47 }
48 
49 
50 bool StaticStructureFactor::put(xmlNodePtr cur)
51 {
52  using std::sqrt;
53  reset();
54  const k2_t& k2_init = Pinit.getSimulationCell().getKLists().ksq;
55 
56  std::string write_report = "no";
57  OhmmsAttributeSet attrib;
58  attrib.add(name_, "name");
59  //attrib.add(ecut,"ecut");
60  attrib.add(write_report, "report");
61  attrib.put(cur);
62 
63  if (ecut < 0.0)
64  nkpoints = k2_init.size();
65  else
66  {
67  RealType k2cut = 2.0 * ecut;
68  nkpoints = 0;
69  for (int i = 0; i < k2_init.size(); ++i)
70  if (k2_init[i] < k2cut)
71  nkpoints++;
72  }
73 
74  if (nkpoints == 0)
75  APP_ABORT("StaticStructureFactor::put could not find any kpoints");
76 
77  ecut = .5 * k2_init[nkpoints - 1];
78 
79  if (write_report == "yes")
80  report(" ");
81 
82  return true;
83 }
84 
85 
86 void StaticStructureFactor::report(const std::string& pad)
87 {
88  app_log() << pad << "StaticStructureFactor report" << std::endl;
89  app_log() << pad << " name = " << name_ << std::endl;
90  app_log() << pad << " ecut = " << ecut << std::endl;
91  app_log() << pad << " nkpoints = " << nkpoints << std::endl;
92  app_log() << pad << " nspecies = " << nspecies << std::endl;
93  for (int s = 0; s < nspecies; ++s)
94  app_log() << pad << " species[" << s << "] = " << species_name[s] << std::endl;
95  app_log() << pad << "end StaticStructureFactor report" << std::endl;
96 }
97 
98 
100 {
101  my_index_ = collectables.current();
102  std::vector<RealType> tmp(nspecies * 2 * nkpoints); // real & imag parts
103  collectables.add(tmp.begin(), tmp.end());
104 }
105 
106 
107 void StaticStructureFactor::registerCollectables(std::vector<ObservableHelper>& h5desc, hdf_archive& file) const
108 {
109  h5desc.emplace_back(hdf_path(name_) / "kpoints");
110  auto& oh = h5desc.back();
111  oh.addProperty(const_cast<std::vector<PosType>&>(Pinit.getSimulationCell().getKLists().kpts_cart), "value", file);
112 
113  std::vector<int> ng(2);
114  ng[0] = 2;
115  ng[1] = nkpoints;
116  for (int s = 0; s < nspecies; ++s)
117  {
118  h5desc.emplace_back(hdf_path{species_name[s]});
119  auto& ohSpeciesName = h5desc.back();
120  ohSpeciesName.set_dimensions(ng, my_index_ + s * 2 * nkpoints);
121  }
122 }
123 
124 
126 {
128  const Matrix<RealType>& rhok_r = P.getSK().rhok_r;
129  const Matrix<RealType>& rhok_i = P.getSK().rhok_i;
130  int nkptot = rhok_r.cols();
131  for (int s = 0; s < nspecies; ++s)
132  {
133  int kc = my_index_ + s * 2 * nkpoints;
134  //int kstart = s*nkptot;
135  //for(int k=kstart;k<kstart+nkpoints;++k,++kc)
136  // P.Collectables[kc] += w*rhok_r(k);
137  //for(int k=kstart;k<kstart+nkpoints;++k,++kc)
138  // P.Collectables[kc] += w*rhok_i(k);
139  for (int k = 0; k < nkpoints; ++k, ++kc)
140  P.Collectables[kc] += w * rhok_r(s, k);
141  for (int k = 0; k < nkpoints; ++k, ++kc)
142  P.Collectables[kc] += w * rhok_i(s, k);
143  }
144  return 0.0;
145 }
146 
147 } // namespace qmcplusplus
bool put(xmlNodePtr cur) override
Read the input parameter.
Matrix< RealType > rhok_r
2-D container for the phase
Definition: StructFact.h:51
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
Matrix< RealType > rhok_i
Definition: StructFact.h:51
int my_index_
starting index of this object
Definition: OperatorBase.h:535
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
class to handle hdf file
Definition: hdf_archive.h:51
void addObservables(PropertySetType &plist, BufferType &olist) override
named values to the property list Default implementaton uses addValue(plist_)
Vectorized record engine for scalar properties.
void addProperty(T &p, const std::string &pname, hdf_archive &file)
add named property to describe the collectable this helper class handles
int size() const
return the number of species
Definition: SpeciesSet.h:53
std::unique_ptr< OperatorBase > makeClone(ParticleSet &P, TrialWaveFunction &psi) final
size_type cols() const
Definition: OhmmsMatrix.h:78
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
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
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
void registerCollectables(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const override
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
size_type current() const
Definition: PooledData.h:51
const StructFact & getSK() const
return Structure Factor
Definition: ParticleSet.h:216
Walker_t * t_walker_
reference to the current walker
Definition: OperatorBase.h:541
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
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44
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)
Class to represent a many-body trial wave function.
FullPrecRealType Weight
Weight of the walker.
Definition: Walker.h:102
const auto & getLattice() const
Definition: ParticleSet.h:251
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
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< std::string > species_name
void report(const std::string &pad)
std::bitset< 8 > update_mode_
set the current update mode
Definition: OperatorBase.h:521
ObservableHelper oh