Reference documentation for deal.II version GIT relicensing-245-g36f19064f7 2024-03-29 07:20: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
copy_data.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2023 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_meshworker_copy_data_h
16#define dealii_meshworker_copy_data_h
17
18#include <deal.II/base/config.h>
19
21#include <deal.II/base/types.h>
22
24#include <deal.II/lac/vector.h>
25
26#include <vector>
27
29
30namespace MeshWorker
31{
49 template <int n_matrices = 1,
50 int n_vectors = n_matrices,
51 int n_dof_indices = n_matrices,
52 typename ScalarType = double>
53 struct CopyData
54 {
60 CopyData() = default;
61
66 explicit CopyData(const unsigned int size);
67
71 explicit CopyData(
72 const ndarray<unsigned int, n_matrices, 2> &matrix_sizes,
73 const std::array<unsigned int, n_vectors> &vector_sizes,
74 const std::array<unsigned int, n_dof_indices> &dof_indices_sizes);
75
79 CopyData(const CopyData &other) = default;
80
84 CopyData &
85 operator=(const CopyData &other) = default;
86
91 void
92 reinit(const unsigned int size);
93
105 void
106 reinit(const unsigned int index, const unsigned int size);
107
121 void
122 reinit(const unsigned int index,
123 const unsigned int size_rows,
124 const unsigned int size_columns);
125
129 std::array<FullMatrix<ScalarType>, n_matrices> matrices;
130
134 std::array<Vector<ScalarType>, n_vectors> vectors;
135
139 std::array<std::vector<types::global_dof_index>, n_dof_indices>
141 };
142
143
144#ifndef DOXYGEN
145 //
146 // Template definitions
147 //
148 template <int n_matrices,
149 int n_vectors,
150 int n_dof_indices,
151 typename ScalarType>
153 const unsigned int size)
154 {
155 reinit(size);
156 }
157
158
159
160 template <int n_matrices,
161 int n_vectors,
162 int n_dof_indices,
163 typename ScalarType>
165 const ndarray<unsigned int, n_matrices, 2> &matrix_sizes,
166 const std::array<unsigned int, n_vectors> &vector_sizes,
167 const std::array<unsigned int, n_dof_indices> &dof_indices_sizes)
168 {
169 for (unsigned int i = 0; i < n_matrices; ++i)
170 matrices[i].reinit(matrix_sizes[i++]);
171
172 for (unsigned int i = 0; i < n_vectors; ++i)
173 vectors[i].reinit(vector_sizes[i++]);
174
175 for (unsigned int i = 0; i < n_dof_indices; ++i)
176 local_dof_indices[i].resize(dof_indices_sizes[i++]);
177 }
178
179
180
181 template <int n_matrices,
182 int n_vectors,
183 int n_dof_indices,
184 typename ScalarType>
185 void
187 const unsigned int size)
188 {
189 for (auto &m : matrices)
190 m.reinit({size, size});
191 for (auto &v : vectors)
192 v.reinit(size);
193 for (auto &d : local_dof_indices)
194 d.resize(size);
195 }
196
197
198
199 template <int n_matrices,
200 int n_vectors,
201 int n_dof_indices,
202 typename ScalarType>
203 void
205 const unsigned int index,
206 const unsigned int size)
207 {
208 reinit(index, size, size);
209 }
210
211
212
213 template <int n_matrices,
214 int n_vectors,
215 int n_dof_indices,
216 typename ScalarType>
217 void
219 const unsigned int index,
220 const unsigned int size_rows,
221 const unsigned int size_columns)
222 {
223 // We permit different numbers of matrices, vectors and DoF index vectors.
224 // So we have to be a bit permissive here.
225 constexpr const int max_index =
226 std::max(std::max(n_matrices, n_vectors), n_dof_indices);
227 (void)max_index;
228 Assert(index < max_index, ExcIndexRange(index, 0, max_index));
229
230 if (index < n_matrices)
231 matrices[index].reinit({size_rows, size_columns});
232
233 if (index < n_vectors)
234 vectors[index].reinit(size_columns);
235
236 if (index < n_dof_indices)
237 local_dof_indices[index].resize(size_columns);
238 }
239
240#endif // DOXYGEN
241} // namespace MeshWorker
242
244
245#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define Assert(cond, exc)
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
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:107
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:129
CopyData(const unsigned int size)
std::array< Vector< ScalarType >, n_vectors > vectors
Definition copy_data.h:134
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:140