Reference documentation for deal.II version Git d84be816e2 2019-07-13 22:20:17 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
dof_accessor.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 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_dof_accessor_h
17 #define dealii_dof_accessor_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/dofs/dof_handler.h>
23 
24 #include <deal.II/grid/tria_accessor.h>
25 
26 #include <deal.II/hp/dof_handler.h>
27 
28 #include <vector>
29 
30 DEAL_II_NAMESPACE_OPEN
31 
32 template <typename number>
33 class FullMatrix;
34 template <typename number>
35 class Vector;
36 template <typename number>
38 
39 template <typename Accessor>
41 
42 template <int, int>
44 
45 
46 namespace internal
47 {
48  namespace DoFCellAccessorImplementation
49  {
50  struct Implementation;
51  }
52 
53  namespace DoFHandlerImplementation
54  {
55  struct Implementation;
56  namespace Policy
57  {
58  struct Implementation;
59  }
60  } // namespace DoFHandlerImplementation
61 
62  namespace hp
63  {
64  namespace DoFHandlerImplementation
65  {
66  struct Implementation;
67  }
68  } // namespace hp
69 } // namespace internal
70 
71 // note: the file dof_accessor.templates.h is included at the end of
72 // this file. this includes a lot of templates and thus makes
73 // compilation slower, but at the same time allows for more aggressive
74 // inlining and thus faster code.
75 
76 
77 namespace internal
78 {
79  namespace DoFAccessorImplementation
80  {
98  template <int structdim, int dim, int spacedim>
99  struct Inheritance
100  {
106  };
107 
108 
114  template <int dim, int spacedim>
115  struct Inheritance<dim, dim, spacedim>
116  {
122  };
123  } // namespace DoFAccessorImplementation
124 } // namespace internal
125 
126 
127 /* -------------------------------------------------------------------------- */
128 
129 
130 
208 template <int structdim, typename DoFHandlerType, bool level_dof_access>
211  structdim,
212  DoFHandlerType::dimension,
213  DoFHandlerType::space_dimension>::BaseClass
214 {
215 public:
220  static const unsigned int dimension = DoFHandlerType::dimension;
221 
226  static const unsigned int space_dimension = DoFHandlerType::space_dimension;
227 
232  using BaseClass = typename ::internal::DoFAccessorImplementation::
233  Inheritance<structdim, dimension, space_dimension>::BaseClass;
234 
238  using AccessorData = DoFHandlerType;
239 
250  DoFAccessor();
251 
268  DoFAccessor(const Triangulation<DoFHandlerType::dimension,
269  DoFHandlerType::space_dimension> *tria,
270  const int level,
271  const int index,
272  const DoFHandlerType *dof_handler);
273 
286  template <int structdim2, int dim2, int spacedim2>
288 
293  template <int dim2, class DoFHandlerType2, bool level_dof_access2>
295 
299  template <bool level_dof_access2>
300  DoFAccessor(
302 
314  &da) = delete;
315 
323  const DoFHandlerType &
324  get_dof_handler() const;
325 
329  template <bool level_dof_access2>
330  void
332 
337  void
338  copy_from(const TriaAccessorBase<structdim,
339  DoFHandlerType::dimension,
340  DoFHandlerType::space_dimension> &da);
341 
346  static bool
347  is_level_cell();
348 
360  child(const unsigned int c) const;
361 
367  typename ::internal::DoFHandlerImplementation::
368  Iterators<DoFHandlerType, level_dof_access>::line_iterator
369  line(const unsigned int i) const;
370 
376  typename ::internal::DoFHandlerImplementation::
377  Iterators<DoFHandlerType, level_dof_access>::quad_iterator
378  quad(const unsigned int i) const;
379 
425  void
426  get_dof_indices(
427  std::vector<types::global_dof_index> &dof_indices,
428  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
429 
436  void
437  get_mg_dof_indices(
438  const int level,
439  std::vector<types::global_dof_index> &dof_indices,
440  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
441 
445  void
446  set_mg_dof_indices(
447  const int level,
448  const std::vector<types::global_dof_index> &dof_indices,
449  const unsigned int fe_index = DoFHandlerType::default_fe_index);
450 
469  vertex_dof_index(
470  const unsigned int vertex,
471  const unsigned int i,
472  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
473 
480  mg_vertex_dof_index(
481  const int level,
482  const unsigned int vertex,
483  const unsigned int i,
484  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
485 
514  dof_index(
515  const unsigned int i,
516  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
517 
522  mg_dof_index(const int level, const unsigned int i) const;
523 
545  unsigned int
546  n_active_fe_indices() const;
547 
555  unsigned int
556  nth_active_fe_index(const unsigned int n) const;
557 
564  std::set<unsigned int>
565  get_active_fe_indices() const;
566 
575  bool
576  fe_index_is_active(const unsigned int fe_index) const;
577 
583  const FiniteElement<DoFHandlerType::dimension,
584  DoFHandlerType::space_dimension> &
585  get_fe(const unsigned int fe_index) const;
586 
596  DeclExceptionMsg(ExcInvalidObject,
597  "This accessor object has not been "
598  "associated with any DoFHandler object.");
604  DeclException0(ExcVectorNotEmpty);
610  DeclException0(ExcVectorDoesNotMatch);
616  DeclException0(ExcMatrixDoesNotMatch);
624  DeclException0(ExcNotActive);
631 
632 protected:
636  DoFHandlerType *dof_handler;
637 
638 public:
652  template <int dim2, class DoFHandlerType2, bool level_dof_access2>
653  bool
654  operator==(
656 
660  template <int dim2, class DoFHandlerType2, bool level_dof_access2>
661  bool
662  operator!=(
664 
665 protected:
669  void
670  set_dof_handler(DoFHandlerType *dh);
671 
689  void
690  set_dof_index(
691  const unsigned int i,
692  const types::global_dof_index index,
693  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
694 
695  void
696  set_mg_dof_index(const int level,
697  const unsigned int i,
698  const types::global_dof_index index) const;
699 
717  void
718  set_vertex_dof_index(
719  const unsigned int vertex,
720  const unsigned int i,
721  const types::global_dof_index index,
722  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
723 
724  void
725  set_mg_vertex_dof_index(
726  const int level,
727  const unsigned int vertex,
728  const unsigned int i,
729  const types::global_dof_index index,
730  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
731 
736  template <typename>
737  friend class TriaRawIterator;
738  template <int, class, bool>
739  friend class DoFAccessor;
740 
741 private:
746  template <int dim, int spacedim>
747  friend class DoFHandler;
748  template <int dim, int spacedim>
749  friend class hp::DoFHandler;
750 
751  friend struct ::internal::DoFHandlerImplementation::Policy::
752  Implementation;
753  friend struct ::internal::DoFHandlerImplementation::Implementation;
754  friend struct ::internal::hp::DoFHandlerImplementation::Implementation;
755  friend struct ::internal::DoFCellAccessorImplementation::Implementation;
756  friend struct ::internal::DoFAccessorImplementation::Implementation;
757 };
758 
759 
760 
770 template <template <int, int> class DoFHandlerType,
771  int spacedim,
772  bool level_dof_access>
773 class DoFAccessor<0, DoFHandlerType<1, spacedim>, level_dof_access>
774  : public TriaAccessor<0, 1, spacedim>
775 {
776 public:
781  static const unsigned int dimension = 1;
782 
787  static const unsigned int space_dimension = spacedim;
788 
794 
798  using AccessorData = DoFHandlerType<1, spacedim>;
799 
810  DoFAccessor();
811 
828  DoFAccessor(
829  const Triangulation<1, spacedim> * tria,
830  const typename TriaAccessor<0, 1, spacedim>::VertexKind vertex_kind,
831  const unsigned int vertex_index,
832  const DoFHandlerType<1, spacedim> * dof_handler);
833 
840  const int = 0,
841  const int = 0,
842  const DoFHandlerType<1, spacedim> *dof_handler = 0);
843 
856  template <int structdim2, int dim2, int spacedim2>
858 
863  template <int dim2, class DoFHandlerType2, bool level_dof_access2>
865 
875  DoFAccessor<0, DoFHandlerType<1, spacedim>, level_dof_access> &
876  operator=(const DoFAccessor<0, DoFHandlerType<1, spacedim>, level_dof_access>
877  &da) = delete;
878 
886  const DoFHandlerType<1, spacedim> &
887  get_dof_handler() const;
888 
892  template <bool level_dof_access2>
893  void
894  copy_from(
895  const DoFAccessor<0, DoFHandlerType<1, spacedim>, level_dof_access2> &a);
896 
901  void
902  copy_from(const TriaAccessorBase<0, 1, spacedim> &da);
903 
917  child(const unsigned int c) const;
918 
925  typename ::internal::DoFHandlerImplementation::
926  Iterators<DoFHandlerType<1, spacedim>, level_dof_access>::line_iterator
927  line(const unsigned int i) const;
928 
935  typename ::internal::DoFHandlerImplementation::
936  Iterators<DoFHandlerType<1, spacedim>, level_dof_access>::quad_iterator
937  quad(const unsigned int i) const;
938 
981  void
982  get_dof_indices(
983  std::vector<types::global_dof_index> &dof_indices,
984  const unsigned int fe_index = AccessorData::default_fe_index) const;
985 
992  void
993  get_mg_dof_indices(
994  const int level,
995  std::vector<types::global_dof_index> &dof_indices,
996  const unsigned int fe_index = AccessorData::default_fe_index) const;
997 
1016  vertex_dof_index(
1017  const unsigned int vertex,
1018  const unsigned int i,
1019  const unsigned int fe_index = AccessorData::default_fe_index) const;
1020 
1036  dof_index(const unsigned int i,
1037  const unsigned int fe_index = AccessorData::default_fe_index) const;
1038 
1057  unsigned int
1058  n_active_fe_indices() const;
1059 
1067  unsigned int
1068  nth_active_fe_index(const unsigned int n) const;
1069 
1078  bool
1079  fe_index_is_active(const unsigned int fe_index) const;
1080 
1087  DoFHandlerType<1, spacedim>::space_dimension> &
1088  get_fe(const unsigned int fe_index) const;
1089 
1099  DeclExceptionMsg(ExcInvalidObject,
1100  "This accessor object has not been "
1101  "associated with any DoFHandler object.");
1107  DeclException0(ExcVectorNotEmpty);
1113  DeclException0(ExcVectorDoesNotMatch);
1119  DeclException0(ExcMatrixDoesNotMatch);
1127  DeclException0(ExcNotActive);
1134 
1135 protected:
1139  DoFHandlerType<1, spacedim> *dof_handler;
1140 
1144  template <int dim2, class DoFHandlerType2, bool level_dof_access2>
1145  bool
1146  operator==(
1148 
1152  template <int dim2, class DoFHandlerType2, bool level_dof_access2>
1153  bool
1154  operator!=(
1156 
1160  void set_dof_handler(DoFHandlerType<1, spacedim> *dh);
1161 
1179  void
1180  set_dof_index(
1181  const unsigned int i,
1182  const types::global_dof_index index,
1183  const unsigned int fe_index = AccessorData::default_fe_index) const;
1184 
1202  void
1203  set_vertex_dof_index(
1204  const unsigned int vertex,
1205  const unsigned int i,
1206  const types::global_dof_index index,
1207  const unsigned int fe_index = AccessorData::default_fe_index) const;
1208 
1213  template <typename>
1214  friend class TriaRawIterator;
1215 
1216 
1221  template <int, int>
1222  friend class DoFHandler;
1223  template <int, int>
1224  friend class hp::DoFHandler;
1225 
1226  friend struct ::internal::DoFHandlerImplementation::Policy::
1227  Implementation;
1228  friend struct ::internal::DoFHandlerImplementation::Implementation;
1229  friend struct ::internal::hp::DoFHandlerImplementation::Implementation;
1230  friend struct ::internal::DoFCellAccessorImplementation::Implementation;
1231 };
1232 
1233 
1234 
1235 /* -------------------------------------------------------------------------- */
1236 
1237 
1259 template <int structdim, int dim, int spacedim = dim>
1260 class DoFInvalidAccessor : public InvalidAccessor<structdim, dim, spacedim>
1261 {
1262 public:
1266  using AccessorData =
1268 
1277  const int level = -1,
1278  const int index = -1,
1279  const AccessorData * local_data = 0);
1280 
1289 
1294  template <typename OtherAccessor>
1295  DoFInvalidAccessor(const OtherAccessor &);
1296 
1302  void
1303  set_dof_index(const unsigned int i,
1304  const types::global_dof_index index,
1305  const unsigned int fe_index =
1307 };
1308 
1309 
1310 
1311 /* -------------------------------------------------------------------------- */
1312 
1313 
1326 template <typename DoFHandlerType, bool level_dof_access>
1327 class DoFCellAccessor : public DoFAccessor<DoFHandlerType::dimension,
1328  DoFHandlerType,
1329  level_dof_access>
1330 {
1331 public:
1335  static const unsigned int dim = DoFHandlerType::dimension;
1336 
1340  static const unsigned int spacedim = DoFHandlerType::space_dimension;
1341 
1342 
1346  using AccessorData = DoFHandlerType;
1347 
1352  using BaseClass =
1354 
1358  using Container = DoFHandlerType;
1359 
1364  using face_iterator = TriaIterator<DoFAccessor<DoFHandlerType::dimension - 1,
1365  DoFHandlerType,
1366  level_dof_access>>;
1367 
1378  DoFCellAccessor(const Triangulation<DoFHandlerType::dimension,
1379  DoFHandlerType::space_dimension> *tria,
1380  const int level,
1381  const int index,
1382  const AccessorData *local_data);
1383 
1396  template <int structdim2, int dim2, int spacedim2>
1398 
1403  template <int dim2, class DoFHandlerType2, bool level_dof_access2>
1404  explicit DoFCellAccessor(
1406 
1418  delete;
1419 
1434  parent() const;
1435 
1449  neighbor(const unsigned int i) const;
1450 
1457  periodic_neighbor(const unsigned int i) const;
1458 
1465  neighbor_or_periodic_neighbor(const unsigned int i) const;
1466 
1473  child(const unsigned int i) const;
1474 
1482  face(const unsigned int i) const;
1483 
1491  neighbor_child_on_subface(const unsigned int face_no,
1492  const unsigned int subface_no) const;
1493 
1501  periodic_neighbor_child_on_subface(const unsigned int face_no,
1502  const unsigned int subface_no) const;
1503 
1529  template <class InputVector, typename number>
1530  void
1531  get_dof_values(const InputVector &values, Vector<number> &local_values) const;
1532 
1547  template <class InputVector, typename ForwardIterator>
1548  void
1549  get_dof_values(const InputVector &values,
1550  ForwardIterator local_values_begin,
1551  ForwardIterator local_values_end) const;
1552 
1570  template <class InputVector, typename ForwardIterator>
1571  void
1572  get_dof_values(
1574  const InputVector & values,
1575  ForwardIterator local_values_begin,
1576  ForwardIterator local_values_end) const;
1577 
1599  template <class OutputVector, typename number>
1600  void
1601  set_dof_values(const Vector<number> &local_values,
1602  OutputVector & values) const;
1603 
1635  template <class InputVector, typename number>
1636  void
1637  get_interpolated_dof_values(
1638  const InputVector &values,
1639  Vector<number> & interpolated_values,
1640  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
1641 
1694  template <class OutputVector, typename number>
1695  void
1696  set_dof_values_by_interpolation(
1697  const Vector<number> &local_values,
1698  OutputVector & values,
1699  const unsigned int fe_index = DoFHandlerType::default_fe_index) const;
1700 
1709  template <typename number, typename OutputVector>
1710  void
1711  distribute_local_to_global(const Vector<number> &local_source,
1712  OutputVector & global_destination) const;
1713 
1722  template <typename ForwardIterator, typename OutputVector>
1723  void
1724  distribute_local_to_global(ForwardIterator local_source_begin,
1725  ForwardIterator local_source_end,
1726  OutputVector & global_destination) const;
1727 
1738  template <typename ForwardIterator, typename OutputVector>
1739  void
1740  distribute_local_to_global(
1742  ForwardIterator local_source_begin,
1743  ForwardIterator local_source_end,
1744  OutputVector & global_destination) const;
1745 
1752  template <typename number, typename OutputMatrix>
1753  void
1754  distribute_local_to_global(const FullMatrix<number> &local_source,
1755  OutputMatrix &global_destination) const;
1756 
1761  template <typename number, typename OutputMatrix, typename OutputVector>
1762  void
1763  distribute_local_to_global(const FullMatrix<number> &local_matrix,
1764  const Vector<number> & local_vector,
1765  OutputMatrix & global_matrix,
1766  OutputVector & global_vector) const;
1767 
1792  void
1793  get_active_or_mg_dof_indices(
1794  std::vector<types::global_dof_index> &dof_indices) const;
1795 
1831  void
1832  get_dof_indices(std::vector<types::global_dof_index> &dof_indices) const;
1833 
1838  void
1839  get_mg_dof_indices(std::vector<types::global_dof_index> &dof_indices) const;
1840 
1865  const FiniteElement<DoFHandlerType::dimension,
1866  DoFHandlerType::space_dimension> &
1867  get_fe() const;
1868 
1894  unsigned int
1895  active_fe_index() const;
1896 
1923  void
1924  set_active_fe_index(const unsigned int i) const;
1933  void
1934  set_dof_indices(const std::vector<types::global_dof_index> &dof_indices);
1935 
1939  void
1940  set_mg_dof_indices(const std::vector<types::global_dof_index> &dof_indices);
1941 
1945  void
1946  update_cell_dof_indices_cache() const;
1947 
1973  unsigned int
1974  future_fe_index() const;
1975 
1984  void
1985  set_future_fe_index(const unsigned int i) const;
1986 
1993  bool
1994  future_fe_index_set() const;
1995 
2004  void
2005  clear_future_fe_index() const;
2010 private:
2015  template <int dim, int spacedim>
2016  friend class DoFHandler;
2017  friend struct ::internal::DoFCellAccessorImplementation::Implementation;
2018 };
2019 
2020 
2021 template <int sd, typename DoFHandlerType, bool level_dof_access>
2022 inline bool
2024 {
2025  return level_dof_access;
2026 }
2027 
2028 
2029 
2030 template <int structdim, int dim, int spacedim>
2031 template <typename OtherAccessor>
2033  const OtherAccessor &)
2034 {
2035  Assert(false,
2036  ExcMessage("You are attempting an illegal conversion between "
2037  "iterator/accessor types. The constructor you call "
2038  "only exists to make certain template constructs "
2039  "easier to write as dimension independent code but "
2040  "the conversion is not valid in the current context."));
2041 }
2042 
2043 
2044 
2045 DEAL_II_NAMESPACE_CLOSE
2046 
2047 // include more templates
2048 #include "dof_accessor.templates.h"
2049 
2050 
2051 #endif
DoFHandlerType * dof_handler
Definition: dof_accessor.h:636
static bool is_level_cell()
typename ::internal::DoFAccessorImplementation::Inheritance< structdim, dimension, space_dimension >::BaseClass BaseClass
Definition: dof_accessor.h:233
typename InvalidAccessor< structdim, dim, spacedim >::AccessorData AccessorData
typename TriaAccessorBase< structdim, dim, spacedim >::AccessorData AccessorData
LinearAlgebra::distributed::Vector< Number > Vector
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1407
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:496
#define DeclException0(Exception0)
Definition: exceptions.h:473
Definition: hp.h:117
unsigned int global_dof_index
Definition: types.h:89
DoFHandlerType Container
DoFInvalidAccessor(const Triangulation< dim, spacedim > *parent=0, const int level=-1, const int index=-1, const AccessorData *local_data=0)
Definition: dof_accessor.cc:46
DoFHandlerType AccessorData
static ::ExceptionBase & ExcCantCompareIterators()