https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Ray.h
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#pragma once
11
12// Local includes
13#include "RayTracingCommon.h"
14
15// MOOSE includes
16#include "MooseError.h"
17#include "MooseTypes.h"
18
19// libMesh Includes
20#include "libmesh/parallel.h"
21
22// Forward declarations
23namespace libMesh
24{
25class Elem;
26}
27class RayTracingStudy;
28// Friend access to Ray
29class TraceRay;
30class TestRayLots;
31// Friend access to ChangeDirectionKey for accessing changeDirection()
33// Friend access to ChangeStartDirectionKey for accessing changeStartDirection()
34class RayKernelBase;
35class PeriodicRayBC;
36// Friend access to NonResetCountersKey for accessing constructor/reset without counter reset
37namespace MooseUtils
38{
39template <class T>
40class SharedPool;
41}
42
44typedef unsigned long int RayID;
46#ifdef SINGLE_PRECISION_RAY
47typedef float RayData;
48#else
50#endif
52typedef unsigned int RayDataIndex;
53
57class Ray
58{
59public:
70
81
92
100 {
101 friend class RayTracingStudy;
102 friend class MooseUtils::SharedPool<Ray>;
103 friend class TestRayLots;
106 };
107
123 const RayID id,
124 const std::size_t data_size,
125 const std::size_t aux_data_size,
126 const bool reset,
127 const ConstructRayKey &);
128
145 const RayID id,
146 const std::size_t data_size,
147 const std::size_t aux_data_size,
148 const bool reset,
149 const ConstructRayKey &);
150
161 Ray(const Ray * const other, const ConstructRayKey &);
162
174 void reset(const Ray * const other, const ConstructRayKey &);
175
182 Ray & operator=(const Ray &) = delete;
189 Ray() = delete;
196 Ray(const Ray & other) = delete;
197
203 bool operator==(const Ray & other) const { return equalityHelper(other, true); }
209 bool operator!=(const Ray & other) const { return equalityHelper(other, false); }
210
212 static const RayDataIndex INVALID_RAY_DATA_INDEX = static_cast<RayDataIndex>(-1);
214 static const RayID INVALID_RAY_ID = static_cast<RayID>(-1);
215
219 RayID id() const { return _id; }
223 bool invalidID() const { return _id == INVALID_RAY_ID; }
224
233 const Point & currentPoint() const { return _current_point; }
238
249 void changeDirection(const Point & direction, const ChangeDirectionKey);
250
261 void
262 changeStartDirection(const Point & start, const Point & direction, const ChangeStartDirectionKey);
263
271 void changePointElemSide(const Point & point,
272 const Elem & elem,
273 const unsigned int side,
274 const ChangePointElemSideKey);
275
279 const Point & direction() const { return _direction; }
284
291 std::vector<RayData> & data();
298 const std::vector<RayData> & data() const;
305 RayData & data(const std::size_t i);
312 const RayData & data(const std::size_t i) const;
313
320 std::vector<RayData> & auxData();
327 const std::vector<RayData> & auxData() const;
334 RayData & auxData(const std::size_t i);
341 const RayData & auxData(const std::size_t i) const;
342
355 void setStart(const Point & starting_point,
356 const Elem * starting_elem = nullptr,
357 const unsigned short starting_incoming_side = RayTracingCommon::invalid_side);
365 void setStartingDirection(const Point & starting_direction);
376 void setStartingEndPoint(const Point & starting_end_point);
388 void setStartingMaxDistance(const Real starting_max_distance);
397 void setStationary();
398
427 void clearStartingInfo();
428
434 void resetCounters();
435
449 const Elem * currentElem() const { return _current_elem; }
450
459 unsigned short currentIncomingSide() const { return _current_incoming_side; }
472
478 bool endSet() const { return _end_set; }
487 bool atEnd() const;
497 Point endPoint() const;
498
502 unsigned int processorCrossings() const { return _processor_crossings; }
503
507 unsigned int intersections() const { return _intersections; }
508
512 Real distance() const { return _distance; }
519 Real maxDistance() const { return _max_distance; }
523 bool maxDistanceSet() const { return _max_distance != std::numeric_limits<Real>::max(); }
524
528 inline bool stationary() const;
529
533 bool shouldContinue() const { return _should_continue; }
537 void setShouldContinue(const bool should_continue) { _should_continue = should_continue; }
538
542 bool trajectoryChanged() const { return _trajectory_changed; }
546 unsigned int trajectoryChanges() const { return _trajectory_changes; }
547
551 std::string getInfo() const;
552
556 bool hasTraced() const
557 {
558 return (bool)_distance || (bool)_processor_crossings || (bool)_intersections;
559 }
560
564 const RayTracingStudy & study() const { return _study; }
565
566private:
570 void changeID(const RayID id) { _id = id; }
571
576
580 void setCurrentPoint(const Point & current_point) { _current_point = current_point; }
585
589 void setDirection(const Point & direction) { _direction = direction; }
594
598 void setCurrentElem(const Elem * current_elem) { _current_elem = current_elem; }
599
603 void setCurrentIncomingSide(const unsigned short current_incoming_side)
604 {
605 _current_incoming_side = current_incoming_side;
606 }
611
615 void setTrajectoryChanged(const bool trajectory_changed)
616 {
617 _trajectory_changed = trajectory_changed;
618 }
619
624
629
634
638 void addDistance(const Real add_distance) { _distance += add_distance; }
642 void changeMaxDistance(const Real max_distance) { _max_distance = max_distance; }
646 void invalidateMaxDistance() { _max_distance = std::numeric_limits<Real>::max(); }
647
651 void errorIfTracing(const std::string & reason) const;
655 void errorWhenInitializing(const std::string & reason) const;
656
661
665 bool equalityHelper(const Ray & other, const bool equal) const;
666
671
674
684
687
701 const Elem * _current_elem;
702
712
720
723
725 unsigned int _intersections;
726
729
734
737 mutable std::vector<RayData> _data;
738
741 mutable std::vector<RayData> _aux_data;
742
745
746 // TraceRay is the only object that should be executing Rays and therefore needs access
747 friend class TraceRay;
748 // Packing needs access to changing the internal counters during the trace
749 friend class Parallel::Packing<std::shared_ptr<Ray>>;
750 // Allows for testing of equality methods
751 friend class TestRayLots;
752 // Data helpers needs to be able to access the internal methods for a Ray for store/load
753 friend void dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray, void * context);
754 friend void dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray, void * context);
755};
756
757bool
759{
760 const bool stationary = _max_distance == 0;
761 if (stationary)
762 mooseAssert(_intersections == 0, "Should be zero");
763 return stationary;
764}
765
770namespace libMesh
771{
772namespace Parallel
773{
774template <>
775class Packing<std::shared_ptr<Ray>>
776{
777public:
779
780 static unsigned int packed_size(typename std::vector<Real>::const_iterator in);
781 static unsigned int packable_size(const std::shared_ptr<Ray> & ray, const void *);
782 static unsigned int size(const std::size_t data_size, const std::size_t aux_data_size);
783
784 template <typename Iter, typename Context>
785 static void pack(const std::shared_ptr<Ray> & object, Iter data_out, const Context * context);
786
787 template <typename BufferIter, typename Context>
788 static std::shared_ptr<Ray> unpack(BufferIter in, Context * context);
789};
790
791} // namespace Parallel
792
793} // namespace libMesh
794
795void dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray, void * context);
796void dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray, void * context);
unsigned int RayDataIndex
Type for the index into the data and aux data on a Ray.
Definition Ray.h:52
unsigned long int RayID
Type for a Ray's ID.
Definition Ray.h:44
float RayData
Type for a Ray's data.
Definition Ray.h:47
RayBC that enforces periodic boundaries.
Base class for the RayBC syntax.
Base object for the RayKernel syntax.
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...
Class that is used as a parameter to changeDirection() that allows only RayBC methods to call changeD...
Definition Ray.h:65
ChangeDirectionKey(const ChangeDirectionKey &)
Definition Ray.h:68
Class that is used as a parameter to changePointElem() that allows only PeriodicRayBC methods to call...
Definition Ray.h:87
ChangePointElemSideKey(const ChangePointElemSideKey &)
Definition Ray.h:90
Class that is used as a parameter to changeStartDirection() that allows only RayKernelBase methods to...
Definition Ray.h:76
ChangeStartDirectionKey(const ChangeStartDirectionKey &)
Definition Ray.h:79
Class that is used as a parameter to the public constructors/reset methods.
Definition Ray.h:100
ConstructRayKey(const ConstructRayKey &)
Definition Ray.h:105
Basic datastructure for a ray that will traverse the mesh.
Definition Ray.h:58
void addDistance(const Real add_distance)
Adds to the distance this Ray has traveled.
Definition Ray.h:638
unsigned short currentIncomingSide() const
Get a Ray's current incoming side.
Definition Ray.h:459
static const RayDataIndex INVALID_RAY_DATA_INDEX
Invalid index into a Ray's data.
Definition Ray.h:212
void invalidateMaxDistance()
Invalidates the Ray's max distance.
Definition Ray.h:646
std::vector< RayData > _aux_data
Auxiliary data that is carried with the ray This is mutable so that we can resize it if needed within...
Definition Ray.h:741
void changeID(const RayID id)
Changes the Ray's ID.
Definition Ray.h:570
Real _max_distance
Maximum distance the Ray is allowed to travel.
Definition Ray.h:733
bool endSet() const
Whether or not the user has set an end point for this Ray.
Definition Ray.h:478
unsigned int trajectoryChanges() const
Gets the number of trajectory changes this Ray has had.
Definition Ray.h:546
void invalidateCurrentIncomingSide()
Invalidates the Ray's current incoming side.
Definition Ray.h:610
std::vector< RayData > & auxData()
Gets a writeable reference to the Ray's auxilary data.
Definition Ray.C:451
void setStartingEndPoint(const Point &starting_end_point)
Sets the starting end point to starting_point for a Ray.
Definition Ray.C:299
void clearStartingInfo()
Clears the starting information set on the Ray:
Definition Ray.C:367
void changeDirection(const Point &direction, const ChangeDirectionKey)
This method is for internal use only.
Definition Ray.C:196
Point _direction
Direction of the Ray.
Definition Ray.h:686
std::vector< RayData > _data
The data that is carried with the Ray This is mutable so that we can resize it if needed within const...
Definition Ray.h:737
bool invalidCurrentIncomingSide() const
Whether or not the Ray's current incoming side is invalid.
Definition Ray.h:468
void addIntersection()
Increment the Ray's intersection counter.
Definition Ray.h:628
void setStartingDirection(const Point &starting_direction)
Sets the starting direction to starting_direction for a Ray.
Definition Ray.C:282
void resetCountersInternal()
Reset all of the internal counters.
Definition Ray.C:406
Real distance() const
Gets the distance this Ray has traveled.
Definition Ray.h:512
void errorWhenInitializing(const std::string &reason) const
Produces a useful error for use when initializing a Ray.
Definition Ray.C:392
bool hasTraced() const
Whether or not a Ray has begun tracing.
Definition Ray.h:556
bool _should_continue
Wether or not the Ray should continue to be traced (not sent in parallel)
Definition Ray.h:719
void clearStartingInfoInternal()
Clears the starting information.
Definition Ray.C:374
bool maxDistanceSet() const
Whether or not the distance has been set via setStartingMaxDistance()
Definition Ray.h:523
friend void dataStore(std::ostream &stream, std::shared_ptr< Ray > &ray, void *context)
Definition Ray.C:713
Real maxDistance() const
Gets the max distance this Ray is allowed to travel.
Definition Ray.h:519
void reset(RayTracingStudy *study, const RayID id, const std::size_t data_size, const std::size_t aux_data_size, const bool reset, const ConstructRayKey &)
Resets a Ray for internal use only.
bool operator!=(const Ray &other) const
Non-equal operator.
Definition Ray.h:209
Ray()=delete
Deleted default constructor.
unsigned int processorCrossings() const
Gets the number of times this Ray has crossed a processor.
Definition Ray.h:502
void resetCounters()
Clears the internal counters on the Ray so that the Ray can be traced again.
Definition Ray.C:398
void errorIfTracing(const std::string &reason) const
Produces a useful error if a Ray has started tracing.
Definition Ray.C:385
void setCurrentElem(const Elem *current_elem)
Change a Ray's current elem.
Definition Ray.h:598
Ray & operator=(const Ray &)=delete
Deleted copy operator.
std::vector< RayData > & data()
Gets a writeable reference to the Ray's data.
Definition Ray.C:417
bool trajectoryChanged() const
Whether or not this Ray has had its trajectory changed.
Definition Ray.h:542
void setStationary()
Sets the Ray to be stationary (max distance = 0).
Definition Ray.C:339
void setCurrentIncomingSide(const unsigned short current_incoming_side)
Change a Ray's incoming side.
Definition Ray.h:603
const Elem * _current_elem
Current element that the Ray is in.
Definition Ray.h:701
void setShouldContinue(const bool should_continue)
Sets whether or not this Ray should continue.
Definition Ray.h:537
bool _end_set
Whether or not the user has set an end point for this Ray (via limiting its distance with setStarting...
Definition Ray.h:717
Real _distance
Total distance this Ray has traveled.
Definition Ray.h:731
void invalidateStartingIncomingSide()
Invalidates a Ray's starting incoming side.
Definition Ray.C:360
void setCurrentPoint(const Point &current_point)
Sets the Ray's current point.
Definition Ray.h:580
unsigned int intersections() const
Gets the number of intersections this Ray has done.
Definition Ray.h:507
friend void dataLoad(std::istream &stream, std::shared_ptr< Ray > &ray, void *context)
Definition Ray.C:738
Ray(const Ray &other)=delete
Deleted copy constructor.
const Elem * currentElem() const
Gets the current element that the Ray is in.
Definition Ray.h:449
const Point & currentPoint() const
Gets the point that the Ray is currently at.
Definition Ray.h:233
bool operator==(const Ray &other) const
Equality operator.
Definition Ray.h:203
unsigned int _intersections
Number of intersections done for this Ray.
Definition Ray.h:725
const RayTracingStudy & study() const
Get the RayTracingStudy associated with this Ray.
Definition Ray.h:564
void setTrajectoryChanged(const bool trajectory_changed)
Set whether or not this Ray has had its trajectory changed.
Definition Ray.h:615
bool stationary() const
Definition Ray.h:758
bool invalidDirection() const
Whether or not the Ray's direction is set to invalid.
Definition Ray.h:283
Point endPoint() const
Gets the user-set end point for the Ray, if set.
Definition Ray.C:186
bool _trajectory_changed
Whether or not this Ray had its trajectory changed (not sent in parallel)
Definition Ray.h:714
void invalidateDirection()
Invalidates the Ray's current direction.
Definition Ray.h:593
static const RayID INVALID_RAY_ID
Invalid Ray ID.
Definition Ray.h:214
RayID _id
A unique ID for this Ray.
Definition Ray.h:673
bool invalidID() const
Whether or not the Ray's ID is invalid.
Definition Ray.h:223
bool equalityHelper(const Ray &other, const bool equal) const
Helper for the equality operators.
Definition Ray.C:126
void invalidateStartingElem()
Invalidates a Ray's starting element.
Definition Ray.C:353
void setDirection(const Point &direction)
Sets the Ray's direction.
Definition Ray.h:589
bool atEnd() const
Whether or not the Ray is at the user-defined end point.
Definition Ray.C:176
void addTrajectoryChange()
Increment the Ray's trajectory change counter.
Definition Ray.h:633
RayID id() const
Gets the Ray's ID.
Definition Ray.h:219
void setStart(const Point &starting_point, const Elem *starting_elem=nullptr, const unsigned short starting_incoming_side=RayTracingCommon::invalid_side)
Sets the information pretaining to the start point for the Ray.
Definition Ray.C:233
void addProcessorCrossing()
Increment the Ray's processor crossing counter.
Definition Ray.h:623
unsigned int _trajectory_changes
Number of times this Ray has had its trajectory changed.
Definition Ray.h:728
RayTracingStudy & _study
The RayTracingStudy that owns this Ray (not sent in parallel)
Definition Ray.h:744
Point _current_point
Current point of the Ray.
Definition Ray.h:683
void changeStartDirection(const Point &start, const Point &direction, const ChangeStartDirectionKey)
This method is for internal use only.
Definition Ray.C:206
unsigned short _current_incoming_side
The side of _current_elem that the Ray is incoming on (if any).
Definition Ray.h:711
void setStartingMaxDistance(const Real starting_max_distance)
Sets the maximum distance this Ray should travel to starting_max_distance.
Definition Ray.C:324
std::string getInfo() const
Helper function for getting information about the Ray.
Definition Ray.C:483
bool shouldContinue() const
Whether or not this Ray should continue.
Definition Ray.h:533
bool invalidCurrentPoint() const
Whether or not the point that the Ray is currently at is valid.
Definition Ray.h:237
const Point & direction() const
Gets the Ray's direction.
Definition Ray.h:279
void invalidateCurrentElem()
Invalidates the Ray's current element.
Definition Ray.h:575
void changePointElemSide(const Point &point, const Elem &elem, const unsigned int side, const ChangePointElemSideKey)
This method is for internal use only.
Definition Ray.C:219
void invalidateCurrentPoint()
Invalidates the Ray's current point.
Definition Ray.h:584
unsigned int _processor_crossings
Number of times this Ray has been communicated.
Definition Ray.h:722
void changeMaxDistance(const Real max_distance)
Changes the Ray's max distance to be traveled.
Definition Ray.h:642
Traces Rays through the mesh on a single processor.
Definition TraceRay.h:47
static void pack(const std::shared_ptr< Ray > &object, Iter data_out, const Context *context)
static std::shared_ptr< Ray > unpack(BufferIter in, Context *context)
static const unsigned short invalid_side
Identifier for an invalid side index.
static const libMesh::Point invalid_point(invalid_distance, invalid_distance, invalid_distance)
Identifier for an invalid point.
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real