https://mooseframework.inl.gov
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 
15 using namespace libMesh;
16 
18  FEProblemBase & fe_problem,
19  const std::string & name,
20  Moose::VarKindType var_kind)
21  : SystemBase(subproblem, fe_problem, name, var_kind),
22  _current_solution(nullptr),
23  _pc_side(Moose::PCS_DEFAULT),
24  _ksp_norm(Moose::KSPN_UNPRECONDITIONED),
25  _solution_is_invalid(false)
26 {
27 }
28 
29 SolverSystem::~SolverSystem() = default;
30 
31 void
33 {
35 
37 
38  if (_serialized_solution.get())
39  _serialized_solution->init(system().n_dofs(), false, SERIAL);
40 }
41 
42 void
44 {
45  // call parent
47  // and update _current_solution
49 }
50 
51 void
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 
66 void
68 {
69  _current_solution = &soln;
70 
72  associateVectorToTag(const_cast<NumericVector<Number> &>(soln), tag);
73 
74  if (_serialized_solution.get())
76 }
77 
78 void
80 {
81  if (pcs == "left")
83  else if (pcs == "right")
85  else if (pcs == "symmetric")
87  else if (pcs == "default")
89  else
90  mooseError("Unknown PC side specified.");
91 }
92 
93 void
95 {
96  if (kspnorm == "none")
98  else if (kspnorm == "preconditioned")
100  else if (kspnorm == "unpreconditioned")
102  else if (kspnorm == "natural")
104  else if (kspnorm == "default")
106  else
107  mooseError("Unknown ksp norm type specified.");
108 }
109 
110 void
112 {
113  auto & solution_invalidity = _app.solutionInvalidity();
114 
115  // sync all solution invalid counts to rank 0 process
116  solution_invalidity.syncIteration();
117 
118  if (solution_invalidity.hasInvalidSolution())
119  {
122  solution_invalidity.print(_console);
123  else
124  mooseWarning("The Solution Invalidity warnings are detected but silenced! "
125  "Use Problem/show_invalid_solution_console=true to show solution counts");
126  else
127  // output the occurrence of solution invalid in a summary table
129  solution_invalidity.print(_console);
130  }
131 }
132 
133 void
135 {
136  // Let's try not to overcompute
137  bool compute_tds = false;
138  if (type == EXEC_LINEAR)
139  compute_tds = true;
140  else if (type == EXEC_NONLINEAR)
141  {
143  compute_tds = true;
144  }
145  else if ((type == EXEC_TIMESTEP_END) || (type == EXEC_FINAL))
146  {
148  // We likely don't have a final residual evaluation upon which we compute the time derivatives
149  // so we need to do so now
150  compute_tds = true;
151  }
152 
153  if (compute_tds && _fe_problem.dt() > 0.)
154  for (auto & ti : _time_integrators)
155  {
156  // avoid division by dt which might be zero.
157  ti->preStep();
158  ti->computeTimeDerivatives();
159  }
160 }
std::string name(const ElemQuality q)
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
Definition: SystemBase.h:1041
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
Definition: SubProblem.C:203
SolverSystem(SubProblem &subproblem, FEProblemBase &fe_problem, const std::string &name, Moose::VarKindType var_kind)
Definition: SolverSystem.C:17
Moose::PCSideType _pc_side
Preconditioning side.
Definition: SolverSystem.h:108
void checkInvalidSolution()
Definition: SolverSystem.C:111
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
virtual ~SolverSystem()
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:336
virtual void associateVectorToTag(NumericVector< Number > &vec, TagID tag)
Associate a vector for a given tag.
Definition: SystemBase.C:964
void serializeSolution()
Definition: SolverSystem.C:52
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
void setSolution(const NumericVector< Number > &soln)
Set the solution to a given vector.
Definition: SolverSystem.C:67
Solving a linear problem.
Definition: MooseTypes.h:848
void setPCSide(MooseEnum pcs)
Set the side on which the preconditioner is applied to.
Definition: SolverSystem.C:79
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:34
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void computingScalingJacobian(bool computing_scaling_jacobian)
Setter for whether we&#39;re computing the scaling jacobian.
Base class for a system (of equations)
Definition: SystemBase.h:84
std::unique_ptr< NumericVector< Number > > _serialized_solution
Serialized version of the solution vector, or nullptr if a serialized solution is not needed...
Definition: SystemBase.h:1060
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
dof_id_type n_dofs() const
virtual bool matrixFromColoring() const
Whether a system matrix is formed from coloring.
Definition: SolverSystem.h:102
void syncIteration()
Sync iteration counts to main processor.
Use whatever we have in PETSc.
Definition: MooseTypes.h:824
SERIAL
Use whatever we have in PETSc.
Definition: MooseTypes.h:836
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
Definition: MooseApp.h:178
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:714
SubProblem & _subproblem
The subproblem for whom this class holds variable data, etc; this can either be the governing finite ...
Definition: SystemBase.h:977
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
Moose::SolveType _type
Definition: SolverParams.h:19
virtual void restoreSolutions() override final
Restore current solutions (call after your solve failed)
Definition: SolverSystem.C:43
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1159
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:29
bool showInvalidSolutionConsole() const
Whether or not to print out the invalid solutions summary table in console.
const NumericVector< Number > * _current_solution
solution vector from solver
Definition: SolverSystem.h:105
const ExecFlagType EXEC_NONLINEAR
Definition: Moose.C:31
MooseApp & _app
Definition: SystemBase.h:982
FEProblemBase & _fe_problem
the governing finite element/volume problem
Definition: SystemBase.h:980
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
bool acceptInvalidSolution() const
Whether or not to accept the solution based on its invalidity.
virtual void preInit()
This is called prior to the libMesh system has been init&#39;d.
Definition: SystemBase.h:156
virtual void compute(ExecFlagType type) override
Compute time derivatives, auxiliary variables, etc.
Definition: SolverSystem.C:134
virtual void preInit() override
This is called prior to the libMesh system has been init&#39;d.
Definition: SolverSystem.C:32
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
std::unique_ptr< NumericVector< Number > > current_local_solution
const TagName SOLUTION_TAG
Definition: MooseTypes.C:25
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Moose::MooseKSPNormType _ksp_norm
KSP norm type.
Definition: SolverSystem.h:110
virtual void restoreSolutions()
Restore current solutions (call after your solve failed)
Definition: SystemBase.C:1307
virtual Real & dt() const
const ExecFlagType EXEC_FINAL
Definition: Moose.C:44
void setMooseKSPNormType(MooseEnum kspnorm)
Set the norm in which the linear convergence will be measured.
Definition: SolverSystem.C:94
virtual void localize(std::vector< T > &v_local) const=0