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)
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,
220 const Elem * starting_elem ,
221 const unsigned short starting_incoming_side )
227 "\n\nYou may only call Ray::setStart() after it has been called once to" 228 "\nchange the starting element and starting incoming side." 229 "\n\nYou may also clear the starting info via Ray::clearStartingInfo().");
242 "Element is not owned by the mesh");
243 if (!starting_elem->
active())
247 bool non_planar_start =
false;
253 if (starting_elem->
n_sides() < starting_incoming_side)
257 if (!non_planar_start &&
258 !starting_elem->
build_side_ptr(starting_incoming_side)->contains_point(starting_point))
262 if (starting_elem && !non_planar_start && !starting_elem->
contains_point(starting_point))
275 "Cannot change a Ray's starting direction using Ray::setStartingDirection()" 276 "\nafter it has already been set." 277 "\n\nYou must first clear the starting info using Ray::clearStartingInfo().");
294 "\n\nClear the starting information with Ray::clearStartingInfo().");
297 "Cannot use Ray::setStartingEndPoint() after Ray::setStartingMaxDistance().");
302 Point difference = starting_end_point;
315 if (starting_max_distance <= 0)
319 "Cannot use Ray::setStartingMaxDistance() after Ray::setStartingEndPoint().");
335 mooseAssert(
stationary(),
"Stationary not set");
348 errorIfTracing(
"Cannot use Ray::invalidateStartingIncomingSide()");
380 mooseError(
"While initializing starting information for a Ray:\n\n", reason,
"\n\n",
getInfo());
387 mooseError(
"Ray::resetCounters() can only be used during generateRays()\n\n",
getInfo());
402 std::vector<RayData> &
406 "Ray data size of " + std::to_string(
_data.size()) +
407 " is not zero or the size required by the study of " +
413 const std::vector<RayData> &
417 "Ray data size is not zero or the size required by study");
436 std::vector<RayData> &
440 "Ray data size is not zero or the size required by study");
445 const std::vector<RayData> &
449 "Ray data size is not zero or the size required by study");
471 std::ostringstream oss;
475 oss <<
" this = " <<
this <<
"\n";
476 oss <<
" id() = " <<
id() <<
"\n";
479 oss <<
" currentPoint() = ";
481 oss <<
"invalid point\n";
484 oss <<
" direction() = ";
486 oss <<
"invalid point\n";
489 oss <<
" currentIncomingSide() = ";
491 oss <<
"invalid side\n";
494 oss <<
" endSet() = " << (
endSet() ?
"true" :
"false") <<
"\n";
497 oss <<
" endPoint() = " <<
endPoint() <<
"\n";
498 oss <<
" atEnd() = " << (
atEnd() ?
"true" :
"false") <<
"\n";
500 oss <<
" distance() = " <<
distance() <<
"\n";
501 oss <<
" maxDistance() = " <<
maxDistance() <<
"\n";
504 oss <<
" currentElem()->id() = " <<
currentElem()->
id() <<
"\n";
508 oss <<
" currentElem()->id() = invalid\n";
512 oss <<
" shouldContinue() = " << (
shouldContinue() ?
"true" :
"false") <<
"\n";
513 oss <<
" trajectoryChanged() = " << (
trajectoryChanged() ?
"true" :
"false") <<
"\n";
515 for (std::size_t i = 0; i <
data().size(); ++i)
518 oss <<
" auxData() = ";
519 for (std::size_t i = 0; i <
auxData().size(); ++i)
536 constexpr
unsigned int mixed_size = RayTracingPackingUtils::
537 mixedPackSize<buffer_type, unsigned short, bool, unsigned int, unsigned int, unsigned int>();
538 mooseAssert(mixed_size == 2,
"Mixed size should be 2");
543 auto size = 12 + mixed_size;
545 #ifdef SINGLE_PRECISION_RAY 547 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(data_size);
549 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(aux_data_size);
551 size += data_size + aux_data_size;
560 const std::size_t data_size =
static_cast<std::size_t
>(*in++);
561 const std::size_t aux_data_size =
static_cast<std::size_t
>(*in);
563 return size(data_size, aux_data_size);
569 return size(ray->data().size(), ray->auxData().size());
577 mooseAssert(dynamic_cast<ParallelRayStudy *>(study),
"Not a ParallelRayStudy");
581 const std::size_t data_size =
static_cast<std::size_t
>(*in++);
582 const std::size_t aux_data_size =
static_cast<std::size_t
>(*in++);
588 std::shared_ptr<Ray> ray =
596 ray->_current_point(0) = *in++;
597 ray->_current_point(1) = *in++;
598 ray->_current_point(2) = *in++;
601 ray->_direction(0) = *in++;
602 ray->_direction(1) = *in++;
603 ray->_direction(2) = *in++;
610 RayTracingPackingUtils::mixedUnpack<buffer_type>(in,
611 ray->_current_incoming_side,
613 ray->_processor_crossings,
615 ray->_trajectory_changes);
618 ray->_distance = *in++;
621 ray->_max_distance = *in++;
623 #ifdef SINGLE_PRECISION_RAY 624 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_data, in);
625 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_aux_data, in);
632 ray->_should_continue =
true;
633 ray->_trajectory_changed =
false;
641 std::back_insert_iterator<std::vector<buffer_type>> data_out,
644 mooseAssert(dynamic_cast<const ParallelRayStudy *>(study),
"Not a ParallelRayStudy");
647 mooseAssert(&ray->study() == &ray_tracing_study,
"Packing Ray for different study");
650 data_out =
static_cast<buffer_type>(ray->_data.size());
651 data_out =
static_cast<buffer_type>(ray->_aux_data.size());
654 data_out = RayTracingPackingUtils::pack<buffer_type>(ray->id());
657 data_out = ray->_current_point(0);
658 data_out = ray->_current_point(1);
659 data_out = ray->_current_point(2);
662 data_out = ray->_direction(0);
663 data_out = ray->_direction(1);
664 data_out = ray->_direction(2);
668 RayTracingPackingUtils::pack<buffer_type>(ray->_current_elem, &ray_tracing_study.
meshBase());
672 RayTracingPackingUtils::mixedPack<buffer_type>(data_out,
673 ray->_current_incoming_side,
675 ray->_processor_crossings,
677 ray->_trajectory_changes);
680 data_out = ray->_distance;
682 data_out = ray->_max_distance;
685 #ifdef SINGLE_PRECISION_RAY 686 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_data, data_out);
687 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_aux_data, data_out);
689 std::copy(ray->_data.begin(), ray->_data.end(), data_out);
690 std::copy(ray->_aux_data.begin(), ray->_aux_data.end(), data_out);
699 dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray,
void * context)
701 mooseAssert(ray,
"Null ray");
702 mooseAssert(context,
"Missing RayTracingStudy context");
703 mooseAssert(static_cast<RayTracingStudy *>(context) == &ray->study(),
"Different study");
708 auto current_elem_id = ray->currentElem() ? ray->currentElem()->id() : DofObject::invalid_id;
710 storeHelper(stream, ray->_current_incoming_side, context);
712 storeHelper(stream, ray->_processor_crossings, context);
714 storeHelper(stream, ray->_trajectory_changes, context);
715 storeHelper(stream, ray->_trajectory_changed, context);
718 storeHelper(stream, ray->_should_continue, context);
724 dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray,
void * context)
726 mooseAssert(context,
"Missing RayTracingStudy context");
737 loadHelper(stream, ray->_current_point, context);
742 loadHelper(stream, ray->_current_incoming_side, context);
744 loadHelper(stream, ray->_processor_crossings, context);
745 loadHelper(stream, ray->_intersections, context);
746 loadHelper(stream, ray->_trajectory_changes, context);
747 loadHelper(stream, ray->_trajectory_changed, context);
749 loadHelper(stream, ray->_max_distance, context);
750 loadHelper(stream, ray->_should_continue, context);
754 if (ray->hasTraced())
756 "Cannot not load a Ray that has already traced during generation or propagation; " 757 "reset the Ray first");
static const unsigned short invalid_side
Identifier for an invalid side index.
bool currentlyGenerating() const
Whether or not the study is generating.
RayID id() const
Gets the Ray's ID.
std::vector< RayData > & data()
Gets a writeable reference to the Ray's data.
unsigned int processorCrossings() const
Gets the number of times this Ray has crossed a processor.
bool invalidID() const
Whether or not the Ray's ID is invalid.
void invalidateMaxDistance()
Invalidates the Ray's max distance.
unsigned long int RayID
Type for a Ray's ID.
auto norm() const -> decltype(std::norm(Real()))
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Class that is used as a parameter to the public constructors/reset methods.
bool trajectoryChanged() const
Whether or not this Ray has had its trajectory changed.
bool contains_point(const Point &) const
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i)=0
void mooseError(Args &&... args)
const BoundingBox & looseBoundingBox() const
Get the loose nodal bounding box for the domain.
std::size_t rayAuxDataSize() const
The registered size of values in the Ray aux data.
BufferType pack(const ValueType value)
Packs value into a value of type BufferType at a byte level, to be unpacked with the unpack() routine...
bool hasTraced() const
Whether or not a Ray has begun tracing.
Point _direction
Direction of the Ray.
bool useRayRegistration() const
Whether or not ray registration is being used.
std::string getInfo() const
Helper function for getting information about the Ray.
processor_id_type rank() const
const Parallel::Communicator & comm() const
std::vector< RayData > & auxData()
Gets a writeable reference to the Ray's auxilary data.
void invalidateStartingElem()
Invalidates a Ray's starting element.
unsigned int trajectoryChanges() const
Gets the number of trajectory changes this Ray has had.
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
const RayTracingStudy & study() const
Get the RayTracingStudy associated with this Ray.
unsigned int _processor_crossings
Number of times this Ray has been communicated.
const Point & currentPoint() const
Gets the point that the Ray is currently at.
void changeDirection(const Point &direction, const ChangeDirectionKey)
This method is for internal use only.
const Elem * currentElem() const
Gets the current element that the Ray is in.
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.
virtual const std::string & name() const
bool atEnd() const
Whether or not the Ray is at the user-defined end point.
auto max(const L &left, const R &right)
bool invalidCurrentPoint() const
Whether or not the point that the Ray is currently at is valid.
Point _current_point
Current point of the Ray.
void storeHelper(std::ostream &stream, P &data, void *context)
void changeStartDirection(const Point &start, const Point &direction, const ChangeStartDirectionKey)
This method is for internal use only.
bool maxDistanceSet() const
Whether or not the distance has been set via setStartingMaxDistance()
TypeVector< Real > unit() const
bool invalidCurrentIncomingSide() const
Whether or not the Ray's current incoming side is invalid.
bool verifyRays() const
Whether or not to verify if Rays have valid information before being traced.
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
void setStartingEndPoint(const Point &starting_end_point)
Sets the starting end point to starting_point for a Ray.
void dataStore(std::ostream &stream, std::shared_ptr< Ray > &ray, void *context)
void setStartingDirection(const Point &starting_direction)
Sets the starting direction to starting_direction for a Ray.
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...
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 &)
void clearStartingInfo()
Clears the starting information set on the Ray:
bool _should_continue
Wether or not the Ray should continue to be traced (not sent in parallel)
RayTracingStudy & _study
The RayTracingStudy that owns this Ray (not sent in parallel)
void invalidateCurrentIncomingSide()
Invalidates the Ray's current incoming side.
const std::string & getRayDataName(const RayDataIndex index) const
Gets the name associated with a registered value in the Ray data.
const std::string & type() const
Key that is used for restricting access to acquireRayInternal().
const std::string & getRayAuxDataName(const RayDataIndex index) const
Gets the name associated with a registered value in the Ray aux data.
Basic datastructure for a ray that will traverse the mesh.
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.
bool invalidDirection() const
Whether or not the Ray's direction is set to invalid.
bool absolute_fuzzy_equals(const TypeVector< Real > &rhs, Real tol=TOLERANCE) const
bool sideIsNonPlanar(const Elem *elem, const unsigned short s) const
Whether or not the side on elem elem is non-planar.
void setStartingMaxDistance(const Real starting_max_distance)
Sets the maximum distance this Ray should travel to starting_max_distance.
bool shouldContinue() const
Whether or not this Ray should continue.
bool endSet() const
Whether or not the user has set an end point for this Ray.
Real _max_distance
Maximum distance the Ray is allowed to travel.
void invalidateDirection()
Invalidates the Ray's current direction.
void resetCountersInternal()
Reset all of the internal counters.
virtual unsigned int n_sides() const=0
unsigned short currentIncomingSide() const
Get a Ray's current incoming side.
void setStationary()
Sets the Ray to be stationary (max distance = 0).
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const Elem * query_elem_ptr(const dof_id_type i) const=0
bool currentlyPropagating() const
Whether or not the study is propagating (tracing Rays)
void resetCounters()
Clears the internal counters on the Ray so that the Ray can be traced again.
void clearStartingInfoInternal()
Clears the starting information.
Class that is used as a parameter to changeStartDirection() that allows only RayKernelBase methods to...
Real distance() const
Gets the distance this Ray has traveled.
Class that is used as a parameter to changeDirection() that allows only RayBC methods to call changeD...
void invalidateStartingIncomingSide()
Invalidates a Ray's starting incoming side.
const Elem * _current_elem
Current element that the Ray is in.
const Point & direction() const
Gets the Ray's direction.
bool equalityHelper(const Ray &other, const bool equal) const
Helper for the equality operators.
Real maxDistance() const
Gets the max distance this Ray is allowed to travel.
RayID _id
A unique ID for this Ray.
MeshBase & meshBase() const
Access to the libMesh MeshBase.
Real _distance
Total distance this Ray has traveled.
unsigned int _intersections
Number of intersections done for this Ray.
float RayData
Type for a Ray's data.
const std::string & registeredRayName(const RayID ray_id) const
Gets the name of a registered 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 _trajectory_changed
Whether or not this Ray had its trajectory changed (not sent in parallel)
static const libMesh::Point invalid_point(invalid_distance, invalid_distance, invalid_distance)
Identifier for an invalid point.
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.
void unpackCopy(Cont &container, InputIt &input_iterator)
Like std::copy, but passes the input iterator by reference.
bool _end_set
Whether or not the user has set an end point for this Ray (via limiting its distance with setStarting...
unsigned short _current_incoming_side
The side of _current_elem that the Ray is incoming on (if any).
processor_id_type processor_id() const
unsigned int intersections() const
Gets the number of intersections this Ray has done.
void errorWhenInitializing(const std::string &reason) const
Produces a useful error for use when initializing a Ray.
Point endPoint() const
Gets the user-set end point for the Ray, if set.
void loadHelper(std::istream &stream, P &data, void *context)
void invalidateCurrentElem()
Invalidates the Ray's current element.
void dataLoad(std::istream &stream, std::shared_ptr< Ray > &ray, void *context)
void invalidateCurrentPoint()
Invalidates the Ray's current point.
std::size_t rayDataSize() const
The registered size of values in the Ray data.
void errorIfTracing(const std::string &reason) const
Produces a useful error if a Ray has started tracing.
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...