Reference documentation for deal.II version Git b8d130ac44 2020-08-12 22:11:34 +0200
\(\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\}}\)
fe_collection.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2020 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_fe_collection_h
17 #define dealii_fe_collection_h
18 
19 #include <deal.II/base/config.h>
20 
22 #include <deal.II/fe/fe.h>
24 
25 #include <memory>
26 
28 
29 namespace hp
30 {
51  template <int dim, int spacedim = dim>
52  class FECollection : public Subscriptor
53  {
54  public:
65  {
72  static unsigned int
73  next_index(const typename hp::FECollection<dim, spacedim> &fe_collection,
74  const unsigned int fe_index)
75  {
76  return ((fe_index + 1) < fe_collection.size()) ? fe_index + 1 :
77  fe_index;
78  }
79 
86  static unsigned int
88  const typename hp::FECollection<dim, spacedim> &fe_collection,
89  const unsigned int fe_index)
90  {
91  (void)fe_collection;
92  return (fe_index > 0) ? fe_index - 1 : fe_index;
93  }
94  };
95 
101  FECollection();
102 
109  explicit FECollection(const FiniteElement<dim, spacedim> &fe);
110 
117  template <class... FETypes>
118  explicit FECollection(const FETypes &... fes);
119 
127  FECollection(const std::vector<const FiniteElement<dim, spacedim> *> &fes);
128 
132  FECollection(const FECollection<dim, spacedim> &) = default;
133 
144  std::is_nothrow_move_constructible<
145  std::vector<std::shared_ptr<const FiniteElement<dim, spacedim>>>>::value
146  &&std::is_nothrow_move_constructible<std::function<
147  unsigned int(const typename hp::FECollection<dim, spacedim> &,
148  const unsigned int)>>::value) = default;
149 
154  operator=(FECollection<dim, spacedim> &&) = default; // NOLINT
155 
160  bool
161  operator==(const FECollection<dim, spacedim> &fe_collection) const;
162 
167  bool
168  operator!=(const FECollection<dim, spacedim> &fe_collection) const;
169 
179  void
181 
189  operator[](const unsigned int index) const;
190 
194  unsigned int
195  size() const;
196 
206  unsigned int
207  n_components() const;
208 
225  unsigned int
226  n_blocks() const;
227 
232  unsigned int
233  max_degree() const;
234 
239  unsigned int
240  max_dofs_per_vertex() const;
241 
246  unsigned int
247  max_dofs_per_line() const;
248 
253  unsigned int
254  max_dofs_per_quad() const;
255 
260  unsigned int
261  max_dofs_per_hex() const;
262 
267  unsigned int
268  max_dofs_per_face() const;
269 
274  unsigned int
275  max_dofs_per_cell() const;
276 
280  std::size_t
281  memory_consumption() const;
282 
283 
301  bool
303 
325  std::set<unsigned int>
326  find_common_fes(const std::set<unsigned int> &fes,
327  const unsigned int codim = 0) const;
328 
350  std::set<unsigned int>
351  find_enclosing_fes(const std::set<unsigned int> &fes,
352  const unsigned int codim = 0) const;
353 
386  unsigned int
387  find_dominating_fe(const std::set<unsigned int> &fes,
388  const unsigned int codim = 0) const;
389 
422  unsigned int
423  find_dominated_fe(const std::set<unsigned int> &fes,
424  const unsigned int codim = 0) const;
425 
449  unsigned int
450  find_dominating_fe_extended(const std::set<unsigned int> &fes,
451  const unsigned int codim = 0) const;
452 
475  unsigned int
476  find_dominated_fe_extended(const std::set<unsigned int> &fes,
477  const unsigned int codim = 0) const;
478 
491  void
492  set_hierarchy(const std::function<unsigned int(
493  const typename hp::FECollection<dim, spacedim> &,
494  const unsigned int)> &next,
495  const std::function<unsigned int(
496  const typename hp::FECollection<dim, spacedim> &,
497  const unsigned int)> &prev);
498 
506  void
508 
518  unsigned int
519  next_in_hierarchy(const unsigned int fe_index) const;
520 
530  unsigned int
531  previous_in_hierarchy(const unsigned int fe_index) const;
532 
550  component_mask(const FEValuesExtractors::Scalar &scalar) const;
551 
569  component_mask(const FEValuesExtractors::Vector &vector) const;
570 
590  const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
591 
613  component_mask(const BlockMask &block_mask) const;
614 
641  BlockMask
642  block_mask(const FEValuesExtractors::Scalar &scalar) const;
643 
666  BlockMask
667  block_mask(const FEValuesExtractors::Vector &vector) const;
668 
692  BlockMask
693  block_mask(const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
694 
723  BlockMask
724  block_mask(const ComponentMask &component_mask) const;
725 
737 
745  "No FiniteElement has been found in your FECollection that is "
746  "dominated by all children of a cell you are trying to coarsen!");
747 
752  private:
756  std::vector<std::shared_ptr<const FiniteElement<dim, spacedim>>>
758 
763  std::function<unsigned int(const typename hp::FECollection<dim, spacedim> &,
764  const unsigned int)>
766 
771  std::function<unsigned int(const typename hp::FECollection<dim, spacedim> &,
772  const unsigned int)>
774  };
775 
776 
777 
778  /* --------------- inline functions ------------------- */
779 
780  template <int dim, int spacedim>
781  template <class... FETypes>
783  {
784  static_assert(
785  is_base_of_all<FiniteElement<dim, spacedim>, FETypes...>::value,
786  "Not all of the input arguments of this function "
787  "are derived from FiniteElement<dim,spacedim>!");
788 
789  // loop over all of the given arguments and add the finite elements to
790  // this collection. Inlining the definition of fe_pointers causes internal
791  // compiler errors on GCC 7.1.1 so we define it separately:
792  const auto fe_pointers = {
793  (static_cast<const FiniteElement<dim, spacedim> *>(&fes))...};
794  for (const auto p : fe_pointers)
795  push_back(*p);
796  }
797 
798 
799  template <int dim, int spacedim>
800  inline unsigned int
802  {
803  return finite_elements.size();
804  }
805 
806 
807  template <int dim, int spacedim>
808  inline unsigned int
810  {
812 
813  // note that there is no need
814  // here to enforce that indeed
815  // all elements have the same
816  // number of components since we
817  // have already done this when
818  // adding a new element to the
819  // collection.
820 
821  return finite_elements[0]->n_components();
822  }
823 
824 
825 
826  template <int dim, int spacedim>
827  inline bool
829  operator==(const FECollection<dim, spacedim> &fe_collection) const
830  {
831  const unsigned int n_elements = size();
832  if (n_elements != fe_collection.size())
833  return false;
834 
835  for (unsigned int i = 0; i < n_elements; ++i)
836  if (!(*finite_elements[i] == fe_collection[i]))
837  return false;
838 
839  return true;
840  }
841 
842 
843 
844  template <int dim, int spacedim>
845  inline bool
847  operator!=(const FECollection<dim, spacedim> &fe_collection) const
848  {
849  return !(*this == fe_collection);
850  }
851 
852 
853 
854  template <int dim, int spacedim>
856  operator[](const unsigned int index) const
857  {
858  AssertIndexRange(index, finite_elements.size());
859  return *finite_elements[index];
860  }
861 
862 
863 
864  template <int dim, int spacedim>
865  unsigned int
867  {
869 
870  unsigned int max = 0;
871  for (unsigned int i = 0; i < finite_elements.size(); ++i)
872  max = std::max(max, finite_elements[i]->degree);
873 
874  return max;
875  }
876 
877 
878 
879  template <int dim, int spacedim>
880  unsigned int
882  {
884 
885  unsigned int max = 0;
886  for (unsigned int i = 0; i < finite_elements.size(); ++i)
887  max = std::max(max, finite_elements[i]->n_dofs_per_vertex());
888 
889  return max;
890  }
891 
892 
893 
894  template <int dim, int spacedim>
895  unsigned int
897  {
899 
900  unsigned int max = 0;
901  for (unsigned int i = 0; i < finite_elements.size(); ++i)
902  max = std::max(max, finite_elements[i]->n_dofs_per_line());
903 
904  return max;
905  }
906 
907 
908 
909  template <int dim, int spacedim>
910  unsigned int
912  {
914 
915  unsigned int max = 0;
916  for (unsigned int i = 0; i < finite_elements.size(); ++i)
917  max = std::max(max, finite_elements[i]->max_dofs_per_quad());
918 
919  return max;
920  }
921 
922 
923 
924  template <int dim, int spacedim>
925  unsigned int
927  {
929 
930  unsigned int max = 0;
931  for (unsigned int i = 0; i < finite_elements.size(); ++i)
932  max = std::max(max, finite_elements[i]->n_dofs_per_hex());
933 
934  return max;
935  }
936 
937 
938 
939  template <int dim, int spacedim>
940  unsigned int
942  {
944 
945  unsigned int max = 0;
946  for (unsigned int i = 0; i < finite_elements.size(); ++i)
947  max = std::max(max, finite_elements[i]->max_dofs_per_face());
948 
949  return max;
950  }
951 
952 
953 
954  template <int dim, int spacedim>
955  unsigned int
957  {
959 
960  unsigned int max = 0;
961  for (unsigned int i = 0; i < finite_elements.size(); ++i)
962  max = std::max(max, finite_elements[i]->n_dofs_per_cell());
963 
964  return max;
965  }
966 
967 
968  template <int dim, int spacedim>
969  bool
971  {
973  return std::all_of(
974  finite_elements.cbegin(),
975  finite_elements.cend(),
976  [](const std::shared_ptr<const FiniteElement<dim, spacedim>> &fe) {
977  return fe->hp_constraints_are_implemented();
978  });
979  }
980 
981 
982 } // namespace hp
983 
985 
986 #endif
std::function< unsigned int(const typename hp::FECollection< dim, spacedim > &, const unsigned int)> hierarchy_prev
unsigned int find_dominated_fe_extended(const std::set< unsigned int > &fes, const unsigned int codim=0) const
static unsigned int next_index(const typename hp::FECollection< dim, spacedim > &fe_collection, const unsigned int fe_index)
Definition: fe_collection.h:73
ComponentMask component_mask(const FEValuesExtractors::Scalar &scalar) const
std::size_t memory_consumption() const
unsigned int find_dominating_fe(const std::set< unsigned int > &fes, const unsigned int codim=0) const
bool operator!=(const FECollection< dim, spacedim > &fe_collection) const
bool operator==(const FECollection< dim, spacedim > &fe_collection) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1636
unsigned int size() const
unsigned int next_in_hierarchy(const unsigned int fe_index) const
unsigned int find_dominating_fe_extended(const std::set< unsigned int > &fes, const unsigned int codim=0) const
std::function< unsigned int(const typename hp::FECollection< dim, spacedim > &, const unsigned int)> hierarchy_next
unsigned int n_blocks() const
BlockMask block_mask(const FEValuesExtractors::Scalar &scalar) const
unsigned int max_dofs_per_cell() const
void push_back(const FiniteElement< dim, spacedim > &new_fe)
bool hp_constraints_are_implemented() const
static ::ExceptionBase & ExcNoFiniteElements()
static ::ExceptionBase & ExcNoDominatedFiniteElementAmongstChildren()
unsigned int max_dofs_per_hex() const
FECollection< dim, spacedim > & operator=(FECollection< dim, spacedim > &&)=default
#define Assert(cond, exc)
Definition: exceptions.h:1411
unsigned int max_degree() const
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:493
#define DeclException0(Exception0)
Definition: exceptions.h:470
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
unsigned int max_dofs_per_line() const
void set_hierarchy(const std::function< unsigned int(const typename hp::FECollection< dim, spacedim > &, const unsigned int)> &next, const std::function< unsigned int(const typename hp::FECollection< dim, spacedim > &, const unsigned int)> &prev)
Definition: hp.h:117
static unsigned int previous_index(const typename hp::FECollection< dim, spacedim > &fe_collection, const unsigned int fe_index)
Definition: fe_collection.h:87
unsigned int max_dofs_per_face() const
unsigned int max_dofs_per_vertex() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
std::set< unsigned int > find_common_fes(const std::set< unsigned int > &fes, const unsigned int codim=0) const
void set_default_hierarchy()
std::vector< std::shared_ptr< const FiniteElement< dim, spacedim > > > finite_elements
std::set< unsigned int > find_enclosing_fes(const std::set< unsigned int > &fes, const unsigned int codim=0) const
unsigned int find_dominated_fe(const std::set< unsigned int > &fes, const unsigned int codim=0) const
unsigned int n_components() const
T max(const T &t, const MPI_Comm &mpi_communicator)
const FiniteElement< dim, spacedim > & operator[](const unsigned int index) const
unsigned int max_dofs_per_quad() const
unsigned int previous_in_hierarchy(const unsigned int fe_index) const