FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
patch_halo_factory.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/geometry/conformal_mesh.hpp>
9#include <kernel/geometry/mesh_part.hpp>
10#include <kernel/adjacency/graph.hpp>
11
12#include <vector>
13
14namespace FEAT
15{
16 namespace Geometry
17 {
19 namespace Intern
20 {
21 template<typename Shape_, int codim_>
22 class PatchHaloBuild
23 {
24 static constexpr int face_dim = Shape_::dimension - codim_;
25
26 public:
27 const TargetSet& _target_face;
28 Adjacency::Graph _elem_at_face;
29 std::vector<Index> _indices;
30
31 public:
32 explicit PatchHaloBuild(const TargetSetHolder<Shape_>& tsh, const IndexSetHolder<Shape_>& ish) :
33 _target_face(tsh.template get_target_set<face_dim>()),
34 _elem_at_face(Adjacency::RenderType::transpose, ish.template get_index_set<Shape_::dimension, face_dim>())
35 {
36 }
37
38 void build(const Index halo_rank, const Adjacency::Graph& ranks_at_elem)
39 {
40 _indices.clear();
41
42 // loop over all faces in the patch mesh part target set
43 for(Index face(0); face < _target_face.get_num_entities(); ++face)
44 {
45 // get index of base-mesh face
46 const Index base_face = _target_face[face];
47
48 // check whether one of them has our desired rank
49 if(_has_face_rank(base_face, halo_rank, ranks_at_elem))
50 {
51 _indices.push_back(face);
52 }
53 }
54 }
55
56 Index size() const
57 {
58 return Index(_indices.size());
59 }
60
61 void fill(TargetSet& target_set) const
62 {
63 XASSERT(target_set.get_num_entities() == size());
64 for(Index i(0); i < size(); ++i)
65 {
66 target_set[i] = _indices[i];
67 }
68 }
69
70 private:
71 bool _has_face_rank(const Index base_face, const Index halo_rank, const Adjacency::Graph& ranks_at_elem)
72 {
73 // loop over all elements adjacent to that face and
74 auto ib = _elem_at_face.image_begin(base_face);
75 auto ie = _elem_at_face.image_end(base_face);
76 for(auto ii(ib); ii != ie; ++ii)
77 {
78 // now loop over all ranks of this element
79 auto jb = ranks_at_elem.image_begin(*ii);
80 auto je = ranks_at_elem.image_end(*ii);
81 for(auto jj(jb); jj != je; ++jj)
82 {
83 // check rank
84 if(*jj == halo_rank)
85 return true;
86 }
87 }
88 // nope
89 return false;
90 }
91 };
92
93 template<typename Shape_>
94 class PatchHaloBuild<Shape_, 0>
95 {
96 public:
97 const TargetSet& _target_face;
98 std::vector<Index> _indices;
99
100 public:
101 explicit PatchHaloBuild(const TargetSetHolder<Shape_>& tsh, const IndexSetHolder<Shape_>&) :
102 _target_face(tsh.template get_target_set<Shape_::dimension>())
103 {
104 }
105
106 void build(const Index halo_rank, const Adjacency::Graph& ranks_at_elem)
107 {
108 _indices.clear();
109
110 // loop over all faces in the patch mesh part target set
111 for(Index elem(0); elem < _target_face.get_num_entities(); ++elem)
112 {
113 // get index of base-mesh face
114 const Index base_elem = _target_face[elem];
115
116 // now loop over all ranks of this element
117 auto jb = ranks_at_elem.image_begin(base_elem);
118 auto je = ranks_at_elem.image_end(base_elem);
119 for(auto jj(jb); jj != je; ++jj)
120 {
121 // check rank
122 if(*jj == halo_rank)
123 {
124 _indices.push_back(elem);
125 break;
126 }
127 }
128 }
129 }
130
131 Index size() const
132 {
133 return Index(_indices.size());
134 }
135
136 void fill(TargetSet& target_set) const
137 {
138 XASSERT(target_set.get_num_entities() == size());
139 for(Index i(0); i < size(); ++i)
140 {
141 target_set[i] = _indices[i];
142 }
143 }
144 };
145
146 template<typename Shape_, int face_dim_ = Shape_::dimension>
147 class PatchHaloBuildWrapper :
148 public PatchHaloBuildWrapper<Shape_, face_dim_ - 1>
149 {
150 typedef PatchHaloBuildWrapper<Shape_, face_dim_ - 1> BaseClass;
151
152 static constexpr int face_codim = Shape_::dimension - face_dim_;
153
154 PatchHaloBuild<Shape_, face_codim> _hbuild;
155
156 public:
157 explicit PatchHaloBuildWrapper(const TargetSetHolder<Shape_>& tsh, const IndexSetHolder<Shape_>& ish) :
158 BaseClass(tsh, ish),
159 _hbuild(tsh, ish)
160 {
161 }
162
163 void build(const Index halo_rank, const Adjacency::Graph& ranks_at_elem)
164 {
165 BaseClass::build(halo_rank, ranks_at_elem);
166 _hbuild.build(halo_rank, ranks_at_elem);
167 }
168
169 Index get_num_entities(int dim) const
170 {
171 XASSERT(dim <= face_dim_);
172 if(dim == face_dim_)
173 return Index(_hbuild.size());
174 else
175 return BaseClass::get_num_entities(dim);
176 }
177
178 void fill(TargetSetHolder<Shape_>& tsh) const
179 {
180 BaseClass::fill(tsh);
181 _hbuild.fill(tsh.template get_target_set<face_dim_>());
182 }
183 };
184
185 template<typename Shape_>
186 class PatchHaloBuildWrapper<Shape_, 0>
187 {
188 static constexpr int face_codim = Shape_::dimension;
189
190 PatchHaloBuild<Shape_, face_codim> _hbuild;
191
192 public:
193 explicit PatchHaloBuildWrapper(const TargetSetHolder<Shape_>& tsh, const IndexSetHolder<Shape_>& ish) :
194 _hbuild(tsh, ish)
195 {
196 }
197
198 void build(const Index halo_rank, const Adjacency::Graph& ranks_at_elem)
199 {
200 _hbuild.build(halo_rank, ranks_at_elem);
201 }
202
203 Index get_num_entities(int dim) const
204 {
205 XASSERT(dim == 0);
206 return Index(_hbuild.size());
207 }
208
209 void fill(TargetSetHolder<Shape_>& tsh) const
210 {
211 _hbuild.fill(tsh.template get_target_set<0>());
212 }
213 };
214 } // namespace Intern
216
217 template<typename Mesh_>
219
231 template<typename Shape_, int num_coords_, typename Coord_>
232 class PatchHaloFactory<Geometry::ConformalMesh<Shape_, num_coords_, Coord_>> :
233 public Factory<MeshPart<Geometry::ConformalMesh<Shape_, num_coords_, Coord_>>>
234 {
235 public:
236 typedef Shape_ ShapeType;
237 static constexpr int shape_dim = ShapeType::dimension;
238
241
250
251 protected:
252 const Adjacency::Graph& _ranks_at_elem;
253 const MeshType& _base_mesh;
254 const MeshPartType& _patch_mesh_part;
255 Index _cur_halo_rank;
256 Intern::PatchHaloBuildWrapper<ShapeType> _halo_wrapper;
257
258 public:
259 explicit PatchHaloFactory(
260 const Adjacency::Graph& ranks_at_elem, const MeshType& base_mesh,
261 const MeshPartType& patch_mesh_part) :
262 _ranks_at_elem(ranks_at_elem),
263 _base_mesh(base_mesh),
264 _patch_mesh_part(patch_mesh_part),
265 _cur_halo_rank(0),
266 _halo_wrapper(patch_mesh_part.get_target_set_holder(), base_mesh.get_index_set_holder())
267 {
268 }
269
270 virtual ~PatchHaloFactory()
271 {
272 }
273
274 void build(Index halo_rank)
275 {
276 _halo_wrapper.build(halo_rank, _ranks_at_elem);
277 }
278
279 /* *************************************************************************************** */
280 /* F A C T O R Y I N T E R F A C E I M P L E M E N T A T I O N */
281 /* *************************************************************************************** */
282
283 virtual Index get_num_entities(int dim) override
284 {
285 return _halo_wrapper.get_num_entities(dim);
286 }
287
288 virtual void fill_attribute_sets(AttributeSetContainer&) override
289 {
290 // nothing to do
291 }
292
293 virtual void fill_index_sets(std::unique_ptr<IndexSetHolderType>&) override
294 {
295 // nothing to do
296 }
297
298 virtual void fill_target_sets(TargetSetHolderType& target_set_holder) override
299 {
300 _halo_wrapper.fill(target_set_holder);
301 }
302 }; // class PatchHaloFactory<ConformalMesh<...>>
303 } // namespace Geometry
304} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
Adjacency Graph implementation.
Definition: graph.hpp:34
Conformal mesh class template.
Coord_ CoordType
Coordinate type.
Mesh Factory class template.
Definition: factory.hpp:33
Class template for partial meshes.
Definition: mesh_part.hpp:90
TargetSetHolder< ShapeType > TargetSetHolderType
Target set holder type.
Definition: mesh_part.hpp:101
IndexSetHolder< ShapeType > IndexSetHolderType
Index set holder type.
Definition: mesh_part.hpp:99
std::map< String, std::unique_ptr< AttributeSetType > > AttributeSetContainer
submesh node bin container type
Definition: mesh_part.hpp:138
MeshPartType::AttributeSetContainer AttributeSetContainer
Mesh attribute holder type.
RenderType
Render type enumeration.
Definition: base.hpp:26
@ transpose
Render-Transpose mode.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.