ProblemStatTraits.hpp 5.21 KB
Newer Older
1
2
3
4
#pragma once

#include <tuple>

5
6
#include <dune/functions/functionspacebases/basistags.hh>
#include <dune/functions/functionspacebases/compositebasis.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
7
8
#include <dune/functions/functionspacebases/flatmultiindex.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
9
#include <dune/functions/functionspacebases/powerbasis.hh>
10
11
#include <dune/functions/functionspacebases/pqknodalbasis.hh>
#include <dune/grid/yaspgrid.hh>
12

Praetorius, Simon's avatar
Praetorius, Simon committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
namespace Dune {
namespace Functions {
namespace BasisFactory {

  // define the basis-build (factory-tag) for a given pre-basis
  template <class PreBasis>
  struct FactoryTag;

  template <class MultiIndex, class IndexMergingStrategy, class... ChildPreBasisFactory>
  struct FactoryTag<CompositePreBasis<MultiIndex, IndexMergingStrategy, ChildPreBasisFactory...>>
  {
    using type = Imp::CompositePreBasisFactory<IndexMergingStrategy, typename FactoryTag<ChildPreBasisFactory>::type...>;
  };

  template <class MultiIndex, class IndexMergingStrategy, class ChildPreBasisFactory, std::size_t C>
  struct FactoryTag<PowerPreBasis<MultiIndex, IndexMergingStrategy, ChildPreBasisFactory, C>>
  {
    using type = Imp::PowerPreBasisFactory<C, IndexMergingStrategy, typename FactoryTag<ChildPreBasisFactory>::type>;
  };

  template <class GridView, int k, class MultiIndex>
  struct FactoryTag<PQkPreBasis<GridView, k, MultiIndex>>
  {
    using type = Imp::PQkPreBasisFactory<k>;
  };

}}} // end namespace Dune::Functions::BasisFactory

41
42
namespace AMDiS
{
43
  namespace Impl
44
  {
45
    template <class GridView, bool same, int... deg>
Praetorius, Simon's avatar
Praetorius, Simon committed
46
    struct LagrangeBasisCreatorImpl;
47
48

    // specialization for composite basis
49
    template <class GridView, int... deg>
Praetorius, Simon's avatar
Praetorius, Simon committed
50
    struct LagrangeBasisCreatorImpl<GridView, false, deg...>
51
    {
52
      using MultiIndex = Dune::ReservedVector<std::size_t,1>;
Praetorius, Simon's avatar
Praetorius, Simon committed
53
      using IndexTag = Dune::Functions::BasisFactory::FlatLexicographic;
54

Praetorius, Simon's avatar
Praetorius, Simon committed
55
56
      using type = Dune::Functions::CompositePreBasis<MultiIndex, IndexTag,
        Dune::Functions::PQkPreBasis<GridView,deg,MultiIndex>...>;
57
58
59
60
    };

    // specialization for power basis
    template <class GridView, int deg, int... degs>
Praetorius, Simon's avatar
Praetorius, Simon committed
61
    struct LagrangeBasisCreatorImpl<GridView, true, deg, degs...>
62
63
    {
      using MultiIndex = Dune::ReservedVector<std::size_t,1>;
Praetorius, Simon's avatar
Praetorius, Simon committed
64
      using IndexTag = Dune::Functions::BasisFactory::FlatLexicographic;
65

Praetorius, Simon's avatar
Praetorius, Simon committed
66
67
      using type = Dune::Functions::PowerPreBasis<MultiIndex, IndexTag,
        Dune::Functions::PQkPreBasis<GridView,deg,MultiIndex>, 1 + sizeof...(degs)>;
68
69
70
71
    };

    // factory to construct a global basis of several lagrange bases, with flat indexing.
    template <class GridView, int deg, int... degs>
Praetorius, Simon's avatar
Praetorius, Simon committed
72
    struct LagrangeBasisCreator
73
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
74
      using type = typename LagrangeBasisCreatorImpl<GridView, and_t<(deg == degs)...>::value, deg, degs...>::type;
75
76
77
    };


Praetorius, Simon's avatar
Praetorius, Simon committed
78
79
    template <class GridView, int k>
    struct TaylorHoodBasisCreator
80
81
    {
      using MultiIndex = Dune::ReservedVector<std::size_t,1>;
Praetorius, Simon's avatar
Praetorius, Simon committed
82
      using IndexTagV = Dune::Functions::BasisFactory::FlatInterleaved;
83

Praetorius, Simon's avatar
Praetorius, Simon committed
84
85
      using VelocityPreBasis = Dune::Functions::PowerPreBasis<MultiIndex, IndexTagV,
        Dune::Functions::PQkPreBasis<GridView,k+1,MultiIndex>, GridView::dimensionworld>;
86

Praetorius, Simon's avatar
Praetorius, Simon committed
87
      using PressurePreBasis = Dune::Functions::PQkPreBasis<GridView,k,MultiIndex>;
88

Praetorius, Simon's avatar
Praetorius, Simon committed
89
90
91
      using IndexTag = Dune::Functions::BasisFactory::FlatLexicographic;
      using type = Dune::Functions::CompositePreBasis<MultiIndex, IndexTag,
        VelocityPreBasis, PressurePreBasis>;
92
    };
93

94
  } // end namespace Impl
