https://mooseframework.inl.gov
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 
23 class LinearFVKernel;
24 
25 // libMesh forward declarations
26 namespace libMesh
27 {
28 template <typename T>
29 class NumericVector;
30 template <typename T>
31 class SparseMatrix;
32 template <typename T>
33 class DiagonalMatrix;
34 } // namespace libMesh
35 
39 class LinearSystem : public SolverSystem,
40  public PerfGraphInterface,
42 {
43 public:
44  LinearSystem(FEProblemBase & problem, const std::string & name);
45  virtual ~LinearSystem();
46 
47  virtual void solve() override;
48 
54  virtual bool converged() override { return _converged; }
55 
56  virtual void initialSetup() override;
57  virtual void reinit() override;
58 
59  // Overriding these to make sure the linear systems don't do anything during
60  // residual/jacobian setup
61  virtual void residualSetup() override {}
62  virtual void jacobianSetup() override {}
63 
67  virtual void stopSolve(const ExecFlagType & exec_flag,
68  const std::set<TagID> & vector_tags_to_close) override;
69 
75  virtual bool containsTimeKernel() override;
76  virtual std::vector<std::string> timeKernelVariableNames() override { return {}; }
77 
86  void computeLinearSystemTags(const std::set<TagID> & vector_tags,
87  const std::set<TagID> & matrix_tags,
88  const bool compute_gradients = true);
89 
94 
99 
104 
105  virtual void augmentSparsity(SparsityPattern::Graph & sparsity,
106  std::vector<dof_id_type> & n_nz,
107  std::vector<dof_id_type> & n_oz) override;
108 
112  unsigned int nLinearIterations() const { return _n_linear_iters; }
113 
114  virtual System & system() override { return _sys; }
115  virtual const System & system() const override { return _sys; }
116 
122  virtual TagID systemMatrixTag() const override { return _system_matrix_tag; }
124 
128  {
130  }
131 
135 
139 
140  virtual void compute(ExecFlagType type) override;
141 
142 protected:
150  void computeLinearSystemInternal(const std::set<TagID> & vector_tags,
151  const std::set<TagID> & matrix_tags,
152  const bool compute_gradients = true);
153 
155  System & _sys;
156 
158  unsigned int _current_l_its;
159 
161  std::set<TagID> _vector_tags;
162 
164  std::set<TagID> _matrix_tags;
165 
168 
171 
174 
177 
180 
183 
186 
188  unsigned int _n_linear_iters;
189 
192 
195 
198 
201 
202 private:
204  std::vector<NumericVector<Number> *> _solution_state;
205 };
virtual void stopSolve(const ExecFlagType &exec_flag, const std::set< TagID > &vector_tags_to_close) override
Quit the current solve as soon as possible.
Definition: LinearSystem.C:306
Base class for finite volume kernels that contribute to a linear systems.
unsigned int _n_linear_iters
Number of linear iterations.
Definition: LinearSystem.h:188
unsigned int TagID
Definition: MooseTypes.h:238
TagID _system_matrix_non_time_tag
Tag for non-time contribution to the system matrix.
Definition: LinearSystem.h:182
TagID rightHandSideVectorTag() const
Definition: LinearSystem.h:121
virtual bool containsTimeKernel() override
If the system has a kernel that corresponds to a time derivative.
Definition: LinearSystem.C:315
libMesh::LinearImplicitSystem & linearImplicitSystem()
Return a reference to the stored linear implicit system.
Definition: LinearSystem.h:93
NumericVector< Number > & getRightHandSideNonTimeVector()
Return a numeric vector that is associated with the nontime tag.
Definition: LinearSystem.C:265
virtual TagID systemMatrixTag() const override
Return the Matrix Tag ID for System.
Definition: LinearSystem.h:122
const NumericVector< Number > & getRightHandSideVector() const
Definition: LinearSystem.h:127
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.
Definition: LinearSystem.C:190
virtual void compute(ExecFlagType type) override
Compute time derivatives, auxiliary variables, etc.
Definition: LinearSystem.C:337
TagID rightHandSideNonTimeVectorTag() const
Definition: LinearSystem.h:120
NumericVector< Number > * rhs
std::set< TagID > _vector_tags
Vector tags to temporarily store all tags associated with the current system.
Definition: LinearSystem.h:161
TagID rightHandSideTimeVectorTag() const
Definition: LinearSystem.h:119
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
unsigned int nLinearIterations() const
Return the number of linear iterations.
Definition: LinearSystem.h:112
unsigned int _current_l_its
The linear iterations needed for convergence.
Definition: LinearSystem.h:158
SparseMatrix< Number > & getSystemMatrix()
Fetching the system matrix from the libmesh system.
Definition: LinearSystem.h:133
Real _initial_linear_residual
The initial linear residual.
Definition: LinearSystem.h:191
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const SparseMatrix< Number > & getSystemMatrix() const
Definition: LinearSystem.h:134
System & _sys
Base class reference to the libmesh system.
Definition: LinearSystem.h:155
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 requestLinearFVLimitedGradients(const Moose::FV::GradientLimiterType limiter_type, unsigned int variable_number)
Request storage and assembly of limiter-specific cell gradients.
virtual void initialSetup() override
Setup Functions.
Definition: LinearSystem.C:107
virtual const std::string & name() const
Definition: SystemBase.C:1342
libMesh::LinearImplicitSystem & _linear_implicit_system
Base class reference to the linear implicit system in libmesh.
Definition: LinearSystem.h:200
NumericVector< Number > * _rhs_time
right hand side vector for time contributions
Definition: LinearSystem.h:170
Real _final_linear_residual
The final linear residual.
Definition: LinearSystem.h:194
std::set< TagID > _matrix_tags
Matrix tags to temporarily store all tags associated with the current system.
Definition: LinearSystem.h:164
std::vector< NumericVector< Number > * > _solution_state
The current states of the solution (0 = current, 1 = old, etc)
Definition: LinearSystem.h:204
TagID _rhs_tag
Used for the right hand side vector from PETSc.
Definition: LinearSystem.h:179
virtual void jacobianSetup() override
Definition: LinearSystem.h:62
TagID _rhs_non_time_tag
Tag for non-time contribution rhs.
Definition: LinearSystem.h:173
virtual void solve() override
Solve the system (using libMesh magic)
Definition: LinearSystem.C:279
virtual const System & system() const override
Definition: LinearSystem.h:115
Interface for objects interacting with the PerfGraph.
TagID _rhs_time_tag
Tag for time contribution rhs.
Definition: LinearSystem.h:167
TagID _system_matrix_tag
Tag for every contribution to system matrix.
Definition: LinearSystem.h:185
bool _converged
If the solve on the linear system converged.
Definition: LinearSystem.h:197
NumericVector< Number > * _rhs_non_time
right hand side vector for non-time contributions
Definition: LinearSystem.h:176
NumericVector< Number > & getRightHandSideVector()
Fetching the right hand side vector from the libmesh system.
Definition: LinearSystem.h:126
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void reinit() override
Reinitialize the system when the degrees of freedom in this system have changed.
Definition: LinearSystem.C:157
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
NumericVector< Number > & getRightHandSideTimeVector()
Return a numeric vector that is associated with the time tag.
Definition: LinearSystem.C:259
SparseMatrix< Number > * matrix
virtual void residualSetup() override
Definition: LinearSystem.h:61
virtual std::vector< std::string > timeKernelVariableNames() override
Returns the names of the variables that have time derivative kernels in the system.
Definition: LinearSystem.h:76
Linear system to be solved.
Definition: LinearSystem.h:39
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.
Definition: LinearSystem.C:271
virtual ~LinearSystem()
LinearSystem(FEProblemBase &problem, const std::string &name)
Definition: LinearSystem.C:78
virtual System & system() override
Get the reference to the libMesh system.
Definition: LinearSystem.h:114
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.
Definition: LinearSystem.C:164
virtual bool converged() override
At the moment, this is only used for the multi-system fixed point iteration.
Definition: LinearSystem.h:54
void computeGradients()
Compute and store raw and requested limited Green-Gauss gradients for linear FV variables.
Shared storage and allocation logic for linear finite-volume cell gradients for variables in the syst...