LocalAssembler.hpp 2.89 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once

// std c++ headers
#include <memory>

// AMDiS includes
#include <dune/amdis/QuadratureRules.hpp>
#include <dune/amdis/common/TypeDefs.hpp>

namespace AMDiS
{
  // the LocalContext is either an Codim=0-EntityType or an IntersectionType
  template <class GridView, class LocalContext>
  class LocalAssembler
  {
    static constexpr int dim = GridView::dimension;
    using ctype = typename GridView::ctype;

    using LocalQuadratureRules = Dune::QuadratureRules<ctype, LocalContext::mydimension>;
    using QuadratureRule = QuadratureRuleFactory_t<LocalContext, ctype, dim>;
21
22
23

    using Geometry = typename GridView::template Codim<0>::Entity::Geometry;
    using LocalGeometry = typename Impl::Get<LocalContext>::Geometry;
24
25

  public:
26
    explicit LocalAssembler(int degree, FirstOrderType type = GRD_PHI)
27
28
29
30
      : degree_(degree)
      , type_(type)
    {}

31
32
33
    /// Constructor, initializes the geometry of the element and a
    /// quadrature-rule wrapper
    template <class Operator>
34
    void bind(Operator& op, LocalContext const& localContext, Geometry const& geometry, LocalGeometry const& localGeometry)
35
    {
36
37
38
39
40
41
42
43
44
      localContext_ = &localContext;
      geometry_ = &geometry;
      localGeometry_ = &localGeometry;

      int order = op.getQuadratureDegree(localGeometry.type(), localGeometry, degree_, type_);
      auto const& quad = LocalQuadratureRules::rule(localGeometry.type(), order);

      quadrature_.reset(new QuadratureRule(localContext, quad));
    }
45

46
47
48
49
50
    void unbind()
    {
      localContext_ = nullptr;
      geometry_ = nullptr;
      localGeometry_ = nullptr;
51
52
53
54
55
56
57
58
59
60
61
    }

    /// \brief Returns reference to the transformed quadrature rule
    /**
     * For intersections this corresponds to the points in the intersection
     * geometry, but coordinates extended to the whole inside-entity. For
     * elements this is a wrapper around the classical element quadrature rule.
     * Access the underlying dune-quadrature rule, with `quadrature->getRule()`.
     **/
    QuadratureRule const& getQuadrature() const
    {
62
63
64
65
66
67
68
69
      assert( quadrature_ );
      return *quadrature_;
    }

    LocalContext const& getLocalContext() const
    {
      assert( localContext_ );
      return *localContext_;
70
71
72
73
    }

    Geometry const& getGeometry() const
    {
74
75
      assert( geometry_ );
      return *geometry_;
76
77
    }

78
79
80
81
82
    LocalGeometry const& getLocalGeometry() const
    {
      assert( localGeometry_ );
      return *localGeometry_;
    }
83
84

    template <class Coordinate>
85
    decltype(auto) getLocal(Coordinate const& p) const
86
    {
87
      return get_position<LocalContext>(getLocalGeometry(), p);
88
89
90
    }

  private:
91
92
    int degree_;
    FirstOrderType type_;
93

94
95
96
97
98
99
    LocalContext const* localContext_ = nullptr;
    Geometry const* geometry_ = nullptr;
    LocalGeometry const* localGeometry_ = nullptr;

    /// transformed quadrature rule
    std::shared_ptr<QuadratureRule const> quadrature_;
100
101
102
  };

} // end namespace AMDiS