https://mooseframework.inl.gov
ReflectRayBC.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 #include "ReflectRayBC.h"
11 
12 // Local includes
13 #include "RayTracingStudy.h"
14 
15 registerMooseObject("RayTracingApp", ReflectRayBC);
16 
19 {
20  auto params = GeneralRayBC::validParams();
21 
22  params.addParam<bool>(
23  "warn_non_planar",
24  true,
25  "Whether or not to emit a warning if a Ray is being reflected on a non-planar side");
26 
27  params.addClassDescription("A RayBC that reflects a Ray in a specular manner on a boundary.");
28 
29  return params;
30 }
31 
33  : GeneralRayBC(params), _warn_non_planar(getParam<bool>("warn_non_planar"))
34 {
35 }
36 
37 void
38 ReflectRayBC::onBoundary(const unsigned int num_applying)
39 {
41  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  currentRay()->getInfo());
49 
50  // No need to do anything if the Ray's gonna die anyway
51  if (!currentRay()->shouldContinue())
52  return;
53 
54  // The direction this Ray reflects off this boundary
56  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  changeRayDirection(reflected_direction, /* skip_changed_check = */ num_applying > 1);
65 }
66 
67 Point
68 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  Point reflected_direction = direction;
74  reflected_direction -= 2.0 * (reflected_direction * normal) * normal;
75  return reflected_direction / reflected_direction.norm();
76 }
const unsigned short & _current_intersected_side
The side that _current_ray intersects (if any)
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
const std::shared_ptr< Ray > & currentRay() const
Gets the current Ray that this is working on.
ReflectRayBC(const InputParameters &params)
Definition: ReflectRayBC.C:32
virtual const std::string & name() const
void mooseWarning(Args &&... args) const
RayBC that reflects a Ray.
Definition: ReflectRayBC.h:17
static Point reflectedDirection(const Point &direction, const Point &normal)
Computes the reflected direction given a direction and an outward normal for the surface it reflects ...
Definition: ReflectRayBC.C:68
const Elem *const & _current_elem
The current Elem that _current_ray is tracing through.
const THREAD_ID _tid
The thread id.
bool sideIsNonPlanar(const Elem *elem, const unsigned short s) const
Whether or not the side on elem elem is non-planar.
static InputParameters validParams()
Definition: ReflectRayBC.C:18
const bool _warn_non_planar
Whether or not to emit a warning if a Ray is being reflected on a non-planar side.
Definition: ReflectRayBC.h:34
registerMooseObject("RayTracingApp", ReflectRayBC)
virtual const Point & getSideNormal(const Elem *elem, const unsigned short side, const THREAD_ID tid)
Get the outward normal for a given element side.
void changeRayDirection(const Point &direction, const bool skip_changed_check=false)
Changes the current Ray&#39;s direction.
static InputParameters validParams()
Definition: GeneralRayBC.C:13
RayTracingStudy & _study
The RayTracingStudy associated with this object.
virtual void onBoundary(const unsigned int num_applying) override
Called on a Ray on the boundary to apply the Ray boundary condition.
Definition: ReflectRayBC.C:38