FirstOrderTestPartialTrial.hpp 3.53 KB
Newer Older
1
2
3
4
#pragma once

#include <type_traits>

5
#include <dune/amdis/GridFunctionOperator.hpp>
6
7
8
9
10
#include <dune/amdis/Output.hpp>
#include <dune/amdis/common/ValueCategory.hpp>

namespace AMDiS
{
11
12
13
14
15
  /**
   * \addtogroup operators
   * @{
   **/

16
17
18
19
  namespace tag
  {
    struct test_partialtrial
    {
20
      std::size_t comp;
21
22
23
24
    };
  }


25
26
27
28
  /// first-order operator \f$ \langle\psi, c\,\partial_i\phi\rangle \f$
  template <class GridFct, class QuadCreator>
  class GridFunctionOperator<tag::test_partialtrial, GridFct, QuadCreator>
      : public GridFunctionOperatorBase<GridFct, QuadCreator>
29
  {
30
    using Super = GridFunctionOperatorBase<GridFct, QuadCreator>;
31

32
    static_assert( Category::Scalar<typename GridFct::Range>, "Expression must be of scalar type." );
33
34

  public:
35
36
    GridFunctionOperator(tag::test_partialtrial tag, GridFct const& expr, QuadCreator const& quadCreator)
      : Super(expr, quadCreator, 1)
37
38
39
40
41
42
43
44
45
46
47
48
49
      , comp_(tag.comp)
    {}

    template <class Context, class QuadratureRule,
              class ElementMatrix, class RowNode, class ColNode, bool sameFE, bool sameNode>
    void calculateElementMatrix(Context const& context,
                                QuadratureRule const& quad,
                                ElementMatrix& elementMatrix,
                                RowNode const& rowNode,
                                ColNode const& colNode,
                                std::integral_constant<bool, sameFE>,
                                std::integral_constant<bool, sameNode>)
    {
50
51
      static_assert(RowNode::isLeaf && ColNode::isLeaf,
        "Operator can be applied to Leaf-Nodes only.");
52
53
54
55
56
57
58
59
60
61
62
63

      auto const& rowLocalFE = rowNode.finiteElement();
      auto const& colLocalFE = colNode.finiteElement();

      for (std::size_t iq = 0; iq < quad.size(); ++iq) {
        // Position of the current quadrature point in the reference element
        decltype(auto) local = context.position(quad[iq].position());

        // The transposed inverse Jacobian of the map from the reference element to the element
        const auto jacobian = context.geometry.jacobianInverseTransposed(local);

        // The multiplicative factor in the integral transformation formula
64
65
        double factor = context.integrationElement(quad[iq].position()) * quad[iq].weight();
        double c = Super::coefficient(local);
66
67
68
69
70
71
72
73
74
75
76
77

        rowLocalFE.localBasis().evaluateFunction(local, rowShapeValues_);

        // The gradients of the shape functions on the reference element
        std::vector<Dune::FieldMatrix<double,1,Context::dim> > referenceGradients;
        colLocalFE.localBasis().evaluateJacobian(local, referenceGradients);

        // Compute the shape function gradients on the real element
        std::vector<double> colPartial(referenceGradients.size());

        for (std::size_t i = 0; i < colPartial.size(); ++i) {
          colPartial[i] = jacobian[comp_][0] * referenceGradients[i][0][0];
78
          for (std::size_t j = 1; j < jacobian.M(); ++j)
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
            colPartial[i] += jacobian[comp_][j] * referenceGradients[i][0][j];
        }

        for (std::size_t j = 0; j < colLocalFE.size(); ++j) {
          const int local_j = colNode.localIndex(j);
          double value = factor * (c * colPartial[j]);
          for (std::size_t i = 0; i < rowLocalFE.size(); ++i) {
            const int local_i = rowNode.localIndex(i);
            elementMatrix[local_i][local_j] += value * rowShapeValues_[i];
          }
        }
      }

    }

  private:
95
    std::size_t comp_;
96
97
98
    std::vector<Dune::FieldVector<double,1>> rowShapeValues_;
  };

99
100
  /** @} **/

101
} // end namespace AMDiS