QMCPACK
CostFunctionCrowdData.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "CostFunctionCrowdData.h"
15 
16 namespace qmcplusplus
17 {
19  ParticleSet& P,
20  TrialWaveFunction& Psi,
21  QMCHamiltonian& H,
23  : h0_res_("h0 resource"), e0_(0.0), e2_(0.0), wgt_(0.0), wgt2_(0.0)
24 {
28 
29  log_psi_fixed_.resize(crowd_size);
30  log_psi_opt_.resize(crowd_size);
31 
32  wf_ptr_list_.resize(crowd_size);
33  p_ptr_list_.resize(crowd_size);
34  h_ptr_list_.resize(crowd_size);
35  h0_ptr_list_.resize(crowd_size);
36 
37  rng_ptr_list_.resize(crowd_size);
38 
39  // build a temporary H_KE for later calling makeClone
40  // need makeClone to setup internal my_index_ of a new copy.
41  const auto components = H.getTWFDependentComponents();
42  QMCHamiltonian H_KE("h_free");
43  for (OperatorBase& component : components)
44  H_KE.addOperator(component.makeClone(P, Psi), component.getName());
45  H_KE.createResource(h0_res_);
46 
47  for (int ib = 0; ib < crowd_size; ib++)
48  {
49  p_ptr_list_[ib] = std::make_unique<ParticleSet>(P);
50  auto& pCopy = *p_ptr_list_[ib];
51 
52  wf_ptr_list_[ib] = Psi.makeClone(pCopy);
53  auto& psiCopy = *wf_ptr_list_[ib];
54 
55  h_ptr_list_[ib] = H.makeClone(pCopy, psiCopy);
56  h0_ptr_list_[ib] = H_KE.makeClone(pCopy, psiCopy);
57 
58  rng_ptr_list_[ib] = Rng.makeClone();
59  h_ptr_list_[ib]->setRandomGenerator(rng_ptr_list_[ib].get());
60  h0_ptr_list_[ib]->setRandomGenerator(rng_ptr_list_[ib].get());
61  }
62  rng_save_ptr_ = Rng.makeClone();
63 }
64 
66 {
68 }
69 
71 {
73 }
74 
76 {
78 }
79 
81 {
83 }
84 
86 {
87  std::fill(log_psi_opt_.begin(), log_psi_opt_.end(), 0.0);
88  std::fill(log_psi_fixed_.begin(), log_psi_fixed_.end(), 0.0);
89 }
90 
91 } // namespace qmcplusplus
DriverWalkerResourceCollection driverwalker_resource_collection_
UPtrVector< QMCHamiltonian > h_ptr_list_
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
RefVector< OperatorBase > getTWFDependentComponents()
return components, auxH not included, depending on TWF.
void addOperator(std::unique_ptr< OperatorBase > &&h, const std::string &aname, bool physical=true)
add an operator
Collection of Local Energy Operators.
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
UPtrVector< TrialWaveFunction > wf_ptr_list_
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
std::unique_ptr< TrialWaveFunction > makeClone(ParticleSet &tqp) const
RefVector< QMCHamiltonian > get_h_list(int len)
UPtrVector< RandomBase< FullPrecRealType > > rng_ptr_list_
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
ResourceCollection h0_res_
resource collection corresponding to h0
virtual std::unique_ptr< RandomBase< T > > makeClone() const =0
static RefVector< T > convertUPtrToRefVectorSubset(const UPtrVector< T > &ptr_list, int offset, int len)
RefVector< ParticleSet > get_p_list(int len)
CostFunctionCrowdData(int crowd_size, ParticleSet &P, TrialWaveFunction &Psi, QMCHamiltonian &H, RandomBase< FullPrecRealType > &Rng)
Create the arrays of crowd_size and create object copies.
Declaration of a TrialWaveFunction.
An abstract class for Local Energy operators.
Definition: OperatorBase.h:59
std::vector< std::reference_wrapper< T > > RefVector
Class to represent a many-body trial wave function.
RefVector< QMCHamiltonian > get_h0_list(int len)
RefVector< TrialWaveFunction > get_wf_list(int len)
UPtrVector< QMCHamiltonian > h0_ptr_list_
UPtrVector< ParticleSet > p_ptr_list_
std::unique_ptr< QMCHamiltonian > makeClone(ParticleSet &qp, TrialWaveFunction &psi) const
return a clone
std::vector< Return_rt > log_psi_fixed_
void zero_log_psi()
Set the log_psi_* arrays to zero.
std::unique_ptr< RandomBase< FullPrecRealType > > rng_save_ptr_