COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-writemesh.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::tecplot::Writer"
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 
17 
18 #include "mesh/Domain.hpp"
19 #include "mesh/Mesh.hpp"
20 #include "mesh/Region.hpp"
21 #include "mesh/MeshReader.hpp"
22 #include "mesh/MeshWriter.hpp"
23 #include "mesh/MeshTransformer.hpp"
24 #include "mesh/Field.hpp"
25 #include "common/DynTable.hpp"
26 #include "common/List.hpp"
27 #include "common/Table.hpp"
28 #include "mesh/Dictionary.hpp"
29 #include "mesh/WriteMesh.hpp"
30 
31 using namespace std;
32 using namespace boost;
33 using namespace cf3;
34 using namespace cf3::mesh;
35 using namespace cf3::common;
36 
38 
40 {
43  {
44  m_argc = boost::unit_test::framework::master_test_suite().argc;
45  m_argv = boost::unit_test::framework::master_test_suite().argv;
46  }
47 
50  {
51  }
53 
54 
56  int m_argc;
57  char** m_argv;
58 
59 };
60 
62 
63 BOOST_FIXTURE_TEST_SUITE( TecWriterTests_TestSuite, TecWriterTests_Fixture )
64 
65 
68 
69 BOOST_AUTO_TEST_CASE( read_2d_mesh )
70 {
71 
72  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
73 
74  meshreader->options().set("read_groups",true);
75 
76  Domain& domain = *Core::instance().root().create_component<Domain>("domain");
77  // the mesh to store in
78  Mesh& mesh = *domain.create_component<Mesh>( "mesh" );
79 
80  meshreader->read_mesh_into("../../resources/quadtriag.neu",mesh);
81 
82 
83  Field& nodal = mesh.geometry_fields().create_field("nodal","nodal[vector]");
84  nodal.descriptor().options().set(common::Tags::dimension(),mesh.dimension());
85  for (Uint n=0; n<nodal.size(); ++n)
86  {
87  for(Uint j=0; j<nodal.row_size(); ++j)
88  nodal[n][j] = n;
89  }
90 
91  Dictionary& elems_P0 = mesh.create_discontinuous_space("elems_P0","cf3.mesh.LagrangeP0");
92 
93  Field& cell_centred = elems_P0.create_field("cell_centred","cell_centred[vector]");
94  for (Uint e=0; e<cell_centred.size(); ++e)
95  {
96  for(Uint j=0; j<cell_centred.row_size(); ++j)
97  cell_centred[e][j] = e;
98  }
99 
100  std::vector<URI> fields;
101  fields.push_back(nodal.uri());
102  fields.push_back(cell_centred.uri());
103  fields.push_back(mesh.geometry_fields().coordinates().uri());
104 
105  WriteMesh& write_mesh = *Core::instance().root().create_component<WriteMesh>("write_mesh");
106  write_mesh.write_mesh(mesh,"quadtriag.plt",fields);
107  write_mesh.write_mesh(mesh,"quadtriag.msh",fields);
108 
109  BOOST_CHECK(true);
110 
111  domain.write_mesh("quadtriag.plt");
112  domain.write_mesh("quadtriag.msh");
113 }
114 
116 /*
117 BOOST_AUTO_TEST_CASE( threeD_test )
118 {
119 
120  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
121 
122  meshreader->options().set("number_of_processors",(Uint) Comm::instance().size());
123  meshreader->options().set("rank",(Uint) Comm::instance().rank());
124  meshreader->options().set("Repartition",false);
125  meshreader->options().set("OutputRank",(Uint) 2);
126 
127  // the file to read from
128  boost::filesystem::path fp_in ("../../resources/hextet.neu");
129 
130  // the mesh to store in
131  boost::shared_ptr< Mesh > mesh ( allocate_component<Mesh> ( "mesh" ) );
132 
133 
134  CFinfo.setFilterRankZero(false);
135  meshreader->do_read_mesh_into(fp_in,mesh);
136  CFinfo.setFilterRankZero(true);
137 
138  boost::filesystem::path fp_out ("hextet.msh");
139  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
140  gmsh_writer->write_from_to(mesh,fp_out);
141 
142  BOOST_CHECK(true);
143 
144 }
145 */
147 /*
148 BOOST_AUTO_TEST_CASE( read_multiple_2D )
149 {
150 
151  boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>("cf3.mesh.neu.Reader","meshreader");
152 
153  meshreader->options().set("Repartition",true);
154  meshreader->options().set("OutputRank",(Uint) 0);
155 
156  // the file to read from
157  boost::filesystem::path fp_in ("quadtriag.neu");
158 
159  // the mesh to store in
160  boost::shared_ptr< Mesh > mesh ( allocate_component<Mesh> ( "mesh" ) );
161 
162 
163  CFinfo.setFilterRankZero(false);
164 
165 
166 
167  for (Uint count=1; count<=2; ++count)
168  {
169  CFinfo << "\n\n\nMesh parallel:" << CFendl;
170  meshreader->do_read_mesh_into(fp_in,mesh);
171  }
172 
173 
174 
175  CFinfo.setFilterRankZero(true);
176  CFinfo << mesh->tree() << CFendl;
177  CFinfo << meshreader->tree() << CFendl;
178  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("Info","info");
179  info->transform(mesh);
180 
181 
182  boost::filesystem::path fp_out ("quadtriag_mult.msh");
183  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
184  gmsh_writer->write_from_to(mesh,fp_out);
185 
186  BOOST_CHECK_EQUAL(1,1);
187 
188 }
189 */
191 
193 
194 BOOST_AUTO_TEST_SUITE_END()
195 
196 
BOOST_AUTO_TEST_CASE(read_2d_mesh)
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
Definition: Dictionary.cpp:178
external boost library namespace
void write_mesh(const Mesh &, const common::URI &file, const std::vector< common::URI > &fields)
Definition: WriteMesh.cpp:163
TecWriterTests_Fixture()
common setup for each test case
URI uri() const
Construct the full path.
Definition: Component.cpp:248
STL namespace.
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Handle< Component const > root() const
Definition: Component.cpp:266
Uint size() const
Definition: Table.hpp:127
void write_mesh(const common::URI &file)
write the active mesh
Definition: Domain.cpp:179
Basic Classes for Mesh applications used by COOLFluiD.
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
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
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
Definition: Component.cpp:568
Most basic kernel library.
Definition: Action.cpp:19
~TecWriterTests_Fixture()
common tear-down for each test case
Send comments to:
COOLFluiD Web Admin