COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-octtree.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 "Tests mesh octtree"
9 
10 #include <boost/test/unit_test.hpp>
11 #include <boost/assign/list_of.hpp>
12 #include <boost/assign/std/vector.hpp>
13 
14 #include "common/Core.hpp"
15 #include "common/Foreach.hpp"
16 #include "common/Log.hpp"
17 #include "common/OptionList.hpp"
19 #include "common/Link.hpp"
20 
21 #include "common/PE/Comm.hpp"
22 #include "common/PE/debug.hpp"
23 
24 #include "mesh/Mesh.hpp"
25 #include "mesh/Region.hpp"
26 #include "mesh/Elements.hpp"
27 #include "mesh/Space.hpp"
28 #include "common/Table.hpp"
29 #include "mesh/Dictionary.hpp"
30 #include "mesh/MeshGenerator.hpp"
31 #include "mesh/Octtree.hpp"
33 #include "mesh/MeshWriter.hpp"
34 
35 using namespace boost;
36 using namespace boost::assign;
37 using namespace cf3;
38 using namespace cf3::mesh;
39 using namespace cf3::common;
40 
42 
44 {
47  {
48  // uncomment if you want to use arguments to the test executable
49  m_argc = boost::unit_test::framework::master_test_suite().argc;
50  m_argv = boost::unit_test::framework::master_test_suite().argv;
51  }
52 
55  {
56  }
57 
59 
60 
62 
63  int m_argc;
64  char** m_argv;
65 
66 };
67 
69 
70 BOOST_FIXTURE_TEST_SUITE( Octtree_TestSuite, Octtree_Fixture )
71 
72 
73 
76 {
77  PE::Comm::instance().init(m_argc,m_argv);
78 }
79 
81 
82 BOOST_AUTO_TEST_CASE( Octtree_creation )
83 {
84  // create meshreader
85  boost::shared_ptr< MeshGenerator > mesh_generator = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","mesh_generator");
86  Core::instance().root().add_component(mesh_generator);
87  mesh_generator->options().set("mesh",Core::instance().root().uri()/"mesh");
88  mesh_generator->options().set("lengths",std::vector<Real>(2,10.));
89  mesh_generator->options().set("nb_cells",std::vector<Uint>(2,5));
90  mesh_generator->options().set("part",0u);
91  mesh_generator->options().set("nb_parts",1u);
92 
93  Mesh& mesh = mesh_generator->generate();
95  Octtree& octtree = *mesh.create_component<Octtree>("octtree");
96 
97  // Create and configure octtree.
98  octtree.options().set("nb_elems_per_cell", 1u );
99  octtree.options().set("mesh", mesh.handle<Mesh>());
100 
101  // Following configuration option has priority over the the previous one.
102  std::vector<Uint> nb_cells = boost::assign::list_of(5)(5);
103  octtree.options().set("nb_cells", nb_cells );
104 
105  BOOST_CHECK(true);
106 
107  Entity element;
108  RealVector2 coord;
109 
110  coord << 1. , 1. ;
111  element = octtree.find_element(coord);
112  BOOST_CHECK_EQUAL(element.idx,0u);
113 
114  coord << 3. , 1. ;
115  element = octtree.find_element(coord);
116  BOOST_CHECK_EQUAL(element.idx,1u);
117 
118  coord << 1 , 3. ;
119  element = octtree.find_element(coord);
120  BOOST_CHECK_EQUAL(element.idx,5u);
121 
122 
123  Handle<StencilComputerOcttree> stencil_computer = Core::instance().root().create_component<StencilComputerOcttree>("stencilcomputer");
124  stencil_computer->options().set("dict", dict );
125 
126  SpaceElem space_elem = SpaceElem(mesh.elements()[0]->space(*dict),7);
127  std::vector<SpaceElem> stencil;
128  stencil_computer->options().set("stencil_size", 1u );
129  stencil_computer->compute_stencil(space_elem, stencil);
130  BOOST_CHECK_EQUAL(stencil.size(), 1u);
131 
132  stencil_computer->options().set("stencil_size", 2u );
133  stencil_computer->compute_stencil(space_elem, stencil);
134  BOOST_CHECK_EQUAL(stencil.size(), 9u);
135 
136  stencil_computer->options().set("stencil_size", 10u );
137  stencil_computer->compute_stencil(space_elem, stencil);
138  BOOST_CHECK_EQUAL(stencil.size(), 20u);
139 
140  stencil_computer->options().set("stencil_size", 21u );
141  stencil_computer->compute_stencil(space_elem, stencil);
142  BOOST_CHECK_EQUAL(stencil.size(), 25u); // mesh size
143 
144  CFinfo << stencil_computer->tree() << CFendl;
145 
146 }
147 
149 
150 BOOST_AUTO_TEST_CASE( Octtree_parallel )
151 {
152  Handle< MeshGenerator > mesh_generator(Core::instance().root().get_child("mesh_generator"));
153  mesh_generator->options().set("mesh",Core::instance().root().uri()/"parallel_mesh");
154  mesh_generator->options().set("lengths",std::vector<Real>(2,10.));
155  mesh_generator->options().set("nb_cells",std::vector<Uint>(2,5));
156  mesh_generator->options().set("part",PE::Comm::instance().rank());
157  mesh_generator->options().set("nb_parts",PE::Comm::instance().size());
158  Mesh& mesh = mesh_generator->generate();
159 
160  Octtree& octtree = *mesh.create_component<Octtree>("octtree");
161 
162  // Create and configure interpolator.
163  octtree.options().set("nb_elems_per_cell", 1u );
164  octtree.options().set("mesh", mesh.handle<Mesh>() );
165  octtree.create_octtree();
166 
167  // Following configuration option has priority over the the previous one.
168  std::vector<Uint> nb_cells = boost::assign::list_of(5)(5);
169  octtree.options().set("nb_cells", nb_cells );
170 
171  boost::multi_array<Real,2> coordinates;
172  coordinates.resize(boost::extents[2][2]);
173  coordinates[0][XX] = 5.; coordinates[0][YY] = 2.5;
174  coordinates[1][XX] = 5.; coordinates[1][YY] = 7.5;
175 
176  std::vector<Uint> ranks;
177  octtree.find_cell_ranks(coordinates,ranks);
178 
179  BOOST_CHECK_EQUAL(ranks[0] , 0u);
180  BOOST_CHECK_EQUAL(ranks[1] , 1u);
181 
182 
183 // MeshWriter& gmsh_writer = mesh.create_component("gmsh_writer","cf3.mesh.gmsh.Writer").as_type<MeshWriter>();
184 // gmsh_writer.write_from_to(mesh,"octtree.msh");
185 }
186 
188 
190 {
191  PE::Comm::instance().finalize();
192 }
193 
195 
196 BOOST_AUTO_TEST_SUITE_END()
197 
198 
#define CFinfo
these are always defined
Definition: Log.hpp:104
boost::python::object get_child(ComponentWrapper &self, const std::string &name)
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
const std::vector< Handle< Entities > > & elements() const
Definition: Mesh.hpp:70
external boost library namespace
BOOST_AUTO_TEST_CASE(init)
common::URI uri(ComponentWrapper &self)
tuple root
Definition: coolfluid.py:24
~Octtree_Fixture()
common tear-down for each test case
void find_cell_ranks(const boost::multi_array< Real, 2 > &coordinates, std::vector< Uint > &ranks)
Definition: Octtree.cpp:187
#define CFendl
Definition: Log.hpp:109
int m_argc
possibly common functions used on the tests below
Definition: Defs.hpp:17
Mesh & generate()
generate, wraps execute() and returns the mesh reference
Basic Classes for Mesh applications used by COOLFluiD.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
std::string tree(bool basic_mode=false, Uint depth=0, Uint recursion_level=0) const
Definition: Component.cpp:785
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
Low storage struct to uniquely identify one element.
Definition: Entities.hpp:141
Octtree_Fixture()
common setup for each test case
Eigen::Matrix< Real, 2, 1 > RealVector2
Fixed size 2x1 column vector.
Definition: MatrixTypes.hpp:40
virtual void compute_stencil(const SpaceElem &element, std::vector< SpaceElem > &stencil)
Compute the stencil around a given element.
Handle< Component > handle()
Get a handle to the component.
Definition: Component.hpp:179
Definition: Defs.hpp:17
OptionList & options()
Definition: Component.cpp:856
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
Definition: Component.cpp:568
Most basic kernel library.
Definition: Action.cpp:19
void create_octtree()
Definition: Octtree.cpp:76
Send comments to:
COOLFluiD Web Admin