Reference documentation for deal.II version 8.5.1
dof_handler.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2017 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__hp_dof_handler_h
17 #define dealii__hp_dof_handler_h
18 
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/template_constraints.h>
24 #include <deal.II/base/smartpointer.h>
25 #include <deal.II/base/iterator_range.h>
26 #include <deal.II/dofs/function_map.h>
27 #include <deal.II/dofs/dof_accessor.h>
28 #include <deal.II/dofs/dof_iterator_selector.h>
29 #include <deal.II/dofs/number_cache.h>
30 #include <deal.II/hp/fe_collection.h>
31 #include <deal.II/hp/dof_faces.h>
32 #include <deal.II/hp/dof_level.h>
33 
34 #include <vector>
35 #include <map>
36 #include <set>
37 
38 DEAL_II_NAMESPACE_OPEN
39 
40 template <int dim, int spacedim> class Triangulation;
41 
42 namespace internal
43 {
44  namespace hp
45  {
46  class DoFLevel;
47 
48  namespace DoFHandler
49  {
50  struct Implementation;
51  }
52  }
53 }
54 
55 namespace internal
56 {
57  namespace DoFAccessor
58  {
59  struct Implementation;
60  }
61 
62  namespace DoFCellAccessor
63  {
64  struct Implementation;
65  }
66 }
67 
68 
69 
70 namespace hp
71 {
72 
124  template <int dim, int spacedim=dim>
125  class DoFHandler : public Subscriptor
126  {
127  typedef ::internal::DoFHandler::Iterators<DoFHandler<dim,spacedim>, false> ActiveSelector;
128  typedef ::internal::DoFHandler::Iterators<DoFHandler<dim,spacedim>, true> LevelSelector;
129  public:
130  typedef typename ActiveSelector::CellAccessor cell_accessor;
131  typedef typename ActiveSelector::FaceAccessor face_accessor;
132 
133  typedef typename ActiveSelector::line_iterator line_iterator;
134  typedef typename ActiveSelector::active_line_iterator active_line_iterator;
135 
136  typedef typename ActiveSelector::quad_iterator quad_iterator;
137  typedef typename ActiveSelector::active_quad_iterator active_quad_iterator;
138 
139  typedef typename ActiveSelector::hex_iterator hex_iterator;
140  typedef typename ActiveSelector::active_hex_iterator active_hex_iterator;
141 
162 #ifndef _MSC_VER
163  typedef typename ActiveSelector::active_cell_iterator active_cell_iterator;
164 #else
166 #endif
167 
168  typedef typename LevelSelector::cell_iterator level_cell_iterator;
169 
196 #ifndef _MSC_VER
197  typedef typename ActiveSelector::cell_iterator cell_iterator;
198 #else
200 #endif
201 
202 
203  typedef typename ActiveSelector::face_iterator face_iterator;
204  typedef typename ActiveSelector::active_face_iterator active_face_iterator;
205 
206  typedef typename LevelSelector::CellAccessor level_cell_accessor;
207  typedef typename LevelSelector::FaceAccessor level_face_accessor;
208 
209  typedef typename LevelSelector::face_iterator level_face_iterator;
210 
214  static const unsigned int dimension = dim;
215 
219  static const unsigned int space_dimension = spacedim;
220 
231 
242  static const unsigned int default_fe_index = numbers::invalid_unsigned_int;
243 
244 
249 
253  virtual ~DoFHandler ();
254 
276  virtual void distribute_dofs (const hp::FECollection<dim,spacedim> &fe);
277 
282  void set_active_fe_indices (const std::vector<unsigned int> &active_fe_indices);
283 
289  void get_active_fe_indices (std::vector<unsigned int> &active_fe_indices) const;
290 
296  virtual void clear ();
297 
315  void renumber_dofs (const std::vector<types::global_dof_index> &new_numbers);
316 
334  unsigned int max_couplings_between_dofs () const;
335 
348  unsigned int max_couplings_between_boundary_dofs () const;
349 
357  cell_iterator begin (const unsigned int level = 0) const;
358 
371  active_cell_iterator begin_active(const unsigned int level = 0) const;
372 
377  cell_iterator end () const;
378 
383  cell_iterator end (const unsigned int level) const;
384 
390  active_cell_iterator end_active (const unsigned int level) const;
391 
407 
451 
467  IteratorRange<cell_iterator> cell_iterators_on_level (const unsigned int level) const;
468 
485 
486  /*
487  * @}
488  */
489 
490  /*---------------------------------------*/
491 
492 
511 
517  types::global_dof_index n_dofs(const unsigned int level) const;
518 
523 
533  template <typename number>
535  n_boundary_dofs (const std::map<types::boundary_id, const Function<spacedim,number>*> &boundary_ids) const;
536 
542  n_boundary_dofs (const std::set<types::boundary_id> &boundary_ids) const;
543 
558 
564  const IndexSet &locally_owned_dofs() const;
565 
566 
575  const std::vector<IndexSet> &
577 
590  const std::vector<types::global_dof_index> &
592 
597  const hp::FECollection<dim,spacedim> &get_fe () const;
598 
605  const Triangulation<dim,spacedim> &get_tria () const DEAL_II_DEPRECATED;
606 
611  const Triangulation<dim,spacedim> &get_triangulation () const;
612 
621  virtual std::size_t memory_consumption () const;
622 
627  template <class Archive>
628  void save(Archive &ar, const unsigned int version) const;
629 
634  template <class Archive>
635  void load(Archive &ar, const unsigned int version);
636 
637  BOOST_SERIALIZATION_SPLIT_MEMBER()
638 
663  int,
664  << "The matrix has the wrong dimension " << arg1);
673  types::global_dof_index,
674  << "The given list of new dof indices is not consecutive: "
675  << "the index " << arg1 << " does not exist.");
680  int, int,
681  << "The mesh contains a cell with an active_fe_index of "
682  << arg1 << ", but the finite element collection only has "
683  << arg2 << " elements");
688  int,
689  << "The given level " << arg1
690  << " is not in the valid range!");
699  int,
700  << "You tried to do something on level " << arg1
701  << ", but this level is empty.");
702 
703  protected:
704 
708  SmartPointer<const Triangulation<dim,spacedim>,DoFHandler<dim,spacedim> > tria;
709 
718  SmartPointer<const hp::FECollection<dim,spacedim>,hp::DoFHandler<dim,spacedim> > finite_elements;
719 
720  private:
721 
728  DoFHandler (const DoFHandler &);
729 
736  DoFHandler &operator = (const DoFHandler &);
737 
738  class MGVertexDoFs
739  {
740  public:
741  MGVertexDoFs ();
742  ~MGVertexDoFs ();
743  types::global_dof_index get_index (const unsigned int level, const unsigned int dof_number) const;
744  void set_index (const unsigned int level, const unsigned int dof_number, const types::global_dof_index index);
745  };
746 
750  void clear_space ();
751 
752  template<int structdim>
753  types::global_dof_index get_dof_index (const unsigned int obj_level, const unsigned int obj_index, const unsigned int fe_index, const unsigned int local_index) const;
754 
755  template<int structdim>
756  void set_dof_index (const unsigned int obj_level, const unsigned int obj_index, const unsigned int fe_index, const unsigned int local_index, const types::global_dof_index global_index) const;
757 
765  void create_active_fe_table ();
766 
774  void pre_refinement_action ();
775  void post_refinement_action ();
776 
781  void
782  compute_vertex_dof_identities (std::vector<types::global_dof_index> &new_dof_indices) const;
783 
788  void
789  compute_line_dof_identities (std::vector<types::global_dof_index> &new_dof_indices) const;
790 
795  void
796  compute_quad_dof_identities (std::vector<types::global_dof_index> &new_dof_indices) const;
797 
809  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
811 
812  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
814 
815  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
817 
818  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
820 
825  std::vector<::internal::hp::DoFLevel *> levels;
826 
832 
841 
854  std::vector<types::global_dof_index> vertex_dofs;
855 
868  std::vector<types::global_dof_index> vertex_dofs_offsets;
869 
870  std::vector<MGVertexDoFs> mg_vertex_dofs; // we should really remove this field!
871 
878  std::vector<std::vector<bool> *> has_children;
879 
884  std::vector<boost::signals2::connection> tria_listeners;
885 
889  template <int, class, bool> friend class ::DoFAccessor;
890  template <class, bool> friend class ::DoFCellAccessor;
891  friend struct ::internal::DoFAccessor::Implementation;
892  friend struct ::internal::DoFCellAccessor::Implementation;
893 
898  template <int> friend class ::internal::hp::DoFIndicesOnFacesOrEdges;
899  friend struct ::internal::hp::DoFHandler::Implementation;
900  };
901 
902 
903 
904 #ifndef DOXYGEN
905 
906 
907  /* ----------------------- Inline functions ---------------------------------- */
908 
909 
910  template <int dim, int spacedim>
911  template <typename number>
914  {
915  // extract the set of boundary ids and forget about the function object pointers
916  std::set<types::boundary_id> boundary_ids_only;
917  for (typename std::map<types::boundary_id, const Function<spacedim,number>*>::const_iterator
918  p = boundary_ids.begin();
919  p != boundary_ids.end(); ++p)
920  boundary_ids_only.insert (p->first);
921 
922  // then just hand everything over to the other function that does the work
923  return n_boundary_dofs(boundary_ids_only);
924  }
925 
926 
927 
928  template <int dim, int spacedim>
929  template <class Archive>
930  void DoFHandler<dim, spacedim>::save(Archive &ar, unsigned int) const
931  {
932  ar &vertex_dofs;
933  ar &vertex_dofs_offsets;
934  ar &number_cache;
935  ar &levels;
936  ar &faces;
937  ar &has_children;
938 
939  // write out the number of triangulation cells and later check during
940  // loading that this number is indeed correct;
941  unsigned int n_cells = tria->n_cells();
942 
943  ar &n_cells;
944  }
945 
946  template <int dim, int spacedim>
947  template <class Archive>
948  void DoFHandler<dim, spacedim>::load(Archive &ar, unsigned int)
949  {
950  ar &vertex_dofs;
951  ar &vertex_dofs_offsets;
952  ar &number_cache;
953 
954  // boost::serialization can restore pointers just fine, but if the
955  // pointer object still points to something useful, that object is not
956  // destroyed and we end up with a memory leak. consequently, first delete
957  // previous content before re-loading stuff
958  for (unsigned int i = 0; i<levels.size(); ++i)
959  delete levels[i];
960  for (unsigned int i = 0; i<has_children.size(); ++i)
961  delete has_children[i];
962  levels.resize(0);
963  has_children.resize(0);
964  delete faces;
965  faces = 0;
966 
967  ar &levels;
968  ar &faces;
969  ar &has_children;
970 
971  // these are the checks that correspond to the last block in the save()
972  // function
973  unsigned int n_cells;
974 
975  ar &n_cells;
976 
977  AssertThrow(n_cells == tria->n_cells(),
978  ExcMessage("The object being loaded into does not match the triangulation "
979  "that has been stored previously."));
980  }
981 
982  template <int dim, int spacedim>
983  inline
986  {
987  return number_cache.n_global_dofs;
988  }
989 
990 
991  template <int dim, int spacedim>
992  inline
994  DoFHandler<dim,spacedim>::n_dofs (const unsigned int) const
995  {
997  }
998 
999 
1000  template <int dim, int spacedim>
1003  {
1004  return number_cache.n_locally_owned_dofs;
1005  }
1006 
1007 
1008  template <int dim, int spacedim>
1009  const IndexSet &
1011  {
1012  return number_cache.locally_owned_dofs;
1013  }
1014 
1015 
1016  template <int dim, int spacedim>
1017  const std::vector<types::global_dof_index> &
1019  {
1020  return number_cache.n_locally_owned_dofs_per_processor;
1021  }
1022 
1023 
1024  template <int dim, int spacedim>
1025  const std::vector<IndexSet> &
1027  {
1028  return number_cache.locally_owned_dofs_per_processor;
1029  }
1030 
1031 
1032 
1033  template<int dim, int spacedim>
1034  inline
1037  {
1038  Assert (finite_elements != 0,
1039  ExcMessage ("No finite element collection is associated with "
1040  "this DoFHandler"));
1041  return *finite_elements;
1042  }
1043 
1044 
1045 
1046  template<int dim, int spacedim>
1047  inline
1050  {
1051  return *tria;
1052  }
1053 
1054 
1055 
1056  template<int dim, int spacedim>
1057  inline
1060  {
1061  return *tria;
1062  }
1063 
1064 
1065 
1066  template<int dim, int spacedim>
1067  inline
1069  {
1070  Assert (false, ExcNotImplemented ());
1071  }
1072 
1073  template<int dim, int spacedim>
1074  inline
1076  {
1077  Assert (false, ExcNotImplemented ());
1078  }
1079 
1080  template<int dim, int spacedim>
1081  inline
1083  const unsigned int) const
1084  {
1085  Assert (false, ExcNotImplemented ());
1086  return invalid_dof_index;
1087  }
1088 
1089  template<int dim, int spacedim>
1090  inline
1091  void DoFHandler<dim, spacedim>::MGVertexDoFs::set_index (const unsigned int,
1092  const unsigned int,
1094  {
1095  Assert (false, ExcNotImplemented ());
1096  }
1097 
1098 
1099 #endif
1100 
1101 }
1102 
1103 DEAL_II_NAMESPACE_CLOSE
1104 
1105 #endif
cell_iterator begin(const unsigned int level=0) const
IteratorRange< active_cell_iterator > active_cell_iterators_on_level(const unsigned int level) const
void get_active_fe_indices(std::vector< unsigned int > &active_fe_indices) const
types::global_dof_index n_locally_owned_dofs() const
virtual void distribute_dofs(const hp::FECollection< dim, spacedim > &fe)
static const unsigned int invalid_unsigned_int
Definition: types.h:170
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:576
static ::ExceptionBase & ExcInvalidFEIndex(int arg1, int arg2)
DoFHandler(const Triangulation< dim, spacedim > &tria)
SmartPointer< const hp::FECollection< dim, spacedim >, hp::DoFHandler< dim, spacedim > > finite_elements
Definition: dof_handler.h:718
void renumber_dofs(const std::vector< types::global_dof_index > &new_numbers)
virtual std::size_t memory_consumption() const
void set_active_fe_indices(const std::vector< unsigned int > &active_fe_indices)
static ::ExceptionBase & ExcRenumberingIncomplete()
void set_index(const unsigned int level, const unsigned int dof_number, const types::global_dof_index index)
static ::ExceptionBase & ExcGridsDoNotMatch()
void compute_line_dof_identities(std::vector< types::global_dof_index > &new_dof_indices) const
::internal::hp::DoFIndicesOnFaces< dim > * faces
Definition: dof_handler.h:831
const std::vector< types::global_dof_index > & n_locally_owned_dofs_per_processor() const
void pre_refinement_action()
active_cell_iterator begin_active(const unsigned int level=0) const
static ::ExceptionBase & ExcFunctionNotUseful()
::internal::DoFHandler::NumberCache number_cache
Definition: dof_handler.h:840
static ::ExceptionBase & ExcNewNumbersNotConsecutive(types::global_dof_index arg1)
STL namespace.
#define AssertThrow(cond, exc)
Definition: exceptions.h:369
std::vector< boost::signals2::connection > tria_listeners
Definition: dof_handler.h:884
virtual void clear()
static const unsigned int dimension
Definition: dof_handler.h:214
std::vector<::internal::hp::DoFLevel * > levels
Definition: dof_handler.h:825
ActiveSelector::active_cell_iterator active_cell_iterator
Definition: dof_handler.h:163
static const unsigned int default_fe_index
Definition: dof_handler.h:242
const hp::FECollection< dim, spacedim > & get_fe() const
static ::ExceptionBase & ExcNoFESelected()
static ::ExceptionBase & ExcMessage(std::string arg1)
static const unsigned int space_dimension
Definition: dof_handler.h:219
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:564
Definition: types.h:30
unsigned int global_dof_index
Definition: types.h:88
#define Assert(cond, exc)
Definition: exceptions.h:313
static ::ExceptionBase & ExcFacesHaveNoLevel()
IteratorRange< active_cell_iterator > active_cell_iterators() const
const Triangulation< dim, spacedim > & get_tria() const 1
types::global_dof_index get_index(const unsigned int level, const unsigned int dof_number) const
const IndexSet & locally_owned_dofs() const
void save(Archive &ar, const unsigned int version) const
const std::vector< IndexSet > & locally_owned_dofs_per_processor() const
#define DeclException0(Exception0)
Definition: exceptions.h:541
unsigned int max_couplings_between_boundary_dofs() const
ActiveSelector::cell_iterator cell_iterator
Definition: dof_handler.h:197
static ::ExceptionBase & ExcInvalidLevel(int arg1)
void renumber_dofs_internal(const std::vector< types::global_dof_index > &new_numbers, ::internal::int2type< 0 >)
static ::ExceptionBase & ExcInvalidBoundaryIndicator()
Definition: hp.h:102
types::global_dof_index n_boundary_dofs() const
void compute_quad_dof_identities(std::vector< types::global_dof_index > &new_dof_indices) const
active_cell_iterator end_active(const unsigned int level) const
SmartPointer< const Triangulation< dim, spacedim >, DoFHandler< dim, spacedim > > tria
Definition: dof_handler.h:708
void compute_vertex_dof_identities(std::vector< types::global_dof_index > &new_dof_indices) const
const Triangulation< dim, spacedim > & get_triangulation() const
unsigned int max_couplings_between_dofs() const
void load(Archive &ar, const unsigned int version)
virtual ~DoFHandler()
static ::ExceptionBase & ExcMatrixHasWrongSize(int arg1)
std::vector< std::vector< bool > * > has_children
Definition: dof_handler.h:878
types::global_dof_index n_dofs() const
IteratorRange< cell_iterator > cell_iterators_on_level(const unsigned int level) const
static ::ExceptionBase & ExcNotImplemented()
unsigned char boundary_id
Definition: types.h:110
std::vector< types::global_dof_index > vertex_dofs_offsets
Definition: dof_handler.h:868
const types::global_dof_index invalid_dof_index
Definition: types.h:184
void create_active_fe_table()
std::vector< types::global_dof_index > vertex_dofs
Definition: dof_handler.h:854
cell_iterator end() const
IteratorRange< cell_iterator > cell_iterators() const
static ::ExceptionBase & ExcEmptyLevel(int arg1)
static ::ExceptionBase & ExcInvalidTriangulation()
static const types::global_dof_index invalid_dof_index
Definition: dof_handler.h:230