LCOV - code coverage report
Current view: top level - src/postprocessors - ChangeOverFixedPointPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 56 60 93.3 %
Date: 2025-07-17 01:28:37 Functions: 6 6 100.0 %
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 "ChangeOverFixedPointPostprocessor.h"
      12             : #include "Transient.h"
      13             : 
      14             : registerMooseObject("MooseApp", ChangeOverFixedPointPostprocessor);
      15             : 
      16             : InputParameters
      17       14321 : ChangeOverFixedPointPostprocessor::validParams()
      18             : {
      19       14321 :   InputParameters params = GeneralPostprocessor::validParams();
      20             : 
      21       14321 :   params.addRequiredParam<PostprocessorName>("postprocessor", "The name of the postprocessor");
      22       42963 :   params.addParam<bool>("change_with_respect_to_initial",
      23       28642 :                         false,
      24             :                         "Compute change with respect to value at the beginning of the FixedPoint "
      25             :                         "iterations instead of previous value");
      26       42963 :   params.addParam<bool>(
      27       28642 :       "compute_relative_change", false, "Compute magnitude of relative change instead of change");
      28       14321 :   params.addParam<bool>("take_absolute_value", false, "Option to take absolute value of change");
      29             : 
      30       14321 :   params.addClassDescription("Computes the change or relative change in a post-processor value "
      31             :                              "over a single or multiple fixed point iterations");
      32             : 
      33       14321 :   return params;
      34           0 : }
      35             : 
      36          32 : ChangeOverFixedPointPostprocessor::ChangeOverFixedPointPostprocessor(
      37          32 :     const InputParameters & parameters)
      38             :   : GeneralPostprocessor(parameters),
      39          32 :     _change_with_respect_to_initial(getParam<bool>("change_with_respect_to_initial")),
      40          32 :     _compute_relative_change(getParam<bool>("compute_relative_change")),
      41          32 :     _take_absolute_value(getParam<bool>("take_absolute_value")),
      42          32 :     _pps_value(getPostprocessorValue("postprocessor")),
      43          32 :     _pps_value_old(0),
      44          32 :     _pps_value_initial(declareRestartableData<Real>("pps_value_initial")),
      45          32 :     _t_step_old(-1),
      46          32 :     _value(0.0)
      47             : {
      48          32 :   if (_change_with_respect_to_initial)
      49             :   {
      50             :     // ensure dependent post-processor is executed on initial
      51          20 :     const PostprocessorName & pp_name = getParam<PostprocessorName>("postprocessor");
      52          20 :     const UserObject & pp = _fe_problem.getUserObject<UserObject>(pp_name);
      53          20 :     if (!pp.getExecuteOnEnum().isValueSet(EXEC_INITIAL))
      54           4 :       mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
      55           4 :                  "the dependent post-processor ('" +
      56           4 :                  pp_name + "') must include 'initial'");
      57             : 
      58             :     // ensure THIS post-processor is executed on initial
      59          16 :     if (!_execute_enum.isValueSet(EXEC_INITIAL))
      60           4 :       mooseError("When 'change_with_respect_to_initial' is specified to be true, 'execute_on' for "
      61           4 :                  "the ChangeOverFixedPointPostprocessor ('" +
      62           8 :                  name() + "') must include 'initial'");
      63             :   }
      64          24 : }
      65             : 
      66             : void
      67         242 : ChangeOverFixedPointPostprocessor::initialize()
      68             : {
      69         242 : }
      70             : 
      71             : void
      72         242 : ChangeOverFixedPointPostprocessor::execute()
      73             : {
      74         242 : }
      75             : 
      76             : void
      77         242 : ChangeOverFixedPointPostprocessor::finalize()
      78             : {
      79             :   // detect the beginning of a new FixedPoint iteration process
      80             :   // it can either a new time step or a failed time step
      81         242 :   bool new_time_step = false;
      82         242 :   if (_app.getExecutioner()->fixedPointSolve().numFixedPointIts() == 1)
      83             :   {
      84             :     // new time step
      85          44 :     if (_t_step != _t_step_old)
      86             :     {
      87          44 :       new_time_step = true;
      88          44 :       _t_step_old = _t_step;
      89             : 
      90             :       // copy initial value in case difference is measured against initial value
      91             :       // or for a reset if the time step fails
      92          44 :       _pps_value_initial = _pps_value;
      93             :     }
      94             :     // failed time step
      95             :     else
      96           0 :       _pps_value_old = _pps_value_initial;
      97             :   }
      98             : 
      99             :   // determine value which change is measured against
     100             :   Real base_value;
     101         242 :   if (_change_with_respect_to_initial)
     102         121 :     base_value = _pps_value_initial;
     103             :   else
     104             :   {
     105             :     // for a new time step, initial value is the reference
     106         121 :     if (new_time_step)
     107          22 :       base_value = _pps_value_initial;
     108             :     else
     109          99 :       base_value = _pps_value_old;
     110             :   }
     111             : 
     112             :   // Update previous value
     113         242 :   _pps_value_old = _pps_value;
     114             : 
     115             :   // compute change in value
     116             :   Real change;
     117         242 :   if (_compute_relative_change)
     118           0 :     change = (_pps_value - base_value) / base_value;
     119             :   else
     120         242 :     change = _pps_value - base_value;
     121             : 
     122         242 :   if (_take_absolute_value)
     123           0 :     _value = std::fabs(change);
     124             :   else
     125         242 :     _value = change;
     126         242 : }
     127             : 
     128             : Real
     129         242 : ChangeOverFixedPointPostprocessor::getValue() const
     130             : {
     131         242 :   return _value;
     132             : }

Generated by: LCOV version 1.14