PRISMS-PF Manual v3.0-pre
All Classes Functions Variables Enumerations Pages
explicit_postprocess_solver.h
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#ifndef explicit_postprocess_solver_h
5#define explicit_postprocess_solver_h
6
7#include <prismspf/config.h>
8#include <prismspf/core/invm_handler.h>
9#include <prismspf/core/matrix_free_handler.h>
10#include <prismspf/solvers/explicit_constant_solver.h>
11
12#ifdef PRISMS_PF_WITH_CALIPER
13# include <caliper/cali.h>
14#endif
15
16PRISMS_PF_BEGIN_NAMESPACE
17
21template <int dim, int degree, typename number>
22class customPDE;
23
27template <int dim, int degree>
28class explicitPostprocessSolver : public explicitBase<dim, degree>
29{
30public:
32 using VectorType = dealii::LinearAlgebra::distributed::Vector<double>;
33
38 const matrixfreeHandler<dim> &_matrix_free_handler,
39 const invmHandler<dim, degree> &_invm_handler,
40 const constraintHandler<dim> &_constraint_handler,
41 const dofHandler<dim> &_dof_handler,
42 const dealii::MappingQ1<dim> &_mapping,
43 solutionHandler<dim> &_solution_handler);
44
49
53 void
54 init() override;
55
59 void
60 solve() override;
61
62private:
66 std::unordered_map<std::pair<unsigned int, dependencyType>, unsigned int, pairHash>
67 global_to_local_solution;
68
72 std::vector<VectorType *> solution_subset;
73
77 std::vector<VectorType *> new_solution_subset;
78};
79
80template <int dim, int degree>
82 const userInputParameters<dim> &_user_inputs,
83 const matrixfreeHandler<dim> &_matrix_free_handler,
84 const invmHandler<dim, degree> &_invm_handler,
85 const constraintHandler<dim> &_constraint_handler,
86 const dofHandler<dim> &_dof_handler,
87 const dealii::MappingQ1<dim> &_mapping,
88 solutionHandler<dim> &_solution_handler)
89 : explicitBase<dim, degree>(_user_inputs,
90 _matrix_free_handler,
91 _invm_handler,
92 _constraint_handler,
93 _dof_handler,
94 _mapping,
95 _solution_handler)
96{}
97
98template <int dim, int degree>
99inline void
101{
102 this->compute_subset_attributes(fieldSolveType::EXPLICIT_POSTPROCESS);
103
104 // If the subset attribute is empty return early
105 if (this->subset_attributes.empty())
106 {
107 return;
108 }
109
110 this->compute_shared_dependencies();
111
112 // Create the implementation of customPDE with the subset of variable attributes
113 this->system_matrix =
114 std::make_unique<SystemMatrixType>(this->user_inputs, this->subset_attributes);
115
116 // Set up the user-implemented equations and create the residual vectors
117 this->system_matrix->clear();
118 this->system_matrix->initialize(this->matrix_free_handler.get_matrix_free());
119
120 // Create the subset of solution vectors and add the mapping to customPDE
121 for (const auto &[index, map] :
122 this->subset_attributes.begin()->second.dependency_set_RHS)
123 {
124 for (const auto &[dependency_type, field_type] : map)
125 {
126 const auto pair = std::make_pair(index, dependency_type);
127
128 Assert(this->solution_handler.solution_set.find(pair) !=
129 this->solution_handler.solution_set.end(),
130 dealii::ExcMessage("There is no solution vector for the given index = " +
131 std::to_string(index) +
132 " and type = " + to_string(dependency_type)));
133
134 Assert(this->solution_handler.new_solution_set.find(index) !=
135 this->solution_handler.new_solution_set.end(),
136 dealii::ExcMessage(
137 "There is no new solution vector for the given index = " +
138 std::to_string(index)));
139
140 solution_subset.push_back(this->solution_handler.solution_set.at(pair));
141 new_solution_subset.push_back(
142 this->solution_handler.new_solution_set.at(index));
143 global_to_local_solution.emplace(pair, solution_subset.size() - 1);
144 }
145 }
146
147 this->system_matrix->add_global_to_local_mapping(global_to_local_solution);
148}
149
150template <int dim, int degree>
151inline void
153{
154 // If the subset attribute is empty return early
155 if (this->subset_attributes.empty())
156 {
157 return;
158 }
159
160 // Compute the postprocessed fields
161 this->system_matrix->compute_postprocess_explicit_update(new_solution_subset,
162 solution_subset);
163
164 // Scale the update by the respective (SCALAR/VECTOR) invm. Note that we do this with
165 // the original solution set to avoid some messy mapping.
166 for (auto [index, vector] : this->solution_handler.new_solution_set)
167 {
168 if (this->subset_attributes.find(index) != this->subset_attributes.end())
169 {
170 vector->scale(this->invm_handler.get_invm(index));
171 }
172 }
173
174 // Update the solutions
175 this->solution_handler.update(fieldSolveType::EXPLICIT_POSTPROCESS);
176}
177
178PRISMS_PF_END_NAMESPACE
179
180#endif
The class handles the generation and application of boundary conditions based on the user-inputs.
Definition constraint_handler.h:25
Definition explicit_base.h:27
Class that manages the deal.II DoFHandlers.
Definition dof_handler.h:25
Base class for explicit solves.
Definition explicit_base.h:34
This class handles the explicit solves of all postprocessed fields.
Definition explicit_postprocess_solver.h:29
~explicitPostprocessSolver()=default
Destructor.
void solve() override
Solve a single update step.
Definition explicit_postprocess_solver.h:152
explicitPostprocessSolver(const userInputParameters< dim > &_user_inputs, const matrixfreeHandler< dim > &_matrix_free_handler, const invmHandler< dim, degree > &_invm_handler, const constraintHandler< dim > &_constraint_handler, const dofHandler< dim > &_dof_handler, const dealii::MappingQ1< dim > &_mapping, solutionHandler< dim > &_solution_handler)
Constructor.
Definition explicit_postprocess_solver.h:81
void init() override
Initialize system.
Definition explicit_postprocess_solver.h:100
This class handles the computation and access of the inverted mass matrix for explicit solves.
Definition invm_handler.h:25
This class handlers the management and access of the matrix-free objects.
Definition matrix_free_handler.h:25
Class that manages solution initialization and swapping with old solutions.
Definition solution_handler.h:22
Definition user_input_parameters.h:22
Simple hash function for pairs.
Definition variable_attributes.h:24