COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-shapefunctions.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 "Proposition for new element / shapefunction API"
9 
10 #include <iostream>
11 #include <boost/test/unit_test.hpp>
12 #include "common/Log.hpp"
13 #include "common/OptionList.hpp"
14 #include "common/Component.hpp"
15 #include "common/Core.hpp"
16 #include "common/Environment.hpp"
17 
18 #include "mesh/ElementType.hpp"
19 #include "mesh/ShapeFunctionT.hpp"
21 #include "mesh/LagrangeP1/Line.hpp"
23 
24 #include "mesh/ElementTypes.hpp"
25 
26 using namespace cf3;
27 using namespace cf3::common;
28 using namespace cf3::mesh;
29 
31 
33 {
36  {
37  }
38 
41  {
42  }
43 };
44 
46 
47 BOOST_FIXTURE_TEST_SUITE( Test_ShapeFunction_TestSuite, Test_ShapeFunction_Fixture )
48 
49 
51 BOOST_AUTO_TEST_CASE( sf_static_version )
52 {
53  LagrangeP0::Triag::MappedCoordsT mapped_coord = (LagrangeP0::Triag::MappedCoordsT() << 0, 0 ).finished();
54 
55  LagrangeP0::Triag::ValueT values = LagrangeP0::Triag::value( mapped_coord );
56  const RealMatrix& local_coords = LagrangeP0::Triag::local_coordinates();
57 
58  std::cout << "static : values = " << values << std::endl;
59  std::cout << "static : local_coords = " << local_coords << std::endl;
60 
61  LagrangeP0::Triag::compute_value(mapped_coord, values);
62  std::cout << "static : values = " << values << std::endl;
63 
64  const RealMatrix& line_local_coords = LagrangeP1::Line::local_coordinates();
65 
66 }
67 
69 
70 BOOST_AUTO_TEST_CASE( sf_dynamic_version )
71 {
72  RealVector mapped_coord = (RealVector(2) << 0, 0).finished();
73 
74  boost::shared_ptr<ShapeFunction> sf = allocate_component< ShapeFunctionT<LagrangeP0::Triag> >("sf");
75 
76  RealRowVector values(1);// = sf->value(mapped_coord);
77  const RealMatrix& local_coords = sf->local_coordinates();
78 
79 // std::cout << "dynamic: values = " << values << std::endl;
80  std::cout << "dynamic: local_coords = " << local_coords << std::endl;
81 
82  sf->compute_value(mapped_coord,values);
83  std::cout << "dynamic: values = " << values << std::endl;
84 }
85 
87 
88 BOOST_AUTO_TEST_CASE( etype_static_version )
89 {
90  typedef LagrangeP1::Triag2D ETYPE;
92  0, 0,
93  1, 0,
94  0, 1
95  ).finished();
96  ETYPE::CoordsT centroid;
97  ETYPE::compute_centroid(nodes,centroid);
98  std::cout << "static : centroid = " << centroid.transpose() << std::endl;
99 }
100 
102 
103 BOOST_AUTO_TEST_CASE( etype_dynamic_version )
104 {
105  RealMatrix nodes = (RealMatrix(3,2) <<
106  0, 0,
107  1, 0,
108  0, 1
109  ).finished();
110  RealVector centroid(2);
111 
112  boost::shared_ptr< ElementType > etype = build_component_abstract_type<ElementType>("cf3.mesh.LagrangeP1.Triag2D","etype");
113  etype->compute_centroid(nodes,centroid);
114  std::cout << "dynamic: centroid = " << centroid.transpose() << std::endl;
115 
116  // Check if compute_normal throws, as it is not implemented in the static implementation
117  Core::instance().environment().options().set("exception_outputs",false);
118  Core::instance().environment().options().set("exception_backtrace",false);
119  BOOST_CHECK_THROW(etype->compute_normal(nodes,centroid),common::NotImplemented);
120  Core::instance().environment().options().set("exception_outputs",true);
121  Core::instance().environment().options().set("exception_backtrace",true);
122 
123  boost::shared_ptr< ElementType > quad_face = build_component_abstract_type<ElementType>("cf3.mesh.LagrangeP1.Quad3D","etype");
124 
125  RealMatrix quad_face_nodes = (RealMatrix(4,3) <<
126  0, 0, 0,
127  1, 0, 0,
128  1, 1, 0,
129  0, 1, 0
130  ).finished();
131 
132  RealVector normal(quad_face->dimension());
133  quad_face->compute_normal(quad_face_nodes,normal);
134  std::cout << "dynamic: normal = " << normal.transpose() << std::endl;
135  std::cout << "dynamic: sf = " << etype->shape_function().derived_type_name() << std::endl;
136  std::cout << "dynamic: sf = " << quad_face->shape_function().derived_type_name() << std::endl;
137  std::cout << "dynamic: sf = " << etype->face_type(0).derived_type_name() << std::endl;
138 
139  std::cout << "dynamic: type = " << etype->derived_type_name() << std::endl;
140 
141 }
142 
144 
145 
146 BOOST_AUTO_TEST_SUITE_END()
147 
148 
boost::proto::terminal< SFOp< NormalOp > >::type const normal
Translation from dynamic to static API.
~Test_ShapeFunction_Fixture()
common tear-down for each test case
BOOST_AUTO_TEST_CASE(sf_static_version)
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Definition: Triag2D.hpp:36
static void compute_centroid(const NodesT &nodes, CoordsT &centroid)
Definition: Hexa3D.cpp:64
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealMatrix
Dynamic sized matrix of Real scalars.
Definition: MatrixTypes.hpp:22
Holds the Component class, as well as the ComponentIterator class plus some functions related to comp...
Eigen::Matrix< Real, nb_nodes, Hexa3D_traits::dimension > NodesT
Eigen::Matrix< Real, 1, Eigen::Dynamic > RealRowVector
Dynamic sized row vector.
Definition: MatrixTypes.hpp:31
Basic Classes for Mesh applications used by COOLFluiD.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
Definition: MatrixTypes.hpp:25
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Eigen::Matrix< Real, Hexa3D_traits::dimension, 1 > CoordsT
common::Environment & environment() const
Definition: Core.cpp:168
static Core & instance()
Definition: Core.cpp:37
OptionList & options()
Definition: Component.cpp:856
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
Test_ShapeFunction_Fixture()
common setup for each test case
Most basic kernel library.
Definition: Action.cpp:19
Send comments to:
COOLFluiD Web Admin