QMCPACK
test_ObservableHelper.cpp
Go to the documentation of this file.
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) 2019 QMCPACK developers.
6 //
7 // File developed by: William F Godoy, godoywf@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: William F Godoy, godoywf@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
16 #include "io/hdf/hdf_archive.h"
17 
18 #include <filesystem>
19 
20 /*
21  -- 05/07/2021 --
22  Deterministic unit test for the ObservableHelper class.
23 */
24 
25 namespace qmcplusplus
26 {
27 
28 TEST_CASE("ObservableHelper::ObservableHelper(std::vector<std::string>)", "[hamiltonian]")
29 {
30  ObservableHelper oh(hdf_path{"u/v"});
31  CHECK(oh.lower_bound == 0);
32 }
33 
34 TEST_CASE("ObservableHelper::set_dimensions", "[hamiltonian]")
35 {
37 
38  std::vector<int> dims = {10, 10};
40 
41  CHECK(oh.lower_bound == 1);
42 }
43 
44 TEST_CASE("ObservableHelper::ObservableHelper()", "[hamiltonian]")
45 {
46  std::filesystem::path filename("tmp_ObservableHelper2.h5");
48  hFile.create(filename);
49 
51  std::vector<int> dims = {10, 10};
52  float propertyFloat = 10.f;
53  oh.addProperty(propertyFloat, "propertyFloat", hFile);
54 
56  oh.addProperty(propertyTensor, "propertyTensor", hFile);
57 
59  oh.addProperty(propertyMatrix, "propertyMatrix", hFile);
60 
62  oh.addProperty(propertyTensor, "propertyTinyVector", hFile);
63 
64  std::vector<float> propertyVector;
65  oh.addProperty(propertyVector, "propertyVector", hFile);
66 
67  std::vector<TinyVector<float, OHMMS_DIM>> propertyVectorTinyVector;
68  oh.addProperty(propertyVectorTinyVector, "propertyVectorTinyVector", hFile);
69 
70  hFile.close();
71  REQUIRE(std::filesystem::exists(filename));
72  REQUIRE(std::filesystem::remove(filename));
73 }
74 
75 } // namespace qmcplusplus
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
void addProperty(T &p, const std::string &pname, hdf_archive &file)
add named property to describe the collectable this helper class handles
Declaration of ObservableHelper and other helper class for observables.
define ObservableHelper
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
Matrix< float > propertyMatrix
REQUIRE(std::filesystem::exists(filename))
std::vector< float > propertyVector
hsize_t lower_bound
starting index
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
void set_dimensions(const std::vector< int > &dims, int first)
set the shape of this observable
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
TinyVector< float, OHMMS_DIM > propertyTinyVector
std::vector< int > dims
Tensor< float, OHMMS_DIM > propertyTensor
std::vector< TinyVector< float, OHMMS_DIM > > propertyVectorTinyVector
ObservableHelper oh