4#ifndef linear_solver_identity_h
5#define linear_solver_identity_h
7#include <deal.II/lac/precondition.h>
8#include <deal.II/lac/solver_cg.h>
9#include <deal.II/matrix_free/matrix_free.h>
11#include <prismspf/config.h>
12#include <prismspf/solvers/linear_solver_base.h>
14#ifdef PRISMS_PF_WITH_CALIPER
15# include <caliper/cali.h>
18PRISMS_PF_BEGIN_NAMESPACE
24template <
int dim,
int degree>
29 using VectorType = dealii::LinearAlgebra::distributed::Vector<double>;
61 solve(
const double step_length = 1.0)
override;
64template <
int dim,
int degree>
78template <
int dim,
int degree>
82 this->system_matrix->clear();
83 this->system_matrix->initialize(this->matrix_free_handler.get_matrix_free());
84 this->update_system_matrix->clear();
85 this->update_system_matrix->initialize(this->matrix_free_handler.get_matrix_free());
87 this->system_matrix->add_global_to_local_mapping(
88 this->residual_global_to_local_solution);
89 this->system_matrix->add_src_solution_subset(this->residual_src);
91 this->update_system_matrix->add_global_to_local_mapping(
92 this->newton_update_global_to_local_solution);
93 this->update_system_matrix->add_src_solution_subset(this->newton_update_src);
96 this->constraint_handler.get_constraint(this->field_index)
97 .distribute(*(this->solution_handler.solution_set.at(
98 std::make_pair(this->field_index, dependencyType::NORMAL))));
101template <
int dim,
int degree>
106template <
int dim,
int degree>
110 auto *solution = this->solution_handler.solution_set.at(
111 std::make_pair(this->field_index, dependencyType::NORMAL));
114 this->system_matrix->compute_residual(*this->residual, *solution);
116 <<
" field: " << this->field_index
117 <<
" Initial residual: " << this->residual->l2_norm() << std::flush;
120 this->compute_solver_tolerance();
123 this->solver_control.set_tolerance(this->tolerance);
124 dealii::SolverCG<VectorType> cg(this->solver_control);
128 *this->newton_update = 0.0;
129 cg.solve(*(this->update_system_matrix),
130 *this->newton_update,
132 dealii::PreconditionIdentity());
137 <<
"Warning: linear solver did not converge as per set tolerances.\n";
139 this->constraint_handler.get_constraint(this->field_index)
140 .set_zero(*this->newton_update);
143 <<
" Final residual: " << this->solver_control.last_value()
144 <<
" Steps: " << this->solver_control.last_step() <<
"\n"
148 (*solution).add(step_length, *this->newton_update);
149 this->solution_handler.update(fieldSolveType::NONEXPLICIT_LINEAR, this->field_index);
153 this->constraint_handler.get_constraint(this->field_index).distribute(*solution);
156PRISMS_PF_END_NAMESPACE
static dealii::ConditionalOStream & pout_base()
Generic parallel output stream. Used for essential information in release and debug mode.
Definition conditional_ostreams.cc:31
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 handles the assembly and solving of a field with the identity preconditioner (no precondit...
Definition linear_solver_identity.h:26
void reinit() override
Reinitialize the system.
Definition linear_solver_identity.h:103
void init() override
Initialize the system.
Definition linear_solver_identity.h:80
identitySolver(const userInputParameters< dim > &_user_inputs, const variableAttributes &_variable_attributes, const matrixfreeHandler< dim > &_matrix_free_handler, const constraintHandler< dim > &_constraint_handler, solutionHandler< dim > &_solution_handler)
Constructor.
Definition linear_solver_identity.h:65
void solve(const double step_length=1.0) override
Solve the system Ax=b.
Definition linear_solver_identity.h:108
~identitySolver() override=default
Destructor.
Base class that handles the assembly and linear solving of a field.
Definition linear_solver_base.h:36
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
Structure to hold the variable attributes of a field. This includes things like the name,...
Definition variable_attributes.h:39