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 
15 #include "libmesh/numeric_vector.h"
16 
18 
21 {
23  params.addRequiredParam<Real>("scale",
24  "The scale factor for the predictor (can range from 0 to 1)");
25  params.addParam<std::vector<Real>>(
26  "skip_times", "Skip the predictor if the current solution time is in this list of times");
27  params.addParam<std::vector<Real>>(
28  "skip_times_old",
29  "Skip the predictor if the previous solution time is in this list of times");
30 
31  params.registerBase("Predictor");
32 
33  return params;
34 }
35 
37  : MooseObject(parameters),
38  Restartable(this, "Predictors"),
39  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
40  _nl(_fe_problem.getNonlinearSystemBase()),
41 
42  _t_step(_fe_problem.timeStep()),
43  _dt(_fe_problem.dt()),
44  _dt_old(_fe_problem.dtOld()),
45  _solution(*_nl.currentSolution()),
46  _solution_old(_nl.solutionOld()),
47  _solution_older(_nl.solutionOlder()),
48  _solution_predictor(_nl.addVector("predictor", true, GHOSTED)),
49  _scale(getParam<Real>("scale")),
50  _skip_times(getParam<std::vector<Real>>("skip_times")),
51  _skip_times_old(getParam<std::vector<Real>>("skip_times_old"))
52 {
53  if (_scale < 0.0 || _scale > 1.0)
54  mooseError("Input value for scale = ", _scale, " is outside of permissible range (0 to 1)");
55 }
56 
58 
59 void
61 {
62 }
63 
64 bool
66 {
67  bool should_apply = true;
68 
69  const Real & current_time = _fe_problem.time();
70  const Real & old_time = _fe_problem.timeOld();
71  for (unsigned int i = 0; i < _skip_times.size() && should_apply; ++i)
72  {
73  if (MooseUtils::absoluteFuzzyEqual(current_time, _skip_times[i]))
74  should_apply = false;
75  }
76  for (unsigned int i = 0; i < _skip_times_old.size() && should_apply; ++i)
77  {
79  should_apply = false;
80  }
81  return should_apply;
82 }
MooseObject::validParams
static InputParameters validParams()
Definition: MooseObject.C:35
FEProblemBase::timeOld
virtual Real & timeOld() const
Definition: FEProblemBase.h:441
FEProblem.h
Predictor.h
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
Predictor::_skip_times_old
std::vector< Real > _skip_times_old
Old times for which the predictor should not be applied.
Definition: Predictor.h:67
Predictor::_scale
Real _scale
Amount by which to scale the predicted value. Must be in [0,1].
Definition: Predictor.h:61
InputParameters::addParam
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.
Definition: InputParameters.h:1198
FEProblemBase::time
virtual Real & time() const
Definition: FEProblemBase.h:440
Predictor::validParams
static InputParameters validParams()
Definition: Predictor.C:20
Predictor
Base class for predictors.
Definition: Predictor.h:33
InputParameters::registerBase
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
Definition: InputParameters.C:330
MooseObject
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:50
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
NonlinearSystem.h
Predictor::_skip_times
std::vector< Real > _skip_times
Times for which the predictor should not be applied.
Definition: Predictor.h:64
Restartable
A class for creating restricted objects.
Definition: Restartable.h:29
MooseUtils::absoluteFuzzyEqual
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:234
Predictor::shouldApply
virtual bool shouldApply()
Definition: Predictor.C:65
Predictor::~Predictor
virtual ~Predictor()
Definition: Predictor.C:57
std
Definition: TheWarehouse.h:80
Predictor::Predictor
Predictor(const InputParameters &parameters)
Definition: Predictor.C:36
Predictor::timestepSetup
virtual void timestepSetup()
Definition: Predictor.C:60
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
InputParameters::addRequiredParam
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...
Definition: InputParameters.h:1176
defineLegacyParams
defineLegacyParams(Predictor)
Predictor::_fe_problem
FEProblemBase & _fe_problem
Definition: Predictor.h:49