COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-actions-facebuilder.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::actions::BuildFaces"
9 
10 #include <boost/test/unit_test.hpp>
11 #include <boost/assign/list_of.hpp>
12 
13 #include "common/Log.hpp"
14 #include "common/OptionList.hpp"
15 #include "common/Core.hpp"
16 #include "common/Environment.hpp"
18 
21 #include "mesh/MeshTransformer.hpp"
22 #include "mesh/MeshWriter.hpp"
23 #include "mesh/Mesh.hpp"
24 #include "mesh/Space.hpp"
25 #include "mesh/Region.hpp"
26 #include "mesh/Faces.hpp"
27 #include "mesh/MeshReader.hpp"
28 #include "mesh/Field.hpp"
30 #include "mesh/Cells.hpp"
31 #include "mesh/CellFaces.hpp"
33 
34 using namespace cf3;
35 using namespace boost::assign;
36 using namespace cf3::common;
37 using namespace cf3::mesh;
38 using namespace cf3::mesh::actions;
39 
41 
43 {
46  {
47  m_argc = boost::unit_test::framework::master_test_suite().argc;
48  m_argv = boost::unit_test::framework::master_test_suite().argv;
49  }
50 
53  {
54  }
55 
57  int m_argc;
58  char** m_argv;
59 
60 
62  static Handle< Mesh > mesh;
63 };
64 
65 Handle< Mesh > TestBuildFaces_Fixture::mesh = Core::instance().root().create_component<Mesh>("mesh");
66 
68 
69 BOOST_FIXTURE_TEST_SUITE( TestBuildFaces_TestSuite, TestBuildFaces_Fixture )
70 
71 
73 BOOST_AUTO_TEST_CASE( Constructors)
74 {
75  boost::shared_ptr<BuildFaces> facebuilder = allocate_component<BuildFaces>("facebuilder");
76  BOOST_CHECK_EQUAL(facebuilder->name(),"facebuilder");
77  Core::instance().environment().options().set("log_level",(Uint)INFO);
78 }
79 
80 BOOST_AUTO_TEST_CASE( build_faceconnectivity )
81 {
82  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
83  meshreader->read_mesh_into("../../../resources/quadtriag.neu",*mesh);
84 
85  FaceCellConnectivity& f2c = *mesh->create_component<FaceCellConnectivity>("faces");
86  f2c.setup(mesh->topology());
87 
88  BOOST_CHECK_EQUAL( f2c.size() , 31u);
89 
90  Face2Cell face(f2c);
91  Handle<Elements> liquid_triag (mesh->access_component("topology/liquid/elements_cf3.mesh.LagrangeP1.Triag2D"));
92  Handle<Elements> gas_triag (mesh->access_component("topology/gas/elements_cf3.mesh.LagrangeP1.Triag2D"));
93  Handle<Elements> gas_quad (mesh->access_component("topology/gas/elements_cf3.mesh.LagrangeP1.Quad2D"));
94 
95  BOOST_CHECK(is_not_null(liquid_triag));
96  BOOST_CHECK(is_not_null(gas_triag));
97  BOOST_CHECK(is_not_null(gas_quad));
98 
99  face.idx=0;
100  BOOST_CHECK_EQUAL( face.is_bdry() , false);
101  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,0) );
102  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,9) );
103 
104  face.idx=1;
105  BOOST_CHECK_EQUAL( face.is_bdry() , false);
106  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,0) );
107  BOOST_CHECK( face.cells()[1] == Entity(*gas_triag,2) );
108 
109  face.idx=2;
110  BOOST_CHECK_EQUAL( face.is_bdry() , false);
111  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,0) );
112  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,1) );
113 
114  face.idx=3;
115  BOOST_CHECK_EQUAL( face.is_bdry() , false);
116  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,1) );
117  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,2) );
118 
119  face.idx=4;
120  BOOST_CHECK_EQUAL( face.is_bdry() , true);
121  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,1) );
122 
123  face.idx=5;
124  BOOST_CHECK_EQUAL( face.is_bdry() , false);
125  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,2) );
126  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,3) );
127 
128  face.idx=6;
129  BOOST_CHECK_EQUAL( face.is_bdry() , true);
130  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,2) );
131 
132  face.idx=7;
133  BOOST_CHECK_EQUAL( face.is_bdry() , false);
134  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,3) );
135  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,8) );
136 
137  face.idx=8;
138  BOOST_CHECK_EQUAL( face.is_bdry() , true);
139  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,3) );
140 
141  face.idx=9;
142  BOOST_CHECK_EQUAL( face.is_bdry() , false);
143  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,4) );
144  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,5) );
145 
146  face.idx=10;
147  BOOST_CHECK_EQUAL( face.is_bdry() , false);
148  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,4) );
149  BOOST_CHECK( face.cells()[1] == Entity(*gas_triag,0) );
150 
151  face.idx=11;
152  BOOST_CHECK_EQUAL( face.is_bdry() , false);
153  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,4) );
154  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,9) );
155 
156  face.idx=12;
157  BOOST_CHECK_EQUAL( face.is_bdry() , true);
158  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,5) );
159 
160  face.idx=13;
161  BOOST_CHECK_EQUAL( face.is_bdry() , false);
162  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,5) );
163  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,6) );
164 
165  face.idx=14;
166  BOOST_CHECK_EQUAL( face.is_bdry() , true);
167  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,6) );
168 
169  face.idx=15;
170  BOOST_CHECK_EQUAL( face.is_bdry() , false);
171  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,6) );
172  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,7) );
173 
174  face.idx=16;
175  BOOST_CHECK_EQUAL( face.is_bdry() , true);
176  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,7) );
177 
178  face.idx=17;
179  BOOST_CHECK_EQUAL( face.is_bdry() , false);
180  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,7) );
181  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,8) );
182 
183  face.idx=18;
184  BOOST_CHECK_EQUAL( face.is_bdry() , false);
185  BOOST_CHECK( face.cells()[0] == Entity(*liquid_triag,8) );
186  BOOST_CHECK( face.cells()[1] == Entity(*liquid_triag,9) );
187 
188  face.idx=19;
189  BOOST_CHECK_EQUAL( face.is_bdry() , true);
190  BOOST_CHECK( face.cells()[0] == Entity(*gas_quad,0) );
191 
192  face.idx=20;
193  BOOST_CHECK_EQUAL( face.is_bdry() , true);
194  BOOST_CHECK( face.cells()[0] == Entity(*gas_quad,0) );
195 
196  face.idx=21;
197  BOOST_CHECK_EQUAL( face.is_bdry() , false);
198  BOOST_CHECK( face.cells()[0] == Entity(*gas_quad,0) );
199  BOOST_CHECK( face.cells()[1] == Entity(*gas_quad,1) );
200 
201  face.idx=22;
202  BOOST_CHECK_EQUAL( face.is_bdry() , false);
203  BOOST_CHECK( face.cells()[0] == Entity(*gas_quad,0) );
204  BOOST_CHECK( face.cells()[1] == Entity(*gas_triag,1) );
205 
206  face.idx=23;
207  BOOST_CHECK_EQUAL( face.is_bdry() , true);
208  BOOST_CHECK( face.cells()[0] == Entity(*gas_quad,1) );
209 
210  face.idx=24;
211  BOOST_CHECK_EQUAL( face.is_bdry() , true);
212  BOOST_CHECK( face.cells()[0] == Entity(*gas_quad,1) );
213 
214  face.idx=25;
215  BOOST_CHECK_EQUAL( face.is_bdry() , false);
216  BOOST_CHECK( face.cells()[0] == Entity(*gas_quad,1) );
217  BOOST_CHECK( face.cells()[1] == Entity(*gas_triag,3) );
218 
219  face.idx=26;
220  BOOST_CHECK_EQUAL( face.is_bdry() , false);
221  BOOST_CHECK( face.cells()[0] == Entity(*gas_triag,0) );
222  BOOST_CHECK( face.cells()[1] == Entity(*gas_triag,3) );
223 
224  face.idx=27;
225  BOOST_CHECK_EQUAL( face.is_bdry() , false);
226  BOOST_CHECK( face.cells()[0] == Entity(*gas_triag,0) );
227  BOOST_CHECK( face.cells()[1] == Entity(*gas_triag,1) );
228 
229  face.idx=28;
230  BOOST_CHECK_EQUAL( face.is_bdry() , true);
231  BOOST_CHECK( face.cells()[0] == Entity(*gas_triag,1) );
232 
233  face.idx=29;
234  BOOST_CHECK_EQUAL( face.is_bdry() , true);
235  BOOST_CHECK( face.cells()[0] == Entity(*gas_triag,2) );
236 
237  face.idx=30;
238  BOOST_CHECK_EQUAL( face.is_bdry() , false);
239  BOOST_CHECK( face.cells()[0] == Entity(*gas_triag,2) );
240  BOOST_CHECK( face.cells()[1] == Entity(*gas_triag,3) );
241 
242 // for (Face2Cell face(f2c); face.idx<f2c.size(); ++face.idx)
243 // {
244 // CFinfo << face.idx << " : " << face.cells()[0];
245 // if (face.is_bdry())
246 // CFinfo << CFendl;
247 // else
248 // CFinfo << " <--> " << face.cells()[1] << CFendl;
249 // }
250 
251 // CFinfo << mesh->tree() << CFendl<<CFendl;
252 
253 }
254 
256 
257 BOOST_AUTO_TEST_CASE( build_faces )
258 {
259  boost::shared_ptr<BuildFaces> facebuilder = allocate_component<BuildFaces>("facebuilder");
260 
261  facebuilder->set_mesh(mesh);
262  facebuilder->execute();
263 
264  //CFinfo << mesh->tree() << CFendl;
265 
266  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.Info","info");
267  //info->transform(mesh);
268 
269  Region& wall_region = find_component_recursively_with_name<Region>(mesh->topology(),"wall");
270  Faces& wall_faces = find_component<Faces>(wall_region);
271  FaceCellConnectivity& f2c = find_component<FaceCellConnectivity>(wall_faces);
272  Handle< Component > cells;
273  Uint cell_idx(0);
274 
275  CFinfo << "\n\nCHECKING wall connectivity"<<CFendl;
276  BOOST_CHECK_EQUAL(f2c.size(),6u);
277  for (Face2Cell face(f2c); face.idx<f2c.size(); ++face.idx)
278  {
279  CFinfo << wall_faces.parent()->name()<<"/"<<wall_faces.name() << "["<<face.idx<<"] <--> ";
280 
281  Entity cell = face.cells()[0];
282  CFinfo << cell << CFendl;
283  RealMatrix cell_coordinates = cell.get_coordinates();
284  RealVector face_coordinates = wall_faces.geometry_space().get_coordinates(face.idx).row(0);
285  bool match_found = false;
286  for (Uint i=0; i<cell_coordinates.rows(); ++i)
287  {
288  if (cell_coordinates.row(i) == face_coordinates.transpose())
289  {
290  match_found = true;
291  break;
292  }
293  }
294  BOOST_CHECK(match_found);
295  }
296  BOOST_CHECK(true);
297 
298 }
299 
301 
302 BOOST_AUTO_TEST_CASE( build_face_normals )
303 {
304  boost::shared_ptr<BuildFaceNormals> face_normal_builder = allocate_component<BuildFaceNormals>("facenormalsbuilder");
305 
306  face_normal_builder->set_mesh(mesh);
307  face_normal_builder->execute();
308 
309  //CFinfo << mesh->tree() << CFendl;
310 
311  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.Info","info");
312  //info->transform(mesh);
313 
314  boost::shared_ptr< MeshWriter > mesh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","writer");
315 
316  std::vector<URI> fields(1,find_component_ptr_recursively_with_name<Field>(*mesh,mesh::Tags::normal())->uri());
317  mesh_writer->options().set("fields",fields);
318  mesh_writer->options().set("mesh",mesh);
319  mesh_writer->options().set("file",URI("facenormals.msh"));
320  mesh_writer->execute();
321  BOOST_CHECK(true);
322 
323 }
324 
326 
327 BOOST_AUTO_TEST_CASE( build_faces_rectangle )
328 {
329  BOOST_CHECK(true);
330 
331  boost::shared_ptr<SimpleMeshGenerator> mesh_gen = allocate_component<SimpleMeshGenerator>("mesh_gen");
332  std::vector<Real> lengths = list_of(10.)(10.);
333  std::vector<Uint> nb_cells = list_of(5u)(5u);
334  mesh_gen->options().set("mesh",URI("//rectangle_mesh"));
335  mesh_gen->options().set("lengths",lengths);
336  mesh_gen->options().set("nb_cells",nb_cells);
337  Mesh& rmesh = mesh_gen->generate();
338  BOOST_CHECK(true);
339  boost::shared_ptr<BuildFaces> facebuilder = allocate_component<BuildFaces>("facebuilder");
340  BOOST_CHECK(true);
341 
342  facebuilder->set_mesh(rmesh);
343  BOOST_CHECK(true);
344 
345  facebuilder->execute();
346 
347  BOOST_CHECK(true);
348  Region& inner_faces_region = find_component_recursively_with_name<Region>(rmesh.topology(),mesh::Tags::inner_faces());
349  CellFaces& inner_faces = find_component<CellFaces>(inner_faces_region);
350  FaceCellConnectivity& f2c = find_component<FaceCellConnectivity>(inner_faces);
351  Handle< Component > cells;
352  Uint cell_idx(0);
353  BOOST_CHECK(true);
354 
355  CFinfo << "\n\nCHECKING inner faces connectivity"<<CFendl;
356  for (Face2Cell face(f2c); face.idx<f2c.size(); ++face.idx)
357  {
358  CFinfo << inner_faces.parent()->name()<<"/"<<inner_faces.name() << "["<<face.idx<<"] <--> ";
359 
360  Entity cell = face.cells()[0];
361  CFinfo << cell.comp->parent()->parent()->name()<<"/"<<cell.comp->name() << "["<<cell.idx<<"] <--> ";
362  RealMatrix cell_coordinates = cell.get_coordinates();
363  RealVector face_coordinates = inner_faces.geometry_space().get_coordinates(face.idx).row(0);
364  bool match_found = false;
365  for (Uint i=0; i<cell_coordinates.rows(); ++i)
366  {
367  if (cell_coordinates.row(i) == face_coordinates.transpose())
368  {
369  match_found = true;
370  break;
371  }
372  }
373  BOOST_CHECK(match_found);
374 
375  match_found = false;
376  cell = face.cells()[0];
377  CFinfo << cell.comp->parent()->parent()->name()<<"/"<<cell.comp->name() << "["<<cell.idx<<"]"<<CFendl;
378  cell_coordinates = cell.get_coordinates();
379  face_coordinates = inner_faces.geometry_space().get_coordinates(face.idx).row(0);
380  for (Uint i=0; i<cell_coordinates.rows(); ++i)
381  {
382  if (cell_coordinates.row(i) == face_coordinates.transpose())
383  {
384  match_found = true;
385  break;
386  }
387  }
388  BOOST_CHECK(match_found);
389 
390  }
391 }
392 
394 
395 BOOST_AUTO_TEST_SUITE_END()
396 
397 
Entities * comp
Definition: Entities.hpp:160
#define CFinfo
these are always defined
Definition: Log.hpp:104
boost::proto::terminal< SFOp< NormalOp > >::type const normal
RealMatrix get_coordinates() const
Definition: Entities.cpp:213
common::URI uri(ComponentWrapper &self)
const std::string & name() const
Access the name of the component.
Definition: Component.hpp:146
#define CFendl
Definition: Log.hpp:109
static Handle< Mesh > mesh
common values accessed by all tests goes here
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealMatrix
Dynamic sized matrix of Real scalars.
Definition: MatrixTypes.hpp:22
Handle< Component > parent() const
Definition: Component.cpp:256
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
Low storage struct to uniquely identify one element.
Definition: Entities.hpp:141
std::vector< URI > fields
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
Action derived classes for mesh manipulations.
~TestBuildFaces_Fixture()
common tear-down for each test case
Region & topology() const
Definition: Mesh.hpp:51
BOOST_AUTO_TEST_CASE(Constructors)
TestBuildFaces_Fixture()
common setup for each test case
Most basic kernel library.
Definition: Action.cpp:19
bool is_not_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:147
Send comments to:
COOLFluiD Web Admin