Reference documentation for deal.II version GIT relicensing-687-gbf51c6da8c 2024-05-21 02:00:02+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 - 2023 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
589
590
606 template <int dim, int spacedim, typename number>
607 void
609 const FiniteElement<dim, spacedim> &finite_element,
610 const std::vector<Vector<number>> &support_point_values,
611 std::vector<number> &dof_values);
612
613
614
652 template <int dim, int spacedim, class InVector, class OutVector>
653 void
655 const InVector &u1,
656 const DoFHandler<dim, spacedim> &dof2,
657 OutVector &u2);
658
678 template <int dim, int spacedim, class InVector, class OutVector>
679 void
681 const DoFHandler<dim, spacedim> &dof1,
682 const InVector &u1,
683 const DoFHandler<dim, spacedim> &dof2,
685 OutVector &u2);
686
700 template <int dim, class InVector, class OutVector, int spacedim>
701 void
703 const InVector &u1,
705 OutVector &u1_interpolated);
706
719 template <int dim, class InVector, class OutVector, int spacedim>
720 void
722 const DoFHandler<dim, spacedim> &dof1,
724 const InVector &u1,
725 const DoFHandler<dim, spacedim> &dof2,
727 OutVector &u1_interpolated);
728
738 template <int dim, class InVector, class OutVector, int spacedim>
739 void
741 const InVector &z1,
743 OutVector &z1_difference);
744
757 template <int dim, class InVector, class OutVector, int spacedim>
758 void
760 const DoFHandler<dim, spacedim> &dof1,
762 const InVector &z1,
763 const DoFHandler<dim, spacedim> &dof2,
765 OutVector &z1_difference);
766
767
768
777 template <int dim, class InVector, class OutVector, int spacedim>
778 void
780 const InVector &u1,
781 const DoFHandler<dim, spacedim> &dof2,
782 OutVector &u2);
783
844 template <int dim, class InVector, class OutVector, int spacedim>
845 void
847 const InVector &z1,
848 const DoFHandler<dim, spacedim> &dof2,
849 OutVector &z2);
850
863 template <int dim, class InVector, class OutVector, int spacedim>
864 void
866 const DoFHandler<dim, spacedim> &dof1,
867 const InVector &z1,
868 const DoFHandler<dim, spacedim> &dof2,
870 OutVector &z2);
871
887 template <int dim>
888 std::vector<unsigned int>
890
897 template <int dim>
898 std::vector<unsigned int>
900
976 namespace Compositing
977 {
994 template <int dim, int spacedim>
997 const std::vector<const FiniteElement<dim, spacedim> *> &fes,
998 const std::vector<unsigned int> &multiplicities,
999 const bool do_tensor_product = true);
1000
1006 template <int dim, int spacedim>
1009 const std::initializer_list<
1010 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1011 &fe_systems);
1012
1019 template <int dim, int spacedim>
1020 DEAL_II_DEPRECATED_EARLY FiniteElementData<dim>
1022 const unsigned int N1,
1023 const FiniteElement<dim, spacedim> *fe2 = nullptr,
1024 const unsigned int N2 = 0,
1025 const FiniteElement<dim, spacedim> *fe3 = nullptr,
1026 const unsigned int N3 = 0,
1027 const FiniteElement<dim, spacedim> *fe4 = nullptr,
1028 const unsigned int N4 = 0,
1029 const FiniteElement<dim, spacedim> *fe5 = nullptr,
1030 const unsigned int N5 = 0);
1031
1044 template <int dim, int spacedim>
1045 std::vector<bool>
1047 const std::vector<const FiniteElement<dim, spacedim> *> &fes,
1048 const std::vector<unsigned int> &multiplicities);
1049
1055 template <int dim, int spacedim>
1056 std::vector<bool>
1058 const std::initializer_list<
1059 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1060 &fe_systems);
1061
1079 template <int dim, int spacedim>
1080 DEAL_II_DEPRECATED_EARLY std::vector<bool>
1083 const unsigned int N1,
1084 const FiniteElement<dim, spacedim> *fe2 = nullptr,
1085 const unsigned int N2 = 0,
1086 const FiniteElement<dim, spacedim> *fe3 = nullptr,
1087 const unsigned int N3 = 0,
1088 const FiniteElement<dim, spacedim> *fe4 = nullptr,
1089 const unsigned int N4 = 0,
1090 const FiniteElement<dim, spacedim> *fe5 = nullptr,
1091 const unsigned int N5 = 0);
1092
1093
1110 template <int dim, int spacedim>
1111 std::vector<ComponentMask>
1113 const std::vector<const FiniteElement<dim, spacedim> *> &fes,
1114 const std::vector<unsigned int> &multiplicities,
1115 const bool do_tensor_product = true);
1116
1122 template <int dim, int spacedim>
1123 std::vector<ComponentMask>
1125 const std::initializer_list<
1126 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1127 &fe_systems);
1128
1150 template <int dim, int spacedim>
1151 DEAL_II_DEPRECATED_EARLY std::vector<ComponentMask>
1154 const unsigned int N1,
1155 const FiniteElement<dim, spacedim> *fe2 = nullptr,
1156 const unsigned int N2 = 0,
1157 const FiniteElement<dim, spacedim> *fe3 = nullptr,
1158 const unsigned int N3 = 0,
1159 const FiniteElement<dim, spacedim> *fe4 = nullptr,
1160 const unsigned int N4 = 0,
1161 const FiniteElement<dim, spacedim> *fe5 = nullptr,
1162 const unsigned int N5 = 0,
1163 const bool do_tensor_product = true);
1164
1181 template <int dim, int spacedim>
1182 void
1184 std::vector<std::pair<std::pair<unsigned int, unsigned int>,
1185 unsigned int>> &system_to_base_table,
1186 std::vector<std::pair<unsigned int, unsigned int>>
1187 &system_to_component_table,
1188 std::vector<std::pair<std::pair<unsigned int, unsigned int>,
1189 unsigned int>> &component_to_base_table,
1190 const FiniteElement<dim, spacedim> &finite_element,
1191 const bool do_tensor_product = true);
1192
1208 template <int dim, int spacedim>
1209 void
1211 std::vector<std::pair<std::pair<unsigned int, unsigned int>,
1212 unsigned int>> &face_system_to_base_table,
1213 std::vector<std::pair<unsigned int, unsigned int>>
1214 &face_system_to_component_table,
1215 const FiniteElement<dim, spacedim> &finite_element,
1216 const bool do_tensor_product = true,
1217 const unsigned int face_no = 0 /*TODO*/);
1218
1219 } // namespace Compositing
1220
1221
1255 template <int dim, int spacedim = dim>
1256 std::unique_ptr<FiniteElement<dim, spacedim>>
1257 get_fe_by_name(const std::string &name);
1258
1301 template <int dim, int spacedim>
1302 void
1303 add_fe_name(const std::string &name,
1304 const FEFactoryBase<dim, spacedim> *factory);
1305
1316 std::string,
1317 << "Can't re-generate a finite element from the string '"
1318 << arg1 << "'.");
1319
1332 char,
1333 int,
1334 << "The dimension " << arg1
1335 << " in the finite element string must match "
1336 << "the space dimension " << arg2 << '.');
1337
1344
1358
1366 "You are using continuous elements on a grid with "
1367 "hanging nodes but without providing hanging node "
1368 "constraints. Use the respective function with "
1369 "additional AffineConstraints argument(s), instead.");
1382 int,
1383 int,
1384 int,
1385 int,
1386 << "This is a " << arg1 << 'x' << arg2 << " matrix, "
1387 << "but should be a " << arg3 << 'x' << arg4 << " matrix.");
1388
1395 double,
1396 << "Least squares fit leaves a gap of " << arg1);
1397
1404 int,
1405 int,
1406 << arg1 << " must be greater than " << arg2);
1407} // namespace FETools
1408
1409
1410#ifndef DOXYGEN
1411
1412namespace FETools
1413{
1414 template <class FE>
1415 std::unique_ptr<FiniteElement<FE::dimension, FE::space_dimension>>
1416 FEFactory<FE>::get(const unsigned int degree) const
1417 {
1418 return std::make_unique<FE>(degree);
1419 }
1420
1421 namespace Compositing
1422 {
1423 template <int dim, int spacedim>
1424 std::vector<bool>
1426 const std::initializer_list<
1427 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1428 &fe_systems)
1429 {
1430 std::vector<const FiniteElement<dim, spacedim> *> fes;
1431 std::vector<unsigned int> multiplicities;
1432
1433 const auto extract =
1434 [&fes, &multiplicities](
1435 const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
1436 unsigned int> &fe_system) {
1437 fes.push_back(fe_system.first.get());
1438 multiplicities.push_back(fe_system.second);
1439 };
1440
1441 for (const auto &p : fe_systems)
1442 extract(p);
1443
1444 return compute_restriction_is_additive_flags(fes, multiplicities);
1445 }
1446
1447
1448
1449 template <int dim, int spacedim>
1452 const std::initializer_list<
1453 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1454 &fe_systems)
1455 {
1456 std::vector<const FiniteElement<dim, spacedim> *> fes;
1457 std::vector<unsigned int> multiplicities;
1458
1459 const auto extract =
1460 [&fes, &multiplicities](
1461 const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
1462 unsigned int> &fe_system) {
1463 fes.push_back(fe_system.first.get());
1464 multiplicities.push_back(fe_system.second);
1465 };
1466
1467 for (const auto &p : fe_systems)
1468 extract(p);
1469
1470 return multiply_dof_numbers(fes, multiplicities, true);
1471 }
1472
1473
1474
1475 template <int dim, int spacedim>
1476 std::vector<ComponentMask>
1478 const std::initializer_list<
1479 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>>
1480 &fe_systems)
1481 {
1482 std::vector<const FiniteElement<dim, spacedim> *> fes;
1483 std::vector<unsigned int> multiplicities;
1484
1485 const auto extract =
1486 [&fes, &multiplicities](
1487 const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
1488 unsigned int> &fe_system) {
1489 fes.push_back(fe_system.first.get());
1490 multiplicities.push_back(fe_system.second);
1491 };
1492
1493 for (const auto &p : fe_systems)
1494 extract(p);
1495
1496 return compute_nonzero_components(fes, multiplicities, true);
1497 }
1498 } // namespace Compositing
1499} // namespace FETools
1500
1501#endif
1502
1506
1507#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_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:177
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define DeclException0(Exception0)
Definition exceptions.h:471
static ::ExceptionBase & ExcTriangulationMismatch()
static ::ExceptionBase & ExcInvalidFEName(std::string arg1)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition exceptions.h:585
static ::ExceptionBase & ExcInvalidFEDimension(char arg1, int arg2)
static ::ExceptionBase & ExcLeastSquaresError(double arg1)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition exceptions.h:539
static ::ExceptionBase & ExcFENotPrimitive()
static ::ExceptionBase & ExcHangingNodesNotAllowed()
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:494
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:516
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)
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)
spacedim const Point< spacedim > & p
Definition grid_tools.h:990
constexpr ReturnType< rank, T >::value_type & extract(T &t, const ArrayType &indices)