Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
copy_data.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_meshworker_copy_data_h
17 #define dealii_meshworker_copy_data_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/types.h>
22 
23 #include <deal.II/lac/full_matrix.h>
24 #include <deal.II/lac/vector.h>
25 
26 #include <vector>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 namespace MeshWorker
31 {
49  template <int n_matrices = 1,
50  int n_vectors = n_matrices,
51  int n_dof_indices = n_matrices>
52  struct CopyData
53  {
58  CopyData(const unsigned int size);
59 
63  CopyData(
64  const std::array<std::array<unsigned int, 2>, n_matrices> &matrix_sizes,
65  const std::array<unsigned int, n_vectors> & vector_sizes,
66  const std::array<unsigned int, n_dof_indices> &dof_indices_sizes);
67 
72  default;
73 
84  void
85  operator=(const double &number);
86 
90  std::array<FullMatrix<double>, n_matrices> matrices;
91 
95  std::array<Vector<double>, n_vectors> vectors;
96 
100  std::array<std::vector<types::global_dof_index>, n_dof_indices>
102  };
103 
104 
105 #ifndef DOXYGEN
106  //
107  // Template definitions
108  //
109  template <int n_matrices, int n_vectors, int n_dof_indices>
111  const unsigned int size)
112  {
113  for (auto &m : matrices)
114  m.reinit({size, size});
115  for (auto &v : vectors)
116  v.reinit(size);
117  for (auto &d : local_dof_indices)
118  d.resize(size);
119  }
120 
121 
122 
123  template <int n_matrices, int n_vectors, int n_dof_indices>
125  const std::array<std::array<unsigned int, 2>, n_matrices> &matrix_sizes,
126  const std::array<unsigned int, n_vectors> & vector_sizes,
127  const std::array<unsigned int, n_dof_indices> &dof_indices_sizes)
128  {
129  for (unsigned int i = 0; i < n_matrices; ++i)
130  matrices[i].reinit(matrix_sizes[i++]);
131 
132  for (unsigned int i = 0; i < n_vectors; ++i)
133  vectors[i].reinit(vector_sizes[i++]);
134 
135  for (unsigned int i = 0; i < n_dof_indices; ++i)
136  local_dof_indices[i].resize(dof_indices_sizes[i++]);
137  }
138 
139 
140 
141  template <int n_matrices, int n_vectors, int n_dof_indices>
142  void
144  operator=(const double &number)
145  {
146  Assert(number == 0.0,
147  ExcMessage("You should only call this method with "
148  "argument 0.0"));
149 
150  for (auto &m : matrices)
151  m = number;
152  for (auto &v : vectors)
153  v = number;
154  for (auto &d : local_dof_indices)
155  for (auto &val : d)
157  }
158 
159 #endif // DOXYGEN
160 } // namespace MeshWorker
161 
162 DEAL_II_NAMESPACE_CLOSE
163 
164 #endif
CopyData(const unsigned int size)
std::array< FullMatrix< double >, n_matrices > matrices
Definition: copy_data.h:90
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1407
void operator=(const double &number)
std::array< std::vector< types::global_dof_index >, n_dof_indices > local_dof_indices
Definition: copy_data.h:101
const types::global_dof_index invalid_dof_index
Definition: types.h:188
std::array< Vector< double >, n_vectors > vectors
Definition: copy_data.h:95