Reference documentation for deal.II version 9.0.0
fe_tools.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_fe_tools_H
17 #define dealii_fe_tools_H
18 
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/subscriptor.h>
23 #include <deal.II/base/exceptions.h>
24 #include <deal.II/base/geometry_info.h>
25 #include <deal.II/base/tensor.h>
27 #include <deal.II/base/std_cxx14/memory.h>
28 #include <deal.II/distributed/tria.h>
29 #include <deal.II/fe/component_mask.h>
30 #include <deal.II/lac/parallel_vector.h>
31 
32 
33 
34 #include <vector>
35 #include <string>
36 
37 
38 DEAL_II_NAMESPACE_OPEN
39 
40 template <typename number> class FullMatrix;
41 template <int dim> class Quadrature;
42 template <int dim, int spacedim> class FiniteElement;
43 template <int dim, int spacedim> class DoFHandler;
44 template <int dim> class FiniteElementData;
45 class ConstraintMatrix;
46 
47 
48 
51 
52 
68 namespace FETools
69 {
80  template <int dim, int spacedim=dim>
81  class FEFactoryBase : public Subscriptor
82  {
83  public:
87  virtual std::unique_ptr<FiniteElement<dim,spacedim> >
88  get (const unsigned int degree) const = 0;
89 
95  virtual std::unique_ptr<FiniteElement<dim,spacedim> >
96  get (const Quadrature<1> &quad) const = 0;
97 
101  virtual ~FEFactoryBase() = default;
102  };
103 
115  template <class FE>
116  class FEFactory : public FEFactoryBase<FE::dimension,FE::space_dimension>
117  {
118  public:
122  virtual std::unique_ptr<FiniteElement<FE::dimension,FE::space_dimension> >
123  get (const unsigned int degree) const;
124 
129  virtual std::unique_ptr<FiniteElement<FE::dimension,FE::space_dimension> >
130  get (const Quadrature<1> &quad) const;
131  };
132 
148  template <int dim, int spacedim>
150  const FiniteElement<dim,spacedim> &fe,
151  std::vector<unsigned int> &renumbering,
152  std::vector<std::vector<unsigned int> > &start_indices);
153 
169  template <int dim, int spacedim>
171  const FiniteElement<dim,spacedim> &fe,
172  std::vector<types::global_dof_index> &renumbering,
173  std::vector<types::global_dof_index> &block_data,
174  bool return_start_indices = true);
175 
189  template <int dim, typename number, int spacedim>
190  void
192  const FiniteElement<dim,spacedim> &fe2,
193  FullMatrix<number> &interpolation_matrix);
194 
206  template <int dim, typename number, int spacedim>
207  void
209  const FiniteElement<dim,spacedim> &fe2,
210  FullMatrix<number> &interpolation_matrix);
211 
223  template <int dim, typename number, int spacedim>
224  void
226  const FiniteElement<dim,spacedim> &fe2,
227  FullMatrix<number> &difference_matrix);
228 
232  template <int dim, typename number, int spacedim>
234  const FiniteElement<dim,spacedim> &fe2,
235  FullMatrix<number> &matrix);
236 
304  template <int dim, int spacedim>
307 
346  template <int dim, typename number, int spacedim>
348  std::vector<std::vector<FullMatrix<number> > > &matrices,
349  const bool isotropic_only = false,
350  const double threshold = 1.e-12);
351 
373  template <int dim, typename number, int spacedim>
374  void
377  const unsigned int face_coarse,
378  const unsigned int face_fine,
379  const double threshold = 1.e-12);
380 
412  template <int dim, typename number, int spacedim>
414  const FiniteElement<dim,spacedim> &fe,
415  std::vector<std::vector<FullMatrix<number> > > &matrices,
416  const bool isotropic_only = false);
417 
503  template <int dim, int spacedim>
504  void
506  const Quadrature<dim> &lhs_quadrature,
507  const Quadrature<dim> &rhs_quadrature,
508  FullMatrix<double> &X);
509 
517  template <int dim, int spacedim>
518  void
520  const Quadrature<dim> &quadrature,
521  FullMatrix<double> &I_q);
522 
536  template <int dim>
537  void
539  const FullMatrix<double> &projection_matrix,
540  const std::vector< Tensor<1, dim > > &vector_of_tensors_at_qp,
541  std::vector< Tensor<1, dim > > &vector_of_tensors_at_nodes);
542 
543 
544 
548  template <int dim>
549  void
551  const FullMatrix<double> &projection_matrix,
552  const std::vector< SymmetricTensor<2, dim > > &vector_of_tensors_at_qp,
553  std::vector< SymmetricTensor<2, dim > > &vector_of_tensors_at_nodes);
554 
555 
556 
566  template <int dim, int spacedim>
569  const Quadrature<dim - 1> &lhs_quadrature,
570  const Quadrature<dim - 1> &rhs_quadrature,
572  const unsigned int face,
573  FullMatrix<double> &X);
574 
575 
576 
592  template <int dim, int spacedim, typename number>
594  const FiniteElement<dim, spacedim> &finite_element,
595  const std::vector<Vector<number> > &support_point_values,
596  std::vector<number> &dof_values);
597 
598 
599 
601 
633  template <int dim, int spacedim,
634  template <int, int> class DoFHandlerType1,
635  template <int, int> class DoFHandlerType2,
636  class InVector, class OutVector>
637  void
638  interpolate (const DoFHandlerType1<dim,spacedim> &dof1,
639  const InVector &u1,
640  const DoFHandlerType2<dim,spacedim> &dof2,
641  OutVector &u2);
642 
659  template <int dim, int spacedim,
660  template <int, int> class DoFHandlerType1,
661  template <int, int> class DoFHandlerType2,
662  class InVector, class OutVector>
663  void interpolate (const DoFHandlerType1<dim,spacedim> &dof1,
664  const InVector &u1,
665  const DoFHandlerType2<dim,spacedim> &dof2,
666  const ConstraintMatrix &constraints,
667  OutVector &u2);
668 
684  template <int dim,
685  template <int,int> class DoFHandlerType,
686  class InVector, class OutVector, int spacedim>
687  void back_interpolate (const DoFHandlerType<dim,spacedim> &dof1,
688  const InVector &u1,
689  const FiniteElement<dim,spacedim> &fe2,
690  OutVector &u1_interpolated);
691 
704  template <int dim, class InVector, class OutVector, int spacedim>
705  void back_interpolate (const DoFHandler<dim,spacedim> &dof1,
706  const ConstraintMatrix &constraints1,
707  const InVector &u1,
708  const DoFHandler<dim,spacedim> &dof2,
709  const ConstraintMatrix &constraints2,
710  OutVector &u1_interpolated);
711 
721  template <int dim, class InVector, class OutVector, int spacedim>
723  const InVector &z1,
724  const FiniteElement<dim,spacedim> &fe2,
725  OutVector &z1_difference);
726 
739  template <int dim, class InVector, class OutVector, int spacedim>
741  const ConstraintMatrix &constraints1,
742  const InVector &z1,
743  const DoFHandler<dim,spacedim> &dof2,
744  const ConstraintMatrix &constraints2,
745  OutVector &z1_difference);
746 
747 
748 
757  template <int dim, class InVector, class OutVector, int spacedim>
758  void project_dg (const DoFHandler<dim,spacedim> &dof1,
759  const InVector &u1,
760  const DoFHandler<dim,spacedim> &dof2,
761  OutVector &u2);
762 
822  template <int dim, class InVector, class OutVector, int spacedim>
823  void extrapolate (const DoFHandler<dim,spacedim> &dof1,
824  const InVector &z1,
825  const DoFHandler<dim,spacedim> &dof2,
826  OutVector &z2);
827 
840  template <int dim, class InVector, class OutVector, int spacedim>
841  void extrapolate (const DoFHandler<dim,spacedim> &dof1,
842  const InVector &z1,
843  const DoFHandler<dim,spacedim> &dof2,
844  const ConstraintMatrix &constraints,
845  OutVector &z2);
846 
848 
873  template <int dim>
874  void
875  hierarchic_to_lexicographic_numbering (unsigned int degree,
876  std::vector<unsigned int> &h2l);
877 
878  template <int dim>
879  void
881  std::vector<unsigned int> &h2l);
882 
887  template <int dim>
888  std::vector<unsigned int>
890 
896  template <int dim>
897  void
899  std::vector<unsigned int> &l2h);
900 
905  template <int dim>
906  std::vector<unsigned int>
908 
909 
983  namespace Compositing
984  {
985 
1002  template <int dim, int spacedim>
1004  multiply_dof_numbers (const std::vector<const FiniteElement<dim,spacedim>*> &fes,
1005  const std::vector<unsigned int> &multiplicities,
1006  const bool do_tensor_product = true);
1007 
1013  template <int dim, int spacedim>
1016  (const std::initializer_list<std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>> &fe_systems);
1017 
1021  template <int dim, int spacedim>
1024  const unsigned int N1,
1025  const FiniteElement<dim,spacedim> *fe2=nullptr,
1026  const unsigned int N2=0,
1027  const FiniteElement<dim,spacedim> *fe3=nullptr,
1028  const unsigned int N3=0,
1029  const FiniteElement<dim,spacedim> *fe4=nullptr,
1030  const unsigned int N4=0,
1031  const FiniteElement<dim,spacedim> *fe5=nullptr,
1032  const unsigned int N5=0);
1033 
1046  template <int dim, int spacedim>
1047  std::vector<bool>
1049  const std::vector<unsigned int> &multiplicities);
1050 
1055  template <int dim, int spacedim>
1056  std::vector<bool>
1058  (const std::initializer_list<std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>> &fe_systems);
1059 
1074  template <int dim, int spacedim>
1075  std::vector<bool>
1077  const unsigned int N1,
1078  const FiniteElement<dim,spacedim> *fe2=nullptr,
1079  const unsigned int N2=0,
1080  const FiniteElement<dim,spacedim> *fe3=nullptr,
1081  const unsigned int N3=0,
1082  const FiniteElement<dim,spacedim> *fe4=nullptr,
1083  const unsigned int N4=0,
1084  const FiniteElement<dim,spacedim> *fe5=nullptr,
1085  const unsigned int N5=0);
1086 
1087 
1104  template <int dim, int spacedim>
1105  std::vector<ComponentMask>
1106  compute_nonzero_components (const std::vector<const FiniteElement<dim,spacedim>*> &fes,
1107  const std::vector<unsigned int> &multiplicities,
1108  const bool do_tensor_product = true);
1109 
1115  template <int dim, int spacedim>
1116  std::vector<ComponentMask>
1118  (const std::initializer_list<std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>> &fe_systems);
1119 
1138  template <int dim, int spacedim>
1139  std::vector<ComponentMask>
1141  const unsigned int N1,
1142  const FiniteElement<dim,spacedim> *fe2=nullptr,
1143  const unsigned int N2=0,
1144  const FiniteElement<dim,spacedim> *fe3=nullptr,
1145  const unsigned int N3=0,
1146  const FiniteElement<dim,spacedim> *fe4=nullptr,
1147  const unsigned int N4=0,
1148  const FiniteElement<dim,spacedim> *fe5=nullptr,
1149  const unsigned int N5=0,
1150  const bool do_tensor_product = true);
1151 
1168  template <int dim, int spacedim>
1169  void
1170  build_cell_tables(std::vector< std::pair< std::pair< unsigned int, unsigned int >, unsigned int > > &system_to_base_table,
1171  std::vector< std::pair< unsigned int, unsigned int > > &system_to_component_table,
1172  std::vector< std::pair< std::pair< unsigned int, unsigned int >, unsigned int > > &component_to_base_table,
1173  const FiniteElement<dim,spacedim> &finite_element,
1174  const bool do_tensor_product = true);
1175 
1191  template <int dim, int spacedim>
1192  void
1193  build_face_tables(std::vector< std::pair< std::pair< unsigned int, unsigned int >, unsigned int > > &face_system_to_base_table,
1194  std::vector< std::pair< unsigned int, unsigned int > > &face_system_to_component_table,
1195  const FiniteElement<dim,spacedim> &finite_element,
1196  const bool do_tensor_product = true);
1197 
1198  }
1199 
1200 
1234  template <int dim, int spacedim = dim>
1235  std::unique_ptr<FiniteElement<dim, spacedim> >
1236  get_fe_by_name (const std::string &name);
1237 
1238 
1242  template <int dim>
1243  DEAL_II_DEPRECATED
1245  get_fe_from_name (const std::string &name);
1246 
1247 
1290  template <int dim, int spacedim>
1291  void add_fe_name (const std::string &name,
1292  const FEFactoryBase<dim,spacedim> *factory);
1293 
1304  std::string,
1305  << "Can't re-generate a finite element from the string '"
1306  << arg1 << "'.");
1307 
1320  char, int,
1321  << "The dimension " << arg1
1322  << " in the finite element string must match "
1323  << "the space dimension "
1324  << arg2 << ".");
1325 
1332 
1346 
1354  int,
1355  << "You are using continuous elements on a grid with "
1356  << "hanging nodes but without providing hanging node "
1357  << "constraints. Use the respective function with "
1358  << "additional ConstraintMatrix argument(s), instead."
1359  << (arg1?"":""));
1372  int, int, int, int,
1373  << "This is a " << arg1 << "x" << arg2 << " matrix, "
1374  << "but should be a " << arg3 << "x" << arg4 << " matrix.");
1375 
1382  << "Least squares fit leaves a gap of " << arg1);
1383 
1390  int, int,
1391  << arg1 << " must be greater than " << arg2);
1392 }
1393 
1394 
1395 #ifndef DOXYGEN
1396 
1397 namespace FETools
1398 {
1399  template <class FE>
1400  std::unique_ptr<FiniteElement<FE::dimension, FE::space_dimension> >
1401  FEFactory<FE>::get (const unsigned int degree) const
1402  {
1403  return std_cxx14::make_unique<FE>(degree);
1404  }
1405 
1406  namespace Compositing
1407  {
1408  template <int dim, int spacedim>
1409  std::vector<bool>
1411  (const std::initializer_list<std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>> &fe_systems)
1412  {
1413  std::vector<const FiniteElement<dim,spacedim>*> fes;
1414  std::vector<unsigned int> multiplicities;
1415 
1416  const auto extract =
1417  [&fes, &multiplicities]
1418  (const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int> &fe_system)
1419  {
1420  fes.push_back(fe_system.first.get());
1421  multiplicities.push_back(fe_system.second);
1422  };
1423 
1424  for (const auto &p : fe_systems)
1425  extract (p);
1426 
1427  return compute_restriction_is_additive_flags (fes, multiplicities);
1428  }
1429 
1430 
1431 
1432  template <int dim, int spacedim>
1435  (const std::initializer_list<std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>> &fe_systems)
1436  {
1437  std::vector<const FiniteElement<dim,spacedim>*> fes;
1438  std::vector<unsigned int> multiplicities;
1439 
1440  const auto extract =
1441  [&fes, &multiplicities]
1442  (const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int> &fe_system)
1443  {
1444  fes.push_back(fe_system.first.get());
1445  multiplicities.push_back(fe_system.second);
1446  };
1447 
1448  for (const auto &p : fe_systems)
1449  extract (p);
1450 
1451  return multiply_dof_numbers (fes, multiplicities, true);
1452  }
1453 
1454 
1455 
1456  template <int dim, int spacedim>
1457  std::vector<ComponentMask>
1459  (const std::initializer_list<std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int>> &fe_systems)
1460  {
1461  std::vector<const FiniteElement<dim,spacedim>*> fes;
1462  std::vector<unsigned int> multiplicities;
1463 
1464  const auto extract =
1465  [&fes, &multiplicities]
1466  (const std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>, unsigned int> &fe_system)
1467  {
1468  fes.push_back(fe_system.first.get());
1469  multiplicities.push_back(fe_system.second);
1470  };
1471 
1472  for (const auto &p : fe_systems)
1473  extract (p);
1474 
1475  return compute_nonzero_components (fes, multiplicities, true);
1476  }
1477  } //Compositing
1478 } //FETools
1479 
1480 #endif
1481 
1484 DEAL_II_NAMESPACE_CLOSE
1485 
1486 #endif /* dealii_fe_tools_H */
Definition: tria.h:67
void project_dg(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const DoFHandler< dim, spacedim > &dof2, OutVector &u2)
static ::ExceptionBase & ExcLeastSquaresError(double arg1)
void compute_interpolation_to_quadrature_points_matrix(const FiniteElement< dim, spacedim > &fe, const Quadrature< dim > &quadrature, FullMatrix< double > &I_q)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
static ::ExceptionBase & ExcGridNotRefinedAtLeastOnce()
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)
std::unique_ptr< FiniteElement< dim, spacedim > > get_fe_by_name(const std::string &name)
void compute_component_wise(const FiniteElement< dim, spacedim > &fe, std::vector< unsigned int > &renumbering, std::vector< std::vector< unsigned int > > &start_indices)
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)
static ::ExceptionBase & ExcHangingNodesNotAllowed(int arg1)
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)
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 interpolation_difference(const DoFHandler< dim, spacedim > &dof1, const InVector &z1, const FiniteElement< dim, spacedim > &fe2, OutVector &z1_difference)
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)
void hierarchic_to_lexicographic_numbering(unsigned int degree, std::vector< unsigned int > &h2l)
std::vector< bool > compute_restriction_is_additive_flags(const std::vector< const FiniteElement< dim, spacedim > *> &fes, const std::vector< unsigned int > &multiplicities)
ActiveSelector::active_cell_iterator active_cell_iterator
Definition: dof_handler.h:229
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)
FullMatrix< double > compute_node_matrix(const FiniteElement< dim, spacedim > &fe)
void extrapolate(const DoFHandler< dim, spacedim > &dof1, const InVector &z1, const DoFHandler< dim, spacedim > &dof2, OutVector &z2)
static ::ExceptionBase & ExcFENotPrimitive()
void get_projection_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &matrix)
static ::ExceptionBase & ExcMatrixDimensionMismatch(int arg1, int arg2, int arg3, int arg4)
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)
virtual ~FEFactoryBase()=default
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:346
void get_interpolation_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &interpolation_matrix)
static ::ExceptionBase & ExcNotGreaterThan(int arg1, int arg2)
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)
#define DeclException0(Exception0)
Definition: exceptions.h:323
void get_back_interpolation_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &interpolation_matrix)
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)
ReturnType< rank, T >::value_type & extract(T &t, const ArrayType &indices)
virtual std::unique_ptr< FiniteElement< FE::dimension, FE::space_dimension > > get(const unsigned int degree) const
static ::ExceptionBase & ExcInvalidFEDimension(char arg1, int arg2)
void lexicographic_to_hierarchic_numbering(const FiniteElementData< dim > &fe_data, std::vector< unsigned int > &l2h)
static ::ExceptionBase & ExcInvalidFE()
FiniteElement< dim, dim > * get_fe_from_name(const std::string &name)
void add_fe_name(const std::string &name, const FEFactoryBase< dim, spacedim > *factory)
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)
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)
void get_interpolation_difference_matrix(const FiniteElement< dim, spacedim > &fe1, const FiniteElement< dim, spacedim > &fe2, FullMatrix< number > &difference_matrix)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition: exceptions.h:382
static ::ExceptionBase & ExcInvalidFEName(std::string arg1)
void compute_projection_matrices(const FiniteElement< dim, spacedim > &fe, std::vector< std::vector< FullMatrix< number > > > &matrices, const bool isotropic_only=false)
static ::ExceptionBase & ExcTriangulationMismatch()
void back_interpolate(const DoFHandlerType< dim, spacedim > &dof1, const InVector &u1, const FiniteElement< dim, spacedim > &fe2, OutVector &u1_interpolated)
void interpolate(const DoFHandlerType1< dim, spacedim > &dof1, const InVector &u1, const DoFHandlerType2< dim, spacedim > &dof2, OutVector &u2)