https://mooseframework.inl.gov
MFEMRWTE10IntegratedBC.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 #ifdef MOOSE_MFEM_ENABLED
11 
12 #include "MFEMRWTE10IntegratedBC.h"
13 
15 
18 {
20  params.addClassDescription("Adds the Robin boundary conditions for an electromagnetic problem "
21  "with transverse waves in a rectangular waveguide.");
22  params.addParam<RealVectorValue>(
23  "port_length_vector",
24  "Vector along the x-axis of the port, where its magnitude is the port length in meters.");
25  params.addParam<RealVectorValue>(
26  "port_width_vector",
27  "Vector along the y-axis of the port, where its magnitude is the port width in meters.");
28  params.addParam<Real>("frequency", 1.0, "Mode frequency in Hz.");
29  params.addParam<Real>("epsilon", 1.0, "Electric permittivity constant.");
30  params.addParam<Real>("mu", 1.0, "Magnetic permeability constant.");
31  params.addParam<bool>("input_port",
32  false,
33  "Whether the boundary attribute passed to this BC corresponds to the input "
34  "port of the waveguide.");
35 
36  return params;
37 }
38 
40  : MFEMComplexIntegratedBC(parameters),
41  _mu(getParam<Real>("mu")),
42  _epsilon(getParam<Real>("epsilon")),
43  _omega(2 * M_PI * getParam<Real>("frequency")),
44  _a1(const_cast<mfem::real_t *>(&getParam<RealGradient>("port_length_vector")(0)), Moose::dim),
45  _a2(const_cast<mfem::real_t *>(&getParam<RealGradient>("port_width_vector")(0)), Moose::dim),
46  _k0(_omega * std::sqrt(_mu * _epsilon)),
47  _kc(M_PI / _a1.Norml2()),
48  _k(std::complex<mfem::real_t>(0., std::sqrt(_k0 * _k0 - _kc * _kc))),
49  _k_c(normalizedCrossProduct(_a1, _a2) *= _k.imag()),
50  _k_a(normalizedCrossProduct(_a2, _k_c) *= _kc)
51 {
52  _robin_coef_im = std::make_unique<mfem::ConstantCoefficient>(_k.imag() / _mu);
53 
54  if (getParam<bool>("input_port"))
55  {
56  _u_real = std::make_unique<mfem::VectorFunctionCoefficient>(
57  3, [this](const mfem::Vector & x, mfem::Vector & v) { return RWTE10Real(x, v); });
58 
59  _u_imag = std::make_unique<mfem::VectorFunctionCoefficient>(
60  3, [this](const mfem::Vector & x, mfem::Vector & v) { return RWTE10Imag(x, v); });
61  }
62 }
63 
64 void
65 MFEMRWTE10IntegratedBC::RWTE10(const mfem::Vector & x, std::vector<std::complex<mfem::real_t>> & E)
66 {
67  mfem::Vector e_hat(normalizedCrossProduct(_k_c, _k_a));
68  std::complex<mfem::real_t> zi(0., 1.);
69 
70  mfem::real_t e0 = std::sqrt(2 * _omega * _mu / (_a1.Norml2() * _a2.Norml2() * _k.imag()));
71  std::complex<mfem::real_t> e_mag =
72  e0 * sin(mfem::InnerProduct(_k_a, x)) * exp(-zi * mfem::InnerProduct(_k_c, x));
73 
74  E[0] = e_mag * e_hat(1);
75  E[1] = e_mag * e_hat(2);
76  E[2] = e_mag * e_hat(0);
77 }
78 
79 void
80 MFEMRWTE10IntegratedBC::RWTE10Real(const mfem::Vector & x, mfem::Vector & v)
81 {
82  std::vector<std::complex<mfem::real_t>> eval(x.Size());
83  RWTE10(x, eval);
84  for (int i = 0; i < x.Size(); ++i)
85  v(i) = -2 * _k.imag() * eval[i].imag() / _mu;
86 }
87 void
88 MFEMRWTE10IntegratedBC::RWTE10Imag(const mfem::Vector & x, mfem::Vector & v)
89 {
90  std::vector<std::complex<mfem::real_t>> eval(x.Size());
91  RWTE10(x, eval);
92  for (int i = 0; i < x.Size(); ++i)
93  v(i) = 2 * _k.imag() * eval[i].real() / _mu;
94 }
95 
96 #endif
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sin(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tan
auto exp(const T &)
std::unique_ptr< mfem::VectorFunctionCoefficient > _u_imag
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
void RWTE10Imag(const mfem::Vector &x, mfem::Vector &v)
registerMooseObject("MooseApp", MFEMRWTE10IntegratedBC)
std::complex< mfem::real_t > _k
mfem::Vector normalizedCrossProduct(const mfem::Vector &va, const mfem::Vector &vb)
Computes the unit vector in the direction of the cross product of two 3d vectors. ...
static InputParameters validParams()
void RWTE10Real(const mfem::Vector &x, mfem::Vector &v)
MFEMRWTE10IntegratedBC(const InputParameters &parameters)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void RWTE10(const mfem::Vector &x, std::vector< std::complex< mfem::real_t >> &E)
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
std::unique_ptr< mfem::ConstantCoefficient > _robin_coef_im
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
std::unique_ptr< mfem::VectorFunctionCoefficient > _u_real
static InputParameters validParams()