From a8b908f439c72dc636c7140bd878757255f8c220 Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Fri, 4 May 2018 16:07:14 -0500 Subject: [PATCH 1/3] Reimplement WaveFunction to be generic. --- src/Drivers/miniqmc.cpp | 8 +- src/QMCWaveFunctions/Determinant.h | 2 +- src/QMCWaveFunctions/DeterminantRef.h | 2 +- src/QMCWaveFunctions/WaveFunction.cpp | 130 +++++++++++++---------- src/QMCWaveFunctions/WaveFunction.h | 30 +++--- src/QMCWaveFunctions/WaveFunctionRef.cpp | 4 +- 6 files changed, 98 insertions(+), 78 deletions(-) diff --git a/src/Drivers/miniqmc.cpp b/src/Drivers/miniqmc.cpp index 1a30f3ef7..ea4b917d2 100644 --- a/src/Drivers/miniqmc.cpp +++ b/src/Drivers/miniqmc.cpp @@ -379,11 +379,13 @@ int main(int argc, char **argv) } else { - wavefunction = new WaveFunction(ions, els, random_th, enableJ3); + WaveFunction *WFtemp = new WaveFunction(); + wavefunction = WFtemp; + build_WaveFunction(false, *WFtemp, ions, els, random_th, enableJ3); } // set Rmax for ion-el distance table for PP - wavefunction->setRmax(Rmax); + els.DistTables[wavefunction->ei_TableID]->setRmax(Rmax); // create pseudopp NonLocalPP ecp(random_th); @@ -484,7 +486,7 @@ int main(int argc, char **argv) // Compute NLPP energy using integral over spherical points ecp.randomize(rOnSphere); // pick random sphere - const DistanceTableData *d_ie = wavefunction->d_ie; + const DistanceTableData *d_ie = els.DistTables[wavefunction->ei_TableID]; Timers[Timer_ECP]->start(); for (int iat = 0; iat < nions; ++iat) diff --git a/src/QMCWaveFunctions/Determinant.h b/src/QMCWaveFunctions/Determinant.h index c9d830ccf..28f691a97 100644 --- a/src/QMCWaveFunctions/Determinant.h +++ b/src/QMCWaveFunctions/Determinant.h @@ -179,7 +179,7 @@ void checkDiff(const MT1 &a, const MT2 &b, const std::string &tag) struct DiracDeterminant : public WaveFunctionComponentBase { - DiracDeterminant(int nels, RandomGenerator &RNG, int First=0) + DiracDeterminant(int nels, const RandomGenerator &RNG, int First=0) : FirstIndex(First), myRandom(RNG) { psiMinv.resize(nels, nels); diff --git a/src/QMCWaveFunctions/DeterminantRef.h b/src/QMCWaveFunctions/DeterminantRef.h index 5dc5bc955..d7259802b 100644 --- a/src/QMCWaveFunctions/DeterminantRef.h +++ b/src/QMCWaveFunctions/DeterminantRef.h @@ -184,7 +184,7 @@ struct DiracDeterminantRef : public qmcplusplus::WaveFunctionComponentBase { using ParticleSet = qmcplusplus::ParticleSet; - DiracDeterminantRef(int nels, qmcplusplus::RandomGenerator &RNG, int First=0) + DiracDeterminantRef(int nels, const qmcplusplus::RandomGenerator &RNG, int First=0) : FirstIndex(First), myRandom(RNG) { psiMinv.resize(nels, nels); diff --git a/src/QMCWaveFunctions/WaveFunction.cpp b/src/QMCWaveFunctions/WaveFunction.cpp index 4413814ff..be2b7d34e 100644 --- a/src/QMCWaveFunctions/WaveFunction.cpp +++ b/src/QMCWaveFunctions/WaveFunction.cpp @@ -19,48 +19,73 @@ namespace qmcplusplus { -WaveFunction::WaveFunction(ParticleSet &ions, ParticleSet &els, - RandomGenerator &RNG, bool enableJ3) -{ - FirstTime = true; - - ions.RSoA = ions.R; - els.RSoA = els.R; - - // distance tables - d_ee = DistanceTable::add(els, DT_SOA); - d_ie = DistanceTable::add(ions, els, DT_SOA); - // determinant component - nelup = els.getTotalNum()/2; - Det_up = new DetType(nelup, RNG, 0); - Det_dn = new DetType(els.getTotalNum()-nelup, RNG, nelup); +void build_WaveFunction(bool useRef, WaveFunction &WF, ParticleSet &ions, ParticleSet &els, const RandomGenerator &RNG, bool enableJ3) +{ + using valT = WaveFunction::valT; + using posT = WaveFunction::posT; - // J1 component - J1 = new J1OrbType(ions, els); - buildJ1(*J1, els.Lattice.WignerSeitzRadius); + if(WF.Is_built) + { + app_log() << "The wavefunction was built before!" << std::endl; + return; + } - // J2 component - J2 = new J2OrbType(els); - buildJ2(*J2, els.Lattice.WignerSeitzRadius); + const int nelup = els.getTotalNum()/2; - // J3 component - if(enableJ3) + if(useRef) { - J3 = new J3OrbType(ions, els); - buildJeeI(*J3, els.Lattice.WignerSeitzRadius); } else - J3 = nullptr; + { + using J1OrbType = OneBodyJastrow>; + using J2OrbType = TwoBodyJastrow>; + using J3OrbType = ThreeBodyJastrow; + using DetType = DiracDeterminant; + + ions.RSoA = ions.R; + els.RSoA = els.R; + + // distance tables + els.addTable(els, DT_SOA); + WF.ei_TableID = els.addTable(ions, DT_SOA); + + // determinant component + WF.nelup = nelup; + WF.Det_up = new DetType(nelup, RNG, 0); + WF.Det_dn = new DetType(els.getTotalNum()-nelup, RNG, nelup); + + // J1 component + J1OrbType *J1 = new J1OrbType(ions, els); + buildJ1(*J1, els.Lattice.WignerSeitzRadius); + WF.Jastrows.push_back(J1); + + // J2 component + J2OrbType *J2 = new J2OrbType(els); + buildJ2(*J2, els.Lattice.WignerSeitzRadius); + WF.Jastrows.push_back(J2); + + // J3 component + if(enableJ3) + { + J3OrbType *J3 = new J3OrbType(ions, els); + buildJeeI(*J3, els.Lattice.WignerSeitzRadius); + WF.Jastrows.push_back(J3); + } + } + + WF.Is_built = true; } WaveFunction::~WaveFunction() { - delete Det_up; - delete Det_dn; - delete J1; - delete J2; - if(J3) delete J3; + if (Is_built) + { + delete Det_up; + delete Det_dn; + for(size_t i=0; ievaluateLog(P, P.G, P.L); - LogValue += Det_dn->evaluateLog(P, P.G, P.L); - LogValue += J1->evaluateLog(P, P.G, P.L); - LogValue += J2->evaluateLog(P, P.G, P.L); - if(J3) LogValue += J3->evaluateLog(P, P.G, P.L); + LogValue = Det_up -> evaluateLog(P, P.G, P.L); + LogValue += Det_dn -> evaluateLog(P, P.G, P.L); + for(size_t i=0; ievaluateLog(P, P.G, P.L); FirstTime = false; } } WaveFunctionBase::posT WaveFunction::evalGrad(ParticleSet &P, int iat) { - return ( iatevalGrad(P, iat) : Det_dn->evalGrad(P, iat) ) - + J1->evalGrad(P, iat) - + J2->evalGrad(P, iat) - + (J3?J3->evalGrad(P, iat):posT(0)); + posT grad_iat = ( iatevalGrad(P, iat) : Det_dn->evalGrad(P, iat) ); + for(size_t i=0; ievalGrad(P, iat); + return grad_iat; } WaveFunctionBase::valT WaveFunction::ratioGrad(ParticleSet &P, int iat, posT &grad) { - return ( iatratioGrad(P, iat, grad) : Det_dn->ratioGrad(P, iat, grad) ) - * J1->ratioGrad(P, iat, grad) - * J2->ratioGrad(P, iat, grad) - * (J3?J3->ratioGrad(P, iat, grad):1.0); + valT ratio = ( iatratioGrad(P, iat, grad) : Det_dn->ratioGrad(P, iat, grad) ); + for(size_t i=0; iratioGrad(P, iat, grad); + return ratio; } WaveFunctionBase::valT WaveFunction::ratio(ParticleSet &P, int iat) { - return ( iatratio(P, iat) : Det_dn->ratio(P, iat) ) - * J1->ratio(P, iat) - * J2->ratio(P, iat) - * (J3?J3->ratio(P, iat):1.0); + valT ratio = ( iatratio(P, iat) : Det_dn->ratio(P, iat) ); + for(size_t i=0; iratio(P, iat); + return ratio; } void WaveFunction::acceptMove(ParticleSet &P, int iat) @@ -110,9 +134,8 @@ void WaveFunction::acceptMove(ParticleSet &P, int iat) Det_up->acceptMove(P, iat); else Det_dn->acceptMove(P, iat); - J1->acceptMove(P, iat); - J2->acceptMove(P, iat); - if(J3) J3->acceptMove(P, iat); + for(size_t i=0; iacceptMove(P, iat); } void WaveFunction::restore(int iat) {} @@ -124,8 +147,7 @@ void WaveFunction::evaluateGL(ParticleSet &P) P.L = czero; Det_up->evaluateGL(P, P.G, P.L); Det_dn->evaluateGL(P, P.G, P.L); - J1->evaluateGL(P, P.G, P.L); - J2->evaluateGL(P, P.G, P.L); - if(J3) J3->evaluateGL(P, P.G, P.L); + for(size_t i=0; ievaluateGL(P, P.G, P.L); } } // qmcplusplus diff --git a/src/QMCWaveFunctions/WaveFunction.h b/src/QMCWaveFunctions/WaveFunction.h index ca84d815b..c4fe28a4a 100644 --- a/src/QMCWaveFunctions/WaveFunction.h +++ b/src/QMCWaveFunctions/WaveFunction.h @@ -47,11 +47,9 @@ struct WaveFunctionBase typedef OHMMS_PRECISION RealType; valT LogValue; - DistanceTableData *d_ee; - DistanceTableData *d_ie; - - inline void setRmax(valT x) { d_ie->setRmax(x); } + int ei_TableID; + WaveFunctionBase(): ei_TableID(0) {}; virtual ~WaveFunctionBase() {} virtual void evaluateLog(ParticleSet &P) = 0; virtual posT evalGrad(ParticleSet &P, int iat) = 0; @@ -64,21 +62,17 @@ struct WaveFunctionBase struct WaveFunction : public WaveFunctionBase { - using J1OrbType = OneBodyJastrow>; - using J2OrbType = TwoBodyJastrow>; - using J3OrbType = ThreeBodyJastrow; - using DetType = DiracDeterminant; + friend void build_WaveFunction(bool useRef, WaveFunction &WF, ParticleSet &ions, ParticleSet &els, const RandomGenerator &RNG, bool enableJ3); - bool FirstTime; - J1OrbType *J1; - J2OrbType *J2; - J3OrbType *J3; + private: + std::vector Jastrows; + WaveFunctionComponentBase *Det_up; + WaveFunctionComponentBase *Det_dn; + bool FirstTime, Is_built; int nelup; - DetType *Det_up; - DetType *Det_dn; - WaveFunction(ParticleSet &ions, ParticleSet &els, - RandomGenerator &RNG, bool enableJ3); + public: + WaveFunction(): FirstTime(true), Is_built(false), nelup(0), Det_up(nullptr), Det_dn(nullptr) { } ~WaveFunction(); void evaluateLog(ParticleSet &P); posT evalGrad(ParticleSet &P, int iat); @@ -89,6 +83,8 @@ struct WaveFunction : public WaveFunctionBase void evaluateGL(ParticleSet &P); }; +void build_WaveFunction(bool useRef, WaveFunction &WF, ParticleSet &ions, ParticleSet &els, const RandomGenerator &RNG, bool enableJ3); + } // qmcplusplus namespace miniqmcreference @@ -105,10 +101,10 @@ struct WaveFunctionRef : public qmcplusplus::WaveFunctionBase using DetType = DiracDeterminantRef; bool FirstTime; + int nelup; J1OrbType *J1; J2OrbType *J2; J3OrbType *J3; - int nelup; DetType *Det_up; DetType *Det_dn; PooledData Buffer; diff --git a/src/QMCWaveFunctions/WaveFunctionRef.cpp b/src/QMCWaveFunctions/WaveFunctionRef.cpp index d4033b820..d3030a1d1 100644 --- a/src/QMCWaveFunctions/WaveFunctionRef.cpp +++ b/src/QMCWaveFunctions/WaveFunctionRef.cpp @@ -34,8 +34,8 @@ WaveFunctionRef::WaveFunctionRef(ParticleSet &ions, ParticleSet &els, els.RSoA = els.R; // distance tables - d_ee = DistanceTable::add(els, DT_SOA); - d_ie = DistanceTable::add(ions, els, DT_SOA); + els.addTable(els, DT_SOA); + ei_TableID = els.addTable(ions, DT_SOA); // determinant component nelup = els.getTotalNum()/2; From b6288216f8d5dace8b1472ecd53d3048038e911f Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Fri, 4 May 2018 16:50:31 -0500 Subject: [PATCH 2/3] Merge WaveFunction{Base/Ref} as one WaveFunction. --- src/CMakeLists.txt | 1 - src/Drivers/CMakeLists.txt | 2 +- src/Drivers/check_wfc.cpp | 14 +-- src/Drivers/miniqmc.cpp | 17 +-- src/Particle/DistanceTable.cpp | 52 --------- src/Particle/DistanceTable.h | 11 -- src/QMCWaveFunctions/WaveFunction.cpp | 40 ++++++- src/QMCWaveFunctions/WaveFunction.h | 67 ++--------- src/QMCWaveFunctions/WaveFunctionRef.cpp | 137 ----------------------- 9 files changed, 60 insertions(+), 281 deletions(-) delete mode 100644 src/Particle/DistanceTable.cpp delete mode 100644 src/QMCWaveFunctions/WaveFunctionRef.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0e4c1d96f..818de39d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,7 +159,6 @@ ENDIF() Particle/ParticleSet.BC.cpp Particle/DistanceTableAA.cpp Particle/DistanceTableAB.cpp - Particle/DistanceTable.cpp ) diff --git a/src/Drivers/CMakeLists.txt b/src/Drivers/CMakeLists.txt index 8d82da9c1..9ddf6b244 100644 --- a/src/Drivers/CMakeLists.txt +++ b/src/Drivers/CMakeLists.txt @@ -10,7 +10,7 @@ FOREACH(p ${ESTEST}) TARGET_LINK_LIBRARIES(${p} qmcbase qmcutil ${QMC_UTIL_LIBS} ${MPI_LIBRARY}) ENDFOREACH(p ${ESTEST}) -ADD_LIBRARY(miniwfs ../QMCWaveFunctions/WaveFunctionRef.cpp ../QMCWaveFunctions/WaveFunction.cpp) +ADD_LIBRARY(miniwfs ../QMCWaveFunctions/WaveFunction.cpp) ADD_EXECUTABLE(miniqmc miniqmc.cpp) TARGET_LINK_LIBRARIES(miniqmc miniwfs qmcbase qmcutil ${QMC_UTIL_LIBS} ${MPI_LIBRARY}) diff --git a/src/Drivers/check_wfc.cpp b/src/Drivers/check_wfc.cpp index fd50af273..ccb635253 100644 --- a/src/Drivers/check_wfc.cpp +++ b/src/Drivers/check_wfc.cpp @@ -186,10 +186,10 @@ int main(int argc, char **argv) els_ref.RSoA = els_ref.R; // create tables - DistanceTable::add(els, DT_SOA); - DistanceTable::add(els_ref, DT_SOA); - DistanceTableData *d_ie = DistanceTable::add(ions, els_ref, DT_SOA); - d_ie->setRmax(Rmax); + els.addTable(els, DT_SOA); + els_ref.addTable(els_ref, DT_SOA); + const int ei_TableID = els_ref.addTable(ions, DT_SOA); + els_ref.DistTables[ei_TableID]->setRmax(Rmax); ParticlePos_t delta(nels); @@ -381,12 +381,12 @@ int main(int argc, char **argv) int nsphere = 0; for (int iat = 0; iat < nions; ++iat) { - for (int nj = 0, jmax = d_ie->nadj(iat); nj < jmax; ++nj) + for (int nj = 0, jmax = els_ref.DistTables[ei_TableID]->nadj(iat); nj < jmax; ++nj) { - const RealType r = d_ie->distance(iat, nj); + const RealType r = els_ref.DistTables[ei_TableID]->distance(iat, nj); if (r < Rmax) { - const int iel = d_ie->iadj(iat, nj); + const int iel = els_ref.DistTables[ei_TableID]->iadj(iat, nj); nsphere++; random_th.generate_uniform(&delta[0][0], nknots * 3); for (int k = 0; k < nknots; ++k) diff --git a/src/Drivers/miniqmc.cpp b/src/Drivers/miniqmc.cpp index ea4b917d2..0d78ba2f3 100644 --- a/src/Drivers/miniqmc.cpp +++ b/src/Drivers/miniqmc.cpp @@ -370,22 +370,15 @@ int main(int argc, char **argv) els.RSoA = els.R; } - WaveFunctionBase *wavefunction; + WaveFunction *wavefunction = new WaveFunction(); if (useRef) - { - wavefunction = - new miniqmcreference::WaveFunctionRef(ions, els, random_th, enableJ3); - } + build_WaveFunction(true, *wavefunction, ions, els, random_th, enableJ3); else - { - WaveFunction *WFtemp = new WaveFunction(); - wavefunction = WFtemp; - build_WaveFunction(false, *WFtemp, ions, els, random_th, enableJ3); - } + build_WaveFunction(false, *wavefunction, ions, els, random_th, enableJ3); // set Rmax for ion-el distance table for PP - els.DistTables[wavefunction->ei_TableID]->setRmax(Rmax); + els.DistTables[wavefunction->get_ei_TableID()]->setRmax(Rmax); // create pseudopp NonLocalPP ecp(random_th); @@ -486,7 +479,7 @@ int main(int argc, char **argv) // Compute NLPP energy using integral over spherical points ecp.randomize(rOnSphere); // pick random sphere - const DistanceTableData *d_ie = els.DistTables[wavefunction->ei_TableID]; + const DistanceTableData *d_ie = els.DistTables[wavefunction->get_ei_TableID()]; Timers[Timer_ECP]->start(); for (int iat = 0; iat < nions; ++iat) diff --git a/src/Particle/DistanceTable.cpp b/src/Particle/DistanceTable.cpp deleted file mode 100644 index b8fa0a316..000000000 --- a/src/Particle/DistanceTable.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source -// License. See LICENSE file in top directory for details. -// -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. -// -// File developed by: -// Ken Esler, kpesler@gmail.com, -// University of Illinois at Urbana-Champaign -// Jeremy McMinnis, jmcminis@gmail.com, -// University of Illinois at Urbana-Champaign -// Jeongnim Kim, jeongnim.kim@gmail.com, -// University of Illinois at Urbana-Champaign -// Jaron T. Krogel, krogeljt@ornl.gov, -// Oak Ridge National Laboratory -// Mark A. Berrill, berrillma@ornl.gov, -// Oak Ridge National Laboratory -// -// File created by: -// Jeongnim Kim, jeongnim.kim@gmail.com, -// University of Illinois at Urbana-Champaign -//////////////////////////////////////////////////////////////////////////////// - -#include "Particle/DistanceTable.h" -#include "Particle/DistanceTableData.h" -#include "Particle/Lattice/ParticleBConds.h" -namespace qmcplusplus -{ - -/** Adding SymmetricDTD to the list, e.g., el-el distance table - *\param s source/target particle set - *\return DistanceTableData* - */ -DistanceTableData *DistanceTable::add(ParticleSet &s, int dt_type) -{ - int tid = s.addTable(s, dt_type); - return s.DistTables[tid]; -} - -/** Adding AsymmetricDTD to the list, e.g., el-nuclei distance table - *\param s source particle set - *\param t target particle set - *\return DistanceTableData* - */ -DistanceTableData *DistanceTable::add(const ParticleSet &s, ParticleSet &t, - int dt_type) -{ - int tid = t.addTable(s, dt_type); - return t.DistTables[tid]; -} - -} // namespace qmcplusplus diff --git a/src/Particle/DistanceTable.h b/src/Particle/DistanceTable.h index 91e8a9044..93f8055d7 100644 --- a/src/Particle/DistanceTable.h +++ b/src/Particle/DistanceTable.h @@ -39,17 +39,6 @@ namespace qmcplusplus *DistanceTable * to generically control the crystalline structure. */ -// struct DistanceTable -namespace DistanceTable -{ -/// add a named DistanceTableData_t of Symmectric type -DistanceTableData *add(ParticleSet &s, - int dt_type); //, const char* aname = NULL); - -/// add a named DistanceTableData_t of Asymmectric type -DistanceTableData *add(const ParticleSet &s, ParticleSet &t, - int dt_type); //, const char* aname = NULL); -} /// free function to create a distable table of s-s DistanceTableData *createDistanceTable(ParticleSet &s, int dt_type); diff --git a/src/QMCWaveFunctions/WaveFunction.cpp b/src/QMCWaveFunctions/WaveFunction.cpp index be2b7d34e..73d57fd59 100644 --- a/src/QMCWaveFunctions/WaveFunction.cpp +++ b/src/QMCWaveFunctions/WaveFunction.cpp @@ -35,6 +35,40 @@ void build_WaveFunction(bool useRef, WaveFunction &WF, ParticleSet &ions, Partic if(useRef) { + using J1OrbType = miniqmcreference::OneBodyJastrowRef>; + using J2OrbType = miniqmcreference::TwoBodyJastrowRef>; + using J3OrbType = miniqmcreference::ThreeBodyJastrowRef; + using DetType = miniqmcreference::DiracDeterminantRef; + + ions.RSoA = ions.R; + els.RSoA = els.R; + + // distance tables + els.addTable(els, DT_SOA); + WF.ei_TableID = els.addTable(ions, DT_SOA); + + // determinant component + WF.nelup = nelup; + WF.Det_up = new DetType(nelup, RNG, 0); + WF.Det_dn = new DetType(els.getTotalNum()-nelup, RNG, nelup); + + // J1 component + J1OrbType *J1 = new J1OrbType(ions, els); + buildJ1(*J1, els.Lattice.WignerSeitzRadius); + WF.Jastrows.push_back(J1); + + // J2 component + J2OrbType *J2 = new J2OrbType(els); + buildJ2(*J2, els.Lattice.WignerSeitzRadius); + WF.Jastrows.push_back(J2); + + // J3 component + if(enableJ3) + { + J3OrbType *J3 = new J3OrbType(ions, els); + buildJeeI(*J3, els.Lattice.WignerSeitzRadius); + WF.Jastrows.push_back(J3); + } } else { @@ -103,7 +137,7 @@ void WaveFunction::evaluateLog(ParticleSet &P) } } -WaveFunctionBase::posT WaveFunction::evalGrad(ParticleSet &P, int iat) +WaveFunction::posT WaveFunction::evalGrad(ParticleSet &P, int iat) { posT grad_iat = ( iatevalGrad(P, iat) : Det_dn->evalGrad(P, iat) ); for(size_t i=0; iratioGrad(P, iat, grad) : Det_dn->ratioGrad(P, iat, grad) ); @@ -120,7 +154,7 @@ WaveFunctionBase::valT WaveFunction::ratioGrad(ParticleSet &P, int iat, return ratio; } -WaveFunctionBase::valT WaveFunction::ratio(ParticleSet &P, int iat) +WaveFunction::valT WaveFunction::ratio(ParticleSet &P, int iat) { valT ratio = ( iatratio(P, iat) : Det_dn->ratio(P, iat) ); for(size_t i=0; i; - typedef OHMMS_PRECISION RealType; - - valT LogValue; - int ei_TableID; - WaveFunctionBase(): ei_TableID(0) {}; - virtual ~WaveFunctionBase() {} - virtual void evaluateLog(ParticleSet &P) = 0; - virtual posT evalGrad(ParticleSet &P, int iat) = 0; - virtual valT ratioGrad(ParticleSet &P, int iat, posT &grad) = 0; - virtual valT ratio(ParticleSet &P, int iat) = 0; - virtual void acceptMove(ParticleSet &P, int iat) = 0; - virtual void restore(int iat) = 0; - virtual void evaluateGL(ParticleSet &P) = 0; -}; - -struct WaveFunction : public WaveFunctionBase +struct WaveFunction { friend void build_WaveFunction(bool useRef, WaveFunction &WF, ParticleSet &ions, ParticleSet &els, const RandomGenerator &RNG, bool enableJ3); + using RealType = OHMMS_PRECISION; + using valT = OHMMS_PRECISION; + using posT = TinyVector; + private: std::vector Jastrows; WaveFunctionComponentBase *Det_up; WaveFunctionComponentBase *Det_dn; + valT LogValue; + bool FirstTime, Is_built; - int nelup; + int nelup, ei_TableID; public: - WaveFunction(): FirstTime(true), Is_built(false), nelup(0), Det_up(nullptr), Det_dn(nullptr) { } + WaveFunction(): FirstTime(true), Is_built(false), nelup(0), ei_TableID(1), Det_up(nullptr), Det_dn(nullptr) { } ~WaveFunction(); void evaluateLog(ParticleSet &P); posT evalGrad(ParticleSet &P, int iat); @@ -81,45 +68,11 @@ struct WaveFunction : public WaveFunctionBase void acceptMove(ParticleSet &P, int iat); void restore(int iat); void evaluateGL(ParticleSet &P); + int get_ei_TableID() const {return ei_TableID;} }; void build_WaveFunction(bool useRef, WaveFunction &WF, ParticleSet &ions, ParticleSet &els, const RandomGenerator &RNG, bool enableJ3); } // qmcplusplus -namespace miniqmcreference -{ -/** A minimial TrialWaveFunction - the reference version. - */ -using namespace qmcplusplus; -struct WaveFunctionRef : public qmcplusplus::WaveFunctionBase -{ - - using J1OrbType = OneBodyJastrow>; - using J2OrbType = TwoBodyJastrow>; - using J3OrbType = ThreeBodyJastrow; - using DetType = DiracDeterminantRef; - - bool FirstTime; - int nelup; - J1OrbType *J1; - J2OrbType *J2; - J3OrbType *J3; - DetType *Det_up; - DetType *Det_dn; - PooledData Buffer; - - WaveFunctionRef(ParticleSet &ions, ParticleSet &els, - RandomGenerator &RNG, bool enableJ3); - ~WaveFunctionRef(); - void evaluateLog(ParticleSet &P); - posT evalGrad(ParticleSet &P, int iat); - valT ratioGrad(ParticleSet &P, int iat, posT &grad); - valT ratio(ParticleSet &P, int iat); - void acceptMove(ParticleSet &P, int iat); - void restore(int iat); - void evaluateGL(ParticleSet &P); -}; -} // miniqmcreference - #endif diff --git a/src/QMCWaveFunctions/WaveFunctionRef.cpp b/src/QMCWaveFunctions/WaveFunctionRef.cpp deleted file mode 100644 index d3030a1d1..000000000 --- a/src/QMCWaveFunctions/WaveFunctionRef.cpp +++ /dev/null @@ -1,137 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source -// License. See LICENSE file in top directory for details. -// -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. -// -// File developed by: -// -// File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp. -//////////////////////////////////////////////////////////////////////////////// -// -*- C++ -*- -#include -#include - -/*! - * @file WaveFunctionRef.cpp - * @brief Wavefunction based on reference implemenation - */ - -/*! - * Namespace containing reference implementation. - */ - -namespace miniqmcreference -{ -using namespace qmcplusplus; - -WaveFunctionRef::WaveFunctionRef(ParticleSet &ions, ParticleSet &els, - RandomGenerator &RNG, bool enableJ3) -{ - FirstTime = true; - - ions.RSoA = ions.R; - els.RSoA = els.R; - - // distance tables - els.addTable(els, DT_SOA); - ei_TableID = els.addTable(ions, DT_SOA); - - // determinant component - nelup = els.getTotalNum()/2; - Det_up = new DetType(nelup, RNG, 0); - Det_dn = new DetType(els.getTotalNum()-nelup, RNG, nelup); - - // J1 component - J1 = new J1OrbType(ions, els); - buildJ1(*J1, els.Lattice.WignerSeitzRadius); - - // J2 component - J2 = new J2OrbType(els); - buildJ2(*J2, els.Lattice.WignerSeitzRadius); - - // J3 component - if(enableJ3) - { - J3 = new J3OrbType(ions, els); - buildJeeI(*J3, els.Lattice.WignerSeitzRadius); - } - else - J3 = nullptr; -} - -WaveFunctionRef::~WaveFunctionRef() -{ - delete Det_up; - delete Det_dn; - delete J1; - delete J2; - if(J3) delete J3; -} - -void WaveFunctionRef::evaluateLog(ParticleSet &P) -{ - constexpr valT czero(0); - if (FirstTime) - { - P.G = czero; - P.L = czero; - LogValue = Det_up->evaluateLog(P, P.G, P.L); - LogValue += Det_dn->evaluateLog(P, P.G, P.L); - LogValue += J1->evaluateLog(P, P.G, P.L); - LogValue += J2->evaluateLog(P, P.G, P.L); - if(J3) LogValue += J3->evaluateLog(P, P.G, P.L); - FirstTime = false; - } -} - -WaveFunctionBase::posT WaveFunctionRef::evalGrad(ParticleSet &P, int iat) -{ - return ( iatevalGrad(P, iat) : Det_dn->evalGrad(P, iat) ) - + J1->evalGrad(P, iat) - + J2->evalGrad(P, iat) - + (J3?J3->evalGrad(P, iat):posT()); -} - -WaveFunctionBase::valT WaveFunctionRef::ratioGrad(ParticleSet &P, int iat, - posT &grad) -{ - return ( iatratioGrad(P, iat, grad) : Det_dn->ratioGrad(P, iat, grad) ) - * J1->ratioGrad(P, iat, grad) - * J2->ratioGrad(P, iat, grad) - * (J3?J3->ratioGrad(P, iat, grad):1.0); -} - -WaveFunctionBase::valT WaveFunctionRef::ratio(ParticleSet &P, int iat) -{ - return ( iatratio(P, iat) : Det_dn->ratio(P, iat) ) - * J1->ratio(P, iat) - * J2->ratio(P, iat) - * (J3?J3->ratio(P, iat):1.0); -} - -void WaveFunctionRef::acceptMove(ParticleSet &P, int iat) -{ - if(iatacceptMove(P, iat); - else - Det_dn->acceptMove(P, iat); - J1->acceptMove(P, iat); - J2->acceptMove(P, iat); - if(J3) J3->acceptMove(P, iat); -} - -void WaveFunctionRef::restore(int iat) {} - -void WaveFunctionRef::evaluateGL(ParticleSet &P) -{ - constexpr valT czero(0); - P.G = czero; - P.L = czero; - Det_up->evaluateGL(P, P.G, P.L); - Det_dn->evaluateGL(P, P.G, P.L); - J1->evaluateGL(P, P.G, P.L); - J2->evaluateGL(P, P.G, P.L); - if(J3) J3->evaluateGL(P, P.G, P.L); -} -} // miniqmcreferencce From bc8faa7eb1cb6ac11c6bbf6e012abd27e5ebceab Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Fri, 4 May 2018 17:30:35 -0500 Subject: [PATCH 3/3] Allows accessing the reference implementation. --- src/Drivers/miniqmc.cpp | 6 +++++- src/QMCWaveFunctions/WaveFunction.cpp | 4 ++++ src/QMCWaveFunctions/WaveFunction.h | 3 ++- src/QMCWaveFunctions/WaveFunctionComponentBase.h | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Drivers/miniqmc.cpp b/src/Drivers/miniqmc.cpp index 0d78ba2f3..00ee014a0 100644 --- a/src/Drivers/miniqmc.cpp +++ b/src/Drivers/miniqmc.cpp @@ -155,6 +155,7 @@ void print_help() app_summary() << " miniqmc [-hjvV] [-g \"n0 n1 n2\"] [-m meshfactor]" << '\n'; app_summary() << " [-n steps] [-N substeps] [-r rmax] [-s seed]" << '\n'; app_summary() << "options:" << '\n'; + app_summary() << " -b use reference implementations default: off" << '\n'; app_summary() << " -g set the 3D tiling. default: 1 1 1" << '\n'; app_summary() << " -h print help and exit" << '\n'; app_summary() << " -j enable three body Jastrow default: off" << '\n'; @@ -210,11 +211,14 @@ int main(int argc, char **argv) int opt; while(optind < argc) { - if ((opt = getopt(argc, argv, "hjvVa:c:g:m:n:N:r:s:")) != -1) + if ((opt = getopt(argc, argv, "bhjvVa:c:g:m:n:N:r:s:")) != -1) { switch (opt) { case 'a': tileSize = atoi(optarg); break; + case 'b': + useRef = true; + break; case 'c': // number of members per team team_size = atoi(optarg); break; diff --git a/src/QMCWaveFunctions/WaveFunction.cpp b/src/QMCWaveFunctions/WaveFunction.cpp index 73d57fd59..8e463765b 100644 --- a/src/QMCWaveFunctions/WaveFunction.cpp +++ b/src/QMCWaveFunctions/WaveFunction.cpp @@ -181,7 +181,11 @@ void WaveFunction::evaluateGL(ParticleSet &P) P.L = czero; Det_up->evaluateGL(P, P.G, P.L); Det_dn->evaluateGL(P, P.G, P.L); + LogValue = Det_up->LogValue + Det_dn->LogValue; for(size_t i=0; ievaluateGL(P, P.G, P.L); + LogValue += Jastrows[i]->LogValue; + } } } // qmcplusplus diff --git a/src/QMCWaveFunctions/WaveFunction.h b/src/QMCWaveFunctions/WaveFunction.h index 0289e5a9a..8cb13942b 100644 --- a/src/QMCWaveFunctions/WaveFunction.h +++ b/src/QMCWaveFunctions/WaveFunction.h @@ -59,7 +59,7 @@ struct WaveFunction int nelup, ei_TableID; public: - WaveFunction(): FirstTime(true), Is_built(false), nelup(0), ei_TableID(1), Det_up(nullptr), Det_dn(nullptr) { } + WaveFunction(): FirstTime(true), Is_built(false), nelup(0), ei_TableID(1), Det_up(nullptr), Det_dn(nullptr), LogValue(0.0) { } ~WaveFunction(); void evaluateLog(ParticleSet &P); posT evalGrad(ParticleSet &P, int iat); @@ -69,6 +69,7 @@ struct WaveFunction void restore(int iat); void evaluateGL(ParticleSet &P); int get_ei_TableID() const {return ei_TableID;} + valT getLogValue() const {return LogValue;} }; void build_WaveFunction(bool useRef, WaveFunction &WF, ParticleSet &ions, ParticleSet &els, const RandomGenerator &RNG, bool enableJ3); diff --git a/src/QMCWaveFunctions/WaveFunctionComponentBase.h b/src/QMCWaveFunctions/WaveFunctionComponentBase.h index fc5c1fde2..dff92ffa8 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponentBase.h +++ b/src/QMCWaveFunctions/WaveFunctionComponentBase.h @@ -107,7 +107,7 @@ struct WaveFunctionComponentBase : public QMCTraits /// default constructor WaveFunctionComponentBase() : IsOptimizing(false), Optimizable(true), UpdateMode(ORB_WALKER), - LogValue(1.0), PhaseValue(0.0), WaveFunctionComponentName("WaveFunctionComponentBase") + LogValue(0.0), PhaseValue(0.0), WaveFunctionComponentName("WaveFunctionComponentBase") { } /// default destructor