Debian Codegraph @

include/deal.II/dofs/dof_handler_policy.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2010 - 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
15 #ifndef dealii_dof_handler_policy_h
16 #define dealii_dof_handler_policy_h
17
18
19
20 #include <deal.II/base/config.h>
21
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/template_constraints.h>
24
25 #include <deal.II/dofs/dof_renumbering.h>
26 #include <deal.II/dofs/dof_tools.h>
27
28 #include <vector>
29
30 DEAL_II_NAMESPACE_OPEN
31
32 // Forward declaration
33 #ifndef DOXYGEN
34 template <int dim, int spacedim>
35 DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
36 class DoFHandler;
37 #endif
38
39 namespace internal
40 {
41 namespace DoFHandlerImplementation
42 {
43 struct NumberCache;
44
45 /**
46 * A namespace in which we define classes that describe how to distribute
47 * and renumber degrees of freedom.
48 */
49 namespace Policy
50 {
51 struct Implementation;
52
53 /**
54 * A class that implements policies for how the
55 * DoFHandler::distribute_dofs and DoFHandler::renumber_dofs functions
56 * should work.
57 */
58 template <int dim, int spacedim>
59 class PolicyBase
60 {
61 public:
62 /**
63 * Destructor.
64 */
65 virtual ~PolicyBase() = default;
66
67 /**
68 * Distribute degrees of freedom on the DoFHandler object associated
69 * with this policy object. The argument is a reference to the
70 * NumberCache of the DoFHandler object. The function may modify it to
71 * make DoFHandler related functions work properly when called within
72 * the policies classes. The updated NumberCache is written to that
73 * argument.
74 */
75 virtual NumberCache
76 distribute_dofs() const = 0;
77
78 /**
79 * Distribute the multigrid dofs on each level of the DoFHandler
80 * associated with this policy object. Return a vector of number
81 * caches for all of the levels.
82 */
83 virtual std::vector<NumberCache>
84 distribute_mg_dofs() const = 0;
85
86 /**
87 * Renumber degrees of freedom as specified by the first argument.
88 *
89 * Return an updated NumberCache for the DoFHandler after renumbering.
90 */
91 virtual NumberCache
92 renumber_dofs(
93 const std::vector<types::global_dof_index> &new_numbers) const = 0;
94
95 /**
96 * Renumber multilevel degrees of freedom on one level of a multigrid
97 * hierarchy. The second argument specifies the set of new DoF
98 * indices.
99 *
100 * Return an updated NumberCache for the specified level of the
101 * DoFHandler after renumbering.
102 */
103 virtual NumberCache
104 renumber_mg_dofs(
105 const unsigned int level,
106 const std::vector<types::global_dof_index> &new_numbers) const = 0;
107 };
108
109
110 /**
111 * This class implements the default policy for sequential operations,
112 * i.e. for the case where all cells get degrees of freedom.
113 */
114 template <int dim, int spacedim>
115 class Sequential : public PolicyBase<dim, spacedim>
116 {
117 public:
118 /**
119 * Constructor.
120 * @param dof_handler The DoFHandler object upon which this
121 * policy class is supposed to work.
122 */
123 Sequential(DoFHandler<dim, spacedim> &dof_handler);
124
125 // documentation is inherited
126 virtual NumberCache
127 distribute_dofs() const override;
128
129 // documentation is inherited
130 virtual std::vector<NumberCache>
131 distribute_mg_dofs() const override;
132
133 // documentation is inherited
134 virtual NumberCache
135 renumber_dofs(const std::vector<types::global_dof_index> &new_numbers)
136 const override;
137
138 // documentation is inherited
139 virtual NumberCache
140 renumber_mg_dofs(const unsigned int level,
141 const std::vector<types::global_dof_index>
142 &new_numbers) const override;
143
144 protected:
145 /**
146 * The DoFHandler object on which this policy object works.
147 */
148 ObserverPointer<DoFHandler<dim, spacedim>> dof_handler;
149 };
150
151
152
153 /**
154 * This class implements the policy for operations when we use a
155 * parallel::shared::Triangulation object.
156 */
157 template <int dim, int spacedim>
158 class ParallelShared : public PolicyBase<dim, spacedim>
159 {
160 public:
161 /**
162 * Constructor.
163 * @param dof_handler The DoFHandler object upon which this
164 * policy class is supposed to work.
165 */
166 ParallelShared(DoFHandler<dim, spacedim> &dof_handler);
167
168 /**
169 * Distribute degrees of freedom on the object given as first
170 * argument.
171 *
172 * On distribution, DoFs are renumbered subdomain-wise and
173 * number_cache.n_locally_owned_dofs_per_processor[i] and
174 * number_cache.locally_owned_dofs are updated consistently.
175 */
176 virtual NumberCache
177 distribute_dofs() const override;
178
179 /**
180 * This function is not yet implemented.
181 */
182 virtual std::vector<NumberCache>
183 distribute_mg_dofs() const override;
184
185 /**
186 * Renumber degrees of freedom as specified by the first argument.
187 *
188 * The input argument @p new_numbers may either have as many entries
189 * as there are global degrees of freedom (i.e. dof_handler.n_dofs() )
190 * or dof_handler.locally_owned_dofs().n_elements(). Therefore it can
191 * be utilized with renumbering functions implemented for the
192 * parallel::distributed case.
193 */
194 virtual NumberCache
195 renumber_dofs(const std::vector<types::global_dof_index> &new_numbers)
196 const override;
197
198 // documentation is inherited
199 virtual NumberCache
200 renumber_mg_dofs(const unsigned int level,
201 const std::vector<types::global_dof_index>
202 &new_numbers) const override;
203
204 private:
205 /**
206 * The DoFHandler object on which this policy object works.
207 */
208 ObserverPointer<DoFHandler<dim, spacedim>> dof_handler;
209 };
210
211
212 /**
213 * This class implements the policy for operations when we use a
214 * parallel::DistributedTriangulationBase object.
215 */
216 template <int dim, int spacedim>
217 class ParallelDistributed : public PolicyBase<dim, spacedim>
218 {
219 public:
220 /**
221 * Constructor.
222 * @param dof_handler The DoFHandler object upon which this
223 * policy class is supposed to work.
224 */
225 ParallelDistributed(DoFHandler<dim, spacedim> &dof_handler);
226
227 // documentation is inherited
228 virtual NumberCache
229 distribute_dofs() const override;
230
231 // documentation is inherited
232 virtual std::vector<NumberCache>
233 distribute_mg_dofs() const override;
234
235 // documentation is inherited
236 virtual NumberCache
237 renumber_dofs(const std::vector<types::global_dof_index> &new_numbers)
238 const override;
239
240 // documentation is inherited
241 virtual NumberCache
242 renumber_mg_dofs(const unsigned int level,
243 const std::vector<types::global_dof_index>
244 &new_numbers) const override;
245
246 private:
247 /**
248 * The DoFHandler object on which this policy object works.
249 */
250 ObserverPointer<DoFHandler<dim, spacedim>> dof_handler;
251 };
252 } // namespace Policy
253 } // namespace DoFHandlerImplementation
254 } // namespace internal
255
256
257
258 DEAL_II_NAMESPACE_CLOSE
259
260 #endif