LCOV - code coverage report
Current view: top level - src/postprocessors - ElementW1pError.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 19 20 95.0 %
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             : #include "ElementW1pError.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("MooseApp", ElementW1pError);
      14             : 
      15             : InputParameters
      16       29400 : ElementW1pError::validParams()
      17             : {
      18       29400 :   InputParameters params = ElementIntegralVariablePostprocessor::validParams();
      19       29400 :   params.addRangeCheckedParam<Real>("p", 2.0, "p>=1", "The exponent used in the norm.");
      20       29400 :   params.addRequiredParam<FunctionName>("function", "The analytic solution to compare against");
      21       29400 :   params.addClassDescription("Computes the W1p norm of the difference between a variable and an "
      22             :                              "analytic solution, as a function");
      23       29400 :   return params;
      24           0 : }
      25             : 
      26         451 : ElementW1pError::ElementW1pError(const InputParameters & parameters)
      27             :   : ElementIntegralVariablePostprocessor(parameters),
      28         451 :     _p(getParam<Real>("p")),
      29         902 :     _func(getFunction("function"))
      30             : {
      31         451 : }
      32             : 
      33             : Real
      34         606 : ElementW1pError::getValue() const
      35             : {
      36         606 :   return std::pow(ElementIntegralPostprocessor::getValue(), 1. / _p);
      37             : }
      38             : 
      39             : Real
      40     1391438 : ElementW1pError::computeQpIntegral()
      41             : {
      42     1391438 :   RealGradient graddiff = _grad_u[_qp] - _func.gradient(_t, _q_point[_qp]);
      43     1391438 :   Real funcdiff = _u[_qp] - _func.value(_t, _q_point[_qp]);
      44             : 
      45             :   // Raise the absolute function value difference to the pth power
      46     1391438 :   Real val = std::pow(std::abs(funcdiff), _p);
      47             : 
      48             :   // Add all of the absolute gradient component differences to the pth power
      49     5565752 :   for (const auto i : make_range(Moose::dim))
      50     4174314 :     val += std::pow(std::abs(graddiff(i)), _p);
      51             : 
      52     1391438 :   return val;
      53             : }

Generated by: LCOV version 1.14