KASKADE 7 development version
hierarchicspace.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2023 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef HIERARCHICSPACE_HH
14#define HIERARCHICSPACE_HH
15
16#include <numeric>
17#include <tuple>
18#include <type_traits>
19
20#include "boost/multi_array.hpp"
21
22#include "dune/grid/common/capabilities.hh"
23
24#include "fem/converter.hh"
25#include "fem/firstless.hh"
26#include "fem/fixdune.hh"
27#include "fem/functionspace.hh"
30#include "fem/scalarspace.hh"
31#include "utilities/power.hh"
32#include "utilities/sign.hh"
33
41namespace Kaskade
42{
49 template <class Scalar_, class GV, bool restricted>
51 {
52 public:
53 typedef Scalar_ RT;
54 typedef Scalar_ Scalar;
55 typedef GV GridView;
56 typedef typename GridView::Grid Grid;
57 typedef typename GridView::IndexSet IndexSet;
58 typedef typename Grid::template Codim<0>::Entity Cell;
59
60 public:
61 static constexpr int dim = Grid::dimension;
62
64
70 ord(order), gv(gridView_), is(gridView_.indexSet())
71 {}
72
79 void update()
80 {}
81
87 bool inSupport(Cell const& cell) const
88 {
89 return true;
90 }
91
95 typename IndexSet::IndexType subIndex(Cell const& cell, int subentity, int codim) const
96 {
97 return indexSet().subIndex(cell,subentity,codim);
98 }
99
100
102 {
103 return hierarchicShapeFunctionSet<typename Grid::ctype,dim,Scalar>(Dune::GeometryType(Dune::GeometryType::simplex,Grid::dimension),-1);
104 }
105
106 IndexSet const& indexSet() const { return is; }
107
108 GridView const& gridView() const { return gv; }
109
110
111 size_t size(Dune::GeometryType gt) const
112 {
113 return is.size(gt);
114 }
115
119 int order() const { return ord; }
120
129
139 {
141
142 public:
143 Combiner(GlobalIndices globalIndices, ShapeFunctionSet const& /* sfs */)
144 : s(globalIndices)
145 {}
146
151 template <class Matrix>
152 void rightTransform(Matrix& A) const
153 {
154 for (int j=0; j<A.M(); ++j)
155 if (sign(j)<0)
156 for (int i=0; i<A.N(); ++i)
157 A[i][j] = -A[i][j];
158 }
159
161 template <int n, int m>
162 void rightTransform(std::vector<VariationalArg<Scalar,n,m> >& v) const
163 {
164 for (int i=0; i<v.size(); ++i)
165 if (sign(i)<0)
166 {
167 v[i].value = -v[i].value;
168 v[i].derivative = -v[i].derivative;
169 }
170 }
171
176 template <class Matrix>
177 void leftPseudoInverse(Matrix& A) const
178 {
179 for (int i=0; i<A.N(); ++i)
180 if (sign(i)<0)
181 for (int j=0; j<A.M(); ++j)
182 A[i][j] = - A[i][j];
183 }
184
187 operator Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1>>() const
188 {
189 int n = s.size();
190 Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1> > K(n,n,Dune::BCRSMatrix<Dune::FieldMatrix<Scalar,1,1> >::random);
191 for (int i=0; i<n; ++i)
192 K.incrementrowsize(i);
193 K.endrowsizes();
194 for (int i=0; i<n; ++i)
195 K.addindex(i,i);
196 K.endindices();
197 for (int i=0; i<n; ++i)
198 *K[i].begin() = sign(i);
199 return K;
200 }
201
202 private:
203 // Extracts the sign of dof i
204 int sign(int i) const { return s[i].second().second(); }
205
206 // A view on the dof range, together with signs for ensuring continuity.
207 GlobalIndices s;
208 };
209
210 private:
211 int ord;
212 GridView gv;
213 IndexSet const& is;
214 };
215
216 //---------------------------------------------------------------------
217 //---------------------------------------------------------------------
218
223 template <class Scalar, class GV, bool restricted=false>
225 {
227
228 public:
231 {}
232
233 typename Base::ShapeFunctionSet const& shapeFunctions(typename Base::Cell const& cell, int ordr=0) const
234 {
235 return hierarchicShapeFunctionSet<typename GV::Grid::ctype,GV::Grid::dimension,Scalar>(cell.type(),ord);
236 }
237
238 typename Base::ShapeFunctionSet const& lowerShapeFunctions(typename Base::Cell const& cell) const
239 {
240 return hierarchicShapeFunctionSet<typename GV::Grid::ctype,GV::Grid::dimension,Scalar>(cell.type(),ord-1);
241 }
242
243 private:
244 int ord;
245 };
246
247 //---------------------------------------------------------------------
248
249 template <class ScalarType, class GV>
251 {
253 typedef typename Base::Cell Cell;
254
255 public:
258 {}
259
260 // Returns the number of degrees of freedom (global ansatz
261 // functions) uniquely associated to the given subentity type.
262 int dofOnEntity(Dune::GeometryType gt) const
263 {
264 int n = 0;
265 if (gt.dim() == GV::Grid::dimension) {
266 // dofs live only on codim 0 entities (cells).
267 for (int p=0; p<=this->order(); ++p)
268 n += HierarchicDetail::size(GV::Grid::dimension,p);
269 }
270
271 return n;
272 }
273
274 template <class Cell, class ShapeFunction, class Data>
275 void entityIndex(Cell const& cell, ShapeFunction const& /*sf*/, int n,
276 Dune::GeometryType& gt, int& subentity, int& codim, int& indexInSubentity, Data& data) const
277 {
278 codim = 0;
279 gt = cell.type();
280 subentity = 0;
281 indexInSubentity = n;
282 //sign = 1;
283 }
284
285 };
286
287
295 template <class Scalar, class GV>
297 public UniformScalarMapper<DiscontinuousHierarchicMapperImplementation<Scalar,GV>,boost::compressed_pair<bool,int> >
298 {
302 public:
303 typedef GV GridView;
305 static int const continuity = -1;
306
307 template <int m>
309
310 template <int m>
311 struct [[deprecated]] Element
312 {
314 };
315
316
319 {}
320 };
321
322 //---------------------------------------------------------------------
323
324 template <class Scalar, class GV, class ShapeFunctionFilter=ScalarSpaceDetail::AllShapeFunctions>
325 class ContinuousHierarchicMapperImplementation: public HierarchicMapperImplementation<Scalar,GV,ScalarSpaceDetail::isRestriction<ShapeFunctionFilter>()>, public ShapeFunctionFilter
326 {
328 typedef typename Base::Cell Cell;
329 static constexpr int dim = GV::dimension;
330
331 public:
332 ContinuousHierarchicMapperImplementation(GV const& gridView, int order, ShapeFunctionFilter shapeFunctionFilter = ShapeFunctionFilter()):
333 Base(gridView,order), ShapeFunctionFilter(shapeFunctionFilter)
334 {}
335
336 // Returns the number of degrees of freedom (global ansatz
337 // functions) uniquely associated to the given subentity type.s
338 int dofOnEntity(Dune::GeometryType gt) const
339 {
340 using namespace HierarchicDetail;
341
342 int codim = GV::Grid::dimension-gt.dim();
343
344 int n = 0;
345 for (int p=0; p<=this->order(); ++p)
346 n += cdimSize(GV::Grid::dimension,p,codim) / nSubentities(GV::Grid::dimension,codim);
347
348 return n;
349 }
350
351 template <class Cell, class ShapeFunction, class Data>
352 void entityIndex(Cell const& cell, ShapeFunction const& sf, int n,
353 Dune::GeometryType& gt, int& subentity, int& codim, int& indexInSubentity, Data& data) const
354 {
355 using namespace HierarchicDetail;
356 typename Base::IndexSet const& is = this->indexSet();
357
358 // Compute global ids of cell vertices.
359 int vIds[dim+1];
360 vertexids(dim,0,0,vIds);
361 for (int j=0; j<=dim; ++j)
362 vIds[j] = this->indexSet().subIndex(cell,j,dim);
363
364 int p, k;
365 std::tie(p,codim,subentity,k) = sf.location();
366 gt = is.types(codim)[0]; // limited to just one geometry type....
367
368 // Compute tuple index corresponding to vertex permutation.
369 std::tie(k,data.second()) = sfPermutation(dim,p,codim,subentity,k,vIds);
370
371 // Compute index in subentity taking all preceding lower order
372 // shapefunctions into account.
373 indexInSubentity = 0;
374 for (int o=0; o<p; ++o)
375 indexInSubentity += cdimSize(dim,o,codim)/nSubentities(dim,codim);
376 indexInSubentity += k;
377
378 // consider restrictions to the boundary here
379 this->treatBoundary(data,this->gridView(),cell,codim,subentity);
380 }
381 };
382
383
391 template <class Scalar, class GV>
393 public UniformScalarMapper<ContinuousHierarchicMapperImplementation<Scalar,GV>,boost::compressed_pair<bool,int> >
394 {
398
399 public:
400 typedef GV GridView;
402 static int const continuity = 0;
403
404 template <int m>
406
407 template <int m>
408 struct [[deprecated]] Element
409 {
411 };
412
414 : Base(Implementation(gridView,order)) {
415 assert(order >= 0);
416 }
417 };
418
419 //---------------------------------------------------------------------
420 //---------------------------------------------------------------------
421 //---------------------------------------------------------------------
422
423 template <class Scalar, class GV, bool restricted=false>
425 {
427
428 public:
431 {}
432
433 typename Base::ShapeFunctionSet const& shapeFunctions(typename Base::Cell const& cell,int ordr=0) const
434 {
435 return hierarchicExtensionShapeFunctionSet<typename GV::Grid::ctype,GV::Grid::dimension,Scalar>(cell.type(),this->order());
436 }
437
438 typename Base::ShapeFunctionSet const& lowerShapeFunctions(typename Base::Cell const& cell) const
439 {
440 return hierarchicExtensionShapeFunctionSet<typename GV::Grid::ctype,GV::Grid::dimension,Scalar>(cell.type(),-1);
441 }
442 };
443
444
445 template <class Scalar, class GV>
448 {
450 typedef typename Base::Cell Cell;
451
452 public:
455 {}
456
457 // Returns the number of degrees of freedom (global ansatz
458 // functions) uniquely associated to the given subentity type.
459 int dofOnEntity(Dune::GeometryType gt) const
460 {
461 // dofs live only on codim 0 entities (cells).
462 return gt.dim()==GV::Grid::dimension? HierarchicDetail::size(GV::Grid::dimension,this->order()): 0;
463 }
464
465 template <class Cell, class ShapeFunction, class Data>
466 void entityIndex(Cell const& cell, ShapeFunction const& /*sf*/, int n,
467 Dune::GeometryType& gt, int& subentity, int& codim, int& indexInSubentity, Data& data) const
468 {
469 codim = 0;
470 gt = cell.type();
471 subentity = 0;
472 indexInSubentity = n;
473 //sign = 1;
474 }
475
476 };
477
478
486 template <class Scalar, class GV>
488 public UniformScalarMapper<DiscontinuousHierarchicExtensionMapperImplementation<Scalar,GV>,boost::compressed_pair<bool,int> >
489 {
493 public:
494
495 typedef GV GridView;
498 static int const continuity = -1;
499
500 template <int m>
501 struct Element
502 {
504 };
505
506
509 {}
510 };
511
512 //---------------------------------------------------------------------
513
514 template <class Scalar, class GV, class ShapeFunctionFilter = ScalarSpaceDetail::AllShapeFunctions>
516 : public HierarchicExtensionMapperImplementation<Scalar,GV,ScalarSpaceDetail::isRestriction<ShapeFunctionFilter>()>, public ShapeFunctionFilter
517 {
519 typedef typename Base::Cell Cell;
520
521 public:
522 ContinuousHierarchicExtensionMapperImplementation(GV const& gridView, int order, ShapeFunctionFilter shapeFunctionFilter = ShapeFunctionFilter()):
523 Base(gridView,order), ShapeFunctionFilter(shapeFunctionFilter)
524 {}
525
526 // Returns the number of degrees of freedom (global ansatz
527 // functions) uniquely associated to the given subentity type.
528 int dofOnEntity(Dune::GeometryType gt) const
529 {
530// std::cerr << " ContinuousHierarchicExtensionMapperImplementation::dofOnEntity\n";
531 using namespace HierarchicDetail;
532
533 int codim = GV::Grid::dimension-gt.dim();
534 return cdimSize(GV::Grid::dimension,this->order(),codim) / nSubentities(GV::Grid::dimension,codim);
535 }
536
537 template <class Cell, class ShapeFunction, class Data>
538 void entityIndex(Cell const& cell, ShapeFunction const& sf, int n,
539 Dune::GeometryType& gt, int& subentity, int& codim, int& indexInSubentity, Data& data) const
540 {
541 using namespace HierarchicDetail;
542
543 // Compute global ids of cell vertices.
544 int const d = Cell::dimension;
545 int vIds[d+1];
546 vertexids(d,0,0,vIds);
547 for (int j=0; j<=d; ++j)
548 vIds[j] = this->indexSet().subIndex(cell,j,d);
549
550 int nominalOrder, k;
551 std::tie(nominalOrder,codim,subentity,k) = sf.location();
552 gt = this->indexSet().types(codim)[0]; // limited to just one geometry type....
553
554 // Compute tuple index corresponding to vertex permutation.
555 std::tie(indexInSubentity,data.second()) = sfPermutation(d,nominalOrder,codim,subentity,k,vIds);
556
557 // consider restrictions to the boundary here
558 this->treatBoundary(data,this->gridView(),cell,codim,subentity);
559 }
560 };
561
562
570 template <class Scalar, class GV>
572 public UniformScalarMapper<ContinuousHierarchicExtensionMapperImplementation<Scalar,GV>,boost::compressed_pair<bool,int>>
573 {
577
578 public:
579 typedef GV GridView;
582 static int const continuity = 0;
583
584 template <int m>
585 struct Element
586 {
588 };
589
592 {
593 assert(order >= 0);
594 }
595 };
596
597} // End of namespace Kaskade
598
599//-------------------------------------------------------------------
600
601#endif
A degrees of freedom manager for globally continuous FEFunctionSpace s of piecewise polynomials.
ContinuousHierarchicExtensionMapper(GridView const &gridView, int order)
HierarchicSimplexShapeFunctionSet< typename GridView::Grid::ctype, GridView::Grid::dimension, Scalar > ShapeFunctionSetImplementation
void entityIndex(Cell const &cell, ShapeFunction const &sf, int n, Dune::GeometryType &gt, int &subentity, int &codim, int &indexInSubentity, Data &data) const
ContinuousHierarchicExtensionMapperImplementation(GV const &gridView, int order, ShapeFunctionFilter shapeFunctionFilter=ShapeFunctionFilter())
A degrees of freedom manager for globally continuous FEFunctionSpace s of piecewise polynomials.
ContinuousHierarchicMapper(GridView const &gridView, int order)
ContinuousHierarchicMapperImplementation(GV const &gridView, int order, ShapeFunctionFilter shapeFunctionFilter=ShapeFunctionFilter())
int dofOnEntity(Dune::GeometryType gt) const
void entityIndex(Cell const &cell, ShapeFunction const &sf, int n, Dune::GeometryType &gt, int &subentity, int &codim, int &indexInSubentity, Data &data) const
A degrees of freedom manager for FEFunctionSpace s of piecewise polynomials of given order.
HierarchicSimplexShapeFunctionSet< typename GridView::Grid::ctype, GridView::Grid::dimension, Scalar > ShapeFunctionSetImplementation
DiscontinuousHierarchicExtensionMapper(GV const &gridView, int order)
DiscontinuousHierarchicExtensionMapperImplementation(GV const &gridView, int order)
void entityIndex(Cell const &cell, ShapeFunction const &, int n, Dune::GeometryType &gt, int &subentity, int &codim, int &indexInSubentity, Data &data) const
A degrees of freedom manager for FEFunctionSpace s of piecewise polynomials of order Order.
DiscontinuousHierarchicMapper(GridView const &gridView, int order)
DiscontinuousHierarchicMapperImplementation(GV const &gridView, int order)
void entityIndex(Cell const &cell, ShapeFunction const &, int n, Dune::GeometryType &gt, int &subentity, int &codim, int &indexInSubentity, Data &data) const
A class for representing finite element functions.
Base::ShapeFunctionSet const & lowerShapeFunctions(typename Base::Cell const &cell) const
Base::ShapeFunctionSet const & shapeFunctions(typename Base::Cell const &cell, int ordr=0) const
HierarchicExtensionMapperImplementation(GV const &gridView, int order)
void rightTransform(std::vector< VariationalArg< Scalar, n, m > > &v) const
In-place computation of row vectors .
void leftPseudoInverse(Matrix &A) const
In-place computation of .
void rightTransform(Matrix &A) const
In-place computation of .
Combiner(GlobalIndices globalIndices, ShapeFunctionSet const &)
A local to global mapper implementation for scalar hierarchic bases.
HierarchicMapperImplementationBase(GridView const &gridView_, int order)
int order() const
Returns the nominal order of the shape function set.
ShapeFunctionSet const & emptyShapeFunctionSet() const
bool inSupport(Cell const &cell) const
Tells whether the given cell is contained in the support.
ScalarConverter< Cell, Scalar > Converter
size_t size(Dune::GeometryType gt) const
IndexSet::IndexType subIndex(Cell const &cell, int subentity, int codim) const
Returns the index of the specified subentity.
Grid::template Codim< 0 >::Entity Cell
void update()
This is called on grid modifications and can be overwritten if internal data needs to be recomputed o...
HierarchicShapeFunctionSetContainer< typenameGrid::ctype, dim, Scalar, restricted >::value_type ShapeFunctionSet
HierarchicMapperImplementation(GV const &gridView, int order)
Base::ShapeFunctionSet const & shapeFunctions(typename Base::Cell const &cell, int ordr=0) const
Base::ShapeFunctionSet const & lowerShapeFunctions(typename Base::Cell const &cell) const
A container of hierarchic shape functions (see HierarchicSimplexShapeFunction) up to a given nominal ...
DEPRECATED. Use boost::iterator_range instead.
Definition: views.hh:25
size_t size() const
Definition: views.hh:39
A Converter for scalar shape functions that do not change their value under transformation from refer...
Definition: converter.hh:62
virtual std::tuple< int, int, int, int > location() const =0
Returns a tuple (nominalOrder,codim,entity,index) giving detailed information about the location of t...
Base class for uniform scalar local to global mappers.
Definition: scalarspace.hh:205
This file contains various utility functions that augment the basic functionality of Dune.
FEFunctionSpace and FunctionSpaceElement and the like.
define hierarchic shape functions for simplicial elements of arbitrary dimension and order
void vertexids(int d, int c, int k, int *idx)
Computes the d-c+1 local vertex indices of the vertices incident to the k-th subentity of codimension...
FunctionSpaceElement< FEFunctionSpace< Self >, m > type
FunctionSpaceElement< FEFunctionSpace< Self >, m > type
FunctionSpaceElement< FEFunctionSpace< Self >, m > type
FunctionSpaceElement< FEFunctionSpace< Self >, m > type
void treatBoundary(Data &, GridView const &, Cell const &, int, int) const
Definition: scalarspace.hh:162
A class that stores values, gradients, and Hessians of evaluated shape functions.