7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for parallel fields"
11 #include <boost/test/unit_test.hpp>
13 #include "coolfluid-packages.hpp"
45 using namespace boost;
59 m_argc = boost::unit_test::framework::master_test_suite().argc;
60 m_argv = boost::unit_test::framework::master_test_suite().argv;
85 Core::instance().initiate(m_argc,m_argv);
86 PE::Comm::instance().init(m_argc,m_argv);
94 Core::instance().environment().options().set(
"log_level",(
Uint)
DEBUG);
101 boost::shared_ptr< MeshGenerator > meshgenerator = build_component_abstract_type<MeshGenerator>(
"cf3.mesh.SimpleMeshGenerator",
"1Dgenerator");
102 meshgenerator->options().set(
"mesh",
URI(
"//rect"));
103 std::vector<Uint> nb_cells(2);
104 std::vector<Real> lengths(2);
107 lengths[0] = nb_cells[0];
108 lengths[1] = nb_cells[1];
109 meshgenerator->options().set(
"nb_cells",nb_cells);
110 meshgenerator->options().set(
"lengths",lengths);
111 meshgenerator->options().set(
"bdry",
false);
112 Mesh&
mesh = meshgenerator->generate();
116 boost::shared_ptr< MeshReader > meshreader =
117 build_component_abstract_type<MeshReader>(
"cf3.mesh.neu.Reader",
"meshreader");
118 Handle< Mesh > mesh_ptr = meshreader->create_mesh_from(
"rotation-tg-p1.neu");
119 Mesh& mesh = *mesh_ptr;
120 Core::instance().
root().add_component(mesh_ptr):
124 boost::shared_ptr< MeshReader > meshreader =
125 build_component_abstract_type<MeshReader>(
"cf3.mesh.gmsh.Reader",
"meshreader");
128 meshreader->options().set(
"file",
URI(
"../../resources/rectangle-tg-p1.msh"));
129 meshreader->execute();
130 Mesh& mesh = *mesh_ptr;
132 boost::shared_ptr< MeshWriter > mesh_writer =
133 build_component_abstract_type<MeshWriter>(
"cf3.mesh.gmsh.Writer",
"msh_writer");
136 mesh_writer->
options().
set(
"file",
URI(
"parallel_fields.msh"));
137 mesh_writer->options().set(
"mesh",mesh.
handle<
Mesh>());
138 mesh_writer->execute();
142 build_component_abstract_type<MeshTransformer>(
"cf3.mesh.actions.LoadBalance",
"load_balancer")->transform(mesh);
152 field[
n][j] = PE::Comm::instance().
rank();
173 nodes_P1_node_rank[
n][0] = nodes_P1.
rank()[
n];
177 const Entities& elements = *elements_handle;
178 const Space& space = elems_P0.
space(elements);
182 glb_elem_idx[field_idx][0] = elems_P0.
glb_idx()[field_idx];
183 elem_rank[field_idx][0] = elems_P0.
rank()[field_idx];
193 glb_node_idx[
n][0] = glb_idx[
n];
200 interpolator->interpolate(nodes_P1_node_rank,P1_node_rank);
205 fields.push_back(field.
uri());
206 fields.push_back(P1_node_rank.
uri());
207 fields.push_back(glb_elem_idx.
uri());
208 fields.push_back(elem_rank.
uri());
209 fields.push_back(glb_node_idx.
uri());
211 boost::shared_ptr< MeshWriter > tec_writer =
212 build_component_abstract_type<MeshWriter>(
"cf3.mesh.tecplot.Writer",
"tec_writer");
214 tec_writer->options().set(
"fields",fields);
215 tec_writer->options().set(
"cell_centred",
true);
216 tec_writer->options().set(
"file",
URI(
"parallel_fields.plt"));
217 tec_writer->options().set(
"mesh",mesh.
handle<
Mesh>());
218 tec_writer->execute();
222 boost::shared_ptr< MeshWriter > msh_writer =
223 build_component_abstract_type<MeshWriter>(
"cf3.mesh.gmsh.Writer",
"msh_writer");
225 msh_writer->options().set(
"fields",fields);
226 msh_writer->options().set(
"file",
URI(
"parallel_fields.msh"));
227 msh_writer->options().set(
"mesh",mesh.
handle<
Mesh>());
228 msh_writer->execute();
240 Core::instance().environment().options().set(
"log_level",(
Uint)
DEBUG);
242 boost::shared_ptr< MeshGenerator > meshgenerator = build_component_abstract_type<MeshGenerator>(
"cf3.mesh.SimpleMeshGenerator",
"1Dgenerator");
243 meshgenerator->options().set(
"mesh",
URI(
"//line"));
244 meshgenerator->options().set(
"nb_cells",std::vector<Uint>(1,10));
245 meshgenerator->options().set(
"lengths",std::vector<Real>(1,10.));
246 meshgenerator->options().set(
"bdry",
false);
247 Mesh&
mesh = meshgenerator->generate();
249 build_component_abstract_type<MeshTransformer>(
"cf3.mesh.actions.LoadBalance",
"load_balancer")->transform(mesh);
260 node_rank[
n][j] = PE::Comm::instance().
rank();
265 if (Comm::instance().size() == 2)
267 if (Comm::instance().rank() == 0)
270 BOOST_CHECK_EQUAL( node_rank[0][0] , 0. );
272 BOOST_CHECK_EQUAL( node_rank[1][0] , 0. );
274 BOOST_CHECK_EQUAL( node_rank[2][0] , 0. );
276 BOOST_CHECK_EQUAL( node_rank[3][0] , 0. );
278 BOOST_CHECK_EQUAL( node_rank[4][0] , 0. );
281 BOOST_CHECK_EQUAL( node_rank[5][0] , 1. );
283 BOOST_CHECK_EQUAL( node_rank[6][0] , 1. );
285 else if (Comm::instance().rank() == 1)
288 BOOST_CHECK_EQUAL( node_rank[0][0] , 1. );
290 BOOST_CHECK_EQUAL( node_rank[1][0] , 1. );
292 BOOST_CHECK_EQUAL( node_rank[2][0] , 1. );
294 BOOST_CHECK_EQUAL( node_rank[3][0] , 1. );
296 BOOST_CHECK_EQUAL( node_rank[4][0] , 1. );
298 BOOST_CHECK_EQUAL( node_rank[5][0] , 1. );
301 BOOST_CHECK_EQUAL( node_rank[6][0] , 0. );
305 CFwarn <<
"Checks only performed when run with 2 procs" <<
CFendl;
316 elem_rank[
n][j] = PE::Comm::instance().
rank();
321 if (Comm::instance().size() == 2)
323 if (Comm::instance().rank() == 0)
326 BOOST_CHECK_EQUAL( elem_rank[0][0] , 0 );
328 BOOST_CHECK_EQUAL( elem_rank[1][0] , 0 );
330 BOOST_CHECK_EQUAL( elem_rank[2][0] , 0 );
332 BOOST_CHECK_EQUAL( elem_rank[3][0] , 0 );
334 BOOST_CHECK_EQUAL( elem_rank[4][0] , 0 );
336 BOOST_CHECK_EQUAL( elem_rank[5][0] , 1 );
338 else if (Comm::instance().rank() == 1)
341 BOOST_CHECK_EQUAL( elem_rank[0][0] , 1 );
343 BOOST_CHECK_EQUAL( elem_rank[1][0] , 1 );
345 BOOST_CHECK_EQUAL( elem_rank[2][0] , 1 );
347 BOOST_CHECK_EQUAL( elem_rank[3][0] , 1 );
349 BOOST_CHECK_EQUAL( elem_rank[4][0] , 1 );
351 BOOST_CHECK_EQUAL( elem_rank[5][0] , 0 );
358 Gnuplot gp(std::string(GNUPLOT_COMMAND));
359 gp <<
"set terminal png" << std::endl;
360 gp <<
"set output 'ranks_P"<<Comm::instance().rank()<<
".png'" << std::endl;
361 gp <<
"set yrange [-0.5:1.5]" << std::endl;
362 gp <<
"set title 'Rank "<<Comm::instance().rank()<<
"'" << std::endl;
364 gp <<
"'-' with points title 'node-rank'" <<
", ";
365 gp <<
"'-' with points title 'elem-rank'" <<
"\n";
387 PE::Comm::instance().finalize();
389 Core::instance().terminate();
394 BOOST_AUTO_TEST_SUITE_END()
#define CFinfo
these are always defined
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
const std::vector< Handle< Entities > > & entities_range() const
Dictionary & create_discontinuous_space(const std::string &space_name, const std::string &space_lib_name, const std::vector< Handle< Entities > > &entities)
external boost library namespace
int m_argc
possibly common functions used on the tests below
Dictionary & create_continuous_space(const std::string &space_name, const std::string &space_lib_name, const std::vector< Handle< Entities > > &entities)
Parallel Communication Pattern. This class provides functionality to collect communication. For efficiency it works such a way that you submit your request via the constructor or the add/remove/move magic triangle and then call setup to modify the commpattern. The data needed to be kept synchronous can be registered via the insert function. The word node here means any kind of "point of storage", in this context it is not directly related with the computational mesh.
ParallelFieldsTests_Fixture()
common setup for each test case
URI uri() const
Construct the full path.
Gnuplot & send(T p, T last)
common::List< Uint > & rank()
Return the rank of every field row.
#define boost_foreach
lowercase version of BOOST_FOREACH
const Field & coordinates() const
Handle< Component const > root() const
Uint size() const
return the number of elements
common::PE::CommPattern & parallelize()
Basic Classes for Mesh applications used by COOLFluiD.
Top-level namespace for coolfluid.
common::List< Uint > & glb_idx()
Return the global index of every field row.
~ParallelFieldsTests_Fixture()
common tear-down for each test case
const Space & space(const Entities &entities) const
Return the space of given entities.
Uint row_size(Uint i=0) const
std::vector< URI > fields
unsigned int Uint
typedef for unsigned int
Classes offering a MPI interface for COOLFluiD.
common::List< Uint > & rank() const
Handle< Component > handle()
Get a handle to the component.
BOOST_AUTO_TEST_CASE(init_mpi)
Dictionary & geometry_fields() const
void set(const std::string &pname, const boost::any &val)
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.
Most basic kernel library.
Connectivity & connectivity()
connectivity table to dictionary entries