COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-gmsh.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 cf3::mesh::gmsh::Reader"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/Log.hpp"
13 #include "common/OptionList.hpp"
14 
15 
16 #include "common/Core.hpp"
17 #include "common/Environment.hpp"
18 
20 
21 #include "mesh/Mesh.hpp"
22 #include "mesh/Region.hpp"
23 #include "mesh/MeshReader.hpp"
24 #include "mesh/MeshWriter.hpp"
25 #include "mesh/MeshTransformer.hpp"
26 #include "mesh/Field.hpp"
27 #include "mesh/Entities.hpp"
28 #include "mesh/Space.hpp"
29 #include "common/DynTable.hpp"
30 #include "common/List.hpp"
31 #include "common/Table.hpp"
32 #include "mesh/Dictionary.hpp"
33 
34 using namespace std;
35 using namespace boost;
36 using namespace cf3;
37 using namespace cf3::mesh;
38 using namespace cf3::common;
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  }
56 
57 
59  int m_argc;
60  char** m_argv;
61 
62 };
63 
65 
66 BOOST_FIXTURE_TEST_SUITE( gmshReaderMPITests_TestSuite, gmshReaderMPITests_Fixture )
67 
68 
71 {
72  Core::instance().initiate(m_argc,m_argv);
73  Core::instance().environment().options().set("log_level",4u);
74 }
75 
77 
78 BOOST_AUTO_TEST_CASE( read_2d_mesh_triag_p1 )
79 {
80 
81  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.gmsh.Reader","meshreader");
82  BOOST_CHECK_EQUAL( meshreader->name() , "meshreader" );
83  BOOST_CHECK_EQUAL( meshreader->get_format() , "Gmsh" );
84  std::vector<std::string> extensions = meshreader->get_extensions();
85  BOOST_CHECK_EQUAL( extensions[0] , ".msh" );
86 
87 // meshreader->options().set("Repartition",true);
88 // meshreader->options().set("OutputRank",(Uint) 0);
89 // meshreader->options().set("Unified Zones",false);
90 
91 
92  // the mesh to store in
93  Mesh& mesh = *Core::instance().root().create_component<Mesh>("mesh_2d_triag_p1");
94 
95  // CFinfo.setFilterRankZero(false);
96  meshreader->read_mesh_into("../../resources/rectangle-tg-p1.msh",mesh);
97  // CFinfo.setFilterRankZero(true);
98 
99  // CFinfo << mesh.tree() << CFendl;
100 
101 boost::shared_ptr< MeshWriter > mesh_writer =
102  build_component_abstract_type<MeshWriter> ("cf3.mesh.gmsh.Writer", "GmshWriter" );
103 mesh_writer->options().set("mesh",mesh.handle<Mesh const>());
104 mesh_writer->options().set("file",URI("rectangle-tg-p1-out.msh"));
105 mesh_writer->execute();
106 
107  CFinfo << "elements count = " << find_component<Region>(mesh).recursive_elements_count(true) << CFendl;
108  CFinfo << "nodes count = " << find_component<Region>(mesh).recursive_nodes_count() << CFendl;
109 
110 }
111 
113 
114 BOOST_AUTO_TEST_CASE( read_2d_mesh_triag_p2 )
115 {
116 
117  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.gmsh.Reader","meshreader");
118 
119  // the mesh to store in
120  Mesh& mesh = *Core::instance().root().create_component<Mesh>("mesh_2d_triag_p2");
121 
122  // CFinfo.setFilterRankZero(false);
123  meshreader->read_mesh_into("../../resources/rectangle-tg-p2.msh",mesh);
124  // CFinfo.setFilterRankZero(true);
125 
126  // CFinfo << mesh.tree() << CFendl;
127 
128  boost::shared_ptr< MeshWriter > mesh_writer =
129  build_component_abstract_type<MeshWriter> ("cf3.mesh.gmsh.Writer", "GmshWriter" );
130  mesh_writer->options().set("mesh",mesh.handle<Mesh const>());
131  mesh_writer->options().set("file",URI("rectangle-tg-p2-out.msh"));
132  mesh_writer->execute();
133 
134  CFinfo << "elements count = " << find_component<Region>(mesh).recursive_elements_count(true) << CFendl;
135  CFinfo << "nodes count = " << find_component<Region>(mesh).recursive_nodes_count() << CFendl;
136 
137 }
138 
140 
141 BOOST_AUTO_TEST_CASE( read_2d_mesh_quad_p1 )
142 {
143 
144  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.gmsh.Reader","meshreader");
145 
146  // the mesh to store in
147  Mesh& mesh = *Core::instance().root().create_component<Mesh>("mesh_2d_quad_p1");
148 
149  // CFinfo.setFilterRankZero(false);
150  meshreader->read_mesh_into("../../resources/rectangle-qd-p2.msh",mesh);
151  // CFinfo.setFilterRankZero(true);
152 
153  // CFinfo << mesh.tree() << CFendl;
154 
155  boost::shared_ptr< MeshWriter > mesh_writer =
156  build_component_abstract_type<MeshWriter> ("cf3.mesh.gmsh.Writer", "GmshWriter" );
157  mesh_writer->options().set("mesh",mesh.handle<Mesh const>());
158  mesh_writer->options().set("file",URI("rectangle-qd-p1-out.msh"));
159  mesh_writer->execute();
160 
161  CFinfo << "elements count = " << find_component<Region>(mesh).recursive_elements_count(true) << CFendl;
162  CFinfo << "nodes count = " << find_component<Region>(mesh).recursive_nodes_count() << CFendl;
163 
164 }
166 
167 BOOST_AUTO_TEST_CASE( read_2d_mesh_quad_p2 )
168 {
169 
170  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.gmsh.Reader","meshreader");
171 
172  // the mesh to store in
173  Mesh& mesh = *Core::instance().root().create_component<Mesh>("mesh_2d_quad_p2");
174 
175  // CFinfo.setFilterRankZero(false);
176  meshreader->read_mesh_into("../../resources/rectangle-qd-p2.msh",mesh);
177  // CFinfo.setFilterRankZero(true);
178 
179  // CFinfo << mesh.tree() << CFendl;
180 
181  boost::shared_ptr< MeshWriter > mesh_writer =
182  build_component_abstract_type<MeshWriter> ("cf3.mesh.gmsh.Writer", "GmshWriter" );
183  mesh_writer->options().set("mesh",mesh.handle<Mesh const>());
184  mesh_writer->options().set("file",URI("rectangle-qd-p2-out.msh"));
185  mesh_writer->execute();
186 
187  CFinfo << "elements count = " << find_component<Region>(mesh).recursive_elements_count(true) << CFendl;
188  CFinfo << "nodes count = " << find_component<Region>(mesh).recursive_nodes_count() << CFendl;
189 
190 }
191 
193 
194 BOOST_AUTO_TEST_CASE( read_2d_mesh_mix_p1 )
195 {
196 
197  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.gmsh.Reader","meshreader");
198 
199  // the mesh to store in
200  Mesh& mesh = *Core::instance().root().create_component<Mesh>("mesh_2d_mix_p1");
201 
202  // CFinfo.setFilterRankZero(false);
203  meshreader->read_mesh_into("../../resources/rectangle-mix-p1.msh",mesh);
204  // CFinfo.setFilterRankZero(true);
205 
206  // CFinfo << mesh.tree() << CFendl;
207 
208  boost::shared_ptr< MeshWriter > mesh_writer =
209  build_component_abstract_type<MeshWriter> ("cf3.mesh.gmsh.Writer", "GmshWriter" );
210  mesh_writer->options().set("mesh",mesh.handle<Mesh const>());
211  mesh_writer->options().set("file",URI("rectangle-mix-p1-out.msh"));
212  mesh_writer->execute();
213 
214  CFinfo << "elements count = " << find_component<Region>(mesh).recursive_elements_count(true) << CFendl;
215  CFinfo << "nodes count = " << find_component<Region>(mesh).recursive_nodes_count() << CFendl;
216 
217 }
218 
220 
221 BOOST_AUTO_TEST_CASE( read_2d_mesh_mix_p2 )
222 {
223 
224  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.gmsh.Reader","meshreader");
225 
226  // the mesh to store in
227  Mesh& mesh = *Core::instance().root().create_component<Mesh>("mesh_2d_mix_p2");
228 
229  // CFinfo.setFilterRankZero(false);
230  meshreader->read_mesh_into("../../resources/rectangle-mix-p2.msh",mesh);
231  // CFinfo.setFilterRankZero(true);
232 
233  // CFinfo << mesh.tree() << CFendl;
234 
235  boost::shared_ptr< MeshWriter > mesh_writer =
236  build_component_abstract_type<MeshWriter> ("cf3.mesh.gmsh.Writer", "GmshWriter" );
237  mesh_writer->options().set("mesh",mesh.handle<Mesh const>());
238  mesh_writer->options().set("file",URI("rectangle-mix-p2-out.msh"));
239  mesh_writer->execute();
240 
241  CFinfo << "elements count = " << find_component<Region>(mesh).recursive_elements_count(true) << CFendl;
242  CFinfo << "nodes count = " << find_component<Region>(mesh).recursive_nodes_count() << CFendl;
243 
244 }
245 
247 
248 BOOST_AUTO_TEST_CASE( read_2d_mesh_mix_p1_out )
249 {
250  BOOST_CHECK(true);
251  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.gmsh.Reader","meshreader");
252 
253  // the mesh to store in
254  Mesh& mesh = *Core::instance().root().create_component<Mesh>("mesh_2d_mix_p1_out");
255 
256  // CFinfo.setFilterRankZero(false);
257  meshreader->read_mesh_into("rectangle-mix-p1-out_P0.msh",mesh);
258  // CFinfo.setFilterRankZero(true);
259  BOOST_CHECK(true);
260 
261  // CFinfo << mesh.tree() << CFendl;
262 
263  Field& nodal = mesh.geometry_fields().create_field("nodal" , "nodal[vector]");
264  nodal.descriptor().options().set(common::Tags::dimension(),mesh.dimension());
265  for (Uint n=0; n<nodal.size(); ++n)
266  {
267  for(Uint j=0; j<nodal.row_size(); ++j)
268  nodal[n][j] = n;
269  }
270 
271  mesh.create_discontinuous_space("elems_P0","cf3.mesh.LagrangeP0");
272 
273  Field& cell_centred = mesh.geometry_fields().create_field("cell_centred","cell_centred[vector]");
274  for (Uint e=0; e<cell_centred.size(); ++e)
275  {
276  for(Uint j=0; j<cell_centred.row_size(); ++j)
277  cell_centred[e][j] = e;
278  }
279 
280  std::vector<URI> fields;
281  fields.push_back(cell_centred.uri());
282  fields.push_back(nodal.uri());
283 
284  std::vector<URI> regions;
285  regions.push_back(mesh.uri()/"topology/inlet");
286  regions.push_back(mesh.uri()/"topology/outlet");
287  regions.push_back(mesh.uri()/"topology/wall");
288  regions.push_back(mesh.uri()/"topology/left");
289 
290  BOOST_CHECK(true);
291 
292  boost::shared_ptr< MeshWriter > mesh_writer =
293  build_component_abstract_type<MeshWriter> ("cf3.mesh.gmsh.Writer", "GmshWriter" );
294 
295  BOOST_CHECK(true);
296 
297  Handle<Mesh> mesh_arg = mesh.handle<Mesh>();
298  BOOST_CHECK(true);
299  mesh_writer->options().set("mesh",mesh_arg);
300  mesh_writer->options().set("fields",fields);
301  mesh_writer->options().set("file",URI("rectangle-mix-p1-out-out.msh"));
302  mesh_writer->options().set("regions",regions);
303  mesh_writer->execute();
304 
305  BOOST_CHECK(true);
306 
307  CFinfo << "elements count = " << find_component<Region>(mesh).recursive_elements_count(true) << CFendl;
308  CFinfo << "nodes count = " << find_component<Region>(mesh).recursive_nodes_count() << CFendl;
309 
310 }
311 
313 
314 BOOST_AUTO_TEST_CASE( finalize_mpi )
315 {
316  Core::instance().terminate();
317 }
318 
320 
321 BOOST_AUTO_TEST_SUITE_END()
322 
323 
#define CFinfo
these are always defined
Definition: Log.hpp:104
external boost library namespace
URI uri() const
Construct the full path.
Definition: Component.cpp:248
STL namespace.
#define CFendl
Definition: Log.hpp:109
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Uint size() const
Definition: Table.hpp:127
Basic Classes for Mesh applications used by COOLFluiD.
BOOST_AUTO_TEST_CASE(init_mpi)
gmshReaderMPITests_Fixture()
common setup for each test case
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Uint row_size(Uint i=0) const
Definition: Table.hpp:133
std::vector< URI > fields
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
~gmshReaderMPITests_Fixture()
common tear-down for each test case
Handle< Component > handle()
Get a handle to the component.
Definition: Component.hpp:179
math::VariablesDescriptor & descriptor() const
Definition: Field.hpp:127
OptionList & options()
Definition: Component.cpp:856
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
Most basic kernel library.
Definition: Action.cpp:19
Send comments to:
COOLFluiD Web Admin