COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-simplemeshgenerator.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::neu::Reader"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/Log.hpp"
13 #include "common/OptionList.hpp"
14 #include "common/Core.hpp"
15 
16 #include "mesh/Mesh.hpp"
17 #include "mesh/Region.hpp"
18 #include "mesh/MeshWriter.hpp"
20 #include "mesh/MeshTransformer.hpp"
21 
22 #include "common/DynTable.hpp"
23 #include "common/List.hpp"
24 #include "common/Table.hpp"
25 #include "mesh/Dictionary.hpp"
26 
27 using namespace std;
28 using namespace boost;
29 using namespace cf3;
30 using namespace cf3::mesh;
31 using namespace cf3::common;
32 
34 
36 {
39  {
40  m_argc = boost::unit_test::framework::master_test_suite().argc;
41  m_argv = boost::unit_test::framework::master_test_suite().argv;
42  }
43 
46  {
47  }
49 
50 
52  int m_argc;
53  char** m_argv;
54 
55 };
56 
58 
59 BOOST_FIXTURE_TEST_SUITE( SimpleMeshGeneratorTests_TestSuite, SimpleMeshGeneratorTests_Fixture )
60 
61 
64 {
65  PE::Comm::instance().init(m_argc,m_argv);
66 }
67 
69 
70 BOOST_AUTO_TEST_CASE( generate_1d_mesh )
71 {
72 
73  boost::shared_ptr< MeshGenerator > meshgenerator = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","1Dgenerator");
74 
75  meshgenerator->options().set("mesh",URI("//line"));
76  meshgenerator->options().set("nb_cells",std::vector<Uint>(1,10));
77  meshgenerator->options().set("lengths",std::vector<Real>(1,10.));
78  Mesh& mesh = meshgenerator->generate();
79 
80 
81  CFinfo << "elements count = " << mesh.topology().recursive_elements_count(true) << CFendl;
82  CFinfo << "nodes count = " << mesh.topology().recursive_nodes_count() << CFendl;
83 
84  Uint nb_ghosts=0;
85 
86  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
87  gmsh_writer->write_from_to(mesh,"line.msh");
88 
89  BOOST_CHECK(true);
90 
91  CFinfo << mesh.tree() << CFendl;
92 
94  for (Uint n=0; n<nodes.size(); ++n)
95  {
96  if (nodes.is_ghost(n))
97  {
98  CFinfo << "node " << n << " is a ghost node" << CFendl;
99  ++nb_ghosts;
100  }
101  }
102  CFinfo << "ghost node count = " << nb_ghosts << CFendl;
103 }
104 
106 
107 BOOST_AUTO_TEST_CASE( generate_2d_mesh )
108 {
109 
110  boost::shared_ptr< MeshGenerator > meshgenerator = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","2Dgenerator");
111 
112  meshgenerator->options().set("mesh",URI("//rect"));
113  meshgenerator->options().set("nb_cells",std::vector<Uint>(2,2));
114  meshgenerator->options().set("lengths",std::vector<Real>(2,2.));
115  Mesh& mesh = meshgenerator->generate();
116 
117 
118  CFinfo << "elements count = " << mesh.topology().recursive_elements_count(true) << CFendl;
119  CFinfo << "nodes count = " << mesh.topology().recursive_nodes_count() << CFendl;
120 
121  Uint nb_ghosts=0;
122 
123  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
124  gmsh_writer->write_from_to(mesh,"rect.msh");
125 
126  BOOST_CHECK(true);
127 
128  CFinfo << mesh.tree() << CFendl;
129 
130  Dictionary& nodes = mesh.geometry_fields();
131  for (Uint n=0; n<nodes.size(); ++n)
132  {
133  if (nodes.is_ghost(n))
134  {
135  CFinfo << "node " << n << " is a ghost node" << CFendl;
136  ++nb_ghosts;
137  }
138  }
139  CFinfo << "ghost node count = " << nb_ghosts << CFendl;
140 }
141 
143 
144 BOOST_AUTO_TEST_CASE( generate_3d_mesh )
145 {
146 
147  boost::shared_ptr< MeshGenerator > meshgenerator = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","3Dgenerator");
148 
149  meshgenerator->options().set("mesh",URI("//box"));
150  meshgenerator->options().set("nb_cells",std::vector<Uint>(3,6));
151  meshgenerator->options().set("lengths",std::vector<Real>(3,2.));
152  Mesh& mesh = meshgenerator->generate();
153 
154  CFinfo << "elements count = " << mesh.topology().recursive_elements_count(true) << CFendl;
155  CFinfo << "nodes count = " << mesh.topology().recursive_nodes_count() << CFendl;
156 
157  Uint nb_ghosts=0;
158 
159  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
160  gmsh_writer->write_from_to(mesh,"box.msh");
161 
162  BOOST_CHECK(true);
163 
164  CFinfo << mesh.tree() << CFendl;
165 
166  Dictionary& nodes = mesh.geometry_fields();
167  for (Uint n=0; n<nodes.size(); ++n)
168  {
169  if (nodes.is_ghost(n))
170  {
171  CFinfo << "node " << n << " is a ghost node" << CFendl;
172  ++nb_ghosts;
173  }
174  }
175  CFinfo << "ghost node count = " << nb_ghosts << CFendl;
176 }
177 
179 
180 BOOST_AUTO_TEST_CASE( finalize_mpi )
181 {
182  PE::Comm::instance().finalize();
183 }
184 
186 
187 BOOST_AUTO_TEST_SUITE_END()
188 
189 
#define CFinfo
these are always defined
Definition: Log.hpp:104
Uint recursive_elements_count(bool include_ghost_elems) const
Definition: Region.cpp:107
external boost library namespace
STL namespace.
#define CFendl
Definition: Log.hpp:109
BOOST_AUTO_TEST_CASE(init_mpi)
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
SimpleMeshGeneratorTests_Fixture()
common setup for each test case
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
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
bool is_ghost(const Uint idx) const
Check if a field row is owned by this rank.
Definition: Dictionary.cpp:151
Region & topology() const
Definition: Mesh.hpp:51
~SimpleMeshGeneratorTests_Fixture()
common tear-down for each test case
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
Uint size() const
Number of rows of contained fields.
Definition: Dictionary.cpp:99
Most basic kernel library.
Definition: Action.cpp:19
Uint recursive_nodes_count()
Definition: Region.cpp:135
int m_argc
possibly common functions used on the tests below
Send comments to:
COOLFluiD Web Admin