Skip to content

Commit

Permalink
Update with respect to #3243
Browse files Browse the repository at this point in the history
  • Loading branch information
shivupa committed Jul 24, 2021
1 parent 3bdd6f8 commit 76ddb75
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
41 changes: 20 additions & 21 deletions src/QMCWaveFunctions/Jastrow/J1SpinOrbitalSoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
///Container for \f$F[ig*NIons+jg]\f$
std::vector<FT*> J1Functors;
///container for the unique Jastrow functions
std::vector<std::unique_ptr<FT>> J1UniqueFunctors;
std::map<std::string, std::unique_ptr<FT>> J1UniqueFunctors;

std::vector<std::pair<int, int>> OffSet;
Vector<RealType> dLogPsi;
Expand All @@ -90,7 +90,10 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
J1SpinOrbitalSoA(const std::string& obj_name, const ParticleSet& ions, ParticleSet& els)
: WaveFunctionComponent("J1SpinOrbitalSoA", obj_name),
myTableID(els.addTable(ions)),
Nions(ions.getTotalNum()), Nelec(els.getTotalNum()), NumTargetGroups(determineNumGroups(ions)), NumTargetGroups(determineNumGroups(els)),
Nions(ions.getTotalNum()),
Nelec(els.getTotalNum()),
NumGroups(determineNumGroups(ions)),
NumTargetGroups(determineNumGroups(els)),
Ions(ions),
Elecs(els),
NumVars(0)
Expand Down Expand Up @@ -123,12 +126,7 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
/* initialize storage */
void initialize()
{
Nions = Ions.getTotalNum();
Nelec = Elecs.getTotalNum();
NumGroups = Ions.groups();
NumTargetGroups = Elecs.groups();
J1Functors.resize(Nions * Nelec, nullptr);
J1UniqueFunctors.resize(NumGroups * NumTargetGroups);
Vat.resize(Nelec);
Grad.resize(Nelec);
Lap.resize(Nelec);
Expand Down Expand Up @@ -166,7 +164,8 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
{
for (int i = 0; i < Nions; i++)
for (int j = 0; j < Nelec; j++)
if (Ions.getGroupID(i) == source_type && Elecs.getGroupID(j) == target_type && J1Functors[i * Nelec + j] == nullptr)
if (Ions.getGroupID(i) == source_type && Elecs.getGroupID(j) == target_type &&
J1Functors[i * Nelec + j] == nullptr)
J1Functors[i * Nelec + j] = afunc.get();
//if (J1UniqueFunctors[source_type] != nullptr)
// delete J1UniqueFunctors[source_type];
Expand Down Expand Up @@ -372,8 +371,8 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
aname << jg;
}
if (J1UniqueFunctors[aname.str()] != nullptr)
curVat +=
J1UniqueFunctors[aname.str()]->evaluateV(-1, Ions.first(jg), Ions.last(jg), dist.data(), DistCompressed.data());
curVat += J1UniqueFunctors[aname.str()]->evaluateV(-1, Ions.first(jg), Ions.last(jg), dist.data(),
DistCompressed.data());
}
}
else
Expand Down Expand Up @@ -414,8 +413,8 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
}

if (J1UniqueFunctors[gid.str()] != nullptr)
curAt +=
J1UniqueFunctors[gid.str()]->evaluateV(-1, Ions.first(ig), Ions.last(ig), dist.data(), DistCompressed.data());
curAt += J1UniqueFunctors[gid.str()]->evaluateV(-1, Ions.first(ig), Ions.last(ig), dist.data(),
DistCompressed.data());
}
}
}
Expand Down Expand Up @@ -505,7 +504,7 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
if (J1UniqueFunctors[gid.str()] == nullptr)
continue;
J1UniqueFunctors[gid.str()]->evaluateVGL(-1, Ions.first(jg), Ions.last(jg), dist.data(), U.data(), dU.data(),
d2U.data(), DistCompressed.data(), DistIndice.data());
d2U.data(), DistCompressed.data(), DistIndice.data());
}
}
else
Expand Down Expand Up @@ -621,10 +620,10 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
}


