COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-blockmesh-2d-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/test/unit_test.hpp>
12 
13 #include "common/Core.hpp"
14 #include "common/Log.hpp"
15 #include "common/List.hpp"
16 
17 #include "common/PE/Comm.hpp"
18 #include "common/PE/debug.hpp"
19 #include "common/OptionList.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 
32 using namespace cf3;
33 using namespace cf3::common;
34 using namespace cf3::mesh;
35 
36 using namespace boost::assign;
37 
39 
40 BOOST_AUTO_TEST_SUITE( BlockMesh2D )
41 
42 
45 {
46  PE::Comm::instance().init(boost::unit_test::framework::master_test_suite().argc, boost::unit_test::framework::master_test_suite().argv);
47 
49  const Uint rank = PE::Comm::instance().rank();
50  cf3_assert(nb_procs==8);
51 
52  //PE::wait_for_debugger(0);
53 
55 
56  const Real length = 1.;
57  const Real half_height = 1.;
58  const Real ratio = 0.2;
59  const Uint x_segs = 12;
60  const Uint y_segs = 10;
61 
63 
64  (*blocks.create_points(2, 6)) << 0. << -half_height
65  << length << -half_height
66  << 0. << 0.
67  << length << 0.
68  << 0. << half_height
69  << length << half_height;
70 
71  (*blocks.create_blocks(2)) << 0 << 1 << 3 << 2
72  << 2 << 3 << 5 << 4;
73 
74  (*blocks.create_block_subdivisions()) << x_segs << y_segs
75  << x_segs << y_segs;
76 
77  (*blocks.create_block_gradings()) << 1. << 1. << 1./ratio << 1./ratio
78  << 1. << 1. << ratio << ratio;
79 
80  *blocks.create_patch("left", 2) << 2 << 0 << 4 << 2;
81  *blocks.create_patch("right", 2) << 1 << 3 << 3 << 5;
82  *blocks.create_patch("top", 1) << 5 << 4;
83  *blocks.create_patch("bottom", 1) << 0 << 1;
84 
85  // Partition the blocks
86  blocks.partition_blocks(4, 1);
87  blocks.partition_blocks(2, 0);
88 
89  // Build the mesh
90  Mesh& mesh = *domain.create_component<Mesh>("mesh");
91  blocks.create_mesh(mesh);
92 
93  // Store element ranks
94  Dictionary& elems_P0 = mesh.create_discontinuous_space("elems_P0","cf3.mesh.LagrangeP0");
95  Field& elem_rank = elems_P0.create_field("elem_rank");
96 
97  boost_foreach(const Handle<Entities>& elements_handle, elems_P0.entities_range())
98  {
99  Entities& elements = *elements_handle;
100  const Space& space = elems_P0.space(elements);
101  for (Uint elem=0; elem<elements.size(); ++elem)
102  {
103  Uint field_idx = space.connectivity()[elem][0];
104  elem_rank[field_idx][0] = elements.rank()[elem];
105  }
106  }
107 
108  // Write to disk
109  std::vector<URI> fields;
110  fields.push_back(elem_rank.uri());
111  mesh.write_mesh("utest-blockmesh-2d-mpi_output.pvtu", fields);
112 }
113 
115 
116 BOOST_AUTO_TEST_SUITE_END()
117 
118 
void write_mesh(const common::URI &file, const std::vector< common::URI > fields=std::vector< common::URI >())
Definition: Mesh.cpp:391
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
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
Dictionary & create_discontinuous_space(const std::string &space_name, const std::string &space_lib_name, const std::vector< Handle< Entities > > &entities)
Definition: Mesh.cpp:316
#define cf3_assert(a)
Definition: Assertions.hpp:93
URI uri() const
Construct the full path.
Definition: Component.cpp:248
#define boost_foreach
lowercase version of BOOST_FOREACH
Definition: Foreach.hpp:16
common::List< Uint > & rank()
Definition: Entities.hpp:71
Handle< common::Table< Uint > > create_block_subdivisions()
Definition: BlockData.cpp:1315
Uint rank() const
Return rank, additionally, if is_init==0.
Definition: Comm.cpp:135
void partition_blocks(const Uint nb_partitions, const Uint direction)
Definition: BlockData.cpp:1495
Handle< common::Table< Uint > > create_blocks(const Uint nb_blocks)
Create the table that holds the blocks.
Definition: BlockData.cpp:1299
Uint size() const
Return the number of processes, or 1 if is_init==0.
Definition: Comm.cpp:145
BOOST_AUTO_TEST_CASE(Grid2D)
Uint size() const
return the number of elements
Definition: Entities.cpp:161
Basic Classes for Mesh applications used by COOLFluiD.
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Handle< common::Table< Real > > create_block_gradings()
Definition: BlockData.cpp:1329
Handle< common::Table< Uint > > create_patch(const std::string &name, const Uint nb_faces)
Definition: BlockData.cpp:1343
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
static Comm & instance()
Return a reference to the current PE.
Definition: Comm.cpp:44
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
Handle< common::Table< Real > > create_points(const Uint dimensions, const Uint nb_points)
Create the table that holds the points for the blocks.
Definition: BlockData.cpp:1287
Send comments to:
COOLFluiD Web Admin