deal.II version GIT relicensing-6846-gd1ccc50c04 2026-10-05 21:50: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
copy_data.h
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) 2019 - 2025 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
13#ifndef dealii_meshworker_copy_data_h
14#define dealii_meshworker_copy_data_h
15
16#include <deal.II/base/config.h>
17
19#include <deal.II/base/types.h>
20
22#include <deal.II/lac/vector.h>
23
24#include <algorithm>
25#include <vector>
26
28
29namespace MeshWorker
30{
48 template <int n_matrices = 1,
49 int n_vectors = n_matrices,
50 int n_dof_indices = n_matrices,
51 typename ScalarType = double>
52 struct CopyData
53 {
59 CopyData() = default;
60
65 explicit CopyData(const unsigned int size);
66
70 explicit CopyData(
71 const ndarray<unsigned int, n_matrices, 2> &matrix_sizes,
72 const std::array<unsigned int, n_vectors> &vector_sizes,
73 const std::array<unsigned int, n_dof_indices> &dof_indices_sizes);
74
78 CopyData(const CopyData &other) = default;
79
83 CopyData &
84 operator=(const CopyData &other) = default;
85
90 void
91 reinit(const unsigned int size);
92
104 void
105 reinit(const unsigned int index, const unsigned int size);
106
120 void
121 reinit(const unsigned int index,
122 const unsigned int size_rows,
123 const unsigned int size_columns);
124
128 std::array<FullMatrix<ScalarType>, n_matrices> matrices;
129
133 std::array<Vector<ScalarType>, n_vectors> vectors;
134
138 std::array<std::vector<types::global_dof_index>, n_dof_indices>
140 };
141
142
143#ifndef DOXYGEN
144 //
145 // Template definitions
146 //
147 template <int n_matrices,
148 int n_vectors,
149 int n_dof_indices,
150 typename ScalarType>
152 const unsigned int size)
153 {
154 reinit(size);
155 }
156
157
158
159 template <int n_matrices,
160 int n_vectors,
161 int n_dof_indices,
162 typename ScalarType>
164 const ndarray<unsigned int, n_matrices, 2> &matrix_sizes,
165 const std::array<unsigned int, n_vectors> &vector_sizes,
166 const std::array<unsigned int, n_dof_indices> &dof_indices_sizes)
167 {
168 for (unsigned int i = 0; i < n_matrices; ++i)
169 matrices[i].reinit(matrix_sizes[i++]);
170
171 for (unsigned int i = 0; i < n_vectors; ++i)
172 vectors[i].reinit(vector_sizes[i++]);
173
174 for (unsigned int i = 0; i < n_dof_indices; ++i)
175 local_dof_indices[i].resize(dof_indices_sizes[i++]);
176 }
177
178
179
180 template <int n_matrices,
181 int n_vectors,
182 int n_dof_indices,
183 typename ScalarType>
184 void
186 const unsigned int size)
187 {
188 for (auto &m : matrices)
189 m.reinit({size, size});
190 for (auto &v : vectors)
191 v.reinit(size);
192 for (auto &d : local_dof_indices)
193 d.resize(size);
194 }
195
196
197
198 template <int n_matrices,
199 int n_vectors,
200 int n_dof_indices,
201 typename ScalarType>
202 void
204 const unsigned int index,
205 const unsigned int size)
206 {
207 reinit(index, size, size);
208 }
209
210
211
212 template <int n_matrices,
213 int n_vectors,
214 int n_dof_indices,
215 typename ScalarType>
216 void
218 const unsigned int index,
219 const unsigned int size_rows,
220 const unsigned int size_columns)
221 {
222 // We permit different numbers of matrices, vectors and DoF index vectors.
223 // So we have to be a bit permissive here.
224 constexpr int max_index = std::max({n_matrices, n_vectors, n_dof_indices});
225 Assert(index < max_index, ExcIndexRange(index, 0, max_index));
226
227 if (index < n_matrices)
228 matrices[index].reinit({size_rows, size_columns});
229
230 if (index < n_vectors)
231 vectors[index].reinit(size_columns);
232
233 if (index < n_dof_indices)
234 local_dof_indices[index].resize(size_columns);
235 }
236
237#endif // DOXYGEN
238} // namespace MeshWorker
239
241
242#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
std::size_t size
Definition mpi.cc:733
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
typename internal::ndarray::HelperArray< T, Ns... >::type ndarray
Definition ndarray.h:105
CopyData(const CopyData &other)=default
void reinit(const unsigned int index, const unsigned int size_rows, const unsigned int size_columns)
CopyData & operator=(const CopyData &other)=default
std::array< FullMatrix< ScalarType >, n_matrices > matrices
Definition copy_data.h:128
CopyData(const unsigned int size)
std::array< Vector< ScalarType >, n_vectors > vectors
Definition copy_data.h:133
void reinit(const unsigned int size)
void reinit(const unsigned int index, const unsigned int size)
CopyData(const ndarray< unsigned int, n_matrices, 2 > &matrix_sizes, const std::array< unsigned int, n_vectors > &vector_sizes, const std::array< unsigned int, n_dof_indices > &dof_indices_sizes)
std::array< std::vector< types::global_dof_index >, n_dof_indices > local_dof_indices
Definition copy_data.h:139