LCOV - code coverage report
Current view: top level - src/auxkernels - ElementH1ErrorFunctionAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 23 25 92.0 %
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 "ElementH1ErrorFunctionAux.h"
      12             : #include "Function.h"
      13             : 
      14             : #include "libmesh/quadrature.h"
      15             : 
      16             : registerMooseObject("MooseApp", ElementH1ErrorFunctionAux);
      17             : 
      18             : InputParameters
      19       14292 : ElementH1ErrorFunctionAux::validParams()
      20             : {
      21       14292 :   InputParameters params = ElementL2ErrorFunctionAux::validParams();
      22       14292 :   params.addClassDescription(
      23             :       "Computes the H1 or W^{1,p} error between an exact function and a coupled variable.");
      24             : 
      25       14292 :   return params;
      26           0 : }
      27             : 
      28          14 : ElementH1ErrorFunctionAux::ElementH1ErrorFunctionAux(const InputParameters & parameters)
      29          14 :   : ElementL2ErrorFunctionAux(parameters), _grad_coupled_var(coupledGradient("coupled_variable"))
      30             : {
      31          14 : }
      32             : 
      33             : void
      34       50400 : ElementH1ErrorFunctionAux::compute()
      35             : {
      36       50400 :   precalculateValue();
      37             : 
      38       50400 :   if (isNodal())
      39           0 :     mooseError("ElementH1ErrorFunctionAux only makes sense as an Elemental AuxVariable.");
      40             : 
      41       50400 :   Real summed_value = 0;
      42      252000 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      43             :   {
      44      201600 :     Real val = computeValue(); // already raised to the p, see below.
      45      201600 :     summed_value += _JxW[_qp] * _coord[_qp] * val;
      46             :   }
      47             : 
      48       50400 :   _var.setNodalValue(std::pow(summed_value, 1. / _p));
      49       50400 : }
      50             : 
      51             : Real
      52      201600 : ElementH1ErrorFunctionAux::computeValue()
      53             : {
      54      201600 :   RealGradient graddiff = _func.gradient(_t, _q_point[_qp]) - _grad_coupled_var[_qp];
      55      201600 :   Real funcdiff = _func.value(_t, _q_point[_qp]) - _coupled_var[_qp];
      56             : 
      57             :   // Raise the absolute function value difference to the pth power
      58      201600 :   Real val = std::pow(std::abs(funcdiff), _p);
      59             : 
      60             :   // Add all of the absolute gradient component differences to the pth power
      61      806400 :   for (const auto i : make_range(Moose::dim))
      62      604800 :     val += std::pow(std::abs(graddiff(i)), _p);
      63             : 
      64      201600 :   return val;
      65             : }

Generated by: LCOV version 1.14