PRISMS-PF Manual v3.0-pre
All Classes Functions Variables Enumerations Pages
explicit_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_solver_h
5#define explicit_solver_h
6
7#include <prismspf/config.h>
8#include <prismspf/core/constraint_handler.h>
9#include <prismspf/core/dof_handler.h>
10#include <prismspf/core/invm_handler.h>
11#include <prismspf/core/matrix_free_handler.h>
12#include <prismspf/core/solution_handler.h>
13#include <prismspf/core/type_enums.h>
14#include <prismspf/solvers/explicit_base.h>
15#include <prismspf/user_inputs/user_input_parameters.h>
16
17#ifdef PRISMS_PF_WITH_CALIPER
18# include <caliper/cali.h>
19#endif
20
21PRISMS_PF_BEGIN_NAMESPACE
22
26template <int dim, int degree, typename number>
27class customPDE;
28
32template <int dim, int degree>
33class explicitSolver : public explicitBase<dim, degree>
34{
35public:
37 using VectorType = dealii::LinearAlgebra::distributed::Vector<double>;
38
42 explicitSolver(const userInputParameters<dim> &_user_inputs,
43 const matrixfreeHandler<dim> &_matrix_free_handler,
44 const invmHandler<dim, degree> &_invm_handler,
45 const constraintHandler<dim> &_constraint_handler,
46 const dofHandler<dim> &_dof_handler,
47 const dealii::MappingQ1<dim> &_mapping,
48 solutionHandler<dim> &_solution_handler);
49
53 ~explicitSolver() = default;
54
58 void
59 init() override;
60
64 void
65 solve() override;
66
67private:
71 std::unordered_map<std::pair<unsigned int, dependencyType>, unsigned int, pairHash>
72 global_to_local_solution;
73
77 std::vector<VectorType *> solution_subset;
78
82 std::vector<VectorType *> new_solution_subset;
83};
84
85template <int dim, int degree>
87 const userInputParameters<dim> &_user_inputs,
88 const matrixfreeHandler<dim> &_matrix_free_handler,
89 const invmHandler<dim, degree> &_invm_handler,
90 const constraintHandler<dim> &_constraint_handler,
91 const dofHandler<dim> &_dof_handler,
92 const dealii::MappingQ1<dim> &_mapping,
93 solutionHandler<dim> &_solution_handler)
94 : explicitBase<dim, degree>(_user_inputs,
95 _matrix_free_handler,
96 _invm_handler,
97 _constraint_handler,
98 _dof_handler,
99 _mapping,
100 _solution_handler)
101{}
102
103template <int dim, int degree>
104inline void
106{
107 this->compute_subset_attributes(fieldSolveType::EXPLICIT);
108
109 // If the subset attribute is empty return early
110 if (this->subset_attributes.empty())
111 {
112 return;
113 }
114
115 this->compute_shared_dependencies();
116
117 // Create the implementation of customPDE with the subset of variable attributes
118 this->system_matrix =
119 std::make_unique<SystemMatrixType>(this->user_inputs, this->subset_attributes);
120
121 // Set the initial conditions
122 this->set_initial_condition();
123
124 // Apply constraints
125 for (auto &[pair, vector] : this->solution_handler.solution_set)
126 {
127 if (this->subset_attributes.find(pair.first) == this->subset_attributes.end())
128 {
129 continue;
130 }
131 this->constraint_handler.get_constraint(pair.first).distribute(*vector);
132 }
133
134 // Set up the user-implemented equations and create the residual vectors
135 this->system_matrix->clear();
136 this->system_matrix->initialize(this->matrix_free_handler.get_matrix_free());
137
138 // Create the subset of solution vectors and add the mapping to customPDE
139 for (const auto &[index, map] :
140 this->subset_attributes.begin()->second.dependency_set_RHS)
141 {
142 for (const auto &[dependency_type, field_type] : map)
143 {
144 const auto pair = std::make_pair(index, dependency_type);
145
146 Assert(this->solution_handler.solution_set.find(pair) !=
147 this->solution_handler.solution_set.end(),
148 dealii::ExcMessage("There is no solution vector for the given index = " +
149 std::to_string(index) +
150 " and type = " + to_string(dependency_type)));
151
152 Assert(this->solution_handler.new_solution_set.find(index) !=
153 this->solution_handler.new_solution_set.end(),
154 dealii::ExcMessage(
155 "There is no new solution vector for the given index = " +
156 std::to_string(index)));
157
158 solution_subset.push_back(this->solution_handler.solution_set.at(pair));
159 new_solution_subset.push_back(
160 this->solution_handler.new_solution_set.at(index));
161 global_to_local_solution.emplace(pair, solution_subset.size() - 1);
162 }
163 }
164 this->system_matrix->add_global_to_local_mapping(global_to_local_solution);
165}
166
167template <int dim, int degree>
168inline void
170{
171 // If the subset attribute is empty return early
172 if (this->subset_attributes.empty())
173 {
174 return;
175 }
176
177 // Compute the update
178 this->system_matrix->compute_explicit_update(new_solution_subset, solution_subset);
179
180 // Scale the update by the respective (SCALAR/VECTOR) invm. Note that we do this with
181 // the original solution set to avoid some messy mapping.
182 for (auto [index, vector] : this->solution_handler.new_solution_set)
183 {
184 if (this->subset_attributes.find(index) != this->subset_attributes.end())
185 {
186 vector->scale(this->invm_handler.get_invm(index));
187 }
188 }
189
190 // Update the solutions
191 this->solution_handler.update(fieldSolveType::EXPLICIT);
192
193 // Apply constraints
194 for (auto &[pair, vector] : this->solution_handler.solution_set)
195 {
196 if (this->subset_attributes.find(pair.first) == this->subset_attributes.end())
197 {
198 continue;
199 }
200 this->constraint_handler.get_constraint(pair.first).distribute(*vector);
201 }
202}
203
204PRISMS_PF_END_NAMESPACE
205
206#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 explicit fields.
Definition explicit_solver.h:34
void solve() override
Solve a single update step.
Definition explicit_solver.h:169
explicitSolver(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_solver.h:86
~explicitSolver()=default
Destructor.
void init() override
Initialize system.
Definition explicit_solver.h:105
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