LCOV - code coverage report
Current view: top level - src/auxkernels - ElementLpNormAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 20 22 90.9 %
Date: 2025-08-08 20:01:16 Functions: 4 4 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 "ElementLpNormAux.h"
      12             : 
      13             : #include "libmesh/quadrature.h"
      14             : 
      15             : registerMooseObject("MooseApp", ElementLpNormAux);
      16             : 
      17             : InputParameters
      18       42902 : ElementLpNormAux::validParams()
      19             : {
      20       42902 :   InputParameters params = AuxKernel::validParams();
      21       42902 :   params.addClassDescription("Compute an elemental field variable (single value per element) equal "
      22             :                              "to the Lp-norm of a coupled Variable.");
      23       42902 :   params.addRangeCheckedParam<Real>("p", 2.0, "p>=1", "The exponent used in the norm.");
      24       42902 :   params.addRequiredCoupledVar("coupled_variable", "The variable to compute the norm of.");
      25       42902 :   return params;
      26           0 : }
      27             : 
      28          55 : ElementLpNormAux::ElementLpNormAux(const InputParameters & parameters)
      29          55 :   : AuxKernel(parameters), _p(getParam<Real>("p")), _coupled_var(coupledValue("coupled_variable"))
      30             : {
      31          55 :   if (mooseVariableBase()->feType() != libMesh::FEType(CONSTANT, MONOMIAL))
      32           0 :     paramError("variable", "Must be of type CONSTANT MONOMIAL");
      33          55 : }
      34             : 
      35             : void
      36      100827 : ElementLpNormAux::compute()
      37             : {
      38      100827 :   precalculateValue();
      39             : 
      40             :   // Sum up the squared-error values by calling computeValue(), then
      41             :   // return the sqrt of the result.
      42      100827 :   Real summed_value = 0;
      43      504135 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      44             :   {
      45      403308 :     Real val = computeValue();
      46      403308 :     summed_value += _JxW[_qp] * _coord[_qp] * std::pow(std::abs(val), _p);
      47             :   }
      48             : 
      49      100827 :   _var.setDofValue(std::pow(summed_value, 1. / _p), 0);
      50      100827 : }
      51             : 
      52             : Real
      53      201708 : ElementLpNormAux::computeValue()
      54             : {
      55      201708 :   return _coupled_var[_qp];
      56             : }

Generated by: LCOV version 1.14