From c47d3a701ea9f7c3b25fdc19449d39d051e808e9 Mon Sep 17 00:00:00 2001 From: Peter Doak Date: Wed, 1 Nov 2023 14:16:36 -0400 Subject: [PATCH] missing consistency test between per ptcl and per QMCham nrg --- src/QMCHamiltonians/tests/test_QMCHamiltonian.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/QMCHamiltonians/tests/test_QMCHamiltonian.cpp b/src/QMCHamiltonians/tests/test_QMCHamiltonian.cpp index fc209ea307..9a7836c4cf 100644 --- a/src/QMCHamiltonians/tests/test_QMCHamiltonian.cpp +++ b/src/QMCHamiltonians/tests/test_QMCHamiltonian.cpp @@ -269,6 +269,19 @@ TEST_CASE("integrateListeners", "[hamiltonian]") auto sum_kinetic = std::accumulate(kinetic.begin(), kinetic.end(), 0.0); auto sum_local_nrg = std::accumulate(local_nrg.begin(), local_nrg.end(), 0.0); CHECK(sum_local_nrg == Approx(sum_local_pots + sum_kinetic)); + + // Here we test consistency between the per particle energies and the per hamiltonian energies + typename decltype(energies)::value_type hamiltonian_local_nrg_sum = 0.0; + typename decltype(energies)::value_type energies_sum = 0.0; + for (int iw = 0; iw < num_walkers; ++iw) { + hamiltonian_local_nrg_sum += ham_list[iw].getLocalEnergy(); + energies_sum += energies[iw]; + } + + // the QMCHamiltonian.getLocalEnergy() contains the ion_potential as well. + sum_local_nrg += std::accumulate(ion_pots.begin(), ion_pots.end(), 0.0); + CHECK(sum_local_nrg == Approx(hamiltonian_local_nrg_sum)); + CHECK(sum_local_nrg == Approx(energies_sum)); } }