PRISMS-PF Manual v3.0-pre
All Classes Functions Variables Enumerations Pages
nonexplicit_base.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 nonexplicit_base_h
5#define nonexplicit_base_h
6
7#include <deal.II/numerics/vector_tools.h>
8
9#include <prismspf/config.h>
10#include <prismspf/core/constraint_handler.h>
11#include <prismspf/core/dof_handler.h>
12#include <prismspf/core/exceptions.h>
13#include <prismspf/core/initial_conditions.h>
14#include <prismspf/core/invm_handler.h>
15#include <prismspf/core/matrix_free_handler.h>
16#include <prismspf/core/solution_handler.h>
17#include <prismspf/core/triangulation_handler.h>
18#include <prismspf/core/type_enums.h>
19#include <prismspf/core/variable_attributes.h>
20#include <prismspf/user_inputs/user_input_parameters.h>
21
22PRISMS_PF_BEGIN_NAMESPACE
23
27template <int dim, int degree, typename number>
28class customPDE;
29
33template <int dim, int degree>
35{
36public:
38
43 const userInputParameters<dim> &_user_inputs,
44 const matrixfreeHandler<dim> &_matrix_free_handler,
45 const triangulationHandler<dim> &_triangulation_handler,
46 const invmHandler<dim, degree> &_invm_handler,
47 const constraintHandler<dim> &_constraint_handler,
48 const dofHandler<dim> &_dof_handler,
49 const dealii::MappingQ1<dim> &_mapping,
50 dealii::MGLevelObject<matrixfreeHandler<dim, float>> &_mg_matrix_free_handler,
51 solutionHandler<dim> &_solution_handler);
52
56 ~nonexplicitBase() = default;
57
61 virtual void
62 init() = 0;
63
67 virtual void
68 solve() = 0;
69
70protected:
77 void
78 compute_subset_attributes(const fieldSolveType &field_solve_type);
79
86 void
88
93 void
95
99 void
100 print();
101
106
111
116
121
126
131
135 const dealii::MappingQ1<dim> &mapping;
136
140 dealii::MGLevelObject<matrixfreeHandler<dim, float>> &mg_matrix_free_handler;
141
146
150 std::map<unsigned int, variableAttributes> subset_attributes;
151
155 std::map<unsigned int, std::unique_ptr<SystemMatrixType>> system_matrix;
156
160 std::map<unsigned int, std::unique_ptr<SystemMatrixType>> update_system_matrix;
161};
162
163template <int dim, int degree>
165 const userInputParameters<dim> &_user_inputs,
166 const matrixfreeHandler<dim> &_matrix_free_handler,
167 const triangulationHandler<dim> &_triangulation_handler,
168 const invmHandler<dim, degree> &_invm_handler,
169 const constraintHandler<dim> &_constraint_handler,
170 const dofHandler<dim> &_dof_handler,
171 const dealii::MappingQ1<dim> &_mapping,
172 dealii::MGLevelObject<matrixfreeHandler<dim, float>> &_mg_matrix_free_handler,
173 solutionHandler<dim> &_solution_handler)
174 : user_inputs(_user_inputs)
175 , matrix_free_handler(_matrix_free_handler)
176 , triangulation_handler(_triangulation_handler)
177 , invm_handler(_invm_handler)
178 , constraint_handler(_constraint_handler)
179 , dof_handler(_dof_handler)
180 , mapping(_mapping)
181 , mg_matrix_free_handler(_mg_matrix_free_handler)
182 , solution_handler(_solution_handler)
183{}
184
185template <int dim, int degree>
186inline void
188 const fieldSolveType &field_solve_type)
189{
190 Assert((field_solve_type == fieldSolveType::NONEXPLICIT_LINEAR ||
191 field_solve_type == fieldSolveType::NONEXPLICIT_SELF_NONLINEAR ||
192 field_solve_type == fieldSolveType::NONEXPLICIT_AUXILIARY ||
193 field_solve_type == fieldSolveType::NONEXPLICIT_CO_NONLINEAR),
194 dealii::ExcMessage(
195 "compute_subset_attributes() should only be used for "
196 "NONEXPLICIT_LINEAR, NONEXPLICIT_SELF_NONLINEAR, NONEXPLICIT_AUXILIARY, and "
197 "NONEXPLICIT_CO_NONLINEAR fieldSolveTypes"));
198
199 subset_attributes.clear();
200
201 for (const auto &[index, variable] : user_inputs.var_attributes)
202 {
203 if (variable.field_solve_type == field_solve_type)
204 {
205 subset_attributes.emplace(index, variable);
206 }
207 }
208}
209
210template <int dim, int degree>
211inline void
213{
214 Assert(subset_attributes.begin()->second.field_solve_type ==
215 fieldSolveType::NONEXPLICIT_CO_NONLINEAR,
216 dealii::ExcMessage("compute_shared_dependencies() should only be used for "
217 "NONEXPLICIT_CO_NONLINEAR fieldSolveTypes"));
218
219 // Compute the shared dependency flags
220 auto &dependency_flag_set = subset_attributes.begin()->second.eval_flag_set_RHS;
221 for (const auto &[index, variable] : subset_attributes)
222 {
223 if (!variable.eval_flag_set_RHS.empty())
224 {
225 for (const auto &[pair, flag] : variable.eval_flag_set_RHS)
226 {
227 dependency_flag_set[pair] |= flag;
228 }
229 }
230 }
231 for (auto &[index, variable] : subset_attributes)
232 {
233 for (const auto &[pair, flag] : dependency_flag_set)
234 {
235 variable.eval_flag_set_RHS[pair] |= flag;
236 }
237 }
238
239 // Compute the shared dependency set
240 auto &dependency_set = subset_attributes.begin()->second.dependency_set_RHS;
241 for (const auto &[index, variable] : subset_attributes)
242 {
243 for (const auto &[index, map] : variable.dependency_set_RHS)
244 {
245 for (const auto &[dependency_type, field_type] : map)
246 {
247 dependency_set[index].emplace(dependency_type, field_type);
248 }
249 }
250 }
251 for (auto &[index, variable] : subset_attributes)
252 {
253 variable.dependency_set_RHS = dependency_set;
254 }
255
256#ifdef DEBUG
257 print();
258#endif
259}
260
261template <int dim, int degree>
262inline void
264{
265 for (const auto &[index, variable] : subset_attributes)
266 {
267 if (variable.pde_type != PDEType::IMPLICIT_TIME_DEPENDENT &&
268 variable.pde_type != PDEType::TIME_INDEPENDENT)
269 {
270 continue;
271 }
272
273 Assert(dof_handler.get_dof_handlers().size() > index,
274 dealii::ExcMessage(
275 "The const DoFHandler set is smaller than the given index = " +
276 std::to_string(index)));
277 Assert(subset_attributes.find(index) != subset_attributes.end(),
278 dealii::ExcMessage(
279 "There is no entry in the attribute subset for the given index = " +
280 std::to_string(index)));
281 Assert(solution_handler.solution_set.find(
282 std::make_pair(index, dependencyType::NORMAL)) !=
283 solution_handler.solution_set.end(),
284 dealii::ExcMessage("There is no solution vector for the given index = " +
285 std::to_string(index) +
286 " and type = " + to_string(dependencyType::NORMAL)));
287
288 dealii::VectorTools::interpolate(
289 mapping,
290 *(dof_handler.get_dof_handlers().at(index)),
291 initialCondition<dim>(index, subset_attributes.at(index).field_type, user_inputs),
292 *(solution_handler.solution_set.at(
293 std::make_pair(index, dependencyType::NORMAL))));
294
295 // TODO (landinjm): Fix so that we apply some sort of initial condition to all old
296 // vector for all types.
297 if (solution_handler.solution_set.find(
298 std::make_pair(index, dependencyType::OLD_1)) !=
299 solution_handler.solution_set.end())
300 {
301 *(solution_handler.solution_set.at(
302 std::make_pair(index, dependencyType::OLD_1))) =
303 *(solution_handler.solution_set.at(
304 std::make_pair(index, dependencyType::NORMAL)));
305 }
306 }
307}
308
309template <int dim, int degree>
310inline void
312{
314 << " ==============================================\n"
315 << " Shared dependency set\n"
316 << " ==============================================\n";
317 const auto &dependency_set = subset_attributes.begin()->second.dependency_set_RHS;
318 for (const auto &[index, map] : dependency_set)
319 {
320 for (const auto &[dependency_type, field_type] : map)
321 {
323 << " Index: " << index << " Dependency: " << to_string(dependency_type)
324 << " Field: " << to_string(field_type) << "\n";
325 }
326 }
327 conditionalOStreams::pout_summary() << "\n" << std::flush;
328}
329
330PRISMS_PF_END_NAMESPACE
331
332#endif
static dealii::ConditionalOStream & pout_summary()
Log output stream for writing a summary.log file.
Definition conditional_ostreams.cc:22
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
Function for user-implemented initial conditions. These are only ever calculated for explicit time de...
Definition initial_conditions.h:30
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
Base class for nonexplicit solves.
Definition nonexplicit_base.h:35
void print()
Print dependency_set_RHS to summary.log.
Definition nonexplicit_base.h:311
const constraintHandler< dim > & constraint_handler
Constraint handler.
Definition nonexplicit_base.h:125
virtual void init()=0
Initialize system.
std::map< unsigned int, std::unique_ptr< SystemMatrixType > > system_matrix
PDE operator for the residual side.
Definition nonexplicit_base.h:155
~nonexplicitBase()=default
Destructor.
void compute_shared_dependencies()
Compute the shared dependency set and copy it to all eval_flag_set_RHS. Also do something similar wit...
Definition nonexplicit_base.h:212
std::map< unsigned int, variableAttributes > subset_attributes
Subset of variable attributes for fields.
Definition nonexplicit_base.h:150
const dealii::MappingQ1< dim > & mapping
Mappings to and from reference cell.
Definition nonexplicit_base.h:135
nonexplicitBase(const userInputParameters< dim > &_user_inputs, const matrixfreeHandler< dim > &_matrix_free_handler, const triangulationHandler< dim > &_triangulation_handler, const invmHandler< dim, degree > &_invm_handler, const constraintHandler< dim > &_constraint_handler, const dofHandler< dim > &_dof_handler, const dealii::MappingQ1< dim > &_mapping, dealii::MGLevelObject< matrixfreeHandler< dim, float > > &_mg_matrix_free_handler, solutionHandler< dim > &_solution_handler)
Constructor.
Definition nonexplicit_base.h:164
const userInputParameters< dim > & user_inputs
User-inputs.
Definition nonexplicit_base.h:105
std::map< unsigned int, std::unique_ptr< SystemMatrixType > > update_system_matrix
PDE operator for the newton update side.
Definition nonexplicit_base.h:160
const dofHandler< dim > & dof_handler
DoF handler.
Definition nonexplicit_base.h:130
virtual void solve()=0
Solve a single update step.
const matrixfreeHandler< dim > & matrix_free_handler
Matrix-free object handler for non-multigrid data.
Definition nonexplicit_base.h:110
dealii::MGLevelObject< matrixfreeHandler< dim, float > > & mg_matrix_free_handler
Matrix-free object handler for multigrid data.
Definition nonexplicit_base.h:140
const invmHandler< dim, degree > & invm_handler
invm handler.
Definition nonexplicit_base.h:120
void set_initial_condition()
Set the initial condition according to subset_attributes. This only applies for PDEType IMPLICIT_TIME...
Definition nonexplicit_base.h:263
solutionHandler< dim > & solution_handler
Solution handler.
Definition nonexplicit_base.h:145
void compute_subset_attributes(const fieldSolveType &field_solve_type)
Compute the subset of variableAttributes that belongs to a given fieldSolveType. This function should...
Definition nonexplicit_base.h:187
const triangulationHandler< dim > & triangulation_handler
Triangulation handler.
Definition nonexplicit_base.h:115
Class that manages solution initialization and swapping with old solutions.
Definition solution_handler.h:22
This class handlers the generation and manipulation of triangulations.
Definition triangulation_handler.h:24
Definition user_input_parameters.h:22