www.mooseframework.org
Predictor.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // MOOSE includes
11 #include "Predictor.h"
12 #include "NonlinearSystem.h"
13 #include "FEProblem.h"
14 #include "Transient.h"
15 
16 #include "libmesh/numeric_vector.h"
17 
20 {
22  params.addRequiredParam<Real>("scale",
23  "The scale factor for the predictor (can range from 0 to 1)");
24  params.addParam<std::vector<Real>>(
25  "skip_times", {}, "Skip the predictor if the current solution time is in this list of times");
26  params.addParam<std::vector<Real>>(
27  "skip_times_old",
28  {},
29  "Skip the predictor if the previous solution time is in this list of times");
30  params.addParam<bool>("skip_after_failed_timestep",
31  false,
32  "Skip prediction in a repeated time step after a failed time step");
33  params.addParam<NonlinearSystemName>(
34  "nl_sys", "nl0", "The nonlinear system that this predictor should be applied to.");
35 
36  params.registerBase("Predictor");
37 
38  return params;
39 }
40 
42  : MooseObject(parameters),
43  Restartable(this, "Predictors"),
44  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
45  _nl(_fe_problem.getNonlinearSystemBase(
46  _fe_problem.nlSysNum(getParam<NonlinearSystemName>("nl_sys")))),
47  _t_step(_fe_problem.timeStep()),
48  _dt(_fe_problem.dt()),
49  _dt_old(_fe_problem.dtOld()),
50  _solution(*_nl.currentSolution()),
51  _solution_old(_nl.solutionOld()),
52  _solution_older(_nl.solutionOlder()),
53  _solution_predictor(_nl.addVector("predictor", true, GHOSTED)),
54  _t_step_old(declareRestartableData<int>("t_step_old", 0)),
55  _is_repeated_timestep(declareRestartableData<bool>("is_repeated_timestep", false)),
56  _scale(getParam<Real>("scale")),
57  _skip_times(getParam<std::vector<Real>>("skip_times")),
58  _skip_times_old(getParam<std::vector<Real>>("skip_times_old")),
59  _skip_after_failed_timetep(getParam<bool>("skip_after_failed_timestep")),
60  _timestep_tolerance(dynamic_cast<Transient *>(_app.getExecutioner())->timestepTol())
61 {
62  if (_scale < 0.0 || _scale > 1.0)
63  mooseError("Input value for scale = ", _scale, " is outside of permissible range (0 to 1)");
64 }
65 
67 
68 void
70 {
71  _is_repeated_timestep = false;
72 
73  // if the time step number hasn't changed
74  // we are recomputing a failed time step
75  if (_t_step == _t_step_old)
76  _is_repeated_timestep = true;
77 
79 }
80 
81 bool
83 {
84  bool should_apply = true;
85 
86  // if no prediction in a repeated timestep should be made
88  should_apply = false;
89 
90  const Real & current_time = _fe_problem.time();
91  const Real & old_time = _fe_problem.timeOld();
92  for (unsigned int i = 0; i < _skip_times.size() && should_apply; ++i)
93  {
95  should_apply = false;
96  }
97  for (unsigned int i = 0; i < _skip_times_old.size() && should_apply; ++i)
98  {
100  should_apply = false;
101  }
102  return should_apply;
103 }
Transient executioners usually loop through a number of timesteps...
Definition: Transient.h:26
A class for creating restricted objects.
Definition: Restartable.h:28
virtual Real & time() const
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:346
std::vector< Real > _skip_times
Times for which the predictor should not be applied.
Definition: Predictor.h:61
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
virtual void timestepSetup()
Definition: Predictor.C:69
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
const Real & _timestep_tolerance
Timestep tolerance from Transient executioner.
Definition: Predictor.h:70
GHOSTED
const bool & _skip_after_failed_timetep
Option to skip prediction after a failed timestep.
Definition: Predictor.h:67
int & _t_step_old
Definition: Predictor.h:54
static InputParameters validParams()
Definition: Predictor.C:19
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
Real _scale
Amount by which to scale the predicted value. Must be in [0,1].
Definition: Predictor.h:58
FEProblemBase & _fe_problem
Definition: Predictor.h:44
virtual Real & timeOld() const
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
bool & _is_repeated_timestep
Definition: Predictor.h:55
virtual ~Predictor()
Definition: Predictor.C:66
std::vector< Real > _skip_times_old
Old times for which the predictor should not be applied.
Definition: Predictor.h:64
static InputParameters validParams()
Definition: MooseObject.C:24
int & _t_step
Definition: Predictor.h:47
virtual bool shouldApply()
Definition: Predictor.C:82
void ErrorVector unsigned int
Predictor(const InputParameters &parameters)
Definition: Predictor.C:41