24 const std::size_t data_size,
25 const std::size_t aux_data_size,
31 _current_elem(nullptr),
34 _max_distance(
std::numeric_limits<
Real>::max()),
36 _aux_data(aux_data_size, 0),
45 const std::size_t data_size,
46 const std::size_t aux_data_size,
48 const ConstructRayKey &)
51 _data.resize(data_size, 0);
67 mooseAssert(
study == &
_study,
"Resetting Ray from different study");
74 other->_aux_data.size(),
101 mooseAssert(&other->
_study == &
_study,
"Cannot copy Ray from different study");
161 for (std::size_t i = 0; i <
_data.size(); ++i)
162 if (!MooseUtils::absoluteFuzzyEqual(
_data[i], other.
_data[i]))
166 for (std::size_t i = 0; i <
_aux_data.size(); ++i)
179 mooseError(
"Cannot use Ray::atEnd() for a Ray that does not have an end set\n\n",
getInfo());
189 mooseError(
"Cannot use Ray::endPoint() for a Ray that does not have an end set\n\n",
getInfo());
207 const Point & direction,
221 const unsigned int side,
234 const Elem * starting_elem ,
235 const unsigned short starting_incoming_side )
241 "\n\nYou may only call Ray::setStart() after it has been called once to"
242 "\nchange the starting element and starting incoming side."
243 "\n\nYou may also clear the starting info via Ray::clearStartingInfo().");
256 "Element is not owned by the mesh");
257 if (!starting_elem->
active())
261 bool non_planar_start =
false;
267 if (starting_elem->
n_sides() < starting_incoming_side)
271 if (!non_planar_start &&
272 !starting_elem->
build_side_ptr(starting_incoming_side)->contains_point(starting_point))
276 if (starting_elem && !non_planar_start && !starting_elem->
contains_point(starting_point))
289 "Cannot change a Ray's starting direction using Ray::setStartingDirection()"
290 "\nafter it has already been set."
291 "\n\nYou must first clear the starting info using Ray::clearStartingInfo().");
308 "\n\nClear the starting information with Ray::clearStartingInfo().");
311 "Cannot use Ray::setStartingEndPoint() after Ray::setStartingMaxDistance().");
316 Point difference = starting_end_point;
329 if (starting_max_distance <= 0)
333 "Cannot use Ray::setStartingMaxDistance() after Ray::setStartingEndPoint().");
349 mooseAssert(
stationary(),
"Stationary not set");
362 errorIfTracing(
"Cannot use Ray::invalidateStartingIncomingSide()");
394 mooseError(
"While initializing starting information for a Ray:\n\n", reason,
"\n\n",
getInfo());
401 mooseError(
"Ray::resetCounters() can only be used during generateRays()\n\n",
getInfo());
416std::vector<RayData> &
420 "Ray data size of " + std::to_string(
_data.size()) +
421 " is not zero or the size required by the study of " +
427const std::vector<RayData> &
431 "Ray data size is not zero or the size required by study");
450std::vector<RayData> &
454 "Ray data size is not zero or the size required by study");
459const std::vector<RayData> &
463 "Ray data size is not zero or the size required by study");
485 std::ostringstream oss;
489 oss <<
" this = " <<
this <<
"\n";
490 oss <<
" id() = " <<
id() <<
"\n";
493 oss <<
" currentPoint() = ";
495 oss <<
"invalid point\n";
498 oss <<
" direction() = ";
500 oss <<
"invalid point\n";
503 oss <<
" currentIncomingSide() = ";
505 oss <<
"invalid side\n";
508 oss <<
" endSet() = " << (
endSet() ?
"true" :
"false") <<
"\n";
511 oss <<
" endPoint() = " <<
endPoint() <<
"\n";
512 oss <<
" atEnd() = " << (
atEnd() ?
"true" :
"false") <<
"\n";
514 oss <<
" distance() = " <<
distance() <<
"\n";
515 oss <<
" maxDistance() = " <<
maxDistance() <<
"\n";
518 oss <<
" currentElem()->id() = " <<
currentElem()->
id() <<
"\n";
522 oss <<
" currentElem()->id() = invalid\n";
526 oss <<
" shouldContinue() = " << (
shouldContinue() ?
"true" :
"false") <<
"\n";
527 oss <<
" trajectoryChanged() = " << (
trajectoryChanged() ?
"true" :
"false") <<
"\n";
529 for (std::size_t i = 0; i <
data().size(); ++i)
532 oss <<
" auxData() = ";
533 for (std::size_t i = 0; i <
auxData().size(); ++i)
550 constexpr unsigned int mixed_size = RayTracingPackingUtils::
551 mixedPackSize<buffer_type, unsigned short, bool, unsigned int, unsigned int, unsigned int>();
552 mooseAssert(mixed_size == 2,
"Mixed size should be 2");
557 auto size = 12 + mixed_size;
559#ifdef SINGLE_PRECISION_RAY
561 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(data_size);
563 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(aux_data_size);
565 size += data_size + aux_data_size;
574 const std::size_t data_size =
static_cast<std::size_t
>(*in++);
575 const std::size_t aux_data_size =
static_cast<std::size_t
>(*in);
577 return size(data_size, aux_data_size);
583 return size(ray->data().size(), ray->auxData().size());
591 mooseAssert(
dynamic_cast<ParallelRayStudy *
>(study),
"Not a ParallelRayStudy");
595 const std::size_t data_size =
static_cast<std::size_t
>(*in++);
596 const std::size_t aux_data_size =
static_cast<std::size_t
>(*in++);
602 std::shared_ptr<Ray> ray =
610 ray->_current_point(0) = *in++;
611 ray->_current_point(1) = *in++;
612 ray->_current_point(2) = *in++;
615 ray->_direction(0) = *in++;
616 ray->_direction(1) = *in++;
617 ray->_direction(2) = *in++;
624 RayTracingPackingUtils::mixedUnpack<buffer_type>(in,
625 ray->_current_incoming_side,
627 ray->_processor_crossings,
629 ray->_trajectory_changes);
632 ray->_distance = *in++;
635 ray->_max_distance = *in++;
637#ifdef SINGLE_PRECISION_RAY
638 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_data, in);
639 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_aux_data, in);
646 ray->_should_continue =
true;
647 ray->_trajectory_changed =
false;
655 std::back_insert_iterator<std::vector<buffer_type>> data_out,
658 mooseAssert(
dynamic_cast<const ParallelRayStudy *
>(study),
"Not a ParallelRayStudy");
661 mooseAssert(&ray->study() == &ray_tracing_study,
"Packing Ray for different study");
664 data_out =
static_cast<buffer_type>(ray->_data.size());
665 data_out =
static_cast<buffer_type>(ray->_aux_data.size());
668 data_out = RayTracingPackingUtils::pack<buffer_type>(ray->id());
671 data_out = ray->_current_point(0);
672 data_out = ray->_current_point(1);
673 data_out = ray->_current_point(2);
676 data_out = ray->_direction(0);
677 data_out = ray->_direction(1);
678 data_out = ray->_direction(2);
682 RayTracingPackingUtils::pack<buffer_type>(ray->_current_elem, &ray_tracing_study.
meshBase());
686 RayTracingPackingUtils::mixedPack<buffer_type>(data_out,
687 ray->_current_incoming_side,
689 ray->_processor_crossings,
691 ray->_trajectory_changes);
694 data_out = ray->_distance;
696 data_out = ray->_max_distance;
699#ifdef SINGLE_PRECISION_RAY
700 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_data, data_out);
701 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_aux_data, data_out);
703 std::copy(ray->_data.begin(), ray->_data.end(), data_out);
704 std::copy(ray->_aux_data.begin(), ray->_aux_data.end(), data_out);
713dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray,
void * context)
715 mooseAssert(ray,
"Null ray");
716 mooseAssert(context,
"Missing RayTracingStudy context");
717 mooseAssert(
static_cast<RayTracingStudy *
>(context) == &ray->study(),
"Different study");
724 storeHelper(stream, ray->_current_incoming_side, context);
725 storeHelper(stream, ray->_trajectory_changed, context);
727 storeHelper(stream, ray->_should_continue, context);
728 storeHelper(stream, ray->_processor_crossings, context);
730 storeHelper(stream, ray->_trajectory_changes, context);
738dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray,
void * context)
740 mooseAssert(context,
"Missing RayTracingStudy context");
751 loadHelper(stream, ray->_current_point, context);
756 loadHelper(stream, ray->_current_incoming_side, context);
757 loadHelper(stream, ray->_trajectory_changed, context);
759 loadHelper(stream, ray->_should_continue, context);
760 loadHelper(stream, ray->_processor_crossings, context);
761 loadHelper(stream, ray->_intersections, context);
762 loadHelper(stream, ray->_trajectory_changes, context);
764 loadHelper(stream, ray->_max_distance, context);
768 if (ray->hasTraced())
770 "Cannot not load a Ray that has already traced during generation or propagation; "
771 "reset the Ray first");
void storeHelper(std::ostream &stream, P &data, void *context)
void loadHelper(std::istream &stream, P &data, void *context)
void mooseError(Args &&... args)
void dataStore(std::ostream &stream, std::shared_ptr< Ray > &ray, void *context)
void dataLoad(std::istream &stream, std::shared_ptr< Ray > &ray, void *context)
unsigned long int RayID
Type for a Ray's ID.
float RayData
Type for a Ray's data.
const std::string & type() const
const std::string & name() const
Key that is used for restricting access to acquireRayInternal().
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...
MeshBase & meshBase() const
Access to the libMesh MeshBase.
bool sideIsNonPlanar(const Elem *elem, const unsigned short s) const
Whether or not the side \s on elem elem is non-planar.
std::size_t rayDataSize() const
The registered size of values in the Ray data.
bool currentlyGenerating() const
Whether or not the study is generating.
const std::string & getRayAuxDataName(const RayDataIndex index) const
Gets the name associated with a registered value in the Ray aux data.
bool useRayRegistration() const
Whether or not ray registration is being used.
const BoundingBox & looseBoundingBox() const
Get the loose nodal bounding box for the domain.
const std::string & registeredRayName(const RayID ray_id) const
Gets the name of a registered ray.
bool verifyRays() const
Whether or not to verify if Rays have valid information before being traced.
const std::string & getRayDataName(const RayDataIndex index) const
Gets the name associated with a registered value in the Ray data.
std::size_t rayAuxDataSize() const
The registered size of values in the Ray aux data.
std::shared_ptr< Ray > acquireRayInternal(const RayID id, const std::size_t data_size, const std::size_t aux_data_size, const bool reset, const AcquireRayInternalKey &)
bool currentlyPropagating() const
Whether or not the study is propagating (tracing Rays)
Class that is used as a parameter to changeDirection() that allows only RayBC methods to call changeD...
Class that is used as a parameter to changePointElem() that allows only PeriodicRayBC methods to call...
Class that is used as a parameter to changeStartDirection() that allows only RayKernelBase methods to...
Class that is used as a parameter to the public constructors/reset methods.
Basic datastructure for a ray that will traverse the mesh.
unsigned short currentIncomingSide() const
Get a Ray's current incoming side.
void invalidateMaxDistance()
Invalidates the Ray's max distance.
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...
Real _max_distance
Maximum distance the Ray is allowed to travel.
bool endSet() const
Whether or not the user has set an end point for this Ray.
unsigned int trajectoryChanges() const
Gets the number of trajectory changes this Ray has had.
void invalidateCurrentIncomingSide()
Invalidates the Ray's current incoming side.
std::vector< RayData > & auxData()
Gets a writeable reference to the Ray's auxilary data.
void setStartingEndPoint(const Point &starting_end_point)
Sets the starting end point to starting_point for a Ray.
void clearStartingInfo()
Clears the starting information set on the Ray:
void changeDirection(const Point &direction, const ChangeDirectionKey)
This method is for internal use only.
Point _direction
Direction of the Ray.
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...
bool invalidCurrentIncomingSide() const
Whether or not the Ray's current incoming side is invalid.
void setStartingDirection(const Point &starting_direction)
Sets the starting direction to starting_direction for a Ray.
void resetCountersInternal()
Reset all of the internal counters.
Real distance() const
Gets the distance this Ray has traveled.
void errorWhenInitializing(const std::string &reason) const
Produces a useful error for use when initializing a Ray.
bool hasTraced() const
Whether or not a Ray has begun tracing.
bool _should_continue
Wether or not the Ray should continue to be traced (not sent in parallel)
void clearStartingInfoInternal()
Clears the starting information.
bool maxDistanceSet() const
Whether or not the distance has been set via setStartingMaxDistance()
Real maxDistance() const
Gets the max distance this Ray is allowed to travel.
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.
Ray()=delete
Deleted default constructor.
unsigned int processorCrossings() const
Gets the number of times this Ray has crossed a processor.
void resetCounters()
Clears the internal counters on the Ray so that the Ray can be traced again.
void errorIfTracing(const std::string &reason) const
Produces a useful error if a Ray has started tracing.
std::vector< RayData > & data()
Gets a writeable reference to the Ray's data.
bool trajectoryChanged() const
Whether or not this Ray has had its trajectory changed.
void setStationary()
Sets the Ray to be stationary (max distance = 0).
const Elem * _current_elem
Current element that the Ray is in.
bool _end_set
Whether or not the user has set an end point for this Ray (via limiting its distance with setStarting...
Real _distance
Total distance this Ray has traveled.
void invalidateStartingIncomingSide()
Invalidates a Ray's starting incoming side.
unsigned int intersections() const
Gets the number of intersections this Ray has done.
const Elem * currentElem() const
Gets the current element that the Ray is in.
const Point & currentPoint() const
Gets the point that the Ray is currently at.
unsigned int _intersections
Number of intersections done for this Ray.
const RayTracingStudy & study() const
Get the RayTracingStudy associated with this Ray.
bool invalidDirection() const
Whether or not the Ray's direction is set to invalid.
Point endPoint() const
Gets the user-set end point for the Ray, if set.
bool _trajectory_changed
Whether or not this Ray had its trajectory changed (not sent in parallel)
void invalidateDirection()
Invalidates the Ray's current direction.
RayID _id
A unique ID for this Ray.
bool invalidID() const
Whether or not the Ray's ID is invalid.
bool equalityHelper(const Ray &other, const bool equal) const
Helper for the equality operators.
void invalidateStartingElem()
Invalidates a Ray's starting element.
bool atEnd() const
Whether or not the Ray is at the user-defined end point.
RayID id() const
Gets the Ray's ID.
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.
unsigned int _trajectory_changes
Number of times this Ray has had its trajectory changed.
RayTracingStudy & _study
The RayTracingStudy that owns this Ray (not sent in parallel)
Point _current_point
Current point of the Ray.
void changeStartDirection(const Point &start, const Point &direction, const ChangeStartDirectionKey)
This method is for internal use only.
unsigned short _current_incoming_side
The side of _current_elem that the Ray is incoming on (if any).
void setStartingMaxDistance(const Real starting_max_distance)
Sets the maximum distance this Ray should travel to starting_max_distance.
std::string getInfo() const
Helper function for getting information about the Ray.
bool shouldContinue() const
Whether or not this Ray should continue.
bool invalidCurrentPoint() const
Whether or not the point that the Ray is currently at is valid.
const Point & direction() const
Gets the Ray's direction.
void invalidateCurrentElem()
Invalidates the Ray's current element.
void changePointElemSide(const Point &point, const Elem &elem, const unsigned int side, const ChangePointElemSideKey)
This method is for internal use only.
void invalidateCurrentPoint()
Invalidates the Ray's current point.
unsigned int _processor_crossings
Number of times this Ray has been communicated.
processor_id_type rank() const
bool contains_point(const Point &) const
processor_id_type processor_id() const
static constexpr dof_id_type invalid_id
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
virtual unsigned int n_sides() const=0
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i)=0
virtual const Elem * query_elem_ptr(const dof_id_type i) const=0
const Parallel::Communicator & comm() const
bool absolute_fuzzy_equals(const TypeVector< Real > &rhs, Real tol=TOLERANCE) const
TypeVector< Real > unit() const
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.
void unpackCopy(Cont &container, InputIt &input_iterator)
Like std::copy, but passes the input iterator by reference.
void unpack(const BufferType value_as_buffer_type, ValueType &value)
Unpacks value_as_buffer_type (which is packed with pack()) into value at a byte level.
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real