https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SolverSystem.C
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#include "SolverSystem.h"
11#include "SolutionInvalidity.h"
12#include "FEProblemBase.h"
13#include "TimeIntegrator.h"
14#include "MooseUtils.h"
15
16using namespace libMesh;
17
19 FEProblemBase & fe_problem,
20 const std::string & name,
21 Moose::VarKindType var_kind)
22 : SystemBase(subproblem, fe_problem, name, var_kind),
23 _current_solution(nullptr),
24 _pc_side(Moose::PCS_DEFAULT),
25 _ksp_norm(Moose::KSPN_UNPRECONDITIONED)
26{
27}
28
30
31void
41
42void
44{
45 // call parent
47 // and update _current_solution
49}
50
51void
53{
54 if (_serialized_solution.get())
55 {
56 if (!_serialized_solution->initialized() || _serialized_solution->size() != system().n_dofs())
57 {
58 _serialized_solution->clear();
59 _serialized_solution->init(system().n_dofs(), false, SERIAL);
60 }
61
63 }
64}
65
66void
77
78void
80 const Moose::SolutionIterationType iteration_type)
81{
82 if (MooseUtils::absoluteFuzzyEqual(relaxation_factor, 1.0))
83 return;
84
85 mooseAssert(hasSolutionState(1, iteration_type),
86 "Fixed point relaxation was requested but the old fixed point solution was not "
87 "saved.");
88
89 // This might be paranoid but who knows, maybe someone requests nonghosted
90 mooseAssert(solutionStateParallelType(1, iteration_type) == solution().type(),
91 "Fixed point relaxation requires the previous fixed point solution state to have "
92 "the same parallel type as the system solution.");
93
94 auto & sol = solution();
95 sol.scale(relaxation_factor);
96 sol.add(1.0 - relaxation_factor, solutionState(1, iteration_type));
97 sol.close();
98 update();
99}
100
101void
103{
104 if (pcs == "left")
106 else if (pcs == "right")
108 else if (pcs == "symmetric")
110 else if (pcs == "default")
112 else
113 mooseError("Unknown PC side specified.");
114}
115
116void
118{
119 if (kspnorm == "none")
121 else if (kspnorm == "preconditioned")
123 else if (kspnorm == "unpreconditioned")
125 else if (kspnorm == "natural")
127 else if (kspnorm == "default")
129 else
130 mooseError("Unknown ksp norm type specified.");
131}
132
133void
135{
136 auto & solution_invalidity = _app.solutionInvalidity();
137
138 // sync all solution invalid counts to rank 0 process
139 solution_invalidity.syncIteration();
140
141 if (solution_invalidity.hasInvalidSolution())
142 {
145 solution_invalidity.print(_console);
146 else
147 mooseWarning("The Solution Invalidity warnings are detected but silenced! "
148 "Use Problem/show_invalid_solution_console=true to show solution counts");
149 else
150 // output the occurrence of solution invalid in a summary table
152 solution_invalidity.print(_console);
153 }
154}
155
156void
158{
159 // Let's try not to overcompute
160 bool compute_tds = false;
161 if (type == EXEC_LINEAR)
162 compute_tds = true;
163 else if (type == EXEC_NONLINEAR)
164 {
166 compute_tds = true;
167 }
168 else if ((type == EXEC_TIMESTEP_END) || (type == EXEC_FINAL))
169 {
171 // We likely don't have a final residual evaluation upon which we compute the time derivatives
172 // so we need to do so now
173 compute_tds = true;
174 }
175
176 // avoid division by dt which might be zero.
177 if (compute_tds && _fe_problem.dt() > 0.)
178 for (auto & ti : _time_integrators)
179 {
180 // Do things like compute integration weights
181 ti->preStep();
182 ti->computeTimeDerivatives();
183 }
184}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
const ExecFlagType EXEC_NONLINEAR
Definition Moose.C:33
const ExecFlagType EXEC_FINAL
Definition Moose.C:48
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool acceptInvalidSolution() const
Whether or not to accept the solution based on its invalidity.
void computingScalingJacobian(bool computing_scaling_jacobian)
Setter for whether we're computing the scaling jacobian.
virtual Real & dt() const
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
bool showInvalidSolutionConsole() const
Whether or not to print out the invalid solutions summary table in console.
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
Definition MooseApp.h:185
Class for containing MooseEnum item information.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
void syncIteration()
Sync iteration counts to main processor Sum across all processors.
void setPCSide(MooseEnum pcs)
Set the side on which the preconditioner is applied to.
void setSolution(const NumericVector< Number > &soln)
Set the solution to a given vector.
virtual void compute(ExecFlagType type) override
Compute time derivatives, auxiliary variables, etc.
virtual void preInit() override
This is called prior to the libMesh system has been init'd.
void checkInvalidSolution()
SolverSystem(SubProblem &subproblem, FEProblemBase &fe_problem, const std::string &name, Moose::VarKindType var_kind)
virtual bool matrixFromColoring() const
Whether a system matrix is formed from coloring.
const NumericVector< Number > * _current_solution
solution vector from solver
void serializeSolution()
void applyFixedPointRelaxation(const Real relaxation_factor, const Moose::SolutionIterationType iteration_type)
Apply solution under/over-relaxation for fixed point iterations.
virtual ~SolverSystem()
void setMooseKSPNormType(MooseEnum kspnorm)
Set the norm in which the linear convergence will be measured.
Moose::PCSideType _pc_side
Preconditioning side.
virtual void restoreSolutions() override final
Restore current solutions (call after your solve failed)
Moose::MooseKSPNormType _ksp_norm
KSP norm type.
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
Definition SubProblem.C:204
Base class for a system (of equations)
Definition SystemBase.h:87
std::unique_ptr< NumericVector< Number > > _serialized_solution
Serialized version of the solution vector, or nullptr if a serialized solution is not needed.
MooseApp & _app
FEProblemBase & _fe_problem
the governing finite element/volume problem
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
unsigned int number() const
Gets the number of this system.
virtual void associateVectorToTag(NumericVector< Number > &vec, TagID tag)
Associate a vector for a given tag.
Definition SystemBase.C:980
virtual void preInit()
This is called prior to the libMesh system has been init'd.
Definition SystemBase.h:157
virtual void restoreSolutions()
Restore current solutions (call after your solve failed)
libMesh::ParallelType solutionStateParallelType(const unsigned int state, const Moose::SolutionIterationType iteration_type) const
Returns the parallel type of the given solution state.
SubProblem & _subproblem
The subproblem for whom this class holds variable data, etc; this can either be the governing finite ...
virtual NumericVector< Number > & solutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time)
Get a state of the solution (0 = current, 1 = old, 2 = older, etc).
virtual bool hasSolutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time) const
Whether or not the system has the solution state (0 = current, 1 = old, 2 = older,...
NumericVector< Number > & solution()
Definition SystemBase.h:203
void update()
Update the system (doing libMesh magic)
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
virtual void localize(std::vector< T > &v_local) const=0
std::unique_ptr< NumericVector< Number > > current_local_solution
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
@ PCS_LEFT
Definition MooseTypes.h:875
@ PCS_DEFAULT
Use whatever we have in PETSc.
Definition MooseTypes.h:878
@ PCS_SYMMETRIC
Definition MooseTypes.h:877
@ PCS_RIGHT
Definition MooseTypes.h:876
@ ST_LINEAR
Solving a linear problem.
Definition MooseTypes.h:902
@ KSPN_NONE
Definition MooseTypes.h:886
@ KSPN_PRECONDITIONED
Definition MooseTypes.h:887
@ KSPN_UNPRECONDITIONED
Definition MooseTypes.h:888
@ KSPN_DEFAULT
Use whatever we have in PETSc.
Definition MooseTypes.h:890
@ KSPN_NATURAL
Definition MooseTypes.h:889
SolutionIterationType
Definition MooseTypes.h:270
VarKindType
Framework-wide stuff.
Definition MooseTypes.h:769
const TagName SOLUTION_TAG
Definition MooseTypes.C:25
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real