LCOV - code coverage report
Current view: top level - src/postprocessors - ElementVectorL2Error.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 45 50 90.0 %
Date: 2026-05-29 20:35:17 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 "ElementVectorL2Error.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("MooseApp", ElementVectorL2Error);
      14             : 
      15             : InputParameters
      16       16380 : ElementVectorL2Error::validParams()
      17             : {
      18       16380 :   InputParameters params = ElementIntegralPostprocessor::validParams();
      19       32760 :   params.addClassDescription("Returns the L2-norm of the difference between a pair of computed "
      20             :                              "and analytical vector-valued solutions.");
      21       65520 :   params.addParam<FunctionName>("function", 0, "The vector analytical solution to compare against");
      22       49140 :   params.addParam<FunctionName>(
      23       32760 :       "function_x", 0, "The analytical solution to compare against in the x direction");
      24       49140 :   params.addParam<FunctionName>(
      25       32760 :       "function_y", 0, "The analytical solution to compare against in the y direction");
      26       49140 :   params.addParam<FunctionName>(
      27       32760 :       "function_z", 0, "The analytical solution to compare against in the z direction");
      28       98280 :   params.addCoupledVar("variable", {0, 0, 0}, "The vector FE solution");
      29       65520 :   params.addCoupledVar("var_x", 0, "The FE solution in the x direction");
      30       65520 :   params.addCoupledVar("var_y", 0, "The FE solution in the y direction");
      31       49140 :   params.addCoupledVar("var_z", 0, "The FE solution in the z direction");
      32       16380 :   return params;
      33           0 : }
      34             : 
      35         559 : ElementVectorL2Error::ElementVectorL2Error(const InputParameters & parameters)
      36             :   : ElementIntegralPostprocessor(parameters),
      37         559 :     _func(getFunction("function")),
      38        1118 :     _funcx(getFunction("function_x")),
      39        1118 :     _funcy(getFunction("function_y")),
      40        1118 :     _funcz(getFunction("function_z")),
      41        1118 :     _u(coupledVectorValue("variable")),
      42        1118 :     _ux(coupledValue("var_x")),
      43        1118 :     _uy(coupledValue("var_y")),
      44        1118 :     _uz(coupledValue("var_z")),
      45        1118 :     _has_vector_function(isParamSetByUser("function")),
      46        3315 :     _has_scalar_function(isParamSetByUser("function_x") || isParamSetByUser("function_y") ||
      47        2197 :                          isParamSetByUser("function_z")),
      48        1118 :     _has_vector_variable(isParamSetByUser("variable")),
      49        3315 :     _has_scalar_variable(isParamSetByUser("var_x") || isParamSetByUser("var_y") ||
      50        2756 :                          isParamSetByUser("var_z"))
      51             : {
      52         559 :   if (!_has_vector_function && !_has_scalar_function)
      53           0 :     paramError("function",
      54             :                "The 'function' and 'function_{x,y,z}' parameters cannot both be unset.");
      55             : 
      56         559 :   if (_has_vector_function && _has_scalar_function)
      57           0 :     paramError("function", "The 'function' and 'function_{x,y,z}' parameters cannot both be set.");
      58             : 
      59         559 :   if (!_has_vector_variable && !_has_scalar_variable)
      60           0 :     paramError("variable", "The 'variable' and 'var_{x,y,z}' parameters cannot both be unset.");
      61             : 
      62         559 :   if (_has_vector_variable && _has_scalar_variable)
      63           0 :     paramError("variable", "The 'variable' and 'var_{x,y,z}' parameters cannot both be set.");
      64         559 : }
      65             : 
      66             : Real
      67         517 : ElementVectorL2Error::getValue() const
      68             : {
      69         517 :   return std::sqrt(ElementIntegralPostprocessor::getValue());
      70             : }
      71             : 
      72             : Real
      73      709440 : ElementVectorL2Error::computeQpIntegral()
      74             : {
      75      709440 :   RealVectorValue func_val = _has_vector_function
      76      709440 :                                  ? _func.vectorValue(_t, _q_point[_qp])
      77       68800 :                                  : RealVectorValue(_funcx.value(_t, _q_point[_qp]),
      78       68800 :                                                    _funcy.value(_t, _q_point[_qp]),
      79      137600 :                                                    _funcz.value(_t, _q_point[_qp]));
      80             : 
      81             :   RealVectorValue sol_val =
      82      709440 :       _has_vector_variable ? _u[_qp] : RealVectorValue(_ux[_qp], _uy[_qp], _uz[_qp]);
      83             : 
      84      709440 :   return (sol_val - func_val).norm_sq(); // dot product of difference vector
      85             : }

Generated by: LCOV version 1.14