Reference documentation for deal.II version GIT relicensing-362-gab68047079 2024-04-11 17:50:02+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: LGPL-2.1-or-later
4// Copyright (C) 1998 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
18
19#include <deal.II/fe/fe.h>
20
22#include <deal.II/grid/tria_iterator.templates.h>
23
24#include <vector>
25
27
28/* --------------------- Static variables: DoFAccessor --------------------- */
29
30template <int structdim, int dim, int spacedim, bool level_dof_access>
31const unsigned int
33
34template <int structdim, int dim, int spacedim, bool level_dof_access>
35const unsigned int
37
38
39
40/* ---------------------- Functions: DoFInvalidAccessor -------------------- */
41
42template <int structdim, int dim, int spacedim>
44 const void *,
45 const int,
46 const int,
47 const AccessorData *)
48{
49 Assert(false,
50 ExcMessage("You are attempting an illegal conversion between "
51 "iterator/accessor types. The constructor you call "
52 "only exists to make certain template constructs "
53 "easier to write as dimension independent code but "
54 "the conversion is not valid in the current context."));
55}
56
57
58
59template <int structdim, int dim, int spacedim>
61 const DoFInvalidAccessor &i)
62 : InvalidAccessor<structdim, dim, spacedim>(
63 static_cast<const InvalidAccessor<structdim, dim, spacedim> &>(i))
64{
65 Assert(false,
66 ExcMessage("You are attempting an illegal conversion between "
67 "iterator/accessor types. The constructor you call "
68 "only exists to make certain template constructs "
69 "easier to write as dimension independent code but "
70 "the conversion is not valid in the current context."));
71}
72
73
74
75template <int structdim, int dim, int spacedim>
78 const unsigned int,
79 const types::fe_index) const
80{
82 return 0;
83}
84
85
86
87template <int structdim, int dim, int spacedim>
88void
96
97
98
99/*------------------------- Functions: DoFCellAccessor -----------------------*/
100
101
102
103template <int dim, int spacedim, bool lda>
104void
106 const std::vector<types::global_dof_index> &local_dof_indices)
107{
108 Assert(static_cast<unsigned int>(this->present_level) <
109 this->dof_handler->object_dof_indices.size(),
110 ExcMessage("DoFHandler not initialized"));
111
112 Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());
113
114 internal::DoFAccessorImplementation::Implementation::
115 template set_dof_indices<dim, spacedim, lda, dim>(*this,
116 local_dof_indices,
117 this->active_fe_index());
118}
119
120
121
122template <int dim, int spacedim, bool lda>
125 const unsigned int face,
126 const unsigned int subface) const
127{
131 this->dof_handler);
132}
133
134
135
136template <int dim, int spacedim, bool lda>
139 const unsigned int face,
140 const unsigned int subface) const
141{
144 subface);
146 this->dof_handler);
147}
148
149
150
151template <int dim, int spacedim, bool lda>
161
162
163
164template <int dim, int spacedim, bool lda>
174
175
176
177template <int structdim, int dim, int spacedim, bool level_dof_access>
178inline void
180 std::vector<types::global_dof_index> &dof_indices,
181 const types::fe_index fe_index_) const
182{
183 Assert(this->dof_handler != nullptr, ExcInvalidObject());
184
185 const auto fe_index =
186 internal::DoFAccessorImplementation::get_fe_index_or_default(*this,
187 fe_index_);
188
189 Assert(static_cast<unsigned int>(this->level()) <
190 this->dof_handler->object_dof_indices.size(),
192 "The DoFHandler to which this accessor points has not "
193 "been initialized, i.e., it doesn't appear that DoF indices "
194 "have been distributed on it."));
195
196 // this function really only makes sense if either a) there are degrees of
197 // freedom defined on the present object, or b) the object is non-active
198 // objects but all degrees of freedom are located on vertices, since
199 // otherwise there are degrees of freedom on sub-objects which are not
200 // allocated for this non-active thing
201 Assert(this->fe_index_is_active(fe_index) ||
202 (this->dof_handler->get_fe(fe_index).n_dofs_per_cell() ==
203 this->n_vertices() *
204 this->dof_handler->get_fe(fe_index).n_dofs_per_vertex()),
206
207 // now do the actual work
208 ::internal::DoFAccessorImplementation::Implementation::get_dof_indices(
209 *this, dof_indices, fe_index);
210}
211
212
213
214template <int structdim, int dim, int spacedim, bool level_dof_access>
215inline void
217 const int level,
218 std::vector<types::global_dof_index> &dof_indices,
219 const types::fe_index fe_index_) const
220{
221 Assert(this->dof_handler != nullptr, ExcInvalidObject());
222 Assert(this->dof_handler->mg_vertex_dofs.size() > 0,
223 ExcMessage("Multigrid DoF indices can only be accessed after "
224 "DoFHandler::distribute_mg_dofs() has been called!"));
225
226 const auto fe_index =
227 internal::DoFAccessorImplementation::get_fe_index_or_default(*this,
228 fe_index_);
229
230 internal::DoFAccessorImplementation::Implementation::get_mg_dof_indices(
231 *this, level, dof_indices, fe_index);
232}
233
234
235
236template <int structdim, int dim, int spacedim, bool level_dof_access>
237inline void
239 const int level,
240 const std::vector<types::global_dof_index> &dof_indices,
241 const types::fe_index fe_index_)
242{
243 Assert(this->dof_handler != nullptr, ExcInvalidObject());
244
245 const auto fe_index =
246 internal::DoFAccessorImplementation::get_fe_index_or_default(*this,
247 fe_index_);
248
249 internal::DoFAccessorImplementation::Implementation::set_mg_dof_indices(
250 *this, level, dof_indices, fe_index);
251}
252
253
254
255namespace internal
256{
257 namespace DoFAccessorImplementation
258 {
259 template <int dim, int spacedim, bool level_dof_access>
260 void
262 const ::DoFCellAccessor<dim, spacedim, level_dof_access> &accessor,
263 boost::container::small_vector<types::global_dof_index, 27> &dof_indices,
264 const unsigned int fe_index)
265 {
266 Implementation::process_dof_indices(
267 accessor,
268 dof_indices,
269 fe_index,
270 Implementation::DoFIndexProcessor<dim, spacedim>(),
271 [](auto stored_index, auto dof_ptr) { *dof_ptr = stored_index; },
272 false);
273 }
274 } // namespace DoFAccessorImplementation
275} // namespace internal
276
277
278
279template <int dimension_, int space_dimension_, bool level_dof_access>
280inline void
282 get_dof_indices(std::vector<types::global_dof_index> &dof_indices) const
283{
284 Assert(this->is_active(),
285 ExcMessage("get_dof_indices() only works on active cells."));
286 Assert(this->is_artificial() == false,
287 ExcMessage("Can't ask for DoF indices on artificial cells."));
288 AssertDimension(dof_indices.size(), this->get_fe().n_dofs_per_cell());
289
290 ::internal::DoFAccessorImplementation::Implementation::get_dof_indices(
291 *this, dof_indices, this->active_fe_index());
292}
293
294
295
296template <int dimension_, int space_dimension_, bool level_dof_access>
297inline void
299 get_mg_dof_indices(std::vector<types::global_dof_index> &dof_indices) const
300{
301 Assert(this->dof_handler->mg_vertex_dofs.size() > 0,
302 ExcMessage("Multigrid DoF indices can only be accessed after "
303 "DoFHandler::distribute_mg_dofs() has been called!"));
305 get_mg_dof_indices(this->level(), dof_indices);
306}
307
308
309
310template <int dimension_, int space_dimension_, bool level_dof_access>
311inline void
313 set_mg_dof_indices(const std::vector<types::global_dof_index> &dof_indices)
314{
315 Assert(this->dof_handler->mg_vertex_dofs.size() > 0,
316 ExcMessage("Multigrid DoF indices can only be accessed after "
317 "DoFHandler::distribute_mg_dofs() has been called!"));
319 set_mg_dof_indices(this->level(), dof_indices);
320}
321
322// --------------------------------------------------------------------------
323// explicit instantiations
324#include "dof_accessor.inst"
325
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
unsigned int level
Definition grid_out.cc:4626
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DEAL_II_ASSERT_UNREACHABLE()
void get_cell_dof_indices(const ::DoFCellAccessor< dim, spacedim, level_dof_access > &accessor, boost::container::small_vector< types::global_dof_index, 27 > &dof_indices, const unsigned int fe_index)
unsigned short int fe_index
Definition types.h:59