22 const std::size_t data_size,
23 const std::size_t aux_data_size,
29 _current_elem(nullptr),
32 _max_distance(
std::numeric_limits<Real>::max()),
34 _aux_data(aux_data_size, 0),
43 const std::size_t data_size,
44 const std::size_t aux_data_size,
46 const ConstructRayKey &)
49 _data.resize(data_size, 0);
65 mooseAssert(
study == &
_study,
"Resetting Ray from different study");
72 other->_aux_data.size(),
99 mooseAssert(&other->
_study == &
_study,
"Cannot copy Ray from different study");
159 for (std::size_t i = 0; i <
_data.size(); ++i)
160 if (!MooseUtils::absoluteFuzzyEqual(
_data[i], other.
_data[i]))
164 for (std::size_t i = 0; i <
_aux_data.size(); ++i)
177 mooseError(
"Cannot use Ray::atEnd() for a Ray that does not have an end set\n\n",
getInfo());
187 mooseError(
"Cannot use Ray::endPoint() for a Ray that does not have an end set\n\n",
getInfo());
196 if (
direction.absolute_fuzzy_equals(Point(0, 0, 0)))
205 const Point & direction,
208 if (
direction.absolute_fuzzy_equals(Point(0, 0, 0)))
219 const unsigned int side,
232 const Elem * starting_elem ,
233 const unsigned short starting_incoming_side )
239 "\n\nYou may only call Ray::setStart() after it has been called once to"
240 "\nchange the starting element and starting incoming side."
241 "\n\nYou may also clear the starting info via Ray::clearStartingInfo().");
253 mooseAssert(
_study.
meshBase().query_elem_ptr(starting_elem->id()) == starting_elem,
254 "Element is not owned by the mesh");
255 if (!starting_elem->active())
259 bool non_planar_start =
false;
265 if (starting_elem->n_sides() < starting_incoming_side)
269 if (!non_planar_start &&
270 !starting_elem->build_side_ptr(starting_incoming_side)->contains_point(starting_point))
274 if (starting_elem && !non_planar_start && !starting_elem->contains_point(starting_point))
287 "Cannot change a Ray's starting direction using Ray::setStartingDirection()"
288 "\nafter it has already been set."
289 "\n\nYou must first clear the starting info using Ray::clearStartingInfo().");
290 if (starting_direction.absolute_fuzzy_equals(Point(0, 0, 0)))
306 "\n\nClear the starting information with Ray::clearStartingInfo().");
309 "Cannot use Ray::setStartingEndPoint() after Ray::setStartingMaxDistance().");
314 Point difference = starting_end_point;
327 if (starting_max_distance <= 0)
331 "Cannot use Ray::setStartingMaxDistance() after Ray::setStartingEndPoint().");
347 mooseAssert(
stationary(),
"Stationary not set");
360 errorIfTracing(
"Cannot use Ray::invalidateStartingIncomingSide()");
392 mooseError(
"While initializing starting information for a Ray:\n\n", reason,
"\n\n",
getInfo());
399 mooseError(
"Ray::resetCounters() can only be used during generateRays()\n\n",
getInfo());
414std::vector<RayData> &
418 "Ray data size of " + std::to_string(
_data.size()) +
419 " is not zero or the size required by the study of " +
425const std::vector<RayData> &
429 "Ray data size is not zero or the size required by study");
448std::vector<RayData> &
452 "Ray data size is not zero or the size required by study");
457const std::vector<RayData> &
461 "Ray data size is not zero or the size required by study");
483 std::ostringstream oss;
487 oss <<
" this = " <<
this <<
"\n";
488 oss <<
" id() = " <<
id() <<
"\n";
491 oss <<
" currentPoint() = ";
493 oss <<
"invalid point\n";
496 oss <<
" direction() = ";
498 oss <<
"invalid point\n";
501 oss <<
" currentIncomingSide() = ";
503 oss <<
"invalid side\n";
506 oss <<
" endSet() = " << (
endSet() ?
"true" :
"false") <<
"\n";
509 oss <<
" endPoint() = " <<
endPoint() <<
"\n";
510 oss <<
" atEnd() = " << (
atEnd() ?
"true" :
"false") <<
"\n";
512 oss <<
" distance() = " <<
distance() <<
"\n";
513 oss <<
" maxDistance() = " <<
maxDistance() <<
"\n";
516 oss <<
" currentElem()->id() = " <<
currentElem()->id() <<
"\n";
517 oss <<
" currentElem()->processor_id() = " <<
currentElem()->processor_id() <<
"\n";
520 oss <<
" currentElem()->id() = invalid\n";
524 oss <<
" shouldContinue() = " << (
shouldContinue() ?
"true" :
"false") <<
"\n";
525 oss <<
" trajectoryChanged() = " << (
trajectoryChanged() ?
"true" :
"false") <<
"\n";
527 for (std::size_t i = 0; i <
data().size(); ++i)
530 oss <<
" auxData() = ";
531 for (std::size_t i = 0; i <
auxData().size(); ++i)
548 constexpr unsigned int mixed_size = RayTracingPackingUtils::
549 mixedPackSize<buffer_type, unsigned short, bool, unsigned int, unsigned int, unsigned int>();
550 mooseAssert(mixed_size == 2,
"Mixed size should be 2");
555 auto size = 12 + mixed_size;
557#ifdef SINGLE_PRECISION_RAY
559 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(data_size);
561 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(aux_data_size);
563 size += data_size + aux_data_size;
572 const std::size_t data_size =
static_cast<std::size_t
>(*in++);
573 const std::size_t aux_data_size =
static_cast<std::size_t
>(*in);
575 return size(data_size, aux_data_size);
581 return size(ray->data().size(), ray->auxData().size());
589 mooseAssert(
dynamic_cast<ParallelRayStudy *
>(study),
"Not a ParallelRayStudy");
590 RayTracingStudy & ray_tracing_study = cast_ptr<ParallelRayStudy *>(study)->rayTracingStudy();
593 const std::size_t data_size =
static_cast<std::size_t
>(*in++);
594 const std::size_t aux_data_size =
static_cast<std::size_t
>(*in++);
600 std::shared_ptr<Ray> ray =
608 ray->_current_point(0) = *in++;
609 ray->_current_point(1) = *in++;
610 ray->_current_point(2) = *in++;
613 ray->_direction(0) = *in++;
614 ray->_direction(1) = *in++;
615 ray->_direction(2) = *in++;
622 RayTracingPackingUtils::mixedUnpack<buffer_type>(in,
623 ray->_current_incoming_side,
625 ray->_processor_crossings,
627 ray->_trajectory_changes);
630 ray->_distance = *in++;
633 ray->_max_distance = *in++;
635#ifdef SINGLE_PRECISION_RAY
636 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_data, in);
637 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_aux_data, in);
644 ray->_should_continue =
true;
645 ray->_trajectory_changed =
false;
653 std::back_insert_iterator<std::vector<buffer_type>> data_out,
656 mooseAssert(
dynamic_cast<const ParallelRayStudy *
>(study),
"Not a ParallelRayStudy");
658 cast_ptr<const ParallelRayStudy *>(study)->rayTracingStudy();
659 mooseAssert(&ray->study() == &ray_tracing_study,
"Packing Ray for different study");
662 data_out =
static_cast<buffer_type>(ray->_data.size());
663 data_out =
static_cast<buffer_type>(ray->_aux_data.size());
666 data_out = RayTracingPackingUtils::pack<buffer_type>(ray->id());
669 data_out = ray->_current_point(0);
670 data_out = ray->_current_point(1);
671 data_out = ray->_current_point(2);
674 data_out = ray->_direction(0);
675 data_out = ray->_direction(1);
676 data_out = ray->_direction(2);
680 RayTracingPackingUtils::pack<buffer_type>(ray->_current_elem, &ray_tracing_study.
meshBase());
684 RayTracingPackingUtils::mixedPack<buffer_type>(data_out,
685 ray->_current_incoming_side,
687 ray->_processor_crossings,
689 ray->_trajectory_changes);
692 data_out = ray->_distance;
694 data_out = ray->_max_distance;
697#ifdef SINGLE_PRECISION_RAY
698 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_data, data_out);
699 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_aux_data, data_out);
701 std::copy(ray->_data.begin(), ray->_data.end(), data_out);
702 std::copy(ray->_aux_data.begin(), ray->_aux_data.end(), data_out);
711dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray,
void * context)
713 mooseAssert(ray,
"Null ray");
714 mooseAssert(context,
"Missing RayTracingStudy context");
715 mooseAssert(
static_cast<RayTracingStudy *
>(context) == &ray->study(),
"Different study");
718 dataStore(stream, ray->_current_point, context);
719 dataStore(stream, ray->_direction, context);
720 auto current_elem_id = ray->currentElem() ? ray->currentElem()->id() : DofObject::invalid_id;
721 dataStore(stream, current_elem_id, context);
722 dataStore(stream, ray->_current_incoming_side, context);
723 dataStore(stream, ray->_trajectory_changed, context);
724 dataStore(stream, ray->_end_set, context);
725 dataStore(stream, ray->_should_continue, context);
726 dataStore(stream, ray->_processor_crossings, context);
727 dataStore(stream, ray->_intersections, context);
728 dataStore(stream, ray->_trajectory_changes, context);
729 dataStore(stream, ray->_distance, context);
730 dataStore(stream, ray->_max_distance, context);
732 dataStore(stream, ray->_aux_data, context);
736dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray,
void * context)
738 mooseAssert(context,
"Missing RayTracingStudy context");
749 dataLoad(stream, ray->_current_point, context);
750 dataLoad(stream, ray->_direction, context);
751 dof_id_type current_elem_id;
752 dataLoad(stream, current_elem_id, context);
753 ray->_current_elem = study->
meshBase().query_elem_ptr(current_elem_id);
754 dataLoad(stream, ray->_current_incoming_side, context);
755 dataLoad(stream, ray->_trajectory_changed, context);
756 dataLoad(stream, ray->_end_set, context);
757 dataLoad(stream, ray->_should_continue, context);
758 dataLoad(stream, ray->_processor_crossings, context);
759 dataLoad(stream, ray->_intersections, context);
760 dataLoad(stream, ray->_trajectory_changes, context);
761 dataLoad(stream, ray->_distance, context);
762 dataLoad(stream, ray->_max_distance, context);
763 dataLoad(stream, ray->_data, context);
764 dataLoad(stream, ray->_aux_data, context);
766 if (ray->hasTraced())
768 "Cannot not load a Ray that has already traced during generation or propagation; "
769 "reset the Ray first");
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.
friend void dataLoad(std::istream &stream, std::shared_ptr< Ray > &ray, void *context)
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
const Parallel::Communicator & comm() 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...