COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-math-hilbert.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for cf3::mesh::HilbertNumbering"
9 
10 
11 #include <boost/test/unit_test.hpp>
12 
13 #include "common/Log.hpp"
14 
15 #include "common/Core.hpp"
16 #include "common/Environment.hpp"
17 
18 #include "math/Consts.hpp"
19 #include "math/Hilbert.hpp"
20 
21 using namespace cf3;
22 using namespace cf3::math;
23 using namespace cf3::math::Consts;
24 using namespace cf3::common;
25 
27 
29 {
32  {
33  m_argc = boost::unit_test::framework::master_test_suite().argc;
34  m_argv = boost::unit_test::framework::master_test_suite().argv;
35  }
36 
39  {
40  }
42 
43 
45  int m_argc;
46  char** m_argv;
47 
48 };
49 
51 
52 BOOST_FIXTURE_TEST_SUITE( HilbertNumberingTests_TestSuite, HilbertNumberingTests_Fixture )
53 
54 
57 {
58  Core::instance().initiate(m_argc,m_argv);
59 }
60 
62 
63 BOOST_AUTO_TEST_CASE( test_hilbert_1d )
64 {
65  RealVector1 min; min << 0.;
66  RealVector1 max; max << 1.;
67  BoundingBox bounding_box(min,max);
68 
69  RealVector1 point;
70  Hilbert compute_hilbert_level_1(bounding_box, 1);
71  point << 0.25; BOOST_CHECK_EQUAL(compute_hilbert_level_1(point), 0u);
72  point << 0.75; BOOST_CHECK_EQUAL(compute_hilbert_level_1(point), 1u);
73 
74  Hilbert compute_hilbert_level_2(bounding_box, 2);
75  point << 0.125; BOOST_CHECK_EQUAL(compute_hilbert_level_2(point), 0u);
76  point << 0.375; BOOST_CHECK_EQUAL(compute_hilbert_level_2(point), 1u);
77  point << 0.625; BOOST_CHECK_EQUAL(compute_hilbert_level_2(point), 2u);
78  point << 0.875; BOOST_CHECK_EQUAL(compute_hilbert_level_2(point), 3u);
79 
80  CFinfo << "1D: 32 levels: max_key = " << Hilbert(bounding_box,32).max_key() << CFendl;
81  CFinfo << "uint_max() = " << uint_max() << CFendl;
82 }
83 
84 BOOST_AUTO_TEST_CASE( test_hilbert_2d )
85 {
86  BoundingBox bounding_box(RealVector2(0.,0.),RealVector2(1.,1.));
87  Hilbert compute_hilbert_level_1(bounding_box, 1);
88  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector2(0.25,0.25)), 0u);
89  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector2(0.25,0.75)), 1u);
90  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector2(0.75,0.75)), 2u);
91  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector2(0.75,0.25)), 3u);
92 
93  Hilbert compute_hilbert_level_2(bounding_box, 2);
94  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.125,0.125)), 0u);
95  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.375,0.125)), 1u);
96  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.375,0.375)), 2u);
97  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.125,0.375)), 3u);
98  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.125,0.625)), 4u);
99  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.125,0.875)), 5u);
100  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.375,0.875)), 6u);
101  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector2(0.375,0.625)), 7u);
102 
103  CFinfo << "2D: 16 levels: max_key = " << Hilbert(bounding_box,16).max_key() << CFendl;
104  CFinfo << "uint_max() = " << uint_max() << CFendl;
105 }
106 
107 BOOST_AUTO_TEST_CASE( test_hilbert_3d )
108 {
109  BoundingBox bounding_box(RealVector3(0.,0.,0.),RealVector3(1.,1.,1.));
110  Hilbert compute_hilbert_level_1(bounding_box, 1);
111  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.25,0.25,0.25)), 0u);
112  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.25,0.25,0.75)), 1u);
113  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.75,0.25,0.75)), 2u);
114  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.75,0.25,0.25)), 3u);
115  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.75,0.75,0.25)), 4u);
116  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.75,0.75,0.75)), 5u);
117  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.25,0.75,0.75)), 6u);
118  BOOST_CHECK_EQUAL(compute_hilbert_level_1(RealVector3(0.25,0.75,0.25)), 7u);
119 
120  Hilbert compute_hilbert_level_2(bounding_box, 2);
121  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector3(0.125,0.125,0.125)), 0u);
122  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector3(0.125,0.375,0.125)), 1u);
123  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector3(0.375,0.375,0.125)), 2u);
124  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector3(0.375,0.125,0.125)), 3u);
125  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector3(0.875,0.375,0.125)), 28);
126  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector3(0.875,0.875,0.875)), 45);
127  BOOST_CHECK_EQUAL(compute_hilbert_level_2(RealVector3(0.125,0.875,0.125)), 63);
128 
129  Hilbert compute_hilbert(bounding_box,10);
130  CFinfo << "3D: 10 levels: max_key = " << Hilbert(bounding_box,10).max_key() << CFendl;
131  CFinfo << "3D: 11 levels: max_key = " << Hilbert(bounding_box,11).max_key() << CFendl;
132  CFinfo << "uint_max() = " << uint_max() << CFendl;
133 }
134 
136 
138 {
140 }
141 
143 
144 BOOST_AUTO_TEST_SUITE_END()
145 
146 
#define CFinfo
these are always defined
Definition: Log.hpp:104
Eigen::Matrix< Real, 1, 1 > RealVector1
Fixed size 1x1 column vector.
Definition: MatrixTypes.hpp:39
Class to compute a global index given a coordinate, based on the Hilbert Spacefilling Curve...
Definition: Hilbert.hpp:43
BOOST_AUTO_TEST_CASE(init)
Basic Classes for Mathematical applications used by COOLFluiD.
void terminate()
Definition: Core.cpp:131
#define CFendl
Definition: Log.hpp:109
Real max(const Real a, const Real b)
Maximum between two scalars.
Definition: Terminals.hpp:228
Static functions for mathematical constants.
Definition: Consts.hpp:25
HilbertNumberingTests_Fixture()
common setup for each test case
Real min(const Real a, const Real b)
Minimum between two scalars.
Definition: Terminals.hpp:234
boost::uint64_t max_key() const
Definition: Hilbert.cpp:141
void initiate(int argc, char **argv)
Definition: Core.cpp:98
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Uint uint_max()
Returns the maximum number representable with the chosen precision.
Definition: Consts.hpp:32
~HilbertNumberingTests_Fixture()
common tear-down for each test case
Eigen::Matrix< Real, 2, 1 > RealVector2
Fixed size 2x1 column vector.
Definition: MatrixTypes.hpp:40
static Core & instance()
Definition: Core.cpp:37
Bounding box defined by minimum and maximum coordinates.
Definition: BoundingBox.hpp:24
Most basic kernel library.
Definition: Action.cpp:19
int m_argc
possibly common functions used on the tests below
Eigen::Matrix< Real, 3, 1 > RealVector3
Fixed size 3x1 column vector.
Definition: MatrixTypes.hpp:41
Send comments to:
COOLFluiD Web Admin