Reference documentation for deal.II version 8.4.2
dof_handler.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2016 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_iterator_selector.h>
28 #include <deal.II/dofs/number_cache.h>
29 #include <deal.II/hp/fe_collection.h>
30 #include <deal.II/hp/dof_faces.h>
31 #include <deal.II/hp/dof_level.h>
32 
33 #include <vector>
34 #include <map>
35 #include <set>
36 
37 DEAL_II_NAMESPACE_OPEN
38 
39 namespace internal
40 {
41  namespace hp
42  {
43  class DoFLevel;
44 
45  namespace DoFHandler
46  {
47  struct Implementation;
48  }
49  }
50 }
51 
52 namespace internal
53 {
54  namespace DoFAccessor
55  {
56  struct Implementation;
57  }
58 
59  namespace DoFCellAccessor
60  {
61  struct Implementation;
62  }
63 }
64 
65 
66 
67 namespace hp
68 {
69 
118  template <int dim, int spacedim=dim>
119  class DoFHandler : public Subscriptor
120  {
121  typedef ::internal::DoFHandler::Iterators<DoFHandler<dim,spacedim>, false> ActiveSelector;
122  typedef ::internal::DoFHandler::Iterators<DoFHandler<dim,spacedim>, true> LevelSelector;
123  public:
124  typedef typename ActiveSelector::CellAccessor cell_accessor;
125  typedef typename ActiveSelector::FaceAccessor face_accessor;
126 
127  typedef typename ActiveSelector::line_iterator line_iterator;
128  typedef typename ActiveSelector::active_line_iterator active_line_iterator;
129 
130  typedef typename ActiveSelector::quad_iterator quad_iterator;
131  typedef typename ActiveSelector::active_quad_iterator active_quad_iterator;
132 
133  typedef typename ActiveSelector::hex_iterator hex_iterator;
134  typedef typename ActiveSelector::active_hex_iterator active_hex_iterator;
135 
156 #ifndef _MSC_VER
157  typedef typename ActiveSelector::active_cell_iterator active_cell_iterator;
158 #else
159  typedef TriaActiveIterator < ::DoFCellAccessor < DoFHandler < dim, spacedim >, false > > active_cell_iterator;
160 #endif
161 
162  typedef typename LevelSelector::cell_iterator level_cell_iterator;
163 
190 #ifndef _MSC_VER
191  typedef typename ActiveSelector::cell_iterator cell_iterator;
192 #else
194 #endif
195 
196 
197  typedef typename ActiveSelector::face_iterator face_iterator;
198  typedef typename ActiveSelector::active_face_iterator active_face_iterator;
199 
200  typedef typename LevelSelector::CellAccessor level_cell_accessor;
201  typedef typename LevelSelector::FaceAccessor level_face_accessor;
202 
203  typedef typename LevelSelector::face_iterator level_face_iterator;
204 
209 
213  static const unsigned int dimension = dim;
214 
218  static const unsigned int space_dimension = spacedim;
219 
229  static const types::global_dof_index invalid_dof_index = numbers::invalid_dof_index;
230 
241  static const unsigned int default_fe_index = numbers::invalid_unsigned_int;
242 
243 
248 
252  virtual ~DoFHandler ();
253 
275  virtual void distribute_dofs (const hp::FECollection<dim,spacedim> &fe);
276 
281  void set_active_fe_indices (const std::vector<unsigned int> &active_fe_indices);
282 
288  void get_active_fe_indices (std::vector<unsigned int> &active_fe_indices) const;
289 
295  virtual void clear ();
296 
314  void renumber_dofs (const std::vector<types::global_dof_index> &new_numbers);
315 
333  unsigned int max_couplings_between_dofs () const;
334 
347  unsigned int max_couplings_between_boundary_dofs () const;
348 
356  cell_iterator begin (const unsigned int level = 0) const;
357 
370  active_cell_iterator begin_active(const unsigned int level = 0) const;
371 
376  cell_iterator end () const;
377 
382  cell_iterator end (const unsigned int level) const;
383 
389  active_cell_iterator end_active (const unsigned int level) const;
390 
405  IteratorRange<cell_iterator> cell_iterators () const;
406 
449  IteratorRange<active_cell_iterator> active_cell_iterators () const;
450 
466  IteratorRange<cell_iterator> cell_iterators_on_level (const unsigned int level) const;
467 
483  IteratorRange<active_cell_iterator> active_cell_iterators_on_level (const unsigned int level) const;
484 
485  /*
486  * @}
487  */
488 
489  /*---------------------------------------*/
490 
491 
509  types::global_dof_index n_dofs () const;
510 
516  types::global_dof_index n_dofs(const unsigned int level) const;
517 
521  types::global_dof_index n_boundary_dofs () const;
522 
531  n_boundary_dofs (const FunctionMap &boundary_ids) const;
532 
538  n_boundary_dofs (const std::set<types::boundary_id> &boundary_ids) const;
539 
553  types::global_dof_index n_locally_owned_dofs() const;
554 
560  const IndexSet &locally_owned_dofs() const;
561 
562 
571  const std::vector<IndexSet> &
572  locally_owned_dofs_per_processor () const;
573 
586  const std::vector<types::global_dof_index> &
587  n_locally_owned_dofs_per_processor () const;
588 
593  const hp::FECollection<dim,spacedim> &get_fe () const;
594 
601  const Triangulation<dim,spacedim> &get_tria () const DEAL_II_DEPRECATED;
602 
607  const Triangulation<dim,spacedim> &get_triangulation () const;
608 
617  virtual std::size_t memory_consumption () const;
618 
623  template <class Archive>
624  void save(Archive &ar, const unsigned int version) const;
625 
630  template <class Archive>
631  void load(Archive &ar, const unsigned int version);
632 
633  BOOST_SERIALIZATION_SPLIT_MEMBER()
634 
638  DeclException0 (ExcInvalidTriangulation);
642  DeclException0 (ExcNoFESelected);
646  DeclException0 (ExcRenumberingIncomplete);
650  DeclException0 (ExcGridsDoNotMatch);
654  DeclException0 (ExcInvalidBoundaryIndicator);
658  DeclException1 (ExcMatrixHasWrongSize,
659  int,
660  << "The matrix has the wrong dimension " << arg1);
664  DeclException0 (ExcFunctionNotUseful);
668  DeclException1 (ExcNewNumbersNotConsecutive,
669  types::global_dof_index,
670  << "The given list of new dof indices is not consecutive: "
671  << "the index " << arg1 << " does not exist.");
675  DeclException2 (ExcInvalidFEIndex,
676  int, int,
677  << "The mesh contains a cell with an active_fe_index of "
678  << arg1 << ", but the finite element collection only has "
679  << arg2 << " elements");
683  DeclException1 (ExcInvalidLevel,
684  int,
685  << "The given level " << arg1
686  << " is not in the valid range!");
690  DeclException0 (ExcFacesHaveNoLevel);
694  DeclException1 (ExcEmptyLevel,
695  int,
696  << "You tried to do something on level " << arg1
697  << ", but this level is empty.");
698 
699  protected:
700 
704  SmartPointer<const Triangulation<dim,spacedim>,DoFHandler<dim,spacedim> > tria;
705 
714  SmartPointer<const hp::FECollection<dim,spacedim>,hp::DoFHandler<dim,spacedim> > finite_elements;
715 
716  private:
717 
724  DoFHandler (const DoFHandler &);
725 
732  DoFHandler &operator = (const DoFHandler &);
733 
734  class MGVertexDoFs
735  {
736  public:
737  MGVertexDoFs ();
738  ~MGVertexDoFs ();
739  types::global_dof_index get_index (const unsigned int level, const unsigned int dof_number) const;
740  void set_index (const unsigned int level, const unsigned int dof_number, const types::global_dof_index index);
741  };
742 
746  void clear_space ();
747 
748  template<int structdim>
749  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;
750 
751  template<int structdim>
752  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;
753 
761  void create_active_fe_table ();
762 
770  void pre_refinement_action ();
771  void post_refinement_action ();
772 
777  void
778  compute_vertex_dof_identities (std::vector<types::global_dof_index> &new_dof_indices) const;
779 
784  void
785  compute_line_dof_identities (std::vector<types::global_dof_index> &new_dof_indices) const;
786 
791  void
792  compute_quad_dof_identities (std::vector<types::global_dof_index> &new_dof_indices) const;
793 
805  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
807 
808  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
810 
811  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
813 
814  void renumber_dofs_internal (const std::vector<types::global_dof_index> &new_numbers,
816 
821  std::vector<::internal::hp::DoFLevel *> levels;
822 
828 
837 
850  std::vector<types::global_dof_index> vertex_dofs;
851 
864  std::vector<types::global_dof_index> vertex_dofs_offsets;
865 
866  std::vector<MGVertexDoFs> mg_vertex_dofs; // we should really remove this field!
867 
874  std::vector<std::vector<bool> *> has_children;
875 
880  std::vector<boost::signals2::connection> tria_listeners;
881 
885  template <int, class, bool> friend class ::DoFAccessor;
886  template <class, bool> friend class ::DoFCellAccessor;
887  friend struct ::internal::DoFAccessor::Implementation;
888  friend struct ::internal::DoFCellAccessor::Implementation;
889 
894  template <int> friend class ::internal::hp::DoFIndicesOnFacesOrEdges;
895  friend struct ::internal::hp::DoFHandler::Implementation;
896  };
897 
898 
899 
900 #ifndef DOXYGEN
901 
902 
903  /* ----------------------- Inline functions ---------------------------------- */
904 
905  template <int dim, int spacedim>
906  template <class Archive>
907  void DoFHandler<dim, spacedim>::save(Archive &ar, unsigned int) const
908  {
909  ar &vertex_dofs;
910  ar &vertex_dofs_offsets;
911  ar &number_cache;
912  ar &levels;
913  ar &faces;
914  ar &has_children;
915 
916  // write out the number of triangulation cells and later check during
917  // loading that this number is indeed correct;
918  unsigned int n_cells = tria->n_cells();
919 
920  ar &n_cells;
921  }
922 
923  template <int dim, int spacedim>
924  template <class Archive>
925  void DoFHandler<dim, spacedim>::load(Archive &ar, unsigned int)
926  {
927  ar &vertex_dofs;
928  ar &vertex_dofs_offsets;
929  ar &number_cache;
930 
931  // boost::serialization can restore pointers just fine, but if the
932  // pointer object still points to something useful, that object is not
933  // destroyed and we end up with a memory leak. consequently, first delete
934  // previous content before re-loading stuff
935  for (unsigned int i = 0; i<levels.size(); ++i)
936  delete levels[i];
937  for (unsigned int i = 0; i<has_children.size(); ++i)
938  delete has_children[i];
939  levels.resize(0);
940  has_children.resize(0);
941  delete faces;
942  faces = 0;
943 
944  ar &levels;
945  ar &faces;
946  ar &has_children;
947 
948  // these are the checks that correspond to the last block in the save()
949  // function
950  unsigned int n_cells;
951 
952  ar &n_cells;
953 
954  AssertThrow(n_cells == tria->n_cells(),
955  ExcMessage("The object being loaded into does not match the triangulation "
956  "that has been stored previously."));
957  }
958 
959  template <int dim, int spacedim>
960  inline
963  {
964  return number_cache.n_global_dofs;
965  }
966 
967 
968  template <int dim, int spacedim>
969  inline
971  DoFHandler<dim,spacedim>::n_dofs (const unsigned int) const
972  {
974  }
975 
976 
977  template <int dim, int spacedim>
980  {
981  return number_cache.n_locally_owned_dofs;
982  }
983 
984 
985  template <int dim, int spacedim>
986  const IndexSet &
988  {
989  return number_cache.locally_owned_dofs;
990  }
991 
992 
993  template <int dim, int spacedim>
994  const std::vector<types::global_dof_index> &
996  {
997  return number_cache.n_locally_owned_dofs_per_processor;
998  }
999 
1000 
1001  template <int dim, int spacedim>
1002  const std::vector<IndexSet> &
1004  {
1005  return number_cache.locally_owned_dofs_per_processor;
1006  }
1007 
1008 
1009 
1010  template<int dim, int spacedim>
1011  inline
1014  {
1015  Assert (finite_elements != 0,
1016  ExcMessage ("No finite element collection is associated with "
1017  "this DoFHandler"));
1018  return *finite_elements;
1019  }
1020 
1021 
1022 
1023  template<int dim, int spacedim>
1024  inline
1027  {
1028  return *tria;
1029  }
1030 
1031 
1032 
1033  template<int dim, int spacedim>
1034  inline
1037  {
1038  return *tria;
1039  }
1040 
1041 
1042 
1043  template<int dim, int spacedim>
1044  inline
1046  {
1047  Assert (false, ExcNotImplemented ());
1048  }
1049 
1050  template<int dim, int spacedim>
1051  inline
1053  {
1054  Assert (false, ExcNotImplemented ());
1055  }
1056 
1057  template<int dim, int spacedim>
1058  inline
1060  const unsigned int) const
1061  {
1062  Assert (false, ExcNotImplemented ());
1063  return invalid_dof_index;
1064  }
1065 
1066  template<int dim, int spacedim>
1067  inline
1068  void DoFHandler<dim, spacedim>::MGVertexDoFs::set_index (const unsigned int,
1069  const unsigned int,
1071  {
1072  Assert (false, ExcNotImplemented ());
1073  }
1074 
1075 
1076 #endif
1077 
1078 }
1079 
1080 DEAL_II_NAMESPACE_CLOSE
1081 
1082 #endif
static const unsigned int invalid_unsigned_int
Definition: types.h:164
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:552
void set_index(const unsigned int level, const unsigned int dof_number, const types::global_dof_index index)
::ExceptionBase & ExcMessage(std::string arg1)
::internal::hp::DoFIndicesOnFaces< dim > * faces
Definition: dof_handler.h:827
::internal::DoFHandler::NumberCache number_cache
Definition: dof_handler.h:836
STL namespace.
#define AssertThrow(cond, exc)
Definition: exceptions.h:358
std::vector< boost::signals2::connection > tria_listeners
Definition: dof_handler.h:880
const FiniteElement< dim, spacedim > & get_fe() const
std::vector<::internal::hp::DoFLevel * > levels
Definition: dof_handler.h:821
ActiveSelector::active_cell_iterator active_cell_iterator
Definition: dof_handler.h:157
BlockDynamicSparsityPattern BlockCompressedSparsityPattern DEAL_II_DEPRECATED
unsigned int n_locally_owned_dofs() const
const std::vector< types::global_dof_index > & n_locally_owned_dofs_per_processor() const
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:542
Definition: types.h:30
unsigned int global_dof_index
Definition: types.h:88
#define Assert(cond, exc)
Definition: exceptions.h:294
types::global_dof_index get_index(const unsigned int level, const unsigned int dof_number) const
types::global_dof_index n_dofs() const
std::map< types::boundary_id, const Function< dim, Number > * > type
Definition: function_map.h:81
ActiveSelector::cell_iterator cell_iterator
Definition: dof_handler.h:191
Definition: hp.h:102
const Triangulation< dim, spacedim > & get_tria() const DEAL_II_DEPRECATED
const std::vector< IndexSet > & locally_owned_dofs_per_processor() const
void load(Archive &ar, const unsigned int version)
FunctionMap< spacedim >::type FunctionMap
Definition: dof_handler.h:208
std::vector< std::vector< bool > * > has_children
Definition: dof_handler.h:874
const Triangulation< dim, spacedim > & get_triangulation() const
std::vector< types::global_dof_index > vertex_dofs_offsets
Definition: dof_handler.h:864
const types::global_dof_index invalid_dof_index
Definition: types.h:178
std::vector< types::global_dof_index > vertex_dofs
Definition: dof_handler.h:850
const IndexSet & locally_owned_dofs() const
void save(Archive &ar, const unsigned int version) const