3 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALFUNCTIONSPACE_HH 4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALFUNCTIONSPACE_HH 8 #include <dune/common/stdstreams.hh> 10 #include <dune/geometry/referenceelements.hh> 12 #include <dune/localfunctions/common/interfaceswitch.hh> 13 #include <dune/localfunctions/common/localkey.hh> 15 #include <dune/typetree/typetree.hh> 35 template<
typename =
int>
36 struct PropagateGlobalStorageVisitor
37 :
public TypeTree::TreeVisitor
38 ,
public TypeTree::DynamicTraversal
41 template<
typename LFS,
typename Child,
typename TreePath,
typename ChildIndex>
42 void beforeChild(
const LFS& lfs, Child& child, TreePath treePath, ChildIndex childIndex)
const 44 child._dof_indices = lfs._dof_indices;
51 template<
typename =
int>
52 struct ClearSizeVisitor
53 :
public TypeTree::TreeVisitor
54 ,
public TypeTree::DynamicTraversal
57 template<
typename Node,
typename TreePath>
58 void pre(Node& node, TreePath treePath)
63 template<
typename Node,
typename TreePath>
64 void leaf(Node& node, TreePath treePath)
70 ClearSizeVisitor(std::size_t offset_)
79 template<
typename Entity,
bool fast>
80 struct ComputeSizeVisitor
81 :
public TypeTree::TreeVisitor
82 ,
public TypeTree::DynamicTraversal
85 template<
typename Node,
typename TreePath>
86 void pre(Node& node, TreePath treePath)
91 template<
typename Node,
typename TreePath>
92 void post(Node& node, TreePath treePath)
94 node.n =
offset - node.offset;
97 template<
typename Node,
typename TreePath>
98 void leaf(Node& node, TreePath treePath)
104 node.n = node.pgfs->finiteElementMap().maxLocalSize();
105 Node::FESwitch::setStore(node.pfe, node.pgfs->finiteElementMap().find(
e));
109 Node::FESwitch::setStore(node.pfe, node.pgfs->finiteElementMap().find(
e));
110 node.n = Node::FESwitch::basis(*node.pfe).size();
115 ComputeSizeVisitor(
const Entity& entity, std::size_t offset_ = 0)
126 template<
typename Entity,
bool fast>
127 struct FillIndicesVisitor
128 :
public TypeTree::TreeVisitor
129 ,
public TypeTree::DynamicTraversal
132 template<
typename Node,
typename TreePath>
133 void leaf(Node& node, TreePath treePath)
136 node.dofIndices(
e,node._dof_indices->begin()+node.offset,node._dof_indices->begin()+node.offset+node.n,std::integral_constant<bool,fast>{});
139 template<
typename Node,
typename Child,
typename TreePath,
typename ChildIndex>
140 void afterChild(
const Node& node,
const Child& child, TreePath treePath, ChildIndex childIndex)
147 for (std::size_t i = 0; i<child.n; ++i)
150 (*node._dof_indices)[child.offset+i].treeIndex().push_back(childIndex);
154 FillIndicesVisitor(
const Entity& entity)
168 template<
typename GFS,
typename DI>
191 template <
typename GFS,
typename DOFIndex>
194 typedef typename GFS::Traits::Backend B;
197 friend struct PropagateGlobalStorageVisitor;
199 template<
typename,
bool>
200 friend struct ComputeSizeVisitor;
202 template<
typename,
bool>
203 friend struct FillIndicesVisitor;
205 template<
typename LFS,
typename C,
typename Tag,
bool>
214 , _dof_index_storage()
215 , _dof_indices(&_dof_index_storage)
220 typename Traits::IndexContainer::size_type
size ()
const 231 typename Traits::IndexContainer::size_type
maxSize ()
const 234 return _dof_indices->size();
246 return _dof_indices->size();
250 typename Traits::IndexContainer::size_type
localIndex (
typename Traits::IndexContainer::size_type
index)
const 271 std::cout << n <<
" indices = (";
272 for (
typename Traits::IndexContainer::size_type k=0; k<n; k++)
273 std::cout << (*_dof_indices)[localIndex(k)] <<
" ";
274 std::cout <<
")" << std::endl;
284 template<
typename NodeType>
287 _dof_index_storage.resize(gridFunctionSpace().ordering().maxLocalSize());
288 TypeTree::applyToTree(node,PropagateGlobalStorageVisitor<>());
291 std::shared_ptr<GFS const>
pgfs;
294 typename Traits::IndexContainer::size_type
n;
295 typename Traits::IndexContainer::size_type
offset;
299 template<
typename GFS,
typename DOFIndex>
306 typedef typename GFS::Traits::GridViewType
GridView;
314 template <
typename GFS,
typename DOFIndex>
318 typedef typename GFS::Traits::Backend B;
343 template<
typename NodeType,
bool fast = false>
344 void bind (NodeType& node,
const typename Traits::Element&
e, std::integral_constant<bool,fast> = std::integral_constant<bool,fast>{});
347 template <
typename GFS,
typename DOFIndex>
348 template <
typename NodeType,
bool fast>
351 std::integral_constant<bool,fast>)
354 assert(&node ==
this);
357 ComputeSizeVisitor<Element,fast> csv(e);
358 TypeTree::applyToTree(node,csv);
362 FillIndicesVisitor<Element,fast> fiv(e);
363 TypeTree::applyToTree(node,fiv);
371 template<
typename GFS,
typename DOFIndex,
typename N>
379 template<
typename GFS,
typename DOFIndex,
typename ChildLFS, std::
size_t k>
382 public TypeTree::PowerNode<ChildLFS,k>
385 typedef TypeTree::PowerNode<ChildLFS,k> TreeNode;
388 friend struct PropagateGlobalStorageVisitor;
391 friend struct ClearSizeVisitor;
393 template<
typename,
bool>
394 friend struct ComputeSizeVisitor;
396 template<
typename,
bool>
397 friend struct FillIndicesVisitor;
405 template<
typename Transformation>
407 const Transformation& t,
408 const std::array<std::shared_ptr<ChildLFS>,k>& children)
413 template<
typename Transformation>
415 const Transformation& t,
416 const std::array<std::shared_ptr<ChildLFS>,k>& children)
417 : BaseT(stackobject_to_shared_ptr(gfs))
422 template<
bool fast = false>
423 void bind (
const typename Traits::Element&
e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
426 BaseT::bind(*
this,e,fast_);
433 template<
typename SourceNode,
typename Transformation>
436 template<
typename TC>
444 template<
typename PowerGr
idFunctionSpace,
typename Params>
445 TypeTree::TemplatizedGenericPowerNodeTransformation<
458 template<
typename GFS,
typename DOFIndex,
typename... Children>
461 ,
public TypeTree::CompositeNode<Children...>
464 typedef TypeTree::CompositeNode<Children...> NodeType;
467 friend struct PropagateGlobalStorageVisitor;
470 friend struct ClearSizeVisitor;
472 template<
typename,
bool>
473 friend struct ComputeSizeVisitor;
475 template<
typename,
bool>
476 friend struct FillIndicesVisitor;
483 template<
typename Transformation>
485 const Transformation& t,
486 std::shared_ptr<Children>... children)
488 , NodeType(children...)
491 template<
typename Transformation>
493 const Transformation& t,
494 std::shared_ptr<Children>... children)
495 : BaseT(stackobject_to_shared_ptr(gfs))
496 , NodeType(children...)
500 template<
bool fast = false>
501 void bind (
const typename Traits::Element&
e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
504 BaseT::bind(*
this,e,fast_);
510 template<
typename SourceNode,
typename Transformation>
513 template<
typename... TC>
521 template<
typename CompositeGr
idFunctionSpace,
typename Params>
522 TypeTree::TemplatizedGenericCompositeNodeTransformation<
535 template<
typename GFS,
typename DOFIndex,
typename N>
551 template<
typename GFS,
typename DOFIndex>
554 ,
public TypeTree::LeafNode
559 friend struct PropagateGlobalStorageVisitor;
562 friend struct ClearSizeVisitor;
564 template<
typename,
bool>
565 friend struct ComputeSizeVisitor;
567 template<
typename,
bool>
568 friend struct FillIndicesVisitor;
576 typedef FiniteElementInterfaceSwitch<
577 typename Traits::FiniteElementType
583 template<
typename Transformation>
589 template<
typename Transformation>
591 : BaseT(stackobject_to_shared_ptr(gfs))
605 return this->pgfs->constraints();
609 template<
typename Entity,
typename DOFIndexIterator,
bool fast>
610 void dofIndices(
const Entity&
e, DOFIndexIterator it, DOFIndexIterator endit, std::integral_constant<bool,fast>)
615 auto index = this->gridFunctionSpace().entitySet().indexSet().index(e);
616 GFS::Ordering::Traits::DOFIndexAccessor::store(*it,gt,
index,0);
622 const typename FESwitch::Coefficients &coeffs =
623 FESwitch::coefficients(*pfe);
625 using EntitySet =
typename GFS::Traits::EntitySet;
626 auto es = this->gridFunctionSpace().entitySet();
628 auto refEl = Dune::ReferenceElements<double,EntitySet::dimension>::general(this->pfe->type());
630 for (std::size_t i = 0; i < std::size_t(coeffs.size()); ++i, ++it)
633 auto gt = refEl.type(coeffs.localKey(i).subEntity(),
634 coeffs.localKey(i).codim());
637 auto index = es.indexSet().subIndex(e,
638 coeffs.localKey(i).subEntity(),
639 coeffs.localKey(i).codim());
642 GFS::Ordering::Traits::DOFIndexAccessor::store(*it,gt,
index,coeffs.localKey(i).index());
651 template<
typename GC,
typename LC>
655 typedef typename LC::const_iterator local_col_iterator;
656 typedef typename LC::value_type::second_type::const_iterator local_row_iterator;
657 typedef typename GC::iterator global_col_iterator;
658 typedef typename GC::value_type::second_type global_row_type;
660 for (local_col_iterator cit=lc.begin(); cit!=lc.end(); ++cit)
664 global_col_iterator gcit = gc.insert(std::make_pair(std::ref(this->dofIndex(cit->first)),global_row_type())).first;
667 for (local_row_iterator rit=(cit->second).begin(); rit!=(cit->second).end(); ++rit)
668 gcit->second[this->dofIndex(rit->first)] = rit->second;
673 template<
bool fast = false>
674 void bind (
const typename Traits::Element&
e, std::integral_constant<bool,fast> fast_ = std::integral_constant<bool,fast>{})
677 BaseT::bind(*
this,e,fast_);
681 typename FESwitch::Store
pfe;
685 template<
typename Gr
idFunctionSpace,
typename Params>
686 TypeTree::GenericLeafNodeTransformation<
697 template <
typename GFS,
typename TAG=AnySpaceTag>
713 template <
typename GFS,
typename TAG>
715 public TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type
717 typedef typename TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type BaseT;
718 typedef typename BaseT::Traits::IndexContainer::size_type I;
719 typedef typename BaseT::Traits::IndexContainer::size_type LocalIndex;
722 friend struct PropagateGlobalStorageVisitor;
725 friend struct ClearSizeVisitor;
728 friend struct ComputeSizeVisitor;
731 friend struct FillIndicesVisitor;
737 : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform(gfs))
748 this->_dof_indices = &(this->_dof_index_storage);
754 return LocalIndex(BaseT::localIndex(index));
760 void getChild ()
const;
768 template <
typename GFS>
770 public TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type
772 typedef typename TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::Type BaseT;
775 friend struct PropagateGlobalStorageVisitor;
778 friend struct ClearSizeVisitor;
780 template<
typename,
bool>
781 friend struct ComputeSizeVisitor;
783 template<
typename,
bool>
784 friend struct FillIndicesVisitor;
789 : BaseT(TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform(gfs))
791 this->_dof_indices = &(this->_dof_index_storage);
796 : BaseT(*TypeTree::TransformTree<GFS,gfs_to_lfs<GFS> >::transform_storage(pgfs))
798 this->_dof_indices = &(this->_dof_index_storage);
808 this->_dof_indices = &(this->_dof_index_storage);
818 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALFUNCTIONSPACE_HH LocalFunctionSpace(const LocalFunctionSpace &lfs)
Definition: localfunctionspace.hh:742
Tag denoting a PowerLocalFunctionSpace.
Definition: gridfunctionspace/tags.hh:194
LeafLocalFunctionSpaceTraits< GFS, DOFIndex, LeafLocalFunctionSpaceNode > Traits
Definition: localfunctionspace.hh:571
A multi-index representing a degree of freedom in a GridFunctionSpace.
Definition: dofindex.hh:147
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:610
N NodeType
type of local function space node
Definition: localfunctionspace.hh:375
LocalFunctionSpaceBaseTraits< GFS, DOFIndex > Traits
Definition: localfunctionspace.hh:209
const Entity & e
Definition: localfunctionspace.hh:120
Definition: gridfunctionspace/tags.hh:30
Definition: localfunctionspace.hh:514
GFS GridFunctionSpace
Type of the underlying grid function space.
Definition: localfunctionspace.hh:175
base class for tuples of grid function spaces base class that holds implementation of the methods thi...
Definition: compositegridfunctionspace.hh:40
typename GFS::Traits::EntitySet EntitySet
Definition: localfunctionspace.hh:308
Definition: localfunctionspace.hh:437
A grid function space.
Definition: gridfunctionspace.hh:166
traits for multi component local function space
Definition: localfunctionspace.hh:372
PowerLocalFunctionSpaceNode(const GFS &gfs, const Transformation &t, const std::array< std::shared_ptr< ChildLFS >, k > &children)
Definition: localfunctionspace.hh:414
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:423
Traits::IndexContainer::size_type offset
Definition: localfunctionspace.hh:295
GFS::Traits::GridViewType GridView
Type of the grid view that the underlying grid function space is defined on.
Definition: localfunctionspace.hh:306
BaseT::Traits Traits
Definition: localfunctionspace.hh:734
Definition: localfunctionspacetags.hh:40
CompositeLocalFunctionSpaceNode(std::shared_ptr< const GFS > gfs, const Transformation &t, std::shared_ptr< Children >... children)
Definition: localfunctionspace.hh:484
void setup(NodeType &node)
Definition: localfunctionspace.hh:285
single component local function space
Definition: localfunctionspace.hh:552
const Traits::FiniteElementType & finiteElement() const
get finite element
Definition: localfunctionspace.hh:596
GFS::Traits::FiniteElementType FiniteElement
Definition: localfunctionspace.hh:541
Definition: localfunctionspace.hh:511
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:406
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:263
GFS GridFunctionSpaceType
Type of the underlying grid function space.
Definition: localfunctionspace.hh:172
void insert_constraints(const LC &lc, GC &gc) const
Definition: localfunctionspace.hh:652
GridViewLocalFunctionSpaceBaseTraits< GFS, DOFIndex > Traits
Definition: localfunctionspace.hh:322
PowerCompositeLocalFunctionSpaceTraits< GFS, DOFIndex, PowerLocalFunctionSpaceNode > Traits
Definition: localfunctionspace.hh:400
CompositeLocalFunctionSpaceTag ImplementationTag
Definition: localfunctionspace.hh:481
PowerLocalFunctionSpaceTag ImplementationTag
Definition: localfunctionspace.hh:402
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:501
std::vector< SizeType > IndexContainer
Type of container to store indices.
Definition: localfunctionspace.hh:181
void debug() const
print debug information about this local function space
Definition: localfunctionspace.hh:269
Traits::IndexContainer::size_type localVectorSize() const
get size of an appropriate local vector object
Definition: localfunctionspace.hh:244
GridViewLocalFunctionSpaceBaseNode(std::shared_ptr< const GFS > gfs)
construct from global function space
Definition: localfunctionspace.hh:325
PowerCompositeLocalFunctionSpaceTraits< GFS, DOFIndex, CompositeLocalFunctionSpaceNode > Traits
Definition: localfunctionspace.hh:479
const std::size_t offset
Definition: localfunctionspace.hh:74
GFS::Traits::GridViewType GridViewType
Type of the grid view that the underlying grid function space is defined on.
Definition: localfunctionspace.hh:303
GFS::Traits::FiniteElementType FiniteElementType
Type of local finite element.
Definition: localfunctionspace.hh:539
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:674
GFS::Traits::ConstraintsType Constraints
Definition: localfunctionspace.hh:546
GFS::Traits::ConstraintsType ConstraintsType
Type of constraints engine.
Definition: localfunctionspace.hh:544
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
LocalFunctionSpace(std::shared_ptr< const GFS > pgfs)
Definition: localfunctionspace.hh:795
DI DOFIndex
Type of MultiIndex associated with this LocalFunctionSpace.
Definition: localfunctionspace.hh:184
Definition: localfunctionspace.hh:192
Tag denoting a LeafLocalFunctionSpace.
Definition: gridfunctionspace/tags.hh:200
Traits::IndexContainer::size_type n
Definition: localfunctionspace.hh:294
base class for tuples of grid function spaces product of identical grid function spaces base class th...
Definition: powergridfunctionspace.hh:40
LeafLocalFunctionSpaceTag ImplementationTag
Definition: localfunctionspace.hh:573
LeafLocalFunctionSpaceNode(const GFS &gfs, const Transformation &t)
Definition: localfunctionspace.hh:590
PowerLocalFunctionSpaceNode< SourceNode, typename Transformation::DOFIndex, TC, TypeTree::StaticDegree< SourceNode >::value > type
Definition: localfunctionspace.hh:439
LocalFunctionSpace(const GFS &gfs)
Definition: localfunctionspace.hh:736
Definition: localfunctionspace.hh:434
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:250
FESwitch::Store pfe
Definition: localfunctionspace.hh:681
Definition: localfunctionspace.hh:315
Traits::DOFIndexContainer _dof_index_storage
Definition: localfunctionspace.hh:292
std::shared_ptr< GFS const > pgfs
Definition: localfunctionspace.hh:291
CompositeLocalFunctionSpaceNode(const GFS &gfs, const Transformation &t, std::shared_ptr< Children >... children)
Definition: localfunctionspace.hh:492
LocalFunctionSpace(const GFS &gfs)
Definition: localfunctionspace.hh:788
CompositeLocalFunctionSpaceNode< SourceNode, typename Transformation::DOFIndex, TC... > type
Definition: localfunctionspace.hh:516
Definition: gridfunctionspace/tags.hh:32
traits for single component local function space
Definition: localfunctionspace.hh:536
LocalFunctionSpace(const LocalFunctionSpace &lfs)
Definition: localfunctionspace.hh:802
Definition: lfsindexcache.hh:244
Definition: gridfunctionspace/tags.hh:26
Definition: localfunctionspace.hh:459
Dune::TypeTree::GenericLeafNodeTransformation< LeafNode, GridFunctionToLocalViewTransformation, Imp::LocalGridViewFunctionAdapter< LeafNode > > registerNodeTransformation(LeafNode *l, GridFunctionToLocalViewTransformation *t, GridFunctionTag *tag)
GFS::Traits::SizeType SizeType
Type to store indices from Backend.
Definition: localfunctionspace.hh:178
LocalFunctionSpaceBaseNode(std::shared_ptr< const GFS > gfs)
construct from global function space
Definition: localfunctionspace.hh:212
const GFS & gridFunctionSpace() const
Returns the GridFunctionSpace underlying this LocalFunctionSpace.
Definition: localfunctionspace.hh:278
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
LeafLocalFunctionSpaceNode(std::shared_ptr< const GFS > gfs, const Transformation &t)
initialize with grid function space
Definition: localfunctionspace.hh:584
traits mapping global function space information to local function space
Definition: localfunctionspace.hh:169
Tag denoting a CompositeLocalFunctionSpace.
Definition: gridfunctionspace/tags.hh:197
Create a local function space from a global function space.
Definition: localfunctionspace.hh:698
std::size_t index
Definition: interpolate.hh:118
Traits::IndexContainer::size_type maxSize() const
get maximum possible size (which is maxLocalSize from grid function space)
Definition: localfunctionspace.hh:231
std::size_t subSpaceDepth() const
Definition: localfunctionspace.hh:225
Traits::DOFIndexContainer * _dof_indices
Definition: localfunctionspace.hh:293
LocalIndex localIndex(typename Traits::IndexContainer::size_type index) const
Definition: localfunctionspace.hh:752
const Traits::ConstraintsType & constraints() const
get constraints engine
Definition: localfunctionspace.hh:603
Definition: localfunctionspace.hh:380
traits for local function space on a gridview
Definition: localfunctionspace.hh:300
std::vector< DI > DOFIndexContainer
Type of container to store multiindices.
Definition: localfunctionspace.hh:187
typename EntitySet::Element Element
Type of codim 0 entity in the grid.
Definition: localfunctionspace.hh:311
Traits::IndexContainer::size_type size() const
get current size
Definition: localfunctionspace.hh:220