7 #include <dune/common/exceptions.hh> 8 #include <dune/common/hybridutilities.hh> 9 #include <dune/common/version.hh> 10 #include <dune/functions/functionspacebases/nodes.hh> 11 #include <dune/grid/common/gridenums.hh> 12 #include <dune/localfunctions/common/localkey.hh> 14 #include <amdis/Output.hpp> 15 #include <amdis/common/Apply.hpp> 16 #include <amdis/common/ConceptsBase.hpp> 17 #include <amdis/common/ForEach.hpp> 18 #include <amdis/common/TupleUtility.hpp> 19 #include <amdis/functions/Nodes.hpp> 20 #include <amdis/utility/Twist.hpp> 27 template <
class GV,
int k,
class MI>
28 class LagrangeDGPreBasis;
30 template<
typename GV,
class MI,
bool HI>
31 class TaylorHoodPreBasis;
39 template <class PreBasis, class TP, class NodeTag = typename Node_t<PreBasis,TP>::NodeTag>
47 template <
class EntityIdType>
50 using Super = std::pair<EntityIdType, std::size_t>;
54 : Super(EntityIdType{}, i)
72 friend std::ostream& operator<<(std::ostream& os,
GlobalIdType const&
id)
74 os <<
"(" <<
id.first <<
"," <<
id.second <<
")";
79 template <
class Basis>
105 template <
class GB,
class = std::
void_t<> >
109 using GlobalBasis = GB;
110 using Tree =
typename GB::LocalView::Tree;
111 using size_type = std::size_t;
114 using Grid =
typename GridView::Grid;
115 using Element =
typename GridView::template Codim<0>::Entity;
116 using EntityIdType =
typename Grid::GlobalIdSet::IdType;
117 using PartitionType = Dune::PartitionType;
121 using TreePath =
typename GlobalBasis::PrefixPath;
127 : tree_(globalBasis.localView().tree())
128 , nodeIdSet_(globalBasis.gridView())
129 , twist_(globalBasis.gridView().grid().globalIdSet())
131 initializeTree(tree_);
140 void bind(Element
const& element)
142 bindTree(tree_, element);
143 nodeIdSet_.bind(tree_);
144 twist_.bind(element);
145 data_.resize(size());
146 nodeIdSet_.fillIn(twist_, data_.begin());
165 assert( i < data_.size() );
166 return data_[i].first;
180 assert( i < data_.size() );
181 return data_[i].second;
188 using Data = std::pair<IdType, PartitionType>;
189 std::vector<Data> data_;
194 template <
class Basis>
205 template <
class PB,
class TP,
class NodeTag>
210 using Node = Node_t<PreBasis,TP>;
211 using GridView =
typename PreBasis::GridView;
212 using size_type = std::size_t;
214 static_assert(Node::isLeaf,
"Generic NodeIdSet implemented for LeafNodes only. Provide a specialization for your node!");
217 static constexpr
int dim = GridView::template Codim<0>::Entity::mydimension;
221 : gridView_(gridView)
229 size_ = node_->finiteElement().size();
231 std::fill(std::begin(sizes_), std::end(sizes_), 0u);
232 for (size_type i = 0; i < size_ ; ++i) {
233 Dune::LocalKey
const& localKey = node_->finiteElement().localCoefficients().localKey(i);
234 sizes_[localKey.codim()]++;
236 auto refElem = Dune::referenceElement<double,GridView::dimension>(node_->element().type());
237 for (size_type c = 0; c <= GridView::dimension ; ++c)
238 sizes_[c] /= refElem.size(c);
254 template <
class Twist,
class It>
257 assert(node_ !=
nullptr);
258 const auto& gridIdSet = gridView_.grid().globalIdSet();
260 for (size_type i = 0; i < size_ ; ++i, ++it) {
261 Dune::LocalKey localKey = node_->finiteElement().localCoefficients().localKey(i);
262 unsigned int s = localKey.subEntity();
263 unsigned int c = localKey.codim();
264 it->first = {gridIdSet.subId(node_->element(), s, c), shift + twist.
get(localKey,sizes_[c])};
266 it->second = Dune::Hybrid::switchCases(std::make_index_sequence<dim+1>{}, c,
267 [&](
auto codim) {
return node_->element().template subEntity<codim>(s).partitionType(); },
270 return Dune::PartitionType{};
279 const Node* node_ =
nullptr;
281 std::array<unsigned int,GridView::dimension+1> sizes_;
286 template <
class PreBasis,
class TP>
287 class NodeIdSet<PreBasis, TP, Dune::TypeTree::PowerNodeTag>
290 using Node = Node_t<PreBasis,TP>;
291 using GridView =
typename PreBasis::GridView;
292 using size_type = std::size_t;
295 using SubPreBasis =
typename PreBasis::SubPreBasis;
296 using SubTreePath = decltype(Dune::TypeTree::push_back(std::declval<TP>(), std::size_t(0)));
298 static const std::size_t children = Node::CHILDREN;
306 void bind(
const Node& node)
309 subIds_.bind(node.child(0));
320 size_type size()
const 322 return node_->size();
326 template <
class Twist,
class It>
327 It fillIn(
Twist const& twist, It it, size_type shift = 0)
const 329 assert(node_ !=
nullptr);
330 for (std::size_t child = 0; child < children; ++child)
332 size_type subTreeSize = subIds_.size();
333 it = subIds_.fillIn(twist, it, shift);
334 shift += subTreeSize;
340 SubNodeIdSet subIds_;
341 const Node* node_ =
nullptr;
346 template <
class PreBasis,
class TP>
347 class NodeIdSet<PreBasis, TP, Dune::TypeTree::CompositeNodeTag>
350 using Node = Node_t<PreBasis,TP>;
351 using GridView =
typename PreBasis::GridView;
352 using size_type = std::size_t;
355 static const std::size_t children = Node::CHILDREN;
356 using ChildIndices = std::make_index_sequence<children>;
359 template <std::
size_t I>
360 using SubPreBasis =
typename PreBasis::template SubPreBasis<I>;
362 template <std::
size_t I>
363 using SubTreePath = decltype(Dune::TypeTree::push_back(std::declval<TP>(), Dune::index_constant<I>{}));
365 template <std::
size_t I>
369 using IdsTuple = IndexMapTuple_t<std::make_index_sequence<children>, SubNodeIdSet>;
373 : idsTuple_(Ranges::applyIndices<children>([&](
auto... i) {
374 return std::make_tuple(SubNodeIdSet<VALUE(i)>(gridView)...);
379 void bind(
const Node& node)
382 Ranges::forIndices<0,children>([&](
auto i) {
383 std::get<VALUE(i)>(idsTuple_).bind(node.child(i));
391 Ranges::forEach(idsTuple_, [](
auto& ids) {
397 size_type size()
const 399 return node_->size();
403 template <
class Twist,
class It>
404 It fillIn(
Twist const& twist, It it, size_type shift = 0)
const 406 assert(node_ !=
nullptr);
407 Ranges::forEach(idsTuple_, [&](
auto const& ids)
409 size_type subTreeSize = ids.size();
410 it = ids.fillIn(twist, it, shift);
411 shift += subTreeSize;
418 const Node* node_ =
nullptr;
422 template <
class GV,
class MI,
bool HI,
class TP>
423 class NodeIdSet<Dune::Functions::TaylorHoodPreBasis<GV,MI,HI>, TP, Dune::TypeTree::CompositeNodeTag>
426 using PreBasis = Dune::Functions::TaylorHoodPreBasis<GV,MI,HI>;
427 using Node = Node_t<PreBasis,TP>;
428 using GridView =
typename PreBasis::GridView;
429 using size_type = std::size_t;
432 using PTP = decltype(Dune::TypeTree::push_back(std::declval<TP>(), Dune::index_constant<1>{}));
433 using VTP = decltype(Dune::TypeTree::push_back(std::declval<TP>(), Dune::index_constant<0>{}));
434 using V0TP = decltype(Dune::TypeTree::push_back(std::declval<VTP>(), std::size_t(0)));
437 using PQ1PreBasis =
typename NodeIndexSet_t<PreBasis,TP>::PQ1NodeIndexSet::PreBasis;
438 using PQ2PreBasis =
typename NodeIndexSet_t<PreBasis,TP>::PQ2NodeIndexSet::PreBasis;
444 static constexpr
int dow = GridView::dimensionworld;
448 : pq1NodeIdSet_(gridView)
449 , pq2NodeIdSet_(gridView)
453 void bind(
const Node& node)
456 using namespace Dune::Indices;
457 pq1NodeIdSet_.bind(node.child(_1));
458 pq2NodeIdSet_.bind(node.child(_0, 0));
464 pq1NodeIdSet_.unbind();
465 pq2NodeIdSet_.unbind();
470 size_type size()
const 472 return node_->size();
476 template <
class Twist,
class It>
477 It fillIn(
Twist const& twist, It it, size_type shift = 0)
const 479 assert(node_ !=
nullptr);
480 for (
int child = 0; child < dow; ++child) {
481 size_type subTreeSize = pq2NodeIdSet_.size();
482 it = pq2NodeIdSet_.fillIn(twist, it, shift);
483 shift += subTreeSize;
485 it = pq1NodeIdSet_.fillIn(twist, it, shift);
490 PQ1NodeIdSet pq1NodeIdSet_;
491 PQ2NodeIdSet pq2NodeIdSet_;
492 const Node* node_ =
nullptr;
496 template <
class GV,
int k,
class MI,
class TP>
497 class NodeIdSet<Dune::Functions::LagrangeDGPreBasis<GV, k, MI>, TP>
500 using PreBasis = Dune::Functions::LagrangeDGPreBasis<GV, k, MI>;
501 using Node = Node_t<PreBasis, TP>;
502 using GridView =
typename PreBasis::GridView;
503 using size_type = std::size_t;
506 : gridView_(gridView)
510 void bind(
const Node& node)
513 size_ = node_->finiteElement().size();
523 size_type size()
const 529 template <
class Twist,
class It>
530 It fillIn(
Twist const& , It it, size_type shift = 0)
const 532 assert(node_ !=
nullptr);
533 const auto& gridIdSet = gridView_.grid().globalIdSet();
534 auto elementId = gridIdSet.id(node_->element());
536 for (size_type i = 0; i < size_; ++i, ++it)
538 it->first = {elementId, shift + i};
539 it->second = node_->element().partitionType();
547 const Node* node_ =
nullptr;
IdType id(size_type i) const
Return the global unique ID of the ith DOF on the currently bound element in the basis tree...
Definition: GlobalIdSet.hpp:163
unsigned int get(Dune::LocalKey const &localKey, unsigned int size) const
Get the permutated local dof index, living on a subEntity of the bound element.
Definition: Twist.hpp:48
Definition: AdaptiveGrid.hpp:373
void error_exit(std::string const &str, Args &&... args)
print a message and exit
Definition: Output.hpp:142
Definition: FieldMatVec.hpp:12
Definition: GlobalIdSet.hpp:40
Provide global ids for all DOFs in a global basis.
Definition: GlobalIdSet.hpp:106
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Type of a global used used to represent DOFs uniquely.
Definition: GlobalIdSet.hpp:48
size_type size() const
The number of DOFs on the current element in the basis tree.
Definition: GlobalIdSet.hpp:156
void unbind()
Unbind the idset.
Definition: GlobalIdSet.hpp:242
PB PreBasis
Pre-basis providing the implementation details.
Definition: GlobalBasis.hpp:63
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:66
size_type size() const
Number of DOFs in this node.
Definition: GlobalIdSet.hpp:248
GlobalIdType & operator++()
Increment the second index only.
Definition: GlobalIdSet.hpp:60
void unbind()
unbind from the element
Definition: GlobalIdSet.hpp:150
PartitionType partitionType(size_type i) const
Return the partition type of the ith DOF on the currently bound element in the basis tree...
Definition: GlobalIdSet.hpp:178
It fillIn(Twist const &twist, It it, size_type shift=0) const
Maps from subtree index set [0..size-1] to a globally unique id in global basis.
Definition: GlobalIdSet.hpp:255
void bind(Element const &element)
Bind the IdSet to a grid element.
Definition: GlobalIdSet.hpp:140
void bind(const Node &node)
Bind the idset to a tree node.
Definition: GlobalIdSet.hpp:226
EntityIdType entityId(size_type i) const
Return the global unique ID of the entity associated to the ith DOF on the currently bound element in...
Definition: GlobalIdSet.hpp:171