COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-lagrangep1-hexa3d.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 the Hexa3D shape function"
9 
10 #include <boost/assign/list_of.hpp>
11 #include <boost/test/unit_test.hpp>
12 
14 #include <Eigen/StdVector>
15 
16 #include "common/Log.hpp"
17 
18 #include "common/Table.hpp"
21 
23 
24 using namespace boost::assign;
25 using namespace cf3;
26 using namespace cf3::mesh;
27 using namespace cf3::mesh::Integrators;
28 using namespace cf3::mesh::LagrangeP1;
29 using namespace cf3::Tools::Testing;
30 
32 
33 typedef Hexa3D ETYPE;
34 
36 {
39  mapped_coords(0.5, 0.4, 0.1),
40  unit_nodes
41  (
42  (ETYPE::NodesT() <<
43  0., 0., 0.,
44  1., 0., 0.,
45  1., 1., 0.,
46  0., 1., 0.,
47  0., 0., 1.,
48  1., 0., 1.,
49  1., 1., 1.,
50  0., 1., 1.).finished()
51  ),
52  skewed_nodes
53  (
54  (ETYPE::NodesT() <<
55  0.5, 0.5, 0.5,
56  1., 0., 0.,
57  1., 1., 0.,
58  0., 1., 0.,
59  0., 0., 1.,
60  1., 0., 1.,
61  1.5, 1.5, 1.5,
62  0., 1., 1.).finished()
63  )
64  {
65  }
66 
69  {
70  }
75 
76  struct ConstFunctor
77  {
78  ConstFunctor(const ETYPE::NodesT& node_list) : m_nodes(node_list) {}
79 
80  Real operator()() const
81  {
82  return Hexa3D::jacobian_determinant(mapped_coords, m_nodes);
83  }
85  private:
87  };
88 };
89 
91 
92 BOOST_FIXTURE_TEST_SUITE( Hexa3DSuite, Hexa3DFixture )
93 
94 
97 {
98  BOOST_CHECK_CLOSE(ETYPE::volume(unit_nodes), 1., 0.0001);
99  BOOST_CHECK_CLOSE(ETYPE::volume(skewed_nodes), 1., 0.0001);
100 
101  ETYPE::NodesT nodes_hexa3D;
102  nodes_hexa3D <<
103  0.0, 0.0, 0.0,
104  1.0, 0.0, 0.0,
105  1.0, 1.0, 0.0,
106  0.0, 1.0, 0.0,
107  0.0, 0.0, 1.0,
108  1.0, 0.0, 1.0,
109  1.0, 1.0, 1.0,
110  0.0, 1.0, 1.0;
111  BOOST_CHECK_EQUAL(ETYPE::volume(nodes_hexa3D), 1.);
112 }
113 
115 {
116  ETYPE::SF::ValueT reference_result;
117  reference_result << 0.03375, 0.10125, 0.23625, 0.07875, 0.04125, 0.12375, 0.28875, 0.09625;
118 
119  ETYPE::SF::ValueT result;
120  ETYPE::SF::compute_value(mapped_coords, result);
121 
122  Accumulator accumulator;
123  vector_test(result, reference_result, accumulator);
124  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 10); // Maximal difference can't be greater than 10 times the least representable unit
125 }
126 
127 BOOST_AUTO_TEST_CASE( IntegrateConst )
128 {
129  ConstFunctor ftor(unit_nodes);
130  Real result = 0.0;
131 
132  gauss_integrate<1, GeoShape::HEXA>(ftor, ftor.mapped_coords, result);
133  BOOST_CHECK_CLOSE(result, 1., 0.000001);
134 }
135 
136 BOOST_AUTO_TEST_CASE( MappedCoordinates )
137 {
138  ETYPE::NodesT inverted;
139  inverted <<
140  0., 1., 1.,
141  1.3, 1.4, 1.5,
142  1., 0., 1.,
143  0., 0., 1.,
144  0., 1., 0.,
145  1., 1., 0.,
146  1., 0., 0.,
147  0.7, 0.6, 0.5;
148 
149  const ETYPE::NodesT bignodes = unit_nodes * 100.;
150  const ETYPE::NodesT biginverted = inverted * 100.;
151 
152  ETYPE::NodesT parallelepiped = unit_nodes;
153  parallelepiped.block<4, 1>(4, XX).array() += 1.;
154  parallelepiped.block<4, 1>(4, YY).array() += 0.3;
155 
156  const Real max_ulps = boost::accumulators::max(test(0.1+1e-12, 0.1).ulps); //expected max ulps based on the iteration threshold
157 
158  // boost::assign doesn't work here, because of the alignment issues with Eigen fixed-size types
159  std::vector<ETYPE::NodesT,Eigen::aligned_allocator<ETYPE::NodesT> > test_nodes;
160  test_nodes.push_back(unit_nodes);
161  test_nodes.push_back(skewed_nodes);
162  test_nodes.push_back(inverted);
163  test_nodes.push_back(bignodes);
164  test_nodes.push_back(biginverted);
165  test_nodes.push_back(parallelepiped);
166  const std::vector<Real> ulps_list = boost::assign::list_of(15.)(max_ulps)(max_ulps)(15.)(max_ulps)(20.);
167  Uint idx = 0;
168  BOOST_FOREACH(const ETYPE::NodesT& nodes, test_nodes)
169  {
170  ETYPE::SF::ValueT sf;
171  ETYPE::SF::compute_value(mapped_coords, sf);
172  const ETYPE::CoordsT coords = sf * nodes;
173  std::cout << "Looking for coords " << coords << " in mapped coords " << mapped_coords << std::endl;
174 
175  ETYPE::MappedCoordsT result;
176  ETYPE::compute_mapped_coordinate(coords, nodes, result);
177 
178  Accumulator accumulator;
179  vector_test(result, mapped_coords, accumulator);
180  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), ulps_list[idx++]);
181  }
182 }
183 
184 BOOST_AUTO_TEST_CASE( MappedGradient )
185 {
186  ETYPE::SF::GradientT expected;
187  expected(KSI, 0) = -0.06750;
188  expected(ETA, 0) = -0.05625;
189  expected(ZTA, 0) = -0.03750;
190  expected(KSI, 1) = 0.06750;
191  expected(ETA, 1) = -0.16875;
192  expected(ZTA, 1) = -0.1125;
193  expected(KSI, 2) = 0.1575;
194  expected(ETA, 2) = 0.16875;
195  expected(ZTA, 2) = -0.2625;
196  expected(KSI, 3) = -0.1575;
197  expected(ETA, 3) = 0.05625;
198  expected(ZTA, 3) = -0.08750;
199  expected(KSI, 4) = -0.08250;
200  expected(ETA, 4) = -0.06875;
201  expected(ZTA, 4) = 0.03750;
202  expected(KSI, 5) = 0.08250;
203  expected(ETA, 5) = -0.20625;
204  expected(ZTA, 5) = 0.1125;
205  expected(KSI, 6) = 0.1925;
206  expected(ETA, 6) = 0.20625;
207  expected(ZTA, 6) = 0.2625;
208  expected(KSI, 7) = -0.1925;
209  expected(ETA, 7) = 0.06875;
210  expected(ZTA, 7) = 0.08750;
211 
212  ETYPE::SF::GradientT result;
213  ETYPE::SF::compute_gradient(mapped_coords, result);
214 
215  Accumulator accumulator;
216  vector_test(result, expected, accumulator);
217  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
218 }
219 
220 BOOST_AUTO_TEST_CASE( JacobianDeterminant )
221 {
222  BOOST_CHECK_CLOSE(ETYPE::jacobian_determinant(mapped_coords, unit_nodes), 0.125, 0.00001);
223  BOOST_CHECK_CLOSE(ETYPE::jacobian_determinant(mapped_coords, skewed_nodes), 0.1875, 0.00001);
224 }
225 
227 {
228  ETYPE::JacobianT expected;
229  expected(0,0) = 0.5625;
230  expected(0,1) = 0.06250;
231  expected(0,2) = 0.06250;
232  expected(1,0) = 0.07500;
233  expected(1,1) = 0.5750;
234  expected(1,2) = 0.07500;
235  expected(2,0) = 0.1125;
236  expected(2,1) = 0.1125;
237  expected(2,2) = 0.6125;
238 
239  ETYPE::JacobianT result;
240  ETYPE::compute_jacobian(mapped_coords, skewed_nodes, result);
241 
242  Accumulator accumulator;
243  vector_test(result, expected, accumulator);
244  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
245 }
246 
247 BOOST_AUTO_TEST_CASE( JacobianAdjoint )
248 {
249  ETYPE::JacobianT expected;
250  expected(0,0) = 0.34375;
251  expected(0,1) = -0.03125;
252  expected(0,2) = -0.03125;
253  expected(1,0) = -0.03750;
254  expected(1,1) = 0.3375;
255  expected(1,2) = -0.03750;
256  expected(2,0) = -0.05625;
257  expected(2,1) = -0.05625;
258  expected(2,2) = 0.31875;
259 
260  ETYPE::JacobianT result;
261  ETYPE::compute_jacobian_adjoint(mapped_coords, skewed_nodes, result);
262 
263  Accumulator accumulator;
264  vector_test(result, expected, accumulator);
265  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
266 }
267 
268 BOOST_AUTO_TEST_CASE( Is_coord_in_element )
269 {
270  const ETYPE::CoordsT centroid = skewed_nodes.colwise().sum() / ETYPE::nb_nodes;
271 
272  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(centroid,skewed_nodes),true);
273 
274  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(skewed_nodes.row(0),skewed_nodes),true);
275  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(skewed_nodes.row(2),skewed_nodes),true);
276  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(skewed_nodes.row(5),skewed_nodes),true);
277  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(skewed_nodes.row(6),skewed_nodes),true);
278  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(skewed_nodes.row(7),skewed_nodes),true);
279 
280  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(centroid*5.,skewed_nodes),false);
281 }
282 
284 
285 BOOST_AUTO_TEST_SUITE_END()
286 
287 
static void compute_jacobian_adjoint(const MappedCoordsT &mapped_coord, const NodesT &nodes, JacobianT &result)
Definition: Hexa3D.cpp:308
~Hexa3DFixture()
common tear-down for each test case
boost::proto::terminal< SFOp< JacobianDeterminantOp > >::type const jacobian_determinant
static void compute_jacobian(const MappedCoordsT &mapped_coord, const NodesT &nodes, MatrixType &jacobian)
static Real jacobian_determinant(const MappedCoordsT &mapped_coord, const NodesT &nodes)
Definition: Hexa3D.cpp:169
static bool is_coord_in_element(const CoordsT &coord, const NodesT &nodes)
Definition: Hexa3D.cpp:73
Real max(const Real a, const Real b)
Maximum between two scalars.
Definition: Terminals.hpp:228
Hexa3DFixture()
common setup for each test case
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
Definition: Defs.hpp:17
ConstFunctor(const ETYPE::NodesT &node_list)
Eigen::Matrix< Real, nb_nodes, Hexa3D_traits::dimension > NodesT
boost::accumulators::accumulator_set< Real, boost::accumulators::stats< boost::accumulators::tag::min, boost::accumulators::tag::mean, boost::accumulators::tag::max, boost::accumulators::tag::median, boost::accumulators::tag::lazy_variance > > ulps
Stores statistics for comparisons of inexact (floating-point) types using Units in the Last Place (UL...
Definition: Difference.hpp:55
Basic Classes for Mesh applications used by COOLFluiD.
const ETYPE::NodesT skewed_nodes
namespace holding LagrangeP1 shape functions and elements
const ETYPE::NodesT unit_nodes
Top-level namespace for coolfluid.
Definition: Action.cpp:18
static void compute_mapped_coordinate(const CoordsT &coord, const NodesT &nodes, MappedCoordsT &mapped_coord)
Definition: Hexa3D.cpp:85
BOOST_AUTO_TEST_CASE(Volume)
Eigen::Matrix< Real, Hexa3D_traits::dimension, 1 > CoordsT
Functions to provide integration over elements.
Definition: Gauss.hpp:26
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
const ETYPE::MappedCoordsT mapped_coords
common values accessed by all tests goes here
static Real volume(const NodesT &nodes)
Definition: Hexa3D.cpp:324
Definition: Defs.hpp:17
void vector_test(const VectorT &A, const VectorT &B, Accumulator &Result)
Compares vector-like sequences.
Definition: Difference.hpp:139
Eigen::Matrix< Real, Hexa3D_traits::SF::dimensionality, Hexa3D_traits::dimension > JacobianT
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Definition: Hexa3D.hpp:36
Stores the results of the difference::test() function.
Definition: Difference.hpp:49
Send comments to:
COOLFluiD Web Admin