dune-fem 2.8.0
Loading...
Searching...
No Matches
functionspace.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_FUNCTIONSPACE_HH
2#define DUNE_FEM_FUNCTIONSPACE_HH
3
4#include <dune/common/fmatrix.hh>
5#include <dune/common/fvector.hh>
6
7#include <dune/geometry/dimension.hh>
8
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16
17 // Forward declaration of
18 // base class for vector valued function spaces.
19 template< class DomainField, class RangeField, int dimD, int dimR>
20 class FunctionSpace;
21
23 template< class DomainField, class RangeField, int dimD, int dimR>
25 {
27 typedef DomainField DomainFieldType;
29 typedef RangeField RangeFieldType;
30
32 enum { dimDomain = dimD };
34 enum { dimRange = dimR };
35
37 typedef FieldVector< DomainFieldType, dimDomain > DomainType;
38
40 typedef FieldVector< RangeFieldType, dimRange> RangeType;
41
43 typedef FieldMatrix< RangeFieldType, dimRange, dimDomain > LinearMappingType;
44
48 };
49
56 template< class DomainField, class RangeField, int dimD, int dimR>
59 < VectorSpaceTraits< DomainField, RangeField, dimD, dimR> >
60 {
62
63 public:
65 };
66
67 /* Forward declaration of
68 base class for matrix valued function spaces.
69 */
70 template <typename DomainFieldImp,typename RangeFieldImp,int n,int m1,int m2>
72
76 template <typename K,int n,int m>
77 class RangeMatrix : public FieldMatrix<K,n,m> {
78 public:
79 typedef FieldMatrix<K,n,m> BaseType;
80 typedef typename BaseType::row_type RowType;
81 enum {
83 rows = BaseType::rows,
85 cols = BaseType::cols,
87 dimension = BaseType::rows*BaseType::cols
88 };
89 //===== constructors
93
96 RangeMatrix (const K& k) : BaseType(k) {}
97
103 K& operator()(int r,int c) {
104 return static_cast<BaseType&>(*this)[r][c];
105 }
111 const K operator()(int r,int c) const {
112 return static_cast<const BaseType&>(*this)[r][c];
113 }
118 const RowType& row(int r) const{
119 return static_cast<BaseType&>(*this)[r];
120 }
125 RowType& row(int r){
126 return static_cast<BaseType&>(*this)[r];
127 }
128
133 K& operator[](int i) {
134 int r = i/cols;
135 int c = i%cols;
136 return (*this)(r,c);
137 }
142 const K operator[](int i) const {
143 int r = i/cols;
144 int c = i%cols;
145 return (*this)(r,c);
146 }
147
153 {
154 K ret(0);
155 for (int i=0; i<n; i++)
156 ret += static_cast<BaseType&>(*this)[i] * y[i];
157 return ret;
158 }
159
165 RangeMatrix& axpy (const K& a, const BaseType& y)
166 {
167 for (int i=0; i<n; i++)
168 static_cast<BaseType&>(*this)[i].axpy(a,y[i]);
169 return *this;
170 }
171 };
175 template <typename DomainFieldImp,typename RangeFieldImp,int n,int m1,int m2>
177 public FieldMatrix<RangeFieldImp,m1*m2,n> {
178 // Implement L : VD -> VR where VR is the space of FieldMatrix<RFI,m1,m2>
179 // VD is space of FieldVector<DFT,n>
180 public:
182 typedef DomainFieldImp DomainFieldType;
184 typedef RangeFieldImp RangeFieldType;
188 typedef FieldMatrix<RangeFieldImp,m1*m2,n> BaseType;
189 //===== constructors
195 MatrixMapping (const RangeFieldImp& k) : BaseType(k) {}
196
201 FieldVector<DomainFieldImp,n>& operator[](int i) {
202 return static_cast<BaseType&>(*this)[i];
203 }
208 const FieldVector<DomainFieldImp,n>& operator[](int i) const {
209 return static_cast<const BaseType&>(*this)[i];
210 }
211 };
212
214 template <typename DomainFieldImp,typename RangeFieldImp,int n,int m1,int m2>
217 typedef DomainFieldImp DomainFieldType;
219 typedef RangeFieldImp RangeFieldType;
221 typedef FieldVector<DomainFieldImp, n> DomainType;
229 enum { dimRange = m1 * m2};
231 enum { dimDomain = n };
232 };
233
237 template <typename DomainFieldImp,typename RangeFieldImp,int n,int m1,int m2>
238 class MatrixFunctionSpace : public
239 FunctionSpaceInterface<MatrixSpaceTraits<DomainFieldImp,RangeFieldImp,n,m1,m2> > {};
240
241 // function space converter objects
242 // --------------------------------
243
245 template < class FunctionSpaceImp, int newDimDomain >
247
249 template < class FunctionSpaceImp, int newDimRange >
251
253 template< class DomainFieldImp, class RangeFieldImp, int dimDomain, int dimRange, int newDimDomain >
254 struct ToNewDimDomainFunctionSpace< FunctionSpace< DomainFieldImp, RangeFieldImp, dimDomain, dimRange >, newDimDomain >
255 {
257 };
258
260 template< class DomainFieldImp, class RangeFieldImp, int n, int m1, int m2, int newDimDomain >
261 struct ToNewDimDomainFunctionSpace< MatrixFunctionSpace< DomainFieldImp, RangeFieldImp, n, m1, m2 >, newDimDomain >
262 {
264 };
265
267 template< class DomainFieldImp, class RangeFieldImp, int dimDomain, int dimRange, int newDimRange >
268 struct ToNewDimRangeFunctionSpace< FunctionSpace< DomainFieldImp, RangeFieldImp, dimDomain, dimRange >, newDimRange >
269 {
271 };
272
273
274
275 // GridFunctionSpace
276 // -----------------
277
278 namespace Impl
279 {
280
281 template< class GridPart, class >
282 struct GridFunctionSpace;
283
284 template< class GridPart, class K, int dimRange >
285 struct GridFunctionSpace< GridPart, FunctionSpace< typename GridPart::ctype, K, GridPart::dimensionworld, dimRange > >
286 {
288 };
289
290 template< class GridPart, class K, int rows, int cols >
291 struct GridFunctionSpace< GridPart, MatrixFunctionSpace< typename GridPart::ctype, K, GridPart::dimensionworld, rows, cols > >
292 {
293 typedef MatrixFunctionSpace< typename GridPart::ctype, K, GridPart::dimensionworld, rows, cols > Type;
294 };
295
296 template< class GridPart, class K, int dimRange >
297 struct GridFunctionSpace< GridPart, Dune::FieldVector< K, dimRange > >
298 {
299 typedef FunctionSpace< typename GridPart::ctype, K, GridPart::dimensionworld, dimRange > Type;
300 };
301
302 template< class GridPart, class K, int rows, int cols >
303 struct GridFunctionSpace< GridPart, Dune::FieldMatrix< K, rows, cols > >
304 {
305 typedef MatrixFunctionSpace< typename GridPart::ctype, K, GridPart::dimensionworld, rows, cols > Type;
306 };
307
308 template< class GridPart, int dimRange >
309 struct GridFunctionSpace< GridPart, Dune::Dim< dimRange > >
310 {
311 typedef typename GridFunctionSpace< GridPart, Dune::FieldVector< typename GridPart::ctype, dimRange > >::Type Type;
312 };
313
314 } // namespace Impl
315
316 template< class GridPart, class T >
317 using GridFunctionSpace = typename Impl::GridFunctionSpace< GridPart, T >::Type;
318
319 } // namespace Fem
320
321} // namespace Dune
322
323#endif // #ifndef DUNE_FEM_FUNCTIONSPACE_HH
Definition: bindguard.hh:11
typename Impl::GridFunctionSpace< GridPart, T >::Type GridFunctionSpace
Definition: functionspace.hh:317
A vector valued function space.
Definition: functionspace.hh:60
ThisType FunctionSpaceType
Definition: functionspace.hh:64
Traits class for vector function spaces.
Definition: functionspace.hh:25
@ dimDomain
Definition: functionspace.hh:32
FunctionSpace< DomainFieldType, RangeFieldType, dimDomain, 1 > ScalarFunctionSpaceType
scalar function space type
Definition: functionspace.hh:47
FieldVector< RangeFieldType, dimRange > RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspace.hh:40
RangeField RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspace.hh:29
FieldMatrix< RangeFieldType, dimRange, dimDomain > LinearMappingType
linear mapping type
Definition: functionspace.hh:43
@ dimRange
Definition: functionspace.hh:34
FieldVector< DomainFieldType, dimDomain > DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspace.hh:37
DomainField DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspace.hh:27
A matrix valued function space.
Definition: functionspace.hh:239
RangeType class for matrix valued functions - derived from FieldMatrix but has representation as vect...
Definition: functionspace.hh:77
RangeMatrix & axpy(const K &a, const BaseType &y)
vector space axpy operation
Definition: functionspace.hh:165
FieldMatrix< K, n, m > BaseType
Definition: functionspace.hh:79
const K operator[](int i) const
access i element where row = i/col and column = icol
Definition: functionspace.hh:142
RangeMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: functionspace.hh:96
K operator*(const BaseType &y)
scalar product
Definition: functionspace.hh:152
K & operator()(int r, int c)
access element in row r and column c
Definition: functionspace.hh:103
@ dimension
The total dimension of the matrix space.
Definition: functionspace.hh:87
@ cols
The number of columns.
Definition: functionspace.hh:85
@ rows
The number of rows.
Definition: functionspace.hh:83
RangeMatrix()
Default constructor.
Definition: functionspace.hh:92
RowType & row(int r)
access to row r
Definition: functionspace.hh:125
const RowType & row(int r) const
access to row r
Definition: functionspace.hh:118
BaseType::row_type RowType
Definition: functionspace.hh:80
const K operator()(int r, int c) const
access element in row r and column c
Definition: functionspace.hh:111
K & operator[](int i)
access i element where row = i/col and column = icol
Definition: functionspace.hh:133
JacobianRangeType class for matrix valued functions - derived from FieldMatrix.
Definition: functionspace.hh:177
FieldVector< DomainFieldImp, n > & operator[](int i)
returning reference to row
Definition: functionspace.hh:201
MatrixMapping(const RangeFieldImp &k)
Constructor initializing the whole matrix with a scalar.
Definition: functionspace.hh:195
MatrixMapping()
Default constructor.
Definition: functionspace.hh:192
RangeFieldImp RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspace.hh:184
FieldMatrix< RangeFieldImp, m1 *m2, n > BaseType
type of base class
Definition: functionspace.hh:188
RangeMatrix< RangeFieldImp, m1, m2 > RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspace.hh:186
const FieldVector< DomainFieldImp, n > & operator[](int i) const
returning reference to row
Definition: functionspace.hh:208
DomainFieldImp DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspace.hh:182
Traits class for matrix valued spaces.
Definition: functionspace.hh:215
MatrixFunctionSpace< DomainFieldImp, RangeFieldImp, n, 1, 1 > ScalarFunctionSpaceType
scalar function space type
Definition: functionspace.hh:227
DomainFieldImp DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspace.hh:217
RangeMatrix< RangeFieldImp, m1, m2 > RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspace.hh:223
@ dimRange
Definition: functionspace.hh:229
FieldVector< DomainFieldImp, n > DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspace.hh:221
@ dimDomain
Definition: functionspace.hh:231
MatrixMapping< DomainFieldImp, RangeFieldImp, n, m1, m2 > LinearMappingType
linear mapping type
Definition: functionspace.hh:225
RangeFieldImp RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspace.hh:219
convert functions space to space with new dim domain
Definition: functionspace.hh:246
convert functions space to space with new dim range
Definition: functionspace.hh:250
FunctionSpace< DomainFieldImp, RangeFieldImp, newDimDomain, dimRange > Type
Definition: functionspace.hh:256
MatrixFunctionSpace< DomainFieldImp, RangeFieldImp, newDimDomain, m1, m2 > Type
Definition: functionspace.hh:263
FunctionSpace< DomainFieldImp, RangeFieldImp, dimDomain, newDimRange > Type
Definition: functionspace.hh:270
interface for an arbitrary function space
Definition: functionspaceinterface.hh:40