FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
patch_index_mapping.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// includes, FEAT
9#include <kernel/geometry/index_set.hpp>
10#include <kernel/geometry/target_set.hpp>
11
12namespace FEAT
13{
14 namespace Geometry
15 {
17 namespace Intern
18 {
19 struct PatchIndexMappingHelper
20 {
21 template<int num_indices_>
22 static void apply(
23 IndexSet<num_indices_>& iso,
24 const IndexSet<num_indices_>& isi,
25 const TargetSet& tsc,
26 Index* tsf)
27 {
28 const Index num_cells(tsc.get_num_entities());
29 for(Index i(0); i < num_cells; ++i)
30 {
31 const Index isx(tsc[i]);
32 for(int j(0); j < num_indices_; ++j)
33 {
34 iso(i,j) = tsf[isi(isx, j)];
35 }
36 }
37 }
38 };
39
40 template<
41 typename Shape_,
42 int face_dim_ = Shape_::dimension - 1>
43 struct PatchIndexMappingWrapper
44 {
45 static void apply(
46 IndexSetWrapper<Shape_, face_dim_>& iso,
47 const IndexSetWrapper<Shape_, face_dim_>& isi,
48 const TargetSetHolder<Shape_>& tsc,
49 Index** tsf)
50 {
51 // recurse down
52 PatchIndexMappingWrapper<Shape_, face_dim_ - 1>::apply(iso, isi, tsc, tsf);
53
54 // call helper
55 PatchIndexMappingHelper::apply(
56 iso.template get_index_set<face_dim_>(),
57 isi.template get_index_set<face_dim_>(),
58 tsc.template get_target_set<Shape_::dimension>(),
59 tsf[face_dim_]);
60 }
61 };
62
63 template<typename Shape_>
64 struct PatchIndexMappingWrapper<Shape_, 0>
65 {
66 static void apply(
67 IndexSetWrapper<Shape_, 0>& iso,
68 const IndexSetWrapper<Shape_, 0>& isi,
69 const TargetSetHolder<Shape_>& tsc,
70 Index** tsf)
71 {
72 // call helper
73 PatchIndexMappingHelper::apply(
74 iso.template get_index_set<0>(),
75 isi.template get_index_set<0>(),
76 tsc.template get_target_set<Shape_::dimension>(),
77 tsf[0]);
78 }
79 };
80
81 template<typename Shape_>
82 struct PatchIndexMapping
83 {
84 static constexpr int shape_dim = Shape_::dimension;
85 typedef typename Shape::FaceTraits<Shape_, shape_dim - 1>::ShapeType FaceType;
86
87 static void apply(
88 IndexSetHolder<Shape_>& iso,
89 const IndexSetHolder<Shape_>& isi,
90 const TargetSetHolder<Shape_>& tsc,
91 const Index num_entities[])
92 {
93 Index *tsf[shape_dim + 1];
94 _build_tsf(tsf, tsc, num_entities);
95 _apply(iso, isi, tsc, &tsf[0]);
96 for(int i(0); i <= shape_dim; ++i)
97 {
98 delete [] (tsf[i]);
99 }
100 }
101
102 //protected:
103 static void _build_tsf(
104 Index** tsf,
105 const TargetSetHolder<Shape_>& tsh,
106 const Index num_entities[])
107 {
108 // recurse down
109 PatchIndexMapping<FaceType>::_build_tsf(tsf, tsh, num_entities);
110
111 tsf[shape_dim] = new Index[num_entities[shape_dim]];
112 Index* tsi(tsf[shape_dim]);
113 const TargetSet& ts(tsh.template get_target_set<shape_dim>());
114 const Index ni(tsh.get_num_entities(shape_dim));
115 for(Index i(0); i < ni; ++i)
116 {
117 tsi[ts[i]] = i;
118 }
119 }
120
121 static void _apply(
122 IndexSetHolder<Shape_>& iso,
123 const IndexSetHolder<Shape_>& isi,
124 const TargetSetHolder<Shape_>& tsc,
125 Index** tsf)
126 {
127 // recurse down
128 PatchIndexMapping<FaceType>::_apply(iso, isi, tsc, tsf);
129
130 // call wrapper
131 PatchIndexMappingWrapper<Shape_>::apply(
132 iso.template get_index_set_wrapper<shape_dim>(),
133 isi.template get_index_set_wrapper<shape_dim>(), tsc, tsf);
134 }
135 };
136
137 template<>
138 struct PatchIndexMapping<Shape::Vertex>
139 {
140 //protected:
141 static void _build_tsf(
142 Index** tsf,
143 const TargetSetHolder<Shape::Vertex>& tsh,
144 const Index num_entities[])
145 {
146 tsf[0] = new Index[num_entities[0]];
147 Index* tsi(tsf[0]);
148 const TargetSet& ts(tsh.get_target_set<0>());
149 const Index ni(tsh.get_num_entities(0));
150 for(Index i(0); i < ni; ++i)
151 {
152 tsi[ts[i]] = i;
153 }
154 }
155
156 template<typename ISO_, typename ISI_, typename TSC_>
157 static void _apply(ISO_&, const ISI_&, const TSC_&, Index**)
158 {
159 // do nothing
160 }
161 };
162 } // namespace Intern
164 } // namespace Geometry
165} // namespace FEAT
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.