https://mooseframework.inl.gov
RayKernelBase.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 "RayKernelBase.h"
11 
12 // Local includes
13 #include "RayTracingStudy.h"
14 #include "TraceRay.h"
15 
18 {
19  auto params = RayTracingObject::validParams();
21  params += RandomInterface::validParams();
23 
24  params.addParam<std::vector<std::string>>("depends_on",
25  "Other RayKernels that this RayKernel depends on");
26 
27  params.registerBase("RayKernel");
28  params.registerSystemAttributeName("RayKernel");
29 
30  // Allows for a RayKernel to request that it needs a reinit on its segment
31  // We have this so that for RayKernels that still need qps and weights but do not
32  // have any active variables or materials can still call reinitSegment()
33  params.addPrivateParam<bool>("_need_segment_reinit", false);
34 
35  return params;
36 }
37 
39  : RayTracingObject(params),
41  BlockRestrictable(this),
42  RandomInterface(params, _fe_problem, _tid, false),
44  Restartable(this, "RayKernels"),
45  _current_segment_start(_trace_ray.currentIncomingPoint()),
46  _current_segment_end(_trace_ray.currentIntersectionPoint()),
47  _current_segment_length(_trace_ray.currentIntersectionDistance()),
48  _current_incoming_side(_trace_ray.currentIncomingSide()),
49  _need_segment_reinit(getParam<bool>("_need_segment_reinit"))
50 {
51  // Add dependencies
52  if (isParamValid("depends_on"))
53  for (const auto & name : getParam<std::vector<std::string>>("depends_on"))
54  dependsOn(name);
55 
56  // Stateful material properties are not allowed on RayKernels
58 }
59 
61 
62 void
63 RayKernelBase::changeRayStartDirection(const Point & start, const Point & direction)
64 {
65  mooseAssert(_study.currentlyPropagating(), "Should not change Ray outside of tracing");
66 
67  const auto & ray = currentRay();
68 
69  if (!ray->shouldContinue())
70  {
71  if (ray->endSet() && ray->atEnd())
72  mooseError("Cannot changeRayStartDirection() for a Ray that should not continue.\n\n",
73  "It has also hit its user-set end point.\n\n",
74  ray->getInfo());
75  else
76  mooseError("Cannot changeRayStartDirection() for a Ray that should not continue.\n\n",
77  ray->getInfo());
78  }
79 
80  if (ray->trajectoryChanged())
81  mooseError("Cannot change a Ray's trajectory when its trajectory has already been changed\n\n",
82  ray->getInfo());
83 
84  if (ray->endSet())
85  mooseError("Cannot change the direction of a Ray whose end point is set upon generation "
86  "(via setStartingEndPoint()).\n\n",
87  ray->getInfo());
88 
89  if (_study.verifyRays() && !_current_elem->contains_point(start))
90  mooseError("A Ray's start point was changed within a RayKernel, and said start point\n",
91  "is not within the element that the RayKernel was executed on.\n\n",
92  ray->getInfo());
93 
94  ray->changeStartDirection(start, direction, Ray::ChangeStartDirectionKey());
95 }
96 
97 std::shared_ptr<Ray>
98 RayKernelBase::acquireRay(const Point & start, const Point & direction)
99 {
100  mooseAssert(_study.currentlyPropagating(), "Should not be getting a Ray while not propagating");
101 
102  // Acquire a Ray with the proper sizes and a unique ID, and set the start info
103  std::shared_ptr<Ray> ray =
105  ray->setStart(start, _current_elem, RayTracingCommon::invalid_side);
106  ray->setStartingDirection(direction);
107 
108  return ray;
109 }
110 
111 void
112 RayKernelBase::moveRayToBuffer(std::shared_ptr<Ray> & ray)
113 {
114  mooseAssert(_study.currentlyPropagating(),
115  "Should not move Rays into buffer while not propagating");
116 
118 }
119 
120 void
122 {
123 }
124 
125 void
127 {
128 }
static const unsigned short invalid_side
Identifier for an invalid side index.
void moveRayToBufferDuringTrace(std::shared_ptr< Ray > &ray, const THREAD_ID tid, const AcquireMoveDuringTraceKey &)
INTERNAL method for moving a Ray into the buffer during tracing.
Base class for a MooseObject used in ray tracing.
void moveRayToBuffer(std::shared_ptr< Ray > &ray)
Moves a Ray into the working buffer to be traced during tracing with a meaningful error on verificati...
virtual void preTrace()
Called at the beginning of the trace on this processor/thread for a Ray.
const std::shared_ptr< Ray > & currentRay() const
Gets the current Ray that this is working on.
static InputParameters validParams()
Key that is used for restricting access to moveRayToBufferDuringTrace() and acquireRayDuringTrace().
std::shared_ptr< Ray > acquireRayDuringTrace(const THREAD_ID tid, const AcquireMoveDuringTraceKey &)
INTERNAL methods for acquiring a Ray during a trace in RayKernels and RayBCs.
virtual const std::string & name() const
static InputParameters validParams()
bool isParamValid(const std::string &name) const
bool verifyRays() const
Whether or not to verify if Rays have valid information before being traced.
std::shared_ptr< Ray > acquireRay(const Point &start, const Point &direction)
Acquires a Ray to be used for generating a new Ray while tracing on the boundary. ...
Definition: RayKernelBase.C:98
static InputParameters validParams()
Definition: RayKernelBase.C:17
const Elem *const & _current_elem
The current Elem that _current_ray is tracing through.
static InputParameters validParams()
static InputParameters validParams()
const T & getParam(const std::string &name) const
const THREAD_ID _tid
The thread id.
RayKernelBase(const InputParameters &params)
Definition: RayKernelBase.C:38
void statefulPropertiesAllowed(bool)
void dependsOn(const std::string name)
Add an object of this classes base type that this class depends on.
bool currentlyPropagating() const
Whether or not the study is propagating (tracing Rays)
const std::set< BoundaryID > EMPTY_BOUNDARY_IDS
Class that is used as a parameter to changeStartDirection() that allows only RayKernelBase methods to...
Definition: Ray.h:74
void changeRayStartDirection(const Point &start, const Point &direction)
Changes the current Ray&#39;s start point and direction.
Definition: RayKernelBase.C:63
void mooseError(Args &&... args) const
RayTracingStudy & _study
The RayTracingStudy associated with this object.
virtual void postTrace()
This method is called once a ray has reached the end of its trace.
virtual ~RayKernelBase()
Definition: RayKernelBase.C:60