COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-lagrangep1-triag2d.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 ETYPE"
9 
10 #include <boost/assign/list_of.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include "common/Log.hpp"
14 
18 #include "mesh/Elements.hpp"
19 
21 
22 using namespace boost::assign;
23 using namespace cf3;
24 using namespace cf3::common;
25 using namespace cf3::mesh;
26 using namespace cf3::mesh::Integrators;
27 using namespace cf3::mesh::LagrangeP1;
28 
30 
31 typedef Triag2D ETYPE;
32 
34 {
37  LagrangeP1Triag2DFixture() : mapped_coords(0.1, 0.8), nodes((NodesT() << 0.5, 0.3,
38  1.1, 1.2,
39  0.8, 2.1).finished())
40  {
41  }
42 
45  {
46  }
48 
50  const NodesT nodes;
51 
52  struct ConstFunctor
53  {
54  ConstFunctor(const NodesT& node_list) : m_nodes(node_list) {}
55 
56  Real operator()() const
57  {
58  return ETYPE::jacobian_determinant(mapped_coords, m_nodes);
59  }
61  private:
62  const NodesT& m_nodes;
63  };
64 };
65 
67 
68 BOOST_FIXTURE_TEST_SUITE( LagrangeP1Triag2DSuite, LagrangeP1Triag2DFixture )
69 
70 
73 {
74  NodesT nodes_triag2D;
75  nodes_triag2D <<
76  0.0, 0.0,
77  1.0, 0.0,
78  1.0, 1.0;
79  BOOST_CHECK_EQUAL(ETYPE::volume(nodes_triag2D), 0.5);
80 }
81 
83 {
84  boost::shared_ptr<Dictionary> nodes = allocate_component<ContinuousDictionary>("nodes") ;
85  // Create a Elements component
86  boost::shared_ptr<Elements> comp = allocate_component<Elements>("comp");
87 
88  comp->initialize("cf3.mesh.LagrangeP1.Triag2D",*nodes);
89  BOOST_CHECK_EQUAL(comp->element_type().shape(), GeoShape::TRIAG);
90  BOOST_CHECK_EQUAL(comp->element_type().nb_nodes(), (Uint) 3);
91 
92  // Check volume calculation
93  NodesT coord;
94  coord <<
95  15, 15,
96  40, 25,
97  25, 30;
98 
99  BOOST_CHECK_EQUAL(ETYPE::volume(coord), 137.5);
100 }
101 
103 {
104  const ETYPE::SF::ValueT reference_result(0.1, 0.1, 0.8);
105  ETYPE::SF::ValueT result;
106  ETYPE::SF::compute_value(mapped_coords, result);
108  cf3::Tools::Testing::vector_test(result, reference_result, accumulator);
109  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 10); // Maximal difference can't be greater than 10 times the least representable unit
110 }
111 
112 BOOST_AUTO_TEST_CASE( MappedCoordinates )
113 {
114  const ETYPE::CoordsT test_coords(0.8, 1.2);
115  const ETYPE::MappedCoordsT reference_result(1./3., 1./3.);
116  ETYPE::MappedCoordsT result;
117  ETYPE::compute_mapped_coordinate(test_coords, nodes, result);
119  cf3::Tools::Testing::vector_test(result, reference_result, accumulator);
120  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 10); // Maximal difference can't be greater than 10 times the least representable unit
121 }
122 
123 BOOST_AUTO_TEST_CASE( IntegrateConst )
124 {
125  ConstFunctor ftor(nodes);
126  cf3::Real result = 0.0;
127  gauss_integrate<1, GeoShape::TRIAG>(ftor, ftor.mapped_coords, result);
128  BOOST_CHECK_LT(boost::accumulators::max(cf3::Tools::Testing::test(result, ETYPE::volume(nodes)).ulps), 1);
129 }
130 
131 BOOST_AUTO_TEST_CASE( MappedGradient )
132 {
133  ETYPE::SF::GradientT expected;
134  expected(0,0) = -1.;
135  expected(1,0) = -1.;
136  expected(0,1) = 1.;
137  expected(1,1) = 0.;
138  expected(0,2) = 0.;
139  expected(1,2) = 1.;
140  ETYPE::SF::GradientT result;
141  ETYPE::SF::compute_gradient(mapped_coords, result);
143  cf3::Tools::Testing::vector_test(result, expected, accumulator);
144  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
145 }
146 
147 BOOST_AUTO_TEST_CASE( JacobianDeterminant )
148 {
149  // Shapefunction determinant should be double the volume for triangles
151 }
152 
154 {
155  ETYPE::JacobianT expected;
156  expected(0,0) = 0.6;
157  expected(0,1) = 0.9;
158  expected(1,0) = 0.3;
159  expected(1,1) = 1.8;
160  ETYPE::JacobianT result;
161  ETYPE::compute_jacobian(mapped_coords, nodes, result);
163  cf3::Tools::Testing::vector_test(result, expected, accumulator);
164  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
165 }
166 
167 BOOST_AUTO_TEST_CASE( JacobianAdjoint )
168 {
169  ETYPE::JacobianT expected;
170  expected(0,0) = 1.8;
171  expected(0,1) = -0.9;
172  expected(1,0) = -0.3;
173  expected(1,1) = 0.6;
174  ETYPE::JacobianT result(2, 2);
175  ETYPE::compute_jacobian_adjoint(mapped_coords, nodes, result);
177  cf3::Tools::Testing::vector_test(result, expected, accumulator);
178  BOOST_CHECK_LT(boost::accumulators::max(accumulator.ulps), 2);
179 }
180 
181 BOOST_AUTO_TEST_CASE( Is_coord_in_element )
182 {
183  const ETYPE::CoordsT centroid = nodes.colwise().sum() / ETYPE::nb_nodes;
184 
185  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(centroid,nodes),true);
186 
187  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(nodes.row(0),nodes),true);
188  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(nodes.row(1),nodes),true);
189  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(nodes.row(2),nodes),true);
190 
191  BOOST_CHECK_EQUAL(ETYPE::is_coord_in_element(centroid * 2.,nodes),false);
192 }
193 
194 
196 
197 BOOST_AUTO_TEST_SUITE_END()
198 
199 
LagrangeP1Triag2DFixture()
common setup for each test case
static void compute_jacobian_adjoint(const MappedCoordsT &mapped_coord, const NodesT &nodes, JacobianT &result)
Definition: Hexa3D.cpp:308
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
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Definition: Triag2D.hpp:36
void test(const Elements &a, const Elements &b, Accumulator &result)
Compares Elements.
Definition: MeshDiff.cpp:98
static bool is_coord_in_element(const CoordsT &coord, const NodesT &nodes)
Definition: Hexa3D.cpp:73
~LagrangeP1Triag2DFixture()
common tear-down for each test case
Real max(const Real a, const Real b)
Maximum between two scalars.
Definition: Terminals.hpp:228
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
const ETYPE::MappedCoordsT mapped_coords
common values accessed by all tests goes here
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.
BOOST_AUTO_TEST_CASE(Volume)
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
Functions to provide integration over elements.
Definition: Gauss.hpp:26
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
static Real volume(const NodesT &nodes)
Definition: Hexa3D.cpp:324
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
Most basic kernel library.
Definition: Action.cpp:19
Stores the results of the difference::test() function.
Definition: Difference.hpp:49
Send comments to:
COOLFluiD Web Admin