QMCPACK
ForwardWalking.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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #include "ForwardWalking.h"
18 #include "OhmmsData/ParameterSet.h"
19 #include "OhmmsData/AttributeSet.h"
21 #include <cstdlib>
22 #include <set>
23 #include <string>
24 
25 namespace qmcplusplus
26 {
28 
30 
32 {
33  for (int i = 0; i < nobservables_; i++)
34  {
35  int lastindex = t_walker_->PHindex[p_ids_[i]] - 1;
36  if (lastindex < 0)
37  lastindex += walker_lengths_[i][2];
39  }
40  calculate(P);
41  return 0.0;
42 }
43 
45 {
46  std::vector<RealType>::iterator Vit = values_.begin();
47  for (int i = 0; i < nobservables_; i++)
48  {
49  int j = 0;
50  int FWindex = t_walker_->PHindex[p_ids_[i]] - 1;
51  while (j < walker_lengths_[i][1])
52  {
53  FWindex -= walker_lengths_[i][0];
54  if (FWindex < 0)
55  FWindex += walker_lengths_[i][2];
56  (*Vit) = t_walker_->PropertyHistory[p_ids_[i]][FWindex];
57  j++;
58  Vit++;
59  }
60  }
62  return 0.0;
63 }
64 
66 {
67  for (int i = 0; i < nobservables_; i++)
69  calculate(P);
70  return 0.0;
71 }
72 
73 bool ForwardWalking::put(xmlNodePtr cur) { return true; }
74 
76 {
78 
80  nobservables_ = 0;
81  nvalues_ = 0;
82  xmlNodePtr tcur = cur->children;
83  while (tcur != NULL)
84  {
85  std::string cname((const char*)tcur->name);
86  if (cname == "Observable")
87  {
88  std::string tagName("none");
89  int Hindex(-100);
90  int blockSeries(0);
91  int blockFreq(0);
92  OhmmsAttributeSet Tattrib;
93  Tattrib.add(tagName, "name");
94  Tattrib.add(blockSeries, "max");
95  Tattrib.add(blockFreq, "frequency");
96  Tattrib.put(tcur);
97  if (tagName.find("*") == std::string::npos)
98  {
99  //Single Observable case
100  int numProps = P.PropertyList.Names.size();
101  Hindex = h.getObservable(tagName) + WP::NUMPROPERTIES;
102  if (tagName == "LocalPotential")
103  {
104  Hindex = WP::LOCALPOTENTIAL;
105  tagName = "LocPot";
106  }
107  else if (tagName == "LocalEnergy")
108  {
109  Hindex = WP::LOCALENERGY;
110  tagName = "LocEn";
111  }
112  else if (Hindex == (WP::NUMPROPERTIES - 1))
113  {
114  app_log() << "Not a valid H element(" << Hindex << ") Valid names are:";
115  for (int jk = 0; jk < h.sizeOfObservables(); jk++)
116  app_log() << " " << h.getObservableName(jk);
117  app_log() << std::endl;
118  exit(-1);
119  }
120  names_.push_back(tagName);
121  h_ids_.push_back(Hindex);
122  app_log() << " Hamiltonian Element " << tagName << " was found at " << Hindex << std::endl;
123  int numT = blockSeries / blockFreq;
124  nobservables_ += 1;
125  nvalues_ += numT;
126  app_log() << " " << numT << " values will be calculated every " << blockFreq << "*tau H^-1" << std::endl;
127  std::vector<int> pms(3);
128  pms[0] = blockFreq;
129  pms[1] = numT;
130  pms[2] = blockSeries + 2;
131  walker_lengths_.push_back(pms);
132  int maxWsize = blockSeries + 2;
133  int pindx = P.addPropertyHistory(maxWsize);
134  p_ids_.push_back(pindx);
135  }
136  else
137  {
138  bool FOUNDH(false);
139  // Multiple observables for this tag
140  int found = tagName.rfind("*");
141  tagName.replace(found, 1, "");
142  int numProps = P.PropertyList.Names.size();
143  for (int j = 0; j < h.sizeOfObservables(); j++)
144  {
145  std::string Hname = h.getObservableName(j);
146  if (Hname.find(tagName) != std::string::npos)
147  {
148  FOUNDH = true;
149  app_log() << " Hamiltonian Element " << Hname << " was found at " << j << std::endl;
150  names_.push_back(Hname);
151  Hindex = j + WP::NUMPROPERTIES;
152  h_ids_.push_back(Hindex);
153  int numT = blockSeries / blockFreq;
154  nobservables_ += 1;
155  nvalues_ += numT;
156  app_log() << " " << numT << " values will be calculated every " << blockFreq << "*tau H^-1" << std::endl;
157  std::vector<int> pms(3);
158  pms[0] = blockFreq;
159  pms[1] = numT;
160  pms[2] = blockSeries + 2;
161  walker_lengths_.push_back(pms);
162  int maxWsize = blockSeries + 2;
163  int pindx = P.addPropertyHistory(maxWsize);
164  p_ids_.push_back(pindx);
165  }
166  }
167  //handle FOUNDH
168  if (FOUNDH)
169  {
170  nobservables_ += 1;
171  }
172  else
173  {
174  app_log() << "Not a valid H element(" << Hindex << ") Valid names are:";
175  for (int jk = 0; jk < h.sizeOfObservables(); jk++)
176  app_log() << " " << h.getObservableName(jk);
177  app_log() << std::endl;
178  APP_ABORT("ForwardWalking::put");
179  }
180  }
181  }
182  tcur = tcur->next;
183  }
184  app_log() << "Total number of observables calculated:" << nobservables_ << std::endl;
185  app_log() << "Total number of values calculated:" << nvalues_ << std::endl;
186  values_.resize(nvalues_);
187  return true;
188 }
189 
190 bool ForwardWalking::get(std::ostream& os) const
191 {
192  os << "ForwardWalking";
193  return true;
194 }
195 
196 std::unique_ptr<OperatorBase> ForwardWalking::makeClone(ParticleSet& qp, TrialWaveFunction& psi)
197 {
198  //nothing to worry, default copy constructor will do
199  return std::make_unique<ForwardWalking>(*this);
200 }
201 
203 {
204  //not used
205 }
206 
208 {
209  my_index_ = plist.size();
210  int nc = 0;
211  for (int i = 0; i < nobservables_; ++i)
212  for (int j = 0; j < walker_lengths_[i][1]; ++j, ++nc)
213  {
214  std::stringstream sstr;
215  sstr << "FWE_" << names_[i] << "_" << j * walker_lengths_[i][0];
216  int id = plist.add(sstr.str());
217  }
218  app_log() << "ForwardWalking::Observables [" << my_index_ << ", " << my_index_ + nc << ")" << std::endl;
219 }
220 
222 {
223  copy(values_.begin(), values_.end(), plist.begin() + my_index_);
224 }
225 
227 {
228  copy(values_.begin(), values_.end(), plist.begin() + my_index_ + offset);
229 }
230 } // namespace qmcplusplus
std::vector< int > p_ids_
std::vector< int > PHindex
Definition: Walker.h:132
std::vector< RealType > values_
std::string getObservableName(int i) const
return the name of the i-th observable
~ForwardWalking() override
destructor
int startIndex() const
retrun the starting index
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::vector< std::vector< FullPrecRealType > > PropertyHistory
Property history vector.
Definition: Walker.h:131
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
bool putSpecial(xmlNodePtr cur, QMCHamiltonian &h, ParticleSet &P)
rename it to avoid conflicts with put
RealType getObservable(int i) const
return the value of the i-th observable
Collection of Local Energy Operators.
std::vector< T >::iterator begin()
iterators to use std algorithms
void setParticlePropertyList(PropertySetType &plist, int offset) override
Vectorized record engine for scalar properties.
std::vector< int > h_ids_
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
PropertySetType PropertyList
name-value map of Walker Properties
Definition: ParticleSet.h:112
bool get(std::ostream &os) const override
write about the class
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
std::vector< std::string > Names
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
int add(const std::string &aname)
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
int addPropertyHistory(int leng)
int sizeOfObservables() const
return the size of observables
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
Return_t calculate(ParticleSet &P)
Declarations of ForwardWalking.
Walker_t * t_walker_
reference to the current walker
Definition: OperatorBase.h:541
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) final
void setObservables(PropertySetType &plist) override
Set the values evaluated by this object to plist Default implementation is to assign Value which is u...
std::vector< std::string > names_
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
bool put(xmlNodePtr cur) override
Read the input parameter.
Class to represent a many-body trial wave function.
Return_t rejectedMove(ParticleSet &P) override
TODO: add docs.
Indexes
an enum denoting index of physical properties
Declaraton of ParticleAttrib<T>
FullPrecRealType * getPropertyBase()
Definition: Walker.h:277
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
void addPropertyHistoryPoint(int index, FullPrecRealType data)
Definition: Walker.h:203
std::bitset< 8 > update_mode_
set the current update mode
Definition: OperatorBase.h:521
Declaration of QMCHamiltonian.
std::vector< std::vector< int > > walker_lengths_
void addObservables(PropertySetType &plist)