deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
l2.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2010 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_integrators_l2_h
14#define dealii_integrators_l2_h
15
16
17#include <deal.II/base/config.h>
18
21
23#include <deal.II/fe/mapping.h>
24
26
28
30
31namespace LocalIntegrators
32{
38 namespace L2
39 {
53 template <int dim>
56 const FEValuesBase<dim> &fe,
57 const double factor = 1.)
58 {
59 const unsigned int n_dofs = fe.dofs_per_cell;
60 const unsigned int n_components = fe.get_fe().n_components();
61
62 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
63 {
64 const double dx = fe.JxW(k) * factor;
65 for (unsigned int i = 0; i < n_dofs; ++i)
66 {
67 double Mii = 0.0;
68 for (unsigned int d = 0; d < n_components; ++d)
69 Mii += dx * fe.shape_value_component(i, k, d) *
70 fe.shape_value_component(i, k, d);
71
72 M(i, i) += Mii;
73
74 for (unsigned int j = i + 1; j < n_dofs; ++j)
75 {
76 double Mij = 0.0;
77 for (unsigned int d = 0; d < n_components; ++d)
78 Mij += dx * fe.shape_value_component(j, k, d) *
79 fe.shape_value_component(i, k, d);
80
81 M(i, j) += Mij;
82 M(j, i) += Mij;
83 }
84 }
85 }
86 }
87
104 template <int dim>
107 const FEValuesBase<dim> &fe,
108 const std::vector<double> &weights)
109 {
110 const unsigned int n_dofs = fe.dofs_per_cell;
111 const unsigned int n_components = fe.get_fe().n_components();
112 AssertDimension(M.m(), n_dofs);
113 AssertDimension(M.n(), n_dofs);
114 AssertDimension(weights.size(), fe.n_quadrature_points);
115
116 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
117 {
118 const double dx = fe.JxW(k) * weights[k];
119 for (unsigned int i = 0; i < n_dofs; ++i)
120 {
121 double Mii = 0.0;
122 for (unsigned int d = 0; d < n_components; ++d)
123 Mii += dx * fe.shape_value_component(i, k, d) *
124 fe.shape_value_component(i, k, d);
125
126 M(i, i) += Mii;
127
128 for (unsigned int j = i + 1; j < n_dofs; ++j)
129 {
130 double Mij = 0.0;
131 for (unsigned int d = 0; d < n_components; ++d)
132 Mij += dx * fe.shape_value_component(j, k, d) *
133 fe.shape_value_component(i, k, d);
134
135 M(i, j) += Mij;
136 M(j, i) += Mij;
137 }
138 }
139 }
140 }
141
155 template <int dim, typename number>
158 const FEValuesBase<dim> &fe,
159 const std::vector<double> &input,
160 const double factor = 1.)
161 {
162 const unsigned int n_dofs = fe.dofs_per_cell;
163 AssertDimension(result.size(), n_dofs);
165 AssertDimension(input.size(), fe.n_quadrature_points);
166
167 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
168 for (unsigned int i = 0; i < n_dofs; ++i)
169 result(i) += fe.JxW(k) * factor * input[k] * fe.shape_value(i, k);
170 }
171
185 template <int dim, typename number>
188 const FEValuesBase<dim> &fe,
189 const ArrayView<const std::vector<double>> &input,
190 const double factor = 1.)
191 {
192 const unsigned int n_dofs = fe.dofs_per_cell;
193 const unsigned int n_components = input.size();
194
195 AssertDimension(result.size(), n_dofs);
196 AssertDimension(input.size(), fe.get_fe().n_components());
197
198 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
199 for (unsigned int i = 0; i < n_dofs; ++i)
200 for (unsigned int d = 0; d < n_components; ++d)
201 result(i) += fe.JxW(k) * factor *
202 fe.shape_value_component(i, k, d) * input[d][k];
203 }
204
233 template <int dim>
239 const FEValuesBase<dim> &fe1,
240 const FEValuesBase<dim> &fe2,
241 const double factor1 = 1.,
242 const double factor2 = 1.)
243 {
244 const unsigned int n1_dofs = fe1.n_dofs_per_cell();
245 const unsigned int n2_dofs = fe2.n_dofs_per_cell();
246 const unsigned int n_components = fe1.get_fe().n_components();
247
248 Assert(n1_dofs == n2_dofs, ExcNotImplemented());
249 (void)n2_dofs;
250 AssertDimension(n_components, fe2.get_fe().n_components());
251 AssertDimension(M11.m(), n1_dofs);
252 AssertDimension(M12.m(), n1_dofs);
253 AssertDimension(M21.m(), n2_dofs);
254 AssertDimension(M22.m(), n2_dofs);
255 AssertDimension(M11.n(), n1_dofs);
256 AssertDimension(M12.n(), n2_dofs);
257 AssertDimension(M21.n(), n1_dofs);
258 AssertDimension(M22.n(), n2_dofs);
259
260 for (unsigned int k = 0; k < fe1.n_quadrature_points; ++k)
261 {
262 const double dx = fe1.JxW(k);
263
264 for (unsigned int i = 0; i < n1_dofs; ++i)
265 for (unsigned int j = 0; j < n1_dofs; ++j)
266 for (unsigned int d = 0; d < n_components; ++d)
267 {
268 const double u1 =
269 factor1 * fe1.shape_value_component(j, k, d);
270 const double u2 =
271 -factor2 * fe2.shape_value_component(j, k, d);
272 const double v1 =
273 factor1 * fe1.shape_value_component(i, k, d);
274 const double v2 =
275 -factor2 * fe2.shape_value_component(i, k, d);
276
277 M11(i, j) += dx * u1 * v1;
278 M12(i, j) += dx * u2 * v1;
279 M21(i, j) += dx * u1 * v2;
280 M22(i, j) += dx * u2 * v2;
281 }
282 }
283 }
284 } // namespace L2
285} // namespace LocalIntegrators
286
288
289#endif
const unsigned int dofs_per_cell
double shape_value_component(const unsigned int i, const unsigned int q_point, const unsigned int component) const
const unsigned int n_quadrature_points
const FiniteElement< dim, spacedim > & get_fe() const
double JxW(const unsigned int q_point) const
const double & shape_value(const unsigned int i, const unsigned int q_point) const
unsigned int n_components() const
size_type n() const
size_type m() const
virtual size_type size() const override
#define DEAL_II_DEPRECATED
Definition config.h:294
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
const unsigned int v1
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
void L2(Vector< number > &result, const FEValuesBase< dim > &fe, const std::vector< double > &input, const double factor=1.)
Definition l2.h:157
void mass_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const double factor=1.)
Definition l2.h:55
void jump_matrix(FullMatrix< double > &M11, FullMatrix< double > &M12, FullMatrix< double > &M21, FullMatrix< double > &M22, const FEValuesBase< dim > &fe1, const FEValuesBase< dim > &fe2, const double factor1=1., const double factor2=1.)
Definition l2.h:235
void weighted_mass_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const std::vector< double > &weights)
Definition l2.h:106
Library of integrals over cells and faces.
Definition advection.h:32