<commit_before>#include "VectorPortBC.h"

registerMooseObject("ElkApp", VectorPortBC);

template <>
InputParameters
validParams<VectorPortBC>()
{
  InputParameters params = validParams<VectorIntegratedBC>();
  params.addClassDescription(
      "First order Port BC from Jin 'Theory and Computation of Electromagnetic Fields' by <NAME>.");
  params.addRequiredParam<FunctionName>("beta", "Waveguide propagation constant.");
  MooseEnum component("real imaginary");
  params.addParam<MooseEnum>(
      "component", component, "Variable field component (real or imaginary).");
  params.addRequiredCoupledVar("coupled", "Coupled field variable.");
  params.addParam<FunctionName>("Inc_real_x", 0.0, "Real incoming field, x direction.");
  params.addParam<FunctionName>("Inc_real_y", 0.0, "Real incoming field, y direction.");
  params.addParam<FunctionName>("Inc_real_z", 0.0, "Real incoming field, z direction.");
  params.addParam<FunctionName>("Inc_imag_x", 0.0, "Imaginary incoming field, x direction.");
  params.addParam<FunctionName>("Inc_imag_y", 0.0, "Imaginary incoming field, y direction.");
  params.addParam<FunctionName>("Inc_imag_z", 0.0, "Imaginary incoming field, z direction.");
  params.addRequiredParam<Real>("sign", "Sign of term in weak form.");
  return params;
}

VectorPortBC::VectorPortBC(const InputParameters & parameters)
  : VectorIntegratedBC(parameters),

    _beta(getFunction("beta")),

    _component(getParam<MooseEnum>("component")),

    _coupled_val(coupledVectorValue("coupled")),
    _coupled_id(coupled("coupled")),

    _inc_real_x(getFunction("Inc_real_x")),
    _inc_real_y(getFunction("Inc_real_y")),
    _inc_real_z(getFunction("Inc_real_z")),

    _inc_imag_x(getFunction("Inc_imag_x")),
    _inc_imag_y(getFunction("Inc_imag_y")),
    _inc_imag_z(getFunction("Inc_imag_z")),

    _sign(getParam<Real>("sign"))
{
}

Real
VectorPortBC::computeQpResidual()
{

  RealVectorValue incoming_real(_inc_real_x.value(_t, _q_point[_qp]),
                                _inc_real_y.value(_t, _q_point[_qp]),
                                _inc_real_z.value(_t, _q_point[_qp]));
  RealVectorValue incoming_imag(_inc_imag_x.value(_t, _q_point[_qp]),
                                _inc_imag_y.value(_t, _q_point[_qp]),
                                _inc_imag_z.value(_t, _q_point[_qp]));

  RealVectorValue Q_real = 2 * incoming_imag * _beta.value(_t, _q_point[_qp]);
  RealVectorValue Q_imag = -2 * incoming_real * _beta.value(_t, _q_point[_qp]);

  if (_component == "real")
  {
    return _sign * (Q_real * _test[_i][_qp] - _beta.value(_t, _q_point[_qp]) *
                                                  (_normals[_qp].cross(_test[_i][_qp])) *
                                                  (_normals[_qp].cross(_coupled_val[_qp])));
  }
  else
  {
    return _sign * (Q_imag * _test[_i][_qp] + _beta.value(_t, _q_point[_qp]) *
                                                  (_normals[_qp].cross(_test[_i][_qp])) *
                                                  (_normals[_qp].cross(_coupled_val[_qp])));
  }
}

// CURRENTLY DOESN'T SEEM TO BE CORRECT - USE PJFNK OR NEWTON PLUS FDP IF YOU
// NEED THIS BC
Real
VectorPortBC::computeQpJacobian()
{
  return 0.0;
}

