Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
test_mesh.cpp
Go to the documentation of this file.
1 #include <catch.hpp>
2 
3 #define BOOST_LOG_DYN_LINK 1
4 #include <boost/log/trivial.hpp>
5 
6 #include "class_mesh.hpp"
7 
8 TEST_CASE( "UNIT TEST: mesh class {Mesh_base<T>}", "[core]" )
9 {
10  BOOST_LOG_TRIVIAL(info) << "mesh class {Mesh_base<T>}";
11 
12  // dimension
13  Mesh_base<double> mesh(8, 16, 20);
14  CHECK( mesh.N1 == 8 );
15  CHECK( mesh.N2 == 16 );
16  CHECK( mesh.N3 == 20 );
17  CHECK( mesh.length == 2560 );
18  mesh.assign(-0.5);
19  CHECK( mesh.length == 2560 );
20  CHECK( mesh.N2 == 16 );
21  CHECK( mesh[5] == -0.5 );
22 
23  // writing, reading
24  mesh[5] = 3.14;
25  REQUIRE( mesh[5] == 3.14 );
26  CHECK( mesh(0,0,5) == 3.14 );
27  CHECK( *(mesh.real()+5) == 3.14 );
28 
29  mesh(3,4,1) = 2.71;
30  REQUIRE( mesh[1041] == 2.71 );
31  CHECK( mesh(3,4,1) == 2.71 );
32  CHECK( mesh(52,1) == 2.71 );
33  Vec_3D<int> pos(3,4,1);
34  CHECK( mesh(pos) == 2.71 );
35 
36  // copy constructor
37  Mesh_base<double> mesh2(mesh);
38  CHECK( mesh2[0] == -0.5 );
39  CHECK( mesh2[5] == 3.14 );
40  CHECK( mesh2[1041] == 2.71 );
41 
42  // assign operator
43  Mesh_base<double> mesh3(2,5,7);
44  mesh3 = mesh;
45  CHECK( mesh3.N1 == 8 );
46  CHECK( mesh3.N2 == 16 );
47  CHECK( mesh3.N3 == 20 );
48  CHECK( mesh3.length == 2560 );
49  CHECK( mesh3[0] == -0.5 );
50  CHECK( mesh3[5] == 3.14 );
51  CHECK( mesh3[1041] == 2.71 );
52 
53  // operations
54  mesh*=2.;
55  CHECK( mesh[0] == Approx(-1.) );
56  CHECK( mesh[5] == Approx(6.28) );
57  mesh+=1.;
58  CHECK( mesh[0] == Approx(0.) );
59  CHECK( mesh[5] == Approx(7.28) );
60  mesh/=7.28;
61  CHECK( mesh[0] == Approx(0.) );
62  CHECK( mesh[5] == Approx(1.) );
63 }
64 
65 TEST_CASE( "UNIT TEST: mesh class {Mesh}", "[core]" )
66 {
67  BOOST_LOG_TRIVIAL(info) << "mesh class {Mesh}";
68 
69  // dimension
70  Mesh mesh_c(8);
71  mesh_c.assign(0.);
72  CHECK( mesh_c.N == 8 );
73  CHECK( mesh_c.N1 == 8 );
74  CHECK( mesh_c.N2 == 8 );
75  CHECK( mesh_c.N3 == 10 );
76 
77  // writing, reading
78  mesh_c[90] = 3.14;
79  REQUIRE( mesh_c[90] == (FTYPE_t)3.14 );
80  CHECK( mesh_c(1,1,0) == (FTYPE_t)3.14 );
81 
82  Vec_3D<int> pos(1,1,0);
83  CHECK( mesh_c(pos) == (FTYPE_t)3.14 );
84  pos = Vec_3D<int>(9,-7,8);
85  CHECK( mesh_c(pos) == (FTYPE_t)3.14 );
86  pos = Vec_3D<int>(-6,10,0);
87  mesh_c(pos) = (FTYPE_t)2.5;
88  CHECK( mesh_c(2,2,0) == (FTYPE_t)2.5 );
89  CHECK( mesh_c[180] == (FTYPE_t)2.5 );
90 
91  // copy constructor
92  Mesh mesh2_c(mesh_c);
93  CHECK( mesh2_c[90] == (FTYPE_t)3.14 );
94  CHECK( mesh2_c[180] == (FTYPE_t)2.5 );
95 
96  // assign operator
97  Mesh mesh3_c(14);
98  mesh3_c = mesh_c;
99  CHECK( mesh3_c.N1 == 8 );
100  CHECK( mesh3_c.N2 == 8 );
101  CHECK( mesh3_c.N3 == 10 );
102  CHECK( mesh3_c.N == 8 );
103  CHECK( mesh3_c[90] == (FTYPE_t)3.14 );
104  CHECK( mesh3_c[180] == (FTYPE_t)2.5 );
105 
106  // operations
107  mesh3_c*=2.;
108  CHECK( mesh3_c[90] == Approx(6.28) );
109  CHECK( mesh3_c[180] == Approx(5) );
110  mesh3_c-=5.;
111  CHECK( mesh3_c[90] == Approx(1.28) );
112  CHECK( mesh3_c[180] == Approx(0) );
113  mesh3_c/=1.28;
114  CHECK( mesh3_c[90] == Approx(1.) );
115  CHECK( mesh3_c[180] == Approx(0) );
116 }
T * real()
Definition: class_mesh.hpp:36
: creates a mesh of N*N*(N+2) cells
Definition: class_mesh.hpp:95
TEST_CASE("UNIT TEST: mesh class {Mesh_base<T>}","[core]")
Definition: test_mesh.cpp:8
#define REQUIRE(...)
Definition: catch.hpp:13849
size_t N1
Definition: class_mesh.hpp:32
size_t N3
Definition: class_mesh.hpp:32
size_t N
Definition: class_mesh.hpp:102
size_t length
Definition: class_mesh.hpp:32
void assign(T val)
Definition: class_mesh.hpp:38
size_t N2
Definition: class_mesh.hpp:32
#define CHECK(...)
Definition: catch.hpp:13860
define container Mesh