https://mooseframework.inl.gov
Loading...
Searching...
No Matches
EMRobinBC.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 "EMRobinBC.h"
13#include "Function.h"
14#include <complex>
15
16registerMooseObject("ElectromagneticsApp", EMRobinBC);
17
20{
23 "First order Robin-style Absorbing/Port BC for scalar variables, assuming plane waves.");
24 params.addRequiredCoupledVar("field_real", "Real component of field.");
25 params.addRequiredCoupledVar("field_imaginary", "Imaginary component of field.");
26 MooseEnum component("real imaginary");
27 params.addParam<MooseEnum>("component", component, "Real or Imaginary wave component.");
28 params.addParam<FunctionName>("func_real", 1.0, "Function coefficient, real component.");
29 params.addParam<FunctionName>("func_imag", 0.0, "Function coefficient, imaginary component.");
30 params.addParam<FunctionName>("profile_func_real", 1.0, "Function coefficient, real component.");
31 params.addParam<FunctionName>(
32 "profile_func_imag", 0.0, "Function coefficient, imaginary component.");
33 params.addParam<Real>("coeff_real", 1.0, "Constant coefficient, real component.");
34 params.addParam<Real>("coeff_imag", 0.0, "Constant coefficient, real component.");
35 MooseEnum sign("positive=1 negative=-1", "positive");
36 params.addParam<MooseEnum>("sign", sign, "Sign of boundary term in weak form.");
37 MooseEnum mode("absorbing port", "port");
38 params.addParam<MooseEnum>("mode",
39 mode,
40 "Mode of operation for EMRobinBC. Can be set to 'absorbing' or 'port' "
41 "(default: 'port').");
42 return params;
43}
44
46 : ADIntegratedBC(parameters),
47 _field_real(adCoupledValue("field_real")),
48 _field_imag(adCoupledValue("field_imaginary")),
49 _component(getParam<MooseEnum>("component")),
50 _func_real(getFunction("func_real")),
51 _func_imag(getFunction("func_imag")),
52 _profile_func_real(getFunction("profile_func_real")),
53 _profile_func_imag(getFunction("profile_func_imag")),
54 _coeff_real(getParam<Real>("coeff_real")),
55 _coeff_imag(getParam<Real>("coeff_imag")),
56 _sign(getParam<MooseEnum>("sign")),
57 _mode(getParam<MooseEnum>("mode"))
58{
59 bool profile_func_real_was_set = parameters.isParamSetByUser("profile_func_real");
60 bool profile_func_imag_was_set = parameters.isParamSetByUser("profile_func_imag");
61
62 if (_mode == EM::ABSORBING && (profile_func_real_was_set || profile_func_imag_was_set))
64 "In ",
65 _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}
69
72{
73 std::complex<double> func(_func_real.value(_t, _q_point[_qp]),
75 std::complex<double> profile_func(_profile_func_real.value(_t, _q_point[_qp]),
77 std::complex<double> coeff(_coeff_real, _coeff_imag);
78
79 std::complex<double> common = EM::j * coeff * func;
80 ADReal lhs_real = common.real() * _field_real[_qp] - common.imag() * _field_imag[_qp];
81 ADReal lhs_imag = common.real() * _field_imag[_qp] + common.imag() * _field_real[_qp];
82
83 std::complex<double> rhs = 0.0;
84 switch (_mode)
85 {
86 case EM::PORT:
87 rhs = 2.0 * common * profile_func * std::exp(common * _q_point[_qp](0));
88 break;
89 case EM::ABSORBING:
90 break;
91 }
92
93 ADReal diff_real = rhs.real() - lhs_real;
94 ADReal diff_imag = rhs.imag() - lhs_imag;
95
96 ADReal res = 0.0;
97 switch (_component)
98 {
99 case EM::REAL:
100 res = _sign * _test[_i][_qp] * diff_real;
101 break;
102 case EM::IMAGINARY:
103 res = _sign * _test[_i][_qp] * diff_imag;
104 break;
105 }
106 return res;
107}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("ElectromagneticsApp", EMRobinBC)
static InputParameters validParams()
const ADTemplateVariableTestValue< T > & _test
Represents the boundary condition for a first order Robin-style Absorbing/Port boundary for scalar va...
Definition EMRobinBC.h:19
const Real _coeff_imag
Imaginary component of the constant coefficient representing the wavenumber.
Definition EMRobinBC.h:54
const Function & _func_imag
Imaginary component of the function coefficient representing the wavenumber.
Definition EMRobinBC.h:42
EMRobinBC(const InputParameters &parameters)
Definition EMRobinBC.C:45
const ADVariableValue & _field_imag
Imaginary component of the electric field.
Definition EMRobinBC.h:33
const MooseEnum _component
Enum for selection of real or imaginary component of the field wave.
Definition EMRobinBC.h:36
virtual ADReal computeQpResidual() override
Definition EMRobinBC.C:71
static InputParameters validParams()
Definition EMRobinBC.C:19
const Real _coeff_real
Real component of the constant coefficient representing the wavenumber.
Definition EMRobinBC.h:51
const Function & _profile_func_imag
Imaginary component of the incoming wave function amplitude.
Definition EMRobinBC.h:48
const MooseEnum _mode
Enum for selection of boundary condition mode: absorbing or port (Default = port)
Definition EMRobinBC.h:60
const Function & _func_real
Real component of the function coefficient representing the wavenumber.
Definition EMRobinBC.h:39
const Function & _profile_func_real
Real component of the incoming wave function amplitude.
Definition EMRobinBC.h:45
const ADVariableValue & _field_real
Real component of the electric field.
Definition EMRobinBC.h:30
const MooseEnum _sign
Scalar value representing the sign of the term in the weak form.
Definition EMRobinBC.h:57
virtual Real value(Real t, const Point &p) const
bool isParamSetByUser(const std::string &name) const
void addRequiredCoupledVar(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)
unsigned int _qp
const MooseArray< Point > & _q_point
const InputParameters & parameters() const
void mooseError(Args &&... args) const
const std::string & _name
@ ABSORBING
Case when the boundary is configured to absorb impinging electromagnetic radiation.
@ PORT
Case when the boundary is configured to both absorb impinging electromagnetic radiation and launch an...
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")