95

Praetorius, Simon's avatar
Praetorius, Simon committed
96
97
98
  /// An Exemplar for ProblemStatTraits
  template <class GlobalBasisType>
  class DefaultProblemTraits
99
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
100
101
102
  public:
    /// A global-basis of type dune-functions DefaultGlobalBasis<NodeFactory>
    using GlobalBasis = GlobalBasisType;
103
  };
104

Praetorius, Simon's avatar
Praetorius, Simon committed
105
106
107
108
109
110
111
112
  /// \brief ProblemStatTraits for a (composite) basis composed of
  /// lagrange bases of different degree.
  template <class GridView, int... degrees>
  struct LagrangeBasis
      : public DefaultProblemTraits<
          Dune::Functions::DefaultGlobalBasis<
            typename Impl::LagrangeBasisCreator<GridView, degrees...>::type> >
  {};
113

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

Praetorius, Simon's avatar
Praetorius, Simon committed
121
122
123
  /// \brief ProblemStatTraits of Taylor-Hood basis of lagrange-type
  /// with pressure degree k
  template <class GridView, int k = 1>
124
  struct TaylorHoodBasis
Praetorius, Simon's avatar
Praetorius, Simon committed
125
126
127
128
      : public DefaultProblemTraits<
          Dune::Functions::DefaultGlobalBasis<
            typename Impl::TaylorHoodBasisCreator<GridView,k>::type> >
  {};
129

Praetorius, Simon's avatar
Praetorius, Simon committed
130
131
132
  using Dune::Functions::BasisFactory::makeBasis;
  using Dune::Functions::BasisFactory::lagrange;
  using Dune::Functions::BasisFactory::pq;
133

Praetorius, Simon's avatar
Praetorius, Simon committed
134
135
  template <std::size_t k, class ChildPBF>
  auto repeat(ChildPBF&& childPreBasisFactory)
136
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
137
138
139
140
    return Dune::Functions::BasisFactory::power<k>(
      std::forward<ChildPBF>(childPreBasisFactory),
      Dune::Functions::BasisFactory::flatInterleaved());
  }
141

Praetorius, Simon's avatar
Praetorius, Simon committed
142
143
  template <class... Args>
  auto compose(Args&&... args)
144
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
145
146
147
    return Dune::Functions::BasisFactory::composite(
      std::forward<Args>(args)...,
      Dune::Functions::BasisFactory::flatLexicographic());
148
  }
149

150
} // end namespace AMDiS