QMCPACK
LRHandlerBase.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 /** @file LRHandlerBase.h
17  * @brief Define LRHandlerBase and DummyLRHandler<typename Func>
18  */
19 #ifndef QMCPLUSPLUS_LRHANLDERBASE_AND_DUMMY_H
20 #define QMCPLUSPLUS_LRHANLDERBASE_AND_DUMMY_H
21 
22 #include "coulomb_types.h"
23 #include "LongRange/StructFact.h"
24 #include "Particle/ParticleSet.h"
25 
26 namespace qmcplusplus
27 {
28 /** base class for LRHandlerTemp<FUNC,BASIS> and DummyLRHanlder<typename Func>
29  */
31 {
33 
34  /// Maxkimum Kshell for the given Kc
35  int MaxKshell;
36  /// Maximum k cutoff
38  /// Maximum r cutoff
40  ///Fourier component for all the k-point
42  ///Fourier component of the LR part, fit to optimize the gradients.
44  ///Fourier component of the LR part of strain tensor, by optimized breakup.
45  std::vector<SymTensor<mRealType, OHMMS_DIM>> dFk_dstrain;
46  ///Vector of df_k/dk, fit as to optimize strains.
48  ///Fourier component for each k-shell
50 
51  ///Fourier component for each k-shell
52  ///Coefficient
53  std::vector<mRealType> coefs;
54  ///Coefficient for gradient fit.
55  std::vector<mRealType> gcoefs;
56  ///Coefficient for strain fit.
57  std::vector<mRealType> gstraincoefs;
58 
59  virtual mRealType evaluate_vlr_k(mRealType k) const = 0;
60 
61 
62  //constructor
63  explicit LRHandlerBase(mRealType kc) : MaxKshell(0), LR_kc(kc), LR_rc(0), ClassName("LRHandlerBase") {}
64 
65  // virtual destructor
66  virtual ~LRHandlerBase() = default;
67 
68  //return r cutoff
69  inline mRealType get_rc() const { return LR_rc; }
70  //return k cutoff
71  inline mRealType get_kc() const { return LR_kc; }
72 
73  inline mRealType evaluate_w_sk(const std::vector<int>& kshell, const pRealType* restrict sk) const
74  {
75  mRealType vk = 0.0;
76  for (int ks = 0, ki = 0; ks < MaxKshell; ks++)
77  {
78  mRealType u = 0;
79  for (; ki < kshell[ks + 1]; ki++)
80  u += (*sk++);
81  vk += Fk_symm[ks] * u;
82  }
83  return vk;
84  }
85 
86  /** evaluate \f$\sum_k F_{k} \rho^1_{-{\bf k}} \rho^2_{\bf k}\f$
87  * @param kshell degeneracies of the vectors
88  * @param rk1_r/i starting address of \f$\rho^1_{{\bf k}}\f$
89  * @param rk2_r/i starting address of \f$\rho^2_{{\bf k}}\f$
90  *
91  * Valid for the strictly ordered k and \f$F_{k}\f$.
92  */
93  inline mRealType evaluate(const std::vector<int>& kshell,
94  const pRealType* restrict rk1_r,
95  const pRealType* restrict rk1_i,
96  const pRealType* restrict rk2_r,
97  const pRealType* restrict rk2_i) const
98  {
99  mRealType vk = 0.0;
100  for (int ks = 0, ki = 0; ks < MaxKshell; ks++)
101  {
102  mRealType u = 0;
103  for (; ki < kshell[ks + 1]; ki++)
104  u += ((*rk1_r++) * (*rk2_r++) + (*rk1_i++) * (*rk2_i++));
105  vk += Fk_symm[ks] * u;
106  }
107  return vk;
108  }
109 
110  /** Evaluate the long-range potential with the open BC for the D-1 direction */
112  const std::vector<int>& kshell,
113  const pRealType* restrict rk1_r,
114  const pRealType* restrict rk1_i,
115  const pRealType* restrict rk2_r,
116  const pRealType* restrict rk2_i) const
117  {
118  return 0.0;
119  }
120 
121  /** evaluate \f$\sum_k F_{k} \rho^1_{-{\bf k}} \rho^2_{\bf k}\f$
122  * and \f$\sum_k F_{k} \rho^1_{-{\bf k}} \rho^2_{\bf k}\f$
123  * @param kshell degeneracies of the vectors
124  * @param rk1 starting address of \f$\rho^1_{{\bf k}}\f$
125  * @param rk2 starting address of \f$\rho^2_{{\bf k}}\f$
126  *
127  * Valid for the strictly ordered k and \f$F_{k}\f$.
128  */
129  inline void evaluateGrad(const ParticleSet& A,
130  const ParticleSet& B,
131  int specB,
132  std::vector<pRealType>& Zat,
133  std::vector<TinyVector<pRealType, OHMMS_DIM>>& grad1) const
134  {
135  const Matrix<pRealType>& e2ikrA_r = A.getSK().eikr_r;
136  const Matrix<pRealType>& e2ikrA_i = A.getSK().eikr_i;
137  const pRealType* rhokB_r = B.getSK().rhok_r[specB];
138  const pRealType* rhokB_i = B.getSK().rhok_i[specB];
139  const std::vector<PosType>& kpts = A.getSimulationCell().getKLists().kpts_cart;
140  for (int ki = 0; ki < Fk.size(); ki++)
141  {
142  PosType k = kpts[ki];
143  for (int iat = 0; iat < Zat.size(); iat++)
144  {
145  grad1[iat] -= Zat[iat] * k * Fkg[ki] * (e2ikrA_r(iat, ki) * rhokB_i[ki] - e2ikrA_i(iat, ki) * rhokB_r[ki]);
146  }
147  }
148  }
149 
150  ///FIX_PRECISION
151  inline SymTensor<pRealType, OHMMS_DIM> evaluateStress(const std::vector<int>& kshell,
152  const pRealType* rhokA_r,
153  const pRealType* rhokA_i,
154  const pRealType* rhokB_r,
155  const pRealType* rhokB_i) const
156  {
158  for (int ki = 0; ki < dFk_dstrain.size(); ki++)
159  {
160  stress += (rhokA_r[ki] * rhokB_r[ki] + rhokA_i[ki] * rhokB_i[ki]) * dFk_dstrain[ki];
161  }
162 
163  return stress;
164  }
165 
166  /** evaluate \f$ v_{s}(k=0) = \frac{4\pi}{V}\int_0^{r_c} r^2 v_s(r) dr \f$
167  */
168  virtual mRealType evaluateSR_k0() const { return 0.0; }
169  /** evaluate \f$ v_s(r=0) \f$ for the self-interaction term
170  */
171  virtual mRealType evaluateLR_r0() const { return 0.0; }
172 
173  ///These functions return the strain derivatives of all corresponding quantities
174  /// in total energy. See documentation (forthcoming).
178  {
179  return 0;
180  };
182  {
183  return 0;
184  };
185 
186  virtual void initBreakup(ParticleSet& ref) = 0;
187  virtual void Breakup(ParticleSet& ref, mRealType rs_in) = 0;
188  virtual void resetTargetParticleSet(ParticleSet& ref) = 0;
189 
190  virtual mRealType evaluate(mRealType r, mRealType rinv) const = 0;
191  virtual mRealType evaluateLR(mRealType r) const = 0;
192  virtual mRealType srDf(mRealType r, mRealType rinv) const = 0;
193 
194  virtual mRealType lrDf(mRealType r) const
195  {
196  APP_ABORT("Error: lrDf(r) is not implemented in " + ClassName + "\n");
197  return 0.0;
198  };
199 
200  /** make clone */
201  virtual LRHandlerBase* makeClone(ParticleSet& ref) const = 0;
202 
203 protected:
204  std::string ClassName;
205 };
206 
207 /** LRHandler without breakup.
208  *
209  * The template parameter Func should impelement operator()(kk) which
210  * returns the Fourier component of a long-range function. Here kk
211  * is \f$|{\bf k}|^2\f$.
212  */
213 template<class Func>
215 {
216  Func myFunc;
217 
219 
221 
222  void initBreakup(ParticleSet& ref) override
223  {
224  mRealType norm = 4.0 * M_PI / ref.getLattice().Volume;
225  mRealType kcsq = LR_kc * LR_kc;
226  auto& KList(ref.getSimulationCell().getKLists());
227  int maxshell = KList.kshell.size() - 1;
228  const auto& kk(KList.ksq);
229  int ksh = 0, ik = 0;
230  while (ksh < maxshell)
231  {
232  if (kk[ik] > kcsq)
233  break; //exit
234  ik = KList.kshell[++ksh];
235  }
236  MaxKshell = ksh;
238  Fk.resize(KList.kpts_cart.size());
239  for (ksh = 0, ik = 0; ksh < MaxKshell; ksh++, ik++)
240  {
241  mRealType v = norm * myFunc(kk[KList.kshell[ksh]]); //rpa=u0/kk[ik];
242  Fk_symm[ksh] = v;
243  for (; ik < KList.kshell[ksh + 1]; ik++)
244  Fk[ik] = v;
245  }
246  }
247 
248  mRealType evaluate_vlr_k(mRealType k) const override { return 0.0; }
249  mRealType evaluate(mRealType r, mRealType rinv) const override { return 0.0; }
250  mRealType evaluateLR(mRealType r) const override { return 0.0; }
251  mRealType srDf(mRealType r, mRealType rinv) const override { return 0.0; }
252  void Breakup(ParticleSet& ref, mRealType rs_in) override {}
253  void resetTargetParticleSet(ParticleSet& ref) override {}
254  LRHandlerBase* makeClone(ParticleSet& ref) const override { return new DummyLRHandler<Func>(LR_kc); }
255 };
256 
257 } // namespace qmcplusplus
258 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
virtual SymTensor< mRealType, OHMMS_DIM > evaluateLR_r0_dstrain() const
These functions return the strain derivatives of all corresponding quantities in total energy...
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
mRealType evaluate(mRealType r, mRealType rinv) const override
virtual mRealType evaluate_vlr_k(mRealType k) const =0
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
mRealType LR_kc
Maximum k cutoff.
Definition: LRHandlerBase.h:37
virtual mRealType evaluateLR(mRealType r) const =0
virtual void Breakup(ParticleSet &ref, mRealType rs_in)=0
mRealType srDf(mRealType r, mRealType rinv) const override
virtual SymTensor< mRealType, OHMMS_DIM > evaluateLR_dstrain(TinyVector< pRealType, OHMMS_DIM > k, pRealType kmag) const
DECLARE_COULOMB_TYPES int MaxKshell
Maxkimum Kshell for the given Kc.
Definition: LRHandlerBase.h:35
EwaldHandler3D::mRealType mRealType
LRHandler without breakup.
Vector< mRealType > Fkgstrain
Vector of df_k/dk, fit as to optimize strains.
Definition: LRHandlerBase.h:47
DummyLRHandler(const DummyLRHandler &aLR)
std::vector< mRealType > coefs
Fourier component for each k-shell Coefficient.
Definition: LRHandlerBase.h:53
virtual mRealType evaluate_slab(pRealType z, const std::vector< int > &kshell, const pRealType *restrict rk1_r, const pRealType *restrict rk1_i, const pRealType *restrict rk2_r, const pRealType *restrict rk2_i) const
Evaluate the long-range potential with the open BC for the D-1 direction.
mRealType evaluate(const std::vector< int > &kshell, const pRealType *restrict rk1_r, const pRealType *restrict rk1_i, const pRealType *restrict rk2_r, const pRealType *restrict rk2_i) const
evaluate
Definition: LRHandlerBase.h:93
mRealType evaluate_vlr_k(mRealType k) const override
mRealType evaluate_w_sk(const std::vector< int > &kshell, const pRealType *restrict sk) const
Definition: LRHandlerBase.h:73
virtual mRealType evaluateLR_r0() const
evaluate for the self-interaction term
std::vector< SymTensor< mRealType, OHMMS_DIM > > dFk_dstrain
Fourier component of the LR part of strain tensor, by optimized breakup.
Definition: LRHandlerBase.h:45
virtual ~LRHandlerBase()=default
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
size_type size() const
return the current size
Definition: OhmmsVector.h:162
qmcplusplus::LRHandlerBase::pRealType pRealType
virtual SymTensor< mRealType, OHMMS_DIM > evaluateSR_k0_dstrain() const
virtual void initBreakup(ParticleSet &ref)=0
double norm(const zVec &c)
Definition: VectorOps.h:118
mRealType LR_rc
Maximum r cutoff.
Definition: LRHandlerBase.h:39
SymTensor< pRealType, OHMMS_DIM > evaluateStress(const std::vector< int > &kshell, const pRealType *rhokA_r, const pRealType *rhokA_i, const pRealType *rhokB_r, const pRealType *rhokB_i) const
FIX_PRECISION.
mRealType evaluateLR(mRealType r) const override
void resetTargetParticleSet(ParticleSet &ref) override
Vector< mRealType > Fkg
Fourier component of the LR part, fit to optimize the gradients.
Definition: LRHandlerBase.h:43
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
Vector< mRealType > Fk
Fourier component for all the k-point.
Definition: LRHandlerBase.h:41
std::vector< mRealType > gcoefs
Coefficient for gradient fit.
Definition: LRHandlerBase.h:55
void initBreakup(ParticleSet &ref) override
virtual mRealType lrDf(mRealType r) const
#define DECLARE_COULOMB_TYPES
Definition: coulomb_types.h:18
virtual LRHandlerBase * makeClone(ParticleSet &ref) const =0
make clone
void Breakup(ParticleSet &ref, mRealType rs_in) override
DummyLRHandler(mRealType kc=-1.0)
std::vector< mRealType > gstraincoefs
Coefficient for strain fit.
Definition: LRHandlerBase.h:57
const auto & getLattice() const
Definition: ParticleSet.h:251
virtual SymTensor< mRealType, OHMMS_DIM > evaluateSR_dstrain(TinyVector< pRealType, OHMMS_DIM > r, pRealType rmag) const
virtual mRealType evaluateSR_k0() const
evaluate
base class for LRHandlerTemp<FUNC,BASIS> and DummyLRHanlder<typename Func>
Definition: LRHandlerBase.h:30
void evaluateGrad(const ParticleSet &A, const ParticleSet &B, int specB, std::vector< pRealType > &Zat, std::vector< TinyVector< pRealType, OHMMS_DIM >> &grad1) const
evaluate and
mRealType get_rc() const
Definition: LRHandlerBase.h:69
double B(double x, int k, int i, const std::vector< double > &t)
mRealType get_kc() const
Definition: LRHandlerBase.h:71
virtual mRealType srDf(mRealType r, mRealType rinv) const =0
virtual void resetTargetParticleSet(ParticleSet &ref)=0
LRHandlerBase * makeClone(ParticleSet &ref) const override
make clone
Vector< mRealType > Fk_symm
Fourier component for each k-shell.
Definition: LRHandlerBase.h:49