https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MMSTestFunc.C
Go to the documentation of this file.
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 "MMSTestFunc.h"
12#include <complex>
13
14registerMooseObject("ElectromagneticsTestApp", MMSTestFunc);
15
18{
21 "Function of RHS for manufactured solution in scalar_complex_helmholtz test.");
22 params.addRequiredParam<Real>("L", "Length of 1D test domain, where 0 < x < L");
23 params.addRequiredParam<Real>("g0_real", "Real component of DirichletBC where x = 0.");
24 params.addRequiredParam<Real>("g0_imag", "Imaginary component of DirichletBC where x = 0.");
25 params.addRequiredParam<Real>("gL_real", "Real component of DirichletBC where x = L.");
26 params.addRequiredParam<Real>("gL_imag", "Imaginary component of DirichletBC where x = L.");
27 MooseEnum component("real imaginary");
28 params.addParam<MooseEnum>("component", component, "Real or Imaginary wave component.");
29 return params;
30}
31
33 : Function(parameters),
34 _length(getParam<Real>("L")),
35 _g_0_real(getParam<Real>("g0_real")),
36 _g_0_imag(getParam<Real>("g0_imag")),
37 _g_l_real(getParam<Real>("gL_real")),
38 _g_l_imag(getParam<Real>("gL_imag")),
39 _component(getParam<MooseEnum>("component"))
40{
41}
42
43Real
44MMSTestFunc::value(Real /*t*/, const Point & p) const
45{
46
47 Real val = 0;
48 std::complex<double> F(0, 0);
49
50 std::complex<double> g_0(_g_0_real, _g_0_imag);
51 std::complex<double> g_l(_g_l_real, _g_l_imag);
52
53 std::complex<double> k(2.0 * (1.0 + p(0) / _length), (1.0 + p(0) / _length));
54 std::complex<double> k_l(4.0, 2.0);
55 std::complex<double> c(12.0 * (1.0 + p(0) / _length) * (1.0 + p(0) / _length),
56 4.0 * (1.0 + p(0) / _length) * (1.0 + p(0) / _length));
57 std::complex<double> c_l(48.0, 16.0);
58
59 std::complex<double> c_grad((24.0 / _length) * (1 + p(0) / _length),
60 (8.0 / _length) * (1 + p(0) / _length));
61
62 std::complex<double> lambda = k / std::sqrt(c);
63 std::complex<double> lambda_l = k_l / std::sqrt(c_l);
64
65 std::complex<double> constant_1 = g_0;
66 std::complex<double> constant_2 =
67 (g_l - g_0 * std::cos(lambda_l * _length)) / std::sin(lambda_l * _length);
68
69 std::complex<double> sln_grad = -constant_1 * lambda * std::sin(lambda * p(0)) +
70 constant_2 * lambda * std::cos(lambda * p(0));
71
72 F = c_grad * sln_grad;
73
74 if (_component == EM::REAL)
75 {
76 val = F.real();
77 }
78 else
79 {
80 val = F.imag();
81 }
82
83 // sign flip because being used in -(cu')' - k^2 * u = -F(x) strong form
84 return -val;
85}
const Real p
registerMooseObject("ElectromagneticsTestApp", MMSTestFunc)
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
Function of RHS for manufactured solution in scalar_complex_helmholtz test.
Definition MMSTestFunc.h:18
const Real _g_0_imag
Imaginary component of DirichletBC, where x = 0.
Definition MMSTestFunc.h:34
const Real _length
Length of 1D test domain, where 0 < x < L.
Definition MMSTestFunc.h:28
virtual Real value(Real t, const Point &p) const override
Definition MMSTestFunc.C:44
static InputParameters validParams()
Definition MMSTestFunc.C:17
const Real _g_l_real
Real component of DirichletBC, where x = L.
Definition MMSTestFunc.h:37
const MooseEnum _component
Enum signifying the component of the function being calculated.
Definition MMSTestFunc.h:43
MMSTestFunc(const InputParameters &parameters)
Definition MMSTestFunc.C:32
const Real _g_l_imag
Imaginary component of DirichletBC, where x = L.
Definition MMSTestFunc.h:40
const Real _g_0_real
Real component of DirichletBC, where x = 0.
Definition MMSTestFunc.h:31