version GIT relicensing-7278-g091132d5eb 2026-12-02 03:10:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
dof_accessor.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1998 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_dof_accessor_h
14#define dealii_dof_accessor_h
15
16
17#include <deal.II/base/config.h>
18
19#include <deal.II/base/types.h>
20
24
26
30
31#include <boost/container/small_vector.hpp>
32
33#include <set>
34#include <type_traits>
35#include <vector>
36
37
39
40// Forward declarations
41#ifndef DOXYGEN
42template <typename number>
43class FullMatrix;
44template <typename number>
45class Vector;
46template <typename number>
48
49template <typename Accessor>
50class TriaRawIterator;
51
52template <int, int>
53class FiniteElement;
54
55namespace internal
56{
57 namespace DoFCellAccessorImplementation
58 {
59 struct Implementation;
60 }
61
62 namespace DoFHandlerImplementation
63 {
64 struct Implementation;
65 namespace Policy
66 {
67 struct Implementation;
68 }
69 } // namespace DoFHandlerImplementation
70
71 namespace hp
72 {
73 namespace DoFHandlerImplementation
74 {
75 struct Implementation;
76 }
77 } // namespace hp
78} // namespace internal
79#endif
80
81
82namespace internal
83{
84 namespace DoFAccessorImplementation
85 {
102 template <int structdim, int dim, int spacedim>
111
112
118 template <int dim, int spacedim>
119 struct Inheritance<dim, dim, spacedim>
120 {
126 };
127
128 struct Implementation;
129 } // namespace DoFAccessorImplementation
130} // namespace internal
131
132
133/* -------------------------------------------------------------------------- */
134
135
136
209template <int structdim, int dim, int spacedim, bool level_dof_access>
210class DoFAccessor : public ::internal::DoFAccessorImplementation::
211 Inheritance<structdim, dim, spacedim>::BaseClass
212{
213public:
218 static constexpr unsigned int dimension = dim;
219
224 static constexpr unsigned int space_dimension = spacedim;
225
230 using BaseClass = typename ::internal::DoFAccessorImplementation::
231 Inheritance<structdim, dimension, space_dimension>::BaseClass;
232
237
249
266 const int level,
267 const int index,
269
274 default;
275
279 DoFAccessor( // NOLINT
281 default; // NOLINT
282
286 ~DoFAccessor() = default;
287
300 template <int structdim2, int dim2, int spacedim2>
302
307 template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
310
314 template <bool level_dof_access2>
316
328 delete;
329
334 operator=( // NOLINT
336 default; // NOLINT
337
347
351 template <bool level_dof_access2>
352 void
354
359 void
361
366 static bool
368
380 child(const unsigned int c) const;
381
387 typename ::internal::DoFHandlerImplementation::
388 Iterators<dim, spacedim, level_dof_access>::line_iterator
389 line(const unsigned int i) const;
390
396 typename ::internal::DoFHandlerImplementation::
397 Iterators<dim, spacedim, level_dof_access>::quad_iterator
398 quad(const unsigned int i) const;
399
447 void
449 std::vector<types::global_dof_index> &dof_indices,
450 const types::fe_index fe_index = numbers::invalid_fe_index) const;
451
458 void
460 const int level,
461 std::vector<types::global_dof_index> &dof_indices,
462 const types::fe_index fe_index = numbers::invalid_fe_index) const;
463
467 void
469 const int level,
470 const std::vector<types::global_dof_index> &dof_indices,
472
496 const unsigned int vertex,
497 const unsigned int i,
498 const types::fe_index fe_index = numbers::invalid_fe_index) const;
499
507 const int level,
508 const unsigned int vertex,
509 const unsigned int i,
510 const types::fe_index fe_index = numbers::invalid_fe_index) const;
511
540 dof_index(const unsigned int i,
541 const types::fe_index fe_index = numbers::invalid_fe_index) const;
542
547 mg_dof_index(const int level, const unsigned int i) const;
548
570 unsigned int
572
581 nth_active_fe_index(const unsigned int n) const;
582
589 std::set<types::fe_index>
591
601 bool
602 fe_index_is_active(const types::fe_index fe_index) const;
603
610 get_fe(const types::fe_index fe_index) const;
611
622 "This accessor object has not been "
623 "associated with any DoFHandler object.");
656
657protected:
662
663public:
677 template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
678 bool
681
685 template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
686 bool
689
690protected:
694 void
696
715 void
717 const unsigned int i,
718 const types::global_dof_index index,
719 const types::fe_index fe_index = numbers::invalid_fe_index) const;
720
721 void
723 const unsigned int i,
724 const types::global_dof_index index) const;
725
726 void
728 const int level,
729 const unsigned int vertex,
730 const unsigned int i,
731 const types::global_dof_index index,
732 const types::fe_index fe_index = numbers::invalid_fe_index) const;
733
734 // Iterator classes need to be friends because they need to access
735 // operator== and operator!=.
736 template <typename>
737 friend class TriaRawIterator;
738 template <int, int, int, bool>
739 friend class DoFAccessor;
740
741private:
742 // Make the DoFHandler class a friend so that it can call the set_xxx()
743 // functions.
744 friend class DoFHandler<dim, spacedim>;
745
746 friend struct ::internal::DoFHandlerImplementation::Policy::
747 Implementation;
748 friend struct ::internal::DoFHandlerImplementation::Implementation;
749 friend struct ::internal::hp::DoFHandlerImplementation::Implementation;
750 friend struct ::internal::DoFCellAccessorImplementation::Implementation;
751 friend struct ::internal::DoFAccessorImplementation::Implementation;
752};
753
754
755
763template <int spacedim, bool level_dof_access>
764class DoFAccessor<0, 1, spacedim, level_dof_access>
765 : public TriaAccessor<0, 1, spacedim>
766{
767public:
772 static constexpr unsigned int dimension = 1;
773
778 static constexpr unsigned int space_dimension = spacedim;
779
785
790
801 DoFAccessor();
802
820 const Triangulation<1, spacedim> *tria,
821 const typename TriaAccessor<0, 1, spacedim>::VertexKind vertex_kind,
822 const unsigned int vertex_index,
824
832 const int = 0,
833 const int = 0,
835
848 template <int structdim2, int dim2, int spacedim2>
850
855 template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
858
863
867 // NOLINTNEXTLINE OSX does not compile with noexcept
869
873 ~DoFAccessor() = default;
874
886
892 default;
893
901 const DoFHandler<1, spacedim> &
902 get_dof_handler() const;
903
907 template <bool level_dof_access2>
908 void
909 copy_from(const DoFAccessor<0, 1, spacedim, level_dof_access2> &a);
910
915 void
916 copy_from(const TriaAccessorBase<0, 1, spacedim> &da);
917
930 TriaIterator<DoFAccessor<0, 1, spacedim, level_dof_access>>
931 child(const unsigned int c) const;
932
939 typename ::internal::DoFHandlerImplementation::
940 Iterators<1, spacedim, level_dof_access>::line_iterator
941 line(const unsigned int i) const;
942
949 typename ::internal::DoFHandlerImplementation::
950 Iterators<1, spacedim, level_dof_access>::quad_iterator
951 quad(const unsigned int i) const;
952
996 void
998 std::vector<types::global_dof_index> &dof_indices,
999 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1000
1007 void
1009 const int level,
1010 std::vector<types::global_dof_index> &dof_indices,
1011 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1012
1031 types::global_dof_index
1033 const unsigned int vertex,
1034 const unsigned int i,
1035 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1036
1054 types::global_dof_index
1055 dof_index(const unsigned int i,
1056 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1057
1076 unsigned int
1077 n_active_fe_indices() const;
1078
1086 types::fe_index
1087 nth_active_fe_index(const unsigned int n) const;
1088
1097 bool
1098 fe_index_is_active(const types::fe_index fe_index) const;
1099
1105 const FiniteElement<1, spacedim> &
1106 get_fe(const types::fe_index fe_index) const;
1107
1118 "This accessor object has not been "
1119 "associated with any DoFHandler object.");
1152
1153protected:
1158
1162 template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
1163 bool
1164 operator==(
1165 const DoFAccessor<structdim2, dim2, spacedim2, level_dof_access2> &) const;
1166
1170 template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
1171 bool
1172 operator!=(
1173 const DoFAccessor<structdim2, dim2, spacedim2, level_dof_access2> &) const;
1174
1178 void
1179 set_dof_handler(DoFHandler<1, spacedim> *dh);
1180
1199 void
1201 const unsigned int i,
1202 const types::global_dof_index index,
1203 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1204
1205 // Iterator classes need to be friends because they need to access
1206 // operator== and operator!=.
1207 template <typename>
1208 friend class TriaRawIterator;
1209
1210
1211 // Make the DoFHandler class a friend so that it can call the set_xxx()
1212 // functions.
1213 friend class DoFHandler<1, spacedim>;
1214
1215 friend struct ::internal::DoFHandlerImplementation::Policy::
1217 friend struct ::internal::DoFHandlerImplementation::Implementation;
1218 friend struct ::internal::hp::DoFHandlerImplementation::Implementation;
1219 friend struct ::internal::DoFCellAccessorImplementation::Implementation;
1220};
1221
1222
1223
1224/* -------------------------------------------------------------------------- */
1225
1226
1247template <int structdim, int dim, int spacedim = dim>
1248class DoFInvalidAccessor : public InvalidAccessor<structdim, dim, spacedim>
1249{
1250public:
1256
1264 DoFInvalidAccessor(const void *parent = nullptr,
1265 const int level = -1,
1266 const int index = -1,
1267 const AccessorData *local_data = nullptr);
1268
1277
1282 template <typename OtherAccessor>
1283 DoFInvalidAccessor(const OtherAccessor &);
1284
1291 dof_index(const unsigned int i,
1292 const types::fe_index fe_index =
1294
1300 void
1302 const unsigned int i,
1303 const types::global_dof_index index,
1304 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1305};
1306
1307
1308
1309/* -------------------------------------------------------------------------- */
1310
1311
1323template <int dimension_, int space_dimension_, bool level_dof_access>
1324class DoFCellAccessor : public DoFAccessor<dimension_,
1325 dimension_,
1326 space_dimension_,
1327 level_dof_access>
1328{
1329public:
1333 static const unsigned int dim = dimension_;
1334
1338 static const unsigned int spacedim = space_dimension_;
1339
1340
1345
1352
1357
1363 dimension_,
1364 space_dimension_,
1365 level_dof_access>>;
1366
1378 const int level,
1379 const int index,
1380 const AccessorData *local_data);
1381
1394 template <int structdim2, int dim2, int spacedim2>
1396
1401 template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
1402 explicit DoFCellAccessor(
1404
1410 default;
1411
1417 &&) = default; // NOLINT
1418
1422 ~DoFCellAccessor() = default;
1423
1436 delete;
1437
1442 operator=( // NOLINT
1444 &&) = default; // NOLINT
1445
1460 parent() const;
1461
1475 neighbor(const unsigned int i) const;
1476
1483 periodic_neighbor(const unsigned int i) const;
1484
1491 neighbor_or_periodic_neighbor(const unsigned int i) const;
1492
1499 child(const unsigned int i) const;
1500
1504 boost::container::small_vector<
1508 child_iterators() const;
1509
1517 face(const unsigned int i) const;
1518
1522 boost::container::small_vector<face_iterator,
1524 face_iterators() const;
1525
1533 neighbor_child_on_subface(const unsigned int face_no,
1534 const unsigned int subface_no) const;
1535
1543 periodic_neighbor_child_on_subface(const unsigned int face_no,
1544 const unsigned int subface_no) const;
1545
1574 template <class InputVector, typename number>
1575 void
1576 get_dof_values(const InputVector &values, Vector<number> &local_values) const;
1577
1595 template <typename Number, typename ForwardIterator>
1596 void
1597 get_dof_values(const ReadVector<Number> &values,
1598 ForwardIterator local_values_begin,
1599 ForwardIterator local_values_end) const;
1600
1621 template <class InputVector, typename ForwardIterator>
1622 void
1623 get_dof_values(
1625 const InputVector &values,
1626 ForwardIterator local_values_begin,
1627 ForwardIterator local_values_end) const;
1628
1653 template <class OutputVector, typename number>
1654 void
1655 set_dof_values(const Vector<number> &local_values,
1656 OutputVector &values) const;
1657
1689 template <typename Number>
1690 void
1691 get_interpolated_dof_values(
1692 const ReadVector<Number> &values,
1693 ArrayView<Number> interpolated_values,
1694 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1695
1700 template <typename Number>
1701 void
1702 get_interpolated_dof_values(
1703 const ReadVector<Number> &values,
1704 Vector<Number> &interpolated_values,
1705 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1706
1768 template <class OutputVector, typename number>
1769 void
1770 set_dof_values_by_interpolation(
1771 const Vector<number> &local_values,
1772 OutputVector &values,
1774 const bool perform_check = false) const;
1775
1785 template <class OutputVector, typename number>
1786 void
1787 distribute_local_to_global_by_interpolation(
1788 const Vector<number> &local_values,
1789 OutputVector &values,
1790 const types::fe_index fe_index = numbers::invalid_fe_index) const;
1791
1806 template <typename number, typename OutputVector>
1807 void
1808 distribute_local_to_global(const Vector<number> &local_source,
1809 OutputVector &global_destination) const;
1810
1825 template <typename ForwardIterator, typename OutputVector>
1826 void
1827 distribute_local_to_global(ForwardIterator local_source_begin,
1828 ForwardIterator local_source_end,
1829 OutputVector &global_destination) const;
1830
1844 template <typename ForwardIterator, typename OutputVector>
1845 void
1846 distribute_local_to_global(
1848 ForwardIterator local_source_begin,
1849 ForwardIterator local_source_end,
1850 OutputVector &global_destination) const;
1851
1858 template <typename number, typename OutputMatrix>
1859 void
1860 distribute_local_to_global(const FullMatrix<number> &local_source,
1861 OutputMatrix &global_destination) const;
1862
1867 template <typename number, typename OutputMatrix, typename OutputVector>
1868 void
1869 distribute_local_to_global(const FullMatrix<number> &local_matrix,
1870 const Vector<number> &local_vector,
1871 OutputMatrix &global_matrix,
1872 OutputVector &global_vector) const;
1873
1898 void
1899 get_active_or_mg_dof_indices(
1900 std::vector<types::global_dof_index> &dof_indices) const;
1901
1933 void
1934 get_dof_indices(std::vector<types::global_dof_index> &dof_indices) const;
1935
1940 void
1941 get_mg_dof_indices(std::vector<types::global_dof_index> &dof_indices) const;
1942
1968 get_fe() const;
1969
1996 active_fe_index() const;
1997
2024 void
2025 set_active_fe_index(const types::fe_index i) const;
2034 void
2035 set_dof_indices(const std::vector<types::global_dof_index> &dof_indices);
2036
2040 void
2041 set_mg_dof_indices(const std::vector<types::global_dof_index> &dof_indices);
2042
2069 get_future_fe() const;
2070
2090 future_fe_index() const;
2091
2100 void
2101 set_future_fe_index(const types::fe_index i) const;
2102
2109 bool
2110 future_fe_index_set() const;
2111
2120 void
2121 clear_future_fe_index() const;
2126private:
2127 friend struct ::internal::DoFCellAccessorImplementation::Implementation;
2128};
2129
2130
2131template <int structdim, int dim, int spacedim, bool level_dof_access>
2132inline bool
2137
2138
2139
2140template <int structdim, int dim, int spacedim>
2141template <typename OtherAccessor>
2143 const OtherAccessor &)
2144{
2145 Assert(false,
2146 ExcMessage("You are attempting an illegal conversion between "
2147 "iterator/accessor types. The constructor you call "
2148 "only exists to make certain template constructs "
2149 "easier to write as dimension independent code but "
2150 "the conversion is not valid in the current context."));
2151}
2152
2153
2154
2155/*------------------------- Functions: DoFAccessor ---------------------------*/
2156
2157
2158template <int structdim, int dim, int spacedim, bool level_dof_access>
2163
2164
2165
2166template <int structdim, int dim, int spacedim, bool level_dof_access>
2168 const Triangulation<dim, spacedim> *tria,
2169 const int level,
2170 const int index,
2172 : ::internal::DoFAccessorImplementation::
2173 Inheritance<structdim, dim, spacedim>::BaseClass(tria, level, index)
2174 , dof_handler(const_cast<DoFHandler<dim, spacedim> *>(dof_handler))
2175{
2176 Assert(
2177 tria == nullptr || &dof_handler->get_triangulation() == tria,
2178 ExcMessage(
2179 "You can't create a DoF accessor in which the DoFHandler object "
2180 "uses a different triangulation than the one you pass as argument."));
2181}
2182
2183
2184
2185template <int structdim, int dim, int spacedim, bool level_dof_access>
2186template <int structdim2, int dim2, int spacedim2>
2192
2193
2194
2195template <int structdim, int dim, int spacedim, bool level_dof_access>
2196template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
2199 : BaseClass(other)
2200 , dof_handler(nullptr)
2201{
2202 Assert(false,
2203 ExcMessage(
2204 "You are trying to assign iterators that are incompatible. "
2205 "The reason for incompatibility is that they refer to objects of "
2206 "different dimensionality (e.g., assigning a line iterator "
2207 "to a quad iterator)."));
2208}
2209
2210
2211
2212template <int structdim, int dim, int spacedim, bool level_dof_access>
2213template <bool level_dof_access2>
2216 : BaseClass(other)
2217 , dof_handler(const_cast<DoFHandler<dim, spacedim> *>(other.dof_handler))
2218{}
2219
2220
2221
2222template <int structdim, int dim, int spacedim, bool level_dof_access>
2223inline void
2226{
2227 Assert(dh != nullptr, ExcInvalidObject());
2228 this->dof_handler = dh;
2229}
2230
2231
2232
2233template <int structdim, int dim, int spacedim, bool level_dof_access>
2234inline const DoFHandler<dim, spacedim> &
2236{
2237 Assert(this->dof_handler != nullptr, ExcInvalidObject());
2238 return *this->dof_handler;
2239}
2240
2241
2242
2243template <int structdim, int dim, int spacedim, bool level_dof_access>
2244inline void
2247{
2248 Assert(this->dof_handler != nullptr, ExcInvalidObject());
2249 BaseClass::copy_from(da);
2250}
2251
2252
2253
2254template <int structdim, int dim, int spacedim, bool level_dof_access>
2255template <bool level_dof_access2>
2256inline void
2263
2264
2265
2266template <int structdim, int dim, int spacedim, bool level_dof_access>
2267template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
2268inline bool
2271{
2272 Assert(structdim == structdim2, ExcCantCompareIterators());
2273 Assert(this->dof_handler == a.dof_handler, ExcCantCompareIterators());
2274 return (BaseClass::operator==(a));
2275}
2276
2277
2278
2279template <int structdim, int dim, int spacedim, bool level_dof_access>
2280template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
2281inline bool
2284{
2285 Assert(structdim == structdim2, ExcCantCompareIterators());
2286 Assert(this->dof_handler == a.dof_handler, ExcCantCompareIterators());
2287 return (BaseClass::operator!=(a));
2288}
2289
2290
2291
2292template <int structdim, int dim, int spacedim, bool level_dof_access>
2295 const unsigned int i) const
2296{
2297 Assert(static_cast<unsigned int>(this->level()) <
2298 this->dof_handler->object_dof_indices.size(),
2299 ExcMessage("DoFHandler not initialized"));
2300
2303
2305 *t, this->dof_handler);
2306 return q;
2307}
2308
2309
2310namespace internal
2311{
2312 namespace DoFAccessorImplementation
2313 {
2318 template <int structdim, int dim, int spacedim, bool level_dof_access>
2322 const types::fe_index fe_index)
2323 {
2324 if (cell.get_dof_handler().has_hp_capabilities() == false)
2325 {
2326 // No hp enabled, and the argument is at its default value -> we
2327 // can translate to the default active fe index
2328 Assert(
2329 (fe_index == numbers::invalid_fe_index) ||
2331 ExcMessage(
2332 "It is not possible to specify a FE index if no hp support is used!"));
2333
2335 }
2336 else
2337 {
2338 // Otherwise: If anything other than the default is provided by
2339 // the caller, then we should take just that. As an exception, if
2340 // we are on a cell (rather than a face/edge/vertex), then we know
2341 // that there is only one active fe index on this cell and we can
2342 // use that:
2343 if ((dim == structdim) && (fe_index == numbers::invalid_fe_index))
2344 {
2346
2347 return cell.nth_active_fe_index(0);
2348 }
2349
2350 Assert((fe_index != numbers::invalid_fe_index),
2351 ExcMessage(
2352 "You need to specify a FE index if hp support is used!"));
2353
2354 return fe_index;
2355 }
2356 }
2357
2363 {
2373 boost::container::small_vector<::types::global_dof_index, 100>;
2374
2387 template <int dim, int spacedim, int structdim>
2390 const unsigned int obj_level,
2391 const unsigned int obj_index,
2392 const types::fe_index fe_index,
2393 const unsigned int local_index,
2394 const std::integral_constant<int, structdim> &dd)
2395 {
2396 const auto [first, n_dofs] =
2397 process_object_range(dof_handler, obj_level, obj_index, fe_index, dd);
2398 if (n_dofs == 0)
2399 return nullptr;
2400
2401 AssertIndexRange(local_index, n_dofs);
2402 return &dof_handler.object_dof_indices[obj_level][structdim]
2403 [first + local_index];
2404 }
2405
2415 template <int dim, int spacedim, int structdim>
2416 static std::pair<unsigned int, unsigned int>
2418 const unsigned int obj_level,
2419 const unsigned int obj_index,
2420 const types::fe_index fe_index,
2421 const std::integral_constant<int, structdim> &)
2422 {
2423 Assert(structdim == dim || obj_level == 0, ExcNotImplemented());
2424
2425 // determine range of dofs in global data structure
2426 // 1) cell
2427 if (structdim == dim)
2428 {
2429 const unsigned int ptr_0 =
2430 dof_handler.object_dof_ptr[obj_level][structdim][obj_index];
2431 const unsigned int length =
2432 dof_handler.get_fe(fe_index).template n_dofs_per_object<dim>(0);
2433
2434 return {ptr_0, length};
2435 }
2436
2437 // 2) hp is not used -> fe_index == 0
2438 if (dof_handler.hp_capability_enabled == false)
2439 {
2440 AssertDimension(fe_index,
2442
2443 const unsigned int ptr_0 =
2444 dof_handler.object_dof_ptr[obj_level][structdim][obj_index];
2445 const unsigned int length =
2446 dof_handler.object_dof_ptr[obj_level][structdim][obj_index + 1] -
2447 ptr_0;
2448
2449 return {ptr_0, length};
2450 }
2451
2452 // 3) hp is used
2453 AssertIndexRange(obj_level, dof_handler.object_dof_indices.size());
2454 AssertIndexRange(structdim,
2455 dof_handler.object_dof_indices[obj_level].size());
2456
2457 AssertIndexRange(structdim, dof_handler.hp_object_fe_ptr.size());
2458 AssertIndexRange(obj_index,
2459 dof_handler.hp_object_fe_ptr[structdim].size());
2460
2461 // Objects that are only adjacent to artificial cells have no finite
2462 // element and do not store any degrees of freedom.
2463 if (dof_handler.hp_object_fe_ptr[structdim][obj_index] ==
2464 dof_handler.hp_object_fe_ptr[structdim][obj_index + 1])
2465 return {0, 0};
2466
2467 const auto fe_index_local_ptr =
2468 std::find(dof_handler.hp_object_fe_indices[structdim].begin() +
2469 dof_handler.hp_object_fe_ptr[structdim][obj_index],
2470 dof_handler.hp_object_fe_indices[structdim].begin() +
2471 dof_handler.hp_object_fe_ptr[structdim][obj_index + 1],
2472 fe_index);
2473
2474 Assert(fe_index_local_ptr !=
2475 dof_handler.hp_object_fe_indices[structdim].begin() +
2476 dof_handler.hp_object_fe_ptr[structdim][obj_index + 1],
2477 ExcMessage(
2478 "You tried to call a function accessing DoF indices, but "
2479 "they appear not be available (yet) or inconsistent. "
2480 "Did you call distribute_dofs() first? Alternatively, if "
2481 "you are using different elements on different cells (i.e., "
2482 "you are using the hp capabilities of deal.II), did you "
2483 "change the active_fe_index of a cell since you last "
2484 "called distribute_dofs()?"));
2485
2486 const types::fe_index fe_index_local =
2487 std::distance(dof_handler.hp_object_fe_indices[structdim].begin() +
2488 dof_handler.hp_object_fe_ptr[structdim][obj_index],
2489 fe_index_local_ptr);
2490
2492 dof_handler.hp_object_fe_ptr[structdim][obj_index] + fe_index_local,
2493 dof_handler.object_dof_ptr[obj_level][structdim].size());
2494
2495 const unsigned int ptr_0 =
2496 dof_handler
2497 .object_dof_ptr[obj_level][structdim]
2498 [dof_handler.hp_object_fe_ptr[structdim][obj_index] +
2499 fe_index_local];
2500 const unsigned int ptr_1 =
2501 dof_handler
2502 .object_dof_ptr[obj_level][structdim]
2503 [dof_handler.hp_object_fe_ptr[structdim][obj_index] +
2504 fe_index_local + 1];
2505
2506 return {ptr_0, ptr_1 - ptr_0};
2507 }
2508
2509 template <int dim, int spacedim, int structdim, bool level_dof_access>
2510 static std::pair<unsigned int, unsigned int>
2512 const ::DoFAccessor<structdim, dim, spacedim, level_dof_access>
2513 accessor,
2514 const types::fe_index fe_index)
2515 {
2516 return process_object_range(accessor.get_dof_handler(),
2517 accessor.level(),
2518 accessor.index(),
2519 fe_index,
2520 std::integral_constant<int, structdim>());
2521 }
2522
2523 template <int dim, int spacedim, int structdim>
2524 static std::pair<unsigned int, unsigned int>
2526 const unsigned int)
2527 {
2529
2530 return {0, 0};
2531 }
2532
2533
2534
2543 template <int dim,
2544 int spacedim,
2545 int structdim,
2546 typename DoFProcessor,
2547 typename DoFMapping>
2548 static DEAL_II_ALWAYS_INLINE void
2550 const unsigned int obj_level,
2551 const unsigned int obj_index,
2552 const types::fe_index fe_index,
2553 const DoFMapping &mapping,
2554 const std::integral_constant<int, structdim> &dd,
2555 types::global_dof_index *&dof_indices_ptr,
2556 const DoFProcessor &process)
2557 {
2558 Assert(structdim == dim || obj_level == 0, ExcNotImplemented());
2559
2560 // determine range of dofs in global data structure
2561 const auto range =
2562 process_object_range(dof_handler, obj_level, obj_index, fe_index, dd);
2563 if (range.second == 0)
2564 return;
2565
2566 std::vector<types::global_dof_index> &object_dof_indices =
2567 dof_handler
2568 .object_dof_indices[structdim < dim ? 0 : obj_level][structdim];
2569 AssertIndexRange(range.first, object_dof_indices.size());
2571 object_dof_indices.data() + range.first;
2572
2573 // process dofs
2574 for (unsigned int i = 0; i < range.second; ++i)
2575 {
2576 process(
2577 stored_indices[(structdim == 0 || structdim == dim) ? i :
2578 mapping(i)],
2579 dof_indices_ptr);
2580 if (dof_indices_ptr != nullptr)
2581 ++dof_indices_ptr;
2582 }
2583 }
2584
2585
2586
2597 template <int dim, int spacedim, int structdim>
2598 static void
2600 const unsigned int obj_level,
2601 const unsigned int obj_index,
2602 const types::fe_index fe_index,
2603 const unsigned int local_index,
2604 const std::integral_constant<int, structdim> &dd,
2605 const types::global_dof_index global_index)
2606 {
2607 const auto dof_index = find_dof_index(
2608 dof_handler, obj_level, obj_index, fe_index, local_index, dd);
2609 Assert(dof_index != nullptr,
2610 ExcMessage("This object does not store degrees of freedom. "
2611 "It is only adjacent to artificial cells."));
2612 *dof_index = global_index;
2613 }
2614
2615
2626 template <int dim, int spacedim, int structdim>
2629 const unsigned int obj_level,
2630 const unsigned int obj_index,
2631 const types::fe_index fe_index,
2632 const unsigned int local_index,
2633 const std::integral_constant<int, structdim> &dd)
2634 {
2635 const auto dof_index = find_dof_index(
2636 dof_handler, obj_level, obj_index, fe_index, local_index, dd);
2637 return dof_index != nullptr ? *dof_index : numbers::invalid_dof_index;
2638 }
2639
2640
2641 template <int dim, int spacedim>
2644 const int level,
2645 const unsigned int vertex_index,
2646 const unsigned int i)
2647 {
2648 Assert(dof_handler.hp_capability_enabled == false,
2649 ExcMessage(
2650 "DoFHandler in hp-mode does not implement multilevel DoFs."));
2651
2652 return dof_handler.mg_vertex_dofs[vertex_index].access_index(
2653 level, i, dof_handler.get_fe().n_dofs_per_vertex());
2654 }
2655
2656
2657
2667 template <int dim, int spacedim, int structdim>
2668 static unsigned int
2670 const unsigned int obj_level,
2671 const unsigned int obj_index,
2672 const std::integral_constant<int, structdim> &)
2673 {
2674 (void)obj_level;
2675
2676 Assert(structdim == dim || obj_level == 0, ExcNotImplemented());
2677
2678 // 1) no hp used -> fe_index == 0
2679 if (dof_handler.hp_capability_enabled == false)
2680 return 1;
2681
2682 // 2) cell and hp is used -> there is only one fe_index
2683 if (structdim == dim)
2684 return 1;
2685
2686 // 3) general entity and hp is used
2687 AssertIndexRange(structdim, dof_handler.hp_object_fe_ptr.size());
2688 AssertIndexRange(obj_index + 1,
2689 dof_handler.hp_object_fe_ptr[structdim].size());
2690
2691 return dof_handler.hp_object_fe_ptr[structdim][obj_index + 1] -
2692 dof_handler.hp_object_fe_ptr[structdim][obj_index];
2693 }
2694
2695
2696
2706 template <int dim, int spacedim, int structdim>
2707 static types::fe_index
2709 const unsigned int obj_level,
2710 const unsigned int obj_index,
2711 const unsigned int local_index,
2712 const std::integral_constant<int, structdim> &)
2713 {
2714 Assert(structdim == dim || obj_level == 0, ExcNotImplemented());
2715
2716 // for cells only one active FE index available
2717 Assert(((structdim == dim) &&
2719 false,
2721
2722 // 1) no hp used -> fe_index == 0
2723 if (dof_handler.hp_capability_enabled == false)
2725
2726 // 2) cell and hp is used -> there is only one fe_index
2727 if (structdim == dim)
2728 return dof_handler.hp_cell_active_fe_indices[obj_level][obj_index];
2729
2730 // 3) general entity and hp is used
2731 AssertIndexRange(structdim, dof_handler.hp_object_fe_indices.size());
2732 AssertIndexRange(structdim, dof_handler.hp_object_fe_ptr.size());
2733 AssertIndexRange(obj_index,
2734 dof_handler.hp_object_fe_ptr[structdim].size());
2735 AssertIndexRange(dof_handler.hp_object_fe_ptr[structdim][obj_index] +
2736 local_index,
2737 dof_handler.hp_object_fe_indices[structdim].size());
2738
2739 return dof_handler.hp_object_fe_indices
2740 [structdim]
2741 [dof_handler.hp_object_fe_ptr[structdim][obj_index] + local_index];
2742 }
2743
2744
2745
2758 template <int dim, int spacedim, int structdim>
2759 static std::set<types::fe_index>
2761 const unsigned int obj_level,
2762 const unsigned int obj_index,
2763 const std::integral_constant<int, structdim> &t)
2764 {
2765 Assert(structdim == dim || obj_level == 0, ExcNotImplemented());
2766
2767 // 1) no hp used -> fe_index == 0
2768 if (dof_handler.hp_capability_enabled == false)
2770
2771 // 2) cell and hp is used -> there is only one fe_index
2772 if (structdim == dim)
2773 return {dof_handler.hp_cell_active_fe_indices[obj_level][obj_index]};
2774
2775 // 3) general entity and hp is used
2776 std::set<types::fe_index> active_fe_indices;
2777 for (unsigned int i = 0;
2778 i < n_active_fe_indices(dof_handler, obj_level, obj_index, t);
2779 ++i)
2780 active_fe_indices.insert(
2781 nth_active_fe_index(dof_handler, obj_level, obj_index, i, t));
2782 return active_fe_indices;
2783 }
2784
2785
2786
2787 template <int dim, int spacedim, int structdim>
2788 static bool
2790 const unsigned int obj_level,
2791 const unsigned int obj_index,
2792 const types::fe_index fe_index,
2793 const std::integral_constant<int, structdim> &)
2794 {
2795 Assert(structdim == dim || obj_level == 0, ExcNotImplemented());
2796
2797 // 1) no hp used -> fe_index == 0
2798 if (dof_handler.hp_capability_enabled == false)
2800
2801 // 2) cell and hp is used -> there is only one fe_index
2802 if (structdim == dim)
2803 return dof_handler.hp_cell_active_fe_indices[obj_level][obj_index] ==
2804 fe_index;
2805
2806 // 3) general entity and hp is used
2807 return std::find(
2808 dof_handler.hp_object_fe_indices[structdim].begin() +
2809 dof_handler.hp_object_fe_ptr[structdim][obj_index],
2810 dof_handler.hp_object_fe_indices[structdim].begin() +
2811 dof_handler.hp_object_fe_ptr[structdim][obj_index + 1],
2812 fe_index) !=
2813 (dof_handler.hp_object_fe_indices[structdim].begin() +
2814 dof_handler.hp_object_fe_ptr[structdim][obj_index + 1]);
2815 }
2816
2817
2818
2819 template <typename InputVector, typename ForwardIterator>
2820 static void
2821 extract_subvector_to(const InputVector &values,
2822 const types::global_dof_index *cache,
2823 const types::global_dof_index *cache_end,
2824 ForwardIterator local_values_begin)
2825 {
2826 values.extract_subvector_to(cache, cache_end, local_values_begin);
2827 }
2828
2829
2830
2831#ifdef DEAL_II_WITH_TRILINOS
2832 static std::vector<unsigned int>
2834 const types::global_dof_index *v_end)
2835 {
2836 // initialize original index locations
2837 std::vector<unsigned int> idx(v_end - v_begin);
2838 std::iota(idx.begin(), idx.end(), 0u);
2839
2840 // sort indices based on comparing values in v
2841 std::sort(idx.begin(),
2842 idx.end(),
2843 [&v_begin](unsigned int i1, unsigned int i2) {
2844 return *(v_begin + i1) < *(v_begin + i2);
2845 });
2846
2847 return idx;
2848 }
2849
2850
2851
2852# ifdef DEAL_II_TRILINOS_WITH_TPETRA
2853 template <typename ForwardIterator, typename Number, typename MemorySpace>
2854 static void
2857 &values,
2858 const types::global_dof_index *cache_begin,
2859 const types::global_dof_index *cache_end,
2860 ForwardIterator local_values_begin)
2861 {
2862 std::vector<unsigned int> sorted_indices_pos =
2863 sort_indices(cache_begin, cache_end);
2864 const unsigned int cache_size = cache_end - cache_begin;
2865 std::vector<types::global_dof_index> cache_indices(cache_size);
2866 for (unsigned int i = 0; i < cache_size; ++i)
2867 cache_indices[i] = *(cache_begin + sorted_indices_pos[i]);
2868
2869 IndexSet index_set(cache_indices.back() + 1);
2870 index_set.add_indices(cache_indices.begin(), cache_indices.end());
2871 index_set.compress();
2872 LinearAlgebra::ReadWriteVector<Number> read_write_vector(index_set);
2873 read_write_vector.import_elements(values, VectorOperation::insert);
2874
2875 // Copy the elements from read_write_vector and reorder them.
2876 for (unsigned int i = 0; i < cache_size; ++i, ++local_values_begin)
2877 *local_values_begin = read_write_vector[sorted_indices_pos[i]];
2878 }
2879# endif
2880
2881
2882# ifdef DEAL_II_TRILINOS_WITH_EPETRA
2883 template <typename ForwardIterator>
2884 static void
2886 const types::global_dof_index *cache_begin,
2887 const types::global_dof_index *cache_end,
2888 ForwardIterator local_values_begin)
2889 {
2890 std::vector<unsigned int> sorted_indices_pos =
2891 sort_indices(cache_begin, cache_end);
2892 const unsigned int cache_size = cache_end - cache_begin;
2893 std::vector<types::global_dof_index> cache_indices(cache_size);
2894 for (unsigned int i = 0; i < cache_size; ++i)
2895 cache_indices[i] = *(cache_begin + sorted_indices_pos[i]);
2896
2897 IndexSet index_set(cache_indices.back() + 1);
2898 index_set.add_indices(cache_indices.begin(), cache_indices.end());
2899 index_set.compress();
2900 LinearAlgebra::ReadWriteVector<double> read_write_vector(index_set);
2901 read_write_vector.import_elements(values, VectorOperation::insert);
2902
2903 // Copy the elements from read_write_vector and reorder them.
2904 for (unsigned int i = 0; i < cache_size; ++i, ++local_values_begin)
2905 *local_values_begin = read_write_vector[sorted_indices_pos[i]];
2906 }
2907# endif
2908#endif
2909
2914 template <int dim, int spacedim, bool level_dof_access, int structdim>
2915 static unsigned int
2917 const ::DoFAccessor<structdim, dim, spacedim, level_dof_access>
2918 &accessor,
2919 const types::fe_index fe_index_,
2920 const bool count_level_dofs)
2921 {
2922 // note: we cannot rely on the template parameter level_dof_access here,
2923 // since the function get_mg_dof_indices()/set_mg_dof_indices() can be
2924 // called even if level_dof_access==false.
2925 if (count_level_dofs)
2926 {
2927 const auto &fe = accessor.get_fe(fe_index_);
2928
2929 const unsigned int //
2930 dofs_per_vertex = fe.n_dofs_per_vertex(), //
2931 dofs_per_line = fe.n_dofs_per_line(), //
2932 dofs_per_quad = fe.n_dofs_per_quad(0 /*dummy*/), //
2933 dofs_per_hex = fe.n_dofs_per_hex(); //
2934
2935 unsigned int index = 0;
2936
2937 // 1) VERTEX dofs
2938 index += dofs_per_vertex * accessor.n_vertices();
2939
2940 // 2) LINE dofs
2941 if (structdim == 2 || structdim == 3)
2942 index += dofs_per_line * accessor.n_lines();
2943
2944 // 3) FACE dofs
2945 if (structdim == 3)
2946 index += dofs_per_quad * accessor.n_faces();
2947
2948 // 4) INNER dofs
2949 const unsigned int interior_dofs =
2950 structdim == 1 ? dofs_per_line :
2951 (structdim == 2 ? dofs_per_quad : dofs_per_hex);
2952
2953 index += interior_dofs;
2954
2955 return index;
2956 }
2957 else
2958 {
2959 const auto fe_index =
2961 accessor, fe_index_);
2962
2963 unsigned int index = 0;
2964
2965 // 1) VERTEX dofs
2966 for (const auto vertex : accessor.vertex_indices())
2967 index += process_object_range(accessor.get_dof_handler(),
2968 0,
2969 accessor.vertex_index(vertex),
2970 fe_index,
2971 std::integral_constant<int, 0>())
2972 .second;
2973
2974 // 2) LINE dofs
2975 if constexpr (structdim == 2 || structdim == 3)
2976 {
2977 const auto line_indices = TriaAccessorImplementation::
2978 Implementation::get_line_indices_of_cell(accessor);
2979 for (const auto line_no : accessor.line_indices())
2980 {
2982 &accessor.get_triangulation(),
2983 0,
2984 line_indices[line_no],
2985 &accessor.get_dof_handler());
2986 index += process_object_range(line, fe_index).second;
2987 }
2988 }
2989
2990 // 3) FACE dofs
2991 if (structdim == 3)
2992 for (const auto face : accessor.face_indices())
2993 index +=
2994 process_object_range(*accessor.quad(face), fe_index).second;
2995
2996 // 4) INNER dofs
2997 index += process_object_range(accessor, fe_index).second;
2998
2999 return index;
3000 }
3001 }
3002
3003
3004
3005 // The next few internal helper functions are needed to support various
3006 // DoFIndicesType kinds, e.g. actual vectors of DoFIndices or empty
3007 // types that we use when we only want to work on the internally stored
3008 // DoFs and never extract any number.
3009 template <typename ArrayType>
3010 static unsigned int
3011 get_array_length(const ArrayType &array)
3012 {
3013 return array.size();
3014 }
3015
3016 static unsigned int
3017 get_array_length(const std::tuple<> &)
3018 {
3019 return 0;
3020 }
3021
3022 template <typename ArrayType>
3024 get_array_ptr(const ArrayType &array)
3025 {
3026 return const_cast<types::global_dof_index *>(array.data());
3027 }
3028
3030 get_array_ptr(const std::tuple<> &)
3031 {
3032 return nullptr;
3033 }
3034
3035
3036
3042 template <int dim,
3043 int spacedim,
3044 bool level_dof_access,
3045 int structdim,
3046 typename DoFIndicesType,
3047 typename DoFOperation,
3048 typename DoFProcessor>
3049 static void
3051 const ::DoFAccessor<structdim, dim, spacedim, level_dof_access>
3052 &accessor,
3053 const DoFIndicesType &const_dof_indices,
3054 const types::fe_index fe_index_,
3055 const DoFOperation &dof_operation,
3056 const DoFProcessor &dof_processor,
3057 const bool count_level_dofs)
3058 {
3059 const types::fe_index fe_index =
3061 accessor, fe_index_);
3062
3063 // we cannot rely on the template parameter level_dof_access here, since
3064 // the function get_mg_dof_indices()/set_mg_dof_indices() can be called
3065 // even if level_dof_access==false.
3066 (void)count_level_dofs;
3067
3068 const auto &fe = accessor.get_fe(fe_index);
3069
3070 // we want to pass in rvalue 'std::tuple<>' types as `DoFIndicesType`,
3071 // but we need non-const references for std::vector<> types, so get in
3072 // a const reference here and immediately cast the constness away -
3073 // note that any use of the dereferenced invalid type will result in a
3074 // segfault
3075 types::global_dof_index *dof_indices_ptr =
3076 get_array_ptr(const_dof_indices);
3077 types::global_dof_index *end_dof_indices =
3078 dof_indices_ptr + get_array_length(const_dof_indices);
3079
3080 // 1) VERTEX dofs, only step into the functions if we actually have
3081 // DoFs on them
3082 if (fe.n_dofs_per_vertex() > 0)
3083 for (const auto vertex : accessor.vertex_indices())
3084 dof_operation.process_vertex_dofs(*accessor.dof_handler,
3085 accessor.vertex_index(vertex),
3086 fe_index,
3087 dof_indices_ptr,
3088 dof_processor);
3089
3090 // 2) copy dof numbers from the LINE, accounting for the possibility of
3091 // reversed line orientations.
3092 if (structdim > 1 && fe.n_dofs_per_line() > 0)
3093 {
3094 const auto [line_indices, line_orientations] =
3095 internal::TriaAccessorImplementation::Implementation::
3096 get_line_indices_and_orientations_of_cell(accessor);
3097
3098 for (const auto line : accessor.line_indices())
3099 {
3100 const auto line_orientation = line_orientations[line];
3101 if (line_orientation == numbers::default_geometric_orientation)
3102 dof_operation.process_dofs(
3103 accessor.get_dof_handler(),
3104 0,
3105 line_indices[line],
3106 fe_index,
3107 [](const auto d) { return d; },
3108 std::integral_constant<int, 1>(),
3109 dof_indices_ptr,
3110 dof_processor);
3111 else
3112 {
3113 Assert(line_orientation ==
3116 dof_operation.process_dofs(
3117 accessor.get_dof_handler(),
3118 0,
3119 line_indices[line],
3120 fe_index,
3121 [&fe](const auto d) {
3122 return fe.adjust_line_dof_index_for_line_orientation(
3123 d, numbers::reverse_line_orientation);
3124 },
3125 std::integral_constant<int, 1>(),
3126 dof_indices_ptr,
3127 dof_processor);
3128 }
3129 }
3130 }
3131
3132 // 3) copy dof numbers from the QUAD (i.e., 3d faces). Like lines we
3133 // only adjust dof indices (which has some cost) if we are not in the
3134 // default orientation.
3135 if (structdim == 3 && fe.max_dofs_per_quad() > 0)
3136 for (const auto face_no : accessor.face_indices())
3137 {
3138 const auto combined_orientation =
3139 accessor.combined_face_orientation(face_no);
3140 const unsigned int quad_index = accessor.quad_index(face_no);
3141 if (combined_orientation ==
3143 dof_operation.process_dofs(
3144 accessor.get_dof_handler(),
3145 0,
3146 quad_index,
3147 fe_index,
3148 [](const auto d) { return d; },
3149 std::integral_constant<int, 2>(),
3150 dof_indices_ptr,
3151 dof_processor);
3152 else
3153 dof_operation.process_dofs(
3154 accessor.get_dof_handler(),
3155 0,
3156 quad_index,
3157 fe_index,
3158 [&](const auto d) {
3159 return fe.adjust_quad_dof_index_for_face_orientation(
3160 d, face_no, combined_orientation);
3161 },
3162 std::integral_constant<int, 2>(),
3163 dof_indices_ptr,
3164 dof_processor);
3165 }
3166
3167 // 4) INNER dofs (i.e., line dofs in 1d, quad dofs in 2d, or hex dofs in
3168 // 3d) - here we need to make sure that the shortcut to not run the
3169 // function does not miss the faces of wedge and pyramid elements where
3170 // n_dofs_per_object might not return the largest possible value
3171 if (((dim == 3 && structdim == 2) ?
3172 fe.max_dofs_per_quad() :
3173 fe.template n_dofs_per_object<structdim>()) > 0)
3174 dof_operation.process_dofs(
3175 accessor.get_dof_handler(),
3176 accessor.level(),
3177 accessor.index(),
3178 fe_index,
3179 [&](const auto d) { return d; },
3180 std::integral_constant<int, structdim>(),
3181 dof_indices_ptr,
3182 dof_processor);
3183
3184 if (dof_indices_ptr != nullptr)
3185 {
3186 AssertDimension(n_dof_indices(accessor, fe_index, count_level_dofs),
3187 dof_indices_ptr - get_array_ptr(const_dof_indices));
3188 }
3189
3190 // Objects that are only adjacent to artificial cells do not store any
3191 // degrees of freedom and are skipped above. If any of them was
3192 // skipped, report all degrees of freedom of this object as invalid.
3193 // DoFTools::set_periodicity_constraints() relies on this to detect
3194 // faces of artificial cells.
3195 if (dof_indices_ptr != end_dof_indices)
3196 dof_indices_ptr = get_array_ptr(const_dof_indices);
3198 for (; dof_indices_ptr < end_dof_indices; ++dof_indices_ptr)
3199 dof_processor(invalid_index, dof_indices_ptr);
3200 }
3201
3202
3203
3208 template <int dim, int spacedim>
3210 {
3214 template <typename DoFProcessor>
3217 const unsigned int vertex_index,
3218 const types::fe_index fe_index,
3219 types::global_dof_index *&dof_indices_ptr,
3220 const DoFProcessor &dof_processor) const
3221 {
3223 dof_handler,
3224 0,
3225 vertex_index,
3226 fe_index,
3227 [](const auto d) {
3229 return d;
3230 },
3231 std::integral_constant<int, 0>(),
3232 dof_indices_ptr,
3233 dof_processor);
3234 }
3235
3239 template <int structdim, typename DoFMapping, typename DoFProcessor>
3242 const unsigned int obj_level,
3243 const unsigned int obj_index,
3244 const types::fe_index fe_index,
3245 const DoFMapping &mapping,
3246 const std::integral_constant<int, structdim>,
3247 types::global_dof_index *&dof_indices_ptr,
3248 const DoFProcessor &dof_processor) const
3249 {
3251 dof_handler,
3252 obj_level,
3253 obj_index,
3254 fe_index,
3255 mapping,
3256 std::integral_constant<int, std::min(structdim, dim)>(),
3257 dof_indices_ptr,
3258 dof_processor);
3259 }
3260 };
3261
3262
3263
3268 template <int dim, int spacedim>
3270 {
3274 MGDoFIndexProcessor(const unsigned int level)
3275 : level(level)
3276 {}
3277
3281 template <typename DoFProcessor>
3284 const unsigned int vertex_index,
3285 const types::fe_index,
3286 types::global_dof_index *&dof_indices_ptr,
3287 const DoFProcessor &dof_processor) const
3288 {
3289 const unsigned int n_indices =
3290 dof_handler.get_fe(0).template n_dofs_per_object<0>();
3291 types::global_dof_index *stored_indices =
3292 &dof_handler.mg_vertex_dofs[vertex_index].access_index(level,
3293 0,
3294 n_indices);
3295 for (unsigned int d = 0; d < n_indices; ++d, ++dof_indices_ptr)
3296 dof_processor(stored_indices[d], dof_indices_ptr);
3297 }
3298
3302 template <int structdim, typename DoFMapping, typename DoFProcessor>
3305 const unsigned int,
3306 const unsigned int obj_index,
3307 const types::fe_index fe_index,
3308 const DoFMapping &mapping,
3309 const std::integral_constant<int, structdim>,
3310 types::global_dof_index *&dof_indices_ptr,
3311 const DoFProcessor &dof_processor) const
3312 {
3313 const unsigned int n_indices =
3314 dof_handler.get_fe(0).template n_dofs_per_object<structdim>();
3315 types::global_dof_index *stored_indices = &get_mg_dof_index(
3316 dof_handler,
3317 dof_handler.mg_levels[level],
3318 dof_handler.mg_faces,
3319 obj_index,
3320 fe_index,
3321 0,
3322 std::integral_constant<int, std::min(structdim, dim)>());
3323 for (unsigned int d = 0; d < n_indices; ++d, ++dof_indices_ptr)
3324 dof_processor(stored_indices[structdim < dim ? mapping(d) : d],
3325 dof_indices_ptr);
3326 }
3327
3328 private:
3329 const unsigned int level;
3330 };
3331
3332
3333
3334 template <int dim, int spacedim, bool level_dof_access, int structdim>
3335 static void
3337 const ::DoFAccessor<structdim, dim, spacedim, level_dof_access>
3338 &accessor,
3339 std::vector<types::global_dof_index> &dof_indices,
3340 const types::fe_index fe_index)
3341 {
3343 accessor,
3344 dof_indices,
3345 fe_index,
3347 [](auto stored_index, auto dof_ptr) { *dof_ptr = stored_index; },
3348 false);
3349 }
3350
3351
3352
3353 template <int dim, int spacedim, bool level_dof_access, int structdim>
3354 static void
3356 const ::DoFAccessor<structdim, dim, spacedim, level_dof_access>
3357 &accessor,
3358 const std::vector<types::global_dof_index> &dof_indices,
3359 const types::fe_index fe_index)
3360 {
3361 // Note: this function is as general as `get_dof_indices()`. This
3362 // assert is placed here since it is currently only used by the
3363 // function DoFCellAccessor::set_dof_indices(), which is called by
3364 // internal::DoFHandlerImplementation::Policy::Implementation::distribute_dofs().
3365 // In the case of new use cases, this assert can be removed.
3366 Assert(
3367 dim == structdim,
3368 ExcMessage(
3369 "This function is intended to be used for DoFCellAccessor, i.e., "
3370 "dimension == structdim."));
3371
3373 accessor,
3374 dof_indices,
3375 fe_index,
3377 [](auto &stored_index, auto dof_ptr) { stored_index = *dof_ptr; },
3378 false);
3379 }
3380
3381
3382
3383 template <int dim, int spacedim, bool level_dof_access, int structdim>
3384 static void
3386 const ::DoFAccessor<structdim, dim, spacedim, level_dof_access>
3387 &accessor,
3388 const int level,
3389 std::vector<types::global_dof_index> &dof_indices,
3390 const types::fe_index fe_index)
3391 {
3393 ExcMessage("MG DoF indices cannot be queried in hp case"));
3395 accessor,
3396 dof_indices,
3397 fe_index,
3399 [](auto stored_index, auto dof_ptr) { *dof_ptr = stored_index; },
3400 true);
3401 }
3402
3403
3404
3405 template <int dim, int spacedim, bool level_dof_access, int structdim>
3406 static void
3408 const ::DoFAccessor<structdim, dim, spacedim, level_dof_access>
3409 &accessor,
3410 const int level,
3411 const std::vector<types::global_dof_index> &dof_indices,
3412 const types::fe_index fe_index)
3413 {
3415 ExcMessage("MG DoF indices cannot be queried in hp case"));
3416
3417 // Note: this function is as general as `get_mg_dof_indices()`. This
3418 // assert is placed here since it is currently only used by the
3419 // function DoFCellAccessor::set_mg_dof_indices(), which is called by
3420 // internal::DoFHandlerImplementation::Policy::Implementation::distribute_mg_dofs().
3421 // In the case of new use cases, this assert can be removed.
3422 Assert(dim == structdim,
3423 ExcMessage("This function is intended to be used for "
3424 "DoFCellAccessor, i.e., dimension == structdim."));
3425
3427 accessor,
3428 dof_indices,
3429 fe_index,
3431 [](auto &stored_index, auto dof_ptr) { stored_index = *dof_ptr; },
3432 true);
3433 }
3434
3435
3436
3437 template <int dim, int spacedim>
3440 const DoFHandler<dim, spacedim> &dof_handler,
3442 &mg_level,
3444 &,
3445 const unsigned int obj_index,
3446 const types::fe_index fe_index,
3447 const unsigned int local_index,
3448 const std::integral_constant<int, dim>)
3449 {
3450 Assert(dof_handler.hp_capability_enabled == false,
3452
3453 return mg_level->dof_object.access_dof_index(
3454 static_cast<const DoFHandler<dim, spacedim> &>(dof_handler),
3455 obj_index,
3456 fe_index,
3457 local_index);
3458 }
3459
3460
3461
3462 template <int dim, int spacedim, std::enable_if_t<(dim > 1), int> = 0>
3465 const DoFHandler<dim, spacedim> &dof_handler,
3467 &,
3469 &mg_faces,
3470 const unsigned int obj_index,
3471 const types::fe_index fe_index,
3472 const unsigned int local_index,
3473 const std::integral_constant<int, 1>)
3474 {
3475 return mg_faces->lines.access_dof_index(
3476 static_cast<const DoFHandler<dim, spacedim> &>(dof_handler),
3477 obj_index,
3478 fe_index,
3479 local_index);
3480 }
3481
3482
3483
3484 template <int spacedim>
3487 const DoFHandler<3, spacedim> &dof_handler,
3489 &,
3491 &mg_faces,
3492 const unsigned int obj_index,
3493 const types::fe_index fe_index,
3494 const unsigned int local_index,
3495 const std::integral_constant<int, 2>)
3496 {
3497 Assert(dof_handler.hp_capability_enabled == false,
3499 return mg_faces->quads.access_dof_index(
3500 static_cast<const DoFHandler<3, spacedim> &>(dof_handler),
3501 obj_index,
3502 fe_index,
3503 local_index);
3504 }
3505 };
3506
3507
3508
3509 template <int dim, int spacedim, bool level_dof_access>
3510 void
3512 const ::DoFCellAccessor<dim, spacedim, level_dof_access> &accessor,
3514 const unsigned int fe_index);
3515 } // namespace DoFAccessorImplementation
3516} // namespace internal
3517
3518
3519
3520template <int structdim, int dim, int spacedim, bool level_dof_access>
3523 const unsigned int i,
3524 const types::fe_index fe_index_) const
3525{
3526 const auto fe_index =
3528 fe_index_);
3529
3530 // access the respective DoF
3531 return ::internal::DoFAccessorImplementation::Implementation::
3532 get_dof_index(*this->dof_handler,
3533 this->level(),
3534 this->index(),
3535 fe_index,
3536 i,
3537 std::integral_constant<int, structdim>());
3538}
3539
3540
3541template <int structdim, int dim, int spacedim, bool level_dof_access>
3544 const int level,
3545 const unsigned int i) const
3546{
3548 *this->dof_handler,
3549 this->dof_handler->mg_levels[level],
3550 this->dof_handler->mg_faces,
3551 this->index(),
3552 0,
3553 i,
3554 std::integral_constant<int, structdim>());
3555}
3556
3557
3558template <int structdim, int dim, int spacedim, bool level_dof_access>
3559inline void
3561 const unsigned int i,
3562 const types::global_dof_index index,
3563 const types::fe_index fe_index_) const
3564{
3565 const auto fe_index =
3567 fe_index_);
3568
3569 // access the respective DoF
3571 *this->dof_handler,
3572 this->level(),
3573 this->index(),
3574 fe_index,
3575 i,
3576 std::integral_constant<int, structdim>(),
3577 index);
3578}
3579
3580
3581
3582template <int structdim, int dim, int spacedim, bool level_dof_access>
3583inline void
3585 const int level,
3586 const unsigned int i,
3587 const types::global_dof_index index) const
3588{
3590 *this->dof_handler,
3591 this->dof_handler->mg_levels[level],
3592 this->dof_handler->mg_faces,
3593 this->index(),
3594 0,
3595 i,
3596 std::integral_constant<int, structdim>()) = index;
3597}
3598
3599
3600
3601template <int structdim, int dim, int spacedim, bool level_dof_access>
3602inline unsigned int
3604 const
3605{
3606 // access the respective DoF
3607 return ::internal::DoFAccessorImplementation::Implementation::
3608 n_active_fe_indices(*this->dof_handler,
3609 this->level(),
3610 this->index(),
3611 std::integral_constant<int, structdim>());
3612}
3613
3614
3615
3616template <int structdim, int dim, int spacedim, bool level_dof_access>
3617inline types::fe_index
3619 const unsigned int n) const
3620{
3621 // access the respective DoF
3622 return ::internal::DoFAccessorImplementation::Implementation::
3623 nth_active_fe_index(*this->dof_handler,
3624 this->level(),
3625 this->index(),
3626 n,
3627 std::integral_constant<int, structdim>());
3628}
3629
3630
3631
3632template <int structdim, int dim, int spacedim, bool level_dof_access>
3633inline std::set<types::fe_index>
3635 const
3636{
3637 std::set<types::fe_index> active_fe_indices;
3638 for (unsigned int i = 0; i < n_active_fe_indices(); ++i)
3639 active_fe_indices.insert(nth_active_fe_index(i));
3640 return active_fe_indices;
3641}
3642
3643
3644
3645template <int structdim, int dim, int spacedim, bool level_dof_access>
3646inline bool
3648 const types::fe_index fe_index) const
3649{
3650 // access the respective DoF
3651 return ::internal::DoFAccessorImplementation::Implementation::
3652 fe_index_is_active(*this->dof_handler,
3653 this->level(),
3654 this->index(),
3655 fe_index,
3656 std::integral_constant<int, structdim>());
3657}
3658
3659
3660
3661template <int structdim, int dim, int spacedim, bool level_dof_access>
3664 const unsigned int vertex,
3665 const unsigned int i,
3666 const types::fe_index fe_index_) const
3667{
3668 const types::fe_index fe_index =
3669 (((this->dof_handler->hp_capability_enabled == false) &&
3670 (fe_index_ == numbers::invalid_fe_index)) ?
3671 // No hp enabled, and the argument is at its default value -> we
3672 // can translate to the default active fe index
3674 // Otherwise: If anything other than the default is provided by
3675 // the caller, then we should take just that. As an exception, if
3676 // we are on a cell (rather than a face/edge/vertex), then we know
3677 // that there is only one active fe index on this cell and we can
3678 // use that:
3679 ((dim == structdim) && (fe_index_ == numbers::invalid_fe_index) ?
3680 this->nth_active_fe_index(0) :
3681 fe_index_));
3682
3683 return ::internal::DoFAccessorImplementation::Implementation::
3684 get_dof_index(*this->dof_handler,
3685 0,
3686 this->vertex_index(vertex),
3687 fe_index,
3688 i,
3689 std::integral_constant<int, 0>());
3690}
3691
3692
3693template <int structdim, int dim, int spacedim, bool level_dof_access>
3696 const int level,
3697 const unsigned int vertex,
3698 const unsigned int i,
3699 const types::fe_index fe_index_) const
3700{
3701 const auto fe_index =
3703 fe_index_);
3704 (void)fe_index;
3705 Assert(this->dof_handler != nullptr, ExcInvalidObject());
3706 Assert(this->dof_handler->mg_vertex_dofs.size() > 0,
3707 ExcMessage("Multigrid DoF indices can only be accessed after "
3708 "DoFHandler::distribute_mg_dofs() has been called!"));
3709 AssertIndexRange(vertex, this->n_vertices());
3710 AssertIndexRange(i, this->dof_handler->get_fe(fe_index).n_dofs_per_vertex());
3711
3712 Assert(dof_handler->hp_capability_enabled == false,
3713 ExcMessage(
3714 "DoFHandler in hp-mode does not implement multilevel DoFs."));
3715
3716 return this->dof_handler->mg_vertex_dofs[this->vertex_index(vertex)]
3717 .access_index(level, i, this->dof_handler->get_fe().n_dofs_per_vertex());
3718}
3719
3720
3721
3722template <int structdim, int dim, int spacedim, bool level_dof_access>
3723inline void
3726 const unsigned int vertex,
3727 const unsigned int i,
3728 const types::global_dof_index index,
3729 const types::fe_index fe_index_) const
3730{
3731 const auto fe_index =
3733 fe_index_);
3734 (void)fe_index;
3735 Assert(this->dof_handler != nullptr, ExcInvalidObject());
3736 AssertIndexRange(vertex, this->n_vertices());
3737 AssertIndexRange(i, this->dof_handler->get_fe(fe_index).n_dofs_per_vertex());
3738
3739 Assert(dof_handler->hp_capability_enabled == false,
3740 ExcMessage(
3741 "DoFHandler in hp-mode does not implement multilevel DoFs."));
3742
3743 this->dof_handler->mg_vertex_dofs[this->vertex_index(vertex)].access_index(
3744 level, i, this->dof_handler->get_fe().n_dofs_per_vertex()) = index;
3745}
3746
3747
3748
3749template <int structdim, int dim, int spacedim, bool level_dof_access>
3750inline const FiniteElement<dim, spacedim> &
3752 const types::fe_index fe_index) const
3753{
3754 Assert(fe_index_is_active(fe_index) == true,
3755 ExcMessage("This function can only be called for active FE indices"));
3756
3757 return this->dof_handler->get_fe(fe_index);
3758}
3759
3760
3761
3762template <int structdim, int dim, int spacedim, bool level_dof_access>
3763inline typename ::internal::DoFHandlerImplementation::
3764 Iterators<dim, spacedim, level_dof_access>::line_iterator
3766 const unsigned int i) const
3767{
3768 // if we are asking for a particular line and this object refers to
3769 // a line, then the only valid index is i==0 and we should return
3770 // *this
3771 if (structdim == 1)
3772 {
3773 Assert(i == 0,
3774 ExcMessage("You can only ask for line zero if the "
3775 "current object is a line itself."));
3776 return typename ::internal::DoFHandlerImplementation::
3777 Iterators<dim, spacedim, level_dof_access>::cell_iterator(
3778 &this->get_triangulation(),
3779 this->level(),
3780 this->index(),
3781 &this->get_dof_handler());
3782 }
3783
3784 // otherwise we need to be in structdim>=2
3785 Assert(structdim > 1, ExcImpossibleInDim(structdim));
3786 Assert(dim > 1, ExcImpossibleInDim(dim));
3787
3788 // checking of 'i' happens in line_index(i)
3789 return typename ::internal::DoFHandlerImplementation::
3790 Iterators<dim, spacedim, level_dof_access>::line_iterator(
3791 this->tria,
3792 0, // only sub-objects are allowed, which have no level
3793 this->line_index(i),
3794 this->dof_handler);
3795}
3796
3797
3798template <int structdim, int dim, int spacedim, bool level_dof_access>
3799inline typename ::internal::DoFHandlerImplementation::
3800 Iterators<dim, spacedim, level_dof_access>::quad_iterator
3802 const unsigned int i) const
3803{
3804 // if we are asking for a
3805 // particular quad and this object
3806 // refers to a quad, then the only
3807 // valid index is i==0 and we
3808 // should return *this
3809 if (structdim == 2)
3810 {
3811 Assert(i == 0,
3812 ExcMessage("You can only ask for quad zero if the "
3813 "current object is a quad itself."));
3814 return typename ::internal::DoFHandlerImplementation::
3815 Iterators<dim, spacedim>::cell_iterator(&this->get_triangulation(),
3816 this->level(),
3817 this->index(),
3818 &this->get_dof_handler());
3819 }
3820
3821 // otherwise we need to be in structdim>=3
3822 Assert(structdim > 2, ExcImpossibleInDim(structdim));
3823 Assert(dim > 2, ExcImpossibleInDim(dim));
3824
3825 // checking of 'i' happens in quad_index(i)
3826 return typename ::internal::DoFHandlerImplementation::
3827 Iterators<dim, spacedim, level_dof_access>::quad_iterator(
3828 this->tria,
3829 0, // only sub-objects are allowed, which have no level
3830 this->quad_index(i),
3831 this->dof_handler);
3832}
3833
3834
3835/*----------------- Functions: DoFAccessor<0,1,spacedim> --------------------*/
3836
3837
3838template <int spacedim, bool level_dof_access>
3840{
3841 Assert(false, ExcInvalidObject());
3842}
3843
3844
3845
3846template <int spacedim, bool level_dof_access>
3848 const Triangulation<1, spacedim> *tria,
3849 const typename TriaAccessor<0, 1, spacedim>::VertexKind vertex_kind,
3850 const unsigned int vertex_index,
3851 const DoFHandler<1, spacedim> *dof_handler)
3852 : BaseClass(tria, vertex_kind, vertex_index)
3853 , dof_handler(const_cast<DoFHandler<1, spacedim> *>(dof_handler))
3854{}
3855
3856
3857
3858template <int spacedim, bool level_dof_access>
3860 const Triangulation<1, spacedim> *tria,
3861 const int level,
3862 const int index,
3863 const DoFHandler<1, spacedim> *dof_handler)
3864 // This is the constructor signature for "ordinary" (non-vertex)
3865 // accessors and we shouldn't be calling it altogether. But it is also
3866 // the constructor that the default-constructor of TriaRawIterator
3867 // calls when default-constructing an iterator object. If so, this
3868 // happens with level==-2 and index==-2, and this is the only case we
3869 // would like to support. We do this by just forwarding to the
3870 // other constructor of this class, and then asserting the condition
3871 // on level and index.
3872 : DoFAccessor<0, 1, spacedim, level_dof_access>(
3873 tria,
3874 TriaAccessor<0, 1, spacedim>::interior_vertex,
3875 0U,
3876 dof_handler)
3877{
3878 (void)level;
3879 (void)index;
3880 Assert((tria == nullptr) && (level == -2) && (index == -2) &&
3881 (dof_handler == nullptr),
3882 ExcMessage(
3883 "This constructor can not be called for face iterators in 1d, "
3884 "except to default-construct iterator objects."));
3885}
3886
3887
3888
3889template <int spacedim, bool level_dof_access>
3890template <int structdim2, int dim2, int spacedim2>
3896
3897
3898
3899template <int spacedim, bool level_dof_access>
3900template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
3906
3907
3908
3909template <int spacedim, bool level_dof_access>
3910inline void
3913{
3914 Assert(dh != nullptr, ExcInvalidObject());
3915 this->dof_handler = dh;
3916}
3917
3918
3919
3920template <int spacedim, bool level_dof_access>
3921inline void
3923 const unsigned int /*i*/,
3924 const types::global_dof_index /*index*/,
3925 const types::fe_index /*fe_index*/) const
3926{
3928}
3929
3930
3931
3932template <int spacedim, bool level_dof_access>
3933inline const DoFHandler<1, spacedim> &
3935{
3936 return *this->dof_handler;
3937}
3938
3939
3940
3941template <int spacedim, bool level_dof_access>
3942inline void
3944 std::vector<types::global_dof_index> &dof_indices,
3945 const types::fe_index fe_index_) const
3946{
3947 const auto fe_index =
3949 fe_index_);
3950
3951 for (unsigned int i = 0; i < dof_indices.size(); ++i)
3952 dof_indices[i] = ::internal::DoFAccessorImplementation::
3953 Implementation::get_dof_index(*dof_handler,
3954 0,
3955 this->global_vertex_index,
3956 fe_index,
3957 i,
3958 std::integral_constant<int, 0>());
3959}
3960
3961
3962
3963template <int spacedim, bool level_dof_access>
3964inline void
3966 const int level,
3967 std::vector<types::global_dof_index> &dof_indices,
3968 const types::fe_index fe_index_) const
3969{
3970 const auto fe_index =
3972 fe_index_);
3973 (void)fe_index;
3975
3976 for (unsigned int i = 0; i < dof_indices.size(); ++i)
3977 dof_indices[i] =
3979 mg_vertex_dof_index(*dof_handler, level, this->global_vertex_index, i);
3980}
3981
3982
3983
3984template <int spacedim, bool level_dof_access>
3987 const unsigned int vertex,
3988 const unsigned int i,
3989 const types::fe_index fe_index_) const
3990{
3991 const auto fe_index =
3993 fe_index_);
3994
3995 (void)vertex;
3996 AssertIndexRange(vertex, 1);
3997 return ::internal::DoFAccessorImplementation::Implementation::
3998 get_dof_index(*dof_handler,
3999 0,
4000 this->global_vertex_index,
4001 fe_index,
4002 i,
4003 std::integral_constant<int, 0>());
4004}
4005
4006
4007
4008template <int spacedim, bool level_dof_access>
4011 const unsigned int i,
4012 const types::fe_index fe_index_) const
4013{
4014 const auto fe_index =
4016 fe_index_);
4017
4018 return ::internal::DoFAccessorImplementation::Implementation::
4019 get_dof_index(*this->dof_handler,
4020 0,
4021 this->vertex_index(0),
4022 fe_index,
4023 i,
4024 std::integral_constant<int, 0>());
4025}
4026
4027
4028
4029template <int spacedim, bool level_dof_access>
4030inline unsigned int
4035
4036
4037
4038template <int spacedim, bool level_dof_access>
4039inline types::fe_index
4041 const unsigned int /*n*/) const
4042{
4043 return 0;
4044}
4045
4046
4047
4048template <int spacedim, bool level_dof_access>
4049inline bool
4051 const types::fe_index /*fe_index*/) const
4052{
4054 return false;
4055}
4056
4057
4058
4059template <int spacedim, bool level_dof_access>
4060inline const FiniteElement<1, spacedim> &
4062 const types::fe_index fe_index) const
4063{
4064 Assert(this->dof_handler != nullptr, ExcInvalidObject());
4065 return dof_handler->get_fe(fe_index);
4066}
4067
4068
4069
4070template <int spacedim, bool level_dof_access>
4071inline void
4074{
4075 Assert(this->dof_handler != nullptr, ExcInvalidObject());
4076 BaseClass::copy_from(da);
4077}
4078
4079
4080
4081template <int spacedim, bool level_dof_access>
4082template <bool level_dof_access2>
4083inline void
4086{
4087 BaseClass::copy_from(a);
4088 set_dof_handler(a.dof_handler);
4089}
4090
4091
4092
4093template <int spacedim, bool level_dof_access>
4100
4101
4102
4103template <int spacedim, bool level_dof_access>
4104inline typename ::internal::DoFHandlerImplementation::
4105 Iterators<1, spacedim, level_dof_access>::line_iterator
4107 const unsigned int /*c*/) const
4108{
4110 return typename ::internal::DoFHandlerImplementation::
4111 Iterators<1, spacedim, level_dof_access>::line_iterator();
4112}
4113
4114
4115
4116template <int spacedim, bool level_dof_access>
4117inline typename ::internal::DoFHandlerImplementation::
4118 Iterators<1, spacedim, level_dof_access>::quad_iterator
4120 const unsigned int /*c*/) const
4121{
4123 return typename ::internal::DoFHandlerImplementation::
4124 Iterators<1, spacedim, level_dof_access>::quad_iterator();
4125}
4126
4127
4128
4129template <int spacedim, bool level_dof_access>
4130template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
4131inline bool
4134{
4135 Assert(structdim2 == 0, ExcCantCompareIterators());
4136 Assert(this->dof_handler == a.dof_handler, ExcCantCompareIterators());
4137 return (BaseClass::operator==(a));
4138}
4139
4140
4141
4142template <int spacedim, bool level_dof_access>
4143template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
4144inline bool
4147{
4148 Assert(structdim2 == 0, ExcCantCompareIterators());
4149 Assert(this->dof_handler == a.dof_handler, ExcCantCompareIterators());
4150 return (BaseClass::operator!=(a));
4151}
4152
4153
4154
4155/*------------------------- Functions: DoFCellAccessor -----------------------*/
4156
4157
4158namespace internal
4159{
4160 namespace DoFCellAccessorImplementation
4161 {
4167 {
4172 template <int dim, int spacedim, bool level_dof_access>
4173 static types::fe_index
4176 {
4177 if (accessor.dof_handler->hp_capability_enabled == false)
4179
4180 Assert(accessor.dof_handler != nullptr,
4181 (typename std::decay_t<decltype(accessor)>::ExcInvalidObject()));
4182 Assert(static_cast<unsigned int>(accessor.level()) <
4183 accessor.dof_handler->hp_cell_future_fe_indices.size(),
4184 ExcMessage("DoFHandler not initialized"));
4185
4186 return accessor.dof_handler
4187 ->hp_cell_active_fe_indices[accessor.level()][accessor.present_index];
4188 }
4189
4190
4191
4196 template <int dim, int spacedim, bool level_dof_access>
4197 static void
4200 const types::fe_index i)
4201 {
4202 if (accessor.dof_handler->hp_capability_enabled == false)
4203 {
4205 return;
4206 }
4207
4208 Assert(accessor.dof_handler != nullptr,
4209 (typename std::decay_t<decltype(accessor)>::ExcInvalidObject()));
4210 Assert(static_cast<unsigned int>(accessor.level()) <
4211 accessor.dof_handler->hp_cell_future_fe_indices.size(),
4212 ExcMessage("DoFHandler not initialized"));
4214 ExcMessage("Invalid finite element index."));
4215
4216 accessor.dof_handler
4217 ->hp_cell_active_fe_indices[accessor.level()]
4218 [accessor.present_index] = i;
4219 }
4220
4221
4222
4227 template <int dim, int spacedim, bool level_dof_access>
4228 static types::fe_index
4231 {
4232 if (accessor.dof_handler->hp_capability_enabled == false)
4234
4235 Assert(accessor.dof_handler != nullptr,
4236 (typename std::decay_t<decltype(accessor)>::ExcInvalidObject()));
4237 Assert(static_cast<unsigned int>(accessor.level()) <
4238 accessor.dof_handler->hp_cell_future_fe_indices.size(),
4239 ExcMessage("DoFHandler not initialized"));
4240
4241 if (future_fe_index_set(accessor))
4242 return accessor.dof_handler
4243 ->hp_cell_future_fe_indices[accessor.level()]
4244 [accessor.present_index];
4245 else
4246 return accessor.dof_handler
4247 ->hp_cell_active_fe_indices[accessor.level()]
4248 [accessor.present_index];
4249 }
4250
4251
4256 template <int dim, int spacedim, bool level_dof_access>
4257 static void
4260 const types::fe_index i)
4261 {
4262 if (accessor.dof_handler->hp_capability_enabled == false)
4263 {
4265 return;
4266 }
4267
4268 Assert(accessor.dof_handler != nullptr,
4269 (typename std::decay_t<decltype(accessor)>::ExcInvalidObject()));
4270 Assert(static_cast<unsigned int>(accessor.level()) <
4271 accessor.dof_handler->hp_cell_future_fe_indices.size(),
4272 ExcMessage("DoFHandler not initialized"));
4274 ExcMessage("Invalid finite element index."));
4275
4276 accessor.dof_handler
4277 ->hp_cell_future_fe_indices[accessor.level()]
4278 [accessor.present_index] = i;
4279 }
4280
4281
4282
4287 template <int dim, int spacedim, bool level_dof_access>
4288 static bool
4291 {
4292 if (accessor.dof_handler->hp_capability_enabled == false)
4293 return false;
4294
4295 Assert(accessor.dof_handler != nullptr,
4296 (typename std::decay_t<decltype(accessor)>::ExcInvalidObject()));
4297 Assert(static_cast<unsigned int>(accessor.level()) <
4298 accessor.dof_handler->hp_cell_future_fe_indices.size(),
4299 ExcMessage("DoFHandler not initialized"));
4300
4301 return accessor.dof_handler
4302 ->hp_cell_future_fe_indices[accessor.level()]
4303 [accessor.present_index] !=
4305 }
4306
4307
4308
4313 template <int dim, int spacedim, bool level_dof_access>
4314 static void
4317 {
4318 if (accessor.dof_handler->hp_capability_enabled == false)
4319 return;
4320
4321 Assert(accessor.dof_handler != nullptr,
4322 (typename std::decay_t<decltype(accessor)>::ExcInvalidObject()));
4323 Assert(static_cast<unsigned int>(accessor.level()) <
4324 accessor.dof_handler->hp_cell_future_fe_indices.size(),
4325 ExcMessage("DoFHandler not initialized"));
4326
4327 accessor.dof_handler
4328 ->hp_cell_future_fe_indices[accessor.level()]
4329 [accessor.present_index] =
4331 }
4332 };
4333 } // namespace DoFCellAccessorImplementation
4334} // namespace internal
4335
4336
4337
4338template <int dimension_, int space_dimension_, bool level_dof_access>
4341 const int level,
4342 const int index,
4343 const AccessorData *local_data)
4344 : DoFAccessor<dimension_, dimension_, space_dimension_, level_dof_access>(
4345 tria,
4346 level,
4347 index,
4348 local_data)
4349{}
4350
4351
4352
4353template <int dimension_, int space_dimension_, bool level_dof_access>
4354template <int structdim2, int dim2, int spacedim2>
4360
4361
4362
4363template <int dimension_, int space_dimension_, bool level_dof_access>
4364template <int structdim2, int dim2, int spacedim2, bool level_dof_access2>
4370
4371
4372
4373template <int dimension_, int space_dimension_, bool level_dof_access>
4374inline TriaIterator<
4377 const unsigned int i) const
4378{
4380 q(this->tria,
4381 this->neighbor_level(i),
4382 this->neighbor_index(i),
4383 this->dof_handler);
4384
4385 if constexpr (running_in_debug_mode())
4386 {
4388 Assert(q->used(), ExcInternalError());
4389 }
4390 return q;
4391}
4392
4393
4394
4395template <int dimension_, int space_dimension_, bool level_dof_access>
4396inline TriaIterator<
4399 const unsigned int i) const
4400{
4402 q(this->tria, this->level() + 1, this->child_index(i), this->dof_handler);
4403
4404 if constexpr (running_in_debug_mode())
4405 {
4407 Assert(q->used(), ExcInternalError());
4408 }
4409 return q;
4410}
4411
4412
4413
4414template <int dimension_, int space_dimension_, bool level_dof_access>
4415inline boost::container::small_vector<
4419 child_iterators() const
4420{
4421 boost::container::small_vector<
4425 child_iterators(this->n_children());
4426
4427 for (unsigned int i = 0; i < this->n_children(); ++i)
4428 child_iterators[i] = this->child(i);
4429
4430 return child_iterators;
4431}
4432
4433
4434
4435template <int dimension_, int space_dimension_, bool level_dof_access>
4436inline TriaIterator<
4439{
4441 q(this->tria, this->level() - 1, this->parent_index(), this->dof_handler);
4442
4443 return q;
4444}
4445
4446
4447
4448namespace internal
4449{
4450 namespace DoFCellAccessorImplementation
4451 {
4452 template <int dim, int spacedim, bool level_dof_access>
4453 inline TriaIterator<
4454 ::DoFAccessor<dim - 1, dim, spacedim, level_dof_access>>
4456 const ::DoFCellAccessor<dim, spacedim, level_dof_access> &cell,
4457 const unsigned int i,
4458 const std::integral_constant<int, 1>)
4459 {
4461 &cell.get_triangulation(),
4462 ((i == 0) && cell.at_boundary(0) ?
4464 ((i == 1) && cell.at_boundary(1) ?
4467 cell.vertex_index(i),
4468 &cell.get_dof_handler());
4469 return ::TriaIterator<
4471 }
4472
4473
4474 template <int dim, int spacedim, bool level_dof_access>
4475 inline TriaIterator<
4476 ::DoFAccessor<dim - 1, dim, spacedim, level_dof_access>>
4478 const ::DoFCellAccessor<dim, spacedim, level_dof_access> &cell,
4479 const unsigned int i,
4480 const std::integral_constant<int, 2>)
4481 {
4482 return cell.line(i);
4483 }
4484
4485
4486 template <int dim, int spacedim, bool level_dof_access>
4487 inline TriaIterator<
4488 ::DoFAccessor<dim - 1, dim, spacedim, level_dof_access>>
4490 const ::DoFCellAccessor<dim, spacedim, level_dof_access> &cell,
4491 const unsigned int i,
4492 const std::integral_constant<int, 3>)
4493 {
4494 return cell.quad(i);
4495 }
4496 } // namespace DoFCellAccessorImplementation
4497} // namespace internal
4498
4499
4500
4501template <int dimension_, int space_dimension_, bool level_dof_access>
4502inline typename DoFCellAccessor<dimension_,
4503 space_dimension_,
4504 level_dof_access>::face_iterator
4506 const unsigned int i) const
4507{
4508 AssertIndexRange(i, this->n_faces());
4509
4510 return ::internal::DoFCellAccessorImplementation::get_face(
4511 *this, i, std::integral_constant<int, dimension_>());
4512}
4513
4514
4515
4516template <int dimension_, int space_dimension_, bool level_dof_access>
4517inline boost::container::small_vector<
4519 face_iterator,
4522 face_iterators() const
4523{
4524 boost::container::small_vector<
4526 face_iterator,
4528 face_iterators(this->n_faces());
4529
4530 for (const unsigned int i : this->face_indices())
4531 face_iterators[i] =
4533 *this, i, std::integral_constant<int, dimension_>());
4534
4535 return face_iterators;
4536}
4537
4538
4539
4540template <int dimension_, int space_dimension_, bool level_dof_access>
4541inline void
4544 std::vector<types::global_dof_index> &dof_indices) const
4545{
4546 if (level_dof_access)
4547 get_mg_dof_indices(dof_indices);
4548 else
4549 get_dof_indices(dof_indices);
4550}
4551
4552
4553
4554template <int dimension_, int space_dimension_, bool level_dof_access>
4555template <class InputVector, typename number>
4556inline void
4558 const InputVector &values,
4559 Vector<number> &local_values) const
4560{
4561 get_dof_values(values, local_values.begin(), local_values.end());
4562}
4563
4564
4565
4566template <int dimension_, int space_dimension_, bool level_dof_access>
4567template <typename Number, typename ForwardIterator>
4568inline void
4570 const ReadVector<Number> &values,
4571 ForwardIterator local_values_begin,
4572 ForwardIterator local_values_end) const
4573{
4574 (void)local_values_end;
4575 Assert(this->is_artificial() == false,
4576 ExcMessage("Can't ask for DoF indices on artificial cells."));
4577 Assert(this->is_active(), ExcMessage("Cell must be active."));
4578 Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());
4579
4580 Assert(static_cast<unsigned int>(local_values_end - local_values_begin) ==
4581 this->get_fe().n_dofs_per_cell(),
4583 Assert(values.size() == this->get_dof_handler().n_dofs(),
4585
4587 dof_indices(this->get_fe().n_dofs_per_cell());
4589 *this, dof_indices, this->active_fe_index());
4590
4591 boost::container::small_vector<Number, 100> values_temp(local_values_end -
4592 local_values_begin);
4593 auto view = make_array_view(values_temp.begin(), values_temp.end());
4594 values.extract_subvector_to(make_array_view(dof_indices.begin(),
4595 dof_indices.end()),
4596 view);
4597 using view_type = std::remove_reference_t<decltype(*local_values_begin)>;
4598 ArrayView<view_type> values_view2(&*local_values_begin,
4599 local_values_end - local_values_begin);
4600 std::copy(values_temp.begin(), values_temp.end(), values_view2.begin());
4601}
4602
4603
4604
4605template <int dimension_, int space_dimension_, bool level_dof_access>
4606template <class InputVector, typename ForwardIterator>
4607inline void
4610 const InputVector &values,
4611 ForwardIterator local_values_begin,
4612 ForwardIterator local_values_end) const
4613{
4614 Assert(this->is_artificial() == false,
4615 ExcMessage("Can't ask for DoF indices on artificial cells."));
4616 Assert(this->is_active(), ExcMessage("Cell must be active."));
4617
4618 Assert(static_cast<unsigned int>(local_values_end - local_values_begin) ==
4619 this->get_fe().n_dofs_per_cell(),
4621 Assert(values.size() == this->get_dof_handler().n_dofs(),
4623
4624
4626 dof_indices(this->get_fe().n_dofs_per_cell());
4628 *this, dof_indices, this->active_fe_index());
4629
4630 constraints.get_dof_values(values,
4631 dof_indices.data(),
4632 local_values_begin,
4633 local_values_end);
4634}
4635
4636
4637
4638template <int dimension_, int space_dimension_, bool level_dof_access>
4639template <class OutputVector, typename number>
4640inline void
4642 const Vector<number> &local_values,
4643 OutputVector &values) const
4644{
4645 Assert(this->is_artificial() == false,
4646 ExcMessage("Can't ask for DoF indices on artificial cells."));
4647 Assert(this->is_active(), ExcMessage("Cell must be active."));
4648
4649 Assert(static_cast<unsigned int>(local_values.size()) ==
4650 this->get_fe().n_dofs_per_cell(),
4652 Assert(values.size() == this->get_dof_handler().n_dofs(),
4654
4655
4656 Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());
4658 dof_indices(this->get_fe().n_dofs_per_cell());
4660 *this, dof_indices, this->active_fe_index());
4661
4662 for (unsigned int i = 0; i < this->get_fe().n_dofs_per_cell(); ++i)
4664 dof_indices[i],
4665 values);
4666}
4667
4668
4669
4670template <int dimension_, int space_dimension_, bool level_dof_access>
4673{
4674 Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());
4675 Assert((this->dof_handler->hp_capability_enabled == false) ||
4676 this->is_active(),
4677 ExcMessage(
4678 "For DoFHandler objects in hp-mode, finite elements are only "
4679 "associated with active cells. Consequently, you can not ask "
4680 "for the active finite element on cells with children."));
4681
4682 const auto &fe = this->dof_handler->get_fe(active_fe_index());
4683
4684 Assert(this->reference_cell() == fe.reference_cell(),
4685 ExcMessage(
4686 "The reference-cell type used on this cell (" +
4687 this->reference_cell().to_string() +
4688 ") does not match the reference-cell type of the finite element "
4689 "associated with this cell (" +
4690 fe.reference_cell().to_string() +
4691 "). "
4692 "Did you accidentally use simplex elements on hypercube meshes "
4693 "(or the other way around), or are you using a mixed mesh and "
4694 "assigned a simplex element to a hypercube cell (or the other "
4695 "way around) via the active_fe_index?"));
4696
4697 return fe;
4698}
4699
4700
4701
4702template <int dimension_, int space_dimension_, bool level_dof_access>
4703inline types::fe_index
4705 active_fe_index() const
4706{
4707 Assert((this->dof_handler->hp_capability_enabled == false) ||
4708 this->is_active(),
4709 ExcMessage(
4710 "You can not ask for the active FE index on a cell that has "
4711 "children because no degrees of freedom are assigned "
4712 "to this cell and, consequently, no finite element "
4713 "is associated with it."));
4714 Assert((this->dof_handler->hp_capability_enabled == false) ||
4715 (this->is_locally_owned() || this->is_ghost()),
4716 ExcMessage("You can only query active FE index information on cells "
4717 "that are either locally owned or (after distributing "
4718 "degrees of freedom) are ghost cells."));
4719
4720 return ::internal::DoFCellAccessorImplementation::Implementation::
4721 active_fe_index(*this);
4722}
4723
4724
4725
4726template <int dimension_, int space_dimension_, bool level_dof_access>
4727inline void
4730{
4731 Assert((this->dof_handler->hp_capability_enabled == false) ||
4732 this->is_active(),
4733 ExcMessage("You can not set the active FE index on a cell that has "
4734 "children because no degrees of freedom will be assigned "
4735 "to this cell."));
4736
4737 Assert((this->dof_handler->hp_capability_enabled == false) ||
4738 this->is_locally_owned(),
4739 ExcMessage("You can only set active FE index information on cells "
4740 "that are locally owned. On ghost cells, this information "
4741 "will automatically be propagated from the owning process "
4742 "of that cell, and there is no information at all on "
4743 "artificial cells."));
4744
4746 set_active_fe_index(*this, i);
4747}
4748
4749
4750
4751template <int dimension_, int space_dimension_, bool level_dof_access>
4754 const
4755{
4756 Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());
4757 Assert((this->dof_handler->hp_capability_enabled == false) ||
4758 this->is_active(),
4759 ExcMessage(
4760 "For DoFHandler objects in hp-mode, finite elements are only "
4761 "associated with active cells. Consequently, you can not ask "
4762 "for the future finite element on cells with children."));
4763
4764 return this->dof_handler->get_fe(future_fe_index());
4765}
4766
4767
4768
4769template <int dimension_, int space_dimension_, bool level_dof_access>
4770inline types::fe_index
4772 future_fe_index() const
4773{
4774 Assert((this->dof_handler->hp_capability_enabled == false) ||
4775 (this->has_children() == false),
4776 ExcMessage(
4777 "You can not ask for the future FE index on a cell that has "
4778 "children because no degrees of freedom are assigned "
4779 "to this cell and, consequently, no finite element "
4780 "is associated with it."));
4781 Assert((this->dof_handler->hp_capability_enabled == false) ||
4782 (this->is_locally_owned()),
4783 ExcMessage("You can only query future FE index information on cells "
4784 "that are locally owned."));
4785
4786 return ::internal::DoFCellAccessorImplementation::Implementation::
4787 future_fe_index(*this);
4788}
4789
4790
4791
4792template <int dimension_, int space_dimension_, bool level_dof_access>
4793inline void
4796{
4797 Assert((this->dof_handler->hp_capability_enabled == false) ||
4798 (this->has_children() == false),
4799 ExcMessage("You can not set the future FE index on a cell that has "
4800 "children because no degrees of freedom will be assigned "
4801 "to this cell."));
4802
4803 Assert((this->dof_handler->hp_capability_enabled == false) ||
4804 this->is_locally_owned(),
4805 ExcMessage("You can only set future FE index information on cells "
4806 "that are locally owned."));
4807
4809 set_future_fe_index(*this, i);
4810}
4811
4812
4813
4814template <int dimension_, int space_dimension_, bool level_dof_access>
4815inline bool
4818{
4819 Assert((this->dof_handler->hp_capability_enabled == false) ||
4820 (this->has_children() == false),
4821 ExcMessage(
4822 "You can not ask for the future FE index on a cell that has "
4823 "children because no degrees of freedom are assigned "
4824 "to this cell and, consequently, no finite element "
4825 "is associated with it."));
4826 Assert((this->dof_handler->hp_capability_enabled == false) ||
4827 (this->is_locally_owned()),
4828 ExcMessage("You can only query future FE index information on cells "
4829 "that are locally owned."));
4830
4831 return ::internal::DoFCellAccessorImplementation::Implementation::
4832 future_fe_index_set(*this);
4833}
4834
4835
4836
4837template <int dimension_, int space_dimension_, bool level_dof_access>
4838inline void
4841{
4842 Assert((this->dof_handler->hp_capability_enabled == false) ||
4843 (this->has_children() == false),
4844 ExcMessage(
4845 "You can not ask for the future FE index on a cell that has "
4846 "children because no degrees of freedom are assigned "
4847 "to this cell and, consequently, no finite element "
4848 "is associated with it."));
4849 Assert((this->dof_handler->hp_capability_enabled == false) ||
4850 (this->is_locally_owned()),
4851 ExcMessage("You can only query future FE index information on cells "
4852 "that are locally owned."));
4853
4856}
4857
4858
4859
4860template <int dimension_, int space_dimension_, bool level_dof_access>
4861template <typename number, typename OutputVector>
4862inline void
4865 OutputVector &global_destination) const
4866{
4867 this->distribute_local_to_global(local_source.begin(),
4868 local_source.end(),
4869 global_destination);
4870}
4871
4872
4873
4874template <int dimension_, int space_dimension_, bool level_dof_access>
4875template <typename ForwardIterator, typename OutputVector>
4876inline void
4878 distribute_local_to_global(ForwardIterator local_source_begin,
4879 ForwardIterator local_source_end,
4880 OutputVector &global_destination) const
4881{
4882 Assert(this->dof_handler != nullptr,
4883 (typename std::decay_t<decltype(*this)>::ExcInvalidObject()));
4884 Assert(static_cast<unsigned int>(local_source_end - local_source_begin) ==
4885 this->get_fe().n_dofs_per_cell(),
4886 (typename std::decay_t<decltype(*this)>::ExcVectorDoesNotMatch()));
4887 Assert(this->dof_handler->n_dofs() == global_destination.size(),
4888 (typename std::decay_t<decltype(*this)>::ExcVectorDoesNotMatch()));
4889
4890 Assert(!this->has_children(), ExcMessage("Cell must be active"));
4891
4892 Assert(
4893 internal::ArrayViewHelper::is_contiguous(local_source_begin,
4894 local_source_end),
4895 ExcMessage(
4896 "This function can not be called with iterator types that do not point to contiguous memory."));
4897
4898 const unsigned int n_dofs = local_source_end - local_source_begin;
4899
4901 dof_indices(n_dofs);
4903 *this, dof_indices, this->active_fe_index());
4904
4905 // distribute cell vector
4906 global_destination.add(n_dofs, dof_indices.data(), &(*local_source_begin));
4907}
4908
4909
4910
4911template <int dimension_, int space_dimension_, bool level_dof_access>
4912template <typename ForwardIterator, typename OutputVector>
4913inline void
4917 ForwardIterator local_source_begin,
4918 ForwardIterator local_source_end,
4919 OutputVector &global_destination) const
4920{
4921 Assert(this->dof_handler != nullptr,
4922 (typename std::decay_t<decltype(*this)>::ExcInvalidObject()));
4923 Assert(local_source_end - local_source_begin ==
4924 this->get_fe().n_dofs_per_cell(),
4925 (typename std::decay_t<decltype(*this)>::ExcVectorDoesNotMatch()));
4926 Assert(this->dof_handler->n_dofs() == global_destination.size(),
4927 (typename std::decay_t<decltype(*this)>::ExcVectorDoesNotMatch()));
4928
4929 Assert(!this->has_children(), ExcMessage("Cell must be active."));
4930
4932 dof_indices(this->get_fe().n_dofs_per_cell());
4934 *this, dof_indices, this->active_fe_index());
4935
4936 // distribute cell vector
4937 constraints.distribute_local_to_global(local_source_begin,
4938 local_source_end,
4939 dof_indices.data(),
4940 global_destination);
4941}
4942
4943
4944
4945template <int dimension_, int space_dimension_, bool level_dof_access>
4946template <typename number, typename OutputMatrix>
4947inline void
4950 OutputMatrix &global_destination) const
4951{
4952 Assert(this->dof_handler != nullptr,
4953 (typename std::decay_t<decltype(*this)>::ExcInvalidObject()));
4954 Assert(local_source.m() == this->get_fe().n_dofs_per_cell(),
4955 (typename std::decay_t<decltype(*this)>::ExcMatrixDoesNotMatch()));
4956 Assert(local_source.n() == this->get_fe().n_dofs_per_cell(),
4957 (typename std::decay_t<decltype(*this)>::ExcMatrixDoesNotMatch()));
4958 Assert(this->dof_handler->n_dofs() == global_destination.m(),
4959 (typename std::decay_t<decltype(*this)>::ExcMatrixDoesNotMatch()));
4960 Assert(this->dof_handler->n_dofs() == global_destination.n(),
4961 (typename std::decay_t<decltype(*this)>::ExcMatrixDoesNotMatch()));
4962
4963 Assert(!this->has_children(), ExcMessage("Cell must be active."));
4964
4965 const unsigned int n_dofs = local_source.m();
4966
4968 dof_indices(n_dofs);
4970 *this, dof_indices, this->active_fe_index());
4971
4972 // distribute cell matrix
4973 for (unsigned int i = 0; i < n_dofs; ++i)
4974 global_destination.add(dof_indices[i],
4975 n_dofs,
4976 dof_indices.data(),
4977 &local_source(i, 0));
4978}
4979
4980
4981
4982template <int dimension_, int space_dimension_, bool level_dof_access>
4983template <typename number, typename OutputMatrix, typename OutputVector>
4984inline void
4987 const Vector<number> &local_vector,
4988 OutputMatrix &global_matrix,
4989 OutputVector &global_vector) const
4990{
4991 Assert(this->dof_handler != nullptr,
4992 (typename std::decay_t<decltype(*this)>::ExcInvalidObject()));
4993 Assert(local_matrix.m() == this->get_fe().n_dofs_per_cell(),
4994 (typename std::decay_t<decltype(*this)>::ExcMatrixDoesNotMatch()));
4995 Assert(local_matrix.n() == this->get_fe().n_dofs_per_cell(),
4996 (typename std::decay_t<decltype(*this)>::ExcVectorDoesNotMatch()));
4997 Assert(this->dof_handler->n_dofs() == global_matrix.m(),
4998 (typename std::decay_t<decltype(*this)>::ExcMatrixDoesNotMatch()));
4999 Assert(this->dof_handler->n_dofs() == global_matrix.n(),
5000 (typename std::decay_t<decltype(*this)>::ExcMatrixDoesNotMatch()));
5001 Assert(local_vector.size() == this->get_fe().n_dofs_per_cell(),
5002 (typename std::decay_t<decltype(*this)>::ExcVectorDoesNotMatch()));
5003 Assert(this->dof_handler->n_dofs() == global_vector.size(),
5004 (typename std::decay_t<decltype(*this)>::ExcVectorDoesNotMatch()));
5005
5006 Assert(!this->has_children(), ExcMessage("Cell must be active."));
5007
5008 const unsigned int n_dofs = this->get_fe().n_dofs_per_cell();
5010 dof_indices(n_dofs);
5012 *this, dof_indices, this->active_fe_index());
5013
5014 // distribute cell matrices
5015 for (unsigned int i = 0; i < n_dofs; ++i)
5016 {
5017 global_matrix.add(dof_indices[i],
5018 n_dofs,
5019 dof_indices.data(),
5020 &local_matrix(i, 0));
5021 global_vector(dof_indices[i]) += local_vector(i);
5022 }
5023}
5024
5025
5026
5028
5029
5030#endif
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
void get_dof_values(const VectorType &global_vector, ForwardIteratorInd local_indices_begin, ForwardIteratorVec local_vector_begin, ForwardIteratorVec local_vector_end) const
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
iterator begin() const
Definition array_view.h:755
DoFAccessor< 0, 1, spacedim, level_dof_access > & operator=(const DoFAccessor< 0, 1, spacedim, level_dof_access > &da)=delete
DoFAccessor< 0, 1, spacedim, level_dof_access > & operator=(DoFAccessor< 0, 1, spacedim, level_dof_access > &&) noexcept=default
DoFAccessor(DoFAccessor< 0, 1, spacedim, level_dof_access > &&)=default
DoFAccessor(const DoFAccessor< 0, 1, spacedim, level_dof_access > &)=default
typename::internal::DoFHandlerImplementation::Iterators< dim, spacedim, level_dof_access >::line_iterator line(const unsigned int i) const
friend struct ::internal::DoFHandlerImplementation::Policy::Implementation
static constexpr unsigned int space_dimension
const DoFHandler< dim, spacedim > & get_dof_handler() const
void set_mg_dof_index(const int level, const unsigned int i, const types::global_dof_index index) const
friend class DoFAccessor
DoFAccessor< structdim, dim, spacedim, level_dof_access > & operator=(const DoFAccessor< structdim, dim, spacedim, level_dof_access > &da)=delete
types::fe_index nth_active_fe_index(const unsigned int n) const
DoFAccessor(DoFAccessor< structdim, dim, spacedim, level_dof_access > &&)
DoFAccessor(const DoFAccessor< structdim, dim, spacedim, level_dof_access2 > &)
TriaIterator< DoFAccessor< structdim, dim, spacedim, level_dof_access > > child(const unsigned int c) const
void set_mg_vertex_dof_index(const int level, const unsigned int vertex, const unsigned int i, const types::global_dof_index index, const types::fe_index fe_index=numbers::invalid_fe_index) const
~DoFAccessor()=default
static constexpr unsigned int dimension
void set_dof_handler(DoFHandler< dim, spacedim > *dh)
DoFAccessor(const DoFAccessor< structdim2, dim2, spacedim2, level_dof_access2 > &)
DoFAccessor< structdim, dim, spacedim, level_dof_access > & operator=(DoFAccessor< structdim, dim, spacedim, level_dof_access > &&)
std::set< types::fe_index > get_active_fe_indices() const
DoFAccessor(const DoFAccessor< structdim, dim, spacedim, level_dof_access > &)=default
void set_mg_dof_indices(const int level, const std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index=numbers::invalid_fe_index)
void get_mg_dof_indices(const int level, std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index=numbers::invalid_fe_index) const
types::global_dof_index mg_vertex_dof_index(const int level, const unsigned int vertex, const unsigned int i, const types::fe_index fe_index=numbers::invalid_fe_index) const
DoFAccessor(const Triangulation< dim, spacedim > *tria, const int level, const int index, const DoFHandler< dim, spacedim > *dof_handler)
bool operator!=(const DoFAccessor< structdim2, dim2, spacedim2, level_dof_access2 > &) const
void copy_from(const TriaAccessorBase< structdim, dim, spacedim > &da)
types::global_dof_index dof_index(const unsigned int i, const types::fe_index fe_index=numbers::invalid_fe_index) const
typename::internal::DoFHandlerImplementation::Iterators< dim, spacedim, level_dof_access >::quad_iterator quad(const unsigned int i) const
void copy_from(const DoFAccessor< structdim, dim, spacedim, level_dof_access2 > &a)
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index fe_index) const
void get_dof_indices(std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index=numbers::invalid_fe_index) const
bool operator==(const DoFAccessor< structdim2, dim2, spacedim2, level_dof_access2 > &) const
types::global_dof_index mg_dof_index(const int level, const unsigned int i) const
void set_dof_index(const unsigned int i, const types::global_dof_index index, const types::fe_index fe_index=numbers::invalid_fe_index) const
unsigned int n_active_fe_indices() const
static bool is_level_cell()
typename ::internal::DoFAccessorImplementation::Inheritance< structdim, dimension, space_dimension >::BaseClass BaseClass
types::global_dof_index vertex_dof_index(const unsigned int vertex, const unsigned int i, const types::fe_index fe_index=numbers::invalid_fe_index) const
DoFHandler< dim, spacedim > * dof_handler
DoFAccessor(const InvalidAccessor< structdim2, dim2, spacedim2 > &)
bool fe_index_is_active(const types::fe_index fe_index) const
boost::container::small_vector< TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > >, GeometryInfo< dimension_ >::max_children_per_cell > child_iterators() const
DoFCellAccessor(DoFCellAccessor< dimension_, space_dimension_, level_dof_access > &&)=default
void get_active_or_mg_dof_indices(std::vector< types::global_dof_index > &dof_indices) const
void get_dof_values(const InputVector &values, Vector< number > &local_values) const
boost::container::small_vector< face_iterator, GeometryInfo< dimension_ >::faces_per_cell > face_iterators() const
types::fe_index future_fe_index() const
DoFCellAccessor< dimension_, space_dimension_, level_dof_access > & operator=(const DoFCellAccessor< dimension_, space_dimension_, level_dof_access > &da)=delete
const FiniteElement< dimension_, space_dimension_ > & get_fe() const
TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > > child(const unsigned int i) const
DoFCellAccessor(const Triangulation< dimension_, space_dimension_ > *tria, const int level, const int index, const AccessorData *local_data)
void set_future_fe_index(const types::fe_index i) const
void distribute_local_to_global(const Vector< number > &local_source, OutputVector &global_destination) const
const FiniteElement< dimension_, space_dimension_ > & get_future_fe() const
TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > > neighbor(const unsigned int i) const
void set_active_fe_index(const types::fe_index i) const
face_iterator face(const unsigned int i) const
void clear_future_fe_index() const
void set_dof_values(const Vector< number > &local_values, OutputVector &values) const
DoFCellAccessor(const DoFCellAccessor< dimension_, space_dimension_, level_dof_access > &)=default
~DoFCellAccessor()=default
bool future_fe_index_set() const
DoFCellAccessor< dimension_, space_dimension_, level_dof_access > & operator=(DoFCellAccessor< dimension_, space_dimension_, level_dof_access > &&)=default
types::fe_index active_fe_index() const
TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > > parent() const
std::vector< std::unique_ptr<::internal::DoFHandlerImplementation::DoFLevel< dim > > > mg_levels
std::vector< std::vector< types::fe_index > > hp_cell_future_fe_indices
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
std::vector< std::vector< types::fe_index > > hp_cell_active_fe_indices
std::vector< MGVertexDoFs > mg_vertex_dofs
std::vector< std::array< std::vector< types::global_dof_index >, dim+1 > > object_dof_indices
const Triangulation< dim, spacedim > & get_triangulation() const
std::vector< std::array< std::vector< offset_type >, dim+1 > > object_dof_ptr
std::unique_ptr<::internal::DoFHandlerImplementation::DoFFaces< dim > > mg_faces
bool hp_capability_enabled
bool has_hp_capabilities() const
std::array< std::vector< offset_type >, dim+1 > hp_object_fe_ptr
std::array< std::vector< types::fe_index >, dim+1 > hp_object_fe_indices
DoFInvalidAccessor(const void *parent=nullptr, const int level=-1, const int index=-1, const AccessorData *local_data=nullptr)
typename InvalidAccessor< structdim, dim, spacedim >::AccessorData AccessorData
unsigned int n_dofs_per_vertex() const
size_type n() const
size_type m() const
void compress() const
Definition index_set.h:1767
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
Definition index_set.h:1814
void import_elements(const ::Vector< Number > &vec, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
TriaIterator< TriaAccessor< structdim, dim, spacedim > > child(const unsigned int i) const
IteratorState::IteratorStates state() const
virtual size_type size() const override
iterator end()
iterator begin()
#define DEAL_II_ALWAYS_INLINE
Definition config.h:166
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_RESTRICT
Definition config.h:167
constexpr bool running_in_debug_mode()
Definition config.h:76
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
Point< 2 > second
Definition grid_out.cc:4640
Point< 2 > first
Definition grid_out.cc:4639
unsigned int level
Definition grid_out.cc:4642
static ::ExceptionBase & ExcVectorNotEmpty()
#define DeclException0(Exception0)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcNotActive()
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcMatrixDoesNotMatch()
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInvalidObject()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcCantCompareIterators()
static ::ExceptionBase & ExcVectorDoesNotMatch()
static ::ExceptionBase & ExcMessage(std::string arg1)
@ past_the_end
Iterator reached end of container.
Definition hp.h:115
types::fe_index get_fe_index_or_default(const DoFAccessor< structdim, dim, spacedim, level_dof_access > &cell, const types::fe_index fe_index)
void get_cell_dof_indices(const ::DoFCellAccessor< dim, spacedim, level_dof_access > &accessor, Implementation::dof_index_vector_type &dof_indices, const unsigned int fe_index)
TriaIterator< ::DoFAccessor< dim - 1, dim, spacedim, level_dof_access > > get_face(const ::DoFCellAccessor< dim, spacedim, level_dof_access > &cell, const unsigned int i, const std::integral_constant< int, 1 >)
Kokkos::RangePolicy< ExecutionSpace, Kokkos::IndexType< std::size_t > > Policy
Definition solver_cg.cc:113
constexpr types::global_dof_index invalid_dof_index
Definition types.h:259
constexpr types::geometric_orientation reverse_line_orientation
Definition types.h:355
constexpr types::geometric_orientation default_geometric_orientation
Definition types.h:342
constexpr types::fe_index invalid_fe_index
Definition types.h:250
STL namespace.
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
Definition types.h:30
unsigned short int fe_index
Definition types.h:70
void process_vertex_dofs(DoFHandler< dim, spacedim > &dof_handler, const unsigned int vertex_index, const types::fe_index fe_index, types::global_dof_index *&dof_indices_ptr, const DoFProcessor &dof_processor) const
void process_dofs(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const types::fe_index fe_index, const DoFMapping &mapping, const std::integral_constant< int, structdim >, types::global_dof_index *&dof_indices_ptr, const DoFProcessor &dof_processor) const
void process_dofs(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int, const unsigned int obj_index, const types::fe_index fe_index, const DoFMapping &mapping, const std::integral_constant< int, structdim >, types::global_dof_index *&dof_indices_ptr, const DoFProcessor &dof_processor) const
void process_vertex_dofs(DoFHandler< dim, spacedim > &dof_handler, const unsigned int vertex_index, const types::fe_index, types::global_dof_index *&dof_indices_ptr, const DoFProcessor &dof_processor) const
static types::global_dof_index * get_array_ptr(const std::tuple<> &)
static void process_dof_indices(const ::DoFAccessor< structdim, dim, spacedim, level_dof_access > &accessor, const DoFIndicesType &const_dof_indices, const types::fe_index fe_index_, const DoFOperation &dof_operation, const DoFProcessor &dof_processor, const bool count_level_dofs)
static void get_dof_indices(const ::DoFAccessor< structdim, dim, spacedim, level_dof_access > &accessor, std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index)
static void extract_subvector_to(const LinearAlgebra::TpetraWrappers::Vector< Number, MemorySpace > &values, const types::global_dof_index *cache_begin, const types::global_dof_index *cache_end, ForwardIterator local_values_begin)
static std::set< types::fe_index > get_active_fe_indices(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const std::integral_constant< int, structdim > &t)
static types::global_dof_index * get_array_ptr(const ArrayType &array)
static unsigned int get_array_length(const std::tuple<> &)
static types::global_dof_index * find_dof_index(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const types::fe_index fe_index, const unsigned int local_index, const std::integral_constant< int, structdim > &dd)
static unsigned int n_active_fe_indices(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const std::integral_constant< int, structdim > &)
static void set_dof_index(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const types::fe_index fe_index, const unsigned int local_index, const std::integral_constant< int, structdim > &dd, const types::global_dof_index global_index)
static void extract_subvector_to(const LinearAlgebra::EpetraWrappers::Vector &values, const types::global_dof_index *cache_begin, const types::global_dof_index *cache_end, ForwardIterator local_values_begin)
static void get_mg_dof_indices(const ::DoFAccessor< structdim, dim, spacedim, level_dof_access > &accessor, const int level, std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index)
static bool fe_index_is_active(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const types::fe_index fe_index, const std::integral_constant< int, structdim > &)
static types::global_dof_index & get_mg_dof_index(const DoFHandler< dim, spacedim > &dof_handler, const std::unique_ptr< internal::DoFHandlerImplementation::DoFLevel< dim > > &, const std::unique_ptr< internal::DoFHandlerImplementation::DoFFaces< dim > > &mg_faces, const unsigned int obj_index, const types::fe_index fe_index, const unsigned int local_index, const std::integral_constant< int, 1 >)
boost::container::small_vector<::types::global_dof_index, 100 > dof_index_vector_type
static types::global_dof_index & get_mg_dof_index(const DoFHandler< dim, spacedim > &dof_handler, const std::unique_ptr< internal::DoFHandlerImplementation::DoFLevel< dim > > &mg_level, const std::unique_ptr< internal::DoFHandlerImplementation::DoFFaces< dim > > &, const unsigned int obj_index, const types::fe_index fe_index, const unsigned int local_index, const std::integral_constant< int, dim >)
static std::pair< unsigned int, unsigned int > process_object_range(const ::DoFAccessor< structdim, dim, spacedim, level_dof_access > accessor, const types::fe_index fe_index)
static types::global_dof_index & mg_vertex_dof_index(DoFHandler< dim, spacedim > &dof_handler, const int level, const unsigned int vertex_index, const unsigned int i)
static void set_mg_dof_indices(const ::DoFAccessor< structdim, dim, spacedim, level_dof_access > &accessor, const int level, const std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index)
static void set_dof_indices(const ::DoFAccessor< structdim, dim, spacedim, level_dof_access > &accessor, const std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index)
static types::global_dof_index & get_mg_dof_index(const DoFHandler< 3, spacedim > &dof_handler, const std::unique_ptr< internal::DoFHandlerImplementation::DoFLevel< 3 > > &, const std::unique_ptr< internal::DoFHandlerImplementation::DoFFaces< 3 > > &mg_faces, const unsigned int obj_index, const types::fe_index fe_index, const unsigned int local_index, const std::integral_constant< int, 2 >)
static std::pair< unsigned int, unsigned int > process_object_range(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const types::fe_index fe_index, const std::integral_constant< int, structdim > &)
static void extract_subvector_to(const InputVector &values, const types::global_dof_index *cache, const types::global_dof_index *cache_end, ForwardIterator local_values_begin)
static std::vector< unsigned int > sort_indices(const types::global_dof_index *v_begin, const types::global_dof_index *v_end)
static types::fe_index nth_active_fe_index(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const unsigned int local_index, const std::integral_constant< int, structdim > &)
static void process_object(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const types::fe_index fe_index, const DoFMapping &mapping, const std::integral_constant< int, structdim > &dd, types::global_dof_index *&dof_indices_ptr, const DoFProcessor &process)
static types::global_dof_index get_dof_index(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int obj_level, const unsigned int obj_index, const types::fe_index fe_index, const unsigned int local_index, const std::integral_constant< int, structdim > &dd)
static unsigned int n_dof_indices(const ::DoFAccessor< structdim, dim, spacedim, level_dof_access > &accessor, const types::fe_index fe_index_, const bool count_level_dofs)
static std::pair< unsigned int, unsigned int > process_object_range(::DoFInvalidAccessor< structdim, dim, spacedim >, const unsigned int)
static unsigned int get_array_length(const ArrayType &array)
static types::fe_index future_fe_index(const DoFCellAccessor< dim, spacedim, level_dof_access > &accessor)
static void clear_future_fe_index(const DoFCellAccessor< dim, spacedim, level_dof_access > &accessor)
static bool future_fe_index_set(const DoFCellAccessor< dim, spacedim, level_dof_access > &accessor)
static void set_active_fe_index(const DoFCellAccessor< dim, spacedim, level_dof_access > &accessor, const types::fe_index i)
static void set_future_fe_index(const DoFCellAccessor< dim, spacedim, level_dof_access > &accessor, const types::fe_index i)
static types::fe_index active_fe_index(const DoFCellAccessor< dim, spacedim, level_dof_access > &accessor)