COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-cgal-tetra-sf.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 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 "Tetrahedral mesh testing on CGAL generated meshes"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include <boost/assign/list_of.hpp>
13 #include <boost/foreach.hpp>
14 #include <boost/mpl/for_each.hpp>
15 
17 #include "common/Log.hpp"
18 
19 #include "mesh/Connectivity.hpp"
20 #include "mesh/Mesh.hpp"
21 #include "mesh/Region.hpp"
22 #include "common/Table.hpp"
23 #include "mesh/ElementData.hpp"
24 #include "mesh/Dictionary.hpp"
25 #include "mesh/Field.hpp"
26 #include "mesh/Space.hpp"
27 
29 #include "mesh/ElementTypes.hpp"
30 
32 
33 
34 using namespace cf3;
35 using namespace cf3::common;
36 using namespace cf3::mesh;
37 using namespace cf3::CGAL;
38 
40 
42 struct GlobalFixture {
43 
45  if(!sphere) {
46  sphere = allocate_component<Mesh>("sphere");
47  MeshParameters params;
48  create_mesh(SphereFunction(1.), *sphere, params);
49  sphere->write_mesh(URI("sphere.vtk"));
50  }
51  }
52 
53  static boost::shared_ptr< Mesh > sphere;
54 };
55 
56 boost::shared_ptr< Mesh > GlobalFixture::sphere = boost::shared_ptr< Mesh >();
57 
59 
62 {
63  TetraSFFixture() : sphere(*GlobalFixture::sphere) {}
64  const Mesh& sphere;
65 };
66 
68 
71 template<typename FunctorT>
72 struct LoopElems
73 {
74 
75  LoopElems( const Elements& aregion, FunctorT afunctor )
76  : region(aregion),
77  functor(afunctor)
78  {}
79 
80  template < typename EType >
81  void operator() ( EType& T )
82  {
83 
85  if( !IsElementType<EType>()(region.element_type()) )
86  return;
87 
88  typename Table<Uint>::ArrayT const& conn_table = region.geometry_space().connectivity().array();
89  const Table<Real>& coords = region.geometry_fields().coordinates();
90  // loop on elements
91  BOOST_FOREACH(const Table<Uint>::ConstRow& elem, conn_table)
92  {
93  typename EType::NodesT nodes;
94  fill(nodes, coords, elem );
95  functor(nodes, T);
96  }
97  }
98 
99  const Elements& region;
100  FunctorT functor;
101 };
102 
104 template<typename RangeT, typename FunctorT>
105 void loop_over_regions(const RangeT& range, FunctorT functor) {
106  BOOST_FOREACH(const Elements& region, range) {
107  boost::mpl::for_each<LagrangeP1::CellTypes>( LoopElems<FunctorT> ( region, functor ) );
108  }
109 }
110 
113  VolumeFunctor(Real& avolume) : volume(avolume) {}
114  template<typename NodesT, typename ElementT>
115  void operator()(const NodesT& nodes, const ElementT& element) {
116  volume += ElementT::volume(nodes);
117  }
118  Real& volume;
119 };
120 
122 
123 BOOST_GLOBAL_FIXTURE( GlobalFixture ) // creates a global fixture, and thus all meshes
124 
125 
127 BOOST_FIXTURE_TEST_SUITE( TetraSF, TetraSFFixture )
128 
130 
132 BOOST_AUTO_TEST_CASE( MeshStats )
133 {
134  Real volume = 0.;
135  loop_over_regions(find_components_recursively<Elements>(sphere), VolumeFunctor(volume));
136  BOOST_CHECK_CLOSE(4.1627113937322715, volume, 0.1);
137  CFinfo << "calculated volume: " << volume << CFendl;
138 }
139 
141 
142 BOOST_AUTO_TEST_SUITE_END()
143 
144 
#define CFinfo
these are always defined
Definition: Log.hpp:104
void create_mesh(const ImplicitFunction &function, Mesh &mesh, const MeshParameters parameters)
Using the given implicit function delimiting a domain,.
static boost::shared_ptr< Mesh > sphere
ArrayT & array()
Definition: Table.hpp:92
void operator()(const NodesT &nodes, const ElementT &element)
const Elements & region
boost::proto::terminal< SFOp< VolumeOp > >::type const volume
Static terminals that can be used in proto expressions.
LoopElems(const Elements &aregion, FunctorT afunctor)
BOOST_AUTO_TEST_CASE(Channel3D)
#define CFendl
Definition: Log.hpp:109
Sphere around the origin with radius r.
Classes for CGAL mesh format operations.
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
Basic Classes for Mesh applications used by COOLFluiD.
Fixture for each test.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
void fill(NodeValuesT &to_fill, const common::Table< Real > &data_array, const RowT &element_row, const Uint start=0)
Fill STL-vector like per-node data storage.
Definition: ElementData.hpp:28
Component holding a 2 dimensional array of a templated type.
Definition: Table.hpp:45
BOOST_GLOBAL_FIXTURE(GlobalFixture) BOOST_AUTO_TEST_CASE(MeshStats)
Accumulate some statistics about the cell volumes.
VolumeFunctor(Real &avolume)
void loop_over_regions(const RangeT &range, FunctorT functor)
Looping over all elements in a range of regions.
Simple test functor to compute the volume.
Most basic kernel library.
Definition: Action.cpp:19
Parameters for mesh generation, as defined in the CGAL manual.
Use a global fixture, so mesh creation happens only once.
Send comments to:
COOLFluiD Web Admin