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

Generated by: LCOV version 1.14