LCOV - code coverage report
Current view: top level - src/predictors - Predictor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 50 52 96.2 %
Date: 2025-07-17 01:28:37 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14