DUNE PDELab (2.8)

permutedordering.hh
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_ORDERING_PERMUTEDORDERING_HH
5#define DUNE_PDELAB_ORDERING_PERMUTEDORDERING_HH
6
7#include <dune/typetree/typetree.hh>
8
9#include <dune/pdelab/ordering/utility.hh>
10#include <dune/pdelab/ordering/orderingbase.hh>
11#include <dune/pdelab/ordering/decorator.hh>
12
13namespace Dune {
14 namespace PDELab {
15
16 namespace ordering {
17
18#ifndef DOXYGEN // implementation internals
19
20 namespace permuted {
21
22 struct tag_base
23 {
24
25 std::vector<std::size_t>& permutation()
26 {
27 return _permutation;
28 }
29
30 const std::vector<std::size_t>& permutation() const
31 {
32 return _permutation;
33 }
34
35 private:
36
37 std::vector<std::size_t> _permutation;
38
39 };
40
41 template<std::size_t i>
42 struct base_holder
43 : public tag_base
44 {};
45
46 } // namespace permuted
47
48#endif // DOXYGEN
49
51
62 template<typename OrderingTag>
63 struct Permuted
64 : public permuted::base_holder<decorated_ordering_tag<Permuted<OrderingTag>,OrderingTag>::level>
65 , public decorated_ordering_tag<Permuted<OrderingTag>,OrderingTag>
66 {
67
68 Permuted()
69 {}
70
71 Permuted(const OrderingTag& tag)
72 : decorated_ordering_tag<Permuted<OrderingTag>,OrderingTag>(tag)
73 {}
74
75 Permuted(OrderingTag&& tag)
76 : decorated_ordering_tag<Permuted<OrderingTag>,OrderingTag>(std::move(tag))
77 {}
78
79 template<std::size_t i>
80 const permuted::base_holder<i>& permuted() const
81 {
82 return *this;
83 }
84
85 template<std::size_t i>
86 permuted::base_holder<i>& permuted()
87 {
88 return *this;
89 }
90
91 };
92
93 } // namespace ordering
94
97
99 template<typename Ordering>
101 : public TypeTree::CompositeNode<Ordering>
102 , public VirtualOrderingBase<typename Ordering::Traits::DOFIndex,
103 typename Ordering::Traits::ContainerIndex>
104 , public OrderingBase<typename Ordering::Traits::DOFIndex,
105 typename Ordering::Traits::ContainerIndex>
106 {
107 public:
108 typedef typename Ordering::Traits Traits;
109
110 static const bool has_dynamic_ordering_children = true;
111
112 static const bool consume_tree_index = false;
113
114 private:
115
117
118 typedef OrderingBase<typename Ordering::Traits::DOFIndex,
119 typename Ordering::Traits::ContainerIndex> BaseT;
120
121 public:
122
123 Ordering& ordering()
124 {
125 return this->template child<0>();
126 }
127
128 const Ordering& ordering() const
129 {
130 return this->template child<0>();
131 }
132
133
134 PermutedOrdering(const typename NodeT::NodeStorage& ordering, const ordering::permuted::tag_base& tag)
135 : NodeT(ordering)
136 , BaseT(*this,false,nullptr,this)
137 , _tag(tag)
138 {}
139
141 : NodeT(r.nodeStorage())
142 , BaseT(r)
143 ,_tag(r._tag)
144 {
145 this->setDelegate(this);
146 }
147
149 : NodeT(r.nodeStorage())
150 , BaseT(std::move(r))
151 ,_tag(r._tag)
152 {
153 this->setDelegate(this);
154 }
155
156 virtual ~PermutedOrdering() override = default;
157
158 using BaseT::size;
159
160 typename Traits::SizeType size(typename Traits::ContainerIndex suffix) const {
161 if (suffix.size() == 0)
162 return ordering().size(suffix);
163
164 suffix.back() = _tag.permutation()[suffix.back()];
165 return ordering().size(suffix);
166 }
167
168 virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const override
169 {
170 ordering().mapIndex(di,ci);
171 ci.back() = _tag.permutation()[ci.back()];
172 }
173
174 template<typename ItIn, typename ItOut>
175 void map_lfs_indices(ItIn in, const ItIn end, ItOut out) const
176 {
177 for (; in != end; ++in, ++out)
178 {
179 out->back() = _tag.permutation()[out->back()];
180 }
181 }
182
183 template<typename CIOutIterator>
184 typename Traits::SizeType
185 extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
186 typename Traits::SizeType child_index,
187 CIOutIterator ci_out, const CIOutIterator ci_end) const
188 {
189 for (; ci_out != ci_end; ++ci_out)
190 {
191 ci_out->back() = _tag.permutation()[ci_out->back()];
192 }
193 return 0;
194 }
195
196 void update()
197 {
198 ordering().update();
199 BaseT::update();
200 if (!_tag.permutation().empty() && _tag.permutation().size() != this->blockCount())
202 "Size of permutation array does not match block count of ordering: "
203 << _tag.permutation().size()
204 << " != "
205 << this->blockCount()
206 );
207 else
208 {
209 auto& mutable_tag = const_cast<ordering::permuted::tag_base&>(_tag);
210 mutable_tag.permutation().resize(this->blockCount());
211 std::iota(
212 mutable_tag.permutation().begin(),
213 mutable_tag.permutation().end(),
214 0
215 );
216 }
217 }
218
219 private:
220
221 const ordering::permuted::tag_base& _tag;
222
223 };
224
225 namespace ordering {
226
227 namespace permuted {
228
229 template<typename GFS, typename Transformation, typename Undecorated, typename Tag>
230 struct gfs_to_permuted
231 {
232
233 typedef PermutedOrdering<Undecorated> transformed_type;
234 typedef std::shared_ptr<transformed_type> transformed_storage_type;
235
236 static transformed_type transform(const GFS& gfs, const Transformation& t, std::shared_ptr<Undecorated> undecorated)
237 {
238 return transformed_type(make_tuple(undecorated),gfs.orderingTag().template permuted<Tag::level>());
239 }
240
241 static transformed_storage_type transform_storage(std::shared_ptr<const GFS> gfs_pointer, const Transformation& t, std::shared_ptr<Undecorated> undecorated)
242 {
243 return std::make_shared<transformed_type>(make_tuple(undecorated),gfs_pointer->orderingTag().template permuted<Tag::level>());
244 }
245
246 };
247
248 template<typename GFS, typename Transformation, typename Undecorated, typename GlueTag, typename UndecoratedTag>
249 gfs_to_permuted<GFS,Transformation,Undecorated,GlueTag>
250 register_gfs_to_decorator_descriptor(GFS*,Transformation*,Undecorated*,GlueTag*,Permuted<UndecoratedTag>*);
251
252 } // namespace permuted
253 } // namespace ordering
254
255
256 template<typename GFS, typename Transformation, typename U>
257 struct power_gfs_to_local_ordering_descriptor<GFS,Transformation,ordering::Permuted<U> >
258 : public power_gfs_to_local_ordering_descriptor<GFS,Transformation,U>
259 {};
260
261
262 template<typename GFS, typename Transformation, typename U>
263 struct composite_gfs_to_local_ordering_descriptor<GFS,Transformation,ordering::Permuted<U> >
264 : public composite_gfs_to_local_ordering_descriptor<GFS,Transformation,U>
265 {};
266
268 } // namespace PDELab
269} // namespace Dune
270
271#endif // DUNE_PDELAB_ORDERING_PERMUTEDORDERING_HH
A PermutedOrdering got a permutation vector of the wrong size.
Definition: exceptions.hh:51
Ordering that permutes top-level ContainerIndex entries.
Definition: permutedordering.hh:106
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:26
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:34
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:11
Permute the ordering created from the passed-in tag based on a simple lookup table.
Definition: permutedordering.hh:66
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)