AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
FirstOrderTestvecGradTrial.hpp
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <amdis/GridFunctionOperator.hpp>
6 #include <amdis/common/StaticSize.hpp>
7 
8 namespace AMDiS
9 {
15  namespace tag
16  {
17  struct testvec_gradtrial {};
18  }
19 
20 
23  {
24  public:
26 
27  template <class CG, class RN, class CN, class Quad, class LocalFct, class Mat>
28  void assemble(CG const& contextGeo, RN const& rowNode, CN const& colNode,
29  Quad const& quad, LocalFct const& localFct, Mat& elementMatrix) const
30  {
31  static_assert(static_size_v<typename LocalFct::Range> == 1,
32  "Expression must be of scalar type.");
33  static_assert(RN::isPower && CN::isLeaf,
34  "col-node must be Leaf-Node and row-node must be a Power-Node.");
35 
36  static const std::size_t CHILDREN = RN::CHILDREN;
37  static_assert( CHILDREN == CG::dow, "" );
38 
39  std::size_t rowSize = rowNode.child(0).size();
40  std::size_t colSize = colNode.size();
41 
42  using RangeFieldType = typename CN::LocalBasis::Traits::RangeFieldType;
43  using WorldVector = FieldVector<RangeFieldType,CG::dow>;
44  std::vector<WorldVector> colGradients;
45 
46  for (auto const& qp : quad) {
47  // Position of the current quadrature point in the reference element
48  decltype(auto) local = contextGeo.local(qp.position());
49 
50  // The transposed inverse Jacobian of the map from the reference element to the element
51  const auto jacobian = contextGeo.geometry().jacobianInverseTransposed(local);
52 
53  // The multiplicative factor in the integral transformation formula
54  const auto factor = localFct(local) * contextGeo.integrationElement(qp.position()) * qp.weight();
55 
56  // the values of the shape functions on the reference element at the quadrature point
57  auto const& shapeValues = rowNode.child(0).localBasisValuesAt(local);
58 
59  // The gradients of the shape functions on the reference element
60  auto const& shapeGradients = colNode.localBasisJacobiansAt(local);
61 
62  // Compute the shape function gradients on the real element
63  colGradients.resize(shapeGradients.size());
64 
65  for (std::size_t i = 0; i < colGradients.size(); ++i)
66  jacobian.mv(shapeGradients[i][0], colGradients[i]);
67 
68  for (std::size_t i = 0; i < rowSize; ++i) {
69  const auto value = factor * shapeValues[i];
70  for (std::size_t j = 0; j < colSize; ++j) {
71  const auto local_j = colNode.localIndex(j);
72  for (std::size_t k = 0; k < CHILDREN; ++k) {
73  const auto local_ki = rowNode.child(k).localIndex(i);
74  elementMatrix[local_ki][local_j] += value * colGradients[j][k];
75  }
76  }
77  }
78  }
79 
80  }
81  };
82 
83  template <class LC>
84  struct GridFunctionOperatorRegistry<tag::testvec_gradtrial, LC>
85  {
86  static constexpr int degree = 1;
88  };
89 
92 } // end namespace AMDiS
Definition: AdaptBase.hpp:6
Definition: FirstOrderTestvecGradTrial.hpp:17
first-order operator
Definition: FirstOrderTestvecGradTrial.hpp:22
Registry to specify a tag for each implementation type.
Definition: GridFunctionOperator.hpp:204