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 : #ifdef MOOSE_MFEM_ENABLED 11 : 12 : #include "MFEMRWTE10IntegratedBC.h" 13 : 14 : registerMooseObject("MooseApp", MFEMRWTE10IntegratedBC); 15 : 16 : InputParameters 17 2122 : MFEMRWTE10IntegratedBC::validParams() 18 : { 19 2122 : InputParameters params = MFEMComplexIntegratedBC::validParams(); 20 4244 : params.addClassDescription("Adds the Robin boundary conditions for an electromagnetic problem " 21 : "with transverse waves in a rectangular waveguide."); 22 8488 : 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 8488 : 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 8488 : params.addParam<Real>("frequency", 1.0, "Mode frequency in Hz."); 29 8488 : params.addParam<Real>("epsilon", 1.0, "Electric permittivity constant."); 30 8488 : params.addParam<Real>("mu", 1.0, "Magnetic permeability constant."); 31 4244 : params.addParam<bool>("input_port", 32 4244 : false, 33 : "Whether the boundary attribute passed to this BC corresponds to the input " 34 : "port of the waveguide."); 35 : 36 2122 : return params; 37 0 : } 38 : 39 12 : MFEMRWTE10IntegratedBC::MFEMRWTE10IntegratedBC(const InputParameters & parameters) 40 : : MFEMComplexIntegratedBC(parameters), 41 12 : _mu(getParam<Real>("mu")), 42 24 : _epsilon(getParam<Real>("epsilon")), 43 24 : _omega(2 * M_PI * getParam<Real>("frequency")), 44 24 : _a1(const_cast<mfem::real_t *>(&getParam<RealGradient>("port_length_vector")(0)), Moose::dim), 45 24 : _a2(const_cast<mfem::real_t *>(&getParam<RealGradient>("port_width_vector")(0)), Moose::dim), 46 12 : _k0(_omega * std::sqrt(_mu * _epsilon)), 47 12 : _kc(M_PI / _a1.Norml2()), 48 12 : _k(std::complex<mfem::real_t>(0., std::sqrt(_k0 * _k0 - _kc * _kc))), 49 12 : _k_c(normalizedCrossProduct(_a1, _a2) *= _k.imag()), 50 24 : _k_a(normalizedCrossProduct(_a2, _k_c) *= _kc) 51 : { 52 12 : _robin_coef_im = std::make_unique<mfem::ConstantCoefficient>(_k.imag() / _mu); 53 : 54 36 : if (getParam<bool>("input_port")) 55 : { 56 6 : _u_real = std::make_unique<mfem::VectorFunctionCoefficient>( 57 1230 : 3, [this](const mfem::Vector & x, mfem::Vector & v) { return RWTE10Real(x, v); }); 58 : 59 6 : _u_imag = std::make_unique<mfem::VectorFunctionCoefficient>( 60 1236 : 3, [this](const mfem::Vector & x, mfem::Vector & v) { return RWTE10Imag(x, v); }); 61 : } 62 12 : } 63 : 64 : void 65 2448 : MFEMRWTE10IntegratedBC::RWTE10(const mfem::Vector & x, std::vector<std::complex<mfem::real_t>> & E) 66 : { 67 2448 : mfem::Vector e_hat(normalizedCrossProduct(_k_c, _k_a)); 68 2448 : std::complex<mfem::real_t> zi(0., 1.); 69 : 70 2448 : mfem::real_t e0 = std::sqrt(2 * _omega * _mu / (_a1.Norml2() * _a2.Norml2() * _k.imag())); 71 : std::complex<mfem::real_t> e_mag = 72 2448 : e0 * sin(mfem::InnerProduct(_k_a, x)) * exp(-zi * mfem::InnerProduct(_k_c, x)); 73 : 74 2448 : E[0] = e_mag * e_hat(1); 75 2448 : E[1] = e_mag * e_hat(2); 76 2448 : E[2] = e_mag * e_hat(0); 77 2448 : } 78 : 79 : void 80 1224 : MFEMRWTE10IntegratedBC::RWTE10Real(const mfem::Vector & x, mfem::Vector & v) 81 : { 82 1224 : std::vector<std::complex<mfem::real_t>> eval(x.Size()); 83 1224 : RWTE10(x, eval); 84 4896 : for (int i = 0; i < x.Size(); ++i) 85 3672 : v(i) = -2 * _k.imag() * eval[i].imag() / _mu; 86 1224 : } 87 : void 88 2448 : MFEMRWTE10IntegratedBC::RWTE10Imag(const mfem::Vector & x, mfem::Vector & v) 89 : { 90 1224 : std::vector<std::complex<mfem::real_t>> eval(x.Size()); 91 1224 : RWTE10(x, eval); 92 4896 : for (int i = 0; i < x.Size(); ++i) 93 3672 : v(i) = 2 * _k.imag() * eval[i].real() / _mu; 94 1224 : } 95 : 96 : #endif