3 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALFUNCTIONSPACE_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALFUNCTIONSPACE_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>
18 #include <dune/pdelab/gridfunctionspace/tags.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_)
75 const 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)
101 node.offset = offset;
105 node.n = node.pgfs->finiteElementMap().maxLocalSize();
106 Node::FESwitch::setStore(node.pfe, node.pgfs->finiteElementMap().find(e));
110 Node::FESwitch::setStore(node.pfe, node.pgfs->finiteElementMap().find(e));
111 node.n = Node::FESwitch::basis(*node.pfe).size();
116 ComputeSizeVisitor(
const Entity& entity, std::size_t offset_ = 0)
127 template<
typename Entity,
bool fast>
128 struct FillIndicesVisitor
129 :
public TypeTree::TreeVisitor
130 ,
public TypeTree::DynamicTraversal
133 template<
typename Node,
typename TreePath>
134 void leaf(Node& node, TreePath
treePath)
137 node.dofIndices(e,node._dof_indices->begin()+node.offset,node._dof_indices->begin()+node.offset+node.n,std::integral_constant<bool,fast>{});
140 template<
typename Node,
typename Child,
typename TreePath,
typename ChildIndex>
141 void afterChild(
const Node& node,
const Child&
child, TreePath
treePath, ChildIndex childIndex)
148 for (std::size_t i = 0; i<
child.n; ++i)
151 (*node._dof_indices)[
child.offset+i].treeIndex().push_back(childIndex);
155 FillIndicesVisitor(
const Entity& entity)
169 template<
typename GFS,
typename DI>
192 template <
typename GFS,
typename DOFIndex>
193 class LocalFunctionSpaceBaseNode
195 typedef typename GFS::Traits::Backend B;
198 friend struct PropagateGlobalStorageVisitor;
200 template<
typename,
bool>
201 friend struct ComputeSizeVisitor;
203 template<
typename,
bool>
204 friend struct FillIndicesVisitor;
206 template<
typename LFS,
typename C,
typename Tag,
bool>
207 friend class LFSIndexCacheBase;
213 LocalFunctionSpaceBaseNode (std::shared_ptr<const GFS> gfs)
215 , _dof_index_storage()
216 , _dof_indices(&_dof_index_storage)
221 typename Traits::IndexContainer::size_type size ()
const
226 std::size_t subSpaceDepth()
const
232 typename Traits::IndexContainer::size_type maxSize ()
const
235 return _dof_indices->size();
245 typename Traits::IndexContainer::size_type localVectorSize ()
const
247 return _dof_indices->size();
251 typename Traits::IndexContainer::size_type localIndex (
typename Traits::IndexContainer::size_type index)
const
264 const typename Traits::DOFIndex& dofIndex(
typename Traits::IndexContainer::size_type index)
const
266 return (*_dof_indices)[offset + index];
272 std::cout << n <<
" indices = (";
273 for (
typename Traits::IndexContainer::size_type k=0; k<n; k++)
274 std::cout << (*_dof_indices)[localIndex(k)] <<
" ";
275 std::cout <<
")" << std::endl;
279 const GFS& gridFunctionSpace()
const
285 template<
typename NodeType>
286 void setup(NodeType& node)
288 _dof_index_storage.resize(gridFunctionSpace().ordering().maxLocalSize());
292 std::shared_ptr<GFS const> pgfs;
295 typename Traits::IndexContainer::size_type n;
296 typename Traits::IndexContainer::size_type offset;
300 template<
typename GFS,
typename DOFIndex>
307 typedef typename GFS::Traits::GridViewType
GridView;
309 using EntitySet =
typename GFS::Traits::EntitySet;
315 template <
typename GFS,
typename DOFIndex>
316 class GridViewLocalFunctionSpaceBaseNode :
317 public LocalFunctionSpaceBaseNode<GFS,DOFIndex>
319 typedef typename GFS::Traits::Backend B;
320 typedef LocalFunctionSpaceBaseNode<GFS,DOFIndex> BaseT;
326 GridViewLocalFunctionSpaceBaseNode (std::shared_ptr<const GFS> gfs)
344 template<
typename NodeType,
bool fast = false>
345 void bind (NodeType& node,
const typename Traits::Element& e, std::integral_constant<bool,fast> = std::integral_constant<bool,fast>{});
348 template <
typename GFS,
typename DOFIndex>
349 template <
typename NodeType,
bool fast>
350 void GridViewLocalFunctionSpaceBaseNode<GFS,DOFIndex>::bind (NodeType& node,
352 std::integral_constant<bool,fast>)
355 assert(&node ==
this);
358 ComputeSizeVisitor<Element,fast> csv(e);
363 FillIndicesVisitor<Element,fast> fiv(e);
372 template<
typename GFS,
typename DOFIndex,
typename N>
380 template<
typename GFS,
typename DOFIndex,
typename ChildLFS, std::
size_t k>
381 class PowerLocalFunctionSpaceNode :
382 public GridViewLocalFunctionSpaceBaseNode<GFS,DOFIndex>,
385 typedef GridViewLocalFunctionSpaceBaseNode<GFS,DOFIndex> BaseT;
389 friend struct PropagateGlobalStorageVisitor;
392 friend struct ClearSizeVisitor;
394 template<
typename,
bool>
395 friend struct ComputeSizeVisitor;
397 template<
typename,
bool>
398 friend struct FillIndicesVisitor;
406 template<
typename Transformation>
407 PowerLocalFunctionSpaceNode (std::shared_ptr<const GFS> gfs,
408 const Transformation& t,
409 const std::array<std::shared_ptr<ChildLFS>,k>& children)
414 template<
typename Transformation>
415 PowerLocalFunctionSpaceNode (
const GFS& gfs,
416 const Transformation& t,
417 const std::array<std::shared_ptr<ChildLFS>,k>& children)
423 template<
bool fast = false>
424 void bind (
const typename Traits::Element& e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
427 BaseT::bind(*
this,e,fast_);
434 template<
typename SourceNode,
typename Transformation>
435 struct power_gfs_to_lfs_template
437 template<
typename TC>
440 typedef PowerLocalFunctionSpaceNode<SourceNode,typename Transformation::DOFIndex,TC,TypeTree::StaticDegree<SourceNode>::value> type;
445 template<
typename PowerGr
idFunctionSpace,
typename Params>
446 TypeTree::TemplatizedGenericPowerNodeTransformation<
447 PowerGridFunctionSpace,
449 power_gfs_to_lfs_template<PowerGridFunctionSpace,gfs_to_lfs<Params> >::template result
459 template<
typename GFS,
typename DOFIndex,
typename... Children>
460 class CompositeLocalFunctionSpaceNode
461 :
public GridViewLocalFunctionSpaceBaseNode<GFS,DOFIndex>
462 ,
public TypeTree::CompositeNode<Children...>
464 typedef GridViewLocalFunctionSpaceBaseNode<GFS,DOFIndex> BaseT;
465 typedef TypeTree::CompositeNode<Children...> NodeType;
468 friend struct PropagateGlobalStorageVisitor;
471 friend struct ClearSizeVisitor;
473 template<
typename,
bool>
474 friend struct ComputeSizeVisitor;
476 template<
typename,
bool>
477 friend struct FillIndicesVisitor;
480 typedef PowerCompositeLocalFunctionSpaceTraits<GFS,DOFIndex,CompositeLocalFunctionSpaceNode> Traits;
484 template<
typename Transformation>
485 CompositeLocalFunctionSpaceNode (std::shared_ptr<const GFS> gfs,
486 const Transformation& t,
487 std::shared_ptr<Children>... children)
489 , NodeType(children...)
492 template<
typename Transformation>
493 CompositeLocalFunctionSpaceNode (
const GFS& gfs,
494 const Transformation& t,
495 std::shared_ptr<Children>... children)
497 , NodeType(children...)
501 template<
bool fast = false>
502 void bind (
const typename Traits::Element& e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
505 BaseT::bind(*
this,e,fast_);
511 template<
typename SourceNode,
typename Transformation>
512 struct composite_gfs_to_lfs_template
514 template<
typename... TC>
517 typedef CompositeLocalFunctionSpaceNode<SourceNode,
typename Transformation::DOFIndex,TC...> type;
522 template<
typename CompositeGr
idFunctionSpace,
typename Params>
523 TypeTree::TemplatizedGenericCompositeNodeTransformation<
524 CompositeGridFunctionSpace,
526 composite_gfs_to_lfs_template<CompositeGridFunctionSpace,gfs_to_lfs<Params> >::template result
536 template<
typename GFS,
typename DOFIndex,
typename N>
542 typedef typename GFS::Traits::FiniteElementType FiniteElement;
547 typedef typename GFS::Traits::ConstraintsType Constraints;
552 template<
typename GFS,
typename DOFIndex>
554 :
public GridViewLocalFunctionSpaceBaseNode<GFS,DOFIndex>
557 typedef GridViewLocalFunctionSpaceBaseNode<GFS,DOFIndex> BaseT;
560 friend struct PropagateGlobalStorageVisitor;
563 friend struct ClearSizeVisitor;
565 template<
typename,
bool>
566 friend struct ComputeSizeVisitor;
568 template<
typename,
bool>
569 friend struct FillIndicesVisitor;
584 template<
typename Transformation>
590 template<
typename Transformation>
606 return this->pgfs->constraints();
610 template<
typename Entity,
typename DOFIndexIterator,
bool fast>
611 void dofIndices(
const Entity& e, DOFIndexIterator it, DOFIndexIterator endit, std::integral_constant<bool,fast>)
616 auto index = this->gridFunctionSpace().entitySet().indexSet().index(e);
617 GFS::Ordering::Traits::DOFIndexAccessor::store(*it,
gt,index,0);
626 using EntitySet =
typename GFS::Traits::EntitySet;
627 auto es = this->gridFunctionSpace().entitySet();
631 for (std::size_t i = 0; i < std::size_t(coeffs.size()); ++i, ++it)
634 auto gt = refEl.type(coeffs.localKey(i).subEntity(),
635 coeffs.localKey(i).codim());
638 auto index = es.indexSet().subIndex(e,
639 coeffs.localKey(i).subEntity(),
640 coeffs.localKey(i).codim());
643 GFS::Ordering::Traits::DOFIndexAccessor::store(*it,
gt,index,coeffs.localKey(i).index());
652 template<
typename GC,
typename LC>
653 void insert_constraints (
const LC& lc, GC& gc)
const
656 typedef typename LC::const_iterator local_col_iterator;
657 typedef typename LC::value_type::second_type::const_iterator local_row_iterator;
658 typedef typename GC::iterator global_col_iterator;
659 typedef typename GC::value_type::second_type global_row_type;
661 for (local_col_iterator cit=lc.begin(); cit!=lc.end(); ++cit)
665 global_col_iterator gcit = gc.insert(std::make_pair(std::ref(this->dofIndex(cit->first)),global_row_type())).first;
668 for (local_row_iterator rit=(cit->second).begin(); rit!=(cit->second).end(); ++rit)
669 gcit->second[this->dofIndex(rit->first)] = rit->second;
674 template<
bool fast = false>
675 void bind (
const typename Traits::Element& e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
678 BaseT::bind(*
this,e,fast_);
686 template<
typename Gr
idFunctionSpace,
typename Params>
687 TypeTree::GenericLeafNodeTransformation<
690 LeafLocalFunctionSpaceNode<GridFunctionSpace,typename gfs_to_lfs<Params>::DOFIndex>
692 registerNodeTransformation(GridFunctionSpace* gfs, gfs_to_lfs<Params>* t, LeafGridFunctionSpaceTag* tag);
698 template <
typename GFS,
typename TAG=AnySpaceTag>
699 class LocalFunctionSpace;
714 template <
typename GFS,
typename TAG>
719 typedef typename BaseT::Traits::IndexContainer::size_type I;
720 typedef typename BaseT::Traits::IndexContainer::size_type LocalIndex;
723 friend struct PropagateGlobalStorageVisitor;
726 friend struct ClearSizeVisitor;
729 friend struct ComputeSizeVisitor;
732 friend struct FillIndicesVisitor;
735 typedef typename BaseT::Traits
Traits;
749 this->_dof_indices = &(this->_dof_index_storage);
753 LocalIndex localIndex (
typename Traits::IndexContainer::size_type index)
const
755 return LocalIndex(BaseT::localIndex(index));
761 void getChild ()
const;
769 template <
typename GFS>
776 friend struct PropagateGlobalStorageVisitor;
779 friend struct ClearSizeVisitor;
781 template<
typename,
bool>
782 friend struct ComputeSizeVisitor;
784 template<
typename,
bool>
785 friend struct FillIndicesVisitor;
790 : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform(gfs))
792 this->_dof_indices = &(this->_dof_index_storage);
796 LocalFunctionSpace(std::shared_ptr<const GFS> pgfs)
797 : BaseT(*TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform_storage(pgfs))
799 this->_dof_indices = &(this->_dof_index_storage);
803 LocalFunctionSpace(
const LocalFunctionSpace & lfs)
809 this->_dof_indices = &(this->_dof_index_storage);
Wrapper class for entities.
Definition: entity.hh:64
single component local function space
Definition: localfunctionspace.hh:556
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:611
LeafLocalFunctionSpaceNode(std::shared_ptr< const GFS > gfs, const Transformation &t)
initialize with grid function space
Definition: localfunctionspace.hh:585
const Traits::ConstraintsType & constraints() const
get constraints engine
Definition: localfunctionspace.hh:604
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:675
const Traits::FiniteElementType & finiteElement() const
get finite element
Definition: localfunctionspace.hh:597
Create a local function space from a global function space.
Definition: localfunctionspace.hh:717
Base class for leaf nodes in a dune-typetree.
Definition: leafnode.hh:25
Collect k instances of type T within a dune-typetree.
Definition: powernode.hh:50
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
typename std::decay_t< T >::ImplementationTag ImplementationTag
Returns the implementation tag of the given Node.
Definition: nodeinterface.hh:66
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:213
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Standard Dune debug streams.
Switch for uniform treatment of finite element with either the local or the global interface.
Definition: interfaceswitch.hh:27
FiniteElement::Traits::Coefficients Coefficients
export the type of the coefficients
Definition: interfaceswitch.hh:33
std::shared_ptr< const FiniteElement > Store
Type for storing finite elements.
Definition: interfaceswitch.hh:68
static const Coefficients & coefficients(const FiniteElement &fe)
access coefficients
Definition: interfaceswitch.hh:42
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:196
Definition: localfunctionspacetags.hh:40
traits for local function space on a gridview
Definition: localfunctionspace.hh:302
GFS::Traits::GridViewType GridViewType
Type of the grid view that the underlying grid function space is defined on.
Definition: localfunctionspace.hh:304
GFS::Traits::GridViewType GridView
Type of the grid view that the underlying grid function space is defined on.
Definition: localfunctionspace.hh:307
typename EntitySet::Element Element
Type of codim 0 entity in the grid.
Definition: localfunctionspace.hh:312
Tag denoting a LeafLocalFunctionSpace.
Definition: tags.hh:200
traits for single component local function space
Definition: localfunctionspace.hh:538
GFS::Traits::ConstraintsType ConstraintsType
Type of constraints engine.
Definition: localfunctionspace.hh:545
GFS::Traits::FiniteElementType FiniteElementType
Type of local finite element.
Definition: localfunctionspace.hh:540
traits mapping global function space information to local function space
Definition: localfunctionspace.hh:171
GFS GridFunctionSpace
Type of the underlying grid function space.
Definition: localfunctionspace.hh:176
std::vector< SizeType > IndexContainer
Type of container to store indices.
Definition: localfunctionspace.hh:182
GFS::Traits::SizeType SizeType
Type to store indices from Backend.
Definition: localfunctionspace.hh:179
GFS GridFunctionSpaceType
Type of the underlying grid function space.
Definition: localfunctionspace.hh:173
DI DOFIndex
Type of MultiIndex associated with this LocalFunctionSpace.
Definition: localfunctionspace.hh:185
std::vector< DI > DOFIndexContainer
Type of container to store multiindices.
Definition: localfunctionspace.hh:188
traits for multi component local function space
Definition: localfunctionspace.hh:374
N NodeType
type of local function space node
Definition: localfunctionspace.hh:376
Tag denoting a PowerLocalFunctionSpace.
Definition: tags.hh:194