Line data Source code
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 : 18 : using namespace libMesh; 19 : 20 : InputParameters 21 28772 : Predictor::validParams() 22 : { 23 28772 : InputParameters params = MooseObject::validParams(); 24 28772 : params.addRequiredParam<Real>("scale", 25 : "The scale factor for the predictor (can range from 0 to 1)"); 26 28772 : params.addParam<std::vector<Real>>( 27 : "skip_times", {}, "Skip the predictor if the current solution time is in this list of times"); 28 28772 : 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 86316 : params.addParam<bool>("skip_after_failed_timestep", 33 57544 : false, 34 : "Skip prediction in a repeated time step after a failed time step"); 35 28772 : params.addParam<NonlinearSystemName>( 36 : "nl_sys", "nl0", "The nonlinear system that this predictor should be applied to."); 37 : 38 28772 : params.registerBase("Predictor"); 39 : 40 28772 : return params; 41 0 : } 42 : 43 121 : Predictor::Predictor(const InputParameters & parameters) 44 : : MooseObject(parameters), 45 : Restartable(this, "Predictors"), 46 121 : _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")), 47 121 : _nl(_fe_problem.getNonlinearSystemBase( 48 121 : _fe_problem.nlSysNum(getParam<NonlinearSystemName>("nl_sys")))), 49 121 : _t_step(_fe_problem.timeStep()), 50 121 : _dt(_fe_problem.dt()), 51 121 : _dt_old(_fe_problem.dtOld()), 52 121 : _solution(*_nl.currentSolution()), 53 121 : _solution_old(_nl.solutionOld()), 54 121 : _solution_older(_nl.solutionOlder()), 55 121 : _solution_predictor(_nl.addVector("predictor", true, GHOSTED)), 56 121 : _t_step_old(declareRestartableData<int>("t_step_old", 0)), 57 121 : _is_repeated_timestep(declareRestartableData<bool>("is_repeated_timestep", false)), 58 121 : _scale(getParam<Real>("scale")), 59 121 : _skip_times(getParam<std::vector<Real>>("skip_times")), 60 121 : _skip_times_old(getParam<std::vector<Real>>("skip_times_old")), 61 121 : _skip_after_failed_timetep(getParam<bool>("skip_after_failed_timestep")), 62 242 : _timestep_tolerance(dynamic_cast<TransientBase *>(_app.getExecutioner())->timestepTol()) 63 : { 64 121 : if (_scale < 0.0 || _scale > 1.0) 65 0 : mooseError("Input value for scale = ", _scale, " is outside of permissible range (0 to 1)"); 66 121 : } 67 : 68 121 : Predictor::~Predictor() {} 69 : 70 : void 71 387 : Predictor::timestepSetup() 72 : { 73 387 : _is_repeated_timestep = false; 74 : 75 : // if the time step number hasn't changed 76 : // we are recomputing a failed time step 77 387 : if (_t_step == _t_step_old) 78 16 : _is_repeated_timestep = true; 79 : 80 387 : _t_step_old = _t_step; 81 387 : } 82 : 83 : bool 84 387 : Predictor::shouldApply() 85 : { 86 387 : bool should_apply = true; 87 : 88 : // if no prediction in a repeated timestep should be made 89 387 : if (_is_repeated_timestep && _skip_after_failed_timetep) 90 11 : should_apply = false; 91 : 92 387 : const Real & current_time = _fe_problem.time(); 93 387 : const Real & old_time = _fe_problem.timeOld(); 94 437 : for (unsigned int i = 0; i < _skip_times.size() && should_apply; ++i) 95 : { 96 50 : if (MooseUtils::absoluteFuzzyEqual(current_time, _skip_times[i], _timestep_tolerance)) 97 24 : should_apply = false; 98 : } 99 424 : for (unsigned int i = 0; i < _skip_times_old.size() && should_apply; ++i) 100 : { 101 37 : if (MooseUtils::absoluteFuzzyEqual(old_time, _skip_times_old[i], _timestep_tolerance)) 102 12 : should_apply = false; 103 : } 104 387 : return should_apply; 105 : }