COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-block-mesh-reader.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 BlockMeshReader"
9 
10 #include <boost/assign/list_of.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include "common/Core.hpp"
14 #include "common/Log.hpp"
15 
16 #include "mesh/Mesh.hpp"
17 #include "mesh/MeshReader.hpp"
18 #include "mesh/MeshWriter.hpp"
19 
21 
24 
27 
28 using namespace cf3;
29 using namespace cf3::common;
30 using namespace cf3::mesh;
31 using namespace cf3::mesh::BlockMesh;
32 using namespace cf3::BlockMeshReader;
33 
35 
37 {
38  BlockMeshReaderFixture() : root(Core::instance().root())
39  {
40  int argc = boost::unit_test::framework::master_test_suite().argc;
41  char** argv = boost::unit_test::framework::master_test_suite().argv;
42  if(argc < 2)
43  throw ValueNotFound(FromHere(), "Path to base directory was not found");
44  base_dir = URI(argv[1], cf3::common::URI::Scheme::FILE);
45  }
48 };
49 
51 
52 BOOST_FIXTURE_TEST_SUITE( BlockMeshReader, BlockMeshReaderFixture )
53 
54 
57 {
58  BOOST_CHECK(true);
59 
60  // files should be in current working directory
61  URI dict_path = base_dir / URI("channel3d.dict");
62  Handle< MeshReader > dict_reader(root.create_component("meshreader", "cf3.BlockMeshReader.BlockMeshReader"));
63 
64  // Read the dict mesh
65  Mesh& dict_mesh = *root.create_component< Mesh >("dict_mesh");
66  dict_reader->read_mesh_into(dict_path, dict_mesh);
67 
68  // Read the reference mesh
69  URI ref_path = base_dir / URI("uTestBlockMeshReader-Channel3D-reference.neu");
70  Handle< MeshReader > ref_reader(root.create_component("meshreader", "cf3.mesh.neu.Reader"));
71  Mesh& ref_mesh = *root.create_component< Mesh >("ref_mesh");
72  ref_reader->read_mesh_into(ref_path, ref_mesh);
73 
74  // Write output
75  Handle<MeshWriter> writer(root.create_component("meshwriter", "cf3.mesh.gmsh.Writer"));
76  writer->write_from_to(dict_mesh, URI("channel3d-output.msh"));
77 
78  // Check if they are equal
79  //BOOST_CHECK(cf3::Tools::MeshDiff::diff(dict_mesh, ref_mesh, 25000));
80 }
81 /*
82 BOOST_AUTO_TEST_CASE( Cavity2D )
83 {
84  BOOST_CHECK(true);
85 
86  // files should be in current working directory
87  URI dict_path = base_dir / URI("cavity2d.dict");
88  Handle<MeshReader> dict_reader = root.create_component<MeshReader>("meshreader");
89 
90  // Read the dict mesh
91  boost::shared_ptr< Mesh > dict_mesh(allocate_component<Mesh>("dict_mesh"));
92  dict_reader->do_read_mesh_into(dict_path, dict_mesh);
93 
94  // Read the reference mesh
95  URI ref_path = base_dir / URI("uTestBlockMeshReader-Cavity2D-reference.neu");
96  Handle< MeshReader > ref_reader = create_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
97  boost::shared_ptr< Mesh > ref_mesh(allocate_component<Mesh>("reference"));
98  ref_reader->do_read_mesh_into(ref_path, ref_mesh);
99 
100  CFinfo << dict_mesh->tree() << CFendl;
101  CFinfo << ref_mesh->tree() << CFendl;
102 
103  // Check if they are equal
104  BOOST_CHECK(cf3::Tools::MeshDiff::diff(*dict_mesh, *ref_mesh, 100));
105 }
106 
107 BOOST_AUTO_TEST_CASE( PitzDaily )
108 {
109  BOOST_CHECK(true);
110 
111  // files should be in current working directory
112  URI dict_path = base_dir / URI("pitzdaily.dict");
113  Handle<MeshReader> dict_reader = root.create_component<MeshReader>("meshreader");
114 
115  // Read the dict mesh
116  boost::shared_ptr< Mesh > dict_mesh(allocate_component<Mesh>("dict_mesh"));
117  dict_reader->do_read_mesh_into(dict_path, dict_mesh);
118 
119  // Read the reference mesh
120  URI ref_path = base_dir / URI("uTestBlockMeshReader-PitzDaily-reference.neu");
121  Handle< MeshReader > ref_reader = create_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
122  boost::shared_ptr< Mesh > ref_mesh(allocate_component<Mesh>("reference"));
123  ref_reader->do_read_mesh_into(ref_path, ref_mesh);
124 
125  // Check if they are equal
126  BOOST_CHECK(cf3::Tools::MeshDiff::diff(*dict_mesh, *ref_mesh, 50000));
127 }
128 
129 BOOST_AUTO_TEST_CASE( WriteDict )
130 {
131  BOOST_CHECK(true);
132 
133  URI path = base_dir/URI("pitzdaily.dict");
134  boost::filesystem::fstream file;
135  file.open(path,std::ios_base::in);
136 
137  BlockData ref_block_data;
138  parse_blockmesh_dict(file, ref_block_data);
139 
140  std::stringstream out_stream;
141  out_stream << ref_block_data << std::endl;
142 
143  BlockData out_block_data;
144  parse_blockmesh_dict(out_stream, out_block_data);
145 
146  BOOST_CHECK_EQUAL(ref_block_data, out_block_data);
147 }
148 
149 
150 */
152 
153 BOOST_AUTO_TEST_SUITE_END()
154 
155 
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
tuple root
Definition: coolfluid.py:24
BOOST_AUTO_TEST_CASE(Channel3D)
Basic Classes for Mesh applications used by COOLFluiD.
Library for I/O of the OpenFOAM BlockMesh dict files.
Definition: BlockData.cpp:47
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Base class for defining CF components.
Definition: Component.hpp:82
Most basic kernel library.
Definition: Action.cpp:19
#define FromHere()
Send comments to:
COOLFluiD Web Admin