LCOV - code coverage report
Current view: top level - src/raybcs - ReflectRayBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose ray_tracing: #31405 (292dce) with base fef103 Lines: 22 23 95.7 %
Date: 2025-09-04 07:56:07 Functions: 4 4 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 "ReflectRayBC.h"
      11             : 
      12             : // Local includes
      13             : #include "RayTracingStudy.h"
      14             : 
      15             : registerMooseObject("RayTracingApp", ReflectRayBC);
      16             : 
      17             : InputParameters
      18         872 : ReflectRayBC::validParams()
      19             : {
      20         872 :   auto params = GeneralRayBC::validParams();
      21             : 
      22        1744 :   params.addParam<bool>(
      23             :       "warn_non_planar",
      24        1744 :       true,
      25             :       "Whether or not to emit a warning if a Ray is being reflected on a non-planar side");
      26             : 
      27         872 :   params.addClassDescription("A RayBC that reflects a Ray in a specular manner on a boundary.");
      28             : 
      29         872 :   return params;
      30           0 : }
      31             : 
      32         477 : ReflectRayBC::ReflectRayBC(const InputParameters & params)
      33         954 :   : GeneralRayBC(params), _warn_non_planar(getParam<bool>("warn_non_planar"))
      34             : {
      35         477 : }
      36             : 
      37             : void
      38        4601 : ReflectRayBC::onBoundary(const unsigned int num_applying)
      39             : {
      40        4601 :   if (_warn_non_planar && _study.sideIsNonPlanar(_current_elem, _current_intersected_side))
      41           2 :     mooseWarning("A Ray is being reflected on a non-planar side.\n\n",
      42             :                  "Ray tracing on elements with non-planar faces is an approximation.\n\n",
      43             :                  "The normal used to compute the reflected direction is computed at\n",
      44             :                  "the side centroid and may not be valid for a non-planar side.\n\n",
      45             :                  "To disable this warning, set RayKernels/",
      46             :                  name(),
      47             :                  "/warn_non_planar=false.\n\n",
      48           2 :                  currentRay()->getInfo());
      49             : 
      50             :   // No need to do anything if the Ray's gonna die anyway
      51        4599 :   if (!currentRay()->shouldContinue())
      52         540 :     return;
      53             : 
      54             :   // The direction this Ray reflects off this boundary
      55        4059 :   const auto & normal = _study.getSideNormal(_current_elem, _current_intersected_side, _tid);
      56        4059 :   const auto reflected_direction = reflectedDirection(currentRay()->direction(), normal);
      57             : 
      58             :   // Change it! Note here the usage of num_applying: if we are at a corner with a reflecting
      59             :   // boundary condition on both sides, we want to allow both boundary conditions to reflect the Ray.
      60             :   // Therefore, we skip the check that another RayBC has changed the Ray's trajectory when we are
      61             :   // applying multiple of the same ReflectRayBC at different boundaries at the same point to allow
      62             :   // this. Note that this double (or triple in 3D) reflection will only be allowed when the same
      63             :   // ReflectRayBC object is on both boundaries.
      64        4059 :   changeRayDirection(reflected_direction, /* skip_changed_check = */ num_applying > 1);
      65             : }
      66             : 
      67             : Point
      68        4059 : ReflectRayBC::reflectedDirection(const Point & direction, const Point & normal)
      69             : {
      70             :   mooseAssert(MooseUtils::absoluteFuzzyEqual(direction.norm(), 1.), "Direction not normalized");
      71             :   mooseAssert(MooseUtils::absoluteFuzzyEqual(normal.norm(), 1.), "Normal not normalized");
      72             : 
      73        4059 :   Point reflected_direction = direction;
      74        4059 :   reflected_direction -= 2.0 * (reflected_direction * normal) * normal;
      75        4059 :   return reflected_direction / reflected_direction.norm();
      76             : }

Generated by: LCOV version 1.14