3#ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALFUNCTIONSPACE_HH
4#define DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALFUNCTIONSPACE_HH
8#include <dune/common/stdstreams.hh>
9#include <dune/common/shared_ptr.hh>
11#include <dune/geometry/referenceelements.hh>
13#include <dune/localfunctions/common/interfaceswitch.hh>
14#include <dune/localfunctions/common/localkey.hh>
16#include <dune/typetree/typetree.hh>
36 template<
typename =
int>
37 struct PropagateGlobalStorageVisitor
38 :
public TypeTree::TreeVisitor
39 ,
public TypeTree::DynamicTraversal
42 template<
typename LFS,
typename Child,
typename TreePath,
typename ChildIndex>
43 void beforeChild(
const LFS& lfs, Child& child, TreePath treePath, ChildIndex childIndex)
const
45 child._dof_indices = lfs._dof_indices;
52 template<
typename =
int>
53 struct ClearSizeVisitor
54 :
public TypeTree::TreeVisitor
55 ,
public TypeTree::DynamicTraversal
58 template<
typename Node,
typename TreePath>
59 void pre(Node& node, TreePath treePath)
64 template<
typename Node,
typename TreePath>
65 void leaf(Node& node, TreePath treePath)
71 ClearSizeVisitor(std::size_t offset_)
80 template<
typename Entity,
bool fast>
81 struct ComputeSizeVisitor
82 :
public TypeTree::TreeVisitor
83 ,
public TypeTree::DynamicTraversal
86 template<
typename Node,
typename TreePath>
87 void pre(Node& node, TreePath treePath)
92 template<
typename Node,
typename TreePath>
93 void post(Node& node, TreePath treePath)
95 node.n =
offset - node.offset;
98 template<
typename Node,
typename TreePath>
99 void leaf(Node& node, TreePath treePath)
103 node._in_entity_set = node.pgfs->entitySet().contains(e);
104 if (not node._in_entity_set) {
107 node.n = node.pgfs->finiteElementMap().maxLocalSize();
108 Node::FESwitch::setStore(node.pfe,
109 node.pgfs->finiteElementMap().find(e));
111 Node::FESwitch::setStore(node.pfe,
112 node.pgfs->finiteElementMap().find(e));
113 node.n = Node::FESwitch::basis(*node.pfe).size();
118 ComputeSizeVisitor(
const Entity& entity, std::size_t offset_ = 0)
129 template<
typename Entity,
bool fast>
130 struct FillIndicesVisitor
131 :
public TypeTree::TreeVisitor
132 ,
public TypeTree::DynamicTraversal
135 template<
typename Node,
typename TreePath>
136 void leaf(Node& node, TreePath treePath)
139 node.dofIndices(e,node._dof_indices->begin()+node.offset,node._dof_indices->begin()+node.offset+node.n,std::integral_constant<bool,fast>{});
142 template<
typename Node,
typename Child,
typename TreePath,
typename ChildIndex>
143 void afterChild(
const Node& node,
const Child& child, TreePath treePath, ChildIndex childIndex)
150 for (std::size_t i = 0; i<child.n; ++i)
153 (*node._dof_indices)[child.offset+i].treeIndex().push_back(childIndex);
157 FillIndicesVisitor(
const Entity& entity)
171 template<
typename GFS,
typename DI>
194 template <
typename GFS,
typename DOFIndex>
197 typedef typename GFS::Traits::Backend B;
202 template<
typename,
bool>
205 template<
typename,
bool>
208 template<
typename LFS,
typename C,
typename Tag,
bool>
223 typename Traits::IndexContainer::size_type
size ()
const
234 typename Traits::IndexContainer::size_type
maxSize ()
const
253 typename Traits::IndexContainer::size_type
localIndex (
typename Traits::IndexContainer::size_type
index)
const
274 std::cout <<
n <<
" indices = (";
275 for (
typename Traits::IndexContainer::size_type k=0; k<
n; k++)
277 std::cout <<
")" << std::endl;
287 template<
typename NodeType>
291 TypeTree::applyToTree(node,PropagateGlobalStorageVisitor<>());
294 std::shared_ptr<GFS const>
pgfs;
297 typename Traits::IndexContainer::size_type
n;
298 typename Traits::IndexContainer::size_type
offset;
302 template<
typename GFS,
typename DOFIndex>
309 typedef typename GFS::Traits::GridViewType
GridView;
317 template <
typename GFS,
typename DOFIndex>
321 typedef typename GFS::Traits::Backend B;
346 template<
typename NodeType,
bool fast = false>
347 void bind (NodeType& node,
const typename Traits::Element& e, std::integral_constant<bool,fast> = std::integral_constant<bool,fast>{});
350 template <
typename GFS,
typename DOFIndex>
351 template <
typename NodeType,
bool fast>
354 std::integral_constant<bool,fast>)
357 assert(&node ==
this);
360 ComputeSizeVisitor<Element,fast> csv(e);
361 TypeTree::applyToTree(node,csv);
365 FillIndicesVisitor<Element,fast> fiv(e);
366 TypeTree::applyToTree(node,fiv);
374 template<
typename GFS,
typename DOFIndex,
typename N>
382 template<
typename GFS,
typename DOFIndex,
typename ChildLFS, std::
size_t k>
385 public TypeTree::PowerNode<ChildLFS,k>
388 typedef TypeTree::PowerNode<ChildLFS,k> TreeNode;
396 template<
typename,
bool>
399 template<
typename,
bool>
408 template<
typename Transformation>
410 const Transformation& t,
411 const std::array<std::shared_ptr<ChildLFS>,k>& children)
416 template<
typename Transformation>
418 const Transformation& t,
419 const std::array<std::shared_ptr<ChildLFS>,k>& children)
420 :
BaseT(stackobject_to_shared_ptr(gfs))
425 template<
bool fast = false>
426 void bind (
const typename Traits::Element& e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
436 template<
typename SourceNode,
typename Transformation>
439 template<
typename TC>
447 template<
typename PowerGr
idFunctionSpace,
typename Params>
448 TypeTree::TemplatizedGenericPowerNodeTransformation<
461 template<
typename GFS,
typename DOFIndex,
typename... Children>
464 ,
public TypeTree::CompositeNode<Children...>
467 typedef TypeTree::CompositeNode<Children...> NodeType;
475 template<
typename,
bool>
478 template<
typename,
bool>
486 template<
typename Transformation>
488 const Transformation& t,
489 std::shared_ptr<Children>... children)
491 , NodeType(children...)
494 template<
typename Transformation>
496 const Transformation& t,
497 std::shared_ptr<Children>... children)
498 :
BaseT(stackobject_to_shared_ptr(gfs))
499 , NodeType(children...)
503 template<
bool fast = false>
504 void bind (
const typename Traits::Element& e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
513 template<
typename SourceNode,
typename Transformation>
516 template<
typename... TC>
524 template<
typename CompositeGr
idFunctionSpace,
typename Params>
525 TypeTree::TemplatizedGenericCompositeNodeTransformation<
538 template<
typename GFS,
typename DOFIndex,
typename N>
554 template<
typename GFS,
typename DOFIndex>
557 ,
public TypeTree::LeafNode
567 template<
typename,
bool>
570 template<
typename,
bool>
579 typedef FiniteElementInterfaceSwitch<
586 template<
typename Transformation>
592 template<
typename Transformation>
594 :
BaseT(stackobject_to_shared_ptr(gfs))
601 assert((_in_entity_set &&
pfe) &&
602 "Local function spaces outside their entity set should not "
603 "request `finiteElement()`. To check if function has support "
604 "use: `size()!= 0`");
612 return this->
pgfs->constraints();
616 template<
typename Entity,
typename DOFIndexIterator,
bool fast>
617 void dofIndices(
const Entity& e, DOFIndexIterator it, DOFIndexIterator endit, std::integral_constant<bool,fast>)
619 using EntitySet =
typename GFS::Traits::EntitySet;
622 if (not es.contains(e))
626 auto index = es.indexSet().index(e);
627 GFS::Ordering::Traits::DOFIndexAccessor::store(*it, gt,
index, 0);
631 const typename FESwitch::Coefficients &coeffs =
632 FESwitch::coefficients(*
pfe);
635 Dune::ReferenceElements<double, EntitySet::dimension>::general(
638 for (std::size_t i = 0; i < std::size_t(coeffs.size()); ++i, ++it) {
640 auto gt = refEl.type(coeffs.localKey(i).subEntity(),
641 coeffs.localKey(i).codim());
644 auto index = es.indexSet().subIndex(
645 e, coeffs.localKey(i).subEntity(), coeffs.localKey(i).codim());
648 GFS::Ordering::Traits::DOFIndexAccessor::store(
649 *it, gt,
index, coeffs.localKey(i).index());
658 template<
typename GC,
typename LC>
662 typedef typename LC::const_iterator local_col_iterator;
663 typedef typename LC::value_type::second_type::const_iterator local_row_iterator;
664 typedef typename GC::iterator global_col_iterator;
665 typedef typename GC::value_type::second_type global_row_type;
667 for (local_col_iterator cit=lc.begin(); cit!=lc.end(); ++cit)
671 global_col_iterator gcit = gc.insert(std::make_pair(std::ref(this->
dofIndex(cit->first)),global_row_type())).first;
674 for (local_row_iterator rit=(cit->second).begin(); rit!=(cit->second).end(); ++rit)
675 gcit->second[this->
dofIndex(rit->first)] = rit->second;
680 template<
bool fast = false>
681 void bind (
const typename Traits::Element& e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
688 typename FESwitch::Store
pfe;
694 template<
typename Gr
idFunctionSpace,
typename Params>
695 TypeTree::GenericLeafNodeTransformation<
706 template <
typename GFS,
typename TAG=AnySpaceTag>
722 template <
typename GFS,
typename TAG>
724 public TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type
726 typedef typename TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type BaseT;
727 typedef typename BaseT::Traits::IndexContainer::size_type I;
728 typedef typename BaseT::Traits::IndexContainer::size_type LocalIndex;
746 : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform(gfs))
763 return LocalIndex(BaseT::localIndex(
index));
769 void getChild ()
const;
777 template <
typename GFS>
779 public TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type
781 typedef typename TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type BaseT;
789 template<
typename,
bool>
792 template<
typename,
bool>
798 : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform(gfs))
805 : BaseT(*TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform_storage(
pgfs))
std::size_t index
Definition: interpolate.hh:97
const std::size_t offset
Definition: localfunctionspace.hh:75
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::TypeTree::GenericLeafNodeTransformation< LeafNode, GridFunctionToLocalViewTransformation, Imp::LocalGridViewFunctionAdapter< LeafNode > > registerNodeTransformation(LeafNode *l, GridFunctionToLocalViewTransformation *t, GridFunctionTag *tag)
A multi-index representing a degree of freedom in a GridFunctionSpace.
Definition: dofindex.hh:148
base class for tuples of grid function spaces base class that holds implementation of the methods thi...
Definition: compositegridfunctionspace.hh:53
A grid function space.
Definition: gridfunctionspace.hh:191
Definition: lfsindexcache.hh:245
traits mapping global function space information to local function space
Definition: localfunctionspace.hh:173
GFS GridFunctionSpace
Type of the underlying grid function space.
Definition: localfunctionspace.hh:178
std::vector< SizeType > IndexContainer
Type of container to store indices.
Definition: localfunctionspace.hh:184
GFS::Traits::SizeType SizeType
Type to store indices from Backend.
Definition: localfunctionspace.hh:181
GFS GridFunctionSpaceType
Type of the underlying grid function space.
Definition: localfunctionspace.hh:175
DI DOFIndex
Type of MultiIndex associated with this LocalFunctionSpace.
Definition: localfunctionspace.hh:187
std::vector< DI > DOFIndexContainer
Type of container to store multiindices.
Definition: localfunctionspace.hh:190
Definition: localfunctionspace.hh:196
const GFS & gridFunctionSpace() const
Returns the GridFunctionSpace underlying this LocalFunctionSpace.
Definition: localfunctionspace.hh:281
friend struct ComputeSizeVisitor
Definition: localfunctionspace.hh:203
Traits::DOFIndexContainer _dof_index_storage
Definition: localfunctionspace.hh:295
LocalFunctionSpaceBaseTraits< GFS, DOFIndex > Traits
Definition: localfunctionspace.hh:212
Traits::IndexContainer::size_type localVectorSize() const
get size of an appropriate local vector object
Definition: localfunctionspace.hh:247
Traits::IndexContainer::size_type n
Definition: localfunctionspace.hh:297
friend struct FillIndicesVisitor
Definition: localfunctionspace.hh:206
Traits::IndexContainer::size_type offset
Definition: localfunctionspace.hh:298
void debug() const
print debug information about this local function space
Definition: localfunctionspace.hh:272
Traits::DOFIndexContainer * _dof_indices
Definition: localfunctionspace.hh:296
Traits::IndexContainer::size_type maxSize() const
get maximum possible size (which is maxLocalSize from grid function space)
Definition: localfunctionspace.hh:234
Traits::IndexContainer::size_type localIndex(typename Traits::IndexContainer::size_type index) const
map index in this local function space to root local function space
Definition: localfunctionspace.hh:253
LocalFunctionSpaceBaseNode(std::shared_ptr< const GFS > gfs)
construct from global function space
Definition: localfunctionspace.hh:215
void setup(NodeType &node)
Definition: localfunctionspace.hh:288
std::shared_ptr< GFS const > pgfs
Definition: localfunctionspace.hh:294
Traits::IndexContainer::size_type size() const
number of degrees of freedom contained in this lfs node
Definition: localfunctionspace.hh:223
const Traits::DOFIndex & dofIndex(typename Traits::IndexContainer::size_type index) const
Maps given index in this local function space to its corresponding global MultiIndex.
Definition: localfunctionspace.hh:266
friend struct PropagateGlobalStorageVisitor
Definition: localfunctionspace.hh:200
std::size_t subSpaceDepth() const
Definition: localfunctionspace.hh:228
traits for local function space on a gridview
Definition: localfunctionspace.hh:304
GFS::Traits::GridViewType GridViewType
Type of the grid view that the underlying grid function space is defined on.
Definition: localfunctionspace.hh:306
typename GFS::Traits::EntitySet EntitySet
Definition: localfunctionspace.hh:311
GFS::Traits::GridViewType GridView
Type of the grid view that the underlying grid function space is defined on.
Definition: localfunctionspace.hh:309
typename EntitySet::Element Element
Type of codim 0 entity in the grid.
Definition: localfunctionspace.hh:314
Definition: localfunctionspace.hh:320
GridViewLocalFunctionSpaceBaseTraits< GFS, DOFIndex > Traits
Definition: localfunctionspace.hh:325
void bind(NodeType &node, const typename Traits::Element &e, std::integral_constant< bool, fast >=std::integral_constant< bool, fast >{})
bind local function space to entity
GridViewLocalFunctionSpaceBaseNode(std::shared_ptr< const GFS > gfs)
construct from global function space
Definition: localfunctionspace.hh:328
traits for multi component local function space
Definition: localfunctionspace.hh:376
N NodeType
type of local function space node
Definition: localfunctionspace.hh:378
Definition: localfunctionspace.hh:386
PowerLocalFunctionSpaceNode(std::shared_ptr< const GFS > gfs, const Transformation &t, const std::array< std::shared_ptr< ChildLFS >, k > &children)
initialize with grid function space
Definition: localfunctionspace.hh:409
friend struct ComputeSizeVisitor
Definition: localfunctionspace.hh:397
friend struct ClearSizeVisitor
Definition: localfunctionspace.hh:394
friend struct FillIndicesVisitor
Definition: localfunctionspace.hh:400
PowerLocalFunctionSpaceTag ImplementationTag
Definition: localfunctionspace.hh:405
PowerCompositeLocalFunctionSpaceTraits< GFS, DOFIndex, PowerLocalFunctionSpaceNode > Traits
Definition: localfunctionspace.hh:403
PowerLocalFunctionSpaceNode(const GFS &gfs, const Transformation &t, const std::array< std::shared_ptr< ChildLFS >, k > &children)
Definition: localfunctionspace.hh:417
void bind(const typename Traits::Element &e, std::integral_constant< bool, fast > fast_=std::integral_constant< bool, fast >{})
bind local function space to entity
Definition: localfunctionspace.hh:426
friend struct PropagateGlobalStorageVisitor
Definition: localfunctionspace.hh:391
Definition: localfunctionspace.hh:438
Definition: localfunctionspace.hh:441
PowerLocalFunctionSpaceNode< SourceNode, typename Transformation::DOFIndex, TC, TypeTree::StaticDegree< SourceNode >::value > type
Definition: localfunctionspace.hh:442
Definition: localfunctionspace.hh:465
CompositeLocalFunctionSpaceNode(const GFS &gfs, const Transformation &t, std::shared_ptr< Children >... children)
Definition: localfunctionspace.hh:495
friend struct ComputeSizeVisitor
Definition: localfunctionspace.hh:476
friend struct ClearSizeVisitor
Definition: localfunctionspace.hh:473
void bind(const typename Traits::Element &e, std::integral_constant< bool, fast > fast_=std::integral_constant< bool, fast >{})
bind local function space to entity
Definition: localfunctionspace.hh:504
friend struct FillIndicesVisitor
Definition: localfunctionspace.hh:479
CompositeLocalFunctionSpaceNode(std::shared_ptr< const GFS > gfs, const Transformation &t, std::shared_ptr< Children >... children)
Definition: localfunctionspace.hh:487
PowerCompositeLocalFunctionSpaceTraits< GFS, DOFIndex, CompositeLocalFunctionSpaceNode > Traits
Definition: localfunctionspace.hh:482
CompositeLocalFunctionSpaceTag ImplementationTag
Definition: localfunctionspace.hh:484
friend struct PropagateGlobalStorageVisitor
Definition: localfunctionspace.hh:470
Definition: localfunctionspace.hh:515
Definition: localfunctionspace.hh:518
CompositeLocalFunctionSpaceNode< SourceNode, typename Transformation::DOFIndex, TC... > type
Definition: localfunctionspace.hh:519
traits for single component local function space
Definition: localfunctionspace.hh:540
GFS::Traits::FiniteElementType FiniteElement
Definition: localfunctionspace.hh:544
GFS::Traits::ConstraintsType ConstraintsType
Type of constraints engine.
Definition: localfunctionspace.hh:547
GFS::Traits::FiniteElementType FiniteElementType
Type of local finite element.
Definition: localfunctionspace.hh:542
GFS::Traits::ConstraintsType Constraints
Definition: localfunctionspace.hh:549
single component local function space
Definition: localfunctionspace.hh:558
LeafLocalFunctionSpaceNode(const GFS &gfs, const Transformation &t)
Definition: localfunctionspace.hh:593
const Traits::FiniteElementType & finiteElement() const
get finite element
Definition: localfunctionspace.hh:599
void dofIndices(const Entity &e, DOFIndexIterator it, DOFIndexIterator endit, std::integral_constant< bool, fast >)
Calculates the multiindices associated with the given entity.
Definition: localfunctionspace.hh:617
LeafLocalFunctionSpaceTraits< GFS, DOFIndex, LeafLocalFunctionSpaceNode > Traits
Definition: localfunctionspace.hh:574
friend struct ComputeSizeVisitor
Definition: localfunctionspace.hh:568
friend struct ClearSizeVisitor
Definition: localfunctionspace.hh:565
friend struct FillIndicesVisitor
Definition: localfunctionspace.hh:571
const Traits::ConstraintsType & constraints() const
get constraints engine
Definition: localfunctionspace.hh:610
LeafLocalFunctionSpaceNode(std::shared_ptr< const GFS > gfs, const Transformation &t)
initialize with grid function space
Definition: localfunctionspace.hh:587
void insert_constraints(const LC &lc, GC &gc) const
Definition: localfunctionspace.hh:659
void bind(const typename Traits::Element &e, std::integral_constant< bool, fast > fast_=std::integral_constant< bool, fast >{})
bind local function space to entity
Definition: localfunctionspace.hh:681
LeafLocalFunctionSpaceTag ImplementationTag
Definition: localfunctionspace.hh:576
friend struct PropagateGlobalStorageVisitor
Definition: localfunctionspace.hh:562
FESwitch::Store pfe
Definition: localfunctionspace.hh:688
Create a local function space from a global function space.
Definition: localfunctionspace.hh:725
friend struct ClearSizeVisitor
Definition: localfunctionspace.hh:734
friend struct ComputeSizeVisitor
Definition: localfunctionspace.hh:737
LocalIndex localIndex(typename Traits::IndexContainer::size_type index) const
Definition: localfunctionspace.hh:761
LocalFunctionSpace(const GFS &gfs)
Definition: localfunctionspace.hh:745
LocalFunctionSpace(const LocalFunctionSpace &lfs)
Definition: localfunctionspace.hh:751
BaseT::Traits Traits
Definition: localfunctionspace.hh:743
friend struct FillIndicesVisitor
Definition: localfunctionspace.hh:740
friend struct PropagateGlobalStorageVisitor
Definition: localfunctionspace.hh:731
LocalFunctionSpace(std::shared_ptr< const GFS > pgfs)
Definition: localfunctionspace.hh:804
LocalFunctionSpace(const GFS &gfs)
Definition: localfunctionspace.hh:797
LocalFunctionSpace(const LocalFunctionSpace &lfs)
Definition: localfunctionspace.hh:811
Definition: localfunctionspacetags.hh:40
base class for tuples of grid function spaces product of identical grid function spaces base class th...
Definition: powergridfunctionspace.hh:49
Definition: gridfunctionspace/tags.hh:26
Definition: gridfunctionspace/tags.hh:30
Definition: gridfunctionspace/tags.hh:32
Tag denoting a PowerLocalFunctionSpace.
Definition: gridfunctionspace/tags.hh:194
Tag denoting a CompositeLocalFunctionSpace.
Definition: gridfunctionspace/tags.hh:197
Tag denoting a LeafLocalFunctionSpace.
Definition: gridfunctionspace/tags.hh:200