SecondOrderPartialTestPartialTrial.hpp 4.34 KB
Newer Older
1
2
3
4
#pragma once

#include <type_traits>

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

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

16
17
18
19
  namespace tag
  {
    struct partialtest_partialtrial
    {
20
21
      std::size_t comp_test; // i
      std::size_t comp_trial; // j
22
23
24
25
    };
  }


26
  /// second-order operator \f$ \langle\partial_i\psi, c\,\partial_j\phi\rangle \f$
27
28
29
  template <class GridFct>
  class GridFunctionOperator<tag::partialtest_partialtrial, GridFct>
      : public GridFunctionOperatorBase<GridFunctionOperator<tag::partialtest_partialtrial, GridFct>, GridFct>
30
  {
31
32
    using Self = GridFunctionOperator;
    using Super = GridFunctionOperatorBase<Self, GridFct>;
33

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

  public:
37
38
    GridFunctionOperator(tag::partialtest_partialtrial tag, GridFct const& expr)
      : Super(expr, 2)
39
40
41
42
      , compTest_(tag.comp_test)
      , compTrial_(tag.comp_trial)
    {}

43
44
45
46
47
    template <class Context, class RowNode, class ColNode, class ElementMatrix>
    void getElementMatrix(Context const& context,
                          RowNode const& rowNode,
                          ColNode const& colNode,
                          ElementMatrix& elementMatrix)
48
    {
49
50
      static_assert(RowNode::isLeaf && ColNode::isLeaf,
        "Operator can be applied to Leaf-Nodes only.");
51
52
53
54

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

55
56
      using RowLocalBasisType = typename std::decay_t<decltype(rowLocalFE)>::Traits::LocalBasisType;
      using ColLocalBasisType = typename std::decay_t<decltype(colLocalFE)>::Traits::LocalBasisType;
57

58
59
60
61
62
63
64
      using RowFieldType = typename RowLocalBasisType::Traits::RangeFieldType;
      using ColFieldType = typename ColLocalBasisType::Traits::RangeFieldType;
      using RowJacobianType = typename RowLocalBasisType::Traits::JacobianType;
      using ColJacobianType = typename ColLocalBasisType::Traits::JacobianType;

      auto const& quad = this->getQuadratureRule(context.type(), rowNode, colNode);
      for (auto const& qp : quad) {
65
        // Position of the current quadrature point in the reference element
66
        decltype(auto) local = context.local(qp.position());
67
68

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

        // The multiplicative factor in the integral transformation formula
72
73
        const auto factor = context.integrationElement(qp.position()) * qp.weight();
        const auto c = Super::coefficient(local);
74
75

        // The gradients of the shape functions on the reference element
76
77
78
79
        thread_local std::vector<RowJacobianType> rowShapeGradients;
        rowLocalFE.localBasis().evaluateJacobian(local, rowShapeGradients);
        thread_local std::vector<ColJacobianType> colShapeGradients;
        colLocalFE.localBasis().evaluateJacobian(local, colShapeGradients);
80
81

        // Compute the shape function gradients on the real element
82
        thread_local std::vector<RowFieldType> rowPartial(rowShapeGradients.size());
83
        for (std::size_t i = 0; i < rowPartial.size(); ++i) {
84
          rowPartial[i] = jacobian[compTest_][0] * rowShapeGradients[i][0][0];
85
          for (std::size_t j = 1; j < jacobian.cols(); ++j)
86
            rowPartial[i] += jacobian[compTest_][j] * rowShapeGradients[i][0][j];
87
88
        }

89
        thread_local std::vector<ColFieldType> colPartial(colShapeGradients.size());
90
        for (std::size_t i = 0; i < colPartial.size(); ++i) {
91
          colPartial[i] = jacobian[compTrial_][0] * colShapeGradients[i][0][0];
92
          for (std::size_t j = 1; j < jacobian.cols(); ++j)
93
            colPartial[i] += jacobian[compTrial_][j] * colShapeGradients[i][0][j];
94
95
96
        }

        for (std::size_t j = 0; j < colLocalFE.size(); ++j) {
97
98
          const auto local_j = colNode.localIndex(j);
          const auto value = factor * (c * colPartial[j]);
99
          for (std::size_t i = 0; i < rowLocalFE.size(); ++i) {
100
            const auto local_i = rowNode.localIndex(i);
101
102
103
104
105
106
107
108
            elementMatrix[local_i][local_j] += value * rowPartial[i];
          }
        }
      }

    }

  private:
109
110
    std::size_t compTest_;
    std::size_t compTrial_;
111
112
  };

113
114
  /** @} **/

115
} // end namespace AMDiS