Debian Codegraph @

include/deal.II/dofs/dof_objects.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2006 - 2025 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
15 #ifndef dealii_dof_objects_h
16 #define dealii_dof_objects_h
17
18
19 #include <deal.II/base/config.h>
20
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/template_constraints.h>
23 #include <deal.II/base/types.h>
24
25 #include <vector>
26
27 DEAL_II_NAMESPACE_OPEN
28
29 // Forward declarations
30 #ifndef DOXYGEN
31 template <int dim, int spacedim>
32 DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
33 class DoFHandler;
34 #endif
35
36 namespace internal
37 {
38 namespace DoFHandlerImplementation
39 {
40 #ifndef DOXYGEN
41 template <int>
42 class DoFLevel;
43 template <int>
44 class DoFFaces;
45 #endif
46
47 /**
48 * Store the indices of the degrees of freedom which are located on
49 * objects of dimension @p dim.
50 *
51 * <h3>Information for all DoFObjects classes</h3>
52 *
53 * The DoFObjects classes store the global indices of the degrees of
54 * freedom for each cell on a certain level. The global index or number of
55 * a degree of freedom is the zero-based index of the according value in
56 * the solution vector and the row and column index in the global matrix
57 * or the multigrid matrix for this level. These indices refer to the
58 * unconstrained vectors and matrices, where we have not taken account of
59 * the constraints introduced by hanging nodes.
60 *
61 * Since vertices are not associated with a particular level, the indices
62 * associated with vertices are not stored in the DoFObjects classes but
63 * rather in the DoFHandler::vertex_dofs array.
64 *
65 * The DoFObjects classes are not used directly, but objects of these
66 * classes are included in the DoFLevel and DoFFaces classes.
67 *
68 * @ingroup dofs
69 */
70 template <int dim>
71 class DoFObjects
72 {
73 public:
74 /**
75 * Store the global indices of the degrees of freedom.
76 */
77 std::vector<types::global_dof_index> dofs;
78
79 /**
80 * Return the global index of the @p local_index-th degree of freedom
81 * located on the object with number @p obj_index. The @p dof_handler
82 * argument is used to access the finite element that is to be used to
83 * compute the location where this data is stored.
84 *
85 * The third argument, @p fe_index, must equal zero. It is otherwise
86 * unused, but we retain the argument so that we can use the same
87 * interface for non-hp- and hp-finite element methods, in effect making
88 * it possible to share the DoFAccessor class hierarchy between hp- and
89 * non-hp-classes.
90 */
91 template <int dh_dim, int spacedim>
92 types::global_dof_index &
93 access_dof_index(const DoFHandler<dh_dim, spacedim> &dof_handler,
94 const unsigned int obj_index,
95 const types::fe_index fe_index,
96 const unsigned int local_index);
97
98 /**
99 * Return the value 1. The meaning of this function becomes clear by
100 * looking at what the corresponding functions in the classes
101 * internal::hp::DoFObjects
102 */
103 template <int dh_dim, int spacedim>
104 unsigned int
105 n_active_fe_indices(const DoFHandler<dh_dim, spacedim> &dof_handler,
106 const types::global_dof_index index) const;
107
108 /**
109 * Similar to the function above. Assert that the given index is zero,
110 * and then return true.
111 */
112 template <int dh_dim, int spacedim>
113 bool
114 fe_index_is_active(const DoFHandler<dh_dim, spacedim> &dof_handler,
115 const types::global_dof_index index,
116 const types::fe_index fe_index) const;
117
118 /**
119 * Determine an estimate for the memory consumption (in bytes) of this
120 * object.
121 */
122 std::size_t
123 memory_consumption() const;
124
125 /**
126 * Read or write the data of this object to or from a stream for the
127 * purpose of serialization using the [BOOST serialization
128 * library](https://www.boost.org/doc/libs/1_74_0/libs/serialization/doc/index.html).
129 */
130 template <class Archive>
131 void
132 serialize(Archive &ar, const unsigned int version);
133
134 // Declare the classes that store levels and faces of DoFs friends so
135 // that they can resize arrays.
136 template <int>
137 friend class DoFLevel;
138 template <int>
139 friend class DoFFaces;
140 };
141
142
143 // --------------------- template and inline functions ------------------
144
145 template <int dim>
146 template <int dh_dim, int spacedim>
147 inline unsigned int
148 DoFObjects<dim>::n_active_fe_indices(const DoFHandler<dh_dim, spacedim> &,
149 const types::global_dof_index) const
150 {
151 return 1;
152 }
153
154
155
156 template <int dim>
157 template <int dh_dim, int spacedim>
158 inline bool
159 DoFObjects<dim>::fe_index_is_active(const DoFHandler<dh_dim, spacedim> &,
160 const types::global_dof_index,
161 const types::fe_index fe_index) const
162 {
163 (void)fe_index;
164 Assert((fe_index == DoFHandler<dh_dim, spacedim>::default_fe_index),
165 ExcMessage("Only zero fe_index values are allowed for "
166 "non-hp-DoFHandlers."));
167 return true;
168 }
169
170
171
172 template <int dim>
173 template <int dh_dim, int spacedim>
174 inline types::global_dof_index &
175 DoFObjects<dim>::access_dof_index(
176 const DoFHandler<dh_dim, spacedim> &dof_handler,
177 const unsigned int obj_index,
178 const types::fe_index fe_index,
179 const unsigned int local_index)
180 {
181 (void)fe_index;
182 Assert((fe_index == DoFHandler<dh_dim, spacedim>::default_fe_index),
183 ExcMessage("Only the default FE index is allowed for DoFHandler "
184 "objects without hp capability"));
185 AssertIndexRange(local_index,
186 dof_handler.get_fe().template n_dofs_per_object<dim>());
187 AssertIndexRange(
188 obj_index * dof_handler.get_fe().template n_dofs_per_object<dim>() +
189 local_index,
190 dofs.size());
191
192 return dofs[obj_index *
193 dof_handler.get_fe().template n_dofs_per_object<dim>() +
194 local_index];
195 }
196
197
198 template <int dim>
199 template <class Archive>
200 void
201 DoFObjects<dim>::serialize(Archive &ar, const unsigned int)
202 {
203 ar &dofs;
204 }
205
206 } // namespace DoFHandlerImplementation
207 } // namespace internal
208
209 DEAL_II_NAMESPACE_CLOSE
210
211 #endif