From 4b4006bbabbc8106c8152c60200491d0fb8fe6a3 Mon Sep 17 00:00:00 2001 From: Raymond Clay Date: Mon, 17 Feb 2014 18:45:42 +0000 Subject: [PATCH] LRHandler for Natoli breakup git-svn-id: https://subversion.assembla.com/svn/qmcdev/trunk@6233 e5b18d87-469d-4833-9cc0-8cdfa06e9491 --- src/LongRange/LRHandlerSRCoulomb.h | 347 +++++++++++++++++++++++++++++ 1 file changed, 347 insertions(+) create mode 100644 src/LongRange/LRHandlerSRCoulomb.h diff --git a/src/LongRange/LRHandlerSRCoulomb.h b/src/LongRange/LRHandlerSRCoulomb.h new file mode 100644 index 000000000..1c3beb9ea --- /dev/null +++ b/src/LongRange/LRHandlerSRCoulomb.h @@ -0,0 +1,347 @@ +////////////////////////////////////////////////////////////////// +// (c) Copyright 2006- by Kris Delaney and Jeongnim Kim +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +// National Center for Supercomputing Applications & +// Materials Computation Center +// University of Illinois, Urbana-Champaign +// Urbana, IL 61801 +// e-mail: jnkim@ncsa.uiuc.edu +// +// Supported by +// National Center for Supercomputing Applications, UIUC +// Materials Computation Center, UIUC +////////////////////////////////////////////////////////////////// +// -*- C++ -*- +/** @file LRHandlerSRCoulomb.h + * @brief Define a LRHandler with two template parameters + */ +#ifndef QMCPLUSPLUS_LRHANLDERSRCOULOMBTEMP_H +#define QMCPLUSPLUS_LRHANLDERSRCOULOMBTEMP_H + +#include "LongRange/LRHandlerBase.h" +#include "LongRange/LPQHISRCoulombBasis.h" +#include "LongRange/LRBreakup.h" +#include "OhmmsPETE/OhmmsMatrix.h" + +namespace qmcplusplus +{ + +/* Templated LRHandler class + * + * LRHandlerSRCoulomb is a modification of LRHandler + * and a derived class from LRHanlderBase. Implements the LR breakup http://dx.doi.org/10.1006/jcph.1995.1054 . + * The first template parameter Func is a generic functor, e.g., CoulombFunctor. + * The second template parameter is a BreakupBasis and the default is set to LPQHIBasis. + * LRHandlerBase is introduced to enable run-time options. See RPAContstraints.h + */ +template +class LRHandlerSRCoulomb: public LRHandlerBase +{ + +public: + //Typedef for the lattice-type. + typedef ParticleSet::ParticleLayout_t ParticleLayout_t; + typedef BreakupBasis BreakupBasisType; + + bool FirstTime; + RealType rs; + BreakupBasisType Basis; //This needs a Lattice for the constructor... + Func myFunc; + + //Constructor + LRHandlerSRCoulomb(ParticleSet& ref, RealType kc_in=-1.0): + LRHandlerBase(kc_in),FirstTime(true), Basis(ref.LRBox) + { + myFunc.reset(ref); + } + + //LRHandlerSRCoulomb(ParticleSet& ref, RealType rs, RealType kc=-1.0): LRHandlerBase(kc), Basis(ref.LRBox) + //{ + // myFunc.reset(ref,rs); + //} + + /** "copy" constructor + * @param aLR LRHandlerSRCoulomb + * @param ref Particleset + * + * Copy the content of aLR + * References to ParticleSet or ParticleLayoutout_t are not copied. + */ + LRHandlerSRCoulomb(const LRHandlerSRCoulomb& aLR, ParticleSet& ref): + LRHandlerBase(aLR), FirstTime(true), Basis(aLR.Basis, ref.LRBox) + { + myFunc.reset(ref); + fillYk(ref.SK->KLists); + fillYkg(ref.SK->KLists); + } + + LRHandlerBase* makeClone(ParticleSet& ref) + { + return new LRHandlerSRCoulomb(*this,ref); + } + + void initBreakup(ParticleSet& ref) + { + InitBreakup(ref.LRBox,1); + fillYk(ref.SK->KLists); + fillYkg(ref.SK->KLists); + LR_rc=Basis.get_rc(); + } + + void Breakup(ParticleSet& ref, RealType rs_ext) + { + //ref.LRBox.Volume=ref.getTotalNum()*4.0*M_PI/3.0*rs*rs*rs; + rs=rs_ext; + myFunc.reset(ref,rs); + InitBreakup(ref.LRBox,1); + fillYk(ref.SK->KLists); + fillYkg(ref.SK->KLists); + LR_rc=Basis.get_rc(); + } + + void resetTargetParticleSet(ParticleSet& ref) + { + myFunc.reset(ref); + } + + void resetTargetParticleSet(ParticleSet& ref, RealType rs) + { + myFunc.reset(ref,rs); + } + + inline RealType evaluate(RealType r, RealType rinv) + { + RealType v=0.0; + for(int n=0; n breakuphandler(Basis); + //Find size of basis from cutoffs + RealType kc = (LR_kc<0)?ref.LR_kc:LR_kc; + //RealType kc(ref.LR_kc); //User cutoff parameter... + //kcut is the cutoff for switching to approximate k-point degeneracies for + //better performance in making the breakup. A good bet is 30*K-spacing so that + //there are 30 "boxes" in each direction that are treated with exact degeneracies. + //Assume orthorhombic cell just for deriving this cutoff - should be insensitive. + //K-Spacing = (kpt_vol)**1/3 = 2*pi/(cellvol**1/3) + RealType kcut = 60*M_PI*std::pow(Basis.get_CellVolume(),-1.0/3.0); + //Use 3000/LMax here...==6000/rc for non-ortho cells + RealType kmax(6000.0/ref.LR_rc); + MaxKshell = static_cast(breakuphandler.SetupKVecs(kc,kcut,kmax)); + if(FirstTime) + { + app_log() <<" finding kc: "<inf) + //of V_l(r) after the breakup has been done. + fillVk(breakuphandler.KList); + //Allocate the space for the coefficients. + IndexType Nbasis=Basis.NumBasisElem(); + coefs.resize(Nbasis); //This must be after SetupKVecs. + gcoefs.resize(Nbasis); + + //Going to implement a smooth real space cutoff. This means that alpha=0,1,2 for the LPQHI basis at knot r_c + //all equal the 0, 1st, and 2nd derivatives of our bare function. + //These three functions are the last three basis elements in our set. + + + + Vector constraints; + constraints.resize(Nbasis); + for (int i=0; i < Nbasis; i++) constraints[i]=1; + + + RealType rc=Basis.get_rc(); + + ///This is to make sure there's no cusp in the LR part. + gcoefs[0]=coefs[0] = 1.0; + constraints[0]=0; + gcoefs[1] = coefs[1] = 0.0; + constraints[1]=0; + + gcoefs[2] = coefs[2] = 0.0; + constraints[2]=0.0; + + //2nd derivative of SR will go to zero by setting LR at rc equal to the bare function. + // gcoefs[Nbasis-1]=myFunc.df2(rc); + + + gcoefs[Nbasis-1]=coefs[Nbasis-1]=0.0; + constraints[Nbasis-1]=0; + + //1st derivative + + gcoefs[Nbasis-2]=coefs[Nbasis-2]=0.0; + constraints[Nbasis-2]=0; + + //Function value + gcoefs[Nbasis-3]=coefs[Nbasis-3]=0.0; + constraints[Nbasis-3]=0; + //And now to impose the constraints + + + + chisqr_f=breakuphandler.DoBreakup(Fk.data(),coefs.data(),constraints.data()); //Fill array of coefficients. + chisqr_df=breakuphandler.DoGradBreakup(Fkg.data(), gcoefs.data(), constraints.data()); + + app_log()<<"LR function chi^2 = "< >& KList) + { + Fk.resize(KList.size()); + Fkg.resize(KList.size()); + for(int ki=0; ki& kshell(KList.kshell); + if(MaxKshell >= kshell.size()) + MaxKshell=kshell.size()-1; + Fk_symm.resize(MaxKshell); + for(int ks=0,ki=0; ks& kshell(KList.kshell); + if(MaxKshell >= kshell.size()) + MaxKshell=kshell.size()-1; + Fk_symmg.resize(MaxKshell); + for(int ks=0,ki=0; ks