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#include "GradientLimiterType.h"
16
17#include <set>
18
19#include "libmesh/transient_system.h"
20#include "libmesh/linear_implicit_system.h"
21#include "libmesh/linear_solver.h"
22
23class LinearFVKernel;
24class InputParameters;
25namespace Moose::Kokkos
26{
27class LinearFVKernel;
31class System;
32}
33
34// libMesh forward declarations
35namespace libMesh
36{
37template <typename T>
38class NumericVector;
39template <typename T>
40class SparseMatrix;
41template <typename T>
42class DiagonalMatrix;
43} // namespace libMesh
44
49 public PerfGraphInterface,
51{
52public:
53 LinearSystem(FEProblemBase & problem, const std::string & name);
54 virtual ~LinearSystem();
55
56 virtual void solve() override;
57 virtual void preInit() override;
58
64 virtual bool converged() override { return _converged; }
65
66 virtual void initialSetup() override;
67 virtual void reinit() override;
68
69#ifdef MOOSE_KOKKOS_ENABLED
76 void addKokkosKernel(const std::string & kernel_name,
77 const std::string & name,
78 InputParameters & parameters);
79
86 void addKokkosBoundaryCondition(const std::string & bc_name,
87 const std::string & name,
88 InputParameters & parameters);
89#endif
90
91 // Overriding these to make sure the linear systems don't do anything during
92 // residual/jacobian setup
93 virtual void residualSetup() override {}
94 virtual void jacobianSetup() override {}
95
99 virtual void stopSolve(const ExecFlagType & exec_flag,
100 const std::set<TagID> & vector_tags_to_close) override;
101
107 virtual bool containsTimeKernel() override;
108 virtual std::vector<std::string> timeKernelVariableNames() override { return {}; }
109
118 void computeLinearSystemTags(const std::set<TagID> & vector_tags,
119 const std::set<TagID> & matrix_tags,
120 const bool compute_gradients = true);
121
126
130 NumericVector<Number> & getRightHandSideTimeVector();
131
135 NumericVector<Number> & getRightHandSideNonTimeVector();
136
137 virtual void augmentSparsity(SparsityPattern::Graph & sparsity,
138 std::vector<dof_id_type> & n_nz,
139 std::vector<dof_id_type> & n_oz) override;
140
144 unsigned int nLinearIterations() const { return _n_linear_iters; }
145
146 virtual System & system() override { return _sys; }
147 virtual const System & system() const override { return _sys; }
148
154 virtual TagID systemMatrixTag() const override { return _system_matrix_tag; }
156
158 NumericVector<Number> & getRightHandSideVector() { return *_linear_implicit_system.rhs; }
159 const NumericVector<Number> & getRightHandSideVector() const
160 {
162 }
163
165 SparseMatrix<Number> & getSystemMatrix() { return *_linear_implicit_system.matrix; }
166 const SparseMatrix<Number> & getSystemMatrix() const { return *_linear_implicit_system.matrix; }
167
171
172 virtual void compute(ExecFlagType type) override;
173
174protected:
182 void computeLinearSystemInternal(const std::set<TagID> & vector_tags,
183 const std::set<TagID> & matrix_tags,
184 const bool compute_gradients = true);
185
186#ifdef MOOSE_KOKKOS_ENABLED
191
197 void computeKokkosLinearSystem(const std::set<TagID> & vector_tags,
198 const std::set<TagID> & matrix_tags);
199#endif
200
202 System & _sys;
203
205 unsigned int _current_l_its;
206
208 std::set<TagID> _vector_tags;
209
211 std::set<TagID> _matrix_tags;
212
215
217 NumericVector<Number> * _rhs_time;
218
221
223 NumericVector<Number> * _rhs_non_time;
224
227
230
233
235 unsigned int _n_linear_iters;
236
239
242
245
248
249private:
251 std::vector<NumericVector<Number> *> _solution_state;
252};
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...
Shared storage and allocation logic for linear finite-volume cell gradients for variables in the syst...
void requestLinearFVLimitedGradients(const Moose::FV::GradientLimiterType limiter_type, unsigned int variable_number)
Request storage and assembly of limiter-specific cell gradients.
const std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & linearFVLimitedGradientContainer(const Moose::FV::GradientLimiterType limiter_type) const
Access the stored raw or limited cell-centered gradient components.
void computeGradients()
Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.
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...