PRISMS-PF Manual
Loading...
Searching...
No Matches
solver_base.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/base/exceptions.h>
7#include <deal.II/numerics/vector_tools.h>
8
9#include <boost/geometry/core/cs.hpp>
10
18#include <prismspf/core/types.h>
19
21
23
24#include <prismspf/config.h>
25
26#include <memory>
27
29
30template <unsigned int dim, unsigned int degree, typename number>
32{
33public:
43
47 virtual ~SolverBase() = default;
48
55
63
69 SolverBase(SolverBase &&solver_base) noexcept = delete;
70
77 operator=(SolverBase &&solver_base) noexcept = delete;
78
82 virtual void
83 init(const std::list<DependencyMap> &all_dependeny_sets)
84 {
86 solutions.init(solve_context->get_dof_manager(),
87 solve_context->get_constraint_manager(),
88 extents.oldest_age);
89
90 // Apply constraints.
91 solutions.apply_constraints();
92 }
93
97 virtual void
99 {
100 // Apply constraints.
101 solutions.reinit(solve_context->get_dof_manager(),
102 solve_context->get_constraint_manager());
103 solutions.apply_constraints();
104 }
105
109 virtual void
110 solve_level([[maybe_unused]] unsigned int relative_level = 0)
111 {}
112
116 virtual void
118 {
119 if (solve_context->get_simulation_timer().get_increment() == 0 &&
121 {
122 // Set the initial condition
124 return;
125 }
126 this->solve_level(0);
127 if (solve_context->get_simulation_timer().get_increment() == 0)
128 {
129 solutions.apply_initial_condition_for_old_fields();
130 }
131 }
132
136 virtual void
138 {
139 solutions.update();
140 }
141
145 virtual void
147 {
148 solutions.update_ghosts();
149 }
150
154 void
156 {
157 solutions.prepare_for_solution_transfer();
158 }
159
163 void
165 {
166 solutions.execute_solution_transfer();
167 }
168
172 virtual void
174 {}
175
179 void
181 {
182 for (const auto &global_index : solve_group.field_indices)
183 {
184 if (solve_context->get_user_inputs()
185 .load_ic_parameters.get_read_initial_conditions_from_file())
186 {
187 const auto &initial_condition_parameters =
188 solve_context->get_user_inputs().load_ic_parameters;
189 for (const auto &initial_condition_file :
190 initial_condition_parameters.get_initial_condition_files())
191 {
192 auto name_it =
193 std::find(initial_condition_file.simulation_variable_names.begin(),
194 initial_condition_file.simulation_variable_names.end(),
195 solve_context->get_field_attributes()[global_index].name);
196 if (name_it != initial_condition_file.simulation_variable_names.end())
197 {
198 solutions.get_solution_vector(global_index).zero_out_ghost_values();
199 dealii::VectorTools::interpolate(
201 solve_context->get_dof_manager().get_field_dof_handler(
204 *name_it,
205 solve_context->get_field_attributes()[global_index].field_type,
207 solve_context->get_user_inputs().spatial_discretization),
208 solutions.get_solution_vector(global_index));
209 }
210 }
211 }
212 else
213 {
214 solutions.get_solution_vector(global_index).zero_out_ghost_values();
215 dealii::VectorTools::interpolate(
217 solve_context->get_dof_manager().get_field_dof_handler(global_index),
220 solve_context->get_field_attributes()[global_index].field_type,
221 solve_context->get_pde_operator()),
222 solutions.get_solution_vector(global_index));
223 }
224 solutions.apply_initial_condition_for_old_fields();
225 }
226 }
227
233 {
234 return solutions;
235 }
236
242 {
243 return solutions;
244 }
245
249 [[nodiscard]] const SolveGroup &
251 {
252 return solve_group;
253 }
254
255protected:
260
265
270
271 std::vector<SolverBase<dim, degree, number> *> aux_solvers;
272};
273
Class that manages solution initialization and swapping with old solutions.
Definition group_solution_handler.h:72
Function for user-implemented initial conditions. These are only ever calculated for explicit time de...
Definition initial_conditions.h:37
Function for read-in of initial conditions.
Definition initial_conditions.h:69
This class provides context for a solver with ptrs to all the relevant dependencies.
Definition solve_context.h:36
Structure to hold the attributes of a solve-group.
Definition solve_group.h:59
std::set< Types::Index > field_indices
Indices of the fields to be solved in this group.
Definition solve_group.h:98
SolveTiming solve_timing
This is used to determine whether to initialize the solution vector with the initial conditions or ju...
Definition solve_group.h:93
Definition solver_base.h:32
void execute_solution_transfer()
Execute solution transfer (for AMR).
Definition solver_base.h:164
void set_initial_condition()
Set the initial conditions.
Definition solver_base.h:180
virtual void reinit()
Reinitialize the solution vectors & apply constraints.
Definition solver_base.h:98
virtual void update()
Update the fields.
Definition solver_base.h:137
std::vector< SolverBase< dim, degree, number > * > aux_solvers
Definition solver_base.h:271
const GroupSolutionHandler< dim, number > & get_solution_manager() const
Get the solution handler.
Definition solver_base.h:232
virtual void solve()
Solve for a single update step.
Definition solver_base.h:117
virtual void print()
Print information about the solver to summary.log.
Definition solver_base.h:173
SolveGroup solve_group
Information about the solve group this handler is responsible for.
Definition solver_base.h:259
void prepare_for_solution_transfer()
Prepare for solution transfer (for AMR).
Definition solver_base.h:155
virtual ~SolverBase()=default
Destructor.
SolverBase(const SolverBase &solver_base)=delete
Copy constructor.
SolverBase(SolverBase &&solver_base) noexcept=delete
Move constructor.
const SolveGroup & get_solve_group() const
Get the solver context.
Definition solver_base.h:250
virtual void init(const std::list< DependencyMap > &all_dependeny_sets)
Initialize the solver.
Definition solver_base.h:83
SolverBase & operator=(SolverBase &&solver_base) noexcept=delete
Move assignment.
GroupSolutionHandler< dim, number > solutions
Solution vectors for fields handled by this solver.
Definition solver_base.h:269
const SolveContext< dim, degree, number > * solve_context
Solver context provides access to external information.
Definition solver_base.h:264
virtual void solve_level(unsigned int relative_level=0)
Solve one level.
Definition solver_base.h:110
SolverBase(SolveGroup _solve_group, const SolveContext< dim, degree, number > &_solve_context)
Constructor.
Definition solver_base.h:37
SolverBase & operator=(const SolverBase &solver_base)=delete
Copy assignment.
virtual void update_ghosts()
Update the ghosts.
Definition solver_base.h:146
GroupSolutionHandler< dim, number > & get_solution_manager()
Get the solution handler.
Definition solver_base.h:241
This is the main class that handles the construction and solving of user-specified PDEs.
Definition system_wide.h:24
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
Definition conditional_ostreams.cc:20
Definition vectorized_operations.h:17
@ Primary
Definition solve_group.h:31
Information about what fields need to be held onto. This will likely get refactored to be an oldest a...
Definition dependency_extents.h:31