DiscreteFunction.hpp 4.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#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>
#include <amdis/utility/FiniteElementType.hpp>

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

  private:
    using GlobalBasis = GB;
    using TreePath = TP;
33
34
35
36
37
38
39

    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;

40
  public:
41
42
43
    /// Set of entities the DiscreteFunction is defined on
    using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;

44
    /// Global coordinates of the EntitySet
45
46
    using Domain = typename EntitySet::GlobalCoordinate;

47
48
    /// Range type of this DiscreteFunction
    using Range = RangeType_t<SubTree,VT>;
49

50
51
    /// \brief This GridFunction has no derivative function, it can be created
    /// by \ref DiscreteGridFunction.
52
53
    enum { hasDerivative = false };

54
55
56
  public:
    /// A LocalFunction representing the derivative of the DOFVector on a bound element
    class GradientLocalFunction;
57

58
59
    /// A LocalFunction representign the value the DOFVector on a bound element
    class LocalFunction;
60
61

  public:
62
63
64
65
66
    /// Constructor forwards to the treePath constructor, with empty TreePath
    DiscreteFunction(DOFVector<GB,VT> const& dofVector)
      : DiscreteFunction{dofVector, Dune::TypeTree::hybridTreePath()}
    {}

67
    /// Constructor. Stores a pointer to the dofVector and a copy of the treePath.
68
    DiscreteFunction(DOFVector<GB,VT> const& dofVector, TP const& treePath)
69
70
71
72
73
74
      : dofVector_(&dofVector)
      , treePath_(treePath)
      , entitySet_(dofVector.basis().gridView())
      , nodeToRangeEntry_(Dune::Functions::makeDefaultNodeToRangeMap(dofVector.basis(), treePath))
    {}

75
    /// \brief Evaluate DiscreteFunction in global coordinates. NOTE: expensive
76
77
78
79
80
81
82
83
    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};
    }

84
    /// \brief Return a \ref Dune::Functions::GridViewEntitySet
85
86
87
88
89
90
    EntitySet const& entitySet() const
    {
      return entitySet_;
    }

  public:
91
    /// \brief Return global basis bound to the DOFVector
92
93
94
95
96
    GlobalBasis const& basis() const
    {
      return dofVector_->basis();
    }

97
    /// \brief Return treePath associated with this discrete function
98
99
100
101
102
    TreePath const& treePath() const
    {
      return treePath_;
    }

103
104
    /// \brief Return const coefficient vector
    DOFVector<GB,VT> const& coefficients() const
105
106
107
108
109
    {
      return *dofVector_;
    }

  protected:
110
111
    DOFVector<GB,VT> const* dofVector_;
    TreePath treePath_;
112
113
114
115
    EntitySet entitySet_;
    NodeToRangeEntry nodeToRangeEntry_;
  };

116
117
118
119
120
121
122
123

#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

124
  /// A Generator for a \ref DiscreteFunction
125
126
  template <class GlobalBasis, class ValueType, class TreePath>
  auto makeDiscreteFunction(DOFVector<GlobalBasis, ValueType> const& dofVector, TreePath const& treePath)
127
  {
128
    return DiscreteFunction<GlobalBasis, ValueType, TreePath>{dofVector, treePath};
129
130
131
  }

  /// A Generator for a \ref DiscreteFunction
132
133
  template <class GlobalBasis, class ValueType>
  auto makeDiscreteFunction(DOFVector<GlobalBasis, ValueType> const& dofVector)
134
135
  {
    auto treePath = Dune::TypeTree::hybridTreePath();
136
    return DiscreteFunction<GlobalBasis, ValueType, Dune::TypeTree::HybridTreePath<>>{dofVector, treePath};
137
138
139
140
141
  }

} // end namespace AMDiS

#include "DiscreteFunction.inc.hpp"