QMCPACK
J1OrbitalSoA.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) 2021 QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 // Shiv Upadhyay, shivnupadhyay@gmail.com, University of Pittsburgh
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
13 //////////////////////////////////////////////////////////////////////////////////////
14 // -*- C++ -*-
15 #ifndef QMCPLUSPLUS_ONEBODYJASTROW_OPTIMIZED_SOA_H
16 #define QMCPLUSPLUS_ONEBODYJASTROW_OPTIMIZED_SOA_H
17 
18 #include <map>
19 #include <numeric>
20 #include "Configuration.h"
21 #include <ResourceHandle.h>
22 #include "Particle/DistanceTable.h"
25 #include "Utilities/qmc_common.h"
28 #include "CPU/SIMD/algorithm.hpp"
29 
30 #include "BsplineFunctor.h"
31 #include "SplineFunctors.h"
32 #include "UserFunctor.h"
33 #include "ShortRangeCuspFunctor.h"
34 #include "PadeFunctors.h"
35 
36 namespace qmcplusplus
37 {
38 
39 template<typename T>
40 struct J1OrbitalSoAMultiWalkerMem;
41 
42 /** @ingroup WaveFunctionComponent
43  * @brief Specialization for one-body Jastrow function using multiple functors
44  */
45 template<class FT>
47 {
48  ///alias FuncType
49  using FuncType = FT;
50  ///type of each component U, dU, d2U;
51  using valT = typename FT::real_type;
52  ///element position type
54  ///use the same container
57 
60 
61  /// if true use offload
62  const bool use_offload_;
63 
64  ///table index
65  const int myTableID;
66  ///number of ions
67  const int Nions;
68  ///number of electrons
69  const int Nelec;
70  /// number of ion groups
71  const int NumGroups;
72  ///reference to the sources (ions)
73  const ParticleSet& Ions;
74  /// the group_id of each particle
76 
77  ///variables handled by this orbital
79 
83 
84  ///\f$Vat[i] = sum_(j) u_{i,j}\f$
91  ///Container for \f$F[ig*NIons+jg]\f$
92  std::vector<FT*> J1Functors;
93  /** functor for each ion group
94  * Conceptually, this is different from unique functions.
95  * In a spin polarized system, two species may share the same J1 functor.
96  * FIXME However this is not supported right now. Each species needs its dedicated function.
97  */
98  std::vector<FT*> GroupFunctors;
99 
100  std::vector<std::pair<int, int>> OffSet;
102  std::vector<GradDerivVec> gradLogPsi;
103  std::vector<ValueDerivVec> lapLogPsi;
104 
106 
108  {
112  }
113 
114  /// compute G and L from internally stored data
116  {
117  for (size_t iat = 0; iat < Nelec; ++iat)
118  {
119  G[iat] += Grad[iat];
120  L[iat] -= Lap[iat];
121  }
123  }
124 
125  inline LogValue evaluateGL(const ParticleSet& P,
128  bool fromscratch = false) override
129  {
130  return log_value_ = computeGL(G, L);
131  }
132 
133  /** compute gradient and lap
134  * @return lap
135  */
136  inline valT accumulateGL(const valT* restrict du, const valT* restrict d2u, const DisplRow& displ, posT& grad) const
137  {
138  valT lap(0);
139  constexpr valT lapfac = OHMMS_DIM - RealType(1);
140  //#pragma omp simd reduction(+:lap)
141  for (int jat = 0; jat < Nions; ++jat)
142  lap += d2u[jat] + lapfac * du[jat];
143  for (int idim = 0; idim < OHMMS_DIM; ++idim)
144  {
145  const valT* restrict dX = displ.data(idim);
146  valT s = valT();
147  //#pragma omp simd reduction(+:s)
148  for (int jat = 0; jat < Nions; ++jat)
149  s += du[jat] * dX[jat];
150  grad[idim] = s;
151  }
152  return lap;
153  }
154 
155  inline valT computeU(const DistRow& dist)
156  {
157  valT curVat(0);
158  for (int jg = 0; jg < NumGroups; ++jg)
159  {
160  if (J1UniqueFunctors[jg] != nullptr)
161  curVat +=
162  J1UniqueFunctors[jg]->evaluateV(-1, Ions.first(jg), Ions.last(jg), dist.data(), DistCompressed.data());
163  }
164  return curVat;
165  }
166 
167  /** compute U, dU and d2U
168  * @param P quantum particleset
169  * @param iat the moving particle
170  * @param dist starting address of the distances of the ions wrt the iat-th particle
171  */
172  inline void computeU3(const ParticleSet& P, int iat, const DistRow& dist)
173  {
174  constexpr valT czero(0);
175  std::fill_n(U.data(), Nions, czero);
176  std::fill_n(dU.data(), Nions, czero);
177  std::fill_n(d2U.data(), Nions, czero);
178 
179  for (int jg = 0; jg < NumGroups; ++jg)
180  {
181  if (J1UniqueFunctors[jg] == nullptr)
182  continue;
183  J1UniqueFunctors[jg]->evaluateVGL(-1, Ions.first(jg), Ions.last(jg), dist.data(), U.data(), dU.data(), d2U.data(),
184  DistCompressed.data(), DistIndice.data());
185  }
186  }
187 
188 protected:
189  ///container for the unique Jastrow functions
190  std::vector<std::unique_ptr<FT>> J1UniqueFunctors;
191 
192 public:
193  J1OrbitalSoA(const std::string& obj_name, const ParticleSet& ions, ParticleSet& els, bool use_offload);
194 
195  J1OrbitalSoA(const J1OrbitalSoA& rhs) = delete;
196 
197  ~J1OrbitalSoA();
198 
199  std::string getClassName() const override { return "J1OrbitalSoA"; }
200 
201  /* initialize storage */
202  void initialize(const ParticleSet& els)
203  {
204  J1Functors.resize(Nions, nullptr);
205  GroupFunctors.resize(NumGroups, nullptr);
207  Vat.resize(Nelec);
208  Grad.resize(Nelec);
209  Lap.resize(Nelec);
210 
211  U.resize(Nions);
212  dU.resize(Nions);
213  d2U.resize(Nions);
214  d3U.resize(Nions);
215  DistCompressed.resize(Nions);
216  DistIndice.resize(Nions);
217  }
218 
219  void addFunc(int source_type, std::unique_ptr<FT> afunc, int target_type = -1)
220  {
221  for (int i = 0; i < J1Functors.size(); i++)
222  if (Ions.getGroupID(i) == source_type)
223  J1Functors[i] = afunc.get();
224  GroupFunctors[source_type] = afunc.get();
225  J1UniqueFunctors[source_type] = std::move(afunc);
226  }
227 
228  void checkSanity() const override;
229 
230  const auto& getFunctors() const { return J1Functors; }
231 
232  void createResource(ResourceCollection& collection) const override;
233 
234  void acquireResource(ResourceCollection& collection,
235  const RefVectorWithLeader<WaveFunctionComponent>& wfc_list) const override;
236 
237  void releaseResource(ResourceCollection& collection,
238  const RefVectorWithLeader<WaveFunctionComponent>& wfc_list) const override;
239 
240  void recompute(const ParticleSet& P) override
241  {
242  const auto& d_ie(P.getDistTableAB(myTableID));
243  for (int iat = 0; iat < Nelec; ++iat)
244  {
245  computeU3(P, iat, d_ie.getDistRow(iat));
246  Vat[iat] = simd::accumulate_n(U.data(), Nions, valT());
247  Lap[iat] = accumulateGL(dU.data(), d2U.data(), d_ie.getDisplRow(iat), Grad[iat]);
248  }
249  }
250 
253  ParticleSet::ParticleLaplacian& L) override
254  {
255  recompute(P);
256  return log_value_ = computeGL(G, L);
257  }
258 
259  void evaluateHessian(ParticleSet& P, HessVector& grad_grad_psi) override
260  {
261  const auto& d_ie(P.getDistTableAB(myTableID));
262  valT dudr, d2udr2;
263 
264  Tensor<valT, DIM> ident;
265  grad_grad_psi = 0.0;
266  ident.diagonal(1.0);
267 
268  for (int iel = 0; iel < Nelec; ++iel)
269  {
270  const auto& dist = d_ie.getDistRow(iel);
271  const auto& displ = d_ie.getDisplRow(iel);
272  for (int iat = 0; iat < Nions; iat++)
273  {
274  int gid = Ions.getGroupID(iat);
275  auto* func = J1UniqueFunctors[gid].get();
276  if (func != nullptr)
277  {
278  RealType r = dist[iat];
279  RealType rinv = 1.0 / r;
280  PosType dr = displ[iat];
281  func->evaluate(r, dudr, d2udr2);
282  grad_grad_psi[iel] -= rinv * rinv * outerProduct(dr, dr) * (d2udr2 - dudr * rinv) + ident * dudr * rinv;
283  }
284  }
285  }
286  }
287 
288  PsiValue ratio(ParticleSet& P, int iat) override
289  {
292  return std::exp(static_cast<PsiValue>(Vat[iat] - curAt));
293  }
294 
295  inline void evaluateRatios(const VirtualParticleSet& VP, std::vector<ValueType>& ratios) override
296  {
297  for (int k = 0; k < ratios.size(); ++k)
298  ratios[k] = std::exp(Vat[VP.refPtcl] - computeU(VP.getDistTableAB(myTableID).getDistRow(k)));
299  }
300 
303  std::vector<std::vector<ValueType>>& ratios) const override;
304 
306  const opt_variables_type& active,
307  Vector<ValueType>& dlogpsi,
308  Vector<ValueType>& dhpsioverpsi) override
309  {
310  evaluateDerivativesWF(P, active, dlogpsi);
311  bool recalculate(false);
312  std::vector<bool> rcsingles(myVars.size(), false);
313  for (int k = 0; k < myVars.size(); ++k)
314  {
315  int kk = myVars.where(k);
316  if (kk < 0)
317  continue;
318  if (active.recompute(kk))
319  recalculate = true;
320  rcsingles[k] = true;
321  }
322  if (recalculate)
323  {
324  for (int k = 0; k < myVars.size(); ++k)
325  {
326  int kk = myVars.where(k);
327  if (kk < 0)
328  continue;
329  if (rcsingles[k])
330  {
331  dhpsioverpsi[kk] = -RealType(0.5) * ValueType(Sum(lapLogPsi[k])) - ValueType(Dot(P.G, gradLogPsi[k]));
332  }
333  }
334  }
335  }
336 
337  void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& active, Vector<ValueType>& dlogpsi) override
338  {
340  bool recalculate(false);
341  std::vector<bool> rcsingles(myVars.size(), false);
342  for (int k = 0; k < myVars.size(); ++k)
343  {
344  int kk = myVars.where(k);
345  if (kk < 0)
346  continue;
347  if (active.recompute(kk))
348  recalculate = true;
349  rcsingles[k] = true;
350  }
351  if (recalculate)
352  {
353  const size_t NumVars = myVars.size();
354  for (int p = 0; p < NumVars; ++p)
355  {
356  gradLogPsi[p] = 0.0;
357  lapLogPsi[p] = 0.0;
358  }
359  dLogPsi = 0.0;
360 
361  const auto& d_table = P.getDistTableAB(myTableID);
362  std::vector<TinyVector<RealType, 3>> derivs(NumVars);
363 
364  constexpr RealType cone(1);
365  constexpr RealType lapfac(OHMMS_DIM - cone);
366  const size_t ns = d_table.sources();
367  const size_t nt = P.getTotalNum();
368 
369  aligned_vector<int> iadj(nt);
370  aligned_vector<RealType> dist(nt);
371  std::vector<PosType> displ(nt);
372 
373  for (size_t i = 0; i < ns; ++i)
374  {
375  FT* func = J1Functors[i];
376  if (func == nullptr)
377  continue;
378  int first(OffSet[i].first);
379  int last(OffSet[i].second);
380  bool recalcFunc(false);
381  for (int rcs = first; rcs < last; rcs++)
382  if (rcsingles[rcs] == true)
383  recalcFunc = true;
384  if (recalcFunc)
385  {
386  for (size_t j = 0; j < nt; ++j)
387  {
388  std::fill(derivs.begin(), derivs.end(), 0);
389  auto dist = P.getDistTableAB(myTableID).getDistRow(j)[i];
390  if (!func->evaluateDerivatives(dist, derivs))
391  continue;
392  RealType rinv(cone / dist);
393  const PosType& dr = P.getDistTableAB(myTableID).getDisplRow(j)[i];
394  for (int p = first, ip = 0; p < last; ++p, ++ip)
395  {
396  dLogPsi[p] -= derivs[ip][0];
397  RealType dudr(rinv * derivs[ip][1]);
398  gradLogPsi[p][j] += dudr * dr;
399  lapLogPsi[p][j] -= derivs[ip][2] + lapfac * dudr;
400  }
401  }
402  }
403  }
404  for (int k = 0; k < myVars.size(); ++k)
405  {
406  int kk = myVars.where(k);
407  if (kk < 0)
408  continue;
409  if (rcsingles[k])
410  {
411  dlogpsi[kk] = ValueType(dLogPsi[k]);
412  }
413  }
414  }
415  }
416 
417  void evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios) override
418  {
419  const auto& dist = P.getDistTableAB(myTableID).getTempDists();
420  curAt = valT(0);
421  for (int jg = 0; jg < NumGroups; ++jg)
422  {
423  if (J1UniqueFunctors[jg] != nullptr)
424  curAt += J1UniqueFunctors[jg]->evaluateV(-1, Ions.first(jg), Ions.last(jg), dist.data(), DistCompressed.data());
425  }
426 
427  for (int i = 0; i < Nelec; ++i)
428  ratios[i] = std::exp(Vat[i] - curAt);
429  }
430 
431  /** compute the gradient during particle-by-particle update
432  * @param P quantum particleset
433  * @param iat particle index
434  */
435  GradType evalGrad(ParticleSet& P, int iat) override { return GradType(Grad[iat]); }
436 
437  /** compute the gradient during particle-by-particle update
438  * @param P quantum particleset
439  * @param iat particle index
440  *
441  * Using getTempDists(). curAt, curGrad and curLap are computed.
442  */
443  PsiValue ratioGrad(ParticleSet& P, int iat, GradType& grad_iat) override
444  {
446 
449  curAt = simd::accumulate_n(U.data(), Nions, valT());
450  grad_iat += curGrad;
451  return std::exp(static_cast<PsiValue>(Vat[iat] - curAt));
452  }
453 
454  /** Rejected move. Nothing to do */
455  inline void restore(int iat) override {}
456 
457  /** Accpted move. Update Vat[iat],Grad[iat] and Lap[iat] */
458  void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override
459  {
460  if (UpdateMode == ORB_PBYP_RATIO)
461  {
464  }
465 
466  log_value_ += Vat[iat] - curAt;
467  Vat[iat] = curAt;
468  Grad[iat] = curGrad;
469  Lap[iat] = curLap;
470  }
471 
472 
473  inline void registerData(ParticleSet& P, WFBufferType& buf) override
474  {
475  if (Bytes_in_WFBuffer == 0)
476  {
477  Bytes_in_WFBuffer = buf.current();
478  buf.add(Vat.begin(), Vat.end());
479  buf.add(Grad.begin(), Grad.end());
480  buf.add(Lap.begin(), Lap.end());
482  // free local space
483  Vat.free();
484  Grad.free();
485  Lap.free();
486  }
487  else
488  {
490  }
491  }
492 
493  inline LogValue updateBuffer(ParticleSet& P, WFBufferType& buf, bool fromscratch = false) override
494  {
495  log_value_ = computeGL(P.G, P.L);
497  return log_value_;
498  }
499 
500  inline void copyFromBuffer(ParticleSet& P, WFBufferType& buf) override
501  {
503  Grad.attachReference(buf.lendReference<posT>(Nelec), Nelec);
505  }
506 
507  std::unique_ptr<WaveFunctionComponent> makeClone(ParticleSet& tqp) const override
508  {
509  auto j1copy = std::make_unique<J1OrbitalSoA<FT>>(my_name_, Ions, tqp, use_offload_);
510  for (size_t i = 0, n = J1UniqueFunctors.size(); i < n; ++i)
511  {
512  if (J1UniqueFunctors[i] != nullptr)
513  {
514  auto fc = std::make_unique<FT>(*J1UniqueFunctors[i].get());
515  j1copy->addFunc(i, std::move(fc));
516  }
517  }
518  j1copy->myVars = myVars;
519  j1copy->OffSet = OffSet;
520  return j1copy;
521  }
522 
523  /**@{ WaveFunctionComponent virtual functions that are not essential for the development */
524  bool isOptimizable() const override { return true; }
525 
526  void extractOptimizableObjectRefs(UniqueOptObjRefs& opt_obj_refs) override
527  {
528  for (auto& functor : J1UniqueFunctors)
529  if (functor)
530  opt_obj_refs.push_back(*functor);
531  }
532 
533  void checkOutVariables(const opt_variables_type& active) override
534  {
535  myVars.clear();
536  for (int i = 0; i < J1UniqueFunctors.size(); ++i)
537  {
538  if (J1UniqueFunctors[i])
539  {
540  J1UniqueFunctors[i]->myVars.getIndex(active);
542  }
543  }
544  myVars.getIndex(active);
545  const size_t NumVars = myVars.size();
546  if (NumVars)
547  {
548  OffSet.resize(J1Functors.size());
549  int varoffset = myVars.Index[0];
550  for (int i = 0; i < J1Functors.size(); ++i)
551  {
552  if (J1Functors[i] != nullptr)
553  {
554  OffSet[i].first = J1Functors[i]->myVars.Index.front() - varoffset;
555  OffSet[i].second = J1Functors[i]->myVars.Index.size() + OffSet[i].first;
556  }
557  }
558  }
559  for (size_t i = 0, n = J1UniqueFunctors.size(); i < n; ++i)
560  if (J1UniqueFunctors[i] != nullptr)
561  J1UniqueFunctors[i]->checkOutVariables(active);
562  }
563 
564  /**@} */
565 
567  const opt_variables_type& optvars,
568  std::vector<ValueType>& ratios,
569  Matrix<ValueType>& dratios) override
570  {
571  evaluateRatios(VP, ratios);
572  bool recalculate(false);
573  std::vector<bool> rcsingles(myVars.size(), false);
574  for (int k = 0; k < myVars.size(); ++k)
575  {
576  const int kk = myVars.where(k);
577  if (kk < 0)
578  continue;
579  if (optvars.recompute(kk))
580  recalculate = true;
581  rcsingles[k] = true;
582  }
583 
584  if (recalculate)
585  {
586  const size_t NumVars = myVars.size();
587  const auto& d_table = VP.getDistTableAB(myTableID);
588  std::vector<RealType> derivs_ref(NumVars);
589  std::vector<RealType> derivs(NumVars);
590 
591  const size_t ns = d_table.sources();
592  const size_t nt = VP.getTotalNum();
593 
594  const auto& dist_ref = VP.getRefPS().getDistTableAB(myTableID).getDistRow(VP.refPtcl);
595 
596  for (size_t i = 0; i < ns; ++i)
597  {
598  FT* func = J1Functors[i];
599  if (func == nullptr)
600  continue;
601  int first(OffSet[i].first);
602  int last(OffSet[i].second);
603  bool recalcFunc(false);
604  for (int rcs = first; rcs < last; rcs++)
605  if (rcsingles[rcs] == true)
606  recalcFunc = true;
607  if (recalcFunc)
608  {
609  //first calculate the old derivatives VP.refPctl.
610  std::fill(derivs_ref.begin(), derivs_ref.end(), 0);
611  func->evaluateDerivatives(dist_ref[i], derivs_ref);
612  for (size_t j = 0; j < nt; ++j)
613  {
614  std::fill(derivs.begin(), derivs.end(), 0);
615  //first calculate the new derivatives
616  func->evaluateDerivatives(VP.getDistTableAB(myTableID).getDistRow(j)[i], derivs);
617  //compute the new derivatives - old derivatives
618  for (int ip = 0, p = func->myVars.Index.front(); ip < func->myVars.Index.size(); ++ip, ++p)
619  dratios[j][p] += derivs_ref[ip] - derivs[ip];
620  }
621  }
622  }
623  }
624  }
625 
626  inline GradType evalGradSource(ParticleSet& P, ParticleSet& source, int isrc) override
627  {
628  GradType g_return(0.0);
629  const auto& d_ie(P.getDistTableAB(myTableID));
630  for (int iat = 0; iat < Nelec; ++iat)
631  {
632  const auto& dist = d_ie.getDistRow(iat);
633  const auto& displ = d_ie.getDisplRow(iat);
634  int gid = source.getGroupID(isrc);
635  RealType r = dist[isrc];
636  RealType rinv = 1.0 / r;
637  PosType dr = displ[isrc];
638 
639  if (J1UniqueFunctors[gid] != nullptr)
640  {
641  U[isrc] = J1UniqueFunctors[gid]->evaluate(dist[isrc], dU[isrc], d2U[isrc], d3U[isrc]);
642  g_return -= dU[isrc] * rinv * dr;
643  }
644  }
645  return g_return;
646  }
647 
649  ParticleSet& source,
650  int isrc,
653  {
654  GradType g_return(0.0);
655  const auto& d_ie(P.getDistTableAB(myTableID));
656  for (int iat = 0; iat < Nelec; ++iat)
657  {
658  const auto& dist = d_ie.getDistRow(iat);
659  const auto& displ = d_ie.getDisplRow(iat);
660  int gid = source.getGroupID(isrc);
661  RealType r = dist[isrc];
662  RealType rinv = 1.0 / r;
663  PosType dr = displ[isrc];
664 
665  if (J1UniqueFunctors[gid] != nullptr)
666  {
667  U[isrc] = J1UniqueFunctors[gid]->evaluate(dist[isrc], dU[isrc], d2U[isrc], d3U[isrc]);
668  }
669  else
670  {
671  APP_ABORT("J1OrbitalSoa::evaluateGradSource: J1UniqueFunctors[gid]==nullptr")
672  }
673 
674  g_return -= dU[isrc] * rinv * dr;
675 
676  //The following terms depend only on the radial component r. Thus,
677  //we compute them and mix with position vectors to acquire the full
678  //cartesian vector objects.
679  valT grad_component = (d2U[isrc] - dU[isrc] * rinv);
680  valT lapl_component = d3U[isrc] + 2 * rinv * grad_component;
681 
682  for (int idim = 0; idim < OHMMS_DIM; idim++)
683  {
684  grad_grad[idim][iat] += dr[idim] * dr * rinv * rinv * grad_component;
685  grad_grad[idim][iat][idim] += rinv * dU[isrc];
686 
687  lapl_grad[idim][iat] -= lapl_component * rinv * dr[idim];
688  }
689  }
690  return g_return;
691  }
692 };
693 
694 extern template class J1OrbitalSoA<BsplineFunctor<QMCTraits::RealType>>;
695 extern template class J1OrbitalSoA<
696  CubicSplineSingle<QMCTraits::RealType, CubicBspline<QMCTraits::RealType, LINEAR_1DGRID, FIRSTDERIV_CONSTRAINTS>>>;
697 extern template class J1OrbitalSoA<UserFunctor<QMCTraits::RealType>>;
698 extern template class J1OrbitalSoA<ShortRangeCuspFunctor<QMCTraits::RealType>>;
699 extern template class J1OrbitalSoA<PadeFunctor<QMCTraits::RealType>>;
700 extern template class J1OrbitalSoA<Pade2ndOrderFunctor<QMCTraits::RealType>>;
701 } // namespace qmcplusplus
702 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
void checkSanity() const override
Validate the internal consistency of the object.
GradType evalGrad(ParticleSet &P, int iat) override
compute the gradient during particle-by-particle update
Definition: J1OrbitalSoA.h:435
T2 accumulate_n(const T1 *restrict in, size_t n, T2 res)
Definition: algorithm.hpp:26
T Sum(const ParticleAttrib< T > &pa)
LogValue evaluateGL(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L, bool fromscratch=false) override
compute gradients and laplacian of the TWF with respect to each particle.
Definition: J1OrbitalSoA.h:125
bool recompute(int i) const
Definition: VariableSet.h:206
std::vector< T, aligned_allocator< T > > aligned_vector
const std::string my_name_
Name of the object It is required to be different for objects of the same derived type like multiple ...
const ParticleSet & getRefPS() const
ParticleSet this object refers to.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Definition: J1OrbitalSoA.h:473
QTBase::GradType GradType
Definition: Configuration.h:62
const DisplRow & getDisplRow(int iel) const
return a row of displacements for a given target particle
const int NumGroups
number of ion groups
Definition: J1OrbitalSoA.h:71
QTBase::RealType RealType
Definition: Configuration.h:58
const DistRow & getDistRow(int iel) const
return a row of distances for a given target particle
std::vector< FT * > GroupFunctors
functor for each ion group Conceptually, this is different from unique functions. ...
Definition: J1OrbitalSoA.h:98
void forward(size_type n)
Definition: PooledMemory.h:162
size_t getTotalNum() const
Definition: ParticleSet.h:493
void fill_n(T *x, size_t count, const T &value)
Definition: OMPstd.hpp:21
std::vector< std::unique_ptr< FT > > J1UniqueFunctors
container for the unique Jastrow functions
Definition: J1OrbitalSoA.h:190
ResourceHandle manages the temporary resource referenced from a collection.
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
Functor designed to encode short-ranged structure near a nuclear cusp.
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
std::vector< std::pair< int, int > > OffSet
Definition: J1OrbitalSoA.h:100
VectorSoaContainer< RealType, DIM > DisplRow
Definition: DistanceTable.h:47
int refPtcl
Reference particle.
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
SoA adaptor class for Vector<TinyVector<T,D> >
void extractOptimizableObjectRefs(UniqueOptObjRefs &opt_obj_refs) override
extract underlying OptimizableObject references
Definition: J1OrbitalSoA.h:526
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
void free()
free
Definition: OhmmsVector.h:196
QTFull::RealType computeGL(ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) const
compute G and L from internally stored data
Definition: J1OrbitalSoA.h:115
Attaches a unit to a Vector for IO.
ParticleLaplacian L
laplacians of the particles
Definition: ParticleSet.h:85
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
Definition: J1OrbitalSoA.h:507
const bool use_offload_
if true use offload
Definition: J1OrbitalSoA.h:62
aligned_vector< valT > DistCompressed
Definition: J1OrbitalSoA.h:87
#define OHMMS_DIM
Definition: config.h:64
T Dot(const ParticleAttrib< TinyVector< T, D >> &pa, const ParticleAttrib< TinyVector< T, D >> &pb)
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const override
return a shared resource to a collection
std::vector< ValueDerivVec > lapLogPsi
Definition: J1OrbitalSoA.h:103
opt_variables_type myVars
variables handled by this orbital
Definition: J1OrbitalSoA.h:78
std::complex< QTFull::RealType > LogValue
int getTotalNum() const
return the number of species
Definition: SpeciesSet.h:55
void evaluateDerivativesWF(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi) override
Definition: J1OrbitalSoA.h:337
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
void restore(int iat) override
Rejected move.
Definition: J1OrbitalSoA.h:455
An abstract class for a component of a many-body trial wave function.
void attachReference(T *ref, size_type n)
Definition: OhmmsVector.h:131
ResourceHandle< J1OrbitalSoAMultiWalkerMem< RealType > > mw_mem_handle_
Definition: J1OrbitalSoA.h:105
Specialization for one-body Jastrow function using multiple functors.
Definition: J1OrbitalSoA.h:46
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
ParticleAttrib< QTFull::GradType > GradDerivVec
Definition: J1OrbitalSoA.h:58
const DisplRow & getTempDispls() const
return the temporary displacements when a move is proposed
void recompute(const ParticleSet &P) override
recompute the value of the WaveFunctionComponents which require critical accuracy.
Definition: J1OrbitalSoA.h:240
const int Nelec
number of electrons
Definition: J1OrbitalSoA.h:69
void mw_evaluateRatios(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< const VirtualParticleSet > &vp_list, std::vector< std::vector< ValueType >> &ratios) const override
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
QTBase::ValueType ValueType
Definition: Configuration.h:60
const DistRow & getTempDists() const
return the temporary distances when a move is proposed
GradType evalGradSource(ParticleSet &P, ParticleSet &source, int isrc, TinyVector< ParticleSet::ParticleGradient, OHMMS_DIM > &grad_grad, TinyVector< ParticleSet::ParticleLaplacian, OHMMS_DIM > &lapl_grad) override
Adds the gradient w.r.t.
Definition: J1OrbitalSoA.h:648
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > outerProduct(const TinyVector< T1, D > &lhs, const TinyVector< T2, D > &rhs)
Definition: TinyVector.h:211
valT computeU(const DistRow &dist)
Definition: J1OrbitalSoA.h:155
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch
Definition: J1OrbitalSoA.h:251
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
Functors which implement Pade functions.
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
GradType evalGradSource(ParticleSet &P, ParticleSet &source, int isrc) override
return the logarithmic gradient for the iat-th particle of the source particleset ...
Definition: J1OrbitalSoA.h:626
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
void initialize(const ParticleSet &els)
Definition: J1OrbitalSoA.h:202
bool isOptimizable() const override
Definition: J1OrbitalSoA.h:524
aligned_vector< valT > dU
Definition: J1OrbitalSoA.h:86
typename FT::real_type valT
type of each component U, dU, d2U;
Definition: J1OrbitalSoA.h:51
void evaluateDerivRatios(const VirtualParticleSet &VP, const opt_variables_type &optvars, std::vector< ValueType > &ratios, Matrix< ValueType > &dratios) override
Definition: J1OrbitalSoA.h:566
void clear()
clear the variable set
Definition: VariableSet.cpp:28
size_type size() const
return the size
Definition: VariableSet.h:88
aligned_vector< int > DistIndice
Definition: J1OrbitalSoA.h:88
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void diagonal(const T &rhs)
Definition: Tensor.h:205
J1OrbitalSoA(const std::string &obj_name, const ParticleSet &ions, ParticleSet &els, bool use_offload)
void evaluateHessian(ParticleSet &P, HessVector &grad_grad_psi) override
Definition: J1OrbitalSoA.h:259
const int Nions
number of ions
Definition: J1OrbitalSoA.h:67
size_type current() const
Definition: PooledMemory.h:76
void addFunc(int source_type, std::unique_ptr< FT > afunc, int target_type=-1)
Definition: J1OrbitalSoA.h:219
aligned_vector< valT > U
Definition: J1OrbitalSoA.h:86
const ParticleSet & Ions
reference to the sources (ions)
Definition: J1OrbitalSoA.h:73
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
Definition: J1OrbitalSoA.h:493
OHMMS_PRECISION real_type
Vector< int, OffloadPinnedAllocator< int > > grp_ids
the group_id of each particle
Definition: J1OrbitalSoA.h:75
Vector< RealType, aligned_allocator< RealType > > DistRow
Definition: DistanceTable.h:46
User-defined functor.
valT accumulateGL(const valT *restrict du, const valT *restrict d2u, const DisplRow &displ, posT &grad) const
compute gradient and lap
Definition: J1OrbitalSoA.h:136
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const override
acquire a shared resource from a collection
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios) override
Definition: J1OrbitalSoA.h:417
Vector< RealType > dLogPsi
Definition: J1OrbitalSoA.h:101
Precision RealType
Definition: QMCTypes.h:37
Declaraton of ParticleAttrib<T>
aligned_vector< valT > d3U
Definition: J1OrbitalSoA.h:86
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
Definition: J1OrbitalSoA.h:305
void evaluateRatios(const VirtualParticleSet &VP, std::vector< ValueType > &ratios) override
Definition: J1OrbitalSoA.h:295
OrbitalSetTraits< ValueType >::HessVector HessVector
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
Definition: J1OrbitalSoA.h:533
std::vector< GradDerivVec > gradLogPsi
Definition: J1OrbitalSoA.h:102
void insertFrom(const VariableSet &input)
insert a VariableSet to the list
Definition: VariableSet.cpp:37
Declaration of WaveFunctionComponent.
std::vector< FT * > J1Functors
Container for .
Definition: J1OrbitalSoA.h:92
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
compute the gradient during particle-by-particle update
Definition: J1OrbitalSoA.h:443
size_t Bytes_in_WFBuffer
Bytes in WFBuffer.
FT FuncType
alias FuncType
Definition: J1OrbitalSoA.h:49
SIMD version of functions in algorithm.
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter
ParticleAttrib< QTFull::ValueType > ValueDerivVec
Definition: J1OrbitalSoA.h:59
T1 * lendReference(size_type n)
Definition: PooledMemory.h:154
void push_back(OptimizableObject &obj)
const auto & getFunctors() const
Definition: J1OrbitalSoA.h:230
const int myTableID
table index
Definition: J1OrbitalSoA.h:65
aligned_vector< valT > d2U
Definition: J1OrbitalSoA.h:86
PsiValue ratio(ParticleSet &P, int iat) override
evaluate the ratio of the new to old WaveFunctionComponent value
Definition: J1OrbitalSoA.h:288
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Definition: J1OrbitalSoA.h:500
void computeU3(const ParticleSet &P, int iat, const DistRow &dist)
compute U, dU and d2U
Definition: J1OrbitalSoA.h:172
int getGroupID(int iat) const
return the group id of a given particle in the particle set.
Definition: ParticleSet.h:520
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
Accpted move.
Definition: J1OrbitalSoA.h:458
void add(std::complex< T1 > &x)
Definition: PooledMemory.h:113
std::string getClassName() const override
return class name
Definition: J1OrbitalSoA.h:199