1 ////////////////////////////////////////////////////////////////////////////////////// 2 // This file is distributed under the University of Illinois/NCSA Open Source License. 3 // See LICENSE file in top directory for details. 4 // 5 // Copyright (c) 2017 Jeongnim Kim and QMCPACK developers. 6 // 7 // File developed by: Mark Dewing, mdewin@anl.gov, Argonne National Laboratory 8 // 9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory 10 ////////////////////////////////////////////////////////////////////////////////////// 11 12 13 #include "catch.hpp" 14 15 #include "Message/Communicate.h" 16 #include "OhmmsData/Libxml2Doc.h" 17 #include "Particle/MCWalkerConfiguration.h" 18 #include "QMCHamiltonians/QMCHamiltonian.h" 19 #include "Estimators/EstimatorManagerBase.h" 20 #include "Estimators/tests/FakeEstimator.h" 21 #include "Estimators/ScalarEstimatorBase.h" 22 #include "Estimators/tests/EstimatorManagerBaseTest.h" 23 24 #include <stdio.h> 25 #include <sstream> 26 27 namespace qmcplusplus 28 { 29 TEST_CASE("EstimatorManagerBase", "[estimators]") 30 { 31 Communicate* c = OHMMS::Controller; 32 33 EstimatorManagerBase em(c); 34 35 REQUIRE(em.size() == 0); 36 37 // Must create on heap since the EstimatorManager destructor deletes all estimators 38 FakeEstimator* fake_est = new FakeEstimator; 39 40 em.add(fake_est, "fake"); 41 42 ScalarEstimatorBase* est2 = em.getEstimator("fake"); 43 FakeEstimator* fake_est2 = dynamic_cast<FakeEstimator*>(est2); 44 REQUIRE(fake_est2 != NULL); 45 REQUIRE(fake_est2 == fake_est); 46 47 // Check the copy constructor 48 EstimatorManagerBase em2(em); 49 REQUIRE(em.size() == 1); 50 51 em.start(2, true); 52 53 em.stop(); 54 // compute averages over threads 55 //em.stop(); 56 em.reset(); 57 } 58 59 TEST_CASE("Estimator adhoc addVector operator", "[estimators]") 60 { 61 int num_scalars = 3; 62 std::vector<double> vec_a{1.0, 2.0, 3.0}; 63 std::vector<double> vec_b{2.0, 3.0, 4.0}; 64 std::vector<std::vector<double>> est{vec_a, vec_b}; __anon4f309dfd0102(const auto& vec_a, const auto& vec_b) 65 auto addVectors = [](const auto& vec_a, const auto& vec_b) { 66 std::vector<ScalarEstimatorBase::RealType> result_vector(vec_a.size(), 0.0); 67 for (int i = 0; i < vec_a.size(); ++i) 68 result_vector[i] = vec_a[i] + vec_b[i]; 69 return result_vector; 70 }; 71 72 std::vector<double> reduced_scalars(num_scalars); 73 reduced_scalars = std::accumulate(est.begin(), est.end(), std::vector<double>(num_scalars, 0.0), addVectors); 74 std::vector<double> correct{3.0, 5.0, 7.0}; 75 REQUIRE(reduced_scalars == correct); 76 } 77 78 } // namespace qmcplusplus 79