https://mooseframework.inl.gov
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"
15 #include "RayTracingPackingUtils.h"
16 
17 // MOOSE includes
18 #include "DataIO.h"
19 
20 using 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 
42 void
43 Ray::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 
70 Ray::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)
84  setStartingEndPoint(other->endPoint());
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 
97 void
98 Ray::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)
112  setStartingEndPoint(other->endPoint());
113  else
114  {
115  if (!other->invalidDirection())
117  if (other->maxDistanceSet())
118  _max_distance = other->_max_distance;
119  }
120 
121  _data = other->_data;
122  _aux_data = other->_aux_data;
123 }
124 
125 bool
126 Ray::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;
143  if (_end_set != other._end_set)
144  return !equal;
146  return !equal;
147  if (_intersections != other._intersections)
148  return !equal;
150  return !equal;
152  return !equal;
154  return !equal;
156  return !equal;
157  if (_should_continue != other._should_continue)
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)
168  return !equal;
169  if (&_study != &other._study)
170  return !equal;
171 
172  return equal;
173 }
174 
175 bool
176 Ray::atEnd() const
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 
183 }
184 
185 Point
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 
195 void
197 {
198  if (direction.absolute_fuzzy_equals(Point(0, 0, 0)))
199  mooseError("Cannot set zero vector direction for a Ray\n\n", getInfo());
200 
202  _trajectory_changed = true;
203 }
204 
205 void
207  const Point & direction,
209 {
210  if (direction.absolute_fuzzy_equals(Point(0, 0, 0)))
211  mooseError("Cannot set zero vector direction for a Ray\n\n", getInfo());
212 
213  _current_point = start;
215  _trajectory_changed = true;
216 }
217 
218 void
219 Ray::setStart(const Point & starting_point,
220  const Elem * starting_elem /* = nullptr */,
221  const unsigned short starting_incoming_side /* = RayTracingCommon::invalid_side */)
222 {
223  mooseAssert(starting_point != RayTracingCommon::invalid_point, "Invalid point");
224  errorIfTracing("Cannot use Ray::setStart()");
225  if (!invalidCurrentPoint() && !_current_point.absolute_fuzzy_equals(starting_point))
226  errorWhenInitializing("Starting point was already set via Ray::setStart() and is being changed."
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().");
230 
231  _current_point = starting_point;
232  _current_elem = starting_elem;
233  _current_incoming_side = starting_incoming_side;
234 
235  if (_study.verifyRays())
236  {
237  if (!_study.looseBoundingBox().contains_point(starting_point))
238  errorWhenInitializing("Mesh does not contain starting point.");
239  if (starting_elem)
240  {
241  mooseAssert(_study.meshBase().query_elem_ptr(starting_elem->id()) == starting_elem,
242  "Element is not owned by the mesh");
243  if (!starting_elem->active())
244  errorWhenInitializing("Starting element is not active.");
245  }
246 
247  bool non_planar_start = false;
248 
250  {
251  if (!starting_elem)
252  errorWhenInitializing("Starting incoming side is set but starting element is not set.");
253  if (starting_elem->n_sides() < starting_incoming_side)
254  errorWhenInitializing("Starting incoming side is not valid for its starting element.");
255 
256  non_planar_start = _study.sideIsNonPlanar(starting_elem, starting_incoming_side);
257  if (!non_planar_start &&
258  !starting_elem->build_side_ptr(starting_incoming_side)->contains_point(starting_point))
259  errorWhenInitializing("Starting incoming side does not contain the starting point.");
260  }
261 
262  if (starting_elem && !non_planar_start && !starting_elem->contains_point(starting_point))
263  errorWhenInitializing("Starting element does not contain the starting point.");
264  }
265 }
266 
267 void
268 Ray::setStartingDirection(const Point & starting_direction)
269 {
270  errorIfTracing("Cannot use Ray::setStartingDirection()");
271  if (invalidCurrentPoint())
272  errorWhenInitializing("Cannot use Ray::setStartingDirection() before Ray::setStart().");
273  if (!invalidDirection())
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().");
278  if (starting_direction.absolute_fuzzy_equals(Point(0, 0, 0)))
279  errorWhenInitializing("Starting direction in Ray::setStartingDirection() is the zero vector.");
280 
281  _direction = starting_direction.unit();
282 }
283 
284 void
285 Ray::setStartingEndPoint(const Point & starting_end_point)
286 {
287  errorIfTracing("Cannot use Ray::setStartingEndPoint()");
288  if (invalidCurrentPoint())
289  errorWhenInitializing("Cannot use Ray::setStartingEndPoint() before Ray::setStart().");
290  if (_current_point.absolute_fuzzy_equals(starting_end_point))
291  errorWhenInitializing("End point is equal to the start point in Ray::setStartingEndPoint().");
292  if (!invalidDirection())
293  errorWhenInitializing("Cannot use Ray::setStartingEndPoint() after Ray::setStartingDirection()."
294  "\n\nClear the starting information with Ray::clearStartingInfo().");
295  if (maxDistanceSet())
297  "Cannot use Ray::setStartingEndPoint() after Ray::setStartingMaxDistance().");
298 
299  if (_study.verifyRays() && !_study.looseBoundingBox().contains_point(starting_end_point))
300  errorWhenInitializing("End point is not within the mesh for Ray::setStartingEndPoint().");
301 
302  Point difference = starting_end_point;
303  difference -= _current_point;
304  setStartingMaxDistance(difference.norm());
305  setStartingDirection(difference);
306  _end_set = true;
307 }
308 
309 void
310 Ray::setStartingMaxDistance(const Real starting_max_distance)
311 {
312  errorIfTracing("Cannot use Ray::setStartingMaxDistance()");
313  if (invalidCurrentPoint())
314  errorWhenInitializing("Cannot use Ray::setStartingMaxDistance() before Ray::setStart().");
315  if (starting_max_distance <= 0)
316  errorWhenInitializing("Starting max distance is <= 0 in Ray::setStartingMaxDistance().");
317  if (_end_set)
319  "Cannot use Ray::setStartingMaxDistance() after Ray::setStartingEndPoint().");
320 
321  _max_distance = starting_max_distance;
322 }
323 
324 void
326 {
327  errorIfTracing("Cannot use Ray::setStationary()");
328  if (invalidCurrentPoint())
329  errorWhenInitializing("Cannot use Ray::setStationary() before Ray::setStart()");
330  if (_end_set)
331  errorWhenInitializing("Cannot use Ray::setStationary() after Ray::setStartingEndPoint()");
332  if (!invalidDirection())
333  errorWhenInitializing("Cannot use Ray::setStationary() with Ray::setStartingDirection()");
334  _max_distance = 0;
335  mooseAssert(stationary(), "Stationary not set");
336 }
337 
338 void
340 {
341  errorIfTracing("Cannot use Ray::invalidateStartingElem()");
343 }
344 
345 void
347 {
348  errorIfTracing("Cannot use Ray::invalidateStartingIncomingSide()");
350 }
351 
352 void
354 {
355  errorIfTracing("Cannot use Ray::clearStartingInfo()");
357 }
358 
359 void
361 {
367  _end_set = false;
368 }
369 
370 void
371 Ray::errorIfTracing(const std::string & reason) const
372 {
373  if (hasTraced())
374  mooseError(reason, " after it has started tracing\n\n", getInfo());
375 }
376 
377 void
378 Ray::errorWhenInitializing(const std::string & reason) const
379 {
380  mooseError("While initializing starting information for a Ray:\n\n", reason, "\n\n", getInfo());
381 }
382 
383 void
385 {
387  mooseError("Ray::resetCounters() can only be used during generateRays()\n\n", getInfo());
389 }
390 
391 void
393 {
395  _intersections = 0;
397  _distance = 0;
398  _trajectory_changed = false;
399  _should_continue = true;
400 }
401 
402 std::vector<RayData> &
404 {
405  mooseAssert(_data.size() == 0 || _data.size() == _study.rayDataSize(),
406  "Ray data size of " + std::to_string(_data.size()) +
407  " is not zero or the size required by the study of " +
408  std::to_string(_study.rayDataSize()));
409  _data.resize(_study.rayDataSize());
410  return _data;
411 }
412 
413 const std::vector<RayData> &
414 Ray::data() const
415 {
416  mooseAssert(_data.size() == 0 || _data.size() == _study.rayDataSize(),
417  "Ray data size is not zero or the size required by study");
418  _data.resize(_study.rayDataSize());
419  return _data;
420 }
421 
422 RayData &
423 Ray::data(const std::size_t i)
424 {
425  mooseAssert(_study.rayDataSize() > i, "Accessing Ray data out of range");
426  return data()[i];
427 }
428 
429 const RayData &
430 Ray::data(const std::size_t i) const
431 {
432  mooseAssert(_study.rayDataSize() > i, "Accessing Ray data out of range");
433  return data()[i];
434 }
435 
436 std::vector<RayData> &
438 {
439  mooseAssert(_aux_data.size() == 0 || _aux_data.size() == _study.rayAuxDataSize(),
440  "Ray data size is not zero or the size required by study");
441  _aux_data.resize(_study.rayAuxDataSize());
442  return _aux_data;
443 }
444 
445 const std::vector<RayData> &
447 {
448  mooseAssert(_aux_data.size() == 0 || _aux_data.size() == _study.rayAuxDataSize(),
449  "Ray data size is not zero or the size required by study");
450  _aux_data.resize(_study.rayAuxDataSize());
451  return _aux_data;
452 }
453 
454 RayData &
455 Ray::auxData(const std::size_t i)
456 {
457  mooseAssert(_study.rayAuxDataSize() > i, "Accessing Ray data out of range");
458  return auxData()[i];
459 }
460 
461 const RayData &
462 Ray::auxData(const std::size_t i) const
463 {
464  mooseAssert(_study.rayAuxDataSize() > i, "Accessing Ray data out of range");
465  return auxData()[i];
466 }
467 
468 std::string
470 {
471  std::ostringstream oss;
472 
473  oss << "Ray information with " << _study.type() << " '" << _study.name() << "' on pid "
474  << _study.comm().rank() << "\n";
475  oss << " this = " << this << "\n";
476  oss << " id() = " << id() << "\n";
477  if (_study.useRayRegistration() && !invalidID())
478  oss << " _study.registeredRayName(id()) = " << _study.registeredRayName(id()) << "\n";
479  oss << " currentPoint() = ";
480  if (invalidCurrentPoint())
481  oss << "invalid point\n";
482  else
483  oss << currentPoint() << "\n";
484  oss << " direction() = ";
485  if (invalidDirection())
486  oss << "invalid point\n";
487  else
488  oss << direction() << "\n";
489  oss << " currentIncomingSide() = ";
491  oss << "invalid side\n";
492  else
493  oss << currentIncomingSide() << "\n";
494  oss << " endSet() = " << (endSet() ? "true" : "false") << "\n";
495  if (endSet())
496  {
497  oss << " endPoint() = " << endPoint() << "\n";
498  oss << " atEnd() = " << (atEnd() ? "true" : "false") << "\n";
499  }
500  oss << " distance() = " << distance() << "\n";
501  oss << " maxDistance() = " << maxDistance() << "\n";
502  if (currentElem())
503  {
504  oss << " currentElem()->id() = " << currentElem()->id() << "\n";
505  oss << " currentElem()->processor_id() = " << currentElem()->processor_id() << "\n";
506  }
507  else
508  oss << " currentElem()->id() = invalid\n";
509  oss << " processorCrossings() = " << processorCrossings() << "\n";
510  oss << " intersections() = " << intersections() << "\n";
511  oss << " trajectoryChanges() = " << trajectoryChanges() << "\n";
512  oss << " shouldContinue() = " << (shouldContinue() ? "true" : "false") << "\n";
513  oss << " trajectoryChanged() = " << (trajectoryChanged() ? "true" : "false") << "\n";
514  oss << " data() = ";
515  for (std::size_t i = 0; i < data().size(); ++i)
516  oss << "\n '" << _study.getRayDataName(i) << "' = " << data(i);
517  oss << "\n";
518  oss << " auxData() = ";
519  for (std::size_t i = 0; i < auxData().size(); ++i)
520  oss << "\n '" << _study.getRayAuxDataName(i) << "' = " << auxData(i);
521  oss << "\n";
522 
523  return oss.str();
524 }
525 
526 namespace libMesh
527 {
528 namespace Parallel
529 {
530 
531 unsigned int
532 Packing<std::shared_ptr<Ray>>::size(const std::size_t data_size, const std::size_t aux_data_size)
533 {
534  // Current incoming side, end_set, processor crossings, intersections, trajectory
535  // changes (packed into as few buffer_type as possible: 5 values stored as 2 Reals)
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");
539 
540  // First value: size of data, size of aux data, id, current point (3 values), direction (3
541  // values), current element, distance, max distance
542  // Second value: mixed size (see above)
543  auto size = 12 + mixed_size;
544 
545 #ifdef SINGLE_PRECISION_RAY
546  if (data_size)
547  size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(data_size);
548  if (aux_data_size)
549  size += RayTracingPackingUtils::reinterpretCopySize<RayData, buffer_type>(aux_data_size);
550 #else
551  size += data_size + aux_data_size;
552 #endif
553 
554  return size;
555 }
556 
557 unsigned int
558 Packing<std::shared_ptr<Ray>>::packed_size(typename std::vector<buffer_type>::const_iterator in)
559 {
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);
562 
563  return size(data_size, aux_data_size);
564 }
565 
566 unsigned int
567 Packing<std::shared_ptr<Ray>>::packable_size(const std::shared_ptr<Ray> & ray, const void *)
568 {
569  return size(ray->data().size(), ray->auxData().size());
570 }
571 
572 template <>
573 std::shared_ptr<Ray>
574 Packing<std::shared_ptr<Ray>>::unpack(std::vector<buffer_type>::const_iterator in,
575  ParallelStudy<std::shared_ptr<Ray>, Ray> * study)
576 {
577  mooseAssert(dynamic_cast<ParallelRayStudy *>(study), "Not a ParallelRayStudy");
578  RayTracingStudy & ray_tracing_study = static_cast<ParallelRayStudy *>(study)->rayTracingStudy();
579 
580  // Grab the data size
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++);
583 
584  // ID
585  RayID id;
587 
588  std::shared_ptr<Ray> ray =
589  ray_tracing_study.acquireRayInternal(id,
590  data_size,
591  aux_data_size,
592  /* reset = */ false,
594 
595  // Current Point
596  ray->_current_point(0) = *in++;
597  ray->_current_point(1) = *in++;
598  ray->_current_point(2) = *in++;
599 
600  // Direction
601  ray->_direction(0) = *in++;
602  ray->_direction(1) = *in++;
603  ray->_direction(2) = *in++;
604 
605  // Current Element
606  RayTracingPackingUtils::unpack(ray->_current_elem, *in++, &ray_tracing_study.meshBase());
607 
608  // Current incoming size, end set, processor crossings, intersections, trajectory changes
609  // (unpacked from as few buffer_type as possible - 5 values from 2 Reals)
610  RayTracingPackingUtils::mixedUnpack<buffer_type>(in,
611  ray->_current_incoming_side,
612  ray->_end_set,
613  ray->_processor_crossings,
614  ray->_intersections,
615  ray->_trajectory_changes);
616 
617  // Distance
618  ray->_distance = *in++;
619 
620  // Max distance
621  ray->_max_distance = *in++;
622 
623 #ifdef SINGLE_PRECISION_RAY
624  RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_data, in);
625  RayTracingPackingUtils::reinterpretUnpackCopy<buffer_type>(ray->_aux_data, in);
626 #else
627  // Copy out data
628  RayTracingPackingUtils::unpackCopy(ray->_data, in);
629  RayTracingPackingUtils::unpackCopy(ray->_aux_data, in);
630 #endif
631 
632  ray->_should_continue = true;
633  ray->_trajectory_changed = false;
634 
635  return ray;
636 }
637 
638 template <>
639 void
640 Packing<std::shared_ptr<Ray>>::pack(const std::shared_ptr<Ray> & ray,
641  std::back_insert_iterator<std::vector<buffer_type>> data_out,
642  const ParallelStudy<std::shared_ptr<Ray>, Ray> * study)
643 {
644  mooseAssert(dynamic_cast<const ParallelRayStudy *>(study), "Not a ParallelRayStudy");
645  const RayTracingStudy & ray_tracing_study =
646  static_cast<const ParallelRayStudy *>(study)->rayTracingStudy();
647  mooseAssert(&ray->study() == &ray_tracing_study, "Packing Ray for different study");
648 
649  // Storing the data size first makes it easy to verify and reserve space
650  data_out = static_cast<buffer_type>(ray->_data.size());
651  data_out = static_cast<buffer_type>(ray->_aux_data.size());
652 
653  // ID
654  data_out = RayTracingPackingUtils::pack<buffer_type>(ray->id());
655 
656  // Current Point
657  data_out = ray->_current_point(0);
658  data_out = ray->_current_point(1);
659  data_out = ray->_current_point(2);
660 
661  // Direction
662  data_out = ray->_direction(0);
663  data_out = ray->_direction(1);
664  data_out = ray->_direction(2);
665 
666  // Current element
667  data_out =
668  RayTracingPackingUtils::pack<buffer_type>(ray->_current_elem, &ray_tracing_study.meshBase());
669 
670  // Current incoming size, end set, processor crossings, intersections, trajectory changes
671  // (packed into as few buffer_type as possible - 5 values into 2 Reals
672  RayTracingPackingUtils::mixedPack<buffer_type>(data_out,
673  ray->_current_incoming_side,
674  ray->_end_set,
675  ray->_processor_crossings,
676  ray->_intersections,
677  ray->_trajectory_changes);
678 
679  // Distance
680  data_out = ray->_distance;
681  // Max distance
682  data_out = ray->_max_distance;
683 
684  // Copy out data
685 #ifdef SINGLE_PRECISION_RAY
686  RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_data, data_out);
687  RayTracingPackingUtils::reinterpretPackCopy<buffer_type>(ray->_aux_data, data_out);
688 #else
689  std::copy(ray->_data.begin(), ray->_data.end(), data_out);
690  std::copy(ray->_aux_data.begin(), ray->_aux_data.end(), data_out);
691 #endif
692 }
693 
694 } // namespace Parallel
695 
696 } // namespace libMesh
697 
698 void
699 dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray, void * context)
700 {
701  mooseAssert(ray, "Null ray");
702  mooseAssert(context, "Missing RayTracingStudy context");
703  mooseAssert(static_cast<RayTracingStudy *>(context) == &ray->study(), "Different study");
704 
705  storeHelper(stream, ray->_id, context);
706  storeHelper(stream, ray->_current_point, context);
707  storeHelper(stream, ray->_direction, context);
708  auto current_elem_id = ray->currentElem() ? ray->currentElem()->id() : DofObject::invalid_id;
709  storeHelper(stream, current_elem_id, context);
710  storeHelper(stream, ray->_current_incoming_side, context);
711  storeHelper(stream, ray->_end_set, context);
712  storeHelper(stream, ray->_processor_crossings, context);
713  storeHelper(stream, ray->_intersections, context);
714  storeHelper(stream, ray->_trajectory_changes, context);
715  storeHelper(stream, ray->_trajectory_changed, context);
716  storeHelper(stream, ray->_distance, context);
717  storeHelper(stream, ray->_max_distance, context);
718  storeHelper(stream, ray->_should_continue, context);
719  storeHelper(stream, ray->_data, context);
720  storeHelper(stream, ray->_aux_data, context);
721 }
722 
723 void
724 dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray, void * context)
725 {
726  mooseAssert(context, "Missing RayTracingStudy context");
727  RayTracingStudy * study = static_cast<RayTracingStudy *>(context);
728 
729  RayID id;
730  loadHelper(stream, id, context);
731  ray = study->acquireRayInternal(id,
732  /* data_size = */ 0,
733  /* aux_data_size = */ 0,
734  /* reset = */ true,
736 
737  loadHelper(stream, ray->_current_point, context);
738  loadHelper(stream, ray->_direction, context);
739  dof_id_type current_elem_id;
740  loadHelper(stream, current_elem_id, context);
741  ray->_current_elem = study->meshBase().query_elem_ptr(current_elem_id);
742  loadHelper(stream, ray->_current_incoming_side, context);
743  loadHelper(stream, ray->_end_set, 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);
748  loadHelper(stream, ray->_distance, context);
749  loadHelper(stream, ray->_max_distance, context);
750  loadHelper(stream, ray->_should_continue, context);
751  loadHelper(stream, ray->_data, context);
752  loadHelper(stream, ray->_aux_data, context);
753 
754  if (ray->hasTraced())
755  mooseAssert(!study->currentlyGenerating() && !study->currentlyPropagating(),
756  "Cannot not load a Ray that has already traced during generation or propagation; "
757  "reset the Ray first");
758 }
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&#39;s ID.
Definition: Ray.h:207
std::vector< RayData > & data()
Gets a writeable reference to the Ray&#39;s data.
Definition: Ray.C:403
unsigned int processorCrossings() const
Gets the number of times this Ray has crossed a processor.
Definition: Ray.h:478
bool invalidID() const
Whether or not the Ray&#39;s ID is invalid.
Definition: Ray.h:211
void invalidateMaxDistance()
Invalidates the Ray&#39;s max distance.
Definition: Ray.h:622
unsigned long int RayID
Type for a Ray&#39;s ID.
Definition: Ray.h:43
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.
Definition: Ray.h:87
bool trajectoryChanged() const
Whether or not this Ray has had its trajectory changed.
Definition: Ray.h:518
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.
Definition: Ray.h:532
Point _direction
Direction of the Ray.
Definition: Ray.h:662
bool useRayRegistration() const
Whether or not ray registration is being used.
std::string getInfo() const
Helper function for getting information about the Ray.
Definition: Ray.C:469
processor_id_type rank() const
const Parallel::Communicator & comm() const
std::vector< RayData > & auxData()
Gets a writeable reference to the Ray&#39;s auxilary data.
Definition: Ray.C:437
void invalidateStartingElem()
Invalidates a Ray&#39;s starting element.
Definition: Ray.C:339
unsigned int trajectoryChanges() const
Gets the number of trajectory changes this Ray has had.
Definition: Ray.h:522
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.
Definition: Ray.h:540
unsigned int _processor_crossings
Number of times this Ray has been communicated.
Definition: Ray.h:694
const Point & currentPoint() const
Gets the point that the Ray is currently at.
Definition: Ray.h:221
void changeDirection(const Point &direction, const ChangeDirectionKey)
This method is for internal use only.
Definition: Ray.C:196
const Elem * currentElem() const
Gets the current element that the Ray is in.
Definition: Ray.h:425
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.
Definition: Ray.C:176
auto max(const L &left, const R &right)
bool stationary() const
Definition: Ray.h:738
bool invalidCurrentPoint() const
Whether or not the point that the Ray is currently at is valid.
Definition: Ray.h:225
Point _current_point
Current point of the Ray.
Definition: Ray.h:659
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.
Definition: Ray.C:206
bool maxDistanceSet() const
Whether or not the distance has been set via setStartingMaxDistance()
Definition: Ray.h:499
TypeVector< Real > unit() const
bool invalidCurrentIncomingSide() const
Whether or not the Ray&#39;s current incoming side is invalid.
Definition: Ray.h:444
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.
Definition: Ray.C:285
void dataStore(std::ostream &stream, std::shared_ptr< Ray > &ray, void *context)
Definition: Ray.C:699
dof_id_type id() const
void setStartingDirection(const Point &starting_direction)
Sets the starting direction to starting_direction for a Ray.
Definition: Ray.C:268
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:718
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:
Definition: Ray.C:353
bool _should_continue
Wether or not the Ray should continue to be traced (not sent in parallel)
Definition: Ray.h:710
RayTracingStudy & _study
The RayTracingStudy that owns this Ray (not sent in parallel)
Definition: Ray.h:721
void invalidateCurrentIncomingSide()
Invalidates the Ray&#39;s current incoming side.
Definition: Ray.h:586
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.
Definition: Ray.h:56
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&#39;s direction is set to invalid.
Definition: Ray.h:259
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.
Definition: Ray.C:310
bool shouldContinue() const
Whether or not this Ray should continue.
Definition: Ray.h:509
bool endSet() const
Whether or not the user has set an end point for this Ray.
Definition: Ray.h:454
Real _max_distance
Maximum distance the Ray is allowed to travel.
Definition: Ray.h:707
void invalidateDirection()
Invalidates the Ray&#39;s current direction.
Definition: Ray.h:569
void resetCountersInternal()
Reset all of the internal counters.
Definition: Ray.C:392
virtual unsigned int n_sides() const=0
unsigned short currentIncomingSide() const
Get a Ray&#39;s current incoming side.
Definition: Ray.h:435
void setStationary()
Sets the Ray to be stationary (max distance = 0).
Definition: Ray.C:325
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.
Definition: Ray.C:384
void clearStartingInfoInternal()
Clears the starting information.
Definition: Ray.C:360
Class that is used as a parameter to changeStartDirection() that allows only RayKernelBase methods to...
Definition: Ray.h:74
Real distance() const
Gets the distance this Ray has traveled.
Definition: Ray.h:488
Class that is used as a parameter to changeDirection() that allows only RayBC methods to call changeD...
Definition: Ray.h:63
void invalidateStartingIncomingSide()
Invalidates a Ray&#39;s starting incoming side.
Definition: Ray.C:346
const Elem * _current_elem
Current element that the Ray is in.
Definition: Ray.h:677
const Point & direction() const
Gets the Ray&#39;s direction.
Definition: Ray.h:255
bool equalityHelper(const Ray &other, const bool equal) const
Helper for the equality operators.
Definition: Ray.C:126
Real maxDistance() const
Gets the max distance this Ray is allowed to travel.
Definition: Ray.h:495
RayID _id
A unique ID for this Ray.
Definition: Ray.h:649
MeshBase & meshBase() const
Access to the libMesh MeshBase.
Real _distance
Total distance this Ray has traveled.
Definition: Ray.h:705
unsigned int _intersections
Number of intersections done for this Ray.
Definition: Ray.h:697
float RayData
Type for a Ray&#39;s data.
Definition: Ray.h:46
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...
Definition: Ray.h:714
bool _trajectory_changed
Whether or not this Ray had its trajectory changed (not sent in parallel)
Definition: Ray.h:702
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.
Definition: Ray.C:219
unsigned int _trajectory_changes
Number of times this Ray has had its trajectory changed.
Definition: Ray.h:700
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...
Definition: Ray.h:691
unsigned short _current_incoming_side
The side of _current_elem that the Ray is incoming on (if any).
Definition: Ray.h:687
bool active() const
processor_id_type processor_id() const
unsigned int intersections() const
Gets the number of intersections this Ray has done.
Definition: Ray.h:483
void errorWhenInitializing(const std::string &reason) const
Produces a useful error for use when initializing a Ray.
Definition: Ray.C:378
Point endPoint() const
Gets the user-set end point for the Ray, if set.
Definition: Ray.C:186
void loadHelper(std::istream &stream, P &data, void *context)
void invalidateCurrentElem()
Invalidates the Ray&#39;s current element.
Definition: Ray.h:551
void dataLoad(std::istream &stream, std::shared_ptr< Ray > &ray, void *context)
Definition: Ray.C:724
void invalidateCurrentPoint()
Invalidates the Ray&#39;s current point.
Definition: Ray.h:560
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.
Definition: Ray.C:371
uint8_t dof_id_type
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...