Dune-Fufem 2.11-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
25#if DUNE_VERSION_GTE(DUNE_FUNCTIONS, 2, 11)
27#else
28#include <dune/typetree/traversal.hh>
29#endif
30
32
33
34namespace Dune::Fufem
35{
36
37 namespace Impl
38 {
39
46 template <class LV, class M>
47 class LeafNodeMassAssembler
48 {
49 public:
50
51 using LocalView = LV;
52 using Matrix = M;
53 using field_type = typename M::field_type;
54
61 LeafNodeMassAssembler(const LV& lv, M& m)
62 : localView_(lv)
63 , matrix_(m)
64 {}
65
66 template<class Node, class TreePath>
67 void operator()(Node& node, TreePath treePath)
68 {
69 const auto& element = localView_.element();
70 const auto& geometry = element.geometry();
71 const auto& finiteElement = node.finiteElement();
72 const auto& localBasis = finiteElement.localBasis();
73 using RangeType = typename std::decay_t<decltype(localBasis)>::Traits::RangeType;
74 constexpr int gridDim = LocalView::GridView::dimension;
75
76 std::vector<RangeType> values(localBasis.size());
77
78 auto feQuadKey = QuadratureRuleKey(finiteElement);
79 // we have a product of FE functions
80 auto quadKey = feQuadKey.square();
81 const auto& quad = QuadratureRuleCache<double, gridDim>::rule(quadKey);
82
83 for( const auto& qp : quad )
84 {
85 const auto& quadPos = qp.position();
86 const auto integrationElement = geometry.integrationElement(quadPos);
87
88 localBasis.evaluateFunction(quadPos, values);
89
90 // compute matrix entries = inner products
91 auto z = qp.weight() * integrationElement;
92 for (std::size_t i=0; i<localBasis.size(); ++i)
93 {
94 auto zi = values[i]*z;
95
96 auto rowIndex = node.localIndex(i);
97
98 // start off-diagonal, treat the diagonal extra
99 for (std::size_t j=i+1; j<localBasis.size(); ++j)
100 {
101 auto zij = values[j] * zi;
102
103 auto colIndex = node.localIndex(j);
104
105 // mass matrix is symmetric
106 matrix_[rowIndex][colIndex] += zij;
107 matrix_[colIndex][rowIndex] += zij;
108 }
109
110 // z * values[i]^2
111 matrix_[rowIndex][rowIndex] += values[i] * zi;
112 }
113 }
114 }
115
116 private:
117 const LocalView& localView_;
118 Matrix& matrix_;
119 };
120
121 } // namespace Impl
122
131 class
132 [[deprecated("This class is deprecated and will be removed after 2.11. Use Dune::Fufem::Forms instead.")]]
134 {
135 public:
136
137 [[deprecated("This class is deprecated and will be removed after 2.11. Use Dune::Fufem::Forms instead.")]]
140
141 template<class Element, class LocalMatrix, class LocalView>
142 void operator()(const Element& element, LocalMatrix& localMatrix, const LocalView& testLocalView, const LocalView& ansatzLocalView) const
143 {
144 // the mass matrix operator assumes test == ansatz
145 if (&testLocalView != &ansatzLocalView)
146 DUNE_THROW(Dune::Exception,"The mass matrix operator assumes equal ansatz and test functions");
147
148 // create a tree visitor and compute the inner products of the local functions at the leaf nodes
149 Impl::LeafNodeMassAssembler leadNodeMassAssembler(testLocalView,localMatrix);
150 TypeTree::forEachLeafNode(testLocalView.tree(),leadNodeMassAssembler);
151 }
152
153 };
154
155} // namespace Dune::Fufem
156
157#endif // DUNE_FUFEM_ASSEMBLERS_LOCALASSEMBLERS_MASSASSEMBLER_HH
158
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)
Definition dunefunctionsboundaryfunctionalassembler.hh:29
Local mass assembler for dune-functions basis.
Definition massassembler.hh:134
MassAssembler()
Definition massassembler.hh:138
void operator()(const Element &element, LocalMatrix &localMatrix, const LocalView &testLocalView, const LocalView &ansatzLocalView) const
Definition massassembler.hh:142
A token that specifies a quadrature rule.
Definition quadraturerulecache.hh:39
static const Dune::QuadratureRule< coord_type, dim > & rule(const Dune::GeometryType &gt, const int order, int refinement)
Definition quadraturerulecache.hh:196