Make NLPPJob standalone.

This commit is contained in:
Ye Luo 2020-01-10 18:06:15 +08:00
parent 1a269111d3
commit 7f59708ad8
5 changed files with 105 additions and 103 deletions

View File

@ -0,0 +1,46 @@
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2020 QMCPACK developers.
//
// File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
//
// File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
//////////////////////////////////////////////////////////////////////////////////////
#ifndef QMCPLUSPLUS_NLPPJob_H
#define QMCPLUSPLUS_NLPPJob_H
#include "OhmmsPETE/TinyVector.h"
namespace qmcplusplus
{
/** meta data for NLPP calculation of a pair of ion and electron
*/
template<typename T>
struct NLPPJob
{
using RealType = T;
using PosType = TinyVector<RealType, 3>;
const int ion_id;
const int electron_id;
const PosType elec_pos;
const RealType ion_elec_dist;
const PosType ion_elec_displ;
NLPPJob(const int ion_id_in,
const int electron_id_in,
const PosType& elec_pos_in,
const RealType ion_elec_dist_in,
const PosType& ion_elec_displ_in)
: ion_id(ion_id_in),
electron_id(electron_id_in),
elec_pos(elec_pos_in),
ion_elec_dist(ion_elec_dist_in),
ion_elec_displ(ion_elec_displ_in)
{}
};
} // namespace qmcplusplus
#endif

View File

