PRISMS-PF Manual
Loading...
Searching...
No Matches
group_solution_handler.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5
6#include <deal.II/distributed/solution_transfer.h>
7#include <deal.II/lac/affine_constraints.h>
8#include <deal.II/lac/la_parallel_block_vector.h>
9#include <deal.II/lac/la_parallel_vector.h>
10#include <deal.II/matrix_free/matrix_free.h>
11
17#include <prismspf/core/types.h>
18
19#include <prismspf/config.h>
20
21#include <vector>
22
24
28template <typename number>
29using BlockVector = dealii::LinearAlgebra::distributed::BlockVector<number>;
30
34template <typename number>
36
40using dealii::MatrixFree;
41
56template <unsigned int dim, typename number>
58{
60 std::vector<BlockVector<number>> old_solutions;
61};
62
66template <unsigned int dim, typename number>
68{
69public:
70#if DEAL_II_VERSION_MAJOR >= 9 && DEAL_II_VERSION_MINOR >= 7
71 using SolutionTransfer = dealii::SolutionTransfer<dim, SolutionVector<number>>;
72#else
74 dealii::parallel::distributed::SolutionTransfer<dim, SolutionVector<number>>;
75#endif
76
81 const std::vector<FieldAttributes> &_attributes_list,
82 const std::vector<MatrixFree<dim, number>> &_matrix_free_levels);
83
88 [[nodiscard]] BlockVector<number> &
89 get_solution_full_vector(unsigned int relative_level = 0);
90
95 [[nodiscard]] const BlockVector<number> &
96 get_solution_full_vector(unsigned int relative_level = 0) const;
97
101 [[nodiscard]] SolutionVector<number> &
102 get_solution_vector(unsigned int global_index, unsigned int relative_level = 0);
103
107 [[nodiscard]] const SolutionVector<number> &
108 get_solution_vector(unsigned int global_index, unsigned int relative_level = 0) const;
109
113 [[nodiscard]] BlockVector<number> &
114 get_old_solution_full_vector(unsigned int age, unsigned int relative_level = 0);
115
119 [[nodiscard]] const BlockVector<number> &
120 get_old_solution_full_vector(unsigned int age, unsigned int relative_level = 0) const;
121
125 [[nodiscard]] SolutionVector<number> &
126 get_old_solution_vector(unsigned int age,
127 unsigned int global_index,
128 unsigned int relative_level = 0);
129
133 [[nodiscard]] const SolutionVector<number> &
134 get_old_solution_vector(unsigned int age,
135 unsigned int global_index,
136 unsigned int relative_level = 0) const;
137
141 [[nodiscard]] SolutionLevel<dim, number> &
142 get_solution_level(unsigned int relative_level = 0);
143
147 [[nodiscard]] const SolutionLevel<dim, number> &
148 get_solution_level(unsigned int relative_level = 0) const;
149
153 const std::vector<MatrixFree<dim, number>> &
155
159 [[nodiscard]] unsigned int
160 get_block_index(unsigned int global_index) const;
161
165 [[nodiscard]] const SolveBlock &
166 get_solve_block() const;
167
171 [[nodiscard]] const std::vector<unsigned int> &
173
177 [[nodiscard]] const std::vector<unsigned int> &
179
184 void
185 init(unsigned int num_old_saved);
186
191 void
192 reinit();
193
197 void
198 update_ghosts(unsigned int relative_level = 0) const;
199
203 void
204 zero_out_ghosts(unsigned int relative_level = 0) const;
205
209 void
210 apply_constraints(unsigned int relative_level = 0);
211
215 void
216 apply_constraints(BlockVector<number> &solution_vector,
217 unsigned int relative_level = 0);
218
222 void
223 apply_constraints_to_all(unsigned int relative_level);
224
229 void
231
235 void
236 update(unsigned int relative_level = 0);
237
241 void
243
247 void
249
253 void
255
259 void
260 print_solution_full_vector(std::ostream &out, unsigned int relative_level = 0) const;
261
262private:
267
271 std::vector<unsigned int> block_to_global_index;
272
276 std::vector<unsigned int> global_to_block_index;
277
281 std::vector<SolutionLevel<dim, number>> solution_levels;
282
286 const std::vector<MatrixFree<dim, number>> *matrix_free_levels = nullptr;
287
296 std::vector<SolutionTransfer> block_solution_transfer;
297};
298
299PRISMS_PF_END_NAMESPACE
void init(unsigned int num_old_saved)
Initialize the solution set.
Definition group_solution_handler.cc:168
const std::vector< MatrixFree< dim, number > > * matrix_free_levels
Pointer to MatrixFree of each level.
Definition group_solution_handler.h:286
void apply_constraints_to_all(unsigned int relative_level)
Apply the given constraints to all the solution vectors, including old.
Definition group_solution_handler.cc:306
SolutionVector< number > & get_solution_vector(unsigned int global_index, unsigned int relative_level=0)
Get a solution vector of a given field index.
Definition group_solution_handler.cc:56
BlockVector< number > & get_old_solution_full_vector(unsigned int age, unsigned int relative_level=0)
Get the old solution vector set at a given age.
Definition group_solution_handler.cc:76
void reinit()
Reinitialize the solution set.
Definition group_solution_handler.cc:197
void update(unsigned int relative_level=0)
Update and propagate the old solutions.
Definition group_solution_handler.cc:364
std::vector< SolutionLevel< dim, number > > solution_levels
Solutions of each level.
Definition group_solution_handler.h:281
std::vector< unsigned int > block_to_global_index
Mapping from block index to global field index.
Definition group_solution_handler.h:271
SolutionLevel< dim, number > & get_solution_level(unsigned int relative_level=0)
Get the solutions object at a level.
Definition group_solution_handler.cc:116
std::vector< unsigned int > global_to_block_index
Mapping from global field index to block index.
Definition group_solution_handler.h:276
const SolveBlock & get_solve_block() const
Get the underlying solve block object.
Definition group_solution_handler.cc:145
void update_ghosts(unsigned int relative_level=0) const
Update the ghost values.
Definition group_solution_handler.cc:287
void prepare_for_solution_transfer()
Prepare for solution transfer.
Definition group_solution_handler.cc:244
const std::vector< unsigned int > & get_block_to_global_index() const
Get the global index from the block index.
Definition group_solution_handler.cc:159
const std::vector< MatrixFree< dim, number > > & get_matrix_free_levels() const
Get the underlying matrix_free objects.
Definition group_solution_handler.cc:130
void apply_initial_condition_for_old_fields()
Apply initial condition to the old fields. For now, this simply copies the values in the normal field...
Definition group_solution_handler.cc:348
BlockVector< number > & get_solution_full_vector(unsigned int relative_level=0)
Get the solution vector set. This contains all the normal fields and is typically used for output.
Definition group_solution_handler.cc:40
void zero_out_ghosts(unsigned int relative_level=0) const
Zero out the ghost values.
Definition group_solution_handler.cc:299
void execute_solution_transfer()
Transfer solutions.
Definition group_solution_handler.cc:264
void apply_constraints(unsigned int relative_level=0)
Apply the constraints to the solution vector.
Definition group_solution_handler.cc:325
void init_solution_transfer()
Reinit the solution transfer objections.
Definition group_solution_handler.cc:230
SolveBlock solve_block
Information about the solve block this handler is responsible for.
Definition group_solution_handler.h:266
dealii::parallel::distributed::SolutionTransfer< dim, SolutionVector< number > > SolutionTransfer
Definition group_solution_handler.h:73
SolutionVector< number > & get_old_solution_vector(unsigned int age, unsigned int global_index, unsigned int relative_level=0)
Get a solution vector of a given field index at a given age.
Definition group_solution_handler.cc:94
GroupSolutionHandler(SolveBlock _solve_block, const std::vector< FieldAttributes > &_attributes_list, const std::vector< MatrixFree< dim, number > > &_matrix_free_levels)
Constructor.
Definition group_solution_handler.cc:21
void print_solution_full_vector(std::ostream &out, unsigned int relative_level=0) const
Print the solution vector set.
Definition group_solution_handler.cc:385
std::vector< SolutionTransfer > block_solution_transfer
Utility for solution transfer to different mesh (for AMR). Can only work on one block at a time.
Definition group_solution_handler.h:296
const std::vector< unsigned int > & get_global_to_block_index() const
Get the block index from the global index.
Definition group_solution_handler.cc:152
unsigned int get_block_index(unsigned int global_index) const
Get the block index from the global field index.
Definition group_solution_handler.cc:138
Structure to hold the attributes of a solve-block.
Definition solve_block.h:59
typename BlockVector< number >::BlockType SolutionVector
Typedef for solution vector.
Definition group_solution_handler.h:35
dealii::LinearAlgebra::distributed::BlockVector< number > BlockVector
Typedef for solution block vector.
Definition group_solution_handler.h:29
Definition conditional_ostreams.cc:20
The solution vectors with respect to on some multigrid level.
Definition group_solution_handler.h:58
std::vector< BlockVector< number > > old_solutions
Definition group_solution_handler.h:60
BlockVector< number > solutions
Definition group_solution_handler.h:59