QMCPACK
Backflow_ee_kSpace.h
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: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
8 // Jeongnim Kim, jeongnim.kim@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: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #ifndef QMCPLUSPLUS_BACKFLOW_EE_KSPACE_H
17 #define QMCPLUSPLUS_BACKFLOW_EE_KSPACE_H
20 #include "LongRange/StructFact.h"
21 #include "Message/Communicate.h"
22 #include <cmath>
23 
24 namespace qmcplusplus
25 {
27 {
29  ///typedef for real values
30  //using real_type = optimize::VariableSet::real_type;
31  ///typedef for variableset: this is going to be replaced
33 
34 public:
35  //number of groups of the target particleset
36  bool Optimize;
37  int numParams;
38  std::vector<RealType> Fk;
39  std::vector<int> offsetPrms;
40  int NumGroups;
41  int NumKShells; // number of k shells included in bf function
42  int NumKVecs; // number of k vectors included in bf function
43 
45 
47  ///set of variables to be optimized
49 
51  {
52  Optimize = false;
53  numParams = 0;
55  NumGroups = els.groups();
57  for (int i = 0; i < NumTargets; ++i)
58  for (int j = 0; j < NumTargets; ++j)
59  PairID(i, j) = els.GroupID[i] * NumGroups + els.GroupID[j];
60  offsetPrms.resize(NumGroups * NumGroups, 0);
61  }
62 
63  void initialize(ParticleSet& P, std::vector<RealType>& yk)
64  {
65  NumKShells = yk.size();
66  Fk = yk;
67  NumKVecs = P.getSimulationCell().getKLists().kshell[NumKShells + 1];
69  if (Optimize)
71  }
72 
73  void resize(int NT) { NumTargets = NT; }
74 
75  std::unique_ptr<BackflowFunctionBase> makeClone(ParticleSet& tqp) const override
76  {
77  auto clone = std::make_unique<Backflow_ee_kSpace>(CenterSys, tqp);
78  clone->resize(NumTargets);
79  // clone->uniqueRadFun.resize(uniqueRadFun.size());
80  // clone->RadFun.resize(RadFun.size());
81  /*
82  for(int i=0; i<uniqueRadFun.size(); i++)
83  clone->uniqueRadFun[i] = new FT(*(uniqueRadFun[i]));
84  for(int i=0; i<RadFun.size(); i++)
85  {
86  bool done=false;
87  for(int k=0; k<uniqueRadFun.size(); k++)
88  if(RadFun[i] == uniqueRadFun[k]) {
89  done=true;
90  clone->RadFun[i] = clone->uniqueRadFun[k];
91  break;
92  }
93  if(!done) {
94  APP_ABORT("Error cloning Backflow_ee_kSpace object. \n");
95  }
96  }
97  */
98  return clone;
99  }
100 
101  void addFunc(int ia, int ib)
102  {
103  /*
104  uniqueRadFun.push_back(rf);
105  if(first) {
106  // initialize all with rf the first time
107  for(int i=0; i<RadFun.size(); i++)
108  RadFun[i]=rf;
109  first=false;
110  } else {
111  RadFun[ia*NumGroups+ib] = rf;
112  RadFun[ib*NumGroups+ia] = rf;
113  }
114  */
115  }
116 
117  void registerData(WFBufferType& buf) override
118  {
119  /*
120  FirstOfU = &(UIJ(0,0)[0]);
121  LastOfU = FirstOfU + OHMMS_DIM*NumTargets*NumTargets;
122  FirstOfA = &(AIJ(0,0)[0]);
123  LastOfA = FirstOfA + OHMMS_DIM*OHMMS_DIM*NumTargets*NumTargets;
124  FirstOfB = &(BIJ(0,0)[0]);
125  LastOfB = FirstOfB + OHMMS_DIM*NumTargets*NumTargets;
126  buf.add(FirstOfU,LastOfU);
127  buf.add(FirstOfA,LastOfA);
128  buf.add(FirstOfB,LastOfB);
129  */
130  }
131 
132  void reportStatus(std::ostream& os) override { myVars.print(os); }
133 
134  void resetParameters(const opt_variables_type& active) override
135  {
136  if (Optimize)
137  {
138  for (int i = 0; i < Fk.size(); ++i)
139  {
140  int loc = myVars.where(i);
141  if (loc >= 0)
142  {
143  myVars[i] = active[loc];
144  Fk[i] = std::real(myVars[i]);
145  //Fk[i] = myVars[i] = active[loc];
146  }
147  }
148  }
149  }
150 
151  void checkInVariables(opt_variables_type& active) override
152  {
153  if (Optimize)
154  active.insertFrom(myVars);
155  }
156 
157  void checkOutVariables(const opt_variables_type& active) override
158  {
159  if (Optimize)
160  myVars.getIndex(active);
161  }
162 
163  inline bool isOptimizable() override { return Optimize; }
164 
165  inline int indexOffset() override
166  {
167  if (Optimize)
168  return myVars.where(0);
169  else
170  return 0;
171  }
172 
173  inline void acceptMove(int iat, int UpdateMode) override
174  {
175  int num;
176  switch (UpdateMode)
177  {
178  case ORB_PBYP_RATIO:
179  num = UIJ.rows();
180  for (int i = 0; i < num; i++)
181  {
182  // UIJ(iat,i) = UIJ_temp(i);
183  // UIJ(i,iat) = -1.0*UIJ_temp(i);
184  }
185  break;
186  case ORB_PBYP_PARTIAL:
187  num = UIJ.rows();
188  for (int i = 0; i < num; i++)
189  {
190  // UIJ(iat,i) = UIJ_temp(i);
191  // UIJ(i,iat) = -1.0*UIJ_temp(i);
192  }
193  num = AIJ.rows();
194  for (int i = 0; i < num; i++)
195  {
196  // AIJ(iat,i) = AIJ_temp(i);
197  // AIJ(i,iat) = AIJ_temp(i);
198  }
199  break;
200  case ORB_PBYP_ALL:
201  num = UIJ.rows();
202  for (int i = 0; i < num; i++)
203  {
204  // UIJ(iat,i) = UIJ_temp(i);
205  // UIJ(i,iat) = -1.0*UIJ_temp(i);
206  }
207  num = AIJ.rows();
208  for (int i = 0; i < num; i++)
209  {
210  // AIJ(iat,i) = AIJ_temp(i);
211  // AIJ(i,iat) = AIJ_temp(i);
212  }
213  num = BIJ.rows();
214  for (int i = 0; i < num; i++)
215  {
216  // BIJ(iat,i) = BIJ_temp(i);
217  // BIJ(i,iat) = -1.0*BIJ_temp(i);
218  }
219  break;
220  default:
221  num = UIJ.rows();
222  for (int i = 0; i < num; i++)
223  {
224  // UIJ(iat,i) = UIJ_temp(i);
225  // UIJ(i,iat) = -1.0*UIJ_temp(i);
226  }
227  num = AIJ.rows();
228  for (int i = 0; i < num; i++)
229  {
230  // AIJ(iat,i) = AIJ_temp(i);
231  // AIJ(i,iat) = AIJ_temp(i);
232  }
233  num = BIJ.rows();
234  for (int i = 0; i < num; i++)
235  {
236  // BIJ(iat,i) = BIJ_temp(i);
237  // BIJ(i,iat) = -1.0*BIJ_temp(i);
238  }
239  break;
240  }
241  // UIJ_temp=0.0;
242  // AIJ_temp=0.0;
243  // BIJ_temp=0.0;
244  }
245 
246  inline void restore(int iat, int UpdateType) override
247  {
248  // UIJ_temp=0.0;
249  // AIJ_temp=0.0;
250  // BIJ_temp=0.0;
251  }
252 
253  /** calculate quasi-particle coordinates only
254  */
255  inline void evaluate(const ParticleSet& P, ParticleSet& QP) override
256  {
257  throw std::runtime_error("Backflow_ee_kSpace::evaluate not implemented. There was an implementation with"
258  " complex-valued storage that may be resurrected using real-valued storage.");
259  }
260 
261  inline void evaluate(const ParticleSet& P, ParticleSet& QP, GradVector& Bmat, HessMatrix& Amat)
262  {
263  APP_ABORT("This shouldn't be called: Backflow_ee_kSpace::evaluate(Bmat)");
264  }
265 
266 
267  /** calculate quasi-particle coordinates, Bmat and Amat
268  */
269  inline void evaluate(const ParticleSet& P, ParticleSet& QP, GradMatrix& Bmat_full, HessMatrix& Amat) override
270  {
271  throw std::runtime_error("Backflow_ee_kSpace::evaluate not implemented. There was an implementation with"
272  " complex-valued storage that may be resurrected using real-valued storage.");
273  }
274 
275  /** calculate quasi-particle coordinates after pbyp move
276  */
277  inline void evaluatePbyP(const ParticleSet& P,
279  const std::vector<int>& index) override
280  {}
281 
282  /** calculate quasi-particle coordinates after pbyp move
283  */
284  inline void evaluatePbyP(const ParticleSet& P, int iat, ParticleSet::ParticlePos& newQP) override {}
285 
286  /** calculate quasi-particle coordinates and Amat after pbyp move
287  */
288  inline void evaluatePbyP(const ParticleSet& P,
290  const std::vector<int>& index,
291  HessMatrix& Amat) override
292  {}
293 
294  /** calculate quasi-particle coordinates and Amat after pbyp move
295  */
296  inline void evaluatePbyP(const ParticleSet& P, int iat, ParticleSet::ParticlePos& newQP, HessMatrix& Amat) override {}
297 
298  /** calculate quasi-particle coordinates and Amat after pbyp move
299  */
300  inline void evaluatePbyP(const ParticleSet& P,
302  const std::vector<int>& index,
303  GradMatrix& Bmat,
304  HessMatrix& Amat) override
305  {}
306 
307  /** calculate quasi-particle coordinates and Amat after pbyp move
308  */
309  inline void evaluatePbyP(const ParticleSet& P,
310  int iat,
312  GradMatrix& Bmat,
313  HessMatrix& Amat) override
314  {}
315 
316  /** calculate only Bmat
317  * This is used in pbyp moves, in updateBuffer()
318  */
319  inline void evaluateBmatOnly(const ParticleSet& P, GradMatrix& Bmat_full) override {}
320 
321  /** calculate quasi-particle coordinates, Bmat and Amat
322  * calculate derivatives wrt to variational parameters
323  */
324  inline void evaluateWithDerivatives(const ParticleSet& P,
325  ParticleSet& QP,
326  GradMatrix& Bmat_full,
327  HessMatrix& Amat,
328  GradMatrix& Cmat,
329  GradMatrix& Ymat,
330  HessArray& Xmat) override
331  {}
332 };
333 
334 } // namespace qmcplusplus
335 
336 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
void restore(int iat, int UpdateType) override
int NumTargets
number of quantum particles
void evaluate(const ParticleSet &P, ParticleSet &QP, GradMatrix &Bmat_full, HessMatrix &Amat) override
calculate quasi-particle coordinates, Bmat and Amat
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void checkOutVariables(const opt_variables_type &active) override
Base class for backflow transformations.
QMCTraits::ComplexType ComplexType
QTBase::ComplexType ComplexType
Definition: Configuration.h:59
void evaluatePbyP(const ParticleSet &P, int iat, ParticleSet::ParticlePos &newQP, GradMatrix &Bmat, HessMatrix &Amat) override
calculate quasi-particle coordinates and Amat after pbyp move
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
Attaches a unit to a Vector for IO.
Backflow_ee_kSpace(ParticleSet &ions, ParticleSet &els)
void evaluatePbyP(const ParticleSet &P, ParticleSet::ParticlePos &newQP, const std::vector< int > &index, HessMatrix &Amat) override
calculate quasi-particle coordinates and Amat after pbyp move
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
int groups() const
return the number of groups
Definition: ParticleSet.h:511
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
void evaluateWithDerivatives(const ParticleSet &P, ParticleSet &QP, GradMatrix &Bmat_full, HessMatrix &Amat, GradMatrix &Cmat, GradMatrix &Ymat, HessArray &Xmat) override
calculate quasi-particle coordinates, Bmat and Amat calculate derivatives wrt to variational paramete...
void evaluatePbyP(const ParticleSet &P, int iat, ParticleSet::ParticlePos &newQP) override
calculate quasi-particle coordinates after pbyp move
void evaluate(const ParticleSet &P, ParticleSet &QP) override
calculate quasi-particle coordinates only
void evaluatePbyP(const ParticleSet &P, ParticleSet::ParticlePos &newQP, const std::vector< int > &index, GradMatrix &Bmat, HessMatrix &Amat) override
calculate quasi-particle coordinates and Amat after pbyp move
void evaluatePbyP(const ParticleSet &P, int iat, ParticleSet::ParticlePos &newQP, HessMatrix &Amat) override
calculate quasi-particle coordinates and Amat after pbyp move
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
void checkInVariables(opt_variables_type &active) override
void evaluateBmatOnly(const ParticleSet &P, GradMatrix &Bmat_full) override
calculate only Bmat This is used in pbyp moves, in updateBuffer()
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void acceptMove(int iat, int UpdateMode) override
size_type rows() const
Definition: OhmmsMatrix.h:77
void evaluate(const ParticleSet &P, ParticleSet &QP, GradVector &Bmat, HessMatrix &Amat)
ParticleSet & CenterSys
Reference to the center.
opt_variables_type myVars
set of variables to be optimized
void registerData(WFBufferType &buf) override
void insertFrom(const VariableSet &input)
insert a VariableSet to the list
Definition: VariableSet.cpp:37
void reportStatus(std::ostream &os) override
void evaluatePbyP(const ParticleSet &P, ParticleSet::ParticlePos &newQP, const std::vector< int > &index) override
calculate quasi-particle coordinates after pbyp move
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter
void initialize(ParticleSet &P, std::vector< RealType > &yk)
void resetParameters(const opt_variables_type &active) override
std::unique_ptr< BackflowFunctionBase > makeClone(ParticleSet &tqp) const override