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