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 14290 : ElementH1ErrorFunctionAux::validParams() 20 : { 21 14290 : InputParameters params = ElementL2ErrorFunctionAux::validParams(); 22 14290 : params.addClassDescription( 23 : "Computes the H1 or W^{1,p} error between an exact function and a coupled variable."); 24 : 25 14290 : return params; 26 0 : } 27 : 28 13 : ElementH1ErrorFunctionAux::ElementH1ErrorFunctionAux(const InputParameters & parameters) 29 13 : : ElementL2ErrorFunctionAux(parameters), _grad_coupled_var(coupledGradient("coupled_variable")) 30 : { 31 13 : } 32 : 33 : void 34 44800 : ElementH1ErrorFunctionAux::compute() 35 : { 36 44800 : precalculateValue(); 37 : 38 44800 : if (isNodal()) 39 0 : mooseError("ElementH1ErrorFunctionAux only makes sense as an Elemental AuxVariable."); 40 : 41 44800 : Real summed_value = 0; 42 224000 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 43 : { 44 179200 : Real val = computeValue(); // already raised to the p, see below. 45 179200 : summed_value += _JxW[_qp] * _coord[_qp] * val; 46 : } 47 : 48 44800 : _var.setNodalValue(std::pow(summed_value, 1. / _p)); 49 44800 : } 50 : 51 : Real 52 179200 : ElementH1ErrorFunctionAux::computeValue() 53 : { 54 179200 : RealGradient graddiff = _func.gradient(_t, _q_point[_qp]) - _grad_coupled_var[_qp]; 55 179200 : Real funcdiff = _func.value(_t, _q_point[_qp]) - _coupled_var[_qp]; 56 : 57 : // Raise the absolute function value difference to the pth power 58 179200 : Real val = std::pow(std::abs(funcdiff), _p); 59 : 60 : // Add all of the absolute gradient component differences to the pth power 61 716800 : for (const auto i : make_range(Moose::dim)) 62 537600 : val += std::pow(std::abs(graddiff(i)), _p); 63 : 64 179200 : return val; 65 : }