DUNE PDELab (git)

dunefunctionsgridfunctionspace.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_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSGRIDFUNCTIONSPACE_HH
4#define DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSGRIDFUNCTIONSPACE_HH
5
6#include <cstddef>
7#include <map>
8#include <bitset>
9
12
13#include <dune/typetree/leafnode.hh>
14#include <dune/typetree/compositenode.hh>
15
16#include <dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
17#include <dune/pdelab/gridfunctionspace/dunefunctionslocalfunctionspace.hh>
18#include <dune/pdelab/gridfunctionspace/dunefunctionslfsindexcache.hh>
19
20#include <dune/pdelab/backend/istl/dunefunctions.hh>
21#include <dune/pdelab/backend/istl.hh>
22
23namespace Dune {
24 namespace PDELab {
25
29
30 namespace Experimental {
31
32 // The following code recognizes whether the given VectorBackend (VBE) is an ISTL backend.
33 // If this is the case, then we need to replace it by ISTL::SimpleVectorBackend,
34 // because we cannot handle anything more complicated at the moment.
35 template<typename VBE>
36 VBE* registerDuneFunctionsCompatibleVBE(VBE*);
37
38 template<std::size_t block_size>
39 ISTL::SimpleVectorBackend<(block_size > 0 ? block_size : 1)>* registerDuneFunctionsCompatibleVBE(ISTL::VectorBackend<ISTL::Blocking::none,block_size>*);
40
41 template<typename VBE>
42 using DuneFunctionsCompatibleVBE = std::decay_t<decltype(*registerDuneFunctionsCompatibleVBE(std::declval<VBE*>()))>;
43
56 template<typename DFBasis, typename VBE, typename CE>
58 : public TypeTree::LeafNode
60 , public DataHandleProvider<GridFunctionSpace<DFBasis,VBE,CE> >
61 {
62 using GV = typename DFBasis::GridView;
63
64 template<typename,typename>
65 friend class GridFunctionSpaceBase;
66
67 public:
69
70 struct Traits {
71
72 using GridView = Dune::PDELab::impl::GridView<typename DFBasis::GridView>;
73 using GridViewType = GridView; // DiscreteGridFunction wants this
74 using EntitySet = Dune::PDELab::impl::EntitySet<typename DFBasis::GridView>;
75
76 using size_type = std::size_t;
77 using SizeType = size_type;
78 using ConstraintsType = CE;
79
80 using FiniteElementType = typename DFBasis::LocalView::Tree::FiniteElement; // DiscreteGridFunction wants this
81
82 using Basis = DFBasis;
83
84 // The following code recognizes whether the given VectorBackend (VBE) is an ISTL backend.
85 // If this is the case, then we replace it by ISTL::SimpleVectorBackend,
86 // because we cannot handle anything more complicated at the moment.
87 using Backend = DuneFunctionsCompatibleVBE<VBE>;
88
90 struct FEM
91 {
92 struct Traits
93 {
94 using FiniteElement = typename DFBasis::LocalView::Tree::FiniteElement;
95 using FiniteElementType = FiniteElement;
96 };
97
98 FEM(const std::shared_ptr<DFBasis>& basis)
99 : _basis(basis)
100 {}
101
112 const typename Traits::FiniteElementType& find (const typename GridView::template Codim<0>::Entity& element) const
113 {
114 auto type = element.type();
115 auto mapEntry = geometryTypeToLocalView_.find(type);
116 if (mapEntry == geometryTypeToLocalView_.end())
117 {
118 auto newLocalView = std::make_shared<typename DFBasis::LocalView>(_basis->localView());
119 newLocalView->bind(element);
120 auto insertedLocalView = geometryTypeToLocalView_.insert(std::make_pair(type, newLocalView));
121 return insertedLocalView.first->second->tree().finiteElement();
122 }
123 else
124 {
125 return mapEntry->second->tree().finiteElement();
126 }
127 }
128
129 void update()
130 {
131 geometryTypeToLocalView_.clear();
132 }
133
134 private:
135 const std::shared_ptr<DFBasis> _basis;
136
137 mutable std::map<GeometryType, std::shared_ptr<typename DFBasis::LocalView> > geometryTypeToLocalView_;
138 };
139
140 using FiniteElementMap = FEM;
141 using FiniteElementMapType = FEM;
142
143 };
144
145 using Basis = DFBasis;
146
155 : public TypeTree::LeafNode
156 {
157
158 struct Traits {
159
162
170 using size_type = std::size_t;
171 using SizeType = size_type;
172
173 using DOFIndexAccessor = Dune::PDELab::DefaultDOFIndexAccessor;
174
176 static constexpr MultiIndexOrder ContainerIndexOrder = MultiIndexOrder::Inner2Outer;
177 };
178
179 using DOFIndex = typename Traits::DOFIndex;
180 using ContainerIndex = typename Traits::ContainerIndex;
181 using size_type = std::size_t;
182
183
185 : _gfs(gfs)
186 {
187 update();
188 }
189
190 size_type size(ContainerIndex suffix) const
191 {
192 return _gfs.basis().size(suffix);
193 }
194
195 size_type size() const
196 {
197 return _gfs.basis().size();
198 }
199
201 size_type size(const typename DOFIndex::EntityIndex& entity) const
202 {
203 return _containerIndices[entity[0]][entity[1]].size();
204 }
205
206 size_type maxLocalSize() const
207 {
208 return _gfs.basis().localView().maxSize();
209 }
210
213 bool contains(typename Traits::SizeType codim) const
214 {
215 return _contains[codim];
216 }
217
220 bool fixedSize(typename Traits::SizeType codim) const
221 {
222 return _fixedSize[codim];
223 }
224
225 // child_index: Steffen sagt: unklar, im Zweifel einfach ignorieren
226 template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
227 typename Traits::SizeType
228 extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& entityIndex,
229 typename Traits::SizeType child_index,
230 CIOutIterator ci_out, const CIOutIterator ci_end,
231 DIOutIterator dummy) const
232 {
233 for (size_type i=0; i<_containerIndices[entityIndex[0]][entityIndex[1]].size(); i++)
234 {
235 *ci_out = _containerIndices[entityIndex[0]][entityIndex[1]][i];
236 ci_out++;
237 }
238
239 return _containerIndices[entityIndex[0]][entityIndex[1]].size();
240 }
241
242 ContainerIndex containerIndex(const DOFIndex& i) const
243 {
244 return _containerIndices[i.entityIndex()[0]][i.entityIndex()[1]][i.treeIndex()[0]];
245 }
246
247 void update()
248 {
249 _containerIndices.clear();
250
251 constexpr auto dim = GV::dimension;
252 const auto gridView = _gfs.gridView();
253 const auto& indexSet = gridView.indexSet();
254
255 // Count how many dofs there are for each individual entity
256 std::vector<std::vector<size_type> > dofsPerEntity(GlobalGeometryTypeIndex::size(dim));
257 for (size_type codim=0; codim<=dim; codim++)
258 for (auto&& type : indexSet.types(codim))
259 {
260 dofsPerEntity[GlobalGeometryTypeIndex::index(type)].resize(gridView.size(type));
261 std::fill(dofsPerEntity[GlobalGeometryTypeIndex::index(type)].begin(),
262 dofsPerEntity[GlobalGeometryTypeIndex::index(type)].end(), 0);
263 }
264
265 typename DFBasis::LocalView localView = _gfs.basis().localView();
266 for (auto&& element : elements(gridView))
267 {
268 localView.bind(element);
269 const auto refElement = ReferenceElements<typename GV::ctype,dim>::general(element.type());
270
271 const auto& localFiniteElement = localView.tree().finiteElement();
272
273 for (size_type i=0; i<localFiniteElement.size(); i++)
274 {
275 const auto& localKey = localFiniteElement.localCoefficients().localKey(i);
276
277 // Type of the entity that the current local dof is attached to
278 auto subentityTypeIndex = GlobalGeometryTypeIndex::index(refElement.type(localKey.subEntity(), localKey.codim()));
279
280 // Global index of the entity that the current local dof is attached to
281 auto subentityIndex = indexSet.subIndex(element, localKey.subEntity(), localKey.codim());
282
283 dofsPerEntity[subentityTypeIndex][subentityIndex]
284 = std::max(dofsPerEntity[subentityTypeIndex][subentityIndex], (size_type)localKey.index()+1);
285 }
286 }
287
288 // Set up the nested container for the container indices
289 _containerIndices.resize(GlobalGeometryTypeIndex::size(dim));
290
291 for (size_type codim=0; codim<=dim; codim++)
292 for (auto&& type : indexSet.types(codim))
293 {
294 _containerIndices[GlobalGeometryTypeIndex::index(type)].resize(gridView.size(type));
295 for (size_type i=0; i<_containerIndices[GlobalGeometryTypeIndex::index(type)].size(); i++)
296 _containerIndices[GlobalGeometryTypeIndex::index(type)][i].resize(dofsPerEntity[GlobalGeometryTypeIndex::index(type)][i]);
297 }
298
299 // Actually set the container indices for all dofs on all entities
300 for (auto&& element : elements(gridView))
301 {
302 localView.bind(element);
303 const auto refElement = ReferenceElements<typename GV::ctype,dim>::general(element.type());
304
305 const auto& localFiniteElement = localView.tree().finiteElement();
306
307 for (size_type i=0; i<localFiniteElement.size(); i++)
308 {
309 const auto& localKey = localFiniteElement.localCoefficients().localKey(i);
310
311 // Type of the entity that the current local dof is attached to
312 GeometryType subentityType = refElement.type(localKey.subEntity(), localKey.codim());
313
314 // Global index of the entity that the current local dof is attached to
315 auto subentityIndex = indexSet.subIndex(element, localKey.subEntity(), localKey.codim());
316
317 _containerIndices[GlobalGeometryTypeIndex::index(subentityType)][subentityIndex][localKey.index()].set({localView.index(i)});
318 }
319
320 }
321
322 // Precompute for each codimension whether there is at least one entity with degrees of freedom,
323 // and whether all entities have the same number of dofs
324 for (size_type codim=0; codim<=dim; codim++)
325 {
326 _contains[codim] = false;
327 _fixedSize[codim] = true;
328 for (auto&& type : indexSet.types(codim))
329 {
330 const auto& dofs = dofsPerEntity[GlobalGeometryTypeIndex::index(type)];
331
332 if (dofs[0] > 0)
333 _contains[codim] = true;
334
335 for (size_type i=1; i<dofs.size(); i++)
336 {
337 if (dofs[i] > 0)
338 _contains[codim] = true;
339
340 if (dofs[i-1] != dofs[i])
341 _fixedSize[codim] = false;
342 }
343 }
344 }
345 }
346
347 private:
348
349 const GridFunctionSpace& _gfs;
350
351 // Container that contains the ContainerIndices for all dofs, accessible by entities
352 std::vector<std::vector<std::vector<ContainerIndex> > > _containerIndices;
353
357 std::bitset<GV::dimension+1> _contains;
358
361 std::bitset<GV::dimension+1> _fixedSize;
362 };
363
370 struct Ordering
371 : public TypeTree::CompositeNode<LeafOrdering>
372 {
373 friend class LocalFunctionSpace<GridFunctionSpace>;
374
375 using Traits = typename LeafOrdering::Traits;
376
377 static const bool consume_tree_index = false;
378
379 using DOFIndex = typename Traits::DOFIndex;
380 using ContainerIndex = typename Traits::ContainerIndex;
381 using size_type = std::size_t;
382
383 using CacheTag = DuneFunctionsCacheTag;
385
386 Ordering(const GridFunctionSpace& gfs)
388 {}
389
390 size_type size(ContainerIndex suffix) const
391 {
392 return this->child(Indices::_0).size(suffix);
393 }
394
395 size_type size() const
396 {
397 return this->child(Indices::_0).size();
398 }
399
402 size_type blockCount() const
403 {
404 return this->child(Indices::_0).size();
405 }
406
407 size_type maxLocalSize() const
408 {
409 return this->child(Indices::_0).maxLocalSize();
410 }
411
415 bool contains(typename Traits::SizeType codim) const
416 {
417 return this->child(Indices::_0).contains(codim);
418 }
419
422 bool fixedSize(typename Traits::SizeType codim) const
423 {
424 return this->child(Indices::_0).fixedSize(codim);
425 }
426
427 template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
428 typename Traits::SizeType
429 extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
430 typename Traits::SizeType child_index,
431 CIOutIterator ci_out, const CIOutIterator ci_end) const
432 {
433 return 0;
434 }
435
436 void update()
437 {
438 this->child(Indices::_0).update();
439 }
440
441 private:
442
443 ContainerIndex containerIndex(const DOFIndex& i) const
444 {
445 return this->child(Indices::_0).containerIndex(i);
446 }
447
448 };
449
450
452 template<typename E>
454 {
455
457 using Type = std::conditional_t<
458 std::is_same<
459 CE,
460 NoConstraints
461 >::value,
462 EmptyTransformation,
464 >;
465
466 private:
468 };
469
470 // ****************************************************************************************************
471 // Construct from a dune-functions basis
472 // ****************************************************************************************************
473
475 GridFunctionSpace (std::shared_ptr<DFBasis> df_basis, std::shared_ptr<CE> ce)
476 : _es(df_basis->gridView(), Traits::EntitySet::allCodims())
477 , _df_basis(std::move(df_basis))
478 , _finiteElementMap(_df_basis)
479 , _pce(std::move(ce))
480 , _ordering(std::make_shared<Ordering>(*this))
481 {}
482
483 GridFunctionSpace (std::shared_ptr<DFBasis> df_basis)
484 : _es(df_basis->gridView(), Traits::EntitySet::allCodims())
485 , _df_basis(std::move(df_basis))
486 , _finiteElementMap(_df_basis)
487 , _pce(std::make_shared<CE>())
488 , _ordering(std::make_shared<Ordering>(*this))
489 {}
490
492 const typename Traits::GridView& gridView () const
493 {
494 return _es.gridView();
495 }
496
498 const typename Traits::EntitySet& entitySet () const
499 {
500 return _es;
501 }
502
504 const auto& finiteElementMap () const
505 {
506 return _finiteElementMap;
507 }
508
510 const typename Traits::ConstraintsType& constraints () const
511 {
512 return *_pce;
513 }
514
516 std::shared_ptr<const CE> constraintsStorage () const
517 {
518 return _pce;
519 }
520
522 const Ordering& ordering() const
523 {
524 return *_ordering;
525 }
526
527 std::shared_ptr<const Ordering> orderingStorage() const
528 {
529 return _ordering;
530 }
531
532 typename Traits::SizeType size() const
533 {
534 return _ordering->size();
535 }
536
537 typename Traits::SizeType blockCount() const
538 {
539 return _ordering->blockCount();
540 }
541
542 typename Traits::SizeType globalSize() const
543 {
544 return _ordering->size();
545 }
546
547 typename Traits::SizeType maxLocalSize () const
548 {
549 return _ordering->maxLocalSize();
550 }
551
557 void update(bool force = false)
558 {
559 _es.update(force);
560 _df_basis->update(_es.gridView());
561 _finiteElementMap.update();
562 // Apparently there is no need to update the constraints assembler '_pce';
563 _ordering->update();
564 }
565
566 const std::string& name() const
567 {
568 return _name;
569 }
570
571 void name(const std::string& name)
572 {
573 _name = name;
574 }
575
576 bool isRootSpace() const
577 {
578 return true;
579 }
580
581 const Basis& basis() const
582 {
583 return *_df_basis;
584 }
585
586 private:
587
588 typename Traits::EntitySet _es;
589 std::shared_ptr<DFBasis> _df_basis;
590 typename Traits::FiniteElementMap _finiteElementMap;
591 std::shared_ptr<CE const> _pce;
592 std::shared_ptr<Ordering> _ordering;
593 std::string _name;
594 };
595
596 } // namespace Experimental
597
598 } // namespace PDELab
599} // namespace Dune
600
601#endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_DUNEFUNCTIONSGRIDFUNCTIONSPACE_HH
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:138
static constexpr std::size_t size(std::size_t maxdim)
Compute total number of geometry types up to and including the given dimension.
Definition: typeindex.hh:125
a class holding transformation for constrained spaces
Definition: constraintstransformation.hh:20
A multi-index representing a degree of freedom in a GridFunctionSpace.
Definition: dofindex.hh:148
EntityIndex & entityIndex()
Returns the index of the grid entity associated with the DOF.
Definition: dofindex.hh:258
TreeIndex & treeIndex()
Returns the tuple of entity-local indices associated with the DOF.
Definition: dofindex.hh:270
A pdelab grid function space implemented by a dune-functions function space basis.
Definition: dunefunctionsgridfunctionspace.hh:61
Mixin base class for specifying output hints to I/O routines like VTK.
Definition: function.hh:126
A class for representing multi-indices.
Definition: multiindex.hh:29
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:28
Child< k >::Type & child(index_constant< k >={})
Returns the k-th child.
Definition: compositenode.hh:76
Base class for leaf nodes in a dune-typetree.
Definition: leafnode.hh:28
A few common exception classes.
Traits for type conversions and type information.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: indices.hh:52
size_type blockCount() const
Same as size(), because block size is always 1.
Definition: dunefunctionsgridfunctionspace.hh:402
const Ordering & ordering() const
Direct access to the DOF ordering.
Definition: dunefunctionsgridfunctionspace.hh:522
size_type size(const typename DOFIndex::EntityIndex &entity) const
Number of degrees of freedom per entity.
Definition: dunefunctionsgridfunctionspace.hh:201
const Traits::GridView & gridView() const
get grid view
Definition: dunefunctionsgridfunctionspace.hh:492
bool fixedSize(typename Traits::SizeType codim) const
True if for all entities of the given codim the same number of data items has to be communicated.
Definition: dunefunctionsgridfunctionspace.hh:422
bool fixedSize(typename Traits::SizeType codim) const
True if all entities of the given codimension have the same number of dofs.
Definition: dunefunctionsgridfunctionspace.hh:220
const Traits::FiniteElementType & find(const typename GridView::template Codim< 0 >::Entity &element) const
Get local basis functions for entity.
Definition: dunefunctionsgridfunctionspace.hh:112
std::shared_ptr< const CE > constraintsStorage() const
return storage of constraints engine
Definition: dunefunctionsgridfunctionspace.hh:516
const Traits::EntitySet & entitySet() const
get EntitySet
Definition: dunefunctionsgridfunctionspace.hh:498
bool contains(typename Traits::SizeType codim) const
Returns true if there is at least one entity of the given codim for which data needs to be communicat...
Definition: dunefunctionsgridfunctionspace.hh:415
const auto & finiteElementMap() const
get finite element map
Definition: dunefunctionsgridfunctionspace.hh:504
GridFunctionSpace(std::shared_ptr< DFBasis > df_basis, std::shared_ptr< CE > ce)
constructor
Definition: dunefunctionsgridfunctionspace.hh:475
std::conditional_t< std::is_same< CE, NoConstraints >::value, EmptyTransformation, ConstraintsTransformation< typename Ordering::Traits::DOFIndex, typename Ordering::Traits::ContainerIndex, E > > Type
define Type as the Type of a container of E's
Definition: dunefunctionsgridfunctionspace.hh:464
const Traits::ConstraintsType & constraints() const
return constraints engine
Definition: dunefunctionsgridfunctionspace.hh:510
void update(bool force=false)
Update the indexing information of the GridFunctionSpace.
Definition: dunefunctionsgridfunctionspace.hh:557
bool contains(typename Traits::SizeType codim) const
True if there is at least one entity of the given codim that has a dof.
Definition: dunefunctionsgridfunctionspace.hh:213
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
MultiIndexOrder
Information about order semantics on multi-indices.
Definition: utility.hh:32
@ Inner2Outer
indices are ordered from inner to outer container: {inner,...,outer}
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Static tag representing a codimension.
Definition: dimension.hh:24
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
extract type for storing constraints
Definition: dunefunctionsgridfunctionspace.hh:454
The actual Ordering object of the grid function space.
Definition: dunefunctionsgridfunctionspace.hh:156
Root of the ordering tree.
Definition: dunefunctionsgridfunctionspace.hh:372
Rudimentary internal implementation of a FiniteElementMap.
Definition: dunefunctionsgridfunctionspace.hh:91
export Traits class
Definition: dunefunctionsgridfunctionspace.hh:70
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)