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 "EMRobinBC.h"
11 : #include "ElectromagneticEnums.h"
12 : #include "ElectromagneticConstants.h"
13 : #include "Function.h"
14 : #include <complex>
15 :
16 : registerMooseObject("ElectromagneticsApp", EMRobinBC);
17 :
18 : InputParameters
19 336 : EMRobinBC::validParams()
20 : {
21 336 : InputParameters params = ADIntegratedBC::validParams();
22 336 : params.addClassDescription(
23 : "First order Robin-style Absorbing/Port BC for scalar variables, assuming plane waves.");
24 672 : params.addRequiredCoupledVar("field_real", "Real component of field.");
25 672 : params.addRequiredCoupledVar("field_imaginary", "Imaginary component of field.");
26 672 : MooseEnum component("real imaginary");
27 672 : params.addParam<MooseEnum>("component", component, "Real or Imaginary wave component.");
28 672 : params.addParam<FunctionName>("func_real", 1.0, "Function coefficient, real component.");
29 672 : params.addParam<FunctionName>("func_imag", 0.0, "Function coefficient, imaginary component.");
30 672 : params.addParam<FunctionName>("profile_func_real", 1.0, "Function coefficient, real component.");
31 672 : params.addParam<FunctionName>(
32 672 : "profile_func_imag", 0.0, "Function coefficient, imaginary component.");
33 672 : params.addParam<Real>("coeff_real", 1.0, "Constant coefficient, real component.");
34 672 : params.addParam<Real>("coeff_imag", 0.0, "Constant coefficient, real component.");
35 672 : MooseEnum sign("positive=1 negative=-1", "positive");
36 672 : params.addParam<MooseEnum>("sign", sign, "Sign of boundary term in weak form.");
37 672 : MooseEnum mode("absorbing port", "port");
38 672 : params.addParam<MooseEnum>("mode",
39 : mode,
40 : "Mode of operation for EMRobinBC. Can be set to 'absorbing' or 'port' "
41 : "(default: 'port').");
42 336 : return params;
43 336 : }
44 :
45 178 : EMRobinBC::EMRobinBC(const InputParameters & parameters)
46 : : ADIntegratedBC(parameters),
47 178 : _field_real(adCoupledValue("field_real")),
48 178 : _field_imag(adCoupledValue("field_imaginary")),
49 356 : _component(getParam<MooseEnum>("component")),
50 178 : _func_real(getFunction("func_real")),
51 178 : _func_imag(getFunction("func_imag")),
52 178 : _profile_func_real(getFunction("profile_func_real")),
53 178 : _profile_func_imag(getFunction("profile_func_imag")),
54 356 : _coeff_real(getParam<Real>("coeff_real")),
55 356 : _coeff_imag(getParam<Real>("coeff_imag")),
56 356 : _sign(getParam<MooseEnum>("sign")),
57 534 : _mode(getParam<MooseEnum>("mode"))
58 : {
59 178 : bool profile_func_real_was_set = parameters.isParamSetByUser("profile_func_real");
60 178 : bool profile_func_imag_was_set = parameters.isParamSetByUser("profile_func_imag");
61 :
62 178 : if (_mode == EM::ABSORBING && (profile_func_real_was_set || profile_func_imag_was_set))
63 2 : mooseError(
64 : "In ",
65 2 : _name,
66 : ", mode was set to Absorbing, while an incoming profile function (used for Port BCs) was "
67 : "defined. Either remove the profile function parameters, or set your BC to Port mode!");
68 176 : }
69 :
70 : ADReal
71 21600 : EMRobinBC::computeQpResidual()
72 : {
73 21600 : std::complex<double> func(_func_real.value(_t, _q_point[_qp]),
74 21600 : _func_imag.value(_t, _q_point[_qp]));
75 21600 : std::complex<double> profile_func(_profile_func_real.value(_t, _q_point[_qp]),
76 21600 : _profile_func_imag.value(_t, _q_point[_qp]));
77 21600 : std::complex<double> coeff(_coeff_real, _coeff_imag);
78 :
79 : std::complex<double> common = EM::j * coeff * func;
80 43200 : ADReal lhs_real = common.real() * _field_real[_qp] - common.imag() * _field_imag[_qp];
81 64800 : ADReal lhs_imag = common.real() * _field_imag[_qp] + common.imag() * _field_real[_qp];
82 :
83 : std::complex<double> rhs = 0.0;
84 21600 : switch (_mode)
85 : {
86 10908 : case EM::PORT:
87 10908 : rhs = 2.0 * common * profile_func * std::exp(common * _q_point[_qp](0));
88 10908 : break;
89 : case EM::ABSORBING:
90 : break;
91 : }
92 :
93 43200 : ADReal diff_real = rhs.real() - lhs_real;
94 21600 : ADReal diff_imag = rhs.imag() - lhs_imag;
95 :
96 21600 : ADReal res = 0.0;
97 21600 : switch (_component)
98 : {
99 10800 : case EM::REAL:
100 21600 : res = _sign * _test[_i][_qp] * diff_real;
101 10800 : break;
102 10800 : case EM::IMAGINARY:
103 21600 : res = _sign * _test[_i][_qp] * diff_imag;
104 10800 : break;
105 : }
106 21600 : return res;
107 : }
|