Debian Codegraph @

include/deal.II/dofs/number_cache.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2010 - 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_number_cache_h
16 #define dealii_number_cache_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/index_set.h>
21 #include <deal.II/base/mpi_stub.h>
22 #include <deal.II/base/numbers.h>
23 #include <deal.II/base/types.h>
24
25 #include <vector>
26
27
28 DEAL_II_NAMESPACE_OPEN
29
30 namespace internal
31 {
32 namespace DoFHandlerImplementation
33 {
34 /**
35 * A structure used by the DoFHandler classes to store information about
36 * the degrees of freedom they deal with.
37 */
38 struct NumberCache
39 {
40 /**
41 * Default constructor.
42 */
43 NumberCache();
44
45 /**
46 * Copy constructor. Simply copy all members of the referenced
47 * object to the current object.
48 */
49 NumberCache(const NumberCache &) = default;
50
51 /**
52 * Move constructor. Simply move all members of the referenced
53 * object to the current object.
54 */
55 NumberCache(NumberCache &&) = default;
56
57 /**
58 * Create a NumberCache object that corresponds to a sequential
59 * DoFHandler object in which a single processor stores all
60 * degrees of freedom. (Here, "sequential" means that either
61 * the whole program does not use MPI, or that it uses MPI
62 * but only uses a single MPI process, or that there are multiple MPI
63 * processes but the Triangulation on which this DoFHandler builds
64 * works only on one MPI process.)
65 */
66 NumberCache(const types::global_dof_index n_global_dofs);
67
68
69 /**
70 * Create a NumberCache object that corresponds to a parallel
71 * DoFHandler object with as many processors as the size of the
72 * given argument, in which each processor stores the degrees
73 * of freedom indicated in the corresponding element of the
74 * vector passed as first argument. The second argument indicates
75 * the rank among all participating processors the current
76 * processor has, so that we can set the @p locally_owned_dofs
77 * and @p n_locally_owned_dofs fields.
78 *
79 * All other fields stored by the current object can be and are computed
80 * from the argument.
81 */
82 NumberCache(const std::vector<IndexSet> &locally_owned_dofs_per_processor,
83 const unsigned int my_rank);
84
85 /**
86 * Copy operator. Simply copy all members of the referenced
87 * object to the current object.
88 */
89 NumberCache &
90 operator=(const NumberCache &) = default;
91
92 /**
93 * Move assignment operator. Simply move all members of the referenced
94 * object to the current object.
95 */
96 NumberCache &
97 operator=(NumberCache &&) = default;
98
99 /**
100 * Determine an estimate for the memory consumption (in bytes) of this
101 * object.
102 */
103 std::size_t
104 memory_consumption() const;
105
106 /**
107 * This function resets all the stored information.
108 */
109 void
110 clear();
111
112 /**
113 * Return a representation of @p n_locally_owned_dofs_per_processor both
114 * in case it was set up (directly returning the array) or in case we
115 * need to accumulate some information over all processors. The latter
116 * case involves global communication and is typically expensive to set
117 * up because it invokes MPI_Allgather.
118 */
119 std::vector<types::global_dof_index>
120 get_n_locally_owned_dofs_per_processor(
121 const MPI_Comm mpi_communicator) const;
122
123 /**
124 * Return a representation of @p locally_owned_dofs_per_processor both
125 * in case it was set up (directly returning the array of IndexSet
126 * fields) or in case we need to accumulate some information over all
127 * processors. The latter case involves global communication and is
128 * typically expensive to set up because it invokes MPI_Allgather.
129 */
130 std::vector<IndexSet>
131 get_locally_owned_dofs_per_processor(
132 const MPI_Comm mpi_communicator) const;
133
134 /**
135 * Total number of dofs, accumulated over all processors that may
136 * participate on this mesh.
137 */
138 types::global_dof_index n_global_dofs;
139
140 /**
141 * Number of dofs owned by this MPI process. If this is a sequential
142 * computation, then this equals n_global_dofs. (Here, "sequential" means
143 * that either the whole program does not use MPI, or that it uses MPI but
144 * only uses a single MPI process, or that there are multiple MPI
145 * processes but the Triangulation on which this DoFHandler builds
146 * works only on one MPI process.)
147 */
148 types::global_dof_index n_locally_owned_dofs;
149
150 /**
151 * An index set denoting the set of locally owned dofs. If this is a
152 * sequential computation, then it contains the entire range
153 * [0,n_global_dofs). (Here, "sequential" means that either
154 * the whole program does not use MPI, or that it uses MPI
155 * but only uses a single MPI process, or that there are multiple MPI
156 * processes but the Triangulation on which this DoFHandler builds
157 * works only on one MPI process.)
158 */
159 IndexSet locally_owned_dofs;
160
161 /**
162 * The number of dofs owned by each of the various MPI processes. If
163 * this is a sequential computation, then the vector contains a single
164 * element equal to n_global_dofs. (Here, "sequential" means that either
165 * the whole program does not use MPI, or that it uses MPI
166 * but only uses a single MPI process, or that there are multiple MPI
167 * processes but the Triangulation on which this DoFHandler builds
168 * works only on one MPI process.)
169 */
170 std::vector<types::global_dof_index> n_locally_owned_dofs_per_processor;
171
172 /**
173 * The dofs owned by each of the various MPI processes. If this is a
174 * sequential DoFHandler, then the vector has a single element equal to
175 * locally_owned_dofs. (Here, "sequential" means that either
176 * the whole program does not use MPI, or that it uses MPI
177 * but only uses a single MPI process, or that there are multiple MPI
178 * processes but the Triangulation on which this DoFHandler builds
179 * works only on one MPI process.)
180 */
181 std::vector<IndexSet> locally_owned_dofs_per_processor;
182
183 /**
184 * Read or write the data of this object to or from a stream for the
185 * purpose of serialization using the [BOOST serialization
186 * library](https://www.boost.org/doc/libs/1_74_0/libs/serialization/doc/index.html).
187 */
188 template <class Archive>
189 void
190 serialize(Archive &ar, const unsigned int version);
191 };
192
193
194 template <class Archive>
195 void
196 NumberCache::serialize(Archive &ar, const unsigned int /*version*/)
197 {
198 ar &n_global_dofs &n_locally_owned_dofs;
199 ar &locally_owned_dofs;
200 ar &n_locally_owned_dofs_per_processor;
201 ar &locally_owned_dofs_per_processor;
202 }
203
204 } // namespace DoFHandlerImplementation
205 } // namespace internal
206
207
208 DEAL_II_NAMESPACE_CLOSE
209
210 #endif // dealii_dof_iterator_selector_h