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 "NodalL2Error.h" 11 : #include "Function.h" 12 : 13 : registerMooseObject("MooseApp", NodalL2Error); 14 : 15 : InputParameters 16 15261 : NodalL2Error::validParams() 17 : { 18 15261 : InputParameters params = NodalVariablePostprocessor::validParams(); 19 15261 : params.addClassDescription( 20 : "The L2-norm of the difference between a variable and a function computed at nodes."); 21 15261 : params.addRequiredParam<FunctionName>("function", "The analytic solution to compare against"); 22 : 23 15261 : return params; 24 0 : } 25 : 26 516 : NodalL2Error::NodalL2Error(const InputParameters & parameters) 27 516 : : NodalVariablePostprocessor(parameters), _func(getFunction("function")) 28 : { 29 516 : } 30 : 31 : void 32 3462 : NodalL2Error::initialize() 33 : { 34 3462 : _integral_value = 0.; 35 3462 : } 36 : 37 : void 38 331019 : NodalL2Error::execute() 39 : { 40 331019 : Real diff = _u[0] - _func.value(_t, *_current_node); 41 331019 : _integral_value += diff * diff; 42 331019 : } 43 : 44 : Real 45 3173 : NodalL2Error::getValue() const 46 : { 47 3173 : return std::sqrt(_integral_value); 48 : } 49 : 50 : void 51 289 : NodalL2Error::threadJoin(const UserObject & y) 52 : { 53 289 : const auto & pps = static_cast<const NodalL2Error &>(y); 54 289 : _integral_value += pps._integral_value; 55 289 : } 56 : 57 : void 58 3173 : NodalL2Error::finalize() 59 : { 60 3173 : gatherSum(_integral_value); 61 3173 : }