4#ifndef nonexplicit_base_h
5#define nonexplicit_base_h
7#include <deal.II/numerics/vector_tools.h>
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>
22PRISMS_PF_BEGIN_NAMESPACE
27template <
int dim,
int degree,
typename number>
33template <
int dim,
int degree>
49 const dealii::MappingQ1<dim> &_mapping,
163template <
int dim,
int degree>
171 const dealii::MappingQ1<dim> &_mapping,
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)
181 , mg_matrix_free_handler(_mg_matrix_free_handler)
182 , solution_handler(_solution_handler)
185template <
int dim,
int degree>
188 const fieldSolveType &field_solve_type)
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),
195 "compute_subset_attributes() should only be used for "
196 "NONEXPLICIT_LINEAR, NONEXPLICIT_SELF_NONLINEAR, NONEXPLICIT_AUXILIARY, and "
197 "NONEXPLICIT_CO_NONLINEAR fieldSolveTypes"));
199 subset_attributes.clear();
201 for (
const auto &[index, variable] : user_inputs.var_attributes)
203 if (variable.field_solve_type == field_solve_type)
205 subset_attributes.emplace(index, variable);
210template <
int dim,
int degree>
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"));
220 auto &dependency_flag_set = subset_attributes.begin()->second.eval_flag_set_RHS;
221 for (
const auto &[index, variable] : subset_attributes)
223 if (!variable.eval_flag_set_RHS.empty())
225 for (
const auto &[pair, flag] : variable.eval_flag_set_RHS)
227 dependency_flag_set[pair] |= flag;
231 for (
auto &[index, variable] : subset_attributes)
233 for (
const auto &[pair, flag] : dependency_flag_set)
235 variable.eval_flag_set_RHS[pair] |= flag;
240 auto &dependency_set = subset_attributes.begin()->second.dependency_set_RHS;
241 for (
const auto &[index, variable] : subset_attributes)
243 for (
const auto &[index, map] : variable.dependency_set_RHS)
245 for (
const auto &[dependency_type, field_type] : map)
247 dependency_set[index].emplace(dependency_type, field_type);
251 for (
auto &[index, variable] : subset_attributes)
253 variable.dependency_set_RHS = dependency_set;
261template <
int dim,
int degree>
265 for (
const auto &[index, variable] : subset_attributes)
267 if (variable.pde_type != PDEType::IMPLICIT_TIME_DEPENDENT &&
268 variable.pde_type != PDEType::TIME_INDEPENDENT)
273 Assert(dof_handler.get_dof_handlers().size() > index,
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(),
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)));
288 dealii::VectorTools::interpolate(
290 *(dof_handler.get_dof_handlers().at(index)),
292 *(solution_handler.solution_set.at(
293 std::make_pair(index, dependencyType::NORMAL))));
297 if (solution_handler.solution_set.find(
298 std::make_pair(index, dependencyType::OLD_1)) !=
299 solution_handler.solution_set.end())
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)));
309template <
int dim,
int degree>
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)
320 for (
const auto &[dependency_type, field_type] : map)
323 <<
" Index: " << index <<
" Dependency: " << to_string(dependency_type)
324 <<
" Field: " << to_string(field_type) <<
"\n";
330PRISMS_PF_END_NAMESPACE
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