FieldMatVec.hpp 2.3 KB
Newer Older
1
2
#pragma once

3
4
5
6
7
#include <amdis/common/FieldMatVec.hpp>
#include <amdis/operations/Arithmetic.hpp>
#include <amdis/operations/Basic.hpp>
#include <amdis/operations/CMath.hpp>
#include <amdis/operations/Composer.hpp>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

namespace AMDiS
{
  namespace Operation
  {
    /** \addtogroup operations
     *  @{
     **/

    /// (Binary-)Functor representing the euclidean dot-product
    struct Dot
    {
      template <class T0, class T1, int N>
      constexpr auto operator()(Dune::FieldVector<T0,N> const& lhs, Dune::FieldVector<T1,N> const& rhs) const
      {
23
        return lhs.dot(rhs);
24
25
      }

26
      friend constexpr int order(Dot const&, int d1, int d2)
27
28
29
30
      {
        return d1 + d2;
      }

31
      friend constexpr auto partial(Dot const&, index_t<0>)
32
      {
33
        return Arg<1>{};
34
35
      }

36
      friend constexpr auto partial(Dot const&, index_t<1>)
37
      {
38
        return Arg<0>{};
39
40
41
42
43
44
45
46
      }
    };

    // -------------------------------------------------------------------------

    /// (Unary-)Functor representing the euclidean dot-product
    struct UnaryDot
    {
47
48
      template <class V>
      constexpr auto operator()(V const& vec) const
49
      {
50
        using Dune::unary_dot;
51
52
53
        return unary_dot(vec);
      }

54
      friend constexpr int order(UnaryDot const&, int d)
55
56
57
58
      {
        return 2*d;
      }

59
      friend auto partial(UnaryDot const&, index_t<0>)
60
61
62
63
64
65
66
67
68
69
70
      {
        return compose(Multiplies{}, StaticConstant<int,2>{}, Id{});
      }
    };

    // -------------------------------------------------------------------------

    /// (Unary-)Functor representing the euclidean 2-norm
    struct TwoNorm
        : public Composer<Sqrt, UnaryDot>
    {
71
      constexpr TwoNorm()
72
73
74
        : Composer<Sqrt, UnaryDot>(Sqrt{}, UnaryDot{})
      {}

75
76
      template <class V>
      constexpr auto operator()(V const& vec) const
77
      {
78
        using Dune::two_norm;
79
80
81
82
        return two_norm(vec);
      }
    };

83
84
85
86
87
88
89
    // -------------------------------------------------------------------------

    struct Trans
    {
      template <class M>
      constexpr auto operator()(M const& mat) const
      {
90
        using Dune::trans;
91
92
93
        return trans(mat);
      }

94
      friend constexpr int order(Trans const&, int d)
95
96
97
98
99
100
      {
        return d;
      }
    };


101
102
103
104
    /** @} **/

  } // end namespace Operation
} // end namespace AMDiS