FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
parti_2lvl.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8#include <kernel/adjacency/graph.hpp>
9#include <kernel/geometry/conformal_mesh.hpp>
10#include <kernel/geometry/intern/standard_refinement_traits.hpp>
12
13namespace FEAT
14{
15 namespace Geometry
16 {
18 namespace Intern
19 {
20 template<typename Shape_>
21 struct Parti2LvlHelper
22 {
23 static constexpr Index factor = StandardRefinementTraits<Shape_, Shape_::dimension>::count;
24 static constexpr Index lvlinc = Index(1);
25 };
26
27 template<int dim_>
28 struct Parti2LvlHelper<Shape::Hypercube<dim_>>
29 {
30 static constexpr Index factor = Index(2);
31 static constexpr Index lvlinc = Index(dim_);
32 };
33 } // namespace Intern
35
37 template<typename Mesh_>
38 class Parti2Lvl;
39
67 template<typename Shape_, int num_coords_, typename Coord_>
68 class Parti2Lvl<ConformalMesh<Shape_, num_coords_, Coord_>>
69 {
70 public:
73
74 protected:
85
86 public:
96 explicit Parti2Lvl(const MeshType& mesh, Index num_ranks) :
97 _num_elems(mesh.get_num_elements()),
98 _num_ranks(num_ranks),
99 _success(false),
100 _ref_lvl(0),
101 _ref_elems(0)
102 {
103 XASSERT(num_ranks > Index(0));
104
105 const Index factor = Intern::Parti2LvlHelper<Shape_>::factor;
106 const Index lvlinc = Intern::Parti2LvlHelper<Shape_>::lvlinc;
107 Index count(_num_elems);
108 Index power(0);
109
110 while(count < _num_ranks)
111 {
112 count *= factor;
113 ++power;
114 }
115
116 if(count != _num_ranks)
117 {
118 // no 2-level partitioning possible
119 return;
120 }
121
122 _success = true;
123
124 // compute refinement level
125 _ref_lvl = (power + lvlinc - Index(1)) / lvlinc;
126
127 // compute refined element count
128 const Index ref_fac(Intern::StandardRefinementTraits<Shape_, Shape_::dimension>::count);
129 _ref_elems = _num_elems;
130 for(Index i(0); i < _ref_lvl; ++i)
131 _ref_elems *= ref_fac;
132 }
133
140 bool success() const
141 {
142 return _success;
143 }
144
149 {
150 return _ref_lvl;
151 }
152
160 {
161 Adjacency::Graph graph(_num_ranks, _ref_elems, _ref_elems);
162 Index* ptr = graph.get_domain_ptr();
163 Index* idx = graph.get_image_idx();
164
165 // build pointer array
166 const Index elems_per_rank = _ref_elems / _num_ranks;
167 for(Index i(0); i <= _num_ranks; ++i)
168 ptr[i] = elems_per_rank * i;
169
170 // build index array
171 for(Index i(0); i < _ref_elems; ++i)
172 idx[i] = i;
173
174 return graph;
175 }
176 }; // class Parti2Lvl
177 } // namespace Geometry
178} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
Adjacency Graph implementation.
Definition: graph.hpp:34
Index * get_domain_ptr()
Returns the domain pointer array.
Definition: graph.hpp:359
Index * get_image_idx()
Returns the image node index array.
Definition: graph.hpp:374
Conformal mesh class template.
Parti2Lvl(const MeshType &mesh, Index num_ranks)
Constructor.
Definition: parti_2lvl.hpp:96
bool _success
specifies whether partitioning is possible
Definition: parti_2lvl.hpp:80
bool success() const
Specifies whether a 2-level partitioning exists.
Definition: parti_2lvl.hpp:140
Index parti_level() const
Returns the required refinement level for the 2-level partitioning.
Definition: parti_2lvl.hpp:148
ConformalMesh< Shape_, num_coords_, Coord_ > MeshType
our mesh type
Definition: parti_2lvl.hpp:72
Adjacency::Graph build_elems_at_rank() const
Returns the Elements-at-Rank graph of the partitioning.
Definition: parti_2lvl.hpp:159
2-Level-Partitioner class template declaration
Definition: parti_2lvl.hpp:38
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.