www.mooseframework.org
SimplePredictor.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 #include "SimplePredictor.h"
11 #include "NonlinearSystem.h"
12 
14 
15 template <>
18 {
20 
21  return params;
22 }
23 
24 SimplePredictor::SimplePredictor(const InputParameters & parameters) : Predictor(parameters) {}
25 
26 bool
28 {
29  bool should_apply = true;
30  should_apply = Predictor::shouldApply();
31 
32  if (_t_step < 2 || _dt_old <= 0)
33  should_apply = false;
34 
35  if (!should_apply)
36  _console << " Skipping predictor this step" << std::endl;
37 
38  return should_apply;
39 }
40 
41 void
42 SimplePredictor::apply(NumericVector<Number> & sln)
43 {
44  // Save the original stream flags
45  std::ios_base::fmtflags out_flags = Moose::out.flags();
46 
47  _console << " Applying predictor with scale factor = " << std::fixed << std::setprecision(2)
48  << _scale << std::endl;
49 
50  // Restore the flags
51  Moose::out.flags(out_flags);
52 
53  Real dt_adjusted_scale_factor = _scale * _dt / _dt_old;
54  if (dt_adjusted_scale_factor != 0.0)
55  {
56  sln *= (1.0 + dt_adjusted_scale_factor);
57  sln.add(-dt_adjusted_scale_factor, _solution_older);
58  }
59 }
Base class for predictors.
Definition: Predictor.h:33
registerMooseObject("MooseApp", SimplePredictor)
virtual bool shouldApply() override
SimplePredictor(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Real & _dt_old
Definition: Predictor.h:52
A SimplePredictor uses an algorithm that will predict the next solution based on previous solutions...
NumericVector< Number > & _solution_older
Definition: Predictor.h:55
virtual void apply(NumericVector< Number > &sln) override
InputParameters validParams< SimplePredictor >()
InputParameters validParams< Predictor >()
Definition: Predictor.C:19
Real & _dt
Definition: Predictor.h:51
Real _scale
Amount by which to scale the predicted value. Must be in [0,1].
Definition: Predictor.h:59
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
int & _t_step
Definition: Predictor.h:50
virtual bool shouldApply()
Definition: Predictor.C:64