COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-lagrangep1-tetra3d.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 ETYPE shape function"
9 
10 #include <boost/assign/list_of.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include "common/Log.hpp"
14 
15 #include "common/Table.hpp"
18 
20 
21 using namespace boost::assign;
22 using namespace cf3;
23 using namespace cf3::mesh;
24 using namespace cf3::mesh::Integrators;
25 using namespace cf3::mesh::LagrangeP1;
26 using namespace cf3::Tools::Testing;
27 
29 
30 typedef Tetra3D ETYPE;
31 
33 {
37  mapped_coords(0.1, 0.8, 0.45),
38  nodes
39  (
40  (NodesT() <<
41  0.830434, 0.885201, 0.188108,
42  0.89653, 0.899961, 0.297475,
43  0.888273, 0.821744, 0.211428,
44  0.950439, 0.904872, 0.20736).finished()
45  ),
46  volume(1.451803461048456186e-4)
47  {
48  }
49 
52  {
53  }
55 
57  const NodesT nodes;
58  const Real volume;
59 
60  struct ConstFunctor
61  {
62  ConstFunctor(const NodesT& node_list) : m_nodes(node_list) {}
63 
64  Real operator()() const
65  {
66  return ETYPE::jacobian_determinant(mapped_coords, m_nodes);
67  }
69  private:
70  const NodesT& m_nodes;
71  };
72 };
73 
75 
76 BOOST_FIXTURE_TEST_SUITE( LagrangeP1Tetra3DSuite, LagrangeP1Tetra3DFixture )
77 
78 
81 {
82  const ETYPE::SF::ValueT reference_result(-0.35, 0.1, 0.8, 0.45);
83  ETYPE::SF::ValueT result;
84  ETYPE::SF::compute_value(mapped_coords, result);
85  Accumulator accumulator;
86  vector_test(result, reference_result, accumulator);
87  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 10); // Maximal difference can't be greater than 10 times the least representable unit
88 }
89 
90 BOOST_AUTO_TEST_CASE( MappedCoordinates )
91 {
92  const ETYPE::MappedCoordsT test_coords(0.92, 0.87, 0.21);
93  const ETYPE::CoordsT reference_result(1.779178467272182762e-02, 4.106555656123735409e-01, 5.386286149811901902e-01);
94  ETYPE::MappedCoordsT result;
95  ETYPE::compute_mapped_coordinate(test_coords, nodes, result);
96  Accumulator accumulator;
97  vector_test(result, reference_result, accumulator);
98  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 10); // Maximal difference can't be greater than 10 times the least representable unit
99 }
100 
101 BOOST_AUTO_TEST_CASE( IntegrateConst )
102 {
103  ConstFunctor ftor(nodes);
104  Real result = 0.0;
105  gauss_integrate<1, GeoShape::TETRA>(ftor, ftor.mapped_coords, result);
106  BOOST_CHECK_CLOSE(result, volume, 0.0000000001);
107 }
108 
109 BOOST_AUTO_TEST_CASE( MappedGradient )
110 {
111  ETYPE::SF::GradientT expected;
112  expected(XX, 0) = -1.;
113  expected(YY, 0) = -1.;
114  expected(ZZ, 0) = -1.;
115  expected(XX, 1) = 1.;
116  expected(YY, 1) = 0.;
117  expected(ZZ, 1) = 0.;
118  expected(XX, 2) = 0.;
119  expected(YY, 2) = 1.;
120  expected(ZZ, 2) = 0.;
121  expected(XX, 3) = 0.;
122  expected(YY, 3) = 0.;
123  expected(ZZ, 3) = 1.;
124  ETYPE::SF::GradientT result;
125  ETYPE::SF::compute_gradient(mapped_coords, result);
126  Accumulator accumulator;
127  vector_test(result, expected, accumulator);
128  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
129 }
130 
131 BOOST_AUTO_TEST_CASE( JacobianDeterminant )
132 {
133  // Shapefunction determinant should be a sixth of the volume for tetrahedra
134  const Real result = ETYPE::jacobian_determinant(mapped_coords, nodes)/6.;
135  BOOST_CHECK_CLOSE(result, volume, 0.00001);
136 }
137 
139 {
140  ETYPE::JacobianT expected;
141  expected(0,0) = 6.609600000000004361e-02;
142  expected(0,1) = 1.475999999999999535e-02;
143  expected(0,2) = 1.093669999999999920e-01;
144  expected(1,0) = 5.783899999999997377e-02;
145  expected(1,1) = -6.345699999999998564e-02;
146  expected(1,2) = 2.332000000000000739e-02;
147  expected(2,0) = 1.200050000000000283e-01;
148  expected(2,1) = 1.967099999999999405e-02;
149  expected(2,2) = 1.925199999999999134e-02;
150  ETYPE::JacobianT result;
151  ETYPE::compute_jacobian(mapped_coords, nodes, result);
152  Accumulator accumulator;
153  vector_test(result, expected, accumulator);
154  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
155 }
156 
157 BOOST_AUTO_TEST_CASE( JacobianAdjoint )
158 {
159  ETYPE::JacobianT expected;
160  expected(0,0) = -1.680401883999999273e-03;
161  expected(0,1) = 1.867198736999999475e-03;
162  expected(0,2) = 7.284304918999997755e-03;
163  expected(1,0) = 1.685000172000002431e-03;
164  expected(1,1) = -1.185210664300000161e-02;
165  expected(1,2) = 4.784319192999994877e-03;
166  expected(2,0) = 8.752908253999998334e-03;
167  expected(2,1) = 4.710993839999994925e-04;
168  expected(2,2) = -5.047957512000001042e-03;
169  ETYPE::JacobianT result;
170  ETYPE::compute_jacobian_adjoint(mapped_coords, nodes, result);
171  Accumulator accumulator;
172  vector_test(result, expected, accumulator);
173  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 5);
174 }
175 
176 BOOST_AUTO_TEST_CASE( Is_coord_in_element )
177 {
178  const ETYPE::CoordsT centroid = nodes.colwise().sum() / ETYPE::nb_nodes;
179 
180  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(centroid,nodes),true);
181 
182  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(nodes.row(0),nodes),true);
183  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(nodes.row(1),nodes),true);
184  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(nodes.row(2),nodes),true);
185  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(nodes.row(3),nodes),true);
186 
187  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(2.0 * centroid,nodes),false);
188 }
189 
191 
192 BOOST_AUTO_TEST_SUITE_END()
193 
194 
static void compute_jacobian_adjoint(const MappedCoordsT &mapped_coord, const NodesT &nodes, JacobianT &result)
Definition: Hexa3D.cpp:308
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Definition: Tetra3D.hpp:36
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
boost::proto::terminal< SFOp< VolumeOp > >::type const volume
Static terminals that can be used in proto expressions.
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
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
Definition: Defs.hpp:17
Definition: Defs.hpp:17
Eigen::Matrix< Real, nb_nodes, Hexa3D_traits::dimension > NodesT
~LagrangeP1Tetra3DFixture()
common tear-down for each test case
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
LagrangeP1Tetra3DFixture()
common setup for each test case
Basic Classes for Mesh applications used by COOLFluiD.
namespace holding LagrangeP1 shape functions and elements
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
Eigen::Matrix< Real, Hexa3D_traits::dimension, 1 > CoordsT
const ETYPE::MappedCoordsT mapped_coords
common values accessed by all tests goes here
Functions to provide integration over elements.
Definition: Gauss.hpp:26
BOOST_AUTO_TEST_CASE(ShapeFunction)
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
Stores the results of the difference::test() function.
Definition: Difference.hpp:49
Send comments to:
COOLFluiD Web Admin