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 29454 : ElementW1pError::validParams() 17 : { 18 29454 : InputParameters params = ElementIntegralVariablePostprocessor::validParams(); 19 29454 : params.addRangeCheckedParam<Real>("p", 2.0, "p>=1", "The exponent used in the norm."); 20 29454 : params.addRequiredParam<FunctionName>("function", "The analytic solution to compare against"); 21 29454 : params.addClassDescription("Computes the W1p norm of the difference between a variable and an " 22 : "analytic solution, as a function"); 23 29454 : return params; 24 0 : } 25 : 26 478 : ElementW1pError::ElementW1pError(const InputParameters & parameters) 27 : : ElementIntegralVariablePostprocessor(parameters), 28 478 : _p(getParam<Real>("p")), 29 956 : _func(getFunction("function")) 30 : { 31 478 : } 32 : 33 : Real 34 652 : ElementW1pError::getValue() const 35 : { 36 652 : return std::pow(ElementIntegralPostprocessor::getValue(), 1. / _p); 37 : } 38 : 39 : Real 40 1565424 : ElementW1pError::computeQpIntegral() 41 : { 42 1565424 : RealGradient graddiff = _grad_u[_qp] - _func.gradient(_t, _q_point[_qp]); 43 1565424 : Real funcdiff = _u[_qp] - _func.value(_t, _q_point[_qp]); 44 : 45 : // Raise the absolute function value difference to the pth power 46 1565424 : Real val = std::pow(std::abs(funcdiff), _p); 47 : 48 : // Add all of the absolute gradient component differences to the pth power 49 6261696 : for (const auto i : make_range(Moose::dim)) 50 4696272 : val += std::pow(std::abs(graddiff(i)), _p); 51 : 52 1565424 : return val; 53 : }