AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
LocalView.hpp
1 #pragma once
2 
3 #include <tuple>
4 #include <optional>
5 #include <vector>
6 
7 #include <dune/common/concept.hh>
8 #include <dune/functions/functionspacebases/concepts.hh>
9 
10 #include <amdis/common/TypeTraits.hpp>
11 #include <amdis/functions/NodeCache.hpp>
12 #include <amdis/functions/Nodes.hpp>
13 
14 // NOTE: This is a variant of dune-functions DefaultLocalView
15 
16 namespace AMDiS
17 {
19  template <class GB>
20  class LocalView
21  {
22  using PrefixPath = Dune::TypeTree::HybridTreePath<>;
23 
24  // Node index set provided by PreBasis
25  using NodeIndexSet = NodeIndexSet_t<typename GB::PreBasis, PrefixPath>;
26 
27  public:
29  using GlobalBasis = GB;
30 
32  using GridView = typename GlobalBasis::GridView;
33 
35  using Element = typename GridView::template Codim<0>::Entity;
36 
38  using size_type = std::size_t;
39 
41  using Tree = Node_t<typename GlobalBasis::PreBasis, PrefixPath>;
42 
45 
48 
49  private:
50  template <class NIS, class Iter>
51  using hasIndices = decltype(std::declval<NIS>().indices(std::declval<Iter>()));
52 
53  public:
56  : globalBasis_(&globalBasis)
57  , tree_(makeNode(globalBasis_->preBasis(), PrefixPath{}))
58  , treeCache_(makeNodeCache(tree_))
59  , nodeIndexSet_(makeNodeIndexSet(globalBasis_->preBasis(), PrefixPath{}))
60  {
61  static_assert(Dune::models<Dune::Functions::Concept::BasisTree<GridView>, Tree>());
62  initializeTree(tree_);
63  }
64 
66  // NOTE: needs to be implemented manually, because of the reference dependency
67  // between members tree_ and treeCache_
68  LocalView (LocalView const& other)
69  : globalBasis_(other.globalBasis_)
70  , tree_(other.tree_)
71  , treeCache_(makeNodeCache(tree_))
72  , nodeIndexSet_(other.nodeIndexSet_)
73  , element_(other.element_)
74  , indices_(other.indices_)
75  {}
76 
77  // Move constructor
78  // NOTE: needs to be implemented manually, because of the reference dependency
79  // between members tree_ and treeCache_
80  LocalView (LocalView&& other)
81  : globalBasis_(std::move(other.globalBasis_))
82  , tree_(std::move(other.tree_))
83  , treeCache_(makeNodeCache(tree_))
84  , nodeIndexSet_(std::move(other.nodeIndexSet_))
85  , element_(std::move(other.element_))
86  , indices_(std::move(other.indices_))
87  {}
88 
90 
95  void bind (Element const& element)
96  {
97  element_ = element;
98  bindTree(tree_, *element_);
99  nodeIndexSet_.bind(tree_);
100  indices_.resize(size());
101 
102  if constexpr (Dune::Std::is_detected_v<hasIndices, NodeIndexSet, TYPEOF(indices_.begin())>)
103  nodeIndexSet_.indices(indices_.begin());
104  else
105  for (size_type i = 0; i < size(); ++i)
106  indices_[i] = nodeIndexSet_.index(i);
107  }
108 
110  bool isBound () const
111  {
112  return bool(element_);
113  }
114 
116  Element const& element () const
117  {
118  return *element_;
119  }
120 
122 
125  void unbind ()
126  {
127  nodeIndexSet_.unbind();
128  element_.reset();
129  }
130 
132  Tree const& tree () const
133  {
134  return tree_;
135  }
136 
138  TreeCache const& treeCache () const
139  {
140  return treeCache_;
141  }
142 
144  size_type size () const
145  {
146  return tree_.size();
147  }
148 
150 
154  {
155  return globalBasis_->preBasis().maxNodeSize();
156  }
157 
161  {
162  return indices_[i];
163  }
164 
166  GlobalBasis const& globalBasis () const
167  {
168  return *globalBasis_;
169  }
170 
172  LocalView const& rootLocalView () const
173  {
174  return *this;
175  }
176 
177  protected:
178  GlobalBasis const* globalBasis_;
179  Tree tree_;
180  TreeCache treeCache_;
181  NodeIndexSet nodeIndexSet_;
182 
183  std::optional<Element> element_;
184  std::vector<MultiIndex> indices_;
185  };
186 
187 } // end namespace AMDiS
size_type size() const
Total number of degrees of freedom on this element.
Definition: LocalView.hpp:144
constexpr bool MultiIndex
A multi-index type.
Definition: Concepts.hpp:150
size_type maxSize() const
Maximum local size for any element on the GridView.
Definition: LocalView.hpp:153
typename GlobalBasis::GridView GridView
The grid view the global FE basis lives on.
Definition: LocalView.hpp:32
auto makeNodeCache(Node const &node)
Construct a new local-basis cache from a basis-node.
Definition: NodeCache.hpp:35
LocalView const & rootLocalView() const
Return this local-view.
Definition: LocalView.hpp:172
bool isBound() const
Return if the view is bound to a grid element.
Definition: LocalView.hpp:110
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
MultiIndex index(size_type i) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis...
Definition: LocalView.hpp:160
typename GridView::template Codim< 0 >::Entity Element
Type of the grid element we are bound to.
Definition: LocalView.hpp:35
The restriction of a finite element basis to a single element.
Definition: LocalView.hpp:20
typename Impl::NodeCacheFactory< Node >::type NodeCache_t
Defines the type of a node cache associated to a given Node.
Definition: NodeCache.hpp:31
Node_t< typename GlobalBasis::PreBasis, PrefixPath > Tree
Tree of local finite elements / local shape function sets.
Definition: LocalView.hpp:41
TreeCache const & treeCache() const
Cached version of the local ansatz tree.
Definition: LocalView.hpp:138
Tree const & tree() const
Return the local ansatz tree associated to the bound entity.
Definition: LocalView.hpp:132
GlobalBasis const & globalBasis() const
Return the global basis that we are a view on.
Definition: LocalView.hpp:166
Element const & element() const
Return the grid element that the view is bound to.
Definition: LocalView.hpp:116
LocalView(LocalView const &other)
Copy constructor.
Definition: LocalView.hpp:68
void bind(Element const &element)
Bind the view to a grid element.
Definition: LocalView.hpp:95
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:66
void unbind()
Unbind from the current element.
Definition: LocalView.hpp:125
typename NodeIndexSet::MultiIndex MultiIndex
Type used for global numbering of the basis vectors.
Definition: LocalView.hpp:47
LocalView(GlobalBasis const &globalBasis)
Construct local view for a given global finite element basis.
Definition: LocalView.hpp:55
GB GlobalBasis
The global FE basis that this is a view on.
Definition: LocalView.hpp:29
NodeCache_t< Tree > TreeCache
Cached basis-tree.
Definition: LocalView.hpp:44
std::size_t size_type
The type used for sizes.
Definition: LocalView.hpp:38