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
18using namespace libMesh;
19
22{
24 params.addRequiredParam<Real>("scale",
25 "The scale factor for the predictor (can range from 0 to 1)");
26 params.addParam<std::vector<Real>>(
27 "skip_times", {}, "Skip the predictor if the current solution time is in this list of times");
28 params.addParam<std::vector<Real>>(
29 "skip_times_old",
30 {},
31 "Skip the predictor if the previous solution time is in this list of times");
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 _scale(getParam<Real>("scale")),
59 _skip_times(getParam<std::vector<Real>>("skip_times")),
60 _skip_times_old(getParam<std::vector<Real>>("skip_times_old")),
61 _skip_after_failed_timetep(getParam<bool>("skip_after_failed_timestep")),
62 _timestep_tolerance(dynamic_cast<TransientBase *>(_app.getExecutioner())->timestepTol())
63{
64 if (_scale < 0.0 || _scale > 1.0)
65 mooseError("Input value for scale = ", _scale, " is outside of permissible range (0 to 1)");
66}
67
69
70void
72{
74
75 // if the time step number hasn't changed
76 // we are recomputing a failed time step
77 if (_t_step == _t_step_old)
79
81}
82
83bool
85{
86 bool should_apply = true;
87
88 // if no prediction in a repeated timestep should be made
90 should_apply = false;
91
92 const Real & current_time = _fe_problem.time();
93 const Real & old_time = _fe_problem.timeOld();
94 for (unsigned int i = 0; i < _skip_times.size() && should_apply; ++i)
95 {
96 if (MooseUtils::absoluteFuzzyEqual(current_time, _skip_times[i], _timestep_tolerance))
97 should_apply = false;
98 }
99 for (unsigned int i = 0; i < _skip_times_old.size() && should_apply; ++i)
100 {
101 if (MooseUtils::absoluteFuzzyEqual(old_time, _skip_times_old[i], _timestep_tolerance))
102 should_apply = false;
103 }
104 return should_apply;
105}
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:68
FEProblemBase & _fe_problem
Definition Predictor.h:44
virtual bool shouldApply()
Definition Predictor.C:84
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:43
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:21
virtual void timestepSetup()
Definition Predictor.C:71
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...
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