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 72000 : ElementVectorL2Error::validParams()
17 : {
18 72000 : InputParameters params = ElementIntegralPostprocessor::validParams();
19 72000 : params.addClassDescription("Returns the L2-norm of the difference between a pair of computed "
20 : "and analytical vector-valued solutions.");
21 72000 : params.addParam<FunctionName>("function", 0, "The vector analytical solution to compare against");
22 216000 : params.addParam<FunctionName>(
23 144000 : "function_x", 0, "The analytical solution to compare against in the x direction");
24 216000 : params.addParam<FunctionName>(
25 144000 : "function_y", 0, "The analytical solution to compare against in the y direction");
26 216000 : params.addParam<FunctionName>(
27 144000 : "function_z", 0, "The analytical solution to compare against in the z direction");
28 72000 : params.addCoupledVar("variable", {0, 0, 0}, "The vector FE solution");
29 72000 : params.addCoupledVar("var_x", 0, "The FE solution in the x direction");
30 72000 : params.addCoupledVar("var_y", 0, "The FE solution in the y direction");
31 72000 : params.addCoupledVar("var_z", 0, "The FE solution in the z direction");
32 72000 : return params;
33 0 : }
34 :
35 350 : ElementVectorL2Error::ElementVectorL2Error(const InputParameters & parameters)
36 : : ElementIntegralPostprocessor(parameters),
37 350 : _func(getFunction("function")),
38 350 : _funcx(getFunction("function_x")),
39 350 : _funcy(getFunction("function_y")),
40 350 : _funcz(getFunction("function_z")),
41 350 : _u(coupledVectorValue("variable")),
42 350 : _ux(coupledValue("var_x")),
43 350 : _uy(coupledValue("var_y")),
44 350 : _uz(coupledValue("var_z")),
45 350 : _has_vector_function(isParamSetByUser("function")),
46 1036 : _has_scalar_function(isParamSetByUser("function_x") || isParamSetByUser("function_y") ||
47 686 : isParamSetByUser("function_z")),
48 350 : _has_vector_variable(isParamSetByUser("variable")),
49 1036 : _has_scalar_variable(isParamSetByUser("var_x") || isParamSetByUser("var_y") ||
50 1036 : isParamSetByUser("var_z"))
51 : {
52 350 : 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 350 : 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 350 : 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 350 : if (_has_vector_variable && _has_scalar_variable)
63 0 : paramError("variable", "The 'variable' and 'var_{x,y,z}' parameters cannot both be set.");
64 350 : }
65 :
66 : Real
67 348 : ElementVectorL2Error::getValue() const
68 : {
69 348 : return std::sqrt(ElementIntegralPostprocessor::getValue());
70 : }
71 :
72 : Real
73 637416 : ElementVectorL2Error::computeQpIntegral()
74 : {
75 637416 : RealVectorValue func_val = _has_vector_function
76 637416 : ? _func.vectorValue(_t, _q_point[_qp])
77 77400 : : RealVectorValue(_funcx.value(_t, _q_point[_qp]),
78 77400 : _funcy.value(_t, _q_point[_qp]),
79 154800 : _funcz.value(_t, _q_point[_qp]));
80 :
81 : RealVectorValue sol_val =
82 637416 : _has_vector_variable ? _u[_qp] : RealVectorValue(_ux[_qp], _uy[_qp], _uz[_qp]);
83 :
84 637416 : return (sol_val - func_val).norm_sq(); // dot product of difference vector
85 : }
|