QMCPACK
NonLocalTOperator.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 // Ken Esler, kpesler@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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 /**@file NonLocalTOperator.cpp
17  *@brief Definition of NonLocalTOperator
18  */
19 #include "NonLocalTOperator.h"
20 #include "OhmmsData/ParameterSet.h"
21 
22 namespace qmcplusplus
23 {
24 NonLocalTOperator::NonLocalTOperator() : tau_(0.01), alpha_(0.0), gamma_(0.0) {}
25 
26 /** process options related to TMoves
27  * @return Tmove version
28  * Turns out this wants the NodePtr to the entire driver block.
29  */
30 int NonLocalTOperator::put(xmlNodePtr cur)
31 {
32  std::string use_tmove = "no";
33  ParameterSet m_param;
34  m_param.add(tau_, "timeStep");
35  m_param.add(tau_, "timestep");
36  m_param.add(tau_, "Tau");
37  m_param.add(tau_, "tau");
38  m_param.add(alpha_, "alpha");
39  m_param.add(gamma_, "gamma");
40  m_param.add(use_tmove, "nonlocalmove");
41  m_param.add(use_tmove, "nonlocalmoves");
42  bool success = m_param.put(cur);
44  minusFactor = -tau_ * (1.0 - alpha_ * (1.0 + gamma_));
45  int v_tmove = TMOVE_OFF;
46  std::ostringstream o;
47  if (use_tmove == "no")
48  {
49  v_tmove = TMOVE_OFF;
50  o << " Using Locality Approximation";
51  }
52  else if (use_tmove == "yes" || use_tmove == "v0")
53  {
54  v_tmove = TMOVE_V0;
55  o << " Using Non-local T-moves v0, M. Casula, PRB 74, 161102(R) (2006)";
56  }
57  else if (use_tmove == "v1")
58  {
59  v_tmove = TMOVE_V1;
60  o << " Using Non-local T-moves v1, M. Casula et al., JCP 132, 154113 (2010)";
61  }
62  else if (use_tmove == "v3")
63  {
64  v_tmove = TMOVE_V3;
65  o << " Using Non-local T-moves v3, an approximation to v1";
66  }
67  else
68  throw std::runtime_error("NonLocalTOperator::put unknown nonlocalmove option " + use_tmove);
69 
70 #pragma omp master
71  app_log() << o.str() << std::endl;
72 
73  return v_tmove;
74 }
75 
76 int NonLocalTOperator::thingsThatShouldBeInMyConstructor(const std::string& non_local_move_option,
77  const double tau,
78  const double alpha,
79  const double gamma)
80 {
81  tau_ = tau;
82  alpha_ = alpha;
83  gamma_ = gamma;
85  minusFactor = -tau_ * (1.0 - alpha_ * (1.0 + gamma_));
86  int v_tmove = TMOVE_OFF;
87 
88  if (non_local_move_option == "no")
89  v_tmove = TMOVE_OFF;
90  else if (non_local_move_option == "yes" || non_local_move_option == "v0")
91  v_tmove = TMOVE_V0;
92  else if (non_local_move_option == "v1")
93  v_tmove = TMOVE_V1;
94  else if (non_local_move_option == "v3")
95  v_tmove = TMOVE_V3;
96  else
97  throw std::runtime_error("NonLocalTOperator::put unknown nonlocalmove option " + non_local_move_option);
98  return v_tmove;
99 }
100 
101 const NonLocalData* NonLocalTOperator::selectMove(RealType prob, const std::vector<NonLocalData>& txy)
102 {
103  // txy_scan_[0] = 1.0, txy_scan_[i>0] = txy_scan_[i-1] + txy[i-1].Weight (modified)
104  txy_scan_.resize(txy.size());
105  RealType wgt_t = 1.0;
106  for (int i = 0; i < txy.size(); i++)
107  {
108  txy_scan_[i] = wgt_t;
109  if (txy[i].Weight > 0)
110  wgt_t += txy[i].Weight * plusFactor;
111  else
112  wgt_t += txy[i].Weight * minusFactor;
113  }
114 
115  const RealType target = prob * wgt_t;
116  // find ibar which satisify txy_scan_[ibar-1] <= target < txy_scan_[ibar]
117  int ibar = 0;
118  while (ibar < txy_scan_.size() && txy_scan_[ibar] <= target)
119  ibar++;
120 
121  return ibar > 0 ? &(txy[ibar - 1]) : nullptr;
122 }
123 
124 void NonLocalTOperator::groupByElectron(size_t num_elec, const std::vector<NonLocalData>& txy)
125 {
126  txy_by_elec_.resize(num_elec);
127  for (int i = 0; i < num_elec; i++)
128  txy_by_elec_[i].clear();
129 
130  for (int i = 0; i < txy.size(); i++)
131  {
132  assert(txy[i].PID >= 0 && txy[i].PID < num_elec);
133  txy_by_elec_[txy[i].PID].push_back(txy[i]);
134  }
135 }
136 
137 } // namespace qmcplusplus
void groupByElectron(size_t num_elec, const std::vector< NonLocalData > &txy)
sort all the Txy elements by electron
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::ostream & app_log()
Definition: OutputManager.h:65
int thingsThatShouldBeInMyConstructor(const std::string &non_local_move_option, const double tau, const double alpha, const double gamma)
replacement for put because wouldn&#39;t it be cool to know what the classes configuration actually is...
Declaration of NonLocalTOperator.
std::vector< std::vector< NonLocalData > > txy_by_elec_
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
class to handle a set of parameters
Definition: ParameterSet.h:27
NonLocalData::RealType RealType
int put(xmlNodePtr cur)
initialize the parameters
std::vector< RealType > txy_scan_
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
const NonLocalData * selectMove(RealType prob, const std::vector< NonLocalData > &txy)
select the move for a given probability
RealType plusFactor
factor applied on >0 weight
RealType minusFactor
factor applied on <=0 weight