OperatorTermBase.hpp 3.76 KB
Newer Older
1
2
#pragma once

3
4
5
6
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

7
8
#include <vector>
#include <type_traits>
9

10
#include <dune/amdis/QuadratureRules.hpp>
11

12
13
#include <dune/amdis/OperatorEvaluation.hpp>
#include <dune/amdis/common/ValueCategory.hpp>
14
#include <dune/amdis/utility/GetEntity.hpp>
15

16
namespace AMDiS
17
{
18
  /// Abstract base class of all operator terms
19
  template <class Element>
20
21
22
  class OperatorTerm
  {
  protected:
23
24
    static constexpr int dim = Element::dimension;
    static constexpr int dow = Element::Geometry::coorddimension;
25

26
27
    using QuadratureRule = QuadratureRuleFactory_t<Element,double,dim>;
    // using PointList = std::vector<Dune::QuadraturePoint<double, dim>>;
28

29
  public:
30
    virtual void init(Element const& element, QuadratureRule const& points) = 0;
31

32
    virtual double evalZot(std::size_t iq,
33
        Dune::FieldVector<double,1> const& test,
34
        Dune::FieldVector<double,1> const trial = 1.0) const = 0;
35

36
    virtual double evalFot1(std::size_t iq,
37
        Dune::FieldVector<double,1> const& test,
38
        Dune::FieldVector<double,dow> const& grad_trial) const = 0;
39

40
    virtual double evalFot2(std::size_t iq,
41
        Dune::FieldVector<double,dow> const& grad_test,
42
        Dune::FieldVector<double,1> const trial = 1.0) const = 0;
43

44
    virtual double evalSot(std::size_t iq,
45
46
        Dune::FieldVector<double,dow> const& grad_test,
        Dune::FieldVector<double,dow> const& grad_trial) const = 0;
47
48

    virtual int getDegree(Dune::GeometryType const& t) const = 0;
49
  };
50
51
52



53
  /// Base class for all operators based on expressions
54
  template <class Element, class Term, class Traits = tag::none>
55
  class GenericOperatorTerm
56
      : public OperatorTerm<Element>
Praetorius, Simon's avatar
Praetorius, Simon committed
57
      , public OperatorEvaluation // NOTE: better: use static functions
58
  {
59
60
    using Super   = OperatorTerm<Element>;
    using QuadratureRule = typename Super::QuadratureRule;
61

62
63
    static constexpr int dim = Super::dim;
    static constexpr int dow = Super::dow;
64
65

  public:
66
    GenericOperatorTerm(Term const& term, Traits traits = {})
67
      : term(term)
68
      , traits(traits)
69
70
    {}

71
    virtual void init(Element const& element, QuadratureRule const& points) override
72
    {
73
      term.init(get_entity(element), points);
74

75
76
      // cache term evaluation
      values.resize(points.size());
77
      for (std::size_t iq = 0; iq < points.size(); ++iq)
78
79
        values[iq] = term[iq];
    }
80

81
    virtual double evalZot(std::size_t iq,
82
        Dune::FieldVector<double,1> const& test,
83
84
        Dune::FieldVector<double,1> const trial = 1.0) const override
    {
85
      return this->evalZotImpl(_cat{}, traits, values[iq], test, trial);
86
    }
87

88
    virtual double evalFot1(std::size_t iq,
89
        Dune::FieldVector<double,1> const& test,
90
        Dune::FieldVector<double,dow> const& grad_trial) const override
91
    {
92
      return this->evalFotImpl(_cat{}, traits, values[iq], grad_trial, test);
93
    }
94

95
    virtual double evalFot2(std::size_t iq,
96
        Dune::FieldVector<double,dow> const& grad_test,
97
98
        Dune::FieldVector<double,1> const trial = 1.0) const override
    {
99
      return this->evalFotImpl(_cat{}, traits, values[iq], grad_test, trial);
100
    }
101

102
    virtual double evalSot(std::size_t iq,
103
104
        Dune::FieldVector<double,dow> const& grad_test,
        Dune::FieldVector<double,dow> const& grad_trial) const override
105
    {
106
      return this->evalSotImpl(_cat{}, traits, values[iq], grad_test, grad_trial);
107
    }
108
109

    virtual int getDegree(Dune::GeometryType const& t) const override
110
    {
111
      return term.getDegree(t);
112
    }
113

114
115
  private:
    Term term;
116
    Traits traits;
117

118
    using value_type = std::decay_t< decltype( std::declval<Term>()[std::size_t(0)] ) >;
Praetorius, Simon's avatar
Praetorius, Simon committed
119
    using _cat = ValueCategory_t<value_type>;
120

Praetorius, Simon's avatar
Praetorius, Simon committed
121
    std::vector<value_type> values; // NOTE: maybe caching is not necessary here, since cached already in the term
122
  };
123

124
} // end namespace AMDiS