OperatorTermBase.hpp 3.68 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
    using QuadratureRule = QuadratureRuleFactory_t<Element,double,dim>;
27

28
  public:
29
    // operator-terms, when used in operators, must implement this method
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>
57
  {
58
    using Super = OperatorTerm<Element>;
59
    using QuadratureRule = typename Super::QuadratureRule;
60

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

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

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

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

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

87
    virtual double evalFot1(std::size_t iq,
88
        Dune::FieldVector<double,1> const& test,
89
        Dune::FieldVector<double,dow> const& grad_trial) const override
90
    {
91
      return Evaluate::fot(_cat{}, traits, term[iq], grad_trial, test);
92
    }
93

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

101
    virtual double evalSot(std::size_t iq,
102
103
        Dune::FieldVector<double,dow> const& grad_test,
        Dune::FieldVector<double,dow> const& grad_trial) const override
104
    {
105
      return Evaluate::sot(_cat{}, traits, term[iq], grad_test, grad_trial);
106
    }
107
108

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

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

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

120
    // std::vector<value_type> values; // NOTE: maybe caching is not necessary here, since cached already in the term
121
  };
122

123
} // end namespace AMDiS