https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearSystem.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "SolverSystem.h"
14#include "PerfGraphInterface.h"
15
16#include <set>
17
18#include "libmesh/transient_system.h"
19#include "libmesh/linear_implicit_system.h"
20#include "libmesh/linear_solver.h"
21
22class LinearFVKernel;
23class InputParameters;
24namespace Moose::Kokkos
25{
26class LinearFVKernel;
30class System;
31}
32
33// libMesh forward declarations
34namespace libMesh
35{
36template <typename T>
37class NumericVector;
38template <typename T>
39class SparseMatrix;
40template <typename T>
41class DiagonalMatrix;
42} // namespace libMesh
43
48 public PerfGraphInterface,
50{
51public:
52 LinearSystem(FEProblemBase & problem, const std::string & name);
53 virtual ~LinearSystem();
54
55 virtual void solve() override;
56 virtual void preInit() override;
57
63 virtual bool converged() override { return _converged; }
64
65 virtual void initialSetup() override;
66 virtual void reinit() override;
67
68#ifdef MOOSE_KOKKOS_ENABLED
75 void addKokkosKernel(const std::string & kernel_name,
76 const std::string & name,
77 InputParameters & parameters);
78
85 void addKokkosBoundaryCondition(const std::string & bc_name,
86 const std::string & name,
87 InputParameters & parameters);
88#endif
89
90 // Overriding these to make sure the linear systems don't do anything during
91 // residual/jacobian setup
92 virtual void residualSetup() override {}
93 virtual void jacobianSetup() override {}
94
98 virtual void stopSolve(const ExecFlagType & exec_flag,
99 const std::set<TagID> & vector_tags_to_close) override;
100
106 virtual bool containsTimeKernel() override;
107 virtual std::vector<std::string> timeKernelVariableNames() override { return {}; }
108
117 void computeLinearSystemTags(const std::set<TagID> & vector_tags,
118 const std::set<TagID> & matrix_tags,
119 const bool compute_gradients = true);
120
125
129 NumericVector<Number> & getRightHandSideTimeVector();
130
134 NumericVector<Number> & getRightHandSideNonTimeVector();
135
136 virtual void augmentSparsity(SparsityPattern::Graph & sparsity,
137 std::vector<dof_id_type> & n_nz,
138 std::vector<dof_id_type> & n_oz) override;
139
143 unsigned int nLinearIterations() const { return _n_linear_iters; }
144
145 virtual System & system() override { return _sys; }
146 virtual const System & system() const override { return _sys; }
147
153 virtual TagID systemMatrixTag() const override { return _system_matrix_tag; }
155
157 NumericVector<Number> & getRightHandSideVector() { return *_linear_implicit_system.rhs; }
158 const NumericVector<Number> & getRightHandSideVector() const
159 {
161 }
162
164 SparseMatrix<Number> & getSystemMatrix() { return *_linear_implicit_system.matrix; }
165 const SparseMatrix<Number> & getSystemMatrix() const { return *_linear_implicit_system.matrix; }
166
170
171 virtual void compute(ExecFlagType type) override;
172
173protected:
181 void computeLinearSystemInternal(const std::set<TagID> & vector_tags,
182 const std::set<TagID> & matrix_tags,
183 const bool compute_gradients = true);
184
185#ifdef MOOSE_KOKKOS_ENABLED
190
196 void computeKokkosLinearSystem(const std::set<TagID> & vector_tags,
197 const std::set<TagID> & matrix_tags);
198#endif
199
201 System & _sys;
202
204 unsigned int _current_l_its;
205
207 std::set<TagID> _vector_tags;
208
210 std::set<TagID> _matrix_tags;
211
214
216 NumericVector<Number> * _rhs_time;
217
220
222 NumericVector<Number> * _rhs_non_time;
223
226
229
232
234 unsigned int _n_linear_iters;
235
238
241
244
247
248private:
250 std::vector<NumericVector<Number> *> _solution_state;
251};
unsigned int TagID
Definition MooseTypes.h:238
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Base class for boundary conditions for linear FV systems.
Finite volume kernel that contributes approximations of volumetric integral terms to the matrix and r...
Finite volume kernel that contributes approximations of discretized face flux terms to the matrix and...
Registration, update, and allocation logic for linear finite-volume cell gradients.
void updateFVGradient(const LinearFVGradientReader &reader)
Update a registered gradient reader explicitly.
void computeGradients()
Compute and finalize all registered linear FV gradient fields.
LinearFVGradientReader registerFVGradient(unsigned int variable_number, const FVGradientMethod &method)
Register a variable for gradient values produced by a method object.
Base class for finite volume kernels that contribute to a linear systems.
Linear system to be solved.
virtual void augmentSparsity(SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz) override
Will modify the sparsity pattern to add logical geometric connections.
NumericVector< Number > & getRightHandSideNonTimeVector()
Return a numeric vector that is associated with the nontime tag.
virtual const System & system() const override
virtual bool containsTimeKernel() override
If the system has a kernel that corresponds to a time derivative.
Real _initial_linear_residual
The initial linear residual.
virtual void initialSetup() override
Setup Functions.
virtual void stopSolve(const ExecFlagType &exec_flag, const std::set< TagID > &vector_tags_to_close) override
Quit the current solve as soon as possible.
TagID rightHandSideVectorTag() const
TagID _rhs_tag
Used for the right hand side vector from PETSc.
TagID _system_matrix_tag
Tag for every contribution to system matrix.
System & _sys
Base class reference to the libmesh system.
virtual TagID systemMatrixTag() const override
Return the Matrix Tag ID for System.
TagID rightHandSideNonTimeVectorTag() const
unsigned int nLinearIterations() const
Return the number of linear iterations.
void addKokkosBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters &parameters)
Add a Kokkos linear finite volume boundary condition to this system.
virtual void residualSetup() override
NumericVector< Number > & getRightHandSideVector()
Fetching the right hand side vector from the libmesh system.
SparseMatrix< Number > & getSystemMatrix()
Fetching the system matrix from the libmesh system.
std::set< TagID > _matrix_tags
Matrix tags to temporarily store all tags associated with the current system.
virtual void reinit() override
Reinitialize the system when the degrees of freedom in this system have changed.
virtual void preInit() override
This is called prior to the libMesh system has been init'd.
unsigned int _n_linear_iters
Number of linear iterations.
libMesh::LinearImplicitSystem & linearImplicitSystem()
Return a reference to the stored linear implicit system.
std::set< TagID > _vector_tags
Vector tags to temporarily store all tags associated with the current system.
TagID _system_matrix_non_time_tag
Tag for non-time contribution to the system matrix.
virtual System & system() override
Get the reference to the libMesh system.
NumericVector< Number > * _rhs_non_time
right hand side vector for non-time contributions
NumericVector< Number > & getRightHandSideTimeVector()
Return a numeric vector that is associated with the time tag.
unsigned int _current_l_its
The linear iterations needed for convergence.
void computeKokkosLinearSystem(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Assemble the Kokkos contributions to the linear system for the given tags.
const SparseMatrix< Number > & getSystemMatrix() const
TagID rightHandSideTimeVectorTag() const
Real _final_linear_residual
The final linear residual.
libMesh::LinearImplicitSystem & _linear_implicit_system
Base class reference to the linear implicit system in libmesh.
void computeLinearSystemInternal(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags, const bool compute_gradients=true)
Compute the right hand side and system matrix for given tags.
bool _converged
If the solve on the linear system converged.
void computeLinearSystemTags(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags, const bool compute_gradients=true)
Compute the right hand side and the system matrix of the system for given tags.
TagID _rhs_time_tag
Tag for time contribution rhs.
TagID _rhs_non_time_tag
Tag for non-time contribution rhs.
std::vector< NumericVector< Number > * > _solution_state
The current states of the solution (0 = current, 1 = old, etc)
virtual std::vector< std::string > timeKernelVariableNames() override
Returns the names of the variables that have time derivative kernels in the system.
virtual void jacobianSetup() override
void initialSetupKokkosLinearFV()
Perform the initial setup of the Kokkos linear finite volume kernels and boundary conditions.
virtual void compute(ExecFlagType type) override
Compute time derivatives, auxiliary variables, etc.
const NumericVector< Number > & getRightHandSideVector() const
virtual ~LinearSystem()
NumericVector< Number > * _rhs_time
right hand side vector for time contributions
virtual void solve() override
Solve the system (using libMesh magic)
void addKokkosKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Add a Kokkos linear finite volume kernel to this system.
virtual bool converged() override
At the moment, this is only used for the multi-system fixed point iteration.
Class for containing MooseEnum item information.
Interface for objects interacting with the PerfGraph.
virtual const std::string & name() const
NumericVector< Number > * rhs
SparseMatrix< Number > * matrix
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...