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 
17 template <>
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  "Skip the predictor if the previous solution time is in this list of times");
29 
30  params.registerBase("Predictor");
31 
32  return params;
33 }
34 
36  : MooseObject(parameters),
37  Restartable(this, "Predictors"),
38  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
39  _nl(_fe_problem.getNonlinearSystemBase()),
40 
41  _t_step(_fe_problem.timeStep()),
42  _dt(_fe_problem.dt()),
43  _dt_old(_fe_problem.dtOld()),
44  _solution(*_nl.currentSolution()),
45  _solution_old(_nl.solutionOld()),
46  _solution_older(_nl.solutionOlder()),
47  _solution_predictor(_nl.addVector("predictor", true, GHOSTED)),
48  _scale(getParam<Real>("scale")),
49  _skip_times(getParam<std::vector<Real>>("skip_times")),
50  _skip_times_old(getParam<std::vector<Real>>("skip_times_old"))
51 {
52  if (_scale < 0.0 || _scale > 1.0)
53  mooseError("Input value for scale = ", _scale, " is outside of permissible range (0 to 1)");
54 }
55 
57 
58 void
60 {
61 }
62 
63 bool
65 {
66  bool should_apply = true;
67 
68  const Real & current_time = _fe_problem.time();
69  const Real & old_time = _fe_problem.timeOld();
70  for (unsigned int i = 0; i < _skip_times.size() && should_apply; ++i)
71  {
72  if (MooseUtils::absoluteFuzzyEqual(current_time, _skip_times[i]))
73  should_apply = false;
74  }
75  for (unsigned int i = 0; i < _skip_times_old.size() && should_apply; ++i)
76  {
78  should_apply = false;
79  }
80  return should_apply;
81 }
A class for creating restricted objects.
Definition: Restartable.h:29
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:231
std::vector< Real > _skip_times
Times for which the predictor should not be applied.
Definition: Predictor.h:62
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
InputParameters validParams< Predictor >()
Definition: Predictor.C:19
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:59
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:25
Real _scale
Amount by which to scale the predicted value. Must be in [0,1].
Definition: Predictor.h:59
FEProblemBase & _fe_problem
Definition: Predictor.h:47
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...
virtual ~Predictor()
Definition: Predictor.C:56
std::vector< Real > _skip_times_old
Old times for which the predictor should not be applied.
Definition: Predictor.h:65
virtual bool shouldApply()
Definition: Predictor.C:64
Predictor(const InputParameters &parameters)
Definition: Predictor.C:35