Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cls_linear_subequations_solver.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_cls_linear_subequations_solver_h
5#define lethe_cls_linear_subequations_solver_h
6
10
11#include <deal.II/base/timer.h>
12#include <deal.II/base/work_stream.h>
13
14#include <deal.II/distributed/tria_base.h>
15
16#include <deal.II/lac/trilinos_precondition.h>
17#include <deal.II/lac/trilinos_sparse_matrix.h>
18#include <deal.II/lac/trilinos_vector.h>
19
20#include <utility>
21
22/**
23 * @brief Generalized solver for CLS linear subequations.
24 *
25 * @tparam dim Number of dimensions of the problem.
26 *
27 * @ingroup solvers
28 */
29template <int dim>
31{
32public:
33 /**
34 * @brief Constructor for linear subequations solvers within the CLS
35 * auxiliary physics
36 *
37 * @param[in] p_subequation_id Identifier corresponding to the subequation.
38 *
39 * @param[in] p_simulation_parameters Simulation parameters.
40 *
41 * @param[in] p_subequation_verbosity Parameter indicating the verbosity level
42 * of the solver.
43 *
44 * @param[in] p_pcout Parallel cout used to print the information.
45 *
46 * @param[in] p_triangulation Distributed mesh information.
47 *
48 * @param[in,out] p_subequations_interface Subequations interface object used
49 * to get information from other subequations and store information from the
50 * current one.
51 */
53 const CLSSubequationsID &p_subequation_id,
54 const SimulationParameters<dim> &p_simulation_parameters,
55 const Parameters::Verbosity &p_subequation_verbosity,
56 const ConditionalOStream &p_pcout,
57 std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
58 p_triangulation,
59 CLSSubequationsInterface<dim> &p_subequations_interface)
61 , subequation_id(p_subequation_id)
62 , subequations_interface(p_subequations_interface)
63 , simulation_parameters(p_simulation_parameters)
64 , triangulation(std::move(p_triangulation))
65 , dof_handler(std::make_shared<DoFHandler<dim>>(*this->triangulation))
67 p_simulation_parameters.linear_solver.at(PhysicsID::CLS).verbosity)
68 , subequation_verbosity(p_subequation_verbosity)
69 {
70 // Ensure that the shared pointer is properly allocated
71 this->present_solution = std::make_shared<GlobalVectorType>();
72 }
73
74 /**
75 * @brief Default destructor.
76 */
77 virtual ~CLSLinearSubequationsSolver() = default;
78
79 /**
80 * @brief Set up the DofHandler and the degree of freedom associated with
81 * the subequation.
82 */
83 void
84 setup_dofs() override;
85
86 /**
87 * @brief Assemble and solve linear system when the equation to solve is
88 * linear without using the non-linear solver interface.
89 */
90 void
91 solve() override;
92
93protected:
94 /**
95 * @brief Assemble the matrix and the right-hand side (rhs) associated with
96 * the solver.
97 */
98 virtual void
100
101 /**
102 * @brief Solve linear system of equation using a strategy appropriate
103 * for the partial differential equation.
104 */
105 void
107
108 /**
109 * @brief Check if the solutions on which the subequation depends on are
110 * valid.
111 */
112 virtual void
114
117
118 // Parameters
120
121 // Core elements
122 std::shared_ptr<parallel::DistributedTriangulationBase<dim>> triangulation;
123 std::shared_ptr<DoFHandler<dim>> dof_handler;
124 std::shared_ptr<FiniteElement<dim>> fe;
125
126 // Mapping and Quadrature
127 std::shared_ptr<Mapping<dim>> mapping;
128 std::shared_ptr<Quadrature<dim>> cell_quadrature;
129
130 // Solution storage
134 std::shared_ptr<GlobalVectorType> present_solution;
136 AffineConstraints<double> constraints;
137 TrilinosWrappers::SparseMatrix system_matrix;
138 std::shared_ptr<TrilinosWrappers::PreconditionILU> ilu_preconditioner;
139
140 // Verbosity
143};
144
145#endif
const Parameters::Verbosity subequation_verbosity
virtual void assemble_system_matrix_and_rhs()=0
Assemble the matrix and the right-hand side (rhs) associated with the solver.
virtual ~CLSLinearSubequationsSolver()=default
Default destructor.
std::shared_ptr< FiniteElement< dim > > fe
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
CLSLinearSubequationsSolver(const CLSSubequationsID &p_subequation_id, const SimulationParameters< dim > &p_simulation_parameters, const Parameters::Verbosity &p_subequation_verbosity, const ConditionalOStream &p_pcout, std::shared_ptr< parallel::DistributedTriangulationBase< dim > > p_triangulation, CLSSubequationsInterface< dim > &p_subequations_interface)
Constructor for linear subequations solvers within the CLS auxiliary physics.
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
std::shared_ptr< Quadrature< dim > > cell_quadrature
std::shared_ptr< Mapping< dim > > mapping
std::shared_ptr< DoFHandler< dim > > dof_handler
CLSSubequationsInterface< dim > & subequations_interface
void setup_dofs() override
Set up the DofHandler and the degree of freedom associated with the subequation.
void solve() override
Assemble and solve linear system when the equation to solve is linear without using the non-linear so...
const SimulationParameters< dim > & simulation_parameters
std::shared_ptr< GlobalVectorType > present_solution
TrilinosWrappers::SparseMatrix system_matrix
const Parameters::Verbosity linear_solver_verbosity
virtual void check_dependencies_validity()=0
Check if the solutions on which the subequation depends on are valid.
void solve_linear_system_and_update_solution() override
Solve linear system of equation using a strategy appropriate for the partial differential equation.
Interface for secondary equations (subequations) solved within the CLS auxiliary physics.
PhysicsLinearSubequationsSolver(const ConditionalOStream &pcout)
Constructor for physics subequations that require the use of a linear solver within the span of the p...
CLSSubequationsID
IDs associated to the different subequations solved in Lethe.
PhysicsID
Unique identifiers for each physics module in Lethe.
@ CLS
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17