QMCPACK
test_attrib_ops.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "Message/Communicate.h"
16 #include "OhmmsPETE/OhmmsMatrix.h"
17 #include "OhmmsPETE/TinyVector.h"
18 #include "Lattice/CrystalLattice.h"
22 
23 #include <stdio.h>
24 #include <string>
25 
26 using std::string;
27 
28 namespace qmcplusplus
29 {
30 template<unsigned int D>
32 {
34  v1 = 2.0;
35  double val1 = dot(v1, v1);
36  CHECK(val1 == Approx(4.0 * D));
37 
38 
40  PA1.resize(3);
41  REQUIRE(PA1.size() == 3);
42 
43  // Whole array operation
44  PA1 = 1.0;
45 
46  double val = Dot(PA1, PA1);
47  CHECK(val == Approx(3 * 1.0 * D));
48 }
49 
50 
51 TEST_CASE("particle_attrib_ops_double", "[particle_base]")
52 {
53  SECTION("dim = 1") { double_test_case<1>(); }
54  SECTION("dim = 2") { double_test_case<2>(); }
55  SECTION("dim = 3") { double_test_case<3>(); }
56  SECTION("dim = 4") { double_test_case<4>(); }
57 }
58 
59 template<unsigned int D>
61 {
63 
64  v1 = std::complex<double>(2.0, 1.0);
65  double val1 = OTCDot<double, double, D>::apply(v1, v1);
66  CHECK(val1 == Approx(3.0 * D));
67 
68  double val1_cc = OTCDot_CC<double, double, D>::apply(v1, v1);
69  CHECK(val1_cc == Approx(5.0 * D));
70 
71 
73  PA1.resize(3);
74  REQUIRE(PA1.size() == 3);
75 
76  // Whole array operation
77  PA1 = std::complex<double>(1.0, 2.0);
78 
79  double val = Dot(PA1, PA1);
80  CHECK(val == Approx(-3.0 * 3 * D));
81 
82  double val_cc = Dot_CC(PA1, PA1);
83  CHECK(val_cc == Approx(5.0 * 3 * D));
84 }
85 
86 TEST_CASE("particle_attrib_ops_complex", "[particle_base]")
87 {
88  SECTION("dim = 1") { complex_test_case<1>(); }
89  SECTION("dim = 2") { complex_test_case<2>(); }
90  SECTION("dim = 3") { complex_test_case<3>(); }
91  SECTION("dim = 4") { complex_test_case<4>(); }
92 }
93 
94 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void complex_test_case()
static Type_t apply(const TinyVector< std::complex< T1 >, D > &lhs, const TinyVector< std::complex< T2 >, D > &rhs)
static Type_t apply(const TinyVector< std::complex< T1 >, D > &lhs, const TinyVector< std::complex< T2 >, D > &rhs)
TEST_CASE("complex_helper", "[type_traits]")
void double_test_case()
Attaches a unit to a Vector for IO.
Declaration of CrystalLattice<T,D>
T Dot(const ParticleAttrib< TinyVector< T, D >> &pa, const ParticleAttrib< TinyVector< T, D >> &pb)
size_type size() const
return the current size
Definition: OhmmsVector.h:162
REQUIRE(std::filesystem::exists(filename))
Declaraton of ParticleAttrib<T> derived from Vector.
double Dot_CC(const ParticleAttrib< TinyVector< std::complex< double >, D >> &pa, const ParticleAttrib< TinyVector< std::complex< double >, D >> &pb)
Declaraton of ParticleAttrib<T>
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)