QMCPACK
LRRPABFeeHandlerTemp.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: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 /** @file LRHandlerTemp.h
16  * @brief Define a LRHandler with two template parameters
17  */
18 #ifndef QMCPLUSPLUS_LRBFEEHANLDERTEMP_H
19 #define QMCPLUSPLUS_LRBFEEHANLDERTEMP_H
20 
22 #include "LongRange/LPQHIBasis.h"
23 #include "LongRange/LRBreakup.h"
24 
25 namespace qmcplusplus
26 {
27 /* Templated LRHandler class
28  *
29  * LRHandlerTemp<Func,BreakupBasis> is a modification of LRHandler
30  * and a derived class from LRHanlderBase.
31  * The first template parameter Func is a generic functor, e.g., CoulombFunctor.
32  * The second template parameter is a BreakupBasis and the default is set to LPQHIBasis.
33  * LRHandlerBase is introduced to enable run-time options. See RPAContstraints.h
34  */
35 template<class Func, class BreakupBasis = LPQHIBasis>
37 {
39 
40  //Typedef for the lattice-type.
42  using BreakupBasisType = BreakupBasis;
43 
44  bool FirstTime;
47  BreakupBasisType Basis; //This needs a Lattice for the constructor...
48  Func myFunc;
49 
50  //Constructor
52  : LRHandlerBase(kc_in), FirstTime(true), Basis(ref.getLattice())
53  {
54  LRHandlerBase::ClassName = "LRRPAFeeHandlerTemp";
55  myFunc.reset(ref);
56  }
57 
58  //LRHandlerTemp(ParticleSet& ref, mRealType rs, mRealType kc=-1.0): LRHandlerBase(kc), Basis(ref.getLattice())
59  //{
60  // myFunc.reset(ref,rs);
61  //}
62 
63  /** "copy" constructor
64  * @param aLR LRHandlerTemp
65  * @param ref Particleset
66  *
67  * Copy the content of aLR
68  * References to ParticleSet or ParticleLayoutout_t are not copied.
69  */
71  : LRHandlerBase(aLR), FirstTime(true), Basis(aLR.Basis, ref.getLattice())
72  {
73  myFunc.reset(ref);
74  fillFk(ref.getSimulationCell().getKLists());
75  }
76 
77  LRHandlerBase* makeClone(ParticleSet& ref) const override
78  {
79  return new LRRPABFeeHandlerTemp<Func, BreakupBasis>(*this, ref);
80  }
81 
82  void initBreakup(ParticleSet& ref) override
83  {
84  InitBreakup(ref.getLattice(), 1);
85  fillFk(ref.getSimulationCell().getKLists());
86  LR_rc = Basis.get_rc();
87  }
88 
89  void Breakup(ParticleSet& ref, mRealType rs_ext) override
90  {
91  //ref.getLattice().Volume=ref.getTotalNum()*4.0*M_PI/3.0*rs*rs*rs;
92  rs = rs_ext;
93  myFunc.reset(ref, rs);
94  InitBreakup(ref.getLattice(), 1);
95  fillFk(ref.getSimulationCell().getKLists());
96  LR_rc = Basis.get_rc();
97  }
98 
99  void resetTargetParticleSet(ParticleSet& ref) override { myFunc.reset(ref); }
100 
102 
103  inline mRealType evaluate(mRealType r, mRealType rinv) const override
104  {
105  mRealType v = 0.0;
106  for (int n = 0; n < coefs.size(); n++)
107  v += coefs[n] * Basis.h(n, r);
108  return v;
109  }
110 
111  /** evaluate the first derivative of the short range part at r
112  *
113  * @param r radius
114  * @param rinv 1/r
115  */
116  inline mRealType srDf(mRealType r, mRealType rinv) const override
117  {
118  mRealType df = 0.0;
119  //mRealType df = myFunc.df(r, rinv);
120  for (int n = 0; n < coefs.size(); n++)
121  df += coefs[n] * Basis.df(n, r);
122  return df;
123  }
124 
125 
126  /** evaluate the contribution from the long-range part for for spline
127  */
128  inline mRealType evaluateLR(mRealType r) const override
129  {
130  mRealType vk = 0.0;
131  return vk;
132  // for(int n=0; n<coefs.size(); n++) v -= coefs[n]*Basis.h(n,r);
133  }
134 
135  inline mRealType evaluate_vlr_k(mRealType k) const override { return evalFk(k); }
136 
137 private:
138  inline mRealType evalFk(mRealType k) const
139  {
140  //FatK = 4.0*M_PI/(Basis.get_CellVolume()*k*k)* std::cos(k*Basis.get_rc());
141  mRealType FatK = myFunc.Fk(k, Basis.get_rc());
142  for (int n = 0; n < Basis.NumBasisElem(); n++)
143  FatK += coefs[n] * Basis.c(n, k);
144  return FatK;
145  }
146 
147  inline mRealType evalXk(mRealType k) const
148  {
149  //mRealType FatK;
150  //FatK = -4.0*M_PI/(Basis.get_CellVolume()*k*k)* std::cos(k*Basis.get_rc());
151  //return (FatK);
152  return myFunc.Xk(k, Basis.get_rc());
153  }
154 
155  /** Initialise the basis and coefficients for the long-range beakup.
156  *
157  * We loocally create a breakup handler and pass in the basis
158  * that has been initialised here. We then discard the handler, leaving
159  * basis and coefs in a usable state.
160  * This method can be re-called later if lattice changes shape.
161  */
162  void InitBreakup(const ParticleLayout& ref, int NumFunctions)
163  {
164  //First we send the new Lattice to the Basis, in case it has been updated.
165  Basis.set_Lattice(ref);
166  //Compute RC from box-size - in constructor?
167  //No here...need update if box changes
168  int NumKnots(15);
169  Basis.set_NumKnots(NumKnots);
170  Basis.set_rc(ref.LR_rc);
171  //Initialise the breakup - pass in basis.
172  LRBreakup<BreakupBasis> breakuphandler(Basis);
173  // std::cout<<" finding kc: "<<ref.LR_kc<<" , "<<LR_kc<< std::endl;
174  //Find size of basis from cutoffs
175  kc = (LR_kc < 0) ? ref.LR_kc : LR_kc;
176  //mRealType kc(ref.LR_kc); //User cutoff parameter...
177  //kcut is the cutoff for switching to approximate k-point degeneracies for
178  //better performance in making the breakup. A good bet is 30*K-spacing so that
179  //there are 30 "boxes" in each direction that are treated with exact degeneracies.
180  //Assume orthorhombic cell just for deriving this cutoff - should be insensitive.
181  //K-Spacing = (kpt_vol)**1/3 = 2*pi/(cellvol**1/3)
182  mRealType kcut = (30.0) * 2 * M_PI * std::pow(Basis.get_CellVolume(), -1.0 / 3.0);
183  //Use 3000/LMax here...==6000/rc for non-ortho cells
184  mRealType kmax(6000.0 / ref.LR_rc);
185  // std::cout<<"K_STATS !!! "<<kcut<<" "<<kmax<<std::endl;
186  MaxKshell = static_cast<int>(breakuphandler.SetupKVecs(kc, kcut, kmax));
187  if (FirstTime)
188  {
189  app_log() << " finding kc: " << ref.LR_kc << " , " << LR_kc << std::endl;
190  app_log() << " LRBreakp parameter Kc =" << kc << std::endl;
191  app_log() << " Continuum approximation in k = [" << kcut << "," << kmax << ")" << std::endl;
192  FirstTime = false;
193  }
194  //Set up x_k
195  //This is the FT of -V(r) from r_c to infinity.
196  //This is the only data that the breakup handler needs to do the breakup.
197  //We temporarily store it in Fk, which is replaced with the full FT (0->inf)
198  //of V_l(r) after the breakup has been done.
199  fillXk(breakuphandler.KList);
200  //Allocate the space for the coefficients.
201  coefs.resize(Basis.NumBasisElem()); //This must be after SetupKVecs.
202  breakuphandler.DoBreakup(Fk.data(), coefs.data()); //Fill array of coefficients.
203  }
204 
205  void fillXk(std::vector<TinyVector<mRealType, 2>>& KList)
206  {
207  Fk.resize(KList.size());
208  for (int ki = 0; ki < KList.size(); ki++)
209  {
210  mRealType k = KList[ki][0];
211  Fk[ki] = evalXk(k); //Call derived fn.
212  }
213  }
214 
215  void fillFk(const KContainer& KList)
216  {
217  Fk.resize(KList.kpts_cart.size());
218  const std::vector<int>& kshell(KList.kshell);
219  if (MaxKshell >= kshell.size())
220  MaxKshell = kshell.size() - 1;
222  // std::cout<<"Filling FK :"<<std::endl;
223  for (int ks = 0, ki = 0; ks < Fk_symm.size(); ks++)
224  {
225  mRealType k = std::pow(KList.ksq[ki], 0.5);
226  mRealType uk = evalFk(k);
227  Fk_symm[ks] = uk;
228  // std::cout<<uk<<std::endl;
229  while (ki < KList.kshell[ks + 1] && ki < Fk.size())
230  Fk[ki++] = uk;
231  }
232  //for(int ki=0; ki<KList.kpts_cart.size(); ki++){
233  // mRealType k=dot(KList.kpts_cart[ki],KList.kpts_cart[ki]);
234  // k=std::sqrt(k);
235  // Fk[ki] = evalFk(k); //Call derived fn.
236  //}
237  }
238 };
239 } // namespace qmcplusplus
240 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
a class that defines a supercell in D-dimensional Euclean space.
std::vector< PosType > kpts_cart
K-vector in Cartesian coordinates.
Definition: KContainer.h:53
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
void resetTargetParticleSet(ParticleSet &ref) override
void initBreakup(ParticleSet &ref) override
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
LRRPABFeeHandlerTemp(ParticleSet &ref, mRealType kc_in=-1.0)
mRealType LR_kc
Maximum k cutoff.
Definition: LRHandlerBase.h:37
std::ostream & app_log()
Definition: OutputManager.h:65
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > ParticleLayout
Definition: Configuration.h:79
int SetupKVecs(mRealType kc, mRealType kcont, mRealType kmax)
setup KList
Definition: LRBreakup.h:333
LRRPABFeeHandlerTemp(const LRRPABFeeHandlerTemp &aLR, ParticleSet &ref)
"copy" constructor
DECLARE_COULOMB_TYPES int MaxKshell
Maxkimum Kshell for the given Kc.
Definition: LRHandlerBase.h:35
EwaldHandler3D::mRealType mRealType
void fillFk(const KContainer &KList)
std::vector< mRealType > coefs
Fourier component for each k-shell Coefficient.
Definition: LRHandlerBase.h:53
void Breakup(ParticleSet &ref, mRealType rs_ext) override
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
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
mRealType evaluateLR(mRealType r) const override
evaluate the contribution from the long-range part for for spline
mRealType evalXk(mRealType k) const
mRealType LR_rc
Maximum r cutoff.
Definition: LRHandlerBase.h:39
LRHandlerBase * makeClone(ParticleSet &ref) const override
make clone
mRealType evaluate(mRealType r, mRealType rinv) const override
void resetTargetParticleSet(ParticleSet &ref, mRealType rs)
Container for k-points.
Definition: KContainer.h:29
std::vector< int > kshell
kpts which belong to the ith-shell [kshell[i], kshell[i+1])
Definition: KContainer.h:61
Vector< mRealType > Fk
Fourier component for all the k-point.
Definition: LRHandlerBase.h:41
#define DECLARE_COULOMB_TYPES
Definition: coulomb_types.h:18
mRealType DoBreakup(mRealType *Fk, mRealType *t, mRealType *adjust)
Definition: LRBreakup.h:389
std::vector< RealType > ksq
squre of kpts in Cartesian coordniates
Definition: KContainer.h:56
mRealType srDf(mRealType r, mRealType rinv) const override
evaluate the first derivative of the short range part at r
void fillXk(std::vector< TinyVector< mRealType, 2 >> &KList)
mRealType evaluate_vlr_k(mRealType k) const override
const auto & getLattice() const
Definition: ParticleSet.h:251
base class for LRHandlerTemp<FUNC,BASIS> and DummyLRHanlder<typename Func>
Definition: LRHandlerBase.h:30
void InitBreakup(const ParticleLayout &ref, int NumFunctions)
Initialise the basis and coefficients for the long-range beakup.
mRealType evalFk(mRealType k) const
std::vector< TinyVector< mRealType, 2 > > KList
For each k, KList[k][0] = |k| and KList[k][1] = degeneracy.
Definition: LRBreakup.h:44
Define LRHandlerBase and DummyLRHandler<typename Func>
Vector< mRealType > Fk_symm
Fourier component for each k-shell.
Definition: LRHandlerBase.h:49