QMCPACK
J1Spin.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_ONEBODYSPINJASTROW_OPTIMIZED_SOA_H
16 #define QMCPLUSPLUS_ONEBODYSPINJASTROW_OPTIMIZED_SOA_H
17 #include "Configuration.h"
18 #include "Particle/DistanceTable.h"
21 #include "Utilities/qmc_common.h"
24 #include "CPU/SIMD/algorithm.hpp"
25 #include <map>
26 #include <numeric>
27 
28 namespace qmcplusplus
29 {
30 /** @ingroup WaveFunctionComponent
31  * @brief Specialization for one-body Jastrow function using multiple functors
32  */
33 template<class FT>
35 {
36  ///alias FuncType
37  using FuncType = FT;
38  ///type of each component U, dU, d2U;
39  using valT = typename FT::real_type;
40  ///element position type
42  ///use the same container
45 
48 
49  ///table index
50  const int myTableID;
51  ///number of ions
52  const int Nions;
53  ///number of electrons
54  const int Nelec;
55  /* the number of ion groups if ions in 'Ions' particleset are grouped by species. 0 otherwise.
56  * 0 Use slow code path. >= 1 use the code path with ion grouping
57  */
58  const int NumGroups;
59  // number of electron groups
60  const int NumTargetGroups;
61  ///reference to the sources (ions)
62  const ParticleSet& Ions;
63 
64  ///variables handled by this orbital
66 
70 
71  ///\f$Vat[i] = sum_(j) u_{i,j}\f$
78  ///container for the unique Jastrow functors (size NumGroups x NumTargetGroups)
79  std::vector<std::unique_ptr<FT>> J1UniqueFunctors;
80 
81  std::vector<std::pair<int, int>> OffSet;
83  std::vector<GradDerivVec> gradLogPsi;
84  std::vector<ValueDerivVec> lapLogPsi;
85 
87  {
91  }
92 
93  J1Spin(const std::string& obj_name, const ParticleSet& ions, ParticleSet& els, bool use_offload)
94  : WaveFunctionComponent(obj_name),
95  myTableID(els.addTable(ions, DTModes::NEED_VP_FULL_TABLE_ON_HOST)),
96  Nions(ions.getTotalNum()),
97  Nelec(els.getTotalNum()),
98  NumGroups(ions.groups()),
99  NumTargetGroups(els.groups()),
100  Ions(ions)
101  {
102  if (my_name_.empty())
103  throw std::runtime_error("J1Spin object name cannot be empty!");
104  initialize(els);
105  }
106 
107  J1Spin(const J1Spin& rhs) = delete;
108 
109  J1Spin(const J1Spin& rhs, ParticleSet& tqp)
111  myTableID(rhs.myTableID),
112  Nions(rhs.Nions),
113  Nelec(rhs.Nelec),
114  NumGroups(rhs.NumGroups),
116  Ions(rhs.Ions)
117  {
118  initialize(tqp);
119  for (int i = 0; i < NumGroups; i++)
120  for (int j = 0; j < NumTargetGroups; j++)
121  if (rhs.J1UniqueFunctors[i * NumTargetGroups + j])
122  {
123  auto fc = std::make_unique<FT>(*rhs.J1UniqueFunctors[i * NumTargetGroups + j].get());
124  addFunc(i, std::move(fc), j);
125  }
126  myVars = rhs.myVars;
127  OffSet = rhs.OffSet;
128  }
129 
130  std::string getClassName() const override { return "J1Spin"; }
131 
132  /* initialize storage */
134  {
136  Vat.resize(Nelec);
137  Grad.resize(Nelec);
138  Lap.resize(Nelec);
139 
140  U.resize(Nions);
141  dU.resize(Nions);
142  d2U.resize(Nions);
143  d3U.resize(Nions);
144  DistCompressed.resize(Nions);
145  DistIndice.resize(Nions);
146  }
147 
148  void addFunc(int source_type, std::unique_ptr<FT> afunc, int target_type = -1)
149  {
150  // if target type is not specified J1UniqueFunctors[i*NumTargetGroups + (0:NumTargetGroups)] is assigned
151  // if target type is specified J1UniqueFunctors[i*NumTargetGroups + j] is assigned
152  assert(target_type < NumTargetGroups);
153  if (target_type == -1)
154  throw std::runtime_error(
155  "J1Spin::addFunc is not compatible with spin independent Jastrow factors (target_type == -1");
156  else
157  J1UniqueFunctors[source_type * NumTargetGroups + target_type] = std::move(afunc);
158  }
159 
160  void recompute(const ParticleSet& P) override
161  {
162  const auto& d_ie(P.getDistTableAB(myTableID));
163  for (int iat = 0; iat < Nelec; ++iat)
164  {
165  computeU3(P, iat, d_ie.getDistRow(iat));
166  Vat[iat] = simd::accumulate_n(U.data(), Nions, valT());
167  Lap[iat] = accumulateGL(dU.data(), d2U.data(), d_ie.getDisplRow(iat), Grad[iat]);
168  }
169  }
170 
173  ParticleSet::ParticleLaplacian& L) override
174  {
175  recompute(P);
176  return log_value_ = computeGL(G, L);
177  }
178 
179  void evaluateHessian(ParticleSet& P, HessVector& grad_grad_psi) override
180  {
181  const auto& d_ie(P.getDistTableAB(myTableID));
182  valT dudr, d2udr2;
183 
184  Tensor<valT, DIM> ident;
185  grad_grad_psi = 0.0;
186  ident.diagonal(1.0);
187 
188  for (int iel = 0; iel < Nelec; ++iel)
189  {
190  const auto& dist = d_ie.getDistRow(iel);
191  const auto& displ = d_ie.getDisplRow(iel);
192  for (int iat = 0; iat < Nions; iat++)
193  {
194  auto gid = Ions.getGroupID(iat) * NumTargetGroups + P.getGroupID(iel);
195  auto* func = J1UniqueFunctors[gid].get();
196  if (func != nullptr)
197  {
198  RealType r = dist[iat];
199  RealType rinv = 1.0 / r;
200  PosType dr = displ[iat];
201  func->evaluate(r, dudr, d2udr2);
202  grad_grad_psi[iel] -= rinv * rinv * outerProduct(dr, dr) * (d2udr2 - dudr * rinv) + ident * dudr * rinv;
203  }
204  }
205  }
206  }
207 
208  PsiValue ratio(ParticleSet& P, int iat) override
209  {
212  return std::exp(static_cast<PsiValue>(Vat[iat] - curAt));
213  }
214 
215  inline void evaluateRatios(const VirtualParticleSet& VP, std::vector<ValueType>& ratios) override
216  {
217  for (int k = 0; k < ratios.size(); ++k)
218  ratios[k] =
220  }
221 
223  const opt_variables_type& active,
224  Vector<ValueType>& dlogpsi,
225  Vector<ValueType>& dhpsioverpsi) override
226  {
227  evaluateDerivativesWF(P, active, dlogpsi);
228  bool recalculate(false);
229  std::vector<bool> rcsingles(myVars.size(), false);
230  for (int k = 0; k < myVars.size(); ++k)
231  {
232  int kk = myVars.where(k);
233  if (kk < 0)
234  continue;
235  if (active.recompute(kk))
236  recalculate = true;
237  rcsingles[k] = true;
238  }
239  if (recalculate)
240  {
241  for (int k = 0; k < myVars.size(); ++k)
242  {
243  int kk = myVars.where(k);
244  if (kk < 0)
245  continue;
246  if (rcsingles[k])
247  {
248  dhpsioverpsi[kk] = -RealType(0.5) * ValueType(Sum(lapLogPsi[k])) - ValueType(Dot(P.G, gradLogPsi[k]));
249  }
250  }
251  }
252  }
253 
254  void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& active, Vector<ValueType>& dlogpsi) override
255  {
257 
258  bool recalculate(false);
259  std::vector<bool> rcsingles(myVars.size(), false);
260  for (int k = 0; k < myVars.size(); ++k)
261  {
262  int kk = myVars.where(k);
263  if (kk < 0)
264  continue;
265  if (active.recompute(kk))
266  recalculate = true;
267  rcsingles[k] = true;
268  }
269  if (recalculate)
270  {
271  const size_t NumVars = myVars.size();
272  for (int p = 0; p < NumVars; ++p)
273  {
274  gradLogPsi[p] = 0.0;
275  lapLogPsi[p] = 0.0;
276  }
277  dLogPsi = 0.0;
278 
279  const auto& d_table = P.getDistTableAB(myTableID);
280  std::vector<TinyVector<RealType, 3>> derivs(NumVars);
281 
282  constexpr RealType cone(1);
283  constexpr RealType lapfac(OHMMS_DIM - cone);
284  const size_t ns = d_table.sources();
285  const size_t nt = P.getTotalNum();
286 
287  aligned_vector<int> iadj(nt);
288  aligned_vector<RealType> dist(nt);
289  std::vector<PosType> displ(nt);
290 
291  for (size_t i = 0; i < ns; ++i)
292  {
293  for (size_t j = 0; j < nt; ++j)
294  {
295  const auto functor_idx = Ions.getGroupID(i) * NumTargetGroups + P.getGroupID(j);
296  const int first(OffSet[functor_idx].first);
297  const int last(OffSet[functor_idx].second);
298  bool recalcFunc(false);
299  for (int rcs = first; rcs < last; rcs++)
300  if (rcsingles[rcs] == true)
301  recalcFunc = true;
302  if (recalcFunc)
303  {
304  auto* func = J1UniqueFunctors[functor_idx].get();
305  if (func == nullptr)
306  continue;
307  std::fill(derivs.begin(), derivs.end(), 0);
308  auto dist = P.getDistTableAB(myTableID).getDistRow(j)[i];
309  if (!func->evaluateDerivatives(dist, derivs))
310  continue;
311  RealType rinv(cone / dist);
312  const PosType& dr = P.getDistTableAB(myTableID).getDisplRow(j)[i];
313  for (int p = first, ip = 0; p < last; ++p, ++ip)
314  {
315  dLogPsi[p] -= derivs[ip][0];
316  RealType dudr(rinv * derivs[ip][1]);
317  gradLogPsi[p][j] += dudr * dr;
318  lapLogPsi[p][j] -= derivs[ip][2] + lapfac * dudr;
319  }
320  }
321  }
322  }
323  for (int k = 0; k < myVars.size(); ++k)
324  {
325  int kk = myVars.where(k);
326  if (kk < 0)
327  continue;
328  if (rcsingles[k])
329  {
330  dlogpsi[kk] = ValueType(dLogPsi[k]);
331  }
332  }
333  }
334  }
335 
336 
337  inline valT computeU(const ParticleSet& P, int iat, const DistRow& dist)
338  {
339  valT curVat(0);
340  for (int jg = 0; jg < NumGroups; ++jg)
341  {
342  auto gid = jg * NumTargetGroups + P.getGroupID(iat);
343  if (J1UniqueFunctors[gid])
344  curVat +=
345  J1UniqueFunctors[gid]->evaluateV(-1, Ions.first(jg), Ions.last(jg), dist.data(), DistCompressed.data());
346  }
347  return curVat;
348  }
349 
350  void evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios) override
351  {
352  const auto& dist = P.getDistTableAB(myTableID).getTempDists();
353  curAt = valT(0);
354  for (int ig = 0; ig < NumGroups; ++ig)
355  {
356  for (int jg = 0; jg < NumTargetGroups; ++jg)
357  {
358  auto gid = ig * NumTargetGroups + jg;
359  if (J1UniqueFunctors[gid] != nullptr)
360  curAt +=
361  J1UniqueFunctors[gid]->evaluateV(-1, Ions.first(ig), Ions.last(ig), dist.data(), DistCompressed.data());
362  }
363  }
364 
365  for (int i = 0; i < Nelec; ++i)
366  ratios[i] = std::exp(Vat[i] - curAt);
367  }
368 
369  /// compute G and L from internally stored data
371  {
372  for (size_t iat = 0; iat < Nelec; ++iat)
373  {
374  G[iat] += Grad[iat];
375  L[iat] -= Lap[iat];
376  }
378  }
379 
380  inline LogValue evaluateGL(const ParticleSet& P,
383  bool fromscratch = false) override
384  {
385  return log_value_ = computeGL(G, L);
386  }
387 
388  /** compute gradient and lap
389  * @return lap
390  */
391  inline valT accumulateGL(const valT* restrict du, const valT* restrict d2u, const DisplRow& displ, posT& grad) const
392  {
393  valT lap(0);
394  constexpr valT lapfac = OHMMS_DIM - RealType(1);
395  //#pragma omp simd reduction(+:lap)
396  for (int jat = 0; jat < Nions; ++jat)
397  lap += d2u[jat] + lapfac * du[jat];
398  for (int idim = 0; idim < OHMMS_DIM; ++idim)
399  {
400  const valT* restrict dX = displ.data(idim);
401  valT s = valT();
402  //#pragma omp simd reduction(+:s)
403  for (int jat = 0; jat < Nions; ++jat)
404  s += du[jat] * dX[jat];
405  grad[idim] = s;
406  }
407  return lap;
408  }
409 
410  /** compute U, dU and d2U
411  * @param P quantum particleset
412  * @param iat the moving particle
413  * @param dist starting address of the distances of the ions wrt the iat-th particle
414  */
415  inline void computeU3(const ParticleSet& P, int iat, const DistRow& dist)
416  {
417  constexpr valT czero(0);
418  std::fill_n(U.data(), Nions, czero);
419  std::fill_n(dU.data(), Nions, czero);
420  std::fill_n(d2U.data(), Nions, czero);
421 
422  for (int jg = 0; jg < NumGroups; ++jg)
423  {
424  auto gid = NumTargetGroups * jg + P.getGroupID(iat);
425  if (J1UniqueFunctors[gid])
426  J1UniqueFunctors[gid]->evaluateVGL(-1, Ions.first(jg), Ions.last(jg), dist.data(), U.data(), dU.data(),
427  d2U.data(), DistCompressed.data(), DistIndice.data());
428  }
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 cloned_J1Spin = std::make_unique<J1Spin<FT>>(*this, tqp);
510  return cloned_J1Spin;
511  }
512 
513  /**@{ WaveFunctionComponent virtual functions that are not essential for the development */
514  bool isOptimizable() const override { return true; }
515 
516  void extractOptimizableObjectRefs(UniqueOptObjRefs& opt_obj_refs) override
517  {
518  for (auto& functor : J1UniqueFunctors)
519  opt_obj_refs.push_back(*functor);
520  }
521 
522  void checkOutVariables(const opt_variables_type& active) override
523  {
524  myVars.clear();
525  for (auto& J1UniqueFunctor : J1UniqueFunctors)
526  {
527  if (J1UniqueFunctor)
528  {
529  J1UniqueFunctor->myVars.getIndex(active);
530  myVars.insertFrom(J1UniqueFunctor->myVars);
531  }
532  }
533  myVars.getIndex(active);
534  const size_t NumVars = myVars.size();
535  myVars.print(std::cout);
536  if (NumVars)
537  {
538  OffSet.resize(J1UniqueFunctors.size());
539  // Find first active variable for the starting offset
540  int varoffset = -1;
541  for (int i = 0; i < myVars.size(); i++)
542  {
543  varoffset = myVars.Index[i];
544  if (varoffset != -1)
545  break;
546  }
547 
548  for (int i = 0; i < J1UniqueFunctors.size(); ++i)
549  {
550  if (J1UniqueFunctors[i] && J1UniqueFunctors[i]->myVars.Index.size())
551  {
552  OffSet[i].first = J1UniqueFunctors[i]->myVars.Index.front() - varoffset;
553  OffSet[i].second = J1UniqueFunctors[i]->myVars.Index.size() + OffSet[i].first;
554  }
555  else
556  {
557  OffSet[i].first = OffSet[i].second = -1;
558  }
559  }
560  }
561  for (auto& J1UniqueFunctor : J1UniqueFunctors)
562  if (J1UniqueFunctor != nullptr)
563  J1UniqueFunctor->checkOutVariables(active);
564  }
565 
566  /**@} */
567 
568  inline GradType evalGradSource(ParticleSet& P, ParticleSet& source, int isrc) override
569  {
570  GradType g_return(0.0);
571  const auto& d_ie(P.getDistTableAB(myTableID));
572  for (int iat = 0; iat < Nelec; ++iat)
573  {
574  const auto& dist = d_ie.getDistRow(iat);
575  const auto& displ = d_ie.getDisplRow(iat);
576  RealType r = dist[isrc];
577  RealType rinv = 1.0 / r;
578  PosType dr = displ[isrc];
579  auto gid = source.getGroupID(isrc) * NumTargetGroups + P.getGroupID(iat);
580  if (J1UniqueFunctors[gid] != nullptr)
581  {
582  U[isrc] = J1UniqueFunctors[gid]->evaluate(dist[isrc], dU[isrc], d2U[isrc], d3U[isrc]);
583  g_return -= dU[isrc] * rinv * dr;
584  }
585  }
586  return g_return;
587  }
588 
590  ParticleSet& source,
591  int isrc,
594  {
595  GradType g_return(0.0);
596  const auto& d_ie(P.getDistTableAB(myTableID));
597  for (int iat = 0; iat < Nelec; ++iat)
598  {
599  const auto& dist = d_ie.getDistRow(iat);
600  const auto& displ = d_ie.getDisplRow(iat);
601  RealType r = dist[isrc];
602  RealType rinv = 1.0 / r;
603  PosType dr = displ[isrc];
604  auto gid = source.getGroupID(isrc) * NumTargetGroups + P.getGroupID(iat);
605  if (J1UniqueFunctors[gid] != nullptr)
606  U[isrc] = J1UniqueFunctors[gid]->evaluate(dist[isrc], dU[isrc], d2U[isrc], d3U[isrc]);
607  else
608  throw std::runtime_error("J1OrbitalSoa::evaluateGradSource: J1UniqueFunctors[gid]==nullptr");
609 
610  g_return -= dU[isrc] * rinv * dr;
611 
612  //The following terms depend only on the radial component r. Thus,
613  //we compute them and mix with position vectors to acquire the full
614  //cartesian vector objects.
615  valT grad_component = (d2U[isrc] - dU[isrc] * rinv);
616  valT lapl_component = d3U[isrc] + 2 * rinv * grad_component;
617 
618  for (int idim = 0; idim < OHMMS_DIM; idim++)
619  {
620  grad_grad[idim][iat] += dr[idim] * dr * rinv * rinv * grad_component;
621  grad_grad[idim][iat][idim] += rinv * dU[isrc];
622 
623  lapl_grad[idim][iat] -= lapl_component * rinv * dr[idim];
624  }
625  }
626  return g_return;
627  }
628 };
629 
630 
631 } // namespace qmcplusplus
632 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
GradType evalGrad(ParticleSet &P, int iat) override
compute the gradient during particle-by-particle update
Definition: J1Spin.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: J1Spin.h:380
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: J1Spin.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
Definition: J1Spin.h:58
QTBase::RealType RealType
Definition: Configuration.h:58
const DistRow & getDistRow(int iel) const
return a row of distances for a given target particle
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 functors (size NumGroups x NumTargetGroups)
Definition: J1Spin.h:79
J1Spin(const J1Spin &rhs, ParticleSet &tqp)
Definition: J1Spin.h:109
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
For distance tables of virtual particle (VP) sets constructed based on this table, whether full table is needed on host The corresponding DT of VP need to set MW_EVALUATE_RESULT_NO_TRANSFER_TO_HOST accordingly.
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: J1Spin.h:81
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: J1Spin.h:516
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: J1Spin.h:370
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: J1Spin.h:507
aligned_vector< valT > DistCompressed
Definition: J1Spin.h:74
#define OHMMS_DIM
Definition: config.h:64
T Dot(const ParticleAttrib< TinyVector< T, D >> &pa, const ParticleAttrib< TinyVector< T, D >> &pb)
std::vector< ValueDerivVec > lapLogPsi
Definition: J1Spin.h:84
opt_variables_type myVars
variables handled by this orbital
Definition: J1Spin.h:65
std::complex< QTFull::RealType > LogValue
const int NumTargetGroups
Definition: J1Spin.h:60
void evaluateDerivativesWF(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi) override
Definition: J1Spin.h:254
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: J1Spin.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
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
ParticleAttrib< QTFull::GradType > GradDerivVec
Definition: J1Spin.h:46
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: J1Spin.h:160
const int Nelec
number of electrons
Definition: J1Spin.h:54
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
valT computeU(const ParticleSet &P, int iat, const DistRow &dist)
Definition: J1Spin.h:337
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: J1Spin.h:589
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > outerProduct(const TinyVector< T1, D > &lhs, const TinyVector< T2, D > &rhs)
Definition: TinyVector.h:211
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: J1Spin.h:171
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
Specialization for one-body Jastrow function using multiple functors.
Definition: J1Spin.h:34
GradType evalGradSource(ParticleSet &P, ParticleSet &source, int isrc) override
return the logarithmic gradient for the iat-th particle of the source particleset ...
Definition: J1Spin.h:568
Vector< posT > Grad
Definition: J1Spin.h:76
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)
bool isOptimizable() const override
Definition: J1Spin.h:514
Vector< valT > Lap
Definition: J1Spin.h:77
aligned_vector< valT > dU
Definition: J1Spin.h:73
typename FT::real_type valT
type of each component U, dU, d2U;
Definition: J1Spin.h:39
void clear()
clear the variable set
Definition: VariableSet.cpp:28
size_type size() const
return the size
Definition: VariableSet.h:88
Vector< valT > Vat
Definition: J1Spin.h:72
aligned_vector< int > DistIndice
Definition: J1Spin.h:75
void resizeWFOptVectors()
Definition: J1Spin.h:86
void diagonal(const T &rhs)
Definition: Tensor.h:205
void evaluateHessian(ParticleSet &P, HessVector &grad_grad_psi) override
Definition: J1Spin.h:179
const int Nions
number of ions
Definition: J1Spin.h:52
size_type current() const
Definition: PooledMemory.h:76
void addFunc(int source_type, std::unique_ptr< FT > afunc, int target_type=-1)
Definition: J1Spin.h:148
aligned_vector< valT > U
Definition: J1Spin.h:73
const ParticleSet & Ions
reference to the sources (ions)
Definition: J1Spin.h:62
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
Definition: J1Spin.h:493
OHMMS_PRECISION real_type
Vector< RealType, aligned_allocator< RealType > > DistRow
Definition: DistanceTable.h:46
valT accumulateGL(const valT *restrict du, const valT *restrict d2u, const DisplRow &displ, posT &grad) const
compute gradient and lap
Definition: J1Spin.h:391
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios) override
Definition: J1Spin.h:350
Vector< RealType > dLogPsi
Definition: J1Spin.h:82
Precision RealType
Definition: QMCTypes.h:37
Declaraton of ParticleAttrib<T>
aligned_vector< valT > d3U
Definition: J1Spin.h:73
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
Definition: J1Spin.h:222
void evaluateRatios(const VirtualParticleSet &VP, std::vector< ValueType > &ratios) override
Definition: J1Spin.h:215
OrbitalSetTraits< ValueType >::HessVector HessVector
void initialize(ParticleSet &els)
Definition: J1Spin.h:133
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
Definition: J1Spin.h:522
std::vector< GradDerivVec > gradLogPsi
Definition: J1Spin.h:83
void insertFrom(const VariableSet &input)
insert a VariableSet to the list
Definition: VariableSet.cpp:37
Declaration of WaveFunctionComponent.
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
compute the gradient during particle-by-particle update
Definition: J1Spin.h:443
size_t Bytes_in_WFBuffer
Bytes in WFBuffer.
FT FuncType
alias FuncType
Definition: J1Spin.h:37
SIMD version of functions in algorithm.
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
J1Spin(const std::string &obj_name, const ParticleSet &ions, ParticleSet &els, bool use_offload)
Definition: J1Spin.h:93
ParticleAttrib< QTFull::ValueType > ValueDerivVec
Definition: J1Spin.h:47
T1 * lendReference(size_type n)
Definition: PooledMemory.h:154
void push_back(OptimizableObject &obj)
const int myTableID
table index
Definition: J1Spin.h:50
aligned_vector< valT > d2U
Definition: J1Spin.h:73
PsiValue ratio(ParticleSet &P, int iat) override
evaluate the ratio of the new to old WaveFunctionComponent value
Definition: J1Spin.h:208
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Definition: J1Spin.h:500
void computeU3(const ParticleSet &P, int iat, const DistRow &dist)
compute U, dU and d2U
Definition: J1Spin.h:415
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: J1Spin.h:458
void add(std::complex< T1 > &x)
Definition: PooledMemory.h:113
std::string getClassName() const override
return class name
Definition: J1Spin.h:130