DiscreteFunction.hpp 4.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#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>

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

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

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

    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;

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

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

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

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

60
61
  public:
    /// A LocalFunction representing the derivative of the DOFVector on a bound element
62
63
64
    template <class Type>
    class DerivativeLocalFunctionBase;

65
    class GradientLocalFunction;
66
67
    class PartialLocalFunction;
    class DivergenceLocalFunction;
68

69
    /// A LocalFunction representing the value the DOFVector on a bound element
70
    class LocalFunction;
71
72
73

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

    /// Constructor forwards to the treePath constructor, with empty TreePath
    DiscreteFunction(DOFVector<GB,VT> const& dofVector)
      : DiscreteFunction(dofVector, Dune::TypeTree::hybridTreePath())
84
85
    {}

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

    /// \brief Create a local function for this view on the DOFVector. \relates LocalFunction
90
    LocalFunction makeLocalFunction() const
91
    {
92
      return LocalFunction{*this};
93
94
    }

95
    /// \brief Return a \ref Dune::Functions::GridViewEntitySet
96
97
98
99
100
101
    EntitySet const& entitySet() const
    {
      return entitySet_;
    }

  public:
102
    /// \brief Return global basis bound to the DOFVector
103
    std::shared_ptr<GlobalBasis const> basis() const
104
105
106
107
    {
      return dofVector_->basis();
    }

108
    /// \brief Return treePath associated with this discrete function
109
110
111
112
113
    TreePath const& treePath() const
    {
      return treePath_;
    }

114
115
    /// \brief Return const coefficient vector
    DOFVector<GB,VT> const& coefficients() const
116
117
118
119
120
    {
      return *dofVector_;
    }

  protected:
121
122
    DOFVector<GB,VT> const* dofVector_;
    TreePath treePath_;
123
124
125
126
    EntitySet entitySet_;
    NodeToRangeEntry nodeToRangeEntry_;
  };

127
128
129
130
131
132
133
134

#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

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

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

} // end namespace AMDiS

#include "DiscreteFunction.inc.hpp"