https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Predictor.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// 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>("apply", true, "Whether to apply the prediction.");
31 params.declareControllable("apply");
32 params.addParam<bool>("skip_after_failed_timestep",
33 false,
34 "Skip prediction in a repeated time step after a failed time step");
35 params.addParam<NonlinearSystemName>(
36 "nl_sys", "nl0", "The nonlinear system that this predictor should be applied to.");
37
38 params.registerBase("Predictor");
39
40 return params;
41}
42
44 : MooseObject(parameters),
45 Restartable(this, "Predictors"),
46 _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
47 _nl(_fe_problem.getNonlinearSystemBase(
48 _fe_problem.nlSysNum(getParam<NonlinearSystemName>("nl_sys")))),
49 _t_step(_fe_problem.timeStep()),
50 _dt(_fe_problem.dt()),
51 _dt_old(_fe_problem.dtOld()),
52 _solution(*_nl.currentSolution()),
53 _solution_old(_nl.solutionOld()),
54 _solution_older(_nl.solutionOlder()),
55 _solution_predictor(_nl.addVector("predictor", true, GHOSTED)),
56 _t_step_old(declareRestartableData<int>("t_step_old", 0)),
57 _is_repeated_timestep(declareRestartableData<bool>("is_repeated_timestep", false)),
58 _apply(getParam<bool>("apply")),
59 _scale(getParam<Real>("scale")),
60 _skip_times(getParam<std::vector<Real>>("skip_times")),
61 _skip_times_old(getParam<std::vector<Real>>("skip_times_old")),
62 _skip_after_failed_timetep(getParam<bool>("skip_after_failed_timestep")),
63 _timestep_tolerance(dynamic_cast<TransientBase *>(_app.getExecutioner())->timestepTol())
64{
65 if (_scale < 0.0 || _scale > 1.0)
66 mooseError("Input value for scale = ", _scale, " is outside of permissible range (0 to 1)");
67}
68
70
71void
73{
75
76 // if the time step number hasn't changed
77 // we are recomputing a failed time step
78 if (_t_step == _t_step_old)
80
82}
83
84bool
86{
87 // 'apply' is controllable, so that Controls can turn the prediction off
88 bool should_apply = _apply;
89
90 // if no prediction in a repeated timestep should be made
92 should_apply = false;
93
94 const Real & current_time = _fe_problem.time();
95 const Real & old_time = _fe_problem.timeOld();
96 for (unsigned int i = 0; i < _skip_times.size() && should_apply; ++i)
97 {
98 if (MooseUtils::absoluteFuzzyEqual(current_time, _skip_times[i], _timestep_tolerance))
99 should_apply = false;
100 }
101 for (unsigned int i = 0; i < _skip_times_old.size() && should_apply; ++i)
102 {
103 if (MooseUtils::absoluteFuzzyEqual(old_time, _skip_times_old[i], _timestep_tolerance))
104 should_apply = false;
105 }
106 return should_apply;
107}
void ErrorVector unsigned int
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual Real & timeOld() const
virtual Real & time() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
static InputParameters validParams()
Definition MooseObject.C:25
virtual ~Predictor()
Definition Predictor.C:69
FEProblemBase & _fe_problem
Definition Predictor.h:44
virtual bool shouldApply()
Definition Predictor.C:85
std::vector< Real > _skip_times_old
Old times for which the predictor should not be applied.
Definition Predictor.h:67
const bool & _apply
Whether to apply the prediction (controllable)
Definition Predictor.h:58
std::vector< Real > _skip_times
Times for which the predictor should not be applied.
Definition Predictor.h:64
bool & _is_repeated_timestep
Definition Predictor.h:55
Real _scale
Amount by which to scale the predicted value. Must be in [0,1].
Definition Predictor.h:61
Predictor(const InputParameters &parameters)
Definition Predictor.C:43
const Real & _timestep_tolerance
Timestep tolerance from Transient executioner.
Definition Predictor.h:73
const bool & _skip_after_failed_timetep
Option to skip prediction after a failed timestep.
Definition Predictor.h:70
static InputParameters validParams()
Definition Predictor.C:19
virtual void timestepSetup()
Definition Predictor.C:72
int & _t_step
Definition Predictor.h:47
int & _t_step_old
Definition Predictor.h:54
A class for creating restricted objects.
Definition Restartable.h:29
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...