DiscreteFunction.hpp 4.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once

#include <vector>

#include <dune/common/std/optional.hh>
#include <dune/functions/common/defaultderivativetraits.hh>
#include <dune/functions/functionspacebases/defaultnodetorangemap.hh>
#include <dune/functions/functionspacebases/flatvectorview.hh>
#include <dune/functions/gridfunctions/gridviewentityset.hh>
#include <dune/typetree/childextraction.hh>

#include <amdis/GridFunctions.hpp>
13
#include <amdis/LinearAlgebra.hpp>
14
#include <amdis/typetree/FiniteElementType.hpp>
15
#include <amdis/typetree/RangeType.hpp>
16
#include <amdis/typetree/TreePath.hpp>
17
18
19

namespace AMDiS
{
20
  /// \class DiscreteFunction
21
22
23
  /// \brief A view on a subspace of a \ref DOFVector
  /**
   * \ingroup GridFunctions
24
   *
25
   * \tparam GB  Type of the global basis
26
   * \tparam VT  Coefficient type of the DOFVector
27
28
29
30
   * \tparam TP  A realization of \ref Dune::TypeTree::HybridTreePath
   *
   * **Requirements:**
   * - GB models \ref Dune::Functions::Concept::GlobalBasis
31
   **/
32
  template <class GB, class VT, class TP>
33
34
  class DiscreteFunction
  {
35
36
37
38
39
    static_assert(std::is_arithmetic<VT>::value, "");

  private:
    using GlobalBasis = GB;
    using TreePath = TP;
40
41
42
43
44
45
46

    using Tree = typename GlobalBasis::LocalView::Tree;
    using SubTree = typename Dune::TypeTree::ChildForTreePath<Tree, TreePath>;
    using NodeToRangeEntry = Dune::Functions::DefaultNodeToRangeMap<SubTree>;

    using GridView = typename GlobalBasis::GridView;

47
  public:
48
49
50
    /// Set of entities the DiscreteFunction is defined on
    using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;

51
    /// Global coordinates of the EntitySet
52
53
    using Domain = typename EntitySet::GlobalCoordinate;

54
55
    /// Range type of this DiscreteFunction
    using Range = RangeType_t<SubTree,VT>;
56

57
58
    /// \brief This GridFunction has no derivative function, it can be created
    /// by \ref DiscreteGridFunction.
59
60
    enum { hasDerivative = false };

61
62
63
  public:
    /// A LocalFunction representing the derivative of the DOFVector on a bound element
    class GradientLocalFunction;
64

65
    /// A LocalFunction representing the value the DOFVector on a bound element
66
    class LocalFunction;
67
68

  public:
69
70
71
72
73
    /// Constructor forwards to the treePath constructor, with empty TreePath
    DiscreteFunction(DOFVector<GB,VT> const& dofVector)
      : DiscreteFunction{dofVector, Dune::TypeTree::hybridTreePath()}
    {}

74
    /// Constructor. Stores a pointer to the dofVector and a copy of the treePath.
75
    DiscreteFunction(DOFVector<GB,VT> const& dofVector, TP const& treePath)
76
77
78
79
80
81
      : dofVector_(&dofVector)
      , treePath_(treePath)
      , entitySet_(dofVector.basis().gridView())
      , nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(dofVector.basis(), treePath))
    {}

82
    /// \brief Evaluate DiscreteFunction in global coordinates. NOTE: expensive
83
84
85
86
87
88
89
90
    Range operator()(Domain const& x) const;

    /// \brief Create a local function for this view on the DOFVector. \relates LocalFunction
    friend LocalFunction localFunction(DiscreteFunction const& self)
    {
      return LocalFunction{self};
    }

91
    /// \brief Return a \ref Dune::Functions::GridViewEntitySet
92
93
94
95
96
97
    EntitySet const& entitySet() const
    {
      return entitySet_;
    }

  public:
98
    /// \brief Return global basis bound to the DOFVector
99
100
101
102
103
    GlobalBasis const& basis() const
    {
      return dofVector_->basis();
    }

104
    /// \brief Return treePath associated with this discrete function
105
106
107
108
109
    TreePath const& treePath() const
    {
      return treePath_;
    }

110
111
    /// \brief Return const coefficient vector
    DOFVector<GB,VT> const& coefficients() const
112
113
114
115
116
    {
      return *dofVector_;
    }

  protected:
117
118
    DOFVector<GB,VT> const* dofVector_;
    TreePath treePath_;
119
120
121
122
    EntitySet entitySet_;
    NodeToRangeEntry nodeToRangeEntry_;
  };

123
124
125
126
127
128
129
130

#if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
  // Deduction guide for DiscreteFunction class
  template <class GlobalBasis, class ValueType>
  DiscreteFunction(DOFVector<GlobalBasis, ValueType> const& dofVector)
    -> DiscreteFunction<GlobalBasis, ValueType, Dune::TypeTree::HybridTreePath<>>;
#endif

131
  /// A Generator for a \ref DiscreteFunction
132
133
  template <class GlobalBasis, class ValueType, class PreTreePath>
  auto makeDiscreteFunction(DOFVector<GlobalBasis, ValueType> const& dofVector, PreTreePath const& preTreePath)
134
  {
135
136
    auto treePath = makeTreePath(preTreePath);
    return DiscreteFunction<GlobalBasis, ValueType, decltype(treePath)>{dofVector, treePath};
137
138
139
  }

  /// A Generator for a \ref DiscreteFunction
140
141
  template <class GlobalBasis, class ValueType>
  auto makeDiscreteFunction(DOFVector<GlobalBasis, ValueType> const& dofVector)
142
143
  {
    auto treePath = Dune::TypeTree::hybridTreePath();
144
    return DiscreteFunction<GlobalBasis, ValueType, Dune::TypeTree::HybridTreePath<>>{dofVector, treePath};
145
146
147
148
149
  }

} // end namespace AMDiS

#include "DiscreteFunction.inc.hpp"