AMDiS  2.10
The Adaptive Multi-Dimensional Simulation Toolbox
ElementGridFunction.hpp
1 #pragma once
2 
3 #include <functional>
4 #include <type_traits>
5 
6 #include <dune/common/exceptions.hh>
7 #include <dune/functions/gridfunctions/gridviewentityset.hh>
8 
9 #include <amdis/common/DerivativeTraits.hpp>
10 #include <amdis/common/TypeTraits.hpp>
11 #include <amdis/gridfunctions/ConstantGridFunction.hpp>
12 #include <amdis/gridfunctions/GridFunction.hpp>
13 
14 namespace AMDiS
15 {
16 #ifndef DOXYGEN
17  template <class Signature, class IndexSet, class Container>
19 #endif
20 
22  template <class R, class D, class IndexSet, class Container>
23  class ElementLocalFunction<R(D), IndexSet, Container>
24  {
25  public:
27  using Domain = D;
28 
30  using Range = R;
31 
33  enum { hasDerivative = true };
34 
36  using Element = typename IndexSet::template Codim<0>::Entity;
37 
38  public:
40  ElementLocalFunction(IndexSet const& indexSet, Container const& container)
41  : indexSet_(&indexSet)
42  , container_(&container)
43  {}
44 
46  Element const& localContext() const
47  {
48  assert(!!element_);
49  return *element_;
50  }
51 
53  void bind(Element const& element)
54  {
55  element_.emplace(element);
56  value_ = (*container_)[indexSet_->index(element)];
57  }
58 
59  void unbind() {}
60 
62  bool bound() const
63  {
64  return !!element_;
65  }
66 
68  Range const& operator()(Domain const& /*local*/) const
69  {
70  return value_;
71  }
72 
75  template <class Type>
76  auto makeDerivative(Type const& /*type*/) const
77  {
78  using RawSignature = typename Dune::Functions::SignatureTraits<R(D)>::RawSignature;
79  using DerivativeRange = typename DerivativeTraits<RawSignature,Type>::Range;
80  DerivativeRange diff(0);
82  if (bound())
83  df.bind(*element_);
84  return df;
85  }
86 
88  int order() const
89  {
90  return 0;
91  }
92 
93  private:
94  IndexSet const* indexSet_;
95  Container const* container_;
96  std::optional<Element> element_;
97  Range value_ = 0;
98  };
99 
100 
102 
109  template <class GridView, class Container>
111  {
112  public:
113  using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
114  using Domain = typename EntitySet::GlobalCoordinate;
115  using Range = typename Container::value_type;
116 
117  enum { hasDerivative = false };
118 
119  private:
120  using LocalDomain = typename EntitySet::LocalCoordinate;
122 
123  public:
125  ElementGridFunction(GridView const& gridView, Container const& container)
126  : entitySet_(gridView)
127  , container_(&container)
128  {}
129 
131  Range operator()(Domain const& /*x*/) const
132  {
133  DUNE_THROW(Dune::NotImplemented, "Global evaluation not yet implemented");
134  return Range(0);
135  }
136 
137  EntitySet const& entitySet() const
138  {
139  return entitySet_;
140  }
141 
144  {
145  return {entitySet_.gridView().indexSet(), *container_};
146  }
147 
148  private:
149  EntitySet entitySet_;
150  Container const* container_;
151  };
152 
154  template <class G, class T>
155  auto valueOf(ElementVector<G,T> const& ev)
156  {
157  return ElementGridFunction{ev.gridView(), ev.data()};
158  }
159 
160 } // end namespace AMDiS
D Domain
The LocalDomain this LocalFunction can be evaluated in.
Definition: ElementGridFunction.hpp:27
auto gridView() const
Return the GridView the data is defined on.
Definition: ElementVector.hpp:57
void bind(Element const &element)
Extract the constant data associated to the element.
Definition: ElementGridFunction.hpp:53
typename IndexSet::template Codim< 0 >::Entity Element
Type of the entity to bind.
Definition: ElementGridFunction.hpp:36
ElementGridFunction(GridView const &gridView, Container const &container)
Constructor. Stores the function fct and creates an EntitySet.
Definition: ElementGridFunction.hpp:125
Definition: ConstantGridFunction.hpp:19
Range const & operator()(Domain const &) const
Return the constant value_.
Definition: ElementGridFunction.hpp:68
int order() const
Return the constant polynomial order 0.
Definition: ElementGridFunction.hpp:88
Range operator()(Domain const &) const
Return the constant value_
Definition: ElementGridFunction.hpp:131
Data const & data() const
Get a const-ref to the internal data vector.
Definition: ElementVector.hpp:63
R Range
The range type of the LocalFunction.
Definition: ElementGridFunction.hpp:30
Definition: AdaptBase.hpp:6
An adaptive container that stores a value per grid element.
Definition: ElementVector.hpp:21
ElementLocalFunction(IndexSet const &indexSet, Container const &container)
Constructor. Stores the constant value.
Definition: ElementGridFunction.hpp:40
Element const & localContext() const
Return the bound element.
Definition: ElementGridFunction.hpp:46
auto makeDerivative(Type const &) const
Create a ConstantLocalFunction representing the derivative of a constant function, that ist, the value 0.
Definition: ElementGridFunction.hpp:76
Gridfunction returning a constant value per element.
Definition: ElementGridFunction.hpp:110
Definition: ElementGridFunction.hpp:18
Definition: DerivativeTraits.hpp:29
LocalFunction makeLocalFunction() const
Create an ElementLocalFunction.
Definition: ElementGridFunction.hpp:143
bool bound() const
Check whether this localfunction is bound to an element.
Definition: ElementGridFunction.hpp:62