QMCPACK
SpeciesKineticEnergy.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: Yubo Yang, paul.young.0414@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Yubo Yang, paul.young.0414@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "SpeciesKineticEnergy.h"
13 #include "BareKineticHelper.h"
14 #include "OhmmsData/AttributeSet.h"
15 
16 namespace qmcplusplus
17 {
19 {
20  SpeciesSet& tspecies(P.getSpeciesSet());
21  int massind = tspecies.getAttribute("mass");
22 
23  num_species = tspecies.size();
24  app_log() << "SpeciesKineticEnergy is tracking " << num_species << " species." << std::endl;
25 
28  species_names.resize(num_species);
29  for (int ispec = 0; ispec < num_species; ispec++)
30  {
31  species_names[ispec] = tspecies.speciesName[ispec];
32  RealType mass = tspecies(massind, ispec);
33  vec_minus_over_2m[ispec] = -1. / (2. * mass);
34  app_log() << " " << species_names[ispec] << " mass = " << mass << std::endl;
35  }
36 };
37 
38 bool SpeciesKineticEnergy::put(xmlNodePtr cur)
39 {
40  // read hdf5="yes" or "no"
41  OhmmsAttributeSet attrib;
42  std::string hdf5_flag = "no";
43  attrib.add(hdf5_flag, "hdf5");
44  attrib.put(cur);
45 
46  if (hdf5_flag == "yes")
47  hdf5_out = true;
48  else if (hdf5_flag == "no")
49  hdf5_out = false;
50  else
51  APP_ABORT("SpeciesKineticEnergy::put() - Please choose \"yes\" or \"no\" for hdf5 flag");
52  // end if
53 
54  if (hdf5_out)
55  { // add this estimator to stat.h5
56  update_mode_.set(COLLECTABLE, 1);
57  }
58  return true;
59 }
60 
61 bool SpeciesKineticEnergy::get(std::ostream& os) const
62 { // class description
63  os << "SpeciesKineticEnergy: " << name_;
64  return true;
65 }
66 
68 {
69  my_index_ = plist.size();
70  for (int ispec = 0; ispec < num_species; ispec++)
71  { // make columns named "$myName_u", "$myName_d" etc.
72  plist.add(name_ + "_" + species_names[ispec]);
73  }
74  if (hdf5_out)
75  { // make room in h5 file and save its index
76  h5_index = collectables.size();
77  std::vector<RealType> tmp(num_species);
78  collectables.add(tmp.begin(), tmp.end());
79  }
80 }
81 
82 void SpeciesKineticEnergy::registerCollectables(std::vector<ObservableHelper>& h5desc, hdf_archive& file) const
83 {
84  if (!hdf5_out)
85  return;
86 
87  std::vector<int> ndim(1, num_species);
88  h5desc.emplace_back(hdf_path{name_});
89  auto& h5o = h5desc.back();
90  h5o.set_dimensions(ndim, h5_index);
91 }
92 
94 { // slots in plist must be allocated by addObservables() first
95  copy(species_kinetic.begin(), species_kinetic.end(), plist.begin() + my_index_);
96 }
97 
99 {
100  std::fill(species_kinetic.begin(), species_kinetic.end(), 0.0);
101  RealType wgt = t_walker_->Weight;
102 
103  for (int iat = 0; iat < P.getTotalNum(); iat++)
104  {
105  int ispec = P.GroupID[iat];
106  RealType my_kinetic = vec_minus_over_2m[ispec] * laplacian(P.G[iat], P.L[iat]);
107  if (hdf5_out)
108  {
109  P.Collectables[h5_index + ispec] += my_kinetic * wgt;
110  }
111  species_kinetic[ispec] += my_kinetic;
112  }
113 
114  value_ = 0.0; // Value is no longer used
115  return value_;
116 }
117 
118 std::unique_ptr<OperatorBase> SpeciesKineticEnergy::makeClone(ParticleSet& qp, TrialWaveFunction& psi)
119 {
120  return std::make_unique<SpeciesKineticEnergy>(*this);
121 }
122 
123 } // namespace qmcplusplus
size_type size() const
return the size of the data
Definition: PooledData.h:48
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::vector< std::string > species_names
size_t getTotalNum() const
Definition: ParticleSet.h:493
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
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.
ParticleLaplacian L
laplacians of the particles
Definition: ParticleSet.h:85
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
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
void setObservables(PropertySetType &plist) override
Set the values evaluated by this object to plist Default implementation is to assign Value which is u...
int add(const std::string &aname)
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
bool get(std::ostream &os) const override
write about the class
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
Walker_t * t_walker_
reference to the current walker
Definition: OperatorBase.h:541
T laplacian(const TinyVector< T, D > &g, T l)
compute real(laplacian)
void registerCollectables(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const override
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
void addObservables(PropertySetType &plist, BufferType &collectables) override
named values to the property list Default implementaton uses addValue(plist_)
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) final
Class to represent a many-body trial wave function.
int getAttribute(const std::string &aname) const
When a name species does not exist, return attribute.size()
Definition: SpeciesSet.cpp:60
Return_t value_
current value
Definition: OperatorBase.h:524
FullPrecRealType Weight
Weight of the walker.
Definition: Walker.h:102
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
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 > vec_minus_over_2m
std::bitset< 8 > update_mode_
set the current update mode
Definition: OperatorBase.h:521
std::vector< RealType > species_kinetic
bool put(xmlNodePtr cur) override
Read the input parameter.