https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
37void
38ReflectRayBC::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
67Point
68ReflectRayBC::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}
registerMooseObject("RayTracingApp", ReflectRayBC)
const std::string name
Definition Setup.h:21
static InputParameters validParams()
void mooseWarning(Args &&... args) const
void changeRayDirection(const Point &direction, const bool skip_changed_check=false)
Changes the current Ray's direction.
const THREAD_ID _tid
The thread id.
RayTracingStudy & _study
The RayTracingStudy associated with this object.
const unsigned short & _current_intersected_side
The side that _current_ray intersects (if any)
const std::shared_ptr< Ray > & currentRay() const
Gets the current Ray that this is working on.
const Elem *const & _current_elem
The current Elem that _current_ray is tracing through.
bool sideIsNonPlanar(const Elem *elem, const unsigned short s) const
Whether or not the side \s on elem elem is non-planar.
virtual const Point & getSideNormal(const Elem *elem, const unsigned short side, const THREAD_ID tid)
Get the outward normal for a given element side.
RayBC that reflects a Ray.
const bool _warn_non_planar
Whether or not to emit a warning if a Ray is being reflected on a non-planar side.
static InputParameters validParams()
ReflectRayBC(const InputParameters &params)
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 ...
virtual void onBoundary(const unsigned int num_applying) override
Called on a Ray on the boundary to apply the Ray boundary condition.