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
27
28template <unsigned int dim, unsigned int degree, typename number>
30{
31public:
36 SolverBase(SolveBlock _solve_block,
37 const SolveContext<dim, degree, number> &_solve_context)
38 : solve_block(std::move(_solve_block))
39 , solve_context(&_solve_context)
41 solve_context->get_field_attributes(),
42 solve_context->get_matrix_free_manager().get_shared_matrix_free_levels())
43 {}
44
48 virtual ~SolverBase() = default;
49
55 SolverBase(const SolverBase &solver_base) = delete;
56
63 operator=(const SolverBase &solver_base) = delete;
64
70 SolverBase(SolverBase &&solver_base) noexcept = delete;
71
78 operator=(SolverBase &&solver_base) noexcept = delete;
79
83 virtual void
84 init(const std::list<DependencyMap> &all_dependeny_sets)
85 {
86 DependencyExtents extents(solve_block.field_indices, all_dependeny_sets);
87 solutions.init(extents.oldest_age);
88
89 // Apply constraints.
90 solutions.apply_constraints();
91 }
92
96 virtual void
98 {
99 // Apply constraints.
100 solutions.reinit();
101 solutions.apply_constraints();
102 }
103
107 virtual void
109 {}
110
114 virtual void
116 {
117 if (solve_context->get_simulation_timer().get_increment() == 0 &&
118 solve_block.solve_timing == SolveTiming::Primary)
119 {
120 // Set the initial condition
122 return;
123 }
124 this->solve_impl();
125 if (solve_context->get_simulation_timer().get_increment() == 0)
126 {
127 solutions.apply_initial_condition_for_old_fields();
128 }
129 }
130
134 virtual void
136 {
137 solutions.update();
138 }
139
143 virtual void
145 {
146 solutions.update_ghosts();
147 }
148
152 void
154 {
155 solutions.prepare_for_solution_transfer();
156 }
157
161 void
163 {
164 solutions.execute_solution_transfer();
165 }
166
170 virtual void
172 {}
173
177 void
179 {
180 for (const auto &global_index : solve_block.field_indices)
181 {
182 bool initialized_from_file = false;
183
184 // First, try to find this variable in IC files
185 const auto &initial_condition_parameters =
186 solve_context->get_user_inputs().load_ic_parameters;
187
188 for (const auto &initial_condition_file :
189 initial_condition_parameters.get_initial_condition_files())
190 {
191 auto name_it =
192 std::find(initial_condition_file.simulation_variable_names.begin(),
193 initial_condition_file.simulation_variable_names.end(),
194 solve_context->get_field_attributes()[global_index].name);
195 if (name_it != initial_condition_file.simulation_variable_names.end())
196 {
197 // Found in file - read from file
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(global_index),
203 *name_it,
204 solve_context->get_field_attributes()[global_index].field_type,
205 initial_condition_file,
206 solve_context->get_user_inputs().spatial_discretization),
207 solutions.get_solution_vector(global_index));
208
209 initialized_from_file = true;
210 break; // Stop searching once found
211 }
212 }
213 // If not found in files, use programmatic IC
214 if (!initialized_from_file)
215 {
216 solutions.get_solution_vector(global_index).zero_out_ghost_values();
217 dealii::VectorTools::interpolate(
219 solve_context->get_dof_manager().get_field_dof_handler(global_index),
221 global_index,
222 solve_context->get_field_attributes()[global_index].field_type,
223 solve_context->get_pde_operator()),
224 solutions.get_solution_vector(global_index));
225 }
226 solutions.apply_initial_condition_for_old_fields();
227 }
228 }
229
233 [[nodiscard]] const GroupSolutionHandler<dim, number> &
235 {
236 return solutions;
237 }
238
244 {
245 return solutions;
246 }
247
251 [[nodiscard]] const SolveBlock &
253 {
254 return solve_block;
255 }
256
257protected:
262
267
272
273 std::vector<SolverBase<dim, degree, number> *> aux_solvers;
274};
275
276PRISMS_PF_END_NAMESPACE
Class that manages solution initialization and swapping with old solutions.
Definition group_solution_handler.h:68
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
Structure to hold the attributes of a solve-block.
Definition solve_block.h:59
This class provides context for a solver with ptrs to all the relevant dependencies.
Definition solve_context.h:34
void execute_solution_transfer()
Execute solution transfer (for AMR).
Definition solver_base.h:162
void set_initial_condition()
Set the initial conditions.
Definition solver_base.h:178
virtual void reinit()
Reinitialize the solution vectors & apply constraints.
Definition solver_base.h:97
const SolveBlock & get_solve_block() const
Get the solver context.
Definition solver_base.h:252
virtual void update()
Update the fields.
Definition solver_base.h:135
std::vector< SolverBase< dim, degree, number > * > aux_solvers
Definition solver_base.h:273
const GroupSolutionHandler< dim, number > & get_solution_manager() const
Get the solution handler.
Definition solver_base.h:234
virtual void solve()
Solve for a single update step.
Definition solver_base.h:115
virtual void print()
Print information about the solver to summary.log.
Definition solver_base.h:171
void prepare_for_solution_transfer()
Prepare for solution transfer (for AMR).
Definition solver_base.h:153
virtual ~SolverBase()=default
Destructor.
SolverBase(const SolverBase &solver_base)=delete
Copy constructor.
SolverBase(SolverBase &&solver_base) noexcept=delete
Move constructor.
SolverBase(SolveBlock _solve_block, const SolveContext< dim, degree, number > &_solve_context)
Constructor.
Definition solver_base.h:36
virtual void solve_impl()
Solve implementation.
Definition solver_base.h:108
virtual void init(const std::list< DependencyMap > &all_dependeny_sets)
Initialize the solver.
Definition solver_base.h:84
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:271
const SolveContext< dim, degree, number > * solve_context
Solver context provides access to external information.
Definition solver_base.h:266
SolveBlock solve_block
Information about the solve block this handler is responsible for.
Definition solver_base.h:261
SolverBase & operator=(const SolverBase &solver_base)=delete
Copy assignment.
virtual void update_ghosts()
Update the ghosts.
Definition solver_base.h:144
GroupSolutionHandler< dim, number > & get_solution_manager()
Get the solution handler.
Definition solver_base.h:243
static const dealii::MappingQ1< dim > mapping
Mappings to and from reference cell.
Definition system_wide.h:36
Definition conditional_ostreams.cc:20
Definition vectorized_operations.h:17
@ Primary
Primary fields are initialized explicitly through initial conditions rather than through the solver o...
Definition solve_block.h:33
Information about what fields need to be held onto. This will likely get refactored to be an oldest a...
Definition dependency_extents.h:31
unsigned int oldest_age
Definition dependency_extents.h:32