LCOV - code coverage report
Current view: top level - src/postprocessors - ReflectionCoefficient.C (source / functions) Hit Total Coverage
Test: idaholab/moose electromagnetics: #33187 (5aa0b2) with base d7c4bd Lines: 41 42 97.6 %
Date: 2026-06-30 12:19:26 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          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 "ReflectionCoefficient.h"
      11             : #include "ElectromagneticConstants.h"
      12             : #include <complex>
      13             : 
      14             : registerMooseObject("ElectromagneticsApp", ReflectionCoefficient);
      15             : 
      16             : InputParameters
      17          21 : ReflectionCoefficient::validParams()
      18             : {
      19          21 :   InputParameters params = SidePostprocessor::validParams();
      20          21 :   params.addClassDescription(
      21             :       "CURRENTLY ONLY FOR 1D PLANE WAVE SOLVES. Calculate power reflection coefficient "
      22             :       "for impinging wave on a surface. Assumes that wave of form F = F_incoming + R*F_reflected");
      23          42 :   params.addRequiredCoupledVar(
      24             :       "field_real", "The name of the real field variable this postprocessor operates on.");
      25          42 :   params.addRequiredCoupledVar("field_imag", "Coupled imaginary field variable.");
      26          42 :   params.addRequiredRangeCheckedParam<Real>("theta", "theta>=0", "Wave incidence angle");
      27          42 :   params.addRequiredRangeCheckedParam<Real>("length", "length>0", "Domain length");
      28          42 :   params.addRequiredRangeCheckedParam<Real>("k", "k>0", "Wave number");
      29          63 :   params.addRangeCheckedParam<Real>(
      30          42 :       "incoming_field_magnitude", 1.0, "incoming_field_magnitude>0", "Incoming field magnitude");
      31          21 :   return params;
      32           0 : }
      33             : 
      34          12 : ReflectionCoefficient::ReflectionCoefficient(const InputParameters & parameters)
      35             :   : SidePostprocessor(parameters),
      36             :     MooseVariableInterface<Real>(this, false, "field_real"),
      37          12 :     _qp(0),
      38          12 :     _coupled_real(coupledValue("field_real")),
      39          12 :     _coupled_imag(coupledValue("field_imag")),
      40          24 :     _theta(getParam<Real>("theta")),
      41          24 :     _length(getParam<Real>("length")),
      42          24 :     _k(getParam<Real>("k")),
      43          48 :     _incoming_mag(getParam<Real>("incoming_field_magnitude"))
      44             : {
      45          12 :   if (_mesh.dimension() > 1)
      46           2 :     mooseError("This object does not support two and three-dimensional meshes.");
      47          10 : }
      48             : 
      49             : void
      50           9 : ReflectionCoefficient::initialize()
      51             : {
      52           9 :   _reflection_coefficient = 0;
      53           9 : }
      54             : 
      55             : void
      56           6 : ReflectionCoefficient::execute()
      57             : {
      58           6 :   _reflection_coefficient = computeReflection();
      59           6 : }
      60             : 
      61             : PostprocessorValue
      62           8 : ReflectionCoefficient::getValue() const
      63             : {
      64           8 :   return _reflection_coefficient;
      65             : }
      66             : 
      67             : void
      68           1 : ReflectionCoefficient::threadJoin(const UserObject & y)
      69             : {
      70             :   const auto & pps = static_cast<const ReflectionCoefficient &>(y);
      71           1 :   Real temp_rc = _reflection_coefficient;
      72           1 :   _reflection_coefficient = std::max(temp_rc, pps._reflection_coefficient);
      73           1 : }
      74             : 
      75             : void
      76           8 : ReflectionCoefficient::finalize()
      77             : {
      78           8 :   gatherMax(_reflection_coefficient);
      79           8 : }
      80             : 
      81             : Real
      82           6 : ReflectionCoefficient::computeReflection()
      83             : {
      84           6 :   std::complex<double> field(_coupled_real[_qp], _coupled_imag[_qp]);
      85             : 
      86             :   std::complex<double> incoming_wave =
      87           6 :       _incoming_mag * std::exp(EM::j * _k * _length * std::cos(_theta * libMesh::pi / 180.));
      88             :   std::complex<double> reversed_wave =
      89             :       _incoming_mag * std::exp(-EM::j * _k * _length * std::cos(_theta * libMesh::pi / 180.));
      90             : 
      91             :   std::complex<double> reflection_coefficient_complex = (field - incoming_wave) / reversed_wave;
      92             : 
      93           6 :   return std::pow(std::abs(reflection_coefficient_complex), 2);
      94             : }

Generated by: LCOV version 1.14