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
21 const RayID id,
22 const std::size_t data_size,
23 const std::size_t aux_data_size,
24 const bool /* reset */,
25 const ConstructRayKey &)
26 : _id(id),
27 _current_point(RayTracingCommon::invalid_point),
28 _direction(RayTracingCommon::invalid_point),
29 _current_elem(nullptr),
30 _current_incoming_side(RayTracingCommon::invalid_side),
31 _end_set(false),
32 _max_distance(std::numeric_limits<Real>::max()),
33 _data(data_size, 0),
34 _aux_data(aux_data_size, 0),
35 _study(*study)
36{
38}
39
40void
41Ray::reset(RayTracingStudy * libmesh_dbg_var(study),
42 const RayID id,
43 const std::size_t data_size,
44 const std::size_t aux_data_size,
45 const bool reset,
46 const ConstructRayKey &)
47{
48 _id = id;
49 _data.resize(data_size, 0);
50 _aux_data.resize(aux_data_size, 0);
51
52 if (reset)
53 {
57 _current_elem = nullptr;
59 _end_set = false;
60 _max_distance = std::numeric_limits<Real>::max();
61 std::fill(_data.begin(), _data.end(), 0);
62 std::fill(_aux_data.begin(), _aux_data.end(), 0);
63 }
64
65 mooseAssert(study == &_study, "Resetting Ray from different study");
66}
67
68Ray::Ray(const Ray * const other, const ConstructRayKey & key)
69 : Ray(&other->_study,
70 other->_id,
71 other->_data.size(),
72 other->_aux_data.size(),
73 /* reset = */ true,
74 key)
75{
76 other->errorIfTracing("Cannot copy Ray");
77
78 if (!other->invalidCurrentPoint())
80
81 if (other->_end_set)
83 else
84 {
85 if (!other->invalidDirection())
87 if (other->maxDistanceSet())
89 }
90
91 std::copy(other->_data.begin(), other->_data.end(), _data.begin());
92 std::copy(other->_aux_data.begin(), other->_aux_data.end(), _aux_data.begin());
93}
94
95void
96Ray::reset(const Ray * const other, const ConstructRayKey &)
97{
98 other->errorIfTracing("Cannot copy Ray");
99 mooseAssert(&other->_study == &_study, "Cannot copy Ray from different study");
100
103
104 _id = other->_id;
105
106 if (!other->invalidCurrentPoint())
108
109 if (other->_end_set)
111 else
112 {
113 if (!other->invalidDirection())
115 if (other->maxDistanceSet())
117 }
118
119 _data = other->_data;
120 _aux_data = other->_aux_data;
121}
122
123bool
124Ray::equalityHelper(const Ray & other, const bool equal) const
125{
126 if (this == &other)
127 return equal;
128
129 if (_id != other._id)
130 return !equal;
131 if (invalidCurrentPoint() != other.invalidCurrentPoint() ||
132 !_current_point.absolute_fuzzy_equals(other._current_point))
133 return !equal;
134 if (invalidDirection() != other.invalidDirection() ||
135 !_direction.absolute_fuzzy_equals(other._direction))
136 return !equal;
137 if (_current_elem != other._current_elem)
138 return !equal;
140 return !equal;
142 return !equal;
143 if (_end_set != other._end_set)
144 return !equal;
146 return !equal;
148 return !equal;
149 if (_intersections != other._intersections)
150 return !equal;
152 return !equal;
153 if (!MooseUtils::absoluteFuzzyEqual(_distance, other._distance))
154 return !equal;
155 if (!MooseUtils::absoluteFuzzyEqual(_max_distance, other._max_distance))
156 return !equal;
157 if (_data.size() != other._data.size())
158 return !equal;
159 for (std::size_t i = 0; i < _data.size(); ++i)
160 if (!MooseUtils::absoluteFuzzyEqual(_data[i], other._data[i]))
161 return !equal;
162 if (_aux_data.size() != other._aux_data.size())
163 return !equal;
164 for (std::size_t i = 0; i < _aux_data.size(); ++i)
165 if (!MooseUtils::absoluteFuzzyEqual(_aux_data[i], other._aux_data[i]))
166 return !equal;
167 if (&_study != &other._study)
168 return !equal;
169
170 return equal;
171}
172
173bool
175{
176 if (!_end_set)
177 mooseError("Cannot use Ray::atEnd() for a Ray that does not have an end set\n\n", getInfo());
178 mooseAssert(_distance <= _max_distance + TOLERANCE * TOLERANCE, "Distance past max distance");
179
180 return MooseUtils::absoluteFuzzyEqual(_distance, _max_distance);
181}
182
183Point
185{
186 if (!_end_set)
187 mooseError("Cannot use Ray::endPoint() for a Ray that does not have an end set\n\n", getInfo());
188 mooseAssert(_distance <= _max_distance + TOLERANCE * TOLERANCE, "Distance past max distance");
189
191}
192
193void
194Ray::changeDirection(const Point & direction, const ChangeDirectionKey)
195{
196 if (direction.absolute_fuzzy_equals(Point(0, 0, 0)))
197 mooseError("Cannot set zero vector direction for a Ray\n\n", getInfo());
198
199 _direction = direction.unit();
200 _trajectory_changed = true;
201}
202
203void
204Ray::changeStartDirection(const Point & start,
205 const Point & direction,
207{
208 if (direction.absolute_fuzzy_equals(Point(0, 0, 0)))
209 mooseError("Cannot set zero vector direction for a Ray\n\n", getInfo());
210
211 _current_point = start;
212 _direction = direction.unit();
213 _trajectory_changed = true;
214}
215
216void
217Ray::changePointElemSide(const Point & point,
218 const Elem & elem,
219 const unsigned int side,
221{
222 mooseAssert(!_trajectory_changed, "Should not have already changed");
223
224 _current_point = point;
225 _current_elem = &elem;
227 _trajectory_changed = true;
228}
229
230void
231Ray::setStart(const Point & starting_point,
232 const Elem * starting_elem /* = nullptr */,
233 const unsigned short starting_incoming_side /* = RayTracingCommon::invalid_side */)
234{
235 mooseAssert(starting_point != RayTracingCommon::invalid_point, "Invalid point");
236 errorIfTracing("Cannot use Ray::setStart()");
237 if (!invalidCurrentPoint() && !_current_point.absolute_fuzzy_equals(starting_point))
238 errorWhenInitializing("Starting point was already set via Ray::setStart() and is being changed."
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().");
242
243 _current_point = starting_point;
244 _current_elem = starting_elem;
245 _current_incoming_side = starting_incoming_side;
246
247 if (_study.verifyRays())
248 {
249 if (!_study.looseBoundingBox().contains_point(starting_point))
250 errorWhenInitializing("Mesh does not contain starting point.");
251 if (starting_elem)
252 {
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())
256 errorWhenInitializing("Starting element is not active.");
257 }
258
259 bool non_planar_start = false;
260
262 {
263 if (!starting_elem)
264 errorWhenInitializing("Starting incoming side is set but starting element is not set.");
265 if (starting_elem->n_sides() < starting_incoming_side)
266 errorWhenInitializing("Starting incoming side is not valid for its starting element.");
267
268 non_planar_start = _study.sideIsNonPlanar(starting_elem, starting_incoming_side);
269 if (!non_planar_start &&
270 !starting_elem->build_side_ptr(starting_incoming_side)->contains_point(starting_point))
271 errorWhenInitializing("Starting incoming side does not contain the starting point.");
272 }
273
274 if (starting_elem && !non_planar_start && !starting_elem->contains_point(starting_point))
275 errorWhenInitializing("Starting element does not contain the starting point.");
276 }
277}
278
279void
280Ray::setStartingDirection(const Point & starting_direction)
281{
282 errorIfTracing("Cannot use Ray::setStartingDirection()");
284 errorWhenInitializing("Cannot use Ray::setStartingDirection() before Ray::setStart().");
285 if (!invalidDirection())
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)))
291 errorWhenInitializing("Starting direction in Ray::setStartingDirection() is the zero vector.");
292
293 _direction = starting_direction.unit();
294}
295
296void
297Ray::setStartingEndPoint(const Point & starting_end_point)
298{
299 errorIfTracing("Cannot use Ray::setStartingEndPoint()");
301 errorWhenInitializing("Cannot use Ray::setStartingEndPoint() before Ray::setStart().");
302 if (_current_point.absolute_fuzzy_equals(starting_end_point))
303 errorWhenInitializing("End point is equal to the start point in Ray::setStartingEndPoint().");
304 if (!invalidDirection())
305 errorWhenInitializing("Cannot use Ray::setStartingEndPoint() after Ray::setStartingDirection()."
306 "\n\nClear the starting information with Ray::clearStartingInfo().");
307 if (maxDistanceSet())
309 "Cannot use Ray::setStartingEndPoint() after Ray::setStartingMaxDistance().");
310
311 if (_study.verifyRays() && !_study.looseBoundingBox().contains_point(starting_end_point))
312 errorWhenInitializing("End point is not within the mesh for Ray::setStartingEndPoint().");
313
314 Point difference = starting_end_point;
315 difference -= _current_point;
316 setStartingMaxDistance(difference.norm());
317 setStartingDirection(difference);
318 _end_set = true;
319}
320
321void
322Ray::setStartingMaxDistance(const Real starting_max_distance)
323{
324 errorIfTracing("Cannot use Ray::setStartingMaxDistance()");
326 errorWhenInitializing("Cannot use Ray::setStartingMaxDistance() before Ray::setStart().");
327 if (starting_max_distance <= 0)
328 errorWhenInitializing("Starting max distance is <= 0 in Ray::setStartingMaxDistance().");
329 if (_end_set)
331 "Cannot use Ray::setStartingMaxDistance() after Ray::setStartingEndPoint().");
332
333 _max_distance = starting_max_distance;
334}
335
336void
338{
339 errorIfTracing("Cannot use Ray::setStationary()");
341 errorWhenInitializing("Cannot use Ray::setStationary() before Ray::setStart()");
342 if (_end_set)
343 errorWhenInitializing("Cannot use Ray::setStationary() after Ray::setStartingEndPoint()");
344 if (!invalidDirection())
345 errorWhenInitializing("Cannot use Ray::setStationary() with Ray::setStartingDirection()");
346 _max_distance = 0;
347 mooseAssert(stationary(), "Stationary not set");
348}
349
350void
352{
353 errorIfTracing("Cannot use Ray::invalidateStartingElem()");
355}
356
357void
359{
360 errorIfTracing("Cannot use Ray::invalidateStartingIncomingSide()");
362}
363
364void
366{
367 errorIfTracing("Cannot use Ray::clearStartingInfo()");
369}
370
371void
381
382void
383Ray::errorIfTracing(const std::string & reason) const
384{
385 if (hasTraced())
386 mooseError(reason, " after it has started tracing\n\n", getInfo());
387}
388
389void
390Ray::errorWhenInitializing(const std::string & reason) const
391{
392 mooseError("While initializing starting information for a Ray:\n\n", reason, "\n\n", getInfo());
393}
394
395void
397{
399 mooseError("Ray::resetCounters() can only be used during generateRays()\n\n", getInfo());
401}
402
403void
413
414std::vector<RayData> &
416{
417 mooseAssert(_data.size() == 0 || _data.size() == _study.rayDataSize(),
418 "Ray data size of " + std::to_string(_data.size()) +
419 " is not zero or the size required by the study of " +
420 std::to_string(_study.rayDataSize()));
421 _data.resize(_study.rayDataSize());
422 return _data;
423}
424
425const std::vector<RayData> &
427{
428 mooseAssert(_data.size() == 0 || _data.size() == _study.rayDataSize(),
429 "Ray data size is not zero or the size required by study");
430 _data.resize(_study.rayDataSize());
431 return _data;
432}
433
434RayData &
435Ray::data(const std::size_t i)
436{
437 mooseAssert(_study.rayDataSize() > i, "Accessing Ray data out of range");
438 return data()[i];
439}
440
441const RayData &
442Ray::data(const std::size_t i) const
443{
444 mooseAssert(_study.rayDataSize() > i, "Accessing Ray data out of range");
445 return data()[i];
446}
447
448std::vector<RayData> &
450{
451 mooseAssert(_aux_data.size() == 0 || _aux_data.size() == _study.rayAuxDataSize(),
452 "Ray data size is not zero or the size required by study");
454 return _aux_data;
455}
456
457const std::vector<RayData> &
459{
460 mooseAssert(_aux_data.size() == 0 || _aux_data.size() == _study.rayAuxDataSize(),
461 "Ray data size is not zero or the size required by study");
463 return _aux_data;
464}
465
466RayData &
467Ray::auxData(const std::size_t i)
468{
469 mooseAssert(_study.rayAuxDataSize() > i, "Accessing Ray data out of range");
470 return auxData()[i];
471}
472
473const RayData &
474Ray::auxData(const std::size_t i) const
475{
476 mooseAssert(_study.rayAuxDataSize() > i, "Accessing Ray data out of range");
477 return auxData()[i];
478}
479
480std::string
482{
483 std::ostringstream oss;
484
485 oss << "Ray information with " << _study.type() << " '" << _study.name() << "' on pid "
486 << _study.comm().rank() << "\n";
487 oss << " this = " << this << "\n";
488 oss << " id() = " << id() << "\n";
490 oss << " _study.registeredRayName(id()) = " << _study.registeredRayName(id()) << "\n";
491 oss << " currentPoint() = ";
493 oss << "invalid point\n";
494 else
495 oss << currentPoint() << "\n";
496 oss << " direction() = ";
497 if (invalidDirection())
498 oss << "invalid point\n";
499 else
500 oss << direction() << "\n";
501 oss << " currentIncomingSide() = ";
503 oss << "invalid side\n";
504 else
505 oss << currentIncomingSide() << "\n";
506 oss << " endSet() = " << (endSet() ? "true" : "false") << "\n";
507 if (endSet())
508 {
509 oss << " endPoint() = " << endPoint() << "\n";
510 oss << " atEnd() = " << (atEnd() ? "true" : "false") << "\n";
511 }
512 oss << " distance() = " << distance() << "\n";
513 oss << " maxDistance() = " << maxDistance() << "\n";
514 if (currentElem())
515 {
516 oss << " currentElem()->id() = " << currentElem()->id() << "\n";
517 oss << " currentElem()->processor_id() = " << currentElem()->processor_id() << "\n";
518 }
519 else
520 oss << " currentElem()->id() = invalid\n";
521 oss << " processorCrossings() = " << processorCrossings() << "\n";
522 oss << " intersections() = " << intersections() << "\n";
523 oss << " trajectoryChanges() = " << trajectoryChanges() << "\n";
524 oss << " shouldContinue() = " << (shouldContinue() ? "true" : "false") << "\n";
525 oss << " trajectoryChanged() = " << (trajectoryChanged() ? "true" : "false") << "\n";
526 oss << " data() = ";
527 for (std::size_t i = 0; i < data().size(); ++i)
528 oss << "\n '" << _study.getRayDataName(i) << "' = " << data(i);
529 oss << "\n";
530 oss << " auxData() = ";
531 for (std::size_t i = 0; i < auxData().size(); ++i)
532 oss << "\n '" << _study.getRayAuxDataName(i) << "' = " << auxData(i);
533 oss << "\n";
534
535 return oss.str();
536}
537
538namespace libMesh
539{
540namespace Parallel
541{
542
543unsigned int
544Packing<std::shared_ptr<Ray>>::size(const std::size_t data_size, const std::size_t aux_data_size)
545{
546 // Current incoming side, end_set, processor crossings, intersections, trajectory
547 // changes (packed into as few buffer_type as possible: 5 values stored as 2 Reals)
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");
551
552 // First value: size of data, size of aux data, id, current point (3 values), direction (3
553 // values), current element, distance, max distance
554 // Second value: mixed size (see above)
555 auto size = 12 + mixed_size;
556
557#ifdef SINGLE_PRECISION_RAY
558 if (data_size)
559 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(data_size);
560 if (aux_data_size)
561 size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(aux_data_size);
562#else
563 size += data_size + aux_data_size;
564#endif
565
566 return size;
567}
568
569unsigned int
570Packing<std::shared_ptr<Ray>>::packed_size(typename std::vector<buffer_type>::const_iterator in)
571{
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);
574
575 return size(data_size, aux_data_size);
576}
577
578unsigned int
579Packing<std::shared_ptr<Ray>>::packable_size(const std::shared_ptr<Ray> & ray, const void *)
580{
581 return size(ray->data().size(), ray->auxData().size());
582}
583
584template <>
585std::shared_ptr<Ray>
586Packing<std::shared_ptr<Ray>>::unpack(std::vector<buffer_type>::const_iterator in,
587 ParallelStudy<std::shared_ptr<Ray>, Ray> * study)
588{
589 mooseAssert(dynamic_cast<ParallelRayStudy *>(study), "Not a ParallelRayStudy");
590 RayTracingStudy & ray_tracing_study = cast_ptr<ParallelRayStudy *>(study)->rayTracingStudy();
591
592 // Grab the data size
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++);
595
596 // ID
597 RayID id;
599
600 std::shared_ptr<Ray> ray =
601 ray_tracing_study.acquireRayInternal(id,
602 data_size,
603 aux_data_size,
604 /* reset = */ false,
606
607 // Current Point
608 ray->_current_point(0) = *in++;
609 ray->_current_point(1) = *in++;
610 ray->_current_point(2) = *in++;
611
612 // Direction
613 ray->_direction(0) = *in++;
614 ray->_direction(1) = *in++;
615 ray->_direction(2) = *in++;
616
617 // Current Element
618 RayTracingPackingUtils::unpack(ray->_current_elem, *in++, &ray_tracing_study.meshBase());
619
620 // Current incoming size, end set, processor crossings, intersections, trajectory changes
621 // (unpacked from as few buffer_type as possible - 5 values from 2 Reals)
622 RayTracingPackingUtils::mixedUnpack<buffer_type>(in,
623 ray->_current_incoming_side,
624 ray->_end_set,
625 ray->_processor_crossings,
626 ray->_intersections,
627 ray->_trajectory_changes);
628
629 // Distance
630 ray->_distance = *in++;
631
632 // Max distance
633 ray->_max_distance = *in++;
634
635#ifdef SINGLE_PRECISION_RAY
636 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_data, in);
637 RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_aux_data, in);
638#else
639 // Copy out data
641 RayTracingPackingUtils::unpackCopy(ray->_aux_data, in);
642#endif
643
644 ray->_should_continue = true;
645 ray->_trajectory_changed = false;
646
647 return ray;
648}
649
650template <>
651void
652Packing<std::shared_ptr<Ray>>::pack(const std::shared_ptr<Ray> & ray,
653 std::back_insert_iterator<std::vector<buffer_type>> data_out,
654 const ParallelStudy<std::shared_ptr<Ray>, Ray> * study)
655{
656 mooseAssert(dynamic_cast<const ParallelRayStudy *>(study), "Not a ParallelRayStudy");
657 const RayTracingStudy & ray_tracing_study =
658 cast_ptr<const ParallelRayStudy *>(study)->rayTracingStudy();
659 mooseAssert(&ray->study() == &ray_tracing_study, "Packing Ray for different study");
660
661 // Storing the data size first makes it easy to verify and reserve space
662 data_out = static_cast<buffer_type>(ray->_data.size());
663 data_out = static_cast<buffer_type>(ray->_aux_data.size());
664
665 // ID
666 data_out = RayTracingPackingUtils::pack<buffer_type>(ray->id());
667
668 // Current Point
669 data_out = ray->_current_point(0);
670 data_out = ray->_current_point(1);
671 data_out = ray->_current_point(2);
672
673 // Direction
674 data_out = ray->_direction(0);
675 data_out = ray->_direction(1);
676 data_out = ray->_direction(2);
677
678 // Current element
679 data_out =
680 RayTracingPackingUtils::pack<buffer_type>(ray->_current_elem, &ray_tracing_study.meshBase());
681
682 // Current incoming size, end set, processor crossings, intersections, trajectory changes
683 // (packed into as few buffer_type as possible - 5 values into 2 Reals
684 RayTracingPackingUtils::mixedPack<buffer_type>(data_out,
685 ray->_current_incoming_side,
686 ray->_end_set,
687 ray->_processor_crossings,
688 ray->_intersections,
689 ray->_trajectory_changes);
690
691 // Distance
692 data_out = ray->_distance;
693 // Max distance
694 data_out = ray->_max_distance;
695
696 // Copy out data
697#ifdef SINGLE_PRECISION_RAY
698 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_data, data_out);
699 RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_aux_data, data_out);
700#else
701 std::copy(ray->_data.begin(), ray->_data.end(), data_out);
702 std::copy(ray->_aux_data.begin(), ray->_aux_data.end(), data_out);
703#endif
704}
705
706} // namespace Parallel
707
708} // namespace libMesh
709
710void
711dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray, void * context)
712{
713 mooseAssert(ray, "Null ray");
714 mooseAssert(context, "Missing RayTracingStudy context");
715 mooseAssert(static_cast<RayTracingStudy *>(context) == &ray->study(), "Different study");
716
717 dataStore(stream, ray->_id, context);
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);
731 dataStore(stream, ray->_data, context);
732 dataStore(stream, ray->_aux_data, context);
733}
734
735void
736dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray, void * context)
737{
738 mooseAssert(context, "Missing RayTracingStudy context");
739 RayTracingStudy * study = static_cast<RayTracingStudy *>(context);
740
741 RayID id;
742 dataLoad(stream, id, context);
743 ray = study->acquireRayInternal(id,
744 /* data_size = */ 0,
745 /* aux_data_size = */ 0,
746 /* reset = */ true,
748
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);
765
766 if (ray->hasTraced())
767 mooseAssert(!study->currentlyGenerating() && !study->currentlyPropagating(),
768 "Cannot not load a Ray that has already traced during generation or propagation; "
769 "reset the Ray first");
770}
void mooseError(Args &&... args)
void dataStore(std::ostream &stream, std::shared_ptr< Ray > &ray, void *context)
Definition Ray.C:711
void dataLoad(std::istream &stream, std::shared_ptr< Ray > &ray, void *context)
Definition Ray.C:736
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:449
void setStartingEndPoint(const Point &starting_end_point)
Sets the starting end point to starting_point for a Ray.
Definition Ray.C:297
void clearStartingInfo()
Clears the starting information set on the Ray:
Definition Ray.C:365
void changeDirection(const Point &direction, const ChangeDirectionKey)
This method is for internal use only.
Definition Ray.C:194
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:280
void resetCountersInternal()
Reset all of the internal counters.
Definition Ray.C:404
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:390
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:372
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:396
void errorIfTracing(const std::string &reason) const
Produces a useful error if a Ray has started tracing.
Definition Ray.C:383
std::vector< RayData > & data()
Gets a writeable reference to the Ray's data.
Definition Ray.C:415
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:337
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:358
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:736
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:184
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:124
void invalidateStartingElem()
Invalidates a Ray's starting element.
Definition Ray.C:351
bool atEnd() const
Whether or not the Ray is at the user-defined end point.
Definition Ray.C:174
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:231
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:204
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:322
std::string getInfo() const
Helper function for getting information about the Ray.
Definition Ray.C:481
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:217
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
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...