ProblemStatTraits.hpp 3.8 KB
Newer Older
1
2
#pragma once

3
4
#include <dune/functions/functionspacebases/basistags.hh>
#include <dune/functions/functionspacebases/compositebasis.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
5
#include <dune/functions/functionspacebases/lagrangebasis.hh>
6
#include <dune/functions/functionspacebases/powerbasis.hh>
7
#include <dune/grid/yaspgrid.hh>
8

9
#include <amdis/AdaptiveGrid.hpp>
10
#include <amdis/common/Logical.hpp>
11
12
#include <amdis/common/TypeTraits.hpp>
#include <amdis/functions/ParallelGlobalBasis.hpp>
Praetorius, Simon's avatar
Praetorius, Simon committed
13

14
15
namespace AMDiS
{
16
  namespace Impl
17
  {
18
19
    template <bool same, int... degs>
    struct LagrangePreBasisCreatorImpl;
20

21
22
23
24
25
26
27
28
29
30
31
    // specialization for single node basis
    template <int deg>
    struct LagrangePreBasisCreatorImpl<true, deg>
    {
      static auto create()
      {
        using namespace Dune::Functions::BasisFactory;
        return lagrange<deg>();
      }
    };

32
    // specialization for composite basis
33
34
    template <int... degs>
    struct LagrangePreBasisCreatorImpl<false, degs...>
35
    {
36
37
38
39
40
      static auto create()
      {
        using namespace Dune::Functions::BasisFactory;
        return composite(lagrange<degs>()..., flatLexicographic());
      }
41
42
43
    };

    // specialization for power basis
44
45
    template <int deg, int... degs>
    struct LagrangePreBasisCreatorImpl<true, deg, degs...>
46
    {
47
48
49
50
51
      static auto create()
      {
        using namespace Dune::Functions::BasisFactory;
        return power<1+sizeof...(degs)>(lagrange<deg>(), flatLexicographic());
      }
52
53
54
    };

    // factory to construct a global basis of several lagrange bases, with flat indexing.
55
56
57
58
    template <int deg, int... degs>
    struct LagrangePreBasisCreator
        : public LagrangePreBasisCreatorImpl<all_of_v<(deg == degs)...>, deg, degs...>
    {};
59
60


61
62
    template <int dow, int k = 1>
    struct TaylorHoodPreBasisCreator
63
    {
64
65
66
67
68
      static auto create()
      {
        using namespace Dune::Functions::BasisFactory;
        return composite(power<dow>(lagrange<k+1>(), flatInterleaved()), lagrange<k>(), flatLexicographic());
      }
69
    };
70

71
  } // end namespace Impl
72

Praetorius, Simon's avatar
Praetorius, Simon committed
73
74
75
76

  /// Wrapper around a global basis providing default traits
  template <class GB, class T = double,
            template <class> class TraitsImpl = BackendTraits>
77
  struct DefaultProblemTraits
78
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
79
    using GlobalBasis = GB;
80
    using CoefficientType = T;
Praetorius, Simon's avatar
Praetorius, Simon committed
81
    using LinAlgTraits = TraitsImpl<GB>;
82
  };
83

Praetorius, Simon's avatar
Praetorius, Simon committed
84
85
86
  /// Generator for a basis and default problem traits
  template <class HostGrid, class PreBasisCreator, class T = double,
            template <class> class TraitsImpl = BackendTraits>
87
88
  struct DefaultBasisCreator
  {
89
    using Grid = AdaptiveGrid_t<HostGrid>;
90
    using GridView = typename Grid::LeafGridView;
Praetorius, Simon's avatar
Praetorius, Simon committed
91

92
93
94
95
96
    static auto create(std::string const& name, GridView const& gridView)
    {
      return makeGlobalBasis(name, gridView, PreBasisCreator::create());
    }

97
98
    static auto create(GridView const& gridView)
    {
99
      return makeGlobalBasis(gridView, PreBasisCreator::create());
100
101
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
102
    using GlobalBasis = decltype(create(std::declval<GridView>()));
103
    using CoefficientType = T;
Praetorius, Simon's avatar
Praetorius, Simon committed
104
    using LinAlgTraits = TraitsImpl<GlobalBasis>;
105
106
  };

Praetorius, Simon's avatar
Praetorius, Simon committed
107

Praetorius, Simon's avatar
Praetorius, Simon committed
108
109
  /// \brief ProblemStatTraits for a (composite) basis composed of
  /// lagrange bases of different degree.
110
  template <class Grid, int... degrees>
Praetorius, Simon's avatar
Praetorius, Simon committed
111
  struct LagrangeBasis
112
      : public DefaultBasisCreator<Grid, Impl::LagrangePreBasisCreator<degrees...>>
Praetorius, Simon's avatar
Praetorius, Simon committed
113
  {};
114

Praetorius, Simon's avatar
Praetorius, Simon committed
115
116
  /// \brief Specialization of \ref LagrangeBasis for Grid type
  /// \ref Dune::YaspGrid for a given dimension.
117
  template <int dim, int... degrees>
118
  struct YaspGridBasis
119
      : public LagrangeBasis<Dune::YaspGrid<dim>, degrees...>
Praetorius, Simon's avatar
Praetorius, Simon committed
120
  {};
121

Praetorius, Simon's avatar
Praetorius, Simon committed
122
123
  /// \brief ProblemStatTraits of Taylor-Hood basis of lagrange-type
  /// with pressure degree k
124
  template <class Grid, int k = 1>
125
  struct TaylorHoodBasis
126
      : public DefaultBasisCreator<Grid, Impl::TaylorHoodPreBasisCreator<Grid::dimensionworld,k>>
Praetorius, Simon's avatar
Praetorius, Simon committed
127
  {};
128

129
} // end namespace AMDiS