Real
VectorPortBC::computeQpOffDiagJacobian(unsigned jvar)
{
  if (jvar == _coupled_id)
  {
    if (_component == "real")
    {
      return -_beta.value(_t, _q_point[_qp]) * (_normals[_qp].cross(_test[_i][_qp])) *
             (_normals[_qp].cross(_phi[_j][_qp]));
    }<commit_msg>Correct implementation error in VectorPortBC.<commit_after>#include "VectorPortBC.h"

registerMooseObject("ElkApp", VectorPortBC);

template <>
InputParameters
validParams<VectorPortBC>()
{
  InputParameters params = validParams<VectorIntegratedBC>();
  params.addClassDescription(
      "First order Port BC from Jin 'Theory and Computation of Electromagnetic Fields' by <NAME>.");
  params.addRequiredParam<FunctionName>("beta", "Waveguide propagation constant.");
  MooseEnum component("real imaginary");
  params.addParam<MooseEnum>(
      "component", component, "Variable field component (real or imaginary).");
  params.addRequiredCoupledVar("coupled", "Coupled field variable.");
  params.addParam<FunctionName>("Inc_real_x", 0.0, "Real incoming field, x direction.");
  params.addParam<FunctionName>("Inc_real_y", 0.0, "Real incoming field, y direction.");
  params.addParam<FunctionName>("Inc_real_z", 0.0, "Real incoming field, z direction.");
  params.addParam<FunctionName>("Inc_imag_x", 0.0, "Imaginary incoming field, x direction.");
  params.addParam<FunctionName>("Inc_imag_y", 0.0, "Imaginary incoming field, y direction.");
  params.addParam<FunctionName>("Inc_imag_z", 0.0, "Imaginary incoming field, z direction.");
  params.addRequiredParam<Real>("sign", "Sign of term in weak form.");
  return params;
}

VectorPortBC::VectorPortBC(const InputParameters & parameters)
  : VectorIntegratedBC(parameters),

    _beta(getFunction("beta")),

    _component(getParam<MooseEnum>("component")),

    _coupled_val(coupledVectorValue("coupled")),
    _coupled_id(coupled("coupled")),

    _inc_real_x(getFunction("Inc_real_x")),
    _inc_real_y(getFunction("Inc_real_y")),
    _inc_real_z(getFunction("Inc_real_z")),

    _inc_imag_x(getFunction("Inc_imag_x")),
    _inc_imag_y(getFunction("Inc_imag_y")),
    _inc_imag_z(getFunction("Inc_imag_z")),

    _sign(getParam<Real>("sign"))
{
}

Real
VectorPortBC::computeQpResidual()
{

  RealVectorValue incoming_real(_inc_real_x.value(_t, _q_point[_qp]),
                                _inc_real_y.value(_t, _q_point[_qp]),
                                _inc_real_z.value(_t, _q_point[_qp]));
  RealVectorValue incoming_imag(_inc_imag_x.value(_t, _q_point[_qp]),
                                _inc_imag_y.value(_t, _q_point[_qp]),
                                _inc_imag_z.value(_t, _q_point[_qp]));

  RealVectorValue Q_real = -2 * _beta.value(_t, _q_point[_qp]) * _normals[_qp].cross(incoming_imag);
  RealVectorValue Q_imag = 2 * _beta.value(_t, _q_point[_qp]) * _normals[_qp].cross(incoming_real);

  if (_component == "real")
  {
    return _sign * (Q_real * _normals[_qp].cross(_test[_i][_qp]) -
                    _beta.value(_t, _q_point[_qp]) * (_normals[_qp].cross(_test[_i][_qp])) *
                        (_normals[_qp].cross(_coupled_val[_qp])));
  }
  else
  {
    return _sign * (Q_imag * _normals[_qp].cross(_test[_i][_qp]) +
                    _beta.value(_t, _q_point[_qp]) * (_normals[_qp].cross(_test[_i][_qp])) *
                        (_normals[_qp].cross(_coupled_val[_qp])));
  }
}

// CURRENTLY DOESN'T SEEM TO BE CORRECT - USE PJFNK OR NEWTON PLUS FDP IF YOU
// NEED THIS BC
Real
VectorPortBC::computeQpJacobian()
{
  return 0.0;
}

Real
VectorPortBC::computeQpOffDiagJacobian(unsigned jvar)
{
  if (jvar == _coupled_id)
  {
    if (_component == "real")
    {
      return -_beta.value(_t, _q_point[_qp]) * (_normals[_qp].cross(_test[_i][_qp])) *
             (_normals[_qp].cross(_phi[_j][_qp]));
    }
{'fraction_non_alphanumeric': 0.145, 'fraction_numerical': 0.004571428571428572, 'mean_word_length': 3.7625850340136053, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1452781', 'n_tokens_mistral': 2404, 'n_tokens_neox': 2311, 'n_words': 392}