Dune-Fufem 2.12-git
Loading...
Searching...
No Matches
massassembler.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_FUFEM_ASSEMBLERS_LOCALASSEMBLERS_MASSASSEMBLER_HH
5#define DUNE_FUFEM_ASSEMBLERS_LOCALASSEMBLERS_MASSASSEMBLER_HH
6
7#ifndef DUNE_FUFEM_DISABLE_HEADER_DEPRECATION
8#warning This header is deprecated and will be removed after 2.11. Use Dune::Fufem::Forms instead.
9#endif
10
17#include <vector>
18
22
23#include <dune/istl/matrix.hh>
24
26
27
28namespace Dune::Fufem
29{
30
31 namespace Impl
32 {
33
40 template <class LV, class M>
41 class LeafNodeMassAssembler
42 {
43 public:
44
45 using LocalView = LV;
46 using Matrix = M;
47 using field_type = typename M::field_type;
48
55 LeafNodeMassAssembler(const LV& lv, M& m)
56 : localView_(lv)
57 , matrix_(m)
58 {}
59
60 template<class Node, class TreePath>
61 void operator()(Node& node, TreePath treePath)
62 {
63 const auto& element = localView_.element();
64 const auto& geometry = element.geometry();
65 const auto& finiteElement = node.finiteElement();
66 const auto& localBasis = finiteElement.localBasis();
67 using RangeType = typename std::decay_t<decltype(localBasis)>::Traits::RangeType;
68 constexpr int gridDim = LocalView::GridView::dimension;
69
70 std::vector<RangeType> values(localBasis.size());
71
72 auto feQuadKey = QuadratureRuleKey(finiteElement);
73 // we have a product of FE functions
74 auto quadKey = feQuadKey.square();
75 const auto& quad = QuadratureRuleCache<double, gridDim>::rule(quadKey);
76
77 for( const auto& qp : quad )
78 {
79 const auto& quadPos = qp.position();
80 const auto integrationElement = geometry.integrationElement(quadPos);
81
82 localBasis.evaluateFunction(quadPos, values);
83
84 // compute matrix entries = inner products
85 auto z = qp.weight() * integrationElement;
86 for (std::size_t i=0; i<localBasis.size(); ++i)
87 {
88 auto zi = values[i]*z;
89
90 auto rowIndex = node.localIndex(i);
91
92 // start off-diagonal, treat the diagonal extra
93 for (std::size_t j=i+1; j<localBasis.size(); ++j)
94 {
95 auto zij = values[j] * zi;
96
97 auto colIndex = node.localIndex(j);
98
99 // mass matrix is symmetric
100 matrix_[rowIndex][colIndex] += zij;
101 matrix_[colIndex][rowIndex] += zij;
102 }
103
104 // z * values[i]^2
105 matrix_[rowIndex][rowIndex] += values[i] * zi;
106 }
107 }
108 }
109
110 private:
111 const LocalView& localView_;
112 Matrix& matrix_;
113 };
114
115 } // namespace Impl
116
125 class
126 [[deprecated("This class is deprecated and will be removed after 2.11. Use Dune::Fufem::Forms instead.")]]
128 {
129 public:
130
131 [[deprecated("This class is deprecated and will be removed after 2.11. Use Dune::Fufem::Forms instead.")]]
133 {}
134
135 template<class Element, class LocalMatrix, class LocalView>
136 void operator()(const Element& element, LocalMatrix& localMatrix, const LocalView& testLocalView, const LocalView& ansatzLocalView) const
137 {
138 // the mass matrix operator assumes test == ansatz
139 if (&testLocalView != &ansatzLocalView)
140 DUNE_THROW(Dune::Exception,"The mass matrix operator assumes equal ansatz and test functions");
141
142 // create a tree visitor and compute the inner products of the local functions at the leaf nodes
143 Impl::LeafNodeMassAssembler leadNodeMassAssembler(testLocalView,localMatrix);
144 TypeTree::forEachLeafNode(testLocalView.tree(),leadNodeMassAssembler);
145 }
146
147 };
148
149} // namespace Dune::Fufem
150
151#endif // DUNE_FUFEM_ASSEMBLERS_LOCALASSEMBLERS_MASSASSEMBLER_HH
152
std::decay_t< std::invoke_result_t< F, D > > RangeType
Dune::BCRSMatrix< FieldMatrix< T, n, m >, TA > Matrix
static constexpr size_type M()
size_type rowIndex() const
virtual void operator()()=0
#define DUNE_THROW(E,...)
void forEachLeafNode(Tree &&tree, LeafFunc &&leafFunc)
Local mass assembler for dune-functions basis.
Definition massassembler.hh:128
MassAssembler()
Definition massassembler.hh:132
void operator()(const Element &element, LocalMatrix &localMatrix, const LocalView &testLocalView, const LocalView &ansatzLocalView) const
Definition massassembler.hh:136
static const Dune::QuadratureRule< coord_type, dim > & rule(const Dune::GeometryType &gt, const int order, int refinement)
Definition quadraturerulecache.hh:196
A token that specifies a quadrature rule.
Definition quadraturerulecache.hh:39
Definition dunefunctionsboundaryfunctionalassembler.hh:29