COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-reading.cpp
Go to the documentation of this file.
1 
2 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
3 //
4 // This software is distributed under the terms of the
5 // GNU Lesser General Public License version 3 (LGPLv3).
6 // See doc/lgpl.txt and doc/gpl.txt for the license text.
7 
8 #define BOOST_TEST_DYN_LINK
9 #define BOOST_TEST_MODULE "Tests mesh reading"
10 
11 #include <boost/test/unit_test.hpp>
12 #include <boost/foreach.hpp>
13 #include <boost/regex.hpp>
14 
15 #include "common/OptionT.hpp"
16 #include "common/Log.hpp"
17 #include "common/OptionList.hpp"
18 #include "common/Core.hpp"
19 #include "common/OptionArray.hpp"
20 #include "common/OptionURI.hpp"
21 #include "common/Group.hpp"
23 
24 #include "common/XML/Protocol.hpp"
28 
29 #include "mesh/Domain.hpp"
30 #include "mesh/Mesh.hpp"
31 #include "mesh/Region.hpp"
32 #include "mesh/Elements.hpp"
33 #include "common/Table.hpp"
34 #include "mesh/MeshReader.hpp"
35 #include "mesh/MeshWriter.hpp"
36 #include "mesh/MeshTransformer.hpp"
37 
38 using namespace std;
39 using namespace boost;
40 using namespace cf3;
41 using namespace cf3::mesh;
42 using namespace cf3::common;
43 using namespace cf3::common::XML;
44 
46 
48 {
51  {
52  m_argc = boost::unit_test::framework::master_test_suite().argc;
53  m_argv = boost::unit_test::framework::master_test_suite().argv;
54 
55  root = allocate_component<Group>("Root");
56  reader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","MyReader");
57  domain = root->create_component<Domain>("MyDom");
58 
59  root->add_component( reader );
60 
61  ExceptionManager::instance().ExceptionOutputs = false;
62  ExceptionManager::instance().ExceptionDumps = false;
63  }
64 
67  {
68  }
69 
71  boost::shared_ptr< Component > root;
72  boost::shared_ptr< MeshReader > reader;
74 
76  int m_argc;
77  char** m_argv;
78 
79 };
80 
82 
83 BOOST_FIXTURE_TEST_SUITE( MeshReading_TestSuite, MeshReading_Fixture )
84 
85 
87 BOOST_AUTO_TEST_CASE( Constructors )
88 {
89  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
90  BOOST_CHECK_EQUAL(meshreader->name(),"meshreader");
91  BOOST_CHECK_EQUAL(meshreader->get_format(),"neu");
92 
93  boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
94  BOOST_CHECK_EQUAL(meshwriter->name(),"meshwriter");
95  BOOST_CHECK_EQUAL(meshwriter->get_format(),"Gmsh");
96 
97  boost::shared_ptr< MeshWriter > neu_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.neu.Writer","meshwriter");
98  BOOST_CHECK_EQUAL(neu_writer->name(),"meshwriter");
99  BOOST_CHECK_EQUAL(neu_writer->get_format(),"neu");
100 
101 }
102 
104 
105 BOOST_AUTO_TEST_CASE( quadtriag_readneu_writeGmsh_writeneu )
106 {
107  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
108 
109  // the mesh to store in
110  Mesh& mesh = *Core::instance().root().create_component<Mesh> ( "quadtriag" );
111 
112  meshreader->read_mesh_into("../../resources/quadtriag.neu",mesh);
113  BOOST_CHECK(true);
114  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
115  BOOST_CHECK_NO_THROW(gmsh_writer->write_from_to(mesh,"quadtriag.msh"));
116 
117  boost::shared_ptr< MeshWriter > neu_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.neu.Writer","meshwriter");
118  BOOST_CHECK_NO_THROW(neu_writer->write_from_to(mesh,"quadtriag_write.neu"));
119 
120  BOOST_CHECK_EQUAL(mesh.topology().recursive_nodes_count(), (Uint) 16);
121  BOOST_CHECK_EQUAL(mesh.topology().recursive_elements_count(true), (Uint) 28);
122 }
123 
125 
126 BOOST_AUTO_TEST_CASE( quadtriag_read_Newneu_writeGmsh )
127 {
128  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
129  boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
130 
131  // the mesh to store in
132  Mesh& mesh = *Core::instance().root().create_component<Mesh> ( "quadtriag_write" );
133 
134  //CFinfo << "ready to read" << CFendl;
135  BOOST_CHECK_NO_THROW(meshreader->read_mesh_into("quadtriag_write.neu",mesh));
136 
137  //CFinfo << "ready to write" << CFendl;
138  BOOST_CHECK_NO_THROW(meshwriter->write_from_to(mesh,"quadtriag_write.msh"));
139  BOOST_CHECK_EQUAL(mesh.topology().recursive_nodes_count(), (Uint) 16);
140  BOOST_CHECK_EQUAL(mesh.topology().recursive_elements_count(true), (Uint) 28);
141 
142 // boost::shared_ptr< MeshTransformer > meshinfo = build_component_abstract_type<MeshTransformer>("Info","meshinfo");
143 // meshinfo->transform(mesh);
144 }
145 
147 
148 BOOST_AUTO_TEST_CASE( hextet_readneu_writeGmsh_writeneu )
149 {
150  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
151 
152  // the mesh to store in
153  Mesh& mesh = *Core::instance().root().create_component<Mesh> ( "hextet" );
154 
155  BOOST_CHECK_NO_THROW(meshreader->read_mesh_into("../../resources/hextet.neu",mesh));
156 
157  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
158  BOOST_CHECK_NO_THROW(gmsh_writer->write_from_to(mesh,"hextet.msh"));
159  boost::shared_ptr< MeshWriter > neu_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.neu.Writer","meshwriter");
160  BOOST_CHECK_NO_THROW(neu_writer->write_from_to(mesh,"hextet_write.neu"));
161  BOOST_CHECK_EQUAL(mesh.topology().recursive_nodes_count(), (Uint) 35);
162  BOOST_CHECK_EQUAL(mesh.topology().recursive_elements_count(true), (Uint) 44);
163 }
164 
166 
167 BOOST_AUTO_TEST_CASE( hextet_read_Newneu_writeGmsh )
168 {
169  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
170  boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
171 
172  // the mesh to store in
173  Mesh& mesh = *Core::instance().root().create_component<Mesh> ( "hextest_write" );
174 
175  //CFinfo << "ready to read" << CFendl;
176  meshreader->read_mesh_into("hextet_write.neu",mesh);
177 
178  //CFinfo << "ready to write" << CFendl;
179  meshwriter->write_from_to(mesh,"hextet_write.msh");
180  BOOST_CHECK_EQUAL(mesh.topology().recursive_nodes_count(), (Uint) 35);
181  BOOST_CHECK_EQUAL(mesh.topology().recursive_elements_count(true), (Uint) 44);
182 
183 // boost::shared_ptr< MeshTransformer > meshinfo = build_component_abstract_type<MeshTransformer>("Info","meshinfo");
184 // meshinfo->transform(mesh);
185 
186 }
187 /*
188 BOOST_AUTO_TEST_CASE( read_multiple )
189 {
190  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
191 
192  // the file to read from
193  boost::filesystem::path fp_in ("quadtriag.neu");
194 
195  // the mesh to store in
196  boost::shared_ptr< Mesh > mesh ( allocate_component<Mesh> ( "mesh" ) );
197 
198  for (Uint count=1; count<=4; ++count)
199  {
200  meshreader->read_mesh_into(fp_in,mesh);
201  BOOST_CHECK_EQUAL(mesh->domain().recursive_elements_count(true), count*28);
202  }
203 
204  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("Info","info");
205  info->transform(mesh);
206 }*/
207 
209 
210 BOOST_AUTO_TEST_CASE( read_mesh_signal_2 )
211 {
212  SignalFrame frame;
213  SignalOptions options;
214 
215  // URI with a wrong protocol
216  options.add("domain", domain->handle() );
217 
218  frame = options.create_frame("Target", "/", "/");
219  BOOST_CHECK_THROW( reader->signal_read(frame), ValueNotFound );
220 }
221 
222 
223 BOOST_AUTO_TEST_CASE( read_mesh_signal_4 )
224 {
225  SignalFrame frame;
226  SignalOptions options;
227 
228  // no file (no error and the domain should be still empty afterwards)
229  std::vector<URI> files;
230  options.add("domain", domain->handle() );
231  options.add("files", files);
232 
233  frame = options.create_frame("Target", "/", "/");
234 
235  std::string str;
236  XML::to_string(frame.node, str);
237  CFinfo << str << CFendl;
238 
239  BOOST_CHECK_THROW( reader->signal_read(frame), BadValue );
240  BOOST_CHECK_EQUAL( domain->count_children(), (Uint) 0);
241 }
242 
244 
245 BOOST_AUTO_TEST_SUITE_END()
246 
247 
BOOST_AUTO_TEST_CASE(Constructors)
#define CFinfo
these are always defined
Definition: Log.hpp:104
Abstracts the use of XML when adding options to a signal frame.
Handle< Domain > domain
void to_string(const XmlNode &node, std::string &str)
XmlNode node
The frame node.
external boost library namespace
boost::shared_ptr< Component > root
possibly common functions used on the tests below
Classes that implement the XML protocol for use in COOLFluiD.
Definition: Component.hpp:43
STL namespace.
tuple root
Definition: coolfluid.py:24
SignalFrame create_frame(const std::string &name=std::string(), const URI &sender=URI(), const URI &receiver=URI()) const
Creates a frame and puts the options in an "options" map.
#define CFendl
Definition: Log.hpp:109
Manages a set of maps.
Definition: SignalFrame.hpp:31
int m_argc
common values accessed by all tests goes here
Basic Classes for Mesh applications used by COOLFluiD.
~MeshReading_Fixture()
common tear-down for each test case
Top-level namespace for coolfluid.
Definition: Action.cpp:18
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
boost::shared_ptr< MeshReader > reader
MeshReading_Fixture()
common setup for each test case
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
Definition: OptionList.hpp:45
Most basic kernel library.
Definition: Action.cpp:19
Send comments to:
COOLFluiD Web Admin