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

Fix cusp for NaN's and catch bracketing failures #1594

Merged
merged 4 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion src/Numerics/MinimizeOneDim.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ Bracket_min_t<T> bracket_minimum(const F& f, T initial_value, T bound_max = -1.0
{
delx *= 5;
}
cnt++;
if (cnt == 10000)
{
delx *= 5;
}
cnt++;
if (cnt == 100000)
{
throw std::runtime_error("Failed to bracket minimum");
}
Expand Down
48 changes: 34 additions & 14 deletions src/QMCWaveFunctions/lcao/CuspCorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,13 @@ void getCurrentLocalEnergy(const ValueVector_t& pos,
for (int i = 0; i < pos.size(); i++)
{
RealType r = pos[i];
// prevent NaN's if phiBar is zero
RealType offset = 1e-12;
if (r <= Rc)
{
RealType dp = cusp.dpr(r);
ELcurr[i] = -0.5 * cusp.Rr(r) * (2.0 * dp / r + cusp.d2pr(r) + dp * dp) / cusp.phiBar(r, phiMO) - Zeff / r + dE;
ELcurr[i] = -0.5 * cusp.Rr(r) * (2.0 * dp / r + cusp.d2pr(r) + dp * dp) / (offset + cusp.phiBar(r, phiMO)) -
Zeff / r + dE;
}
else
{
Expand Down Expand Up @@ -383,12 +386,20 @@ RealType minimizeForPhiAtZero(CuspCorrection& cusp,
getIdealLocalEnergy(pos, Z, cusp.cparam.Rc, ELorigAtRc, ELideal);
phiMO.phi_vgl(cusp.cparam.Rc, vglAtRc.val, vglAtRc.grad, vglAtRc.lap);

RealType start_phi0 = phiMO.phi(0.0);
Bracket_min_t<RealType> bracket = bracket_minimum(
[&](RealType x) -> RealType {
return evaluateForPhi0Body(x, pos, ELcurr, ELideal, cusp, phiMO, vglAtRc, eta0, ELorigAtRc, Z);
},
start_phi0);
RealType start_phi0 = phiMO.phi(0.0);
Bracket_min_t<RealType> bracket(start_phi0, 0.0, 0.0, false);
try
{
bracket = bracket_minimum(
[&](RealType x) -> RealType {
return evaluateForPhi0Body(x, pos, ELcurr, ELideal, cusp, phiMO, vglAtRc, eta0, ELorigAtRc, Z);
},
start_phi0);
}
catch (const std::runtime_error& e)
{
APP_ABORT("Bracketing minimum failed for finding phi0. \n");
}

auto min_res = find_minimum(
[&](RealType x) -> RealType {
Expand All @@ -412,13 +423,22 @@ void minimizeForRc(CuspCorrection& cusp,
ValueVector_t& ELcurr,
ValueVector_t& ELideal)
{
RealType Rc = Rc_init;
Bracket_min_t<RealType> bracket = bracket_minimum(
[&](RealType x) -> RealType {
cusp.cparam.Rc = x;
return minimizeForPhiAtZero(cusp, phiMO, Z, eta0, pos, ELcurr, ELideal);
},
Rc_init, Rc_max);
RealType Rc = Rc_init;
Bracket_min_t<RealType> bracket(Rc_init, 0.0, 0.0, false);
try
{
bracket = bracket_minimum(
[&](RealType x) -> RealType {
cusp.cparam.Rc = x;
return minimizeForPhiAtZero(cusp, phiMO, Z, eta0, pos, ELcurr, ELideal);
},
Rc_init, Rc_max);
}
catch (const std::runtime_error& e)
{
APP_ABORT("Bracketing minimum failed for finding rc. \n");
}


if (bracket.success)
{
Expand Down