Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
test_mesh.cpp File Reference
#include <catch.hpp>
#include <boost/log/trivial.hpp>
#include "class_mesh.hpp"
Include dependency graph for test_mesh.cpp:

Go to the source code of this file.

Macros

#define BOOST_LOG_DYN_LINK   1
 

Functions

 TEST_CASE ("UNIT TEST: mesh class {Mesh_base<T>}","[core]")
 
 TEST_CASE ("UNIT TEST: mesh class {Mesh}","[core]")
 

Macro Definition Documentation

#define BOOST_LOG_DYN_LINK   1

Definition at line 3 of file test_mesh.cpp.

Function Documentation

TEST_CASE ( "UNIT TEST: mesh class {Mesh_base<T>}"  ,
""  [core] 
)

Definition at line 8 of file test_mesh.cpp.

References Mesh_base< T >::assign(), CHECK, Mesh_base< T >::length, Mesh_base< T >::N1, Mesh_base< T >::N2, Mesh_base< T >::N3, Mesh_base< T >::real(), and REQUIRE.

8  : 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 }
: class handling basic mesh functions, the most important are creating and destroing the underlying d...
Definition: class_mesh.hpp:24
TEST_CASE ( "UNIT TEST: mesh class {Mesh}"  ,
""  [core] 
)

Definition at line 65 of file test_mesh.cpp.

References Mesh_base< T >::assign(), CHECK, Mesh::N, Mesh_base< T >::N1, Mesh_base< T >::N2, Mesh_base< T >::N3, and REQUIRE.

65  : 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 }
: creates a mesh of N*N*(N+2) cells
Definition: class_mesh.hpp:95