WaveFunctionComponentPtr makeClone(ParticleSet& tqp) const override
std::unique_ptr<WaveFunctionComponent> makeClone(ParticleSet& tqp) const override
{
J1SpinOrbitalSoA<FT>* j1copy = std::make_unique<J1SpinOrbitalSoA<FT>>(myName, Ions, tqp);
j1copy->Optimizable = Optimizable;
auto j1copy = std::make_unique<J1SpinOrbitalSoA<FT>>(myName, Ions, tqp);
j1copy->Optimizable = Optimizable;
if (NumGroups > 0)
{
for (int i = 0; i < NumGroups; i++)
Expand Down Expand Up @@ -724,7 +723,7 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
gradLogPsi[i] = new WavefunctionFirstDerivativeType(Nelec);
lapLogPsi[i] = new WavefunctionSecondDerivativeType(Nelec);
}
OffSet.resize(F.size());
OffSet.resize(J1Functors.size());
// Find first active variable for the starting offset
int varoffset = -1;
for (int i = 0; i < myVars.size(); i++)
Expand All @@ -734,12 +733,12 @@ struct J1SpinOrbitalSoA : public WaveFunctionComponent
break;
}

for (int i = 0; i < F.size(); ++i)
for (int i = 0; i < J1Functors.size(); ++i)
{
if (F[i] && F[i]->myVars.Index.size())
if (J1Functors[i] && J1Functors[i]->myVars.Index.size())
{
OffSet[i].first = F[i]->myVars.Index.front() - varoffset;
OffSet[i].second = F[i]->myVars.Index.size() + OffSet[i].first;
OffSet[i].first = J1Functors[i]->myVars.Index.front() - varoffset;
OffSet[i].second = J1Functors[i]->myVars.Index.size() + OffSet[i].first;
}
else
{
Expand Down
31 changes: 15 additions & 16 deletions src/QMCWaveFunctions/Jastrow/RadialJastrowBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class JastrowTypeHelper
{
public:
using J1OrbitalType = J1OrbitalSoA<RadFuncType>;
using J1SpinOrbitalType = J1SpinOrbitalSoA<RadFuncType>;
using J1SpinOrbitalType = J1SpinOrbitalSoA<RadFuncType>;
using J2OrbitalType = J2OrbitalSoA<RadFuncType>;
using DiffJ2OrbitalType = DiffTwoBodyJastrowOrbital<RadFuncType>;
};
Expand All @@ -103,9 +103,9 @@ class JastrowTypeHelper<BsplineFunctor<RadialJastrowBuilder::RealType>>
using J2OrbitalType = TwoBodyJastrowOrbitalBspline<RadFuncType>;
#endif
#if !defined(QMC_CUDA)
using J1OrbitalType = J1OrbitalSoA<RadFuncType>;
using J1OrbitalType = J1OrbitalSoA<RadFuncType>;
using J1SpinOrbitalType = J1SpinOrbitalSoA<RadFuncType>;
using J2OrbitalType = J2OrbitalSoA<RadFuncType>;
using J2OrbitalType = J2OrbitalSoA<RadFuncType>;
#endif
using DiffJ2OrbitalType = DiffTwoBodyJastrowOrbital<RadFuncType>;
};
Expand Down Expand Up @@ -149,15 +149,15 @@ template<class RadFuncType>
std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ2(xmlNodePtr cur)
{
ReportEngine PRE(ClassName, "createJ2(xmlNodePtr)");
using Real = typename RadFuncType::real_type;
using Real = typename RadFuncType::real_type;
using J2OrbitalType = typename JastrowTypeHelper<RadFuncType>::J2OrbitalType;
using DiffJ2OrbitalType = typename JastrowTypeHelper<RadFuncType>::DiffJ2OrbitalType;

XMLAttrString input_name(cur, "name");
std::string j2name = input_name.empty() ? "J2_" + Jastfunction : input_name;
SpeciesSet& species(targetPtcl.getSpeciesSet());
auto J2 = std::make_unique<J2OrbitalType>(j2name, targetPtcl);
auto dJ2 = std::make_unique<DiffJ2OrbitalType>(targetPtcl);
auto J2 = std::make_unique<J2OrbitalType>(j2name, targetPtcl);
auto dJ2 = std::make_unique<DiffJ2OrbitalType>(targetPtcl);

std::string init_mode("0");
{
Expand Down Expand Up @@ -333,13 +333,13 @@ template<class RadFuncType>
std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ1(xmlNodePtr cur)
{
ReportEngine PRE(ClassName, "createJ1(xmlNodePtr)");
using Real = typename RadFuncType::real_type;
using Real = typename RadFuncType::real_type;
using J1OrbitalType = typename JastrowTypeHelper<RadFuncType>::J1OrbitalType;

XMLAttrString input_name(cur, "name");
std::string jname = input_name.empty() ? Jastfunction : input_name;

auto J1 = std::make_unique<J1OrbitalType>(jname, *SourcePtcl, targetPtcl);
auto J1 = std::make_unique<J1OrbitalType>(jname, *SourcePtcl, targetPtcl);

xmlNodePtr kids = cur->xmlChildrenNode;

Expand Down Expand Up @@ -425,7 +425,7 @@ std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ1(xmlNodePtr
template<>
std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ1<RPAFunctor>(xmlNodePtr cur)
{
using Real = RealType;
using Real = RealType;
using SplineEngineType = CubicBspline<Real, LINEAR_1DGRID, FIRSTDERIV_CONSTRAINTS>;
using RadFunctorType = CubicSplineSingle<Real, SplineEngineType>;
using GridType = LinearGrid<Real>;
Expand Down Expand Up @@ -470,18 +470,18 @@ std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ1<RPAFunctor
}
myHandler->Breakup(targetPtcl, Rs);

Real Rcut = myHandler->get_rc() - 0.1;
Real Rcut = myHandler->get_rc() - 0.1;
GridType* myGrid = new GridType;
int npts = static_cast<int>(Rcut / 0.01) + 1;
myGrid->set(0, Rcut, npts);

//create the numerical functor
auto nfunc = std::make_unique<RadFunctorType>();
auto nfunc = std::make_unique<RadFunctorType>();
ShortRangePartAdapter<Real>* SRA = new ShortRangePartAdapter<Real>(myHandler);
SRA->setRmax(Rcut);
nfunc->initialize(SRA, myGrid);

auto J1 = std::make_unique<J1OrbitalType>(jname, *SourcePtcl, targetPtcl);
auto J1 = std::make_unique<J1OrbitalType>(jname, *SourcePtcl, targetPtcl);

SpeciesSet& sSet = SourcePtcl->getSpeciesSet();
for (int ig = 0; ig < sSet.getTotalNum(); ig++)
Expand All @@ -494,7 +494,7 @@ std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ1<RPAFunctor
}

template<class RadFuncType>
WaveFunctionComponent* RadialJastrowBuilder::createJ1Spin(xmlNodePtr cur)
std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ1Spin(xmlNodePtr cur)
{
ReportEngine PRE(ClassName, "createJ1Spin(xmlNodePtr)");
using RT = typename RadFuncType::real_type;
Expand All @@ -503,7 +503,7 @@ WaveFunctionComponent* RadialJastrowBuilder::createJ1Spin(xmlNodePtr cur)
XMLAttrString input_name(cur, "name");
std::string jname = input_name.empty() ? Jastfunction : input_name;

J1OrbitalType* J1 = new J1OrbitalType(jname, *SourcePtcl, targetPtcl);
std::unique_ptr<J1OrbitalType> J1 = std::make_unique<J1OrbitalType>(jname, *SourcePtcl, targetPtcl);

xmlNodePtr kids = cur->xmlChildrenNode;

Expand Down Expand Up @@ -572,8 +572,7 @@ WaveFunctionComponent* RadialJastrowBuilder::createJ1Spin(xmlNodePtr cur)
else
{
PRE.error("BsplineJastrowBuilder failed to add an One-Body Jastrow.");
delete J1;
return nullptr;
return std::unique_ptr<WaveFunctionComponent>();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/QMCWaveFunctions/tests/test_J1SpinOrbitalSoA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_CASE("J1 spin evaluate derivatives Jastrow", "[wavefunction]")
twf.evaluateLog(elec_);
twf.prepareGroup(elec_, 0);

auto twf_component_list = twf.getOrbitals();
auto& twf_component_list = twf.getOrbitals();

opt_variables_type active;
twf.checkInVariables(active);
Expand All @@ -102,8 +102,8 @@ TEST_CASE("J1 spin evaluate derivatives Jastrow", "[wavefunction]")
twf_component_list[0]->evaluateDerivatives(elec_, active, dlogpsi, dhpsioverpsi);

// Numbers not validated
std::vector<ValueType> expected_dlogpsi = {-0.9336294487, -1.0196051794, 0.0, 0.0};
std::vector<ValueType> expected_dhpsioverpsi = {-1.1596433096, 0.7595492539, 0.0, 0.0};
std::vector<ValueType> expected_dlogpsi = {-0.46681472435, -0.5098025897, -0.46681472435, -0.5098025897};
std::vector<ValueType> expected_dhpsioverpsi = {-0.5798216548, 0.37977462695, -0.5798216548, 0.37977462695};
for (int i = 0; i < nparam; i++)
{
CHECK(dlogpsi[i] == ValueApprox(expected_dlogpsi[i]));
Expand Down

0 comments on commit 76ddb75

Please sign in to comment.