Debian Codegraph @

dune/localfunctions/common/interface.hh

raw
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6 #ifndef DUNE_LOCALFUNCTIONS_INTERFACE_HH
7 #define DUNE_LOCALFUNCTIONS_INTERFACE_HH
8
9 #ifndef HEADERCHECK
10 #error This header exists for documentation purposes only and should never be included directly.
11 #endif
12
13 #include <array>
14 #include <cstddef>
15 #include <vector>
16
17
18 #include <dune/geometry/type.hh>
19
20 #include <dune/localfunctions/common/localkey.hh>
21
22 namespace Dune {
23
24 //! Interface for global-valued finite elements
25 class FiniteElementInterface
26 {
27 struct ImplementationDefined;
28
29 public:
30 //! types of component objects
31 /**
32 * \note This may be a typedef instead of a member class.
33 */
34 struct Traits
35 {
36 //! type of the Basis
37 /**
38 * Should be an implementation of BasisInterface
39 *
40 * \note May be an inline class instead of a typedef.
41 */
42 typedef ImplementationDefined Basis;
43 //! type of the Coefficients
44 /**
45 * Should be an implementation of CoefficientsInterface
46 *
47 * \note May be an inline class instead of a typedef.
48 */
49 typedef ImplementationDefined Coefficients;
50 //! type of the Interpolation
51 /**
52 * Should be an implementation of InterpolationInterface
53 *
54 * \note May be an inline class instead of a typedef.
55 */
56 typedef ImplementationDefined Interpolation;
57 };
58
59 //! Construct a finite element
60 /**
61 * \note The arguments of the constructor are implementation specific. In
62 * fact, finite element implementations are not required to be
63 * constructible by the user at all (except for copy-construction).
64 * The official way to construct a finite element is to use its
65 * factory.
66 */
67 FiniteElementInterface(...);
68 //! Finite elements are CopyConstructible
69 FiniteElementInterface(const FiniteElementInterface&);
70
71 //! Extract basis of this finite element
72 /**
73 * The returned lvalue must have a lifetime at least as long as the finite
74 * element object it was acquired from.
75 */
76 const Traits::Basis& basis() const;
77 //! Extract coefficients of this finite element
78 /**
79 * The returned lvalue must have a lifetime at least as long as the finite
80 * element object it was acquired from.
81 */
82 const Traits::Coefficients& coefficients() const;
83 //! Extract interpolation of this finite element
84 /**
85 * The returned lvalue must have a lifetime at least as long as the finite
86 * element object it was acquired from.
87 */
88 const Traits::Interpolation& interpolation() const;
89 //! Extract geometry type of this finite element
90 GeometryType type() const;
91 };
92
93 //! Factory interface for global-valued finite elements
94 /**
95 * The main purpose of the factory class is to provide a concept for
96 * caching. Take for instance a global-valued finite element that wraps a
97 * local finite element. The local finite element will typically have very
98 * few variants, and the global-valued finite element will just apply a
99 * geometric transformation to the derivatives. The wrapped local finite
100 * elements can be stored inside the factory and any global-valued finite
101 * elements created by the factory just contain references or pointers.
102 * This way the local finite elements don't need to be created anew for each
103 * global-valued finite element.
104 *
105 * The other purpose is to semi-standardize the interface used to actually
106 * create finite elements. "Semi" because the information needed to create
107 * an actual global-valued finite element will vary between finite element
108 * types. There are however certain types of information that are needed by
109 * a larger subset of all available finite elements, so it makes sense to
110 * define a common encoding for these types of information. On the other
111 * hand this information is often expensive to obtain, so it makes sense to
112 * only provide it when it is actually needed.
113 */
114 template<class Geometry, class VertexOrder>
115 class FiniteElementFactoryInterface
116 {
117 struct ImplementationDefined;
118
119 public:
120 //! Type of the finite element
121 /**
122 * Should be an implementation of FiniteElementInterface
123 *
124 * \note May be an inline class instead of a typedef.
125 */
126 typedef ImplementationDefined FiniteElement;
127
128 //! Construct a finite element factory
129 /**
130 * \note The arguments of the constructor are implementation specific.
131 */
132 FiniteElementFactoryInterface(...);
133
134 /** \name Finite element creation methods
135 *
136 * Each finite element factory implementation must provide at least one of
137 * these methods. The signatures may be extended by additional
138 * parameters, but the parameters that are specified here should be given
139 * first and in the order specified here.
140 *
141 * The return value of these functions is suitable for binding to a const
142 * reference -- it will either be an rvalue (in which case binding to a
143 * const reference will create a copy whose lifetime is the same as the
144 * reference itself), or it will be an lvalue (in which case the factory
145 * must guarantee that it will be valid until the factory is destroyed or
146 * something else happens that explicitly invalidates all created finite
147 * elements).
148 *
149 * In any case, since global-valued finite element objects are
150 * copy-constructible, it is also possible to use the returned value to
151 * initialize a finite element object instead of a const reference.
152 */
153 //! \{
154
155 //! create a finite element from a geometry and a vertex ordering
156 const FiniteElement make(const Geometry&, const VertexOrder&, ...);
157 //! create a finite element from a geometry
158 const FiniteElement make(const Geometry&, ...);
159 //! create a finite element from a vertex ordering
160 const FiniteElement make(const VertexOrder&, ...);
161 //! create a finite element from a geometry type
162 /**
163 * \note This signature should only be used when only the geometry type
164 * but not the full geometry or vertex ordering are needed.
165 */
166 const FiniteElement make(const GeometryType&, ...);
167 //! create a finite element
168 const FiniteElement make(...);
169
170 //! \}
171
172 };
173
174 //! Interface for global-valued shape functions
175 class BasisInterface
176 {
177 struct ImplementationDefined;
178 constexpr static int implementationDefined = 42;
179
180 public:
181 //! types of domain and range
182 /**
183 * \nosubgrouping
184 *
185 * \note This may be a typedef instead of a member class.
186 */
187 struct Traits
188 {
189 //! \name Domain properties (local and global)
190 //! \{
191
192 //! Field type of the domain
193 typedef ImplementationDefined DomainFieldType;
194
195 //! \brief dimension of the domain
196 constexpr static int dimDomain = implementationDefined;
197
198 //! Type used for coordinate vectors in the domain
199 typedef ImplementationDefined DomainType;
200
201 //! \}
202
203 //! \name Range properties (global range only)
204 //! \{
205
206 //! Field type of the range
207 typedef ImplementationDefined RangeFieldType;
208
209 //! \brief dimension of the range
210 constexpr static int dimRange = implementationDefined;
211
212 //! Type used for range values
213 typedef ImplementationDefined RangeType;
214
215 //! \}
216
217 //! Jacobian properties
218 /**
219 * \note The Jacobian should be some matrix type with \c dimRange x
220 * \c dimDomain components of type \c RangeFieldType.
221 */
222 typedef ImplementationDefined Jacobian;
223 };
224
225 //! Number of shape functions
226 std::size_t size () const;
227 //! Polynomial order of the shape functions for quadrature
228 std::size_t order () const;
229
230 //! Evaluate all shape functions at given position
231 void evaluateFunction(const Traits::DomainType& in,
232 std::vector<Traits::RangeType>& out) const;
233
234 //! Evaluate Jacobian of all shape functions at given position
235 void evaluateJacobian(const Traits::DomainType& in,
236 std::vector<Traits::Jacobian>& out) const;
237
238 /** \brief Evaluate partial derivatives of any order of all shape functions
239 * \param order Order of the partial derivatives, in the classic multi-index notation
240 * \param in Position where to evaluate the derivatives
241 * \param[out] out Return value: the desired partial derivatives
242 */
243 void partial(const std::array<unsigned int,Traits::dimDomain>& order,
244 const typename Traits::DomainType& in,
245 std::vector<typename Traits::RangeType>& out) const;
246 };
247
248 //! Interface for global-valued interpolation
249 struct InterpolationInterface
250 {
251 //! Export basis traits
252 /**
253 * This should be the traits class of the corresponding basis.
254 */
255 typedef BasisInterface::Traits Traits;
256
257 //! Determine coefficients interpolating a given function
258 /**
259 * \param f An object supporting the expression \c f.evaluate(x,y),
260 * where \c x is of type \c Traits::DomainLocal and \c y of the
261 * type \c Traits::Range. When \c f.evaluate(x,y) is
262 * evaluated, \c x will be a local coordinate , and the
263 * expression should set \c y to the function value at that
264 * position. The initial value of \c y should not be used.
265 * \param out Vector where to store the interpolated coefficients.
266 */
267 template<typename F, typename C>
268 void interpolate (const F& f, std::vector<C>& out) const;
269 };
270
271 //! Interface for global-valued coefficients
272 /**
273 * \note This interface is listed separately only to keep it together with
274 * the other global-valued interfaces. It is identical to the
275 * interface for local coefficients.
276 */
277 struct CoefficientsInterface
278 {
279 //! number of coefficients
280 std::size_t size() const;
281
282 //! get i'th index
283 const LocalKey& localKey(std::size_t i) const;
284 };
285 }
286 #endif // DUNE_LOCALFUNCTIONS_INTERFACE_HH