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 Madelung constant in CoulombPBCAA #3806

Merged
merged 5 commits into from
Feb 4, 2022
Merged

Conversation

Paul-St-Young
Copy link
Contributor

Please review the developer documentation
on the wiki of this project that contains help and requirements.

Proposed changes

Add the missing background term (vs_k0) into the Madelung constant.
This makes it correct for simple cubic and body center cubic crystals as shown by the unit tests.

What type(s) of changes does this code introduce?

  • Bugfix

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

workstation

Checklist

Update the following with a yes where the items apply. If you're unsure about any of them, don't hesitate to ask. This is
simply a reminder of what we are going to look for before merging your code.

  • Yes. This PR is up to date with current the current state of 'develop'
  • No. Code added or changed in the PR has been clang-formatted
  • Yes. This PR adds tests to cover any new code, or to catch a bug that is being fixed
  • No. Documentation has been added (if appropriate)

@Paul-St-Young Paul-St-Young self-assigned this Feb 3, 2022
src/QMCHamiltonians/tests/test_coulomb_pbcAA.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/tests/test_coulomb_pbcAA.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/tests/test_coulomb_pbcAA.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/CoulombPBCAA.cpp Show resolved Hide resolved
@prckent
Copy link
Contributor

prckent commented Feb 4, 2022

Thanks Paul. Some background could be helpful for further improvements: how did you notice this? Could the other Coulomb terms (AB) also have the same issue?

@Paul-St-Young
Copy link
Contributor Author

@prckent I need to add the Madelung term for AFQMC total energy.
I've always wondered why the QMCPACK output was off, but didn't take a detailed look until recently.

As Jaron noted, this term affects only the output. As far as I can tell, myConst is correct in both AA and AB handlers.

Copy link
Contributor

@jtkrogel jtkrogel left a comment

Choose a reason for hiding this comment

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

I'm satisfied with the changes here.

app_log() << " PBCAA total constant " << Consts << std::endl;
//app_log() << " MC0 of PBCAA " << MC0 << std::endl;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove {} around 1 line.

@@ -27,6 +27,7 @@ namespace qmcplusplus
{
TEST_CASE("Coulomb PBC A-A", "[hamiltonian]")
{
double vmad_sc = -1.4186487397403098;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use const to avoid unintended altering of values.

//cout << "val = " << val << std::endl;
REQUIRE(val == Approx(-1.418648723)); // not validated
//std::cout << "val = " << val << std::endl;
REQUIRE(val == Approx(vmad_sc));
Copy link
Contributor

Choose a reason for hiding this comment

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

REQUIRE stops the execution. So better suited for flow control or nullptr checks.
CHECK are more suitable for value checks. So please use CHECK.

}

TEST_CASE("Coulomb PBC A-A BCC H", "[hamiltonian]")
{
double alat = 3.77945227;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add const

@@ -101,8 +108,12 @@ TEST_CASE("Coulomb PBC A-A BCC H", "[hamiltonian]")
REQUIRE(consts == Approx(-1.675229452)); // not validated

double val = caa.evaluate(elec);
//cout << "BCC H val = " << val << std::endl;
//std::cout << "BCC H val = " << val << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

elec.create(1);
elec.R[0][0] = 0.0;
elec.R[0][1] = 0.0;
elec.R[0][2] = 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can write

elec.R[0] = {0.0, 0.0, 0.0}

Let's make the code more concise.

int chargeIdx = tspecies.addAttribute("charge");
int massIdx = tspecies.addAttribute("mass");
int pMembersizeIdx = tspecies.addAttribute("membersize");
tspecies(pMembersizeIdx, upIdx) = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

please run clang-format

@Paul-St-Young
Copy link
Contributor Author

@ye-luo I have addressed all your comments.
Please see if this is satisfactory now.

Copy link
Contributor

@ye-luo ye-luo left a comment

Choose a reason for hiding this comment

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

LGTM

@ye-luo
Copy link
Contributor

ye-luo commented Feb 4, 2022

Test this please

@ye-luo ye-luo enabled auto-merge February 4, 2022 20:02
@prckent prckent self-requested a review February 4, 2022 20:21
@ye-luo ye-luo merged commit aee3d6c into QMCPACK:develop Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants