LCOV - code coverage report
Current view: top level - src/postprocessors - AverageVariableChange.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 38 38 100.0 %
Date: 2025-08-08 20:01:16 Functions: 8 8 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             : #include "AverageVariableChange.h"
      11             : #include "MooseUtils.h"
      12             : 
      13             : registerMooseObject("MooseApp", AverageVariableChange);
      14             : 
      15             : InputParameters
      16       14473 : AverageVariableChange::validParams()
      17             : {
      18       14473 :   InputParameters params = ElementIntegralVariablePostprocessor::validParams();
      19             : 
      20       14473 :   params.addClassDescription("Computes the volume-weighted L1 or L2 norm of the change of a "
      21             :                              "variable over a time step or between nonlinear iterations.");
      22             : 
      23       14473 :   MooseEnum change_over("time_step nonlinear_iteration");
      24       14473 :   params.addRequiredParam<MooseEnum>(
      25             :       "change_over", change_over, "Interval over which to compute the change");
      26             : 
      27       14473 :   MooseEnum norm("L1 L2");
      28       14473 :   params.addRequiredParam<MooseEnum>("norm", norm, "Type of norm to compute");
      29             : 
      30       28946 :   return params;
      31       14473 : }
      32             : 
      33         108 : AverageVariableChange::AverageVariableChange(const InputParameters & parameters)
      34             :   : ElementIntegralVariablePostprocessor(parameters),
      35         108 :     _change_over(getParam<MooseEnum>("change_over")),
      36         216 :     _u_change_old(_change_over == "time_step" ? coupledValueOld("variable")
      37         108 :                                               : coupledValuePreviousNL("variable")),
      38         108 :     _norm(getParam<MooseEnum>("norm")),
      39         108 :     _norm_exponent(_norm == "L1" ? 1 : 2),
      40         108 :     _volume(0)
      41             : {
      42         108 : }
      43             : 
      44             : void
      45         679 : AverageVariableChange::initialize()
      46             : {
      47         679 :   ElementIntegralVariablePostprocessor::initialize();
      48         679 :   _volume = 0;
      49         679 : }
      50             : 
      51             : void
      52       45900 : AverageVariableChange::execute()
      53             : {
      54       45900 :   ElementIntegralVariablePostprocessor::execute();
      55       45900 :   _volume += _current_elem_volume;
      56       45900 : }
      57             : 
      58             : void
      59          55 : AverageVariableChange::threadJoin(const UserObject & y)
      60             : {
      61          55 :   ElementIntegralVariablePostprocessor::threadJoin(y);
      62          55 :   const auto & pps = static_cast<const AverageVariableChange &>(y);
      63          55 :   _volume += pps._volume;
      64          55 : }
      65             : 
      66             : void
      67         624 : AverageVariableChange::finalize()
      68             : {
      69         624 :   gatherSum(_volume);
      70         624 :   gatherSum(_integral_value);
      71         624 : }
      72             : 
      73             : Real
      74         624 : AverageVariableChange::getValue() const
      75             : {
      76             :   mooseAssert(!MooseUtils::absoluteFuzzyEqual(_volume, 0.0), "Volume must be nonzero.");
      77         624 :   return std::pow(_integral_value / _volume, 1.0 / _norm_exponent);
      78             : }
      79             : 
      80             : Real
      81      183600 : AverageVariableChange::computeQpIntegral()
      82             : {
      83      183600 :   return std::pow(std::abs(_u[_qp] - _u_change_old[_qp]), _norm_exponent);
      84             : }

Generated by: LCOV version 1.14