deal.II version GIT relicensing-2289-g1e5549a87a 2024-12-21 21:30:00+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
fe_tools.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2000 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_fe_tools_H
16#define dealii_fe_tools_H
17
18
19
20#include <deal.II/base/config.h>
21
26#include <deal.II/base/tensor.h>
27
29
31
33
34#include <memory>
35#include <string>
36#include <vector>
37
38
40
41// Forward declarations
42#ifndef DOXYGEN
43template <typename number>
44class FullMatrix;
45template <int dim>
46class Quadrature;
47template <int dim, int spacedim>
48class FiniteElement;
49template <int dim, int spacedim>
51class DoFHandler;
52template <int dim>
54template <typename number>
56#endif
57
58
77namespace FETools
78{
87 template <int dim, int spacedim = dim>
89 {
90 public:
94 virtual std::unique_ptr<FiniteElement<dim, spacedim>>
95 get(const unsigned int degree) const = 0;
96
102 virtual std::unique_ptr<FiniteElement<dim, spacedim>>
103 get(const Quadrature<1> &quad) const = 0;
104
108 virtual ~FEFactoryBase() override = default;
109 };
110
120 template <class FE>
121 class FEFactory : public FEFactoryBase<FE::dimension, FE::space_dimension>
122 {
123 public:
127 virtual std::unique_ptr<FiniteElement<FE::dimension, FE::space_dimension>>
128 get(const unsigned int degree) const override;
129
134 virtual std::unique_ptr<FiniteElement<FE::dimension, FE::space_dimension>>
135 get(const Quadrature<1> &quad) const override;
136 };
137
153 template <int dim, int spacedim>
154 void
156 std::vector<unsigned int> &renumbering,
157 std::vector<std::vector<unsigned int>> &start_indices);
158
174 template <int dim, int spacedim>
175 void
177 std::vector<types::global_dof_index> &renumbering,
178 std::vector<types::global_dof_index> &block_data,
179 bool return_start_indices = true);
180
194 template <int dim, typename number, int spacedim>
195 void
198 FullMatrix<number> &interpolation_matrix);
199
211 template <int dim, typename number, int spacedim>
212 void
215 FullMatrix<number> &interpolation_matrix);
216
228 template <int dim, typename number, int spacedim>
229 void
232 FullMatrix<number> &difference_matrix);
233
237 template <int dim, typename number, int spacedim>
238 void
241 FullMatrix<number> &matrix);
242
311 template <int dim, int spacedim>
314
353 template <int dim, typename number, int spacedim>
354 void
357 std::vector<std::vector<FullMatrix<number>>> &matrices,
358 const bool isotropic_only = false,
359 const double threshold = 1.e-12);
360
382 template <int dim, typename number, int spacedim>
383 void
387 const unsigned int face_coarse,
388 const unsigned int face_fine,
389 const double threshold = 1.e-12);
390
422 template <int dim, typename number, int spacedim>
423 void
426 std::vector<std::vector<FullMatrix<number>>> &matrices,
427 const bool isotropic_only = false);
428
514 template <int dim, int spacedim>
515 void
518 const Quadrature<dim> &lhs_quadrature,
519 const Quadrature<dim> &rhs_quadrature,
521
529 template <int dim, int spacedim>
530 void
533 const Quadrature<dim> &quadrature,
534 FullMatrix<double> &I_q);
535
549 template <int dim>
550 void
552 const FullMatrix<double> &projection_matrix,
553 const std::vector<Tensor<1, dim>> &vector_of_tensors_at_qp,
554 std::vector<Tensor<1, dim>> &vector_of_tensors_at_nodes);
555
556
557
561 template <int dim>
562 void
564 const FullMatrix<double> &projection_matrix,
565 const std::vector<SymmetricTensor<2, dim>> &vector_of_tensors_at_qp,
566 std::vector<SymmetricTensor<2, dim>> &vector_of_tensors_at_nodes);
567
568
569
579 template <int dim, int spacedim>
580 void
583 const Quadrature<dim - 1> &lhs_quadrature,
584 const Quadrature<dim - 1> &rhs_quadrature,
586 const unsigned int face,
588
621 template <int dim, int spacedim = dim>
624
640 template <int dim, int spacedim, typename number>
641 void
643 const FiniteElement<dim, spacedim> &finite_element,
644 const std::vector<Vector<number>> &support_point_values,
645 std::vector<number> &dof_values);
646
647
648
686 template <int dim, int spacedim, class InVector, class OutVector>
687 void
689 const InVector &u1,
690 const DoFHandler<dim, spacedim> &dof2,
691 OutVector &u2);
692
712 template <int dim, int spacedim, class InVector, class OutVector>
713 void
715 const DoFHandler<dim, spacedim> &dof1,
716 const InVector &u1,
717 const DoFHandler<dim, spacedim> &dof2,
719 OutVector &u2);
720
734 template <int dim, class InVector, class OutVector, int spacedim>
735 void
737 const InVector &u1,
739 OutVector &u1_interpolated);
740
753 template <int dim, class InVector, class OutVector, int spacedim>
754 void
756 const DoFHandler<dim, spacedim> &dof1,
758 const InVector &u1,
759 const DoFHandler<dim, spacedim> &dof2,
761 OutVector &u1_interpolated);
762
772 template <int dim, class InVector, class OutVector, int spacedim>
773 void
775 const InVector &z1,
777 OutVector &z1_difference);
778
791 template <int dim, class InVector, class OutVector, int spacedim>
792 void
794 const DoFHandler<dim, spacedim> &dof1,
796 const InVector &z1,
797 const DoFHandler<dim, spacedim> &dof2,
799 OutVector &z1_difference);
800
801
802
811 template <int dim, class InVector, class OutVector, int spacedim>
812 void
814 const InVector &u1,
815 const DoFHandler<dim, spacedim> &dof2,
816 OutVector &u2);
817
878 template <int dim, class InVector, class OutVector, int spacedim>
879 void
881 const InVector &z1,
882 const DoFHandler<dim, spacedim> &dof2,
883 OutVector &z2);
884
897 template <int dim, class InVector, class OutVector, int spacedim>
898 void
900 const DoFHandler<dim, spacedim> &dof1,
901 const InVector &z1,
902 const DoFHandler<dim, spacedim> &dof2,
904 OutVector &z2);
905
921 template <int dim>
922 std::vector<unsigned int>
924
931 template <int dim>
932 std::vector<unsigned int>
934
1010 namespace Compositing
1011 {
1028 template <int dim, int spacedim>
1031 const std::vector<const FiniteElement<dim, spacedim> *> &fes,
1032 const std::vector<unsigned int> &multiplicities,
1033 const bool do_tensor_product = true);
1034
1040 template <int dim, int spacedim>
1043 const std::initializer_list<
1044 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1045 &fe_systems);
1046
1053 template <int dim, int spacedim>
1056 const unsigned int N1,
1057 const FiniteElement<dim, spacedim> *fe2 = nullptr,
1058 const unsigned int N2 = 0,
1059 const FiniteElement<dim, spacedim> *fe3 = nullptr,
1060 const unsigned int N3 = 0,
1061 const FiniteElement<dim, spacedim> *fe4 = nullptr,
1062 const unsigned int N4 = 0,
1063 const FiniteElement<dim, spacedim> *fe5 = nullptr,
1064 const unsigned int N5 = 0);
1065
1078 template <int dim, int spacedim>
1079 std::vector<bool>
1081 const std::vector<const FiniteElement<dim, spacedim> *> &fes,
1082 const std::vector<unsigned int> &multiplicities);
1083
1089 template <int dim, int spacedim>
1090 std::vector<bool>
1092 const std::initializer_list<
1093 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1094 &fe_systems);
1095
1113 template <int dim, int spacedim>
1114 DEAL_II_DEPRECATED std::vector<bool>
1117 const unsigned int N1,
1118 const FiniteElement<dim, spacedim> *fe2 = nullptr,
1119 const unsigned int N2 = 0,
1120 const FiniteElement<dim, spacedim> *fe3 = nullptr,
1121 const unsigned int N3 = 0,
1122 const FiniteElement<dim, spacedim> *fe4 = nullptr,
1123 const unsigned int N4 = 0,
1124 const FiniteElement<dim, spacedim> *fe5 = nullptr,
1125 const unsigned int N5 = 0);
1126
1127
1144 template <int dim, int spacedim>
1145 std::vector<ComponentMask>
1147 const std::vector<const FiniteElement<dim, spacedim> *> &fes,
1148 const std::vector<unsigned int> &multiplicities,
1149 const bool do_tensor_product = true);
1150
1156 template <int dim, int spacedim>
1157 std::vector<ComponentMask>
1159 const std::initializer_list<
1160 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1161 &fe_systems);
1162
1184 template <int dim, int spacedim>
1185 DEAL_II_DEPRECATED std::vector<ComponentMask>
1188 const unsigned int N1,
1189 const FiniteElement<dim, spacedim> *fe2 = nullptr,
1190 const unsigned int N2 = 0,
1191 const FiniteElement<dim, spacedim> *fe3 = nullptr,
1192 const unsigned int N3 = 0,
1193 const FiniteElement<dim, spacedim> *fe4 = nullptr,
1194 const unsigned int N4 = 0,
1195 const FiniteElement<dim, spacedim> *fe5 = nullptr,
1196 const unsigned int N5 = 0,
1197 const bool do_tensor_product = true);
1198
1215 template <int dim, int spacedim>
1216 void
1218 std::vector<std::pair<std::pair<unsigned int, unsigned int>,
1219 unsigned int>> &system_to_base_table,
1220 std::vector<std::pair<unsigned int, unsigned int>>
1221 &system_to_component_table,
1222 std::vector<std::pair<std::pair<unsigned int, unsigned int>,
1223 unsigned int>> &component_to_base_table,
1224 const FiniteElement<dim, spacedim> &finite_element,
1225 const bool do_tensor_product = true);
1226
1242 template <int dim, int spacedim>
1243 void
1245 std::vector<std::pair<std::pair<unsigned int, unsigned int>,
1246 unsigned int>> &face_system_to_base_table,
1247 std::vector<std::pair<unsigned int, unsigned int>>
1248 &face_system_to_component_table,
1249 const FiniteElement<dim, spacedim> &finite_element,
1250 const bool do_tensor_product = true,
1251 const unsigned int face_no = 0 /*TODO*/);
1252
1253 } // namespace Compositing
1254
1255
1289 template <int dim, int spacedim = dim>
1290 std::unique_ptr<FiniteElement<dim, spacedim>>
1291 get_fe_by_name(const std::string &name);
1292
1335 template <int dim, int spacedim>
1336 void
1337 add_fe_name(const std::string &name,
1338 const FEFactoryBase<dim, spacedim> *factory);
1339
1350 std::string,
1351 << "Can't re-generate a finite element from the string '"
1352 << arg1 << "'.");
1353
1366 char,
1367 int,
1368 << "The dimension " << arg1
1369 << " in the finite element string must match "
1370 << "the space dimension " << arg2 << '.');
1371
1378
1392
1400 "You are using continuous elements on a grid with "
1401 "hanging nodes but without providing hanging node "
1402 "constraints. Use the respective function with "
1403 "additional AffineConstraints argument(s), instead.");
1416 int,
1417 int,
1418 int,
1419 int,
1420 << "This is a " << arg1 << 'x' << arg2 << " matrix, "
1421 << "but should be a " << arg3 << 'x' << arg4 << " matrix.");
1422
1429 double,
1430 << "Least squares fit leaves a gap of " << arg1);
1431
1438 int,
1439 int,
1440 << arg1 << " must be greater than " << arg2);
1441} // namespace FETools
1442
1443
1444#ifndef DOXYGEN
1445
1446namespace FETools
1447{
1448 template <class FE>
1449 std::unique_ptr<FiniteElement<FE::dimension, FE::space_dimension>>
1450 FEFactory<FE>::get(const unsigned int degree) const
1451 {
1452 return std::make_unique<FE>(degree);
1453 }
1454
1455 namespace Compositing
1456 {
1457 template <int dim, int spacedim>
1458 std::vector<bool>
1460 const std::initializer_list<
1461 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1462 &fe_systems)
1463 {
1464 std::vector<const FiniteElement<dim, spacedim> *> fes;
1465 std::vector<unsigned int> multiplicities;
1466
1467 const auto extract =
1468 [&fes, &multiplicities](
1469 const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
1470 unsigned int> &fe_system) {
1471 fes.push_back(fe_system.first.get());
1472 multiplicities.push_back(fe_system.second);
1473 };
1474
1475 for (const auto &p : fe_systems)
1476 extract(p);
1477
1478 return compute_restriction_is_additive_flags(fes, multiplicities);
1479 }
1480
1481
1482
1483 template <int dim, int spacedim>
1486 const std::initializer_list<
1487 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1488 &fe_systems)
1489 {
1490 std::vector<const FiniteElement<dim, spacedim> *> fes;
1491 std::vector<unsigned int> multiplicities;
1492
1493 const auto extract =
1494 [&fes, &multiplicities](
1495 const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
1496 unsigned int> &fe_system) {
1497 fes.push_back(fe_system.first.get());
1498 multiplicities.push_back(fe_system.second);
1499 };
1500
1501 for (const auto &p : fe_systems)
1502 extract(p);
1503
1504 return multiply_dof_numbers(fes, multiplicities, true);
1505 }
1506
1507
1508
1509 template <int dim, int spacedim>
1510 std::vector<ComponentMask>
1512 const std::initializer_list<
1513 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1514 &fe_systems)
1515 {
1516 std::vector<const FiniteElement<dim, spacedim> *> fes;
1517 std::vector<unsigned int> multiplicities;
1518
1519 const auto extract =
1520 [&fes, &multiplicities](
1521 const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
1522 unsigned int> &fe_system) {
1523 fes.push_back(fe_system.first.get());
1524 multiplicities.push_back(fe_system.second);
1525 };
1526
1527 for (const auto &p : fe_systems)
1528 extract(p);
1529
1530 return compute_nonzero_components(fes, multiplicities, true);
1531 }
1532 } // namespace Compositing
1533} // namespace FETools
1534
1535#endif
1536
1540
1541#endif /* dealii_fe_tools_H */
virtual ~FEFactoryBase() override=default
virtual std::unique_ptr< FiniteElement< dim, spacedim > > get(const Quadrature< 1 > &quad) const =0
virtual std::unique_ptr< FiniteElement< dim, spacedim > > get(const unsigned int degree) const =0
virtual std::unique_ptr< FiniteElement< FE::dimension, FE::space_dimension > > get(const Quadrature< 1 > &quad) const override
virtual std::unique_ptr< FiniteElement< FE::dimension, FE::space_dimension > > get(const unsigned int degree) const override
#define DEAL_II_DEPRECATED
Definition config.h:205
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:175
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#define DeclException0(Exception0)
Definition exceptions.h:466
static ::ExceptionBase & ExcTriangulationMismatch()
static ::ExceptionBase & ExcInvalidFEName(std::string arg1)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition exceptions.h:580
static ::ExceptionBase & ExcInvalidFEDimension(char arg1, int arg2)
static ::ExceptionBase & ExcLeastSquaresError(double arg1)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition exceptions.h:534
static ::ExceptionBase & ExcFENotPrimitive()
static ::ExceptionBase & ExcHangingNodesNotAllowed()
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:489
static ::ExceptionBase & ExcInvalidFE()
static ::ExceptionBase & ExcGridNotRefinedAtLeastOnce()
static ::ExceptionBase & ExcMatrixDimensionMismatch(int arg1, int arg2, int arg3, int arg4)
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:511
static ::ExceptionBase & ExcNotGreaterThan(int arg1, int arg2)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void build_face_tables(std::vector< std::pair< std::pair< unsigned int, unsigned int >, unsigned int > > &face_system_to_base_table, std::vector< std::pair< unsigned int, unsigned int > > &face_system_to_component_table, const FiniteElement< dim, spacedim > &finite_element, const bool do_tensor_product=true, const unsigned int face_no=0)
std::vector< ComponentMask > compute_nonzero_components(const std::vector< const FiniteElement< dim, spacedim > * > &fes, const std::vector< unsigned int > &multiplicities, const bool do_tensor_product=true)
std::vector< bool > compute_restriction_is_additive_flags(const std::vector< const FiniteElement< dim, spacedim > * > &fes, const std::vector< unsigned int > &multiplicities)
void build_cell_tables(std::vector< std::pair< std::pair< unsigned int, unsigned int >, unsigned int > > &system_to_base_table, std::vector< std::pair< unsigned int, unsigned int > > &system_to_component_table, std::vector< std::pair< std::pair< unsigned int, unsigned int >, unsigned int > > &component_to_base_table, const FiniteElement< dim, spacedim > &finite_element, const bool do_tensor_product=true)
FiniteElementData< dim > multiply_dof_numbers(const std::vector< const FiniteElement< dim, spacedim > * > &fes, const std::vector< unsigned int > &multiplicities, const bool do_tensor_product=true)
void interpolation_difference(const DoFHandler< dim, spacedim > &dof1, const InVector &z1, const FiniteElement< dim, spacedim > &fe2, OutVector &z1_difference)
void compute_projection_from_quadrature_points(const FullMatrix< double > &projection_matrix, const std::vector< Tensor< 1, dim > > &vector_of_tensors_at_qp, std::vector< Tensor< 1, dim > > &vector_of_tensors_at_nodes)
void project_dg(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const DoFHandler< dim, spacedim > &dof2, OutVector &u2)
void get_back_interpolation_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &interpolation_matrix)
void get_projection_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &matrix)
void compute_component_wise(const FiniteElement< dim, spacedim > &fe, std::vector< unsigned int > &renumbering, std::vector< std::vector< unsigned int > > &start_indices)
void add_fe_name(const std::string &name, const FEFactoryBase< dim, spacedim > *factory)
std::vector< unsigned int > hierarchic_to_lexicographic_numbering(unsigned int degree)
void convert_generalized_support_point_values_to_dof_values(const FiniteElement< dim, spacedim > &finite_element, const std::vector< Vector< number > > &support_point_values, std::vector< number > &dof_values)
void compute_interpolation_to_quadrature_points_matrix(const FiniteElement< dim, spacedim > &fe, const Quadrature< dim > &quadrature, FullMatrix< double > &I_q)
Quadrature< dim > compute_nodal_quadrature(const FiniteElement< dim, spacedim > &fe)
Compute the nodal quadrature rule associated with an element.
std::unique_ptr< FiniteElement< dim, spacedim > > get_fe_by_name(const std::string &name)
void compute_projection_from_quadrature_points_matrix(const FiniteElement< dim, spacedim > &fe, const Quadrature< dim > &lhs_quadrature, const Quadrature< dim > &rhs_quadrature, FullMatrix< double > &X)
void get_interpolation_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &interpolation_matrix)
void extrapolate(const DoFHandler< dim, spacedim > &dof1, const InVector &z1, const DoFHandler< dim, spacedim > &dof2, OutVector &z2)
void compute_embedding_matrices(const FiniteElement< dim, spacedim > &fe, std::vector< std::vector< FullMatrix< number > > > &matrices, const bool isotropic_only=false, const double threshold=1.e-12)
void compute_face_embedding_matrices(const FiniteElement< dim, spacedim > &fe, FullMatrix< number >(&matrices)[GeometryInfo< dim >::max_children_per_face], const unsigned int face_coarse, const unsigned int face_fine, const double threshold=1.e-12)
void interpolate(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const DoFHandler< dim, spacedim > &dof2, OutVector &u2)
void compute_block_renumbering(const FiniteElement< dim, spacedim > &fe, std::vector< types::global_dof_index > &renumbering, std::vector< types::global_dof_index > &block_data, bool return_start_indices=true)
std::vector< unsigned int > lexicographic_to_hierarchic_numbering(unsigned int degree)
void compute_projection_from_face_quadrature_points_matrix(const FiniteElement< dim, spacedim > &fe, const Quadrature< dim - 1 > &lhs_quadrature, const Quadrature< dim - 1 > &rhs_quadrature, const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, const unsigned int face, FullMatrix< double > &X)
FullMatrix< double > compute_node_matrix(const FiniteElement< dim, spacedim > &fe)
void get_interpolation_difference_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &difference_matrix)
void back_interpolate(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const FiniteElement< dim, spacedim > &fe2, OutVector &u1_interpolated)
void compute_projection_matrices(const FiniteElement< dim, spacedim > &fe, std::vector< std::vector< FullMatrix< number > > > &matrices, const bool isotropic_only=false)
constexpr ReturnType< rank, T >::value_type & extract(T &t, const ArrayType &indices)