LCOV - code coverage report
Current view: top level - src/postprocessors - ElementVectorL2Error.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 45 50 90.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 "ElementVectorL2Error.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("MooseApp", ElementVectorL2Error);
      14             : 
      15             : InputParameters
      16       71950 : ElementVectorL2Error::validParams()
      17             : {
      18       71950 :   InputParameters params = ElementIntegralPostprocessor::validParams();
      19       71950 :   params.addClassDescription("Returns the L2-norm of the difference between a pair of computed "
      20             :                              "and analytical vector-valued solutions.");
      21       71950 :   params.addParam<FunctionName>("function", 0, "The vector analytical solution to compare against");
      22      215850 :   params.addParam<FunctionName>(
      23      143900 :       "function_x", 0, "The analytical solution to compare against in the x direction");
      24      215850 :   params.addParam<FunctionName>(
      25      143900 :       "function_y", 0, "The analytical solution to compare against in the y direction");
      26      215850 :   params.addParam<FunctionName>(
      27      143900 :       "function_z", 0, "The analytical solution to compare against in the z direction");
      28       71950 :   params.addCoupledVar("variable", {0, 0, 0}, "The vector FE solution");
      29       71950 :   params.addCoupledVar("var_x", 0, "The FE solution in the x direction");
      30       71950 :   params.addCoupledVar("var_y", 0, "The FE solution in the y direction");
      31       71950 :   params.addCoupledVar("var_z", 0, "The FE solution in the z direction");
      32       71950 :   return params;
      33           0 : }
      34             : 
      35         325 : ElementVectorL2Error::ElementVectorL2Error(const InputParameters & parameters)
      36             :   : ElementIntegralPostprocessor(parameters),
      37         325 :     _func(getFunction("function")),
      38         325 :     _funcx(getFunction("function_x")),
      39         325 :     _funcy(getFunction("function_y")),
      40         325 :     _funcz(getFunction("function_z")),
      41         325 :     _u(coupledVectorValue("variable")),
      42         325 :     _ux(coupledValue("var_x")),
      43         325 :     _uy(coupledValue("var_y")),
      44         325 :     _uz(coupledValue("var_z")),
      45         325 :     _has_vector_function(isParamSetByUser("function")),
      46         962 :     _has_scalar_function(isParamSetByUser("function_x") || isParamSetByUser("function_y") ||
      47         637 :                          isParamSetByUser("function_z")),
      48         325 :     _has_vector_variable(isParamSetByUser("variable")),
      49         962 :     _has_scalar_variable(isParamSetByUser("var_x") || isParamSetByUser("var_y") ||
      50         962 :                          isParamSetByUser("var_z"))
      51             : {
      52         325 :   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         325 :   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         325 :   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         325 :   if (_has_vector_variable && _has_scalar_variable)
      63           0 :     paramError("variable", "The 'variable' and 'var_{x,y,z}' parameters cannot both be set.");
      64         325 : }
      65             : 
      66             : Real
      67         319 : ElementVectorL2Error::getValue() const
      68             : {
      69         319 :   return std::sqrt(ElementIntegralPostprocessor::getValue());
      70             : }
      71             : 
      72             : Real
      73      566592 : ElementVectorL2Error::computeQpIntegral()
      74             : {
      75      566592 :   RealVectorValue func_val = _has_vector_function
      76      566592 :                                  ? _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      566592 :       _has_vector_variable ? _u[_qp] : RealVectorValue(_ux[_qp], _uy[_qp], _uz[_qp]);
      83             : 
      84      566592 :   return (sol_val - func_val).norm_sq(); // dot product of difference vector
      85             : }

Generated by: LCOV version 1.14