COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-blockmesh-3d-mpi.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::BlockMesh::BlockMeshMPI"
9 
10 #include <boost/assign.hpp>
11 #include <boost/lexical_cast.hpp>
12 #include <boost/test/unit_test.hpp>
13 
14 #include "common/Core.hpp"
15 #include "common/Log.hpp"
16 #include "common/OptionList.hpp"
17 #include "common/List.hpp"
18 
19 #include "common/PE/Comm.hpp"
20 
22 #include "mesh/Domain.hpp"
23 #include "mesh/Elements.hpp"
24 #include "mesh/Mesh.hpp"
25 #include "mesh/MeshWriter.hpp"
26 #include "mesh/Region.hpp"
27 #include "mesh/Space.hpp"
28 #include "mesh/Field.hpp"
29 #include "mesh/Connectivity.hpp"
30 #include "mesh/Dictionary.hpp"
31 
34 
35 using namespace cf3;
36 using namespace cf3::common;
37 using namespace cf3::mesh;
38 
39 using namespace boost::assign;
40 
42 
45 {
47  {
48  int argc = boost::unit_test::framework::master_test_suite().argc;
49  char** argv = boost::unit_test::framework::master_test_suite().argv;
50 
51  cf3_assert(argc >= 4);
52  x_segs = boost::lexical_cast<Uint>(argv[1]);
53  y_segs = boost::lexical_cast<Uint>(argv[2]);
54  z_segs = boost::lexical_cast<Uint>(argv[3]);
55 
57  PE::Comm::instance().init(argc, argv);
58 
60  if(!root.get_child("domain"))
61  {
62  m_domain = root.create_component<Domain>("domain");
63  }
64  else
65  {
66  m_domain = Handle<Domain>(root.get_child("domain"));
67  }
68 
69  if(!domain().get_child("mesh"))
70  {
71  m_mesh = domain().create_component<Mesh>("mesh");
72  }
73  else
74  {
75  m_mesh = Handle<Mesh>(domain().get_child("mesh"));
76  }
77  }
78 
80  {
81  return *m_domain;
82  }
83 
85  {
86  return *m_mesh;
87  }
88 
90 
93 };
94 
96 
97 BOOST_FIXTURE_TEST_SUITE( BlockMesh3D, BockMesh3DFixture )
98 
99 
101 std::vector<URI> fields;
102 
104 {
105  // Make sure MPI is up before running the first test
106  BOOST_CHECK(PE::Comm::instance().is_active());
107 }
108 
109 BOOST_AUTO_TEST_CASE( GenerateMesh )
110 {
111  const Uint nb_procs = PE::Comm::instance().size();
112  const Uint rank = PE::Comm::instance().rank();
113 
114  const Real length = 12.;
115  const Real half_height = 0.5;
116  const Real width = 6.;
117  const Real ratio = 0.1;
118 
119  BlockMesh::BlockArrays& blocks = *domain().create_component<BlockMesh::BlockArrays>("BlockArrays");
120 
121  // Create blocks for a 3D channel
122  Tools::MeshGeneration::create_channel_3d(blocks, length, half_height, width, x_segs, y_segs/2, z_segs, ratio);
123 
124  // Try partitioning in multiple directions for certain numbers of CPUS
125  if(nb_procs == 16)
126  {
127  blocks.partition_blocks(8, XX);
128  blocks.partition_blocks(2, ZZ);
129  }
130  else if(nb_procs == 32)
131  {
132  blocks.partition_blocks(8, XX);
133  blocks.partition_blocks(4, ZZ);
134  }
135  else if(nb_procs == 64)
136  {
137  blocks.partition_blocks(16, XX);
138  blocks.partition_blocks(4, ZZ);
139  }
140  else if(nb_procs == 128)
141  {
142  blocks.partition_blocks(16, XX);
143  blocks.partition_blocks(8, ZZ);
144  }
145  else
146  {
147  blocks.partition_blocks(nb_procs, XX);
148  }
149 
150  blocks.create_mesh(mesh());
151 }
152 
154 {
155  // Store element ranks
156  Dictionary& elems_P0 = mesh().create_discontinuous_space("elems_P0","cf3.mesh.LagrangeP0");
157  Field& elem_rank = elems_P0.create_field("elem_rank");
158 
159  boost_foreach(const Handle<Entities>& elements_handle, elems_P0.entities_range())
160  {
161  Entities& elements = *elements_handle;
162  const Space& space = elems_P0.space(elements);
163  for (Uint elem=0; elem<elements.size(); ++elem)
164  {
165  Uint field_idx = space.connectivity()[elem][0];
166  elem_rank[field_idx][0] = elements.rank()[elem];
167  }
168  }
169  fields.push_back(elem_rank.uri());
170 }
171 
173 {
174  mesh().write_mesh("utest-blockmesh-3d-mpi_output.pvtu", fields);
175 }
176 
178 
179 BOOST_AUTO_TEST_SUITE_END()
180 
181 
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
Definition: Dictionary.cpp:178
const std::vector< Handle< Entities > > & entities_range() const
Definition: Dictionary.cpp:353
#define cf3_assert(a)
Definition: Assertions.hpp:93
URI uri() const
Construct the full path.
Definition: Component.cpp:248
STL namespace.
#define boost_foreach
lowercase version of BOOST_FOREACH
Definition: Foreach.hpp:16
common::List< Uint > & rank()
Definition: Entities.hpp:71
tuple root
Definition: coolfluid.py:24
Uint rank() const
Return rank, additionally, if is_init==0.
Definition: Comm.cpp:135
Any test using this fixture (or a derivative) will be timed.
void partition_blocks(const Uint nb_partitions, const Uint direction)
Definition: BlockData.cpp:1495
Definition: Defs.hpp:17
Definition: Defs.hpp:17
Uint size() const
Return the number of processes, or 1 if is_init==0.
Definition: Comm.cpp:145
Uint size() const
return the number of elements
Definition: Entities.cpp:161
bool is_active() const
Definition: Comm.hpp:83
Basic Classes for Mesh applications used by COOLFluiD.
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
void create_channel_3d(BlockArrays &blocks, const Real length, const Real half_height, const Real width, const Uint x_segs, const Uint y_segs_half, const Uint z_segs, const Real ratio)
const Space & space(const Entities &entities) const
Return the space of given entities.
Definition: Dictionary.cpp:161
std::vector< URI > fields
common::Component & root() const
Gives the default root component.
Definition: Core.cpp:145
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
static Core & instance()
Definition: Core.cpp:37
BOOST_AUTO_TEST_CASE(Setup)
static Comm & instance()
Return a reference to the current PE.
Definition: Comm.cpp:44
Base class for defining CF components.
Definition: Component.hpp:82
Space component class.
Definition: Space.hpp:59
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
Connectivity & connectivity()
connectivity table to dictionary entries
Definition: Space.hpp:110
Send comments to:
COOLFluiD Web Admin