Reference documentation for deal.II version Git 3d170a2f6b 2020-04-03 17:03:45 -0400
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
fe_collection.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2019 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 
21 #include <deal.II/fe/component_mask.h>
22 #include <deal.II/fe/fe.h>
23 #include <deal.II/fe/fe_values_extractors.h>
24 
25 #include <memory>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 namespace hp
30 {
53  template <int dim, int spacedim = dim>
54  class FECollection : public Subscriptor
55  {
56  public:
67  {
74  static unsigned int
75  next_index(const typename hp::FECollection<dim, spacedim> &fe_collection,
76  const unsigned int fe_index)
77  {
78  return ((fe_index + 1) < fe_collection.size()) ? fe_index + 1 :
79  fe_index;
80  }
81 
88  static unsigned int
90  const typename hp::FECollection<dim, spacedim> &fe_collection,
91  const unsigned int fe_index)
92  {
93  (void)fe_collection;
94  return (fe_index > 0) ? fe_index - 1 : fe_index;
95  }
96  };
97 
103  FECollection();
104 
111  explicit FECollection(const FiniteElement<dim, spacedim> &fe);
112 
119  template <class... FETypes>
120  explicit FECollection(const FETypes &... fes);
121 
129  FECollection(const std::vector<const FiniteElement<dim, spacedim> *> &fes);
130 
134  FECollection(const FECollection<dim, spacedim> &) = default;
135 
146  std::is_nothrow_move_constructible<
147  std::vector<std::shared_ptr<const FiniteElement<dim, spacedim>>>>::value
148  &&std::is_nothrow_move_constructible<std::function<
149  unsigned int(const typename hp::FECollection<dim, spacedim> &,
150  const unsigned int)>>::value) = default;
151 
156  operator=(FECollection<dim, spacedim> &&) = default; // NOLINT
157 
162  bool
163  operator==(const FECollection<dim, spacedim> &fe_collection) const;
164 
169  bool
170  operator!=(const FECollection<dim, spacedim> &fe_collection) const;
171 
181  void
183 
191  operator[](const unsigned int index) const;
192 
196  unsigned int
197  size() const;
198 
208  unsigned int
209  n_components() const;
210 
227  unsigned int
228  n_blocks() const;
229 
234  unsigned int
235  max_dofs_per_vertex() const;
236 
241  unsigned int
242  max_dofs_per_line() const;
243 
248  unsigned int
249  max_dofs_per_quad() const;
250 
255  unsigned int
256  max_dofs_per_hex() const;
257 
262  unsigned int
263  max_dofs_per_face() const;
264 
269  unsigned int
270  max_dofs_per_cell() const;
271 
275  std::size_t
276  memory_consumption() const;
277 
278 
296  bool
298 
346  DEAL_II_DEPRECATED unsigned int
347  find_least_face_dominating_fe(const std::set<unsigned int> &fes) const;
348 
370  std::set<unsigned int>
371  find_common_fes(const std::set<unsigned int> &fes,
372  const unsigned int codim = 0) const;
373 
395  std::set<unsigned int>
396  find_enclosing_fes(const std::set<unsigned int> &fes,
397  const unsigned int codim = 0) const;
398 
431  unsigned int
432  find_dominating_fe(const std::set<unsigned int> &fes,
433  const unsigned int codim = 0) const;
434 
467  unsigned int
468  find_dominated_fe(const std::set<unsigned int> &fes,
469  const unsigned int codim = 0) const;
470 
494  unsigned int
495  find_dominating_fe_extended(const std::set<unsigned int> &fes,
496  const unsigned int codim = 0) const;
497 
520  unsigned int
521  find_dominated_fe_extended(const std::set<unsigned int> &fes,
522  const unsigned int codim = 0) const;
523 
536  void
537  set_hierarchy(const std::function<unsigned int(
538  const typename hp::FECollection<dim, spacedim> &,
539  const unsigned int)> &next,
540  const std::function<unsigned int(
541  const typename hp::FECollection<dim, spacedim> &,
542  const unsigned int)> &prev);
543 
551  void
553 
563  unsigned int
564  next_in_hierarchy(const unsigned int fe_index) const;
565 
575  unsigned int
576  previous_in_hierarchy(const unsigned int fe_index) const;
577 
595  component_mask(const FEValuesExtractors::Scalar &scalar) const;
596 
614  component_mask(const FEValuesExtractors::Vector &vector) const;
615 
635  const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
636 
658  component_mask(const BlockMask &block_mask) const;
659 
686  BlockMask
687  block_mask(const FEValuesExtractors::Scalar &scalar) const;
688 
711  BlockMask
712  block_mask(const FEValuesExtractors::Vector &vector) const;
713 
737  BlockMask
738  block_mask(const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
739 
768  BlockMask
769  block_mask(const ComponentMask &component_mask) const;
770 
782 
790  "No FiniteElement has been found in your FECollection that is "
791  "dominated by all children of a cell you are trying to coarsen!");
792 
797  private:
801  std::vector<std::shared_ptr<const FiniteElement<dim, spacedim>>>
803 
808  std::function<unsigned int(const typename hp::FECollection<dim, spacedim> &,
809  const unsigned int)>
811 
816  std::function<unsigned int(const typename hp::FECollection<dim, spacedim> &,
817  const unsigned int)>
819  };
820 
821 
822 
823  /* --------------- inline functions ------------------- */
824 
825  template <int dim, int spacedim>
826  template <class... FETypes>
828  {
829  static_assert(
830  is_base_of_all<FiniteElement<dim, spacedim>, FETypes...>::value,
831  "Not all of the input arguments of this function "
832  "are derived from FiniteElement<dim,spacedim>!");
833 
834  // loop over all of the given arguments and add the finite elements to
835  // this collection. Inlining the definition of fe_pointers causes internal
836  // compiler errors on GCC 7.1.1 so we define it separately:
837  const auto fe_pointers = {
838  (static_cast<const FiniteElement<dim, spacedim> *>(&fes))...};
839  for (const auto p : fe_pointers)
840  push_back(*p);
841  }
842 
843 
844  template <int dim, int spacedim>
845  inline unsigned int
847  {
848  return finite_elements.size();
849  }
850 
851 
852  template <int dim, int spacedim>
853  inline unsigned int
855  {
857 
858  // note that there is no need
859  // here to enforce that indeed
860  // all elements have the same
861  // number of components since we
862  // have already done this when
863  // adding a new element to the
864  // collection.
865 
866  return finite_elements[0]->n_components();
867  }
868 
869 
870 
871  template <int dim, int spacedim>
872  inline bool
874  operator==(const FECollection<dim, spacedim> &fe_collection) const
875  {
876  const unsigned int n_elements = size();
877  if (n_elements != fe_collection.size())
878  return false;
879 
880  for (unsigned int i = 0; i < n_elements; ++i)
881  if (!(*finite_elements[i] == fe_collection[i]))
882  return false;
883 
884  return true;
885  }
886 
887 
888 
889  template <int dim, int spacedim>
890  inline bool
892  operator!=(const FECollection<dim, spacedim> &fe_collection) const
893  {
894  return !(*this == fe_collection);
895  }
896 
897 
898 
899  template <int dim, int spacedim>
901  operator[](const unsigned int index) const
902  {
903  AssertIndexRange(index, finite_elements.size());
904  return *finite_elements[index];
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  if (finite_elements[i]->dofs_per_vertex > max)
918  max = finite_elements[i]->dofs_per_vertex;
919 
920  return max;
921  }
922 
923 
924 
925  template <int dim, int spacedim>
926  unsigned int
928  {
930 
931  unsigned int max = 0;
932  for (unsigned int i = 0; i < finite_elements.size(); ++i)
933  if (finite_elements[i]->dofs_per_line > max)
934  max = finite_elements[i]->dofs_per_line;
935 
936  return max;
937  }
938 
939 
940 
941  template <int dim, int spacedim>
942  unsigned int
944  {
946 
947  unsigned int max = 0;
948  for (unsigned int i = 0; i < finite_elements.size(); ++i)
949  if (finite_elements[i]->dofs_per_quad > max)
950  max = finite_elements[i]->dofs_per_quad;
951 
952  return max;
953  }
954 
955 
956 
957  template <int dim, int spacedim>
958  unsigned int
960  {
962 
963  unsigned int max = 0;
964  for (unsigned int i = 0; i < finite_elements.size(); ++i)
965  if (finite_elements[i]->dofs_per_hex > max)
966  max = finite_elements[i]->dofs_per_hex;
967 
968  return max;
969  }
970 
971 
972 
973  template <int dim, int spacedim>
974  unsigned int
976  {
978 
979  unsigned int max = 0;
980  for (unsigned int i = 0; i < finite_elements.size(); ++i)
981  if (finite_elements[i]->dofs_per_face > max)
982  max = finite_elements[i]->dofs_per_face;
983 
984  return max;
985  }
986 
987 
988 
989  template <int dim, int spacedim>
990  unsigned int
992  {
994 
995  unsigned int max = 0;
996  for (unsigned int i = 0; i < finite_elements.size(); ++i)
997  if (finite_elements[i]->dofs_per_cell > max)
998  max = finite_elements[i]->dofs_per_cell;
999 
1000  return max;
1001  }
1002 
1003 
1004  template <int dim, int spacedim>
1005  bool
1007  {
1009 
1010  bool hp_constraints = true;
1011  for (unsigned int i = 0; i < finite_elements.size(); ++i)
1012  hp_constraints =
1013  hp_constraints && finite_elements[i]->hp_constraints_are_implemented();
1014 
1015  return hp_constraints;
1016  }
1017 
1018 
1019 } // namespace hp
1020 
1021 DEAL_II_NAMESPACE_CLOSE
1022 
1023 #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:75
ComponentMask component_mask(const FEValuesExtractors::Scalar &scalar) const
std::size_t memory_consumption() const
unsigned int find_least_face_dominating_fe(const std::set< unsigned int > &fes) 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:1649
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:1419
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:496
#define DeclException0(Exception0)
Definition: exceptions.h:473
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:89
unsigned int max_dofs_per_face() const
unsigned int max_dofs_per_vertex() const
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
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