@ -183,11 +183,8 @@ NonLocalECPComponent::RealType NonLocalECPComponent::calculateProjector(RealType
void NonLocalECPComponent::flex_evaluateOne(const RefVector<NonLocalECPComponent>& ecp_component_list,
const RefVector<ParticleSet>& p_list,
const std::vector<int>& iat_list,
const RefVector<TrialWaveFunction>& psi_list,
const std::vector<int>& iel_list,
const std::vector<RealType>& r_list,
const std::vector<PosType>& dr_list,
const RefVector<const NLPPJob<RealType>>& joblist,
std::vector<RealType>& pairpots,
bool use_DLA)
{
@ -201,14 +198,10 @@ void NonLocalECPComponent::flex_evaluateOne(const RefVector<NonLocalECPComponent
{
NonLocalECPComponent& component(ecp_component_list[i]);
ParticleSet& W(p_list[i]);
int iat(iat_list[i]);
int iel(iel_list[i]);
auto r = r_list[i];
auto& dr = dr_list[i];
const NLPPJob<RealType>& job = joblist[i];
component.buildQuadraturePointDeltaPositions(r, dr, component.deltaV);
component.VP->makeMoves(iel, W.R[iel], component.deltaV, true, iat);
component.buildQuadraturePointDeltaPositions(job.ion_elec_dist, job.ion_elec_displ, component.deltaV);
component.VP->makeMoves(job.electron_id, job.elec_pos, component.deltaV, true, job.ion_id);
}
RefVector<const VirtualParticleSet> vp_list;
@ -238,23 +231,20 @@ void NonLocalECPComponent::flex_evaluateOne(const RefVector<NonLocalECPComponent
NonLocalECPComponent& component(ecp_component_list[i]);
auto* VP = component.VP;
ParticleSet& W(p_list[i]);
int iat(iat_list[i]);
TrialWaveFunction& psi(psi_list[i]);
int iel(iel_list[i]);
auto r = r_list[i];
auto& dr = dr_list[i];
const NLPPJob<RealType>& job = joblist[i];
component.buildQuadraturePointDeltaPositions(r, dr, component.deltaV);
component.buildQuadraturePointDeltaPositions(job.ion_elec_dist, job.ion_elec_displ, component.deltaV);
// Compute ratio of wave functions
for (int j = 0; j < component.getNknot(); j++)
{
W.makeMove(iel, component.deltaV[j], false);
W.makeMove(job.electron_id, component.deltaV[j], false);
if (use_DLA)
component.psiratio[j] = psi.calcRatio(W, iel, TrialWaveFunction::ComputeType::FERMIONIC);
component.psiratio[j] = psi.calcRatio(W, job.electron_id, TrialWaveFunction::ComputeType::FERMIONIC);
else
component.psiratio[j] = psi.calcRatio(W, iel);
W.rejectMove(iel);
component.psiratio[j] = psi.calcRatio(W, job.electron_id);
W.rejectMove(job.electron_id);
psi.resetPhaseDiff();
}
}
@ -263,14 +253,14 @@ void NonLocalECPComponent::flex_evaluateOne(const RefVector<NonLocalECPComponent
for (size_t i = 0; i < p_list.size(); i++)
{
NonLocalECPComponent& component(ecp_component_list[i]);
auto r = r_list[i];
auto& dr = dr_list[i];
pairpots[i] = component.calculateProjector(r, dr);
const NLPPJob<RealType>& job = joblist[i];
pairpots[i] = component.calculateProjector(job.ion_elec_dist, job.ion_elec_displ);
}
}
else if (ecp_component_list.size() == 1)
pairpots[0] = ecp_component_list[0].get().evaluateOne(p_list[0], iat_list[0], psi_list[0], iel_list[0], r_list[0],
dr_list[0], use_DLA);
pairpots[0] = ecp_component_list[0].get().evaluateOne(p_list[0], joblist[0].get().ion_id, psi_list[0],
joblist[0].get().electron_id, joblist[0].get().ion_elec_dist,
joblist[0].get().ion_elec_displ, use_DLA);
}
NonLocalECPComponent::RealType NonLocalECPComponent::evaluateOneWithForces(ParticleSet& W,

View File

@ -17,6 +17,7 @@
#ifndef QMCPLUSPLUS_NONLOCAL_ECPOTENTIAL_COMPONENT_H
#define QMCPLUSPLUS_NONLOCAL_ECPOTENTIAL_COMPONENT_H
#include "QMCHamiltonians/OperatorBase.h"
#include "QMCHamiltonians/NLPPJob.h"
#include "QMCWaveFunctions/TrialWaveFunction.h"
#include "Numerics/OneDimGridBase.h"
#include "Numerics/OneDimGridFunctor.h"
@ -178,11 +179,8 @@ public:
*/
static void flex_evaluateOne(const RefVector<NonLocalECPComponent>& ecp_component_list,
const RefVector<ParticleSet>& p_list,
const std::vector<int>& iat_list,
const RefVector<TrialWaveFunction>& psi_list,
const std::vector<int>& iel_list,
const std::vector<RealType>& r_list,
const std::vector<PosType>& dr_list,
const RefVector<const NLPPJob<RealType>>& joblist,
std::vector<RealType>& pairpots,
bool use_DLA);

View File

@ -324,69 +324,59 @@ void NonLocalECPotential::mw_evaluateImpl(const RefVector<OperatorBase>& O_list,
RefVector<NonLocalECPotential> ecp_potential_list;
RefVector<NonLocalECPComponent> ecp_component_list;
RefVector<ParticleSet> p_list;
std::vector<int> iat_list;
RefVector<TrialWaveFunction> psi_list;
std::vector<int> jel_list;
std::vector<RealType> r_list;
std::vector<PosType> dr_list;
RefVector<const NLPPJob<RealType>> batch_list;
std::vector<RealType> pairpots(nw);
ecp_potential_list.reserve(nw);
ecp_component_list.reserve(nw);
p_list.reserve(nw);
iat_list.reserve(nw);
psi_list.reserve(nw);
jel_list.reserve(nw);
r_list.reserve(nw);
dr_list.reserve(nw);
batch_list.reserve(nw);
for (int ig = 0; ig < ngroups; ++ig) //loop over species
for (size_t jobid = 0; jobid < max_num_jobs[ig]; jobid++)
{
ecp_potential_list.clear();
ecp_component_list.clear();
p_list.clear();
iat_list.clear();
psi_list.clear();
jel_list.clear();
r_list.clear();
dr_list.clear();
for (size_t iw = 0; iw < nw; iw++)
for (size_t jobid = 0; jobid < max_num_jobs[ig]; jobid++)
{
NonLocalECPotential& O(static_cast<NonLocalECPotential&>(O_list[iw].get()));
ParticleSet& P(P_list[iw]);
if (jobid < O.nlpp_jobs[ig].size())
ecp_potential_list.clear();
ecp_component_list.clear();
p_list.clear();
psi_list.clear();
batch_list.clear();
for (size_t iw = 0; iw < nw; iw++)
{
const auto& job = O.nlpp_jobs[ig][jobid];
ecp_potential_list.push_back(O);
ecp_component_list.push_back(*O.PP[job.ion_id]);
p_list.push_back(P);
iat_list.push_back(job.ion_id);
psi_list.push_back(O.Psi);
jel_list.push_back(job.electron_id);
r_list.push_back(job.ion_elec_dist);
dr_list.push_back(job.ion_elec_displ);
NonLocalECPotential& O(static_cast<NonLocalECPotential&>(O_list[iw].get()));
ParticleSet& P(P_list[iw]);
if (jobid < O.nlpp_jobs[ig].size())
{
const auto& job = O.nlpp_jobs[ig][jobid];
ecp_potential_list.push_back(O);
ecp_component_list.push_back(*O.PP[job.ion_id]);
p_list.push_back(P);
psi_list.push_back(O.Psi);
batch_list.push_back(job);
}
}
NonLocalECPComponent::flex_evaluateOne(ecp_component_list, p_list, psi_list, batch_list, pairpots, use_DLA);
for (size_t j = 0; j < ecp_potential_list.size(); j++)
{
if (false)
{ // code usefully for debugging
RealType check_value = ecp_component_list[j].get().evaluateOne(p_list[j], batch_list[j].get().ion_id,
psi_list[j], batch_list[j].get().electron_id,
batch_list[j].get().ion_elec_dist,
batch_list[j].get().ion_elec_displ, use_DLA);
if (std::abs(check_value - pairpots[j]) > 1e-5)
std::cout << "check " << check_value << " wrong " << pairpots[j] << " diff "
<< std::abs(check_value - pairpots[j]) << std::endl;
}
ecp_potential_list[j].get().Value += pairpots[j];
if (Tmove)
ecp_component_list[j].get().contributeTxy(batch_list[j].get().electron_id,
ecp_potential_list[j].get().nonLocalOps.Txy);
}
}
NonLocalECPComponent::flex_evaluateOne(ecp_component_list, p_list, iat_list, psi_list, jel_list, r_list, dr_list,
pairpots, use_DLA);
for (size_t j = 0; j < ecp_potential_list.size(); j++)
{
if (false)
{ // code usefully for debugging
RealType check_value = ecp_component_list[j].get().evaluateOne(p_list[j], iat_list[j], psi_list[j], jel_list[j],
r_list[j], dr_list[j], use_DLA);
if (std::abs(check_value - pairpots[j]) > 1e-5)
std::cout << "check " << check_value << " wrong " << pairpots[j] << " diff "
<< std::abs(check_value - pairpots[j]) << std::endl;
}
ecp_potential_list[j].get().Value += pairpots[j];
if (Tmove)
ecp_component_list[j].get().contributeTxy(jel_list[j], ecp_potential_list[j].get().nonLocalOps.Txy);
}
}
}
NonLocalECPotential::Return_t NonLocalECPotential::evaluateWithIonDerivs(ParticleSet& P,

View File

@ -18,6 +18,7 @@
#define QMCPLUSPLUS_NONLOCAL_ECPOTENTIAL_H
#include "QMCHamiltonians/NonLocalTOperator.h"
#include "QMCHamiltonians/ForceBase.h"
#include "QMCHamiltonians/NLPPJob.h"
#include "Particle/NeighborLists.h"
namespace qmcplusplus
@ -30,29 +31,6 @@ class NonLocalECPComponent;
class NonLocalECPotential : public OperatorBase, public ForceBase
{
public:
/** meta data for NLPP calculation of a pair of ion and electron
*/
struct NLPPJob
{
const int ion_id;
const int electron_id;
const PosType elec_pos;
const RealType ion_elec_dist;
const PosType ion_elec_displ;
NLPPJob(const int ion_id_in,
const int electron_id_in,
const PosType& elec_pos_in,
const RealType ion_elec_dist_in,
const PosType& ion_elec_displ_in)
: ion_id(ion_id_in),
electron_id(electron_id_in),
elec_pos(elec_pos_in),
ion_elec_dist(ion_elec_dist_in),
ion_elec_displ(ion_elec_displ_in)
{}
};
NonLocalECPotential(ParticleSet& ions, ParticleSet& els, TrialWaveFunction& psi, bool computeForces, bool enable_DLA);
~NonLocalECPotential();
@ -169,7 +147,7 @@ private:
Array<TraceReal, 1>* Vi_sample;
#endif
///NLPP job list of ion-electron pairs by spin group
std::vector<std::vector<NLPPJob>> nlpp_jobs;
std::vector<std::vector<NLPPJob<RealType>>> nlpp_jobs;
/** the actual implementation, used by evaluate and evaluateWithToperator
* @param P particle set