Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add evaluateDerivativesWF for J3 #4694

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,90 @@ class JeeIOrbitalSoA : public WaveFunctionComponent
}
}

void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& optvars, Vector<ValueType>& dlogpsi) override
{
resizeWFOptVectors();

bool recalculate(false);
for (int k = 0; k < myVars.size(); ++k)
{
int kk = myVars.where(k);
if (kk < 0)
continue;
if (optvars.recompute(kk))
recalculate = true;
}

if (recalculate)
{
constexpr valT czero(0);
constexpr valT cone(1);
constexpr valT cminus(-1);
constexpr valT ctwo(2);
constexpr valT lapfac = OHMMS_DIM - cone;

const auto& ee_table = P.getDistTableAA(ee_Table_ID_);
const auto& ee_dists = ee_table.getDistances();
const auto& ee_displs = ee_table.getDisplacements();

build_compact_list(P);

dLogPsi = czero;
gradLogPsi = PosType();
lapLogPsi = czero;

for (int iat = 0; iat < Nion; ++iat)
{
const int ig = Ions.GroupID[iat];
for (int jg = 0; jg < eGroups; ++jg)
for (int jind = 0; jind < elecs_inside(jg, iat).size(); jind++)
{
const int jel = elecs_inside(jg, iat)[jind];
const valT r_Ij = elecs_inside_dist(jg, iat)[jind];
const posT disp_Ij = cminus * elecs_inside_displ(jg, iat)[jind];
const valT r_Ij_inv = cone / r_Ij;

for (int kg = 0; kg < eGroups; ++kg)
for (int kind = 0; kind < elecs_inside(kg, iat).size(); kind++)
{
const int kel = elecs_inside(kg, iat)[kind];
if (kel < jel)
{
const valT r_Ik = elecs_inside_dist(kg, iat)[kind];
const posT disp_Ik = cminus * elecs_inside_displ(kg, iat)[kind];
const valT r_Ik_inv = cone / r_Ik;

const valT r_jk = ee_dists[jel][kel];
const posT disp_jk = ee_displs[jel][kel];
const valT r_jk_inv = cone / r_jk;

FT& func = *F(ig, jg, kg);
int idx = J3UniqueIndex[F(ig, jg, kg)];
func.evaluateDerivatives(r_jk, r_Ij, r_Ik, du_dalpha[idx], dgrad_dalpha[idx], dhess_dalpha[idx]);
int first = VarOffset(ig, jg, kg).first;
int last = VarOffset(ig, jg, kg).second;
std::vector<RealType>& dlog = du_dalpha[idx];

for (int p = first, ip = 0; p < last; p++, ip++)
{
RealType& dval = dlog[ip];
dLogPsi[p] -= dval;
}
}
}
}
}

for (int k = 0; k < myVars.size(); ++k)
{
int kk = myVars.where(k);
if (kk < 0)
continue;
dlogpsi[kk] = (ValueType)dLogPsi[k];
}
}
}

void evaluateDerivRatios(const VirtualParticleSet& VP,
const opt_variables_type& optvars,
std::vector<ValueType>& ratios,
Expand Down
6 changes: 6 additions & 0 deletions src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ void test_J3_polynomial3D(const DynamicCoordinateKind kind_selected)
CHECK(std::real(dlogpsi[43]) == Approx(1.3358726814e+05));
CHECK(std::real(dhpsioverpsi[43]) == Approx(-2.3246270644e+05));

Vector<WaveFunctionComponent::ValueType> dlogpsiWF;
dlogpsiWF.resize(NumOptimizables);
j3->evaluateDerivativesWF(elec_, optvars, dlogpsiWF);
for (int i = 0; i < NumOptimizables; i++)
CHECK(dlogpsi[i] == Approx(dlogpsiWF[i]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need ComplexApprox to build.


VirtualParticleSet VP(elec_, 2);
std::vector<PosType> newpos2(2);
std::vector<ValueType> ratios2(2);
Expand Down