QMCPACK
WalkerConfigurations.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: Jordan E. Vincent, University of Illinois at Urbana-Champaign
8 // Bryan Clark, bclark@Princeton.edu, Princeton University
9 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
11 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 // Cynthia Gu, zg1@ornl.gov, Oak Ridge National Laboratory
13 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
14 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
15 //
16 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
17 //////////////////////////////////////////////////////////////////////////////////////
18 
19 
20 #include "WalkerConfigurations.h"
21 #include <map>
23 
24 namespace qmcplusplus
25 {
27 
28 ///default destructor
30 
31 
32 void WalkerConfigurations::createWalkers(int n, size_t numPtcls)
33 {
34  if (walker_list_.empty())
35  {
36  while (n)
37  {
38  walker_list_.push_back(std::make_unique<Walker_t>(numPtcls));
39  --n;
40  }
41  }
42  else
43  {
44  if (walker_list_.size() >= n)
45  {
46  int iw = walker_list_.size(); //copy from the back
47  for (int i = 0; i < n; ++i)
48  {
49  walker_list_.push_back(std::make_unique<Walker_t>(*walker_list_[--iw]));
50  }
51  }
52  else
53  {
54  int nc = n / walker_list_.size();
55  int nw0 = walker_list_.size();
56  for (int iw = 0; iw < nw0; ++iw)
57  {
58  for (int ic = 0; ic < nc; ++ic)
59  walker_list_.push_back(std::make_unique<Walker_t>(*walker_list_[iw]));
60  }
61  n -= nc * nw0;
62  while (n > 0)
63  {
64  walker_list_.push_back(std::make_unique<Walker_t>(*walker_list_[--nw0]));
65  --n;
66  }
67  }
68  }
69 }
70 
71 
72 void WalkerConfigurations::resize(int numWalkers, size_t numPtcls)
73 {
74  int dn = numWalkers - walker_list_.size();
75  if (dn > 0)
76  createWalkers(dn, numPtcls);
77  if (dn < 0)
78  {
79  int nw = -dn;
80  if (nw < walker_list_.size())
81  {
82  walker_list_.erase(walker_list_.begin(), walker_list_.begin() - dn);
83  }
84  }
85 }
86 
87 ///returns the next valid iterator
89 {
90  return walker_list_.erase(first, last);
91 }
92 
94 {
96  while (first != last)
97  {
98  walker_list_.push_back(std::make_unique<Walker_t>(**first));
99  ++first;
100  }
101 }
102 
104 {
105  if (nw > walker_list_.size())
106  {
107  app_warning() << " Cannot remove walkers. Current Walkers = " << walker_list_.size() << std::endl;
108  return;
109  }
110  nw = walker_list_.size() - nw;
111  int iw = nw;
112  walker_list_.erase(walker_list_.begin() + nw, walker_list_.end());
113 }
114 
116 {
117  while (first != last)
118  {
119  (*it++)->makeCopy(**first++);
120  }
121 }
122 
123 /** Make Metropolis move to the walkers and save in a temporary array.
124  * @param it the iterator of the first walker to work on
125  * @param tauinv inverse of the time step
126  *
127  * R + D + X
128  */
130 {
131  for (auto& walker : walker_list_)
132  {
133  walker->Weight = 1.0;
134  walker->Multiplicity = 1.0;
135  }
136 }
137 
139 {
140  for (const auto& walker : walker_list_)
141  {
143  target += get_last_address(walker->R) - get_first_address(walker->R);
144  *weights = walker->Weight;
145  ++weights;
146  }
147 }
148 
149 } // namespace qmcplusplus
std::ostream & app_warning()
Definition: OutputManager.h:69
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Declaration of a WalkerConfigurations.
walker_list__t::iterator iterator
FIX: a type alias of iterator for an object should not be for just one of many objects it holds...
iterator destroyWalkers(iterator first, iterator last)
destroy Walkers from itstart to itend
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
void copyWalkers(iterator first, iterator last, iterator start)
copy walkers
void createWalkers(int numWalkers, size_t numPtcls)
create numWalkers Walkers
T * get_last_address(ParticleAttrib< TinyVector< T, D >> &a)
void resize(int numWalkers, size_t numPtcls)
clean up the walker list and make a new list
typename t_traits::RealType RealType
typedef for real data type
Definition: Walker.h:58
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
void putConfigurations(Walker_t::RealType *target, QMCTraits::FullPrecRealType *weights) const
save the particle positions of all the walkers into target
walker_list__t walker_list_
a collection of walkers
T * get_first_address(ParticleAttrib< TinyVector< T, D >> &a)