Dune Core Modules (2.8.0)

concepts.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_CONCEPTS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_CONCEPTS_HH
5
6
8
9#include <dune/functions/common/utility.hh>
10
11#include <dune/functions/functionspacebases/nodes.hh>
12
13
14namespace Dune {
15namespace Functions {
16namespace Concept {
17
18using namespace Dune::Concept;
19
20
21struct HasResize
22{
23 template<class C>
24 auto require(C&& c) -> decltype(
25 c.resize(0)
26 );
27};
28
29
30
31struct HasSizeMethod
32{
33 template<class C>
34 auto require(C&& c) -> decltype(
35 c.size()
36 );
37};
38
39
40
41struct HasIndexAccess
42{
43 template<class C, class I>
44 auto require(C&& c, I&& i) -> decltype(
45 c[i]
46 );
47};
48
49
50// Concept for a BasisNode in a local ansatz tree
51struct BasisNode
52{
53 template<class N>
54 auto require(const N& node) -> decltype(
55 requireType<typename N::size_type>(),
56 requireConvertible<typename N::size_type>(node.size()),
57 requireConvertible<typename N::size_type>(node.localIndex(std::declval<typename N::size_type>())),
58 requireConvertible<typename N::size_type>(node.treeIndex()),
59 requireBaseOf<BasisNodeMixin, N>()
60 );
61};
62
63
64
65// Concept for a LeafBasisNode in a local ansatz tree
66template<class GridView>
67struct LeafBasisNode : Refines<BasisNode>
68{
69 template<class N>
70 auto require(const N& node) -> decltype(
71 requireType<typename N::Element>(),
72 requireType<typename N::FiniteElement>(),
73 requireConvertible<typename N::Element>(node.element()),
74 requireConvertible<const typename N::FiniteElement&>(node.finiteElement()),
75 requireSameType<typename N::Element, typename GridView::template Codim<0>::Entity>(),
76 requireBaseOf<Dune::Functions::LeafBasisNode, N>()
77 );
78};
79
80
81template<class GridView>
82struct BasisTree;
83
84// Concept for a PowerBasisNode in a local ansatz tree
85template<class GridView>
86struct PowerBasisNode : Refines<BasisNode>
87{
88 template<class N>
89 auto require(const N& node) -> decltype(
90 requireBaseOf<Dune::Functions::PowerBasisNode<typename N::ChildType, N::CHILDREN>, N>(),
91 requireConcept<BasisTree<GridView>, typename N::ChildType>()
92 );
93};
94
95
96// Concept for a CompositeBasisNode in a local ansatz tree
97template<class GridView>
98struct CompositeBasisNode : Refines<BasisNode>
99{
100 template<class N>
101 auto require(const N& node) -> decltype(
102 requireBaseOf<ExpandTuple<Dune::Functions::template CompositeBasisNode, typename N::ChildTypes>, N>(),
103 requireConceptForTupleEntries<BasisTree<GridView>, typename N::ChildTypes>()
104 );
105};
106
107
108// Concept for a full local BasisTree
109template<class GridView>
110struct BasisTree : Refines<BasisNode>
111{
112 template<class N>
113 auto require(const N& node) -> decltype(
114 requireConcept<typename std::conditional< N::isLeaf, LeafBasisNode<GridView>, BasisNode>::type, N>(),
115 requireConcept<typename std::conditional< N::isPower, PowerBasisNode<GridView>, BasisNode>::type, N>(),
116 requireConcept<typename std::conditional< N::isComposite, CompositeBasisNode<GridView>, BasisNode>::type, N>()
117 );
118};
119
120
121// Concept for a NodeIndexSet
122// This concept is deprecated and will be removed.
123template<class PreBasis>
124struct NodeIndexSet
125{
126 template<class I>
127 auto require(const I& indexSet) -> decltype(
128 requireType<typename I::size_type>(),
129 requireType<typename I::MultiIndex>(),
130 requireType<typename I::PreBasis>(),
131 requireType<typename I::Node>(),
132 requireSameType<typename I::PreBasis, PreBasis>(),
133 const_cast<I&>(indexSet).bind(std::declval<typename I::Node>()),
134 const_cast<I&>(indexSet).unbind(),
135 requireConvertible<typename I::size_type>(indexSet.size()),
136 requireConvertible<typename std::vector<typename I::MultiIndex>::iterator>(
137 indexSet.indices(std::declval<typename std::vector<typename I::MultiIndex>::iterator>()))
138 );
139};
140
141// within the concept check ignore deprecation warnings
142#if defined(__GNUC__) || defined(__clang__)
143#pragma GCC diagnostic push
144#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
145#endif
146
147// Concept mixin for old PreBasis interface with NodeIndexSet
148// This concept is deprecated.
149template<class GridView>
150struct PreBasisWithNodeIndexSet
151{
152 template<class PB>
153 auto require(const PB& preBasis) -> decltype(
154 requireType<typename PB::IndexSet>(),
155 requireConvertible<typename PB::IndexSet>(preBasis.makeIndexSet()),
156 requireConcept<NodeIndexSet<PB>>(preBasis.makeIndexSet())
157 );
158};
159
160#if defined(__GNUC__) || defined(__clang__)
161#pragma GCC diagnostic pop
162#endif
163
164// Concept mixin for new PreBasis interface with indices method
165// This concept will be incorporated into the PreBasis concept
166// once PreBasisWithNodeIndexSet was removed.
167template<class GridView>
168struct PreBasisWithIndices
169{
170 template<class PB>
171 auto require(const PB& preBasis) -> decltype(
172 requireConvertible<typename std::vector<typename PB::MultiIndex>::iterator>(
173 preBasis.indices(
174 preBasis.makeNode(),
175 std::declval<typename std::vector<typename PB::MultiIndex>::iterator>()))
176 );
177};
178
179// Concept for a PreBasis
180template<class GridView>
181struct PreBasis
182{
183 template<class PB>
184 auto require(const PB& preBasis) -> decltype(
185 requireType<typename PB::GridView>(),
186 requireType<typename PB::size_type>(),
187 requireType<typename PB::MultiIndex>(),
188 requireType<typename PB::SizePrefix>(),
189 requireType<typename PB::Node>(),
190 requireSameType<typename PB::GridView, GridView>(),
191 const_cast<PB&>(preBasis).initializeIndices(),
192 requireConvertible<typename PB::GridView>(preBasis.gridView()),
193 requireConvertible<typename PB::Node>(preBasis.makeNode()),
194 requireConvertible<typename PB::size_type>(preBasis.size()),
195 requireConvertible<typename PB::size_type>(preBasis.size(std::declval<typename PB::SizePrefix>())),
196 requireConvertible<typename PB::size_type>(preBasis.dimension()),
197 requireConvertible<typename PB::size_type>(preBasis.maxNodeSize()),
198 requireSameType<decltype(const_cast<PB&>(preBasis).update(preBasis.gridView())),void>(),
199 requireConcept<BasisTree<typename PB::GridView>>(preBasis.makeNode()),
200 requireTrue<models<PreBasisWithNodeIndexSet<GridView>, PB>() or models<PreBasisWithIndices<GridView>, PB>()>()
201 // The previous line should be replaced by the following
202 // once PreBasisWithNodeIndexSet was removed:
203 // requireConvertible<typename std::vector<typename PB::MultiIndex>::iterator>(
204 // preBasis.indices(
205 // preBasis.makeNode(),
206 // std::declval<typename std::vector<typename PB::MultiIndex>::iterator>()))
207 );
208};
209
210
211
212// Concept for a LocalView
213template<class GlobalBasis>
214struct LocalView
215{
216 template<class V>
217 auto require(const V& localView) -> decltype(
218 requireType<typename V::size_type>(),
219 requireType<typename V::MultiIndex>(),
220 requireType<typename V::GlobalBasis>(),
221 requireType<typename V::Tree>(),
222 requireType<typename V::GridView>(),
223 requireType<typename V::Element>(),
224 requireSameType<typename V::GlobalBasis, GlobalBasis>(),
225 requireSameType<typename V::GridView, typename GlobalBasis::GridView>(),
226 requireSameType<typename V::size_type, typename GlobalBasis::size_type>(),
227 requireSameType<typename V::Element, typename GlobalBasis::GridView::template Codim<0>::Entity>(),
228 const_cast<V&>(localView).bind(std::declval<typename V::Element>()),
229 const_cast<V&>(localView).unbind(),
230 requireConvertible<typename V::Tree>(localView.tree()),
231 requireConvertible<typename V::size_type>(localView.size()),
232 requireConvertible<typename V::MultiIndex>(localView.index(std::declval<typename V::size_type>())),
233 requireConvertible<typename V::size_type>(localView.maxSize()),
234 requireConvertible<typename V::GlobalBasis>(localView.globalBasis()),
235 requireConcept<BasisTree<typename V::GridView>>(localView.tree()),
236 0
237 );
238};
239
240
241
242// Concept for a GlobalBasis
243template<class GridView>
244struct GlobalBasis
245{
246 template<class B>
247 auto require(const B& basis) -> decltype(
248 requireType<typename B::GridView>(),
249 requireType<typename B::size_type>(),
250 requireType<typename B::MultiIndex>(),
251 requireType<typename B::SizePrefix>(),
252 requireType<typename B::LocalView>(),
253 requireSameType<typename B::GridView, GridView>(),
254 requireConvertible<typename B::GridView>(basis.gridView()),
255 requireConvertible<typename B::LocalView>(basis.localView()),
256 requireConvertible<typename B::size_type>(basis.size()),
257 requireConvertible<typename B::size_type>(basis.size(std::declval<typename B::SizePrefix>())),
258 requireConvertible<typename B::size_type>(basis.dimension()),
259 requireSameType<decltype(const_cast<B&>(basis).update(basis.gridView())),void>(),
260 requireConcept<LocalView<B>>(basis.localView())
261 );
262};
263
264
265
266} // namespace Dune::Functions::Concept
267} // namespace Dune::Functions
268} // namespace Dune
269
270
271#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_CONCEPTS_HH
Grid view abstract base class.
Definition: gridview.hh:63
Infrastructure for concepts.
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:182
Namespace for concepts.
Definition: concept.hh:32
Dune namespace.
Definition: alignedallocator.hh:11
Base class for refined concepts.
Definition: concept.hh:52
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)