Reference documentation for deal.II version 9.1.0-pre
fe_collection.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 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.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:
61  FECollection() = default;
62 
69  explicit FECollection(const FiniteElement<dim, spacedim> &fe);
70 
75  template <class... FETypes>
76  explicit FECollection(const FETypes &... fes);
77 
85  FECollection(const std::vector<const FiniteElement<dim, spacedim> *> &fes);
86 
90  FECollection(const FECollection<dim, spacedim> &) = default;
91 
95  FECollection(FECollection<dim, spacedim> &&) noexcept = default;
96 
100  FECollection<dim, spacedim> &
101  operator=(FECollection<dim, spacedim> &&) = default; // NOLINT
102 
107  bool
108  operator==(const FECollection<dim, spacedim> &fe_collection) const;
109 
114  bool
115  operator!=(const FECollection<dim, spacedim> &fe_collection) const;
116 
126  void
127  push_back(const FiniteElement<dim, spacedim> &new_fe);
128 
135  const FiniteElement<dim, spacedim> &
136  operator[](const unsigned int index) const;
137 
141  unsigned int
142  size() const;
143 
153  unsigned int
154  n_components() const;
155 
172  unsigned int
173  n_blocks() const;
174 
179  unsigned int
180  max_dofs_per_vertex() const;
181 
186  unsigned int
187  max_dofs_per_line() const;
188 
193  unsigned int
194  max_dofs_per_quad() const;
195 
200  unsigned int
201  max_dofs_per_hex() const;
202 
207  unsigned int
208  max_dofs_per_face() const;
209 
214  unsigned int
215  max_dofs_per_cell() const;
216 
220  std::size_t
221  memory_consumption() const;
222 
223 
241  bool
243 
272  unsigned int
273  find_least_face_dominating_fe(const std::set<unsigned int> &fes) const;
274 
292  component_mask(const FEValuesExtractors::Scalar &scalar) const;
293 
311  component_mask(const FEValuesExtractors::Vector &vector) const;
312 
332  const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
333 
355  component_mask(const BlockMask &block_mask) const;
356 
383  BlockMask
384  block_mask(const FEValuesExtractors::Scalar &scalar) const;
385 
408  BlockMask
409  block_mask(const FEValuesExtractors::Vector &vector) const;
410 
434  BlockMask
435  block_mask(const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
436 
465  BlockMask
467 
468 
473 
474  private:
478  std::vector<std::shared_ptr<const FiniteElement<dim, spacedim>>>
480  };
481 
482 
483 
484  /* --------------- inline functions ------------------- */
485 
486  template <int dim, int spacedim>
487  template <class... FETypes>
488  FECollection<dim, spacedim>::FECollection(const FETypes &... fes)
489  {
490  static_assert(
491  is_base_of_all<FiniteElement<dim, spacedim>, FETypes...>::value,
492  "Not all of the input arguments of this function "
493  "are derived from FiniteElement<dim,spacedim>!");
494 
495  // loop over all of the given arguments and add the finite elements to
496  // this collection. Inlining the definition of fe_pointers causes internal
497  // compiler errors on GCC 7.1.1 so we define it separately:
498  const auto fe_pointers = {&fes...};
499  for (auto p : fe_pointers)
500  push_back(*p);
501  }
502 
503 
504  template <int dim, int spacedim>
505  inline unsigned int
507  {
508  return finite_elements.size();
509  }
510 
511 
512  template <int dim, int spacedim>
513  inline unsigned int
515  {
517 
518  // note that there is no need
519  // here to enforce that indeed
520  // all elements have the same
521  // number of components since we
522  // have already done this when
523  // adding a new element to the
524  // collection.
525 
526  return finite_elements[0]->n_components();
527  }
528 
529 
530 
531  template <int dim, int spacedim>
532  inline bool
534  operator==(const FECollection<dim, spacedim> &fe_collection) const
535  {
536  const unsigned int n_elements = size();
537  if (n_elements != fe_collection.size())
538  return false;
539 
540  for (unsigned int i = 0; i < n_elements; ++i)
541  if (!(*finite_elements[i] == fe_collection[i]))
542  return false;
543 
544  return true;
545  }
546 
547 
548 
549  template <int dim, int spacedim>
550  inline bool
552  operator!=(const FECollection<dim, spacedim> &fe_collection) const
553  {
554  return !(*this == fe_collection);
555  }
556 
557 
558 
559  template <int dim, int spacedim>
561  operator[](const unsigned int index) const
562  {
563  Assert(index < finite_elements.size(),
564  ExcIndexRange(index, 0, finite_elements.size()));
565  return *finite_elements[index];
566  }
567 
568 
569 
570  template <int dim, int spacedim>
571  unsigned int
573  {
575 
576  unsigned int max = 0;
577  for (unsigned int i = 0; i < finite_elements.size(); ++i)
578  if (finite_elements[i]->dofs_per_vertex > max)
579  max = finite_elements[i]->dofs_per_vertex;
580 
581  return max;
582  }
583 
584 
585 
586  template <int dim, int spacedim>
587  unsigned int
589  {
591 
592  unsigned int max = 0;
593  for (unsigned int i = 0; i < finite_elements.size(); ++i)
594  if (finite_elements[i]->dofs_per_line > max)
595  max = finite_elements[i]->dofs_per_line;
596 
597  return max;
598  }
599 
600 
601 
602  template <int dim, int spacedim>
603  unsigned int
605  {
607 
608  unsigned int max = 0;
609  for (unsigned int i = 0; i < finite_elements.size(); ++i)
610  if (finite_elements[i]->dofs_per_quad > max)
611  max = finite_elements[i]->dofs_per_quad;
612 
613  return max;
614  }
615 
616 
617 
618  template <int dim, int spacedim>
619  unsigned int
621  {
623 
624  unsigned int max = 0;
625  for (unsigned int i = 0; i < finite_elements.size(); ++i)
626  if (finite_elements[i]->dofs_per_hex > max)
627  max = finite_elements[i]->dofs_per_hex;
628 
629  return max;
630  }
631 
632 
633 
634  template <int dim, int spacedim>
635  unsigned int
637  {
639 
640  unsigned int max = 0;
641  for (unsigned int i = 0; i < finite_elements.size(); ++i)
642  if (finite_elements[i]->dofs_per_face > max)
643  max = finite_elements[i]->dofs_per_face;
644 
645  return max;
646  }
647 
648 
649 
650  template <int dim, int spacedim>
651  unsigned int
653  {
655 
656  unsigned int max = 0;
657  for (unsigned int i = 0; i < finite_elements.size(); ++i)
658  if (finite_elements[i]->dofs_per_cell > max)
659  max = finite_elements[i]->dofs_per_cell;
660 
661  return max;
662  }
663 
664 
665  template <int dim, int spacedim>
666  bool
668  {
670 
671  bool hp_constraints = true;
672  for (unsigned int i = 0; i < finite_elements.size(); ++i)
673  hp_constraints =
674  hp_constraints && finite_elements[i]->hp_constraints_are_implemented();
675 
676  return hp_constraints;
677  }
678 
679 
680 } // namespace hp
681 
682 DEAL_II_NAMESPACE_CLOSE
683 
684 #endif
ComponentMask component_mask(const FEValuesExtractors::Scalar &scalar) const
BlockMask block_mask(const FEValuesExtractors::Scalar &scalar) const
unsigned int max_dofs_per_cell() const
bool operator==(const FECollection< dim, spacedim > &fe_collection) const
unsigned int max_dofs_per_line() const
const FiniteElement< dim, spacedim > & operator[](const unsigned int index) const
unsigned int max_dofs_per_face() const
STL namespace.
unsigned int size() const
static::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
unsigned int max_dofs_per_vertex() const
void push_back(const FiniteElement< dim, spacedim > &new_fe)
static::ExceptionBase & ExcNoFiniteElements()
#define Assert(cond, exc)
Definition: exceptions.h:1227
#define DeclException0(Exception0)
Definition: exceptions.h:385
bool hp_constraints_are_implemented() const
unsigned int n_blocks() const
Definition: hp.h:102
unsigned int max_dofs_per_hex() const
unsigned int n_components() const
bool operator!=(const FECollection< dim, spacedim > &fe_collection) const
unsigned int max_dofs_per_quad() const
FECollection()=default
std::vector< std::shared_ptr< const FiniteElement< dim, spacedim > > > finite_elements
unsigned int find_least_face_dominating_fe(const std::set< unsigned int > &fes) const
std::size_t memory_consumption() const