Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_fe_collection_h
17 #define dealii_fe_collection_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/fe/fe.h>
21 #include <deal.II/fe/fe_values_extractors.h>
22 #include <deal.II/fe/component_mask.h>
23 
24 #include <memory>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
28 namespace hp
29 {
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 
106  bool
107  operator== (const FECollection<dim,spacedim> &fe_collection) const;
108 
112  bool
113  operator!= (const FECollection<dim,spacedim> &fe_collection) const;
114 
124  void push_back (const FiniteElement<dim,spacedim> &new_fe);
125 
132  const FiniteElement<dim,spacedim> &
133  operator[] (const unsigned int index) const;
134 
138  unsigned int size () const;
139 
149  unsigned int n_components () const;
150 
167  unsigned int n_blocks () const;
168 
173  unsigned int max_dofs_per_vertex () const;
174 
179  unsigned int max_dofs_per_line () const;
180 
185  unsigned int max_dofs_per_quad () const;
186 
191  unsigned int max_dofs_per_hex () const;
192 
197  unsigned int max_dofs_per_face () const;
198 
203  unsigned int max_dofs_per_cell () const;
204 
208  std::size_t memory_consumption () const;
209 
210 
228  bool hp_constraints_are_implemented () const;
229 
253  unsigned int
254  find_least_face_dominating_fe (const std::set<unsigned int> &fes) const;
255 
273  component_mask (const FEValuesExtractors::Scalar &scalar) const;
274 
292  component_mask (const FEValuesExtractors::Vector &vector) const;
293 
312  component_mask (const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
313 
335  component_mask (const BlockMask &block_mask) const;
336 
363  BlockMask
364  block_mask (const FEValuesExtractors::Scalar &scalar) const;
365 
388  BlockMask
389  block_mask (const FEValuesExtractors::Vector &vector) const;
390 
414  BlockMask
415  block_mask (const FEValuesExtractors::SymmetricTensor<2> &sym_tensor) const;
416 
445  BlockMask
446  block_mask (const ComponentMask &component_mask) const;
447 
448 
453 
454  private:
458  std::vector<std::shared_ptr<const FiniteElement<dim,spacedim> > > finite_elements;
459  };
460 
461 
462 
463  /* --------------- inline functions ------------------- */
464 
465  template <int dim, int spacedim>
466  template <class... FETypes>
467  FECollection<dim,spacedim>::FECollection (const FETypes &... fes)
468  {
469  static_assert(is_base_of_all<FiniteElement<dim, spacedim>, FETypes...>::value,
470  "Not all of the input arguments of this function "
471  "are derived from FiniteElement<dim,spacedim>!");
472 
473  // loop over all of the given arguments and add the finite elements to
474  // this collection. Inlining the definition of fe_pointers causes internal
475  // compiler errors on GCC 7.1.1 so we define it separately:
476  const auto fe_pointers = { &fes... };
477  for (auto p : fe_pointers)
478  push_back (*p);
479  }
480 
481 
482  template <int dim, int spacedim>
483  inline
484  unsigned int
486  {
487  return finite_elements.size();
488  }
489 
490 
491  template <int dim, int spacedim>
492  inline
493  unsigned int
495  {
496  Assert (finite_elements.size () > 0, ExcNoFiniteElements());
497 
498  // note that there is no need
499  // here to enforce that indeed
500  // all elements have the same
501  // number of components since we
502  // have already done this when
503  // adding a new element to the
504  // collection.
505 
506  return finite_elements[0]->n_components ();
507  }
508 
509 
510 
511  template <int dim, int spacedim>
512  inline
513  bool
515  {
516  const unsigned int n_elements = size();
517  if (n_elements != fe_collection.size())
518  return false;
519 
520  for (unsigned int i=0; i<n_elements; ++i)
521  if (!(*finite_elements[i] == fe_collection[i]))
522  return false;
523 
524  return true;
525  }
526 
527 
528 
529  template <int dim, int spacedim>
530  inline
531  bool
533  {
534  return !(*this == fe_collection);
535  }
536 
537 
538 
539  template <int dim, int spacedim>
540  inline
542  FECollection<dim,spacedim>::operator[] (const unsigned int index) const
543  {
544  Assert (index < finite_elements.size(),
545  ExcIndexRange (index, 0, finite_elements.size()));
546  return *finite_elements[index];
547  }
548 
549 
550 
551  template <int dim, int spacedim>
552  unsigned int
554  {
556 
557  unsigned int max = 0;
558  for (unsigned int i=0; i<finite_elements.size(); ++i)
559  if (finite_elements[i]->dofs_per_vertex > max)
560  max = finite_elements[i]->dofs_per_vertex;
561 
562  return max;
563  }
564 
565 
566 
567  template <int dim, int spacedim>
568  unsigned int
570  {
572 
573  unsigned int max = 0;
574  for (unsigned int i=0; i<finite_elements.size(); ++i)
575  if (finite_elements[i]->dofs_per_line > max)
576  max = finite_elements[i]->dofs_per_line;
577 
578  return max;
579  }
580 
581 
582 
583  template <int dim, int spacedim>
584  unsigned int
586  {
588 
589  unsigned int max = 0;
590  for (unsigned int i=0; i<finite_elements.size(); ++i)
591  if (finite_elements[i]->dofs_per_quad > max)
592  max = finite_elements[i]->dofs_per_quad;
593 
594  return max;
595  }
596 
597 
598 
599  template <int dim, int spacedim>
600  unsigned int
602  {
604 
605  unsigned int max = 0;
606  for (unsigned int i=0; i<finite_elements.size(); ++i)
607  if (finite_elements[i]->dofs_per_hex > max)
608  max = finite_elements[i]->dofs_per_hex;
609 
610  return max;
611  }
612 
613 
614 
615  template <int dim, int spacedim>
616  unsigned int
618  {
620 
621  unsigned int max = 0;
622  for (unsigned int i=0; i<finite_elements.size(); ++i)
623  if (finite_elements[i]->dofs_per_face > max)
624  max = finite_elements[i]->dofs_per_face;
625 
626  return max;
627  }
628 
629 
630 
631  template <int dim, int spacedim>
632  unsigned int
634  {
636 
637  unsigned int max = 0;
638  for (unsigned int i=0; i<finite_elements.size(); ++i)
639  if (finite_elements[i]->dofs_per_cell > max)
640  max = finite_elements[i]->dofs_per_cell;
641 
642  return max;
643  }
644 
645 
646  template <int dim, int spacedim>
647  bool
649  {
651 
652  bool hp_constraints = true;
653  for (unsigned int i=0; i<finite_elements.size(); ++i)
654  hp_constraints = hp_constraints &&
656 
657  return hp_constraints;
658  }
659 
660 
661 } // namespace hp
662 
663 DEAL_II_NAMESPACE_CLOSE
664 
665 #endif
ComponentMask component_mask(const FEValuesExtractors::Scalar &scalar) const
std::vector< std::shared_ptr< const FiniteElement< dim, spacedim > > > finite_elements
std::size_t memory_consumption() const
unsigned int find_least_face_dominating_fe(const std::set< unsigned int > &fes) const
bool operator!=(const FECollection< dim, spacedim > &fe_collection) const
bool operator==(const FECollection< dim, spacedim > &fe_collection) const
STL namespace.
unsigned int size() const
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
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()
unsigned int max_dofs_per_hex() const
#define Assert(cond, exc)
Definition: exceptions.h:1142
#define DeclException0(Exception0)
Definition: exceptions.h:323
unsigned int max_dofs_per_line() const
Definition: hp.h:102
unsigned int max_dofs_per_face() const
unsigned int max_dofs_per_vertex() const
FECollection()=default
unsigned int n_components() const
const FiniteElement< dim, spacedim > & operator[](const unsigned int index) const
unsigned int max_dofs_per_quad() const