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 160 : EMRobinBC::validParams()
20 : {
21 160 : InputParameters params = ADIntegratedBC::validParams();
22 160 : params.addClassDescription(
23 : "First order Robin-style Absorbing/Port BC for scalar variables, assuming plane waves.");
24 320 : params.addRequiredCoupledVar("field_real", "Real component of field.");
25 320 : params.addRequiredCoupledVar("field_imaginary", "Imaginary component of field.");
26 320 : MooseEnum component("real imaginary");
27 320 : params.addParam<MooseEnum>("component", component, "Real or Imaginary wave component.");
28 320 : params.addParam<FunctionName>("func_real", 1.0, "Function coefficient, real component.");
29 320 : params.addParam<FunctionName>("func_imag", 0.0, "Function coefficient, imaginary component.");
30 320 : params.addParam<FunctionName>("profile_func_real", 1.0, "Function coefficient, real component.");
31 320 : params.addParam<FunctionName>(
32 320 : "profile_func_imag", 0.0, "Function coefficient, imaginary component.");
33 320 : params.addParam<Real>("coeff_real", 1.0, "Constant coefficient, real component.");
34 320 : params.addParam<Real>("coeff_imag", 0.0, "Constant coefficient, real component.");
35 320 : MooseEnum sign("positive=1 negative=-1", "positive");
36 320 : params.addParam<MooseEnum>("sign", sign, "Sign of boundary term in weak form.");
37 320 : MooseEnum mode("absorbing port", "port");
38 320 : params.addParam<MooseEnum>("mode",
39 : mode,
40 : "Mode of operation for EMRobinBC. Can be set to 'absorbing' or 'port' "
41 : "(default: 'port').");
42 160 : return params;
43 160 : }
44 :
45 82 : EMRobinBC::EMRobinBC(const InputParameters & parameters)
46 : : ADIntegratedBC(parameters),
47 82 : _field_real(adCoupledValue("field_real")),
48 82 : _field_imag(adCoupledValue("field_imaginary")),
49 164 : _component(getParam<MooseEnum>("component")),
50 82 : _func_real(getFunction("func_real")),
51 82 : _func_imag(getFunction("func_imag")),
52 82 : _profile_func_real(getFunction("profile_func_real")),
53 82 : _profile_func_imag(getFunction("profile_func_imag")),
54 164 : _coeff_real(getParam<Real>("coeff_real")),
55 164 : _coeff_imag(getParam<Real>("coeff_imag")),
56 164 : _sign(getParam<MooseEnum>("sign")),
57 246 : _mode(getParam<MooseEnum>("mode"))
58 : {
59 82 : bool profile_func_real_was_set = parameters.isParamSetByUser("profile_func_real");
60 82 : bool profile_func_imag_was_set = parameters.isParamSetByUser("profile_func_imag");
61 :
62 82 : 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 80 : }
69 :
70 : ADReal
71 14400 : EMRobinBC::computeQpResidual()
72 : {
73 14400 : std::complex<double> func(_func_real.value(_t, _q_point[_qp]),
74 14400 : _func_imag.value(_t, _q_point[_qp]));
75 14400 : std::complex<double> profile_func(_profile_func_real.value(_t, _q_point[_qp]),
76 14400 : _profile_func_imag.value(_t, _q_point[_qp]));
77 14400 : std::complex<double> coeff(_coeff_real, _coeff_imag);
78 :
79 : std::complex<double> common = EM::j * coeff * func;
80 28800 : ADReal lhs_real = common.real() * _field_real[_qp] - common.imag() * _field_imag[_qp];
81 43200 : ADReal lhs_imag = common.real() * _field_imag[_qp] + common.imag() * _field_real[_qp];
82 :
83 : std::complex<double> rhs = 0.0;
84 14400 : switch (_mode)
85 : {
86 7272 : case EM::PORT:
87 7272 : rhs = 2.0 * common * profile_func * std::exp(common * _q_point[_qp](0));
88 7272 : break;
89 : case EM::ABSORBING:
90 : break;
91 : }
92 :
93 28800 : ADReal diff_real = rhs.real() - lhs_real;
94 14400 : ADReal diff_imag = rhs.imag() - lhs_imag;
95 :
96 14400 : ADReal res = 0.0;
97 14400 : switch (_component)
98 : {
99 7200 : case EM::REAL:
100 14400 : res = _sign * _test[_i][_qp] * diff_real;
101 7200 : break;
102 7200 : case EM::IMAGINARY:
103 14400 : res = _sign * _test[_i][_qp] * diff_imag;
104 7200 : break;
105 : }
106 14400 : return res;
107 : }
|