https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Ray.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 "Ray.h"
11
12// Local includes
13#include "ParallelRayStudy.h"
14#include "RayTracingStudy.h"
16
17// MOOSE includes
18#include "DataIO.h"
19
20using namespace libMesh;
21
23 const RayID id,
24 const std::size_t data_size,
25 const std::size_t aux_data_size,
26 const bool /* reset */,
27 const ConstructRayKey &)
28 : _id(id),
29 _current_point(RayTracingCommon::invalid_point),
30 _direction(RayTracingCommon::invalid_point),
31 _current_elem(nullptr),
32 _current_incoming_side(RayTracingCommon::invalid_side),
33 _end_set(false),
34 _max_distance(std::numeric_limits<Real>::max()),
35 _data(data_size, 0),
36 _aux_data(aux_data_size, 0),
37 _study(*study)
38{
40}
41
42void
43Ray::reset(RayTracingStudy * libmesh_dbg_var(study),
44 const RayID id,
45 const std::size_t data_size,
46 const std::size_t aux_data_size,
47 const bool reset,
48 const ConstructRayKey &)
49{
50 _id = id;
51 _data.resize(data_size, 0);
52 _aux_data.resize(aux_data_size, 0);
53
54 if (reset)
55 {
59 _current_elem = nullptr;
61 _end_set = false;
62 _max_distance = std::numeric_limits<Real>::max();
63 std::fill(_data.begin(), _data.end(), 0);
64 std::fill(_aux_data.begin(), _aux_data.end(), 0);
65 }
66
67 mooseAssert(study == &_study, "Resetting Ray from different study");
68}
69
70Ray::Ray(const Ray * const other, const ConstructRayKey & key)
71 : Ray(&other->_study,
72 other->_id,
73 other->_data.size(),
74 other->_aux_data.size(),
75 /* reset = */ true,
76 key)
77{
78 other->errorIfTracing("Cannot copy Ray");
79
80 if (!other->invalidCurrentPoint())
82
83 if (other->_end_set)
85 else
86 {
87 if (!other->invalidDirection())
89 if (other->maxDistanceSet())
91 }
92
93 std::copy(other->_data.begin(), other->_data.end(), _data.begin());
94 std::copy(other->_aux_data.begin(), other->_aux_data.end(), _aux_data.begin());
95}
96
97void
98Ray::reset(const Ray * const other, const ConstructRayKey &)
99{
100 other->errorIfTracing("Cannot copy Ray");
101 mooseAssert(&other->_study == &_study, "Cannot copy Ray from different study");
102
105
106 _id = other->_id;
107
108 if (!other->invalidCurrentPoint())
110
111 if (other->_end_set)
113 else
114 {
115 if (!other->invalidDirection())
117 if (other->maxDistanceSet())
119 }
120
121 _data = other->_data;
122 _aux_data = other->_aux_data;
123}
124
125bool
126Ray::equalityHelper(const Ray & other, const bool equal) const
127{
128 if (this == &other)
129 return equal;
130
131 if (_id != other._id)
132 return !equal;
133 if (invalidCurrentPoint() != other.invalidCurrentPoint() ||
135 return !equal;
136 if (invalidDirection() != other.invalidDirection() ||
138 return !equal;
139 if (_current_elem != other._current_elem)
140 return !equal;
142 return !equal;
144 return !equal;
145 if (_end_set != other._end_set)
146 return !equal;
148 return !equal;
150 return !equal;
151 if (_intersections != other._intersections)
152 return !equal;
154 return !equal;
155 if (!MooseUtils::absoluteFuzzyEqual(_distance, other._distance))
156 return !equal;
157 if (!MooseUtils::absoluteFuzzyEqual(_max_distance, other._max_distance))
158 return !equal;
159 if (_data.size() != other._data.size())
160 return !equal;
161 for (std::size_t i = 0; i < _data.size(); ++i)
162 if (!MooseUtils::absoluteFuzzyEqual(_data[i], other._data[i]))
163 return !equal;
164 if (_aux_data.size() != other._aux_data.size())
165 return !equal;
166 for (std::size_t i = 0; i < _aux_data.size(); ++i)
167 if (!MooseUtils::absoluteFuzzyEqual(_aux_data[i], other._aux_data[i]))
168 return !equal;
169 if (&_study != &other._study)
170 return !equal;
171
172 return equal;
173}
174
175bool
177{
178 if (!_end_set)
179 mooseError("Cannot use Ray::atEnd() for a Ray that does not have an end set\n\n", getInfo());
180 mooseAssert(_distance <= _max_distance + TOLERANCE * TOLERANCE, "Distance past max distance");
181
182 return MooseUtils::absoluteFuzzyEqual(_distance, _max_distance);
183}
184
185Point
187{
188 if (!_end_set)
189 mooseError("Cannot use Ray::endPoint() for a Ray that does not have an end set\n\n", getInfo());
190 mooseAssert(_distance <= _max_distance + TOLERANCE * TOLERANCE, "Distance past max distance");
191
193}
194
195void
197{
199 mooseError("Cannot set zero vector direction for a Ray\n\n", getInfo());
200
202 _trajectory_changed = true;
203}
204
205void
207 const Point & direction,
209{
211 mooseError("Cannot set zero vector direction for a Ray\n\n", getInfo());
212
213 _current_point = start;
215 _trajectory_changed = true;
216}
217
218void
220 const Elem & elem,
221 const unsigned int side,
223{
224 mooseAssert(!_trajectory_changed, "Should not have already changed");
225
226 _current_point = point;
227 _current_elem = &elem;
229 _trajectory_changed = true;
230}
231
232void
233Ray::setStart(const Point & starting_point,
234 const Elem * starting_elem /* = nullptr */,
235 const unsigned short starting_incoming_side /* = RayTracingCommon::invalid_side */)
236{
237 mooseAssert(starting_point != RayTracingCommon::invalid_point, "Invalid point");
238 errorIfTracing("Cannot use Ray::setStart()");
240 errorWhenInitializing("Starting point was already set via Ray::setStart() and is being changed."
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().");
244
245 _current_point = starting_point;
246 _current_elem = starting_elem;
247 _current_incoming_side = starting_incoming_side;
248
249 if (_study.verifyRays())
250 {
251 if (!_study.looseBoundingBox().contains_point(starting_point))
252 errorWhenInitializing("Mesh does not contain starting point.");
253 if (starting_elem)
254 {
255 mooseAssert(_study.meshBase().query_elem_ptr(starting_elem->id()) == starting_elem,
256 "Element is not owned by the mesh");
257 if (!starting_elem->active())
258 errorWhenInitializing("Starting element is not active.");
259 }
260
261 bool non_planar_start = false;
262
264 {
265 if (!starting_elem)
266 errorWhenInitializing("Starting incoming side is set but starting element is not set.");
267 if (starting_elem->n_sides() < starting_incoming_side)
268 errorWhenInitializing("Starting incoming side is not valid for its starting element.");
269
270 non_planar_start = _study.sideIsNonPlanar(starting_elem, starting_incoming_side);
271 if (!non_planar_start &&
272 !starting_elem->build_side_ptr(starting_incoming_side)->contains_point(starting_point))
273 errorWhenInitializing("Starting incoming side does not contain the starting point.");
274 }
275
276 if (starting_elem && !non_planar_start && !starting_elem->contains_point(starting_point))
277 errorWhenInitializing("Starting element does not contain the starting point.");
278 }
279}
280
281void
282Ray::setStartingDirection(const Point & starting_direction)
283{
284 errorIfTracing("Cannot use Ray::setStartingDirection()");
286 errorWhenInitializing("Cannot use Ray::setStartingDirection() before Ray::setStart().");
287 if (!invalidDirection())
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().");
292 if (starting_direction.absolute_fuzzy_equals(Point(0, 0, 0)))
293 errorWhenInitializing("Starting direction in Ray::setStartingDirection() is the zero vector.");
294
295 _direction = starting_direction.unit();
296}
297
298void
299Ray::setStartingEndPoint(const Point & starting_end_point)
300{
301 errorIfTracing("Cannot use Ray::setStartingEndPoint()");
303 errorWhenInitializing("Cannot use Ray::setStartingEndPoint() before Ray::setStart().");
304 if (_current_point.absolute_fuzzy_equals(starting_end_point))
305 errorWhenInitializing("End point is equal to the start point in Ray::setStartingEndPoint().");
306 if (!invalidDirection())
307 errorWhenInitializing("Cannot use Ray::setStartingEndPoint() after Ray::setStartingDirection()."
308 "\n\nClear the starting information with Ray::clearStartingInfo().");
309 if (maxDistanceSet())
311 "Cannot use Ray::setStartingEndPoint() after Ray::setStartingMaxDistance().");
312
313 if (_study.verifyRays() && !_study.looseBoundingBox().contains_point(starting_end_point))
314 errorWhenInitializing("End point is not within the mesh for Ray::setStartingEndPoint().");
315
316 Point difference = starting_end_point;
317 difference -= _current_point;
318 setStartingMaxDistance(difference.norm());
319 setStartingDirection(difference);
320 _end_set = true;
321}
322
323void
324Ray::setStartingMaxDistance(const Real starting_max_distance)
325{
326 errorIfTracing("Cannot use Ray::setStartingMaxDistance()");
328 errorWhenInitializing("Cannot use Ray::setStartingMaxDistance() before Ray::setStart().");
329 if (starting_max_distance <= 0)
330 errorWhenInitializing("Starting max distance is <= 0 in Ray::setStartingMaxDistance().");
331 if (_end_set)
333 "Cannot use Ray::setStartingMaxDistance() after Ray::setStartingEndPoint().");
334
335 _max_distance = starting_max_distance;
336}
337
338void
340{
341 errorIfTracing("Cannot use Ray::setStationary()");
343 errorWhenInitializing("Cannot use Ray::setStationary() before Ray::setStart()");
344 if (_end_set)
345 errorWhenInitializing("Cannot use Ray::setStationary() after Ray::setStartingEndPoint()");
346 if (!invalidDirection())
347 errorWhenInitializing("Cannot use Ray::setStationary() with Ray::setStartingDirection()");
348 _max_distance = 0;
349 mooseAssert(stationary(), "Stationary not set");
350}
351
352void
354{
355 errorIfTracing("Cannot use Ray::invalidateStartingElem()");
357}
358
359void
361{
362 errorIfTracing("Cannot use Ray::invalidateStartingIncomingSide()");
364}
365
366void
368{
369 errorIfTracing("Cannot use Ray::clearStartingInfo()");
371}
372
373void
383
384void
385Ray::errorIfTracing(const std::string & reason) const
386{
387 if (hasTraced())
388 mooseError(reason, " after it has started tracing\n\n", getInfo());
389}
390
391void
392Ray::errorWhenInitializing(const std::string & reason) const
393{
394 mooseError("While initializing starting information for a Ray:\n\n", reason, "\n\n", getInfo());
395}
396
397void
399{
401 mooseError("Ray::resetCounters() can only be used during generateRays()\n\n", getInfo());
403}
404
405void
415
416std::vector<RayData> &
418{
419 mooseAssert(_data.size() == 0 || _data.size() == _study.rayDataSize(),
420 "Ray data size of " + std::to_string(_data.size()) +
421 " is not zero or the size required by the study of " +
422 std::to_string(_study.rayDataSize()));
423 _data.resize(_study.rayDataSize());
424 return _data;
425}
426
427const std::vector<RayData> &
429{
430 mooseAssert(_data.size() == 0 || _data.size() == _study.rayDataSize(),
431 "Ray data size is not zero or the size required by study");
432 _data.resize(_study.rayDataSize());
433 return _data;
434}
435
436RayData &
437Ray::data(const std::size_t i)
438{
439 mooseAssert(_study.rayDataSize() > i, "Accessing Ray data out of range");
440 return data()[i];
441}
442
443const RayData &
444Ray::data(const std::size_t i) const
445{
446 mooseAssert(_study.rayDataSize() > i, "Accessing Ray data out of range");
447 return data()[i];
448}
449
450std::vector<RayData> &
452{
453 mooseAssert(_aux_data.size() == 0 || _aux_data.size() == _study.rayAuxDataSize(),
454 "Ray data size is not zero or the size required by study");
456 return _aux_data;
457}
458
459const std::vector<RayData> &
461{
462 mooseAssert(_aux_data.size() == 0 || _aux_data.size() == _study.rayAuxDataSize(),
463 "Ray data size is not zero or the size required by study");
465 return _aux_data;
466}
467
468RayData &
469Ray::auxData(const std::size_t i)
470{
471 mooseAssert(_study.rayAuxDataSize() > i, "Accessing Ray data out of range");
472 return auxData()[i];
473}
474
475const RayData &
476Ray::auxData(const std::size_t i) const
477{
478 mooseAssert(_study.rayAuxDataSize() > i, "Accessing Ray data out of range");
479 return auxData()[i];
480}
481
482std::string
484{
485 std::ostringstream oss;
486
487 oss << "Ray information with " << _study.type() << " '" << _study.name() << "' on pid "
488 << _study.comm().rank() << "\n";
489 oss << " this = " << this << "\n";
490 oss << " id() = " << id() << "\n";
492 oss << " _study.registeredRayName(id()) = " << _study.registeredRayName(id()) << "\n";
493 oss << " currentPoint() = ";
495 oss << "invalid point\n";
496 else
497 oss << currentPoint() << "\n";
498 oss << " direction() = ";
499 if (invalidDirection())
500 oss << "invalid point\n";
501 else
502 oss << direction() << "\n";
503 oss << " currentIncomingSide() = ";
505 oss << "invalid side\n";
506 else
507 oss << currentIncomingSide() << "\n";
508 oss << " endSet() = " << (endSet() ? "true" : "false") << "\n";
509 if (endSet())
510 {
511 oss << " endPoint() = " << endPoint() << "\n";
512 oss << " atEnd() = " << (atEnd() ? "true" : "false") << "\n";
513 }
514 oss << " distance() = " << distance() << "\n";
515 oss << " maxDistance() = " << maxDistance() << "\n";
516 if (currentElem())
517 {
518 oss << " currentElem()->id() = " << currentElem()->id() << "\n";
519 oss << " currentElem()->processor_id() = " << currentElem()->processor_id() << "\n";
520 }
521 else
522 oss << " currentElem()->id() = invalid\n";
523 oss << " processorCrossings() = " << processorCrossings() << "\n";
524 oss << " intersections() = " << intersections() << "\n";
525 oss << " trajectoryChanges() = " << trajectoryChanges() << "\n";
526 oss << " shouldContinue() = " << (shouldContinue() ? "true" : "false") << "\n";
527 oss << " trajectoryChanged() = " << (trajectoryChanged() ? "true" : "false") << "\n";
528 oss << " data() = ";
529 for (std::size_t i = 0; i < data().size(); ++i)
530 oss << "\n '" << _study.getRayDataName(i) << "' = " << data(i);
531 oss << "\n";
532 oss << " auxData() = ";
533 for (std::size_t i = 0; i < auxData().size(); ++i)
534 oss << "\n '" << _study.getRayAuxDataName(i) << "' = " << auxData(i);
535 oss << "\n";
536
537 return oss.str();
538}
539
540namespace libMesh
541{
542namespace Parallel
543{
544
545unsigned int
546Packing<std::shared_ptr<Ray>>::size(const std::size_t data_size, const std::size_t aux_data_size)
547{
548 // Current incoming side, end_set, processor crossings, intersections, trajectory
549 // changes (packed into as few buffer_type as possible: 5 values stored as 2 Reals)
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");
553
554 // First value: size of data, size of aux data, id, current point (3 values), direction (3
555 // values), current element, distance, max distance
556 // Second value: mixed size (see above)
557 auto size = 12 + mixed_size;
558
559#ifdef SINGLE_PRECISION_RAY
560 if (data_size)
561 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(data_size);
562 if (aux_data_size)
563 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(aux_data_size);
564#else
565 size += data_size + aux_data_size;
566#endif
567
568 return size;
569}
570
571unsigned int
572Packing<std::shared_ptr<Ray>>::packed_size(typename std::vector<buffer_type>::const_iterator in)
573{
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);
576
577 return size(data_size, aux_data_size);
578}
579
580unsigned int
581Packing<std::shared_ptr<Ray>>::packable_size(const std::shared_ptr<Ray> & ray, const void *)
582{
583 return size(ray->data().size(), ray->auxData().size());
584}
585
586template <>
587std::shared_ptr<Ray>
588Packing<std::shared_ptr<Ray>>::unpack(std::vector<buffer_type>::const_iterator in,
589 ParallelStudy<std::shared_ptr<Ray>, Ray> * study)
590{
591 mooseAssert(dynamic_cast<ParallelRayStudy *>(study), "Not a ParallelRayStudy");
592 RayTracingStudy & ray_tracing_study = static_cast<ParallelRayStudy *>(study)->rayTracingStudy();
593
594 // Grab the data size
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++);
597
598 // ID
599 RayID id;
601
602 std::shared_ptr<Ray> ray =
603 ray_tracing_study.acquireRayInternal(id,
604 data_size,
605 aux_data_size,
606 /* reset = */ false,
608
609 // Current Point
610 ray->_current_point(0) = *in++;
611 ray->_current_point(1) = *in++;
612 ray->_current_point(2) = *in++;
613
614 // Direction
615 ray->_direction(0) = *in++;
616 ray->_direction(1) = *in++;
617 ray->_direction(2) = *in++;
618
619 // Current Element
620 RayTracingPackingUtils::unpack(ray->_current_elem, *in++, &ray_tracing_study.meshBase());
621
622 // Current incoming size, end set, processor crossings, intersections, trajectory changes
623 // (unpacked from as few buffer_type as possible - 5 values from 2 Reals)
624 RayTracingPackingUtils::mixedUnpack<buffer_type>(in,
625 ray->_current_incoming_side,
626 ray->_end_set,
627 ray->_processor_crossings,
628 ray->_intersections,
629 ray->_trajectory_changes);
630
631 // Distance
632 ray->_distance = *in++;
633
634 // Max distance
635 ray->_max_distance = *in++;
636
637#ifdef SINGLE_PRECISION_RAY
638 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_data, in);
639 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_aux_data, in);
640#else
641 // Copy out data
643 RayTracingPackingUtils::unpackCopy(ray->_aux_data, in);
644#endif
645
646 ray->_should_continue = true;
647 ray->_trajectory_changed = false;
648
649 return ray;
650}
651
652template <>
653void
654Packing<std::shared_ptr<Ray>>::pack(const std::shared_ptr<Ray> & ray,
655 std::back_insert_iterator<std::vector<buffer_type>> data_out,
656 const ParallelStudy<std::shared_ptr<Ray>, Ray> * study)
657{
658 mooseAssert(dynamic_cast<const ParallelRayStudy *>(study), "Not a ParallelRayStudy");
659 const RayTracingStudy & ray_tracing_study =
660 static_cast<const ParallelRayStudy *>(study)->rayTracingStudy();
661 mooseAssert(&ray->study() == &ray_tracing_study, "Packing Ray for different study");
662
663 // Storing the data size first makes it easy to verify and reserve space
664 data_out = static_cast<buffer_type>(ray->_data.size());
665 data_out = static_cast<buffer_type>(ray->_aux_data.size());
666
667 // ID
668 data_out = RayTracingPackingUtils::pack<buffer_type>(ray->id());
669
670 // Current Point
671 data_out = ray->_current_point(0);
672 data_out = ray->_current_point(1);
673 data_out = ray->_current_point(2);
674
675 // Direction
676 data_out = ray->_direction(0);
677 data_out = ray->_direction(1);
678 data_out = ray->_direction(2);
679
680 // Current element
681 data_out =
682 RayTracingPackingUtils::pack<buffer_type>(ray->_current_elem, &ray_tracing_study.meshBase());
683
684 // Current incoming size, end set, processor crossings, intersections, trajectory changes
685 // (packed into as few buffer_type as possible - 5 values into 2 Reals
686 RayTracingPackingUtils::mixedPack<buffer_type>(data_out,
687 ray->_current_incoming_side,
688 ray->_end_set,
689 ray->_processor_crossings,
690 ray->_intersections,
691 ray->_trajectory_changes);
692
693 // Distance
694 data_out = ray->_distance;
695 // Max distance
696 data_out = ray->_max_distance;
697
698 // Copy out data
699#ifdef SINGLE_PRECISION_RAY
700 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_data, data_out);
701 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_aux_data, data_out);
702#else
703 std::copy(ray->_data.begin(), ray->_data.end(), data_out);
704 std::copy(ray->_aux_data.begin(), ray->_aux_data.end(), data_out);
705#endif
706}
707
708} // namespace Parallel
709
710} // namespace libMesh
711
712void
713dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray, void * context)
714{
715 mooseAssert(ray, "Null ray");
716 mooseAssert(context, "Missing RayTracingStudy context");
717 mooseAssert(static_cast<RayTracingStudy *>(context) == &ray->study(), "Different study");
718
719 storeHelper(stream, ray->_id, context);
720 storeHelper(stream, ray->_current_point, context);
721 storeHelper(stream, ray->_direction, context);
722 auto current_elem_id = ray->currentElem() ? ray->currentElem()->id() : DofObject::invalid_id;
723 storeHelper(stream, current_elem_id, context);
724 storeHelper(stream, ray->_current_incoming_side, context);
725 storeHelper(stream, ray->_trajectory_changed, context);
726 storeHelper(stream, ray->_end_set, context);
727 storeHelper(stream, ray->_should_continue, context);
728 storeHelper(stream, ray->_processor_crossings, context);
729 storeHelper(stream, ray->_intersections, context);
730 storeHelper(stream, ray->_trajectory_changes, context);
731 storeHelper(stream, ray->_distance, context);
732 storeHelper(stream, ray->_max_distance, context);
733 storeHelper(stream, ray->_data, context);
734 storeHelper(stream, ray->_aux_data, context);
735}
736
737void
738dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray, void * context)
739{
740 mooseAssert(context, "Missing RayTracingStudy context");
741 RayTracingStudy * study = static_cast<RayTracingStudy *>(context);
742
743 RayID id;
744 loadHelper(stream, id, context);
745 ray = study->acquireRayInternal(id,
746 /* data_size = */ 0,
747 /* aux_data_size = */ 0,
748 /* reset = */ true,
750
751 loadHelper(stream, ray->_current_point, context);
752 loadHelper(stream, ray->_direction, context);
753 dof_id_type current_elem_id;
754 loadHelper(stream, current_elem_id, context);
755 ray->_current_elem = study->meshBase().query_elem_ptr(current_elem_id);
756 loadHelper(stream, ray->_current_incoming_side, context);
757 loadHelper(stream, ray->_trajectory_changed, context);
758 loadHelper(stream, ray->_end_set, 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);
763 loadHelper(stream, ray->_distance, context);
764 loadHelper(stream, ray->_max_distance, context);
765 loadHelper(stream, ray->_data, context);
766 loadHelper(stream, ray->_aux_data, context);
767
768 if (ray->hasTraced())
769 mooseAssert(!study->currentlyGenerating() && !study->currentlyPropagating(),
770 "Cannot not load a Ray that has already traced during generation or propagation; "
771 "reset the Ray first");
772}
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)
Definition Ray.C:713
void dataLoad(std::istream &stream, std::shared_ptr< Ray > &ray, void *context)
Definition Ray.C:738
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
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...
Definition Ray.h:65
Class that is used as a parameter to changePointElem() that allows only PeriodicRayBC methods to call...
Definition Ray.h:87
Class that is used as a parameter to changeStartDirection() that allows only RayKernelBase methods to...
Definition Ray.h:76
Class that is used as a parameter to the public constructors/reset methods.
Definition Ray.h:100
Basic datastructure for a ray that will traverse the mesh.
Definition Ray.h:58
unsigned short currentIncomingSide() const
Get a Ray's current incoming side.
Definition Ray.h:459
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
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 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
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.
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
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
const Elem * _current_elem
Current element that the Ray is in.
Definition Ray.h:701
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
unsigned int intersections() const
Gets the number of intersections this Ray has done.
Definition Ray.h:507
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
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
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
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
bool atEnd() const
Whether or not the Ray is at the user-defined end point.
Definition Ray.C:176
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
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
processor_id_type rank() const
bool contains_point(const Point &) const
processor_id_type processor_id() const
static constexpr dof_id_type invalid_id
dof_id_type id() const
bool active() const
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
auto norm() 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
uint8_t dof_id_type
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real