deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20: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.cc
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
16
17#include <deal.II/fe/fe.h>
18
20
21#include <boost/container/small_vector.hpp>
22
23#include <vector>
24
26
27/* --------------------- Static variables: DoFAccessor --------------------- */
28
29template <int structdim, int dim, int spacedim, bool level_dof_access>
30const unsigned int
32
33template <int structdim, int dim, int spacedim, bool level_dof_access>
34const unsigned int
36
37
38
39/* ---------------------- Functions: DoFInvalidAccessor -------------------- */
40
41template <int structdim, int dim, int spacedim>
43 const void *,
44 const int,
45 const int,
46 const AccessorData *)
47{
48 Assert(false,
49 ExcMessage("You are attempting an illegal conversion between "
50 "iterator/accessor types. The constructor you call "
51 "only exists to make certain template constructs "
52 "easier to write as dimension independent code but "
53 "the conversion is not valid in the current context."));
54}
55
56
57
58template <int structdim, int dim, int spacedim>
60 const DoFInvalidAccessor &i)
61 : InvalidAccessor<structdim, dim, spacedim>(
62 static_cast<const InvalidAccessor<structdim, dim, spacedim> &>(i))
63{
64 Assert(false,
65 ExcMessage("You are attempting an illegal conversion between "
66 "iterator/accessor types. The constructor you call "
67 "only exists to make certain template constructs "
68 "easier to write as dimension independent code but "
69 "the conversion is not valid in the current context."));
70}
71
72
73
74template <int structdim, int dim, int spacedim>
77 const unsigned int,
78 const types::fe_index) const
79{
81 return 0;
82}
83
84
85
86template <int structdim, int dim, int spacedim>
87void
95
96
97
98/*------------------------- Functions: DoFCellAccessor -----------------------*/
99
100
101
102template <int dim, int spacedim, bool lda>
103void
105 const std::vector<types::global_dof_index> &local_dof_indices)
106{
107 Assert(static_cast<unsigned int>(this->level()) <
108 this->dof_handler->object_dof_indices.size(),
109 ExcMessage("DoFHandler not initialized"));
110
111 Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());
112
113 internal::DoFAccessorImplementation::Implementation::
114 template set_dof_indices<dim, spacedim, lda, dim>(*this,
115 local_dof_indices,
116 this->active_fe_index());
117}
118
119
120
121template <int dim, int spacedim, bool lda>
124 const unsigned int face,
125 const unsigned int subface) const
126{
130 this->dof_handler);
131}
132
133
134
135template <int dim, int spacedim, bool lda>
138 const unsigned int face,
139 const unsigned int subface) const
140{
143 subface);
145 this->dof_handler);
146}
147
148
149
150template <int dim, int spacedim, bool lda>
160
161
162
163template <int dim, int spacedim, bool lda>
173
174
175
176template <int structdim, int dim, int spacedim, bool level_dof_access>
177void
179 std::vector<types::global_dof_index> &dof_indices,
180 const types::fe_index fe_index_) const
181{
182 Assert(this->dof_handler != nullptr, ExcInvalidObject());
183
184 const auto fe_index =
186 fe_index_);
187
188 Assert(static_cast<unsigned int>(this->level()) <
189 this->dof_handler->object_dof_indices.size(),
191 "The DoFHandler to which this accessor points has not "
192 "been initialized, i.e., it doesn't appear that DoF indices "
193 "have been distributed on it."));
194
195 // this function really only makes sense if either a) there are degrees of
196 // freedom defined on the present object, or b) the object is non-active
197 // objects but all degrees of freedom are located on vertices, since
198 // otherwise there are degrees of freedom on sub-objects which are not
199 // allocated for this non-active thing
200 Assert(this->fe_index_is_active(fe_index) ||
201 (this->dof_handler->get_fe(fe_index).n_dofs_per_cell() ==
202 this->n_vertices() *
203 this->dof_handler->get_fe(fe_index).n_dofs_per_vertex()),
205
206 // now do the actual work
208 *this, dof_indices, fe_index);
209}
210
211
212
213template <int structdim, int dim, int spacedim, bool level_dof_access>
214void
216 const int level,
217 std::vector<types::global_dof_index> &dof_indices,
218 const types::fe_index fe_index_) const
219{
220 Assert(this->dof_handler != nullptr, ExcInvalidObject());
221 Assert(this->dof_handler->mg_vertex_dofs.size() > 0,
222 ExcMessage("Multigrid DoF indices can only be accessed after "
223 "DoFHandler::distribute_mg_dofs() has been called!"));
224
225 const auto fe_index =
227 fe_index_);
228
230 *this, level, dof_indices, fe_index);
231}
232
233
234
235template <int structdim, int dim, int spacedim, bool level_dof_access>
236void
238 const int level,
239 const std::vector<types::global_dof_index> &dof_indices,
240 const types::fe_index fe_index_)
241{
242 Assert(this->dof_handler != nullptr, ExcInvalidObject());
243
244 const auto fe_index =
246 fe_index_);
247
249 *this, level, dof_indices, fe_index);
250}
251
252
253
254namespace internal
255{
256 namespace DoFAccessorImplementation
257 {
258 template <int dim, int spacedim, bool level_dof_access>
259 void
261 const ::DoFCellAccessor<dim, spacedim, level_dof_access> &accessor,
263 const unsigned int fe_index)
264 {
266 accessor,
267 dof_indices,
268 fe_index,
270 [](auto stored_index, auto dof_ptr) { *dof_ptr = stored_index; },
271 false);
272 }
273 } // namespace DoFAccessorImplementation
274} // namespace internal
275
276
277
278template <int dimension_, int space_dimension_, bool level_dof_access>
279void
281 get_dof_indices(std::vector<types::global_dof_index> &dof_indices) const
282{
283 Assert(this->is_active(),
284 ExcMessage("get_dof_indices() only works on active cells."));
285 Assert(this->is_artificial() == false,
286 ExcMessage("Can't ask for DoF indices on artificial cells."));
287 AssertDimension(dof_indices.size(), this->get_fe().n_dofs_per_cell());
288
290 *this, dof_indices, this->active_fe_index());
291}
292
293
294
295template <int dimension_, int space_dimension_, bool level_dof_access>
296void
298 get_mg_dof_indices(std::vector<types::global_dof_index> &dof_indices) const
299{
300 Assert(this->dof_handler->mg_vertex_dofs.size() > 0,
301 ExcMessage("Multigrid DoF indices can only be accessed after "
302 "DoFHandler::distribute_mg_dofs() has been called!"));
304 get_mg_dof_indices(this->level(), dof_indices);
305}
306
307
308
309template <int dimension_, int space_dimension_, bool level_dof_access>
310void
312 set_mg_dof_indices(const std::vector<types::global_dof_index> &dof_indices)
313{
314 Assert(this->dof_handler->mg_vertex_dofs.size() > 0,
315 ExcMessage("Multigrid DoF indices can only be accessed after "
316 "DoFHandler::distribute_mg_dofs() has been called!"));
318 set_mg_dof_indices(this->level(), dof_indices);
319}
320
321// --------------------------------------------------------------------------
322// explicit instantiations
323#include "dofs/dof_accessor.inst"
324
TriaIterator< CellAccessor< dim, spacedim > > periodic_neighbor(const unsigned int i) const
TriaIterator< CellAccessor< dim, spacedim > > neighbor_child_on_subface(const unsigned int face_no, const unsigned int subface_no) const
TriaIterator< CellAccessor< dim, spacedim > > periodic_neighbor_child_on_subface(const unsigned int face_no, const unsigned int subface_no) const
TriaIterator< CellAccessor< dim, spacedim > > neighbor_or_periodic_neighbor(const unsigned int i) const
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
void get_dof_indices(std::vector< types::global_dof_index > &dof_indices, const types::fe_index fe_index=numbers::invalid_fe_index) const
TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > > periodic_neighbor_child_on_subface(const unsigned int face_no, const unsigned int subface_no) const
TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > > neighbor_or_periodic_neighbor(const unsigned int i) const
TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > > periodic_neighbor(const unsigned int i) const
void set_dof_indices(const std::vector< types::global_dof_index > &dof_indices)
TriaIterator< DoFCellAccessor< dimension_, space_dimension_, level_dof_access > > neighbor_child_on_subface(const unsigned int face_no, const unsigned int subface_no) const
void set_mg_dof_indices(const std::vector< types::global_dof_index > &dof_indices)
void get_mg_dof_indices(std::vector< types::global_dof_index > &dof_indices) const
void get_dof_indices(std::vector< types::global_dof_index > &dof_indices) const
DoFInvalidAccessor(const void *parent=nullptr, const int level=-1, const int index=-1, const AccessorData *local_data=nullptr)
types::global_dof_index dof_index(const unsigned int i, const types::fe_index fe_index=DoFHandler< dim, spacedim >::default_fe_index) const
typename InvalidAccessor< structdim, dim, spacedim >::AccessorData AccessorData
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
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ASSERT_UNREACHABLE()
unsigned int level
Definition grid_out.cc:4642
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
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)
unsigned short int fe_index
Definition types.h:70
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 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)
boost::container::small_vector<::types::global_dof_index, 100 > dof_index_vector_type
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)