ryujin 2.1.1 revision 0348cbb53a3e4b1da2a4c037e81f88f2d21ce219
state_vector.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2024 by the ryujin authors
4//
5
6#pragma once
7
9
10#include <deal.II/lac/la_parallel_block_vector.h>
11
12namespace ryujin
13{
14#ifndef DOXYGEN
15 /* Forward declaration */
16 template <int dim, typename Number>
17 class OfflineData;
18#endif
19
25 namespace Vectors
26 {
30 template <typename Number>
31 using ScalarVector = dealii::LinearAlgebra::distributed::Vector<Number>;
32
36 template <typename Number>
37 using BlockVector = dealii::LinearAlgebra::distributed::BlockVector<Number>;
38
47 template <typename Number, unsigned int problem_dim, unsigned int prec_dim>
48 using StateVector = std::tuple<
50 MultiComponentVector<Number, prec_dim> /*precomputed values*/,
51 BlockVector<Number> /*parabolic state vector*/>;
52
53
54 template <
55 typename Description,
56 int dim,
57 typename Number,
58 typename View =
59 typename Description::template HyperbolicSystemView<dim, Number>,
60 int problem_dimension = View::problem_dimension,
61 int prec_dimension = View::n_precomputed_values>
64 [[maybe_unused]],
65 const OfflineData<dim, Number> &offline_data [[maybe_unused]])
66 {
67#ifdef DEBUG
68 auto &[U, precomputed, V] = state_vector;
69
70 const unsigned int n_owned = offline_data.n_locally_owned();
71 const auto &partitioner = offline_data.scalar_partitioner();
72
73 for (unsigned int i = 0; i < n_owned; ++i) {
74 if (!offline_data.affine_constraints().is_constrained(
75 partitioner->local_to_global(i)))
76 continue;
77 constexpr auto nan = std::numeric_limits<Number>::signaling_NaN();
78 U.write_tensor(dealii::Tensor<1, problem_dimension, Number>() * nan, i);
79 }
80#endif
81 }
82
83
84 template <
85 typename Description,
86 int dim,
87 typename Number,
88 typename View =
89 typename Description::template HyperbolicSystemView<dim, Number>,
90 int problem_dimension = View::problem_dimension,
91 int prec_dimension = View::n_precomputed_values>
94 [[maybe_unused]],
95 const OfflineData<dim, Number> &offline_data [[maybe_unused]])
96 {
97#ifdef DEBUG
98 auto &[U, precomputed, V] = state_vector;
99
100 constexpr auto nan = std::numeric_limits<Number>::signaling_NaN();
101 const unsigned int n_owned = offline_data.n_locally_owned();
102 const auto block_size = offline_data.n_parabolic_state_vectors();
103
104 for (unsigned int i = 0; i < n_owned; ++i) {
105 precomputed.write_tensor(
106 dealii::Tensor<1, prec_dimension, Number>() * nan, i);
107 for (unsigned int b = 0; b < block_size; ++b) {
108 V.block(b).local_element(i) = nan;
109 }
110 }
111#endif
112 }
113
114
119 template <
120 typename Description,
121 int dim,
122 typename Number,
123 typename View =
124 typename Description::template HyperbolicSystemView<dim, Number>,
125 int problem_dimension = View::problem_dimension,
126 int prec_dimension = View::n_precomputed_values>
129 const OfflineData<dim, Number> &offline_data)
130 {
131 auto &[U, precomputed, V] = state_vector;
132 U.reinit(offline_data.hyperbolic_vector_partitioner());
133 precomputed.reinit(offline_data.precomputed_vector_partitioner());
134
135 const auto block_size = offline_data.n_parabolic_state_vectors();
136 V.reinit(block_size);
137 for (unsigned int i = 0; i < block_size; ++i) {
138 V.block(i).reinit(offline_data.scalar_partitioner());
139 }
140
141#ifdef DEBUG
142 /* Poison all vectors: */
143 using state_type = typename View::state_type;
144
145 constexpr auto nan = std::numeric_limits<Number>::signaling_NaN();
146
147 const unsigned int n_owned = offline_data.n_locally_owned();
148 for (unsigned int i = 0; i < n_owned; ++i) {
149 U.write_tensor(state_type{} * nan, i);
150 precomputed.write_tensor(
151 dealii::Tensor<1, prec_dimension, Number>() * nan, i);
152 for (unsigned int b = 0; b < block_size; ++b) {
153 V.block(b).local_element(i) = nan;
154 }
155 }
156#endif
157 }
158 } // namespace Vectors
159
160} // namespace ryujin
auto & n_locally_owned() const
Definition: offline_data.h:173
const auto & scalar_partitioner() const
Definition: offline_data.h:128
const auto & hyperbolic_vector_partitioner() const
Definition: offline_data.h:134
const auto & precomputed_vector_partitioner() const
Definition: offline_data.h:140
auto & n_parabolic_state_vectors() const
Definition: offline_data.h:145
void reinit_state_vector(StateVector< Number, problem_dimension, prec_dimension > &state_vector, const OfflineData< dim, Number > &offline_data)
Definition: state_vector.h:127
dealii::LinearAlgebra::distributed::Vector< Number > ScalarVector
Definition: state_vector.h:31
void debug_poison_constrained_dofs(StateVector< Number, problem_dimension, prec_dimension > &state_vector, const OfflineData< dim, Number > &offline_data)
Definition: state_vector.h:62
dealii::LinearAlgebra::distributed::BlockVector< Number > BlockVector
Definition: state_vector.h:37
void debug_poison_precomputed_values(StateVector< Number, problem_dimension, prec_dimension > &state_vector, const OfflineData< dim, Number > &offline_data)
Definition: state_vector.h:92
std::tuple< MultiComponentVector< Number, problem_dim >, MultiComponentVector< Number, prec_dim >, BlockVector< Number > > StateVector
Definition: state_vector.h:51
Euler::Description Description