LCOV - code coverage report
Current view: top level - src/postprocessors - AverageVariableChange.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 38 38 100.0 %
Date: 2025-07-17 01:28:37 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       14465 : AverageVariableChange::validParams()
      17             : {
      18       14465 :   InputParameters params = ElementIntegralVariablePostprocessor::validParams();
      19             : 
      20       14465 :   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       14465 :   MooseEnum change_over("time_step nonlinear_iteration");
      24       14465 :   params.addRequiredParam<MooseEnum>(
      25             :       "change_over", change_over, "Interval over which to compute the change");
      26             : 
      27       14465 :   MooseEnum norm("L1 L2");
      28       14465 :   params.addRequiredParam<MooseEnum>("norm", norm, "Type of norm to compute");
      29             : 
      30       28930 :   return params;
      31       14465 : }
      32             : 
      33         104 : AverageVariableChange::AverageVariableChange(const InputParameters & parameters)
      34             :   : ElementIntegralVariablePostprocessor(parameters),
      35         104 :     _change_over(getParam<MooseEnum>("change_over")),
      36         208 :     _u_change_old(_change_over == "time_step" ? coupledValueOld("variable")
      37         104 :                                               : coupledValuePreviousNL("variable")),
      38         104 :     _norm(getParam<MooseEnum>("norm")),
      39         104 :     _norm_exponent(_norm == "L1" ? 1 : 2),
      40         104 :     _volume(0)
      41             : {
      42         104 : }
      43             : 
      44             : void
      45         660 : AverageVariableChange::initialize()
      46             : {
      47         660 :   ElementIntegralVariablePostprocessor::initialize();
      48         660 :   _volume = 0;
      49         660 : }
      50             : 
      51             : void
      52       44000 : AverageVariableChange::execute()
      53             : {
      54       44000 :   ElementIntegralVariablePostprocessor::execute();
      55       44000 :   _volume += _current_elem_volume;
      56       44000 : }
      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         605 : AverageVariableChange::finalize()
      68             : {
      69         605 :   gatherSum(_volume);
      70         605 :   gatherSum(_integral_value);
      71         605 : }
      72             : 
      73             : Real
      74         605 : AverageVariableChange::getValue() const
      75             : {
      76             :   mooseAssert(!MooseUtils::absoluteFuzzyEqual(_volume, 0.0), "Volume must be nonzero.");
      77         605 :   return std::pow(_integral_value / _volume, 1.0 / _norm_exponent);
      78             : }
      79             : 
      80             : Real
      81      176000 : AverageVariableChange::computeQpIntegral()
      82             : {
      83      176000 :   return std::pow(std::abs(_u[_qp] - _u_change_old[_qp]), _norm_exponent);
      84             : }

Generated by: LCOV version 1.14