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>("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<TransientBase *>(_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
68void
70{
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)
77
79}
80
81bool
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 {
94 if (MooseUtils::absoluteFuzzyEqual(current_time, _skip_times[i], _timestep_tolerance))
95 should_apply = false;
96 }
97 for (unsigned int i = 0; i < _skip_times_old.size() && should_apply; ++i)
98 {
99 if (MooseUtils::absoluteFuzzyEqual(old_time, _skip_times_old[i], _timestep_tolerance))
100 should_apply = false;
101 }
102 return should_apply;
103}
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 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:66
FEProblemBase & _fe_problem
Definition Predictor.h:44
virtual bool shouldApply()
Definition Predictor.C:82
std::vector< Real > _skip_times_old
Old times for which the predictor should not be applied.
Definition Predictor.h:64
std::vector< Real > _skip_times
Times for which the predictor should not be applied.
Definition Predictor.h:61
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:58
Predictor(const InputParameters &parameters)
Definition Predictor.C:41
const Real & _timestep_tolerance
Timestep tolerance from Transient executioner.
Definition Predictor.h:70
const bool & _skip_after_failed_timetep
Option to skip prediction after a failed timestep.
Definition Predictor.h:67
static InputParameters validParams()
Definition Predictor.C:19
virtual void timestepSetup()
Definition Predictor.C:69
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...