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

improve stability of lorentzian susceptibility #666

Merged
merged 2 commits into from
Jan 11, 2019
Merged
Changes from all 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
26 changes: 16 additions & 10 deletions src/susceptibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,25 @@ void lorentzian_susceptibility::update_P(realnum *W[NUM_FIELD_COMPONENTS][2],
}
if (s1 && s2) { // 3x3 anisotropic
LOOP_OVER_VOL_OWNED(gv, c, i) {
realnum pcur = p[i];
p[i] =
gamma1inv *
(pcur * (2 - omega0dtsqr_denom) - gamma1 * pp[i] +
omega0dtsqr * (s[i] * w[i] + OFFDIAG(s1, w1, is1, is) + OFFDIAG(s2, w2, is2, is)));
pp[i] = pcur;
// s[i] != 0 check is a bit of a hack to work around
// some instabilities that occur near the boundaries
// of materials; see PR #666
if (s[i] != 0) {
realnum pcur = p[i];
p[i] = gamma1inv * (pcur * (2 - omega0dtsqr_denom) - gamma1 * pp[i] +
omega0dtsqr * (s[i] * w[i] + OFFDIAG(s1, w1, is1, is) +
OFFDIAG(s2, w2, is2, is)));
pp[i] = pcur;
}
}
} else if (s1) { // 2x2 anisotropic
LOOP_OVER_VOL_OWNED(gv, c, i) {
realnum pcur = p[i];
p[i] = gamma1inv * (pcur * (2 - omega0dtsqr_denom) - gamma1 * pp[i] +
omega0dtsqr * (s[i] * w[i] + OFFDIAG(s1, w1, is1, is)));
pp[i] = pcur;
if (s[i] != 0) { // see above
realnum pcur = p[i];
p[i] = gamma1inv * (pcur * (2 - omega0dtsqr_denom) - gamma1 * pp[i] +
omega0dtsqr * (s[i] * w[i] + OFFDIAG(s1, w1, is1, is)));
pp[i] = pcur;
}
}
} else { // isotropic
LOOP_OVER_VOL_OWNED(gv, c, i) {
Expand Down