Line data Source code
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 : #pragma once
11 :
12 : // Local includes
13 : #include "RayTracingCommon.h"
14 :
15 : // MOOSE includes
16 : #include "MooseError.h"
17 : #include "MooseTypes.h"
18 :
19 : // libMesh Includes
20 : #include "libmesh/parallel.h"
21 :
22 : // Forward declarations
23 : namespace libMesh
24 : {
25 : class Elem;
26 : }
27 : class RayTracingStudy;
28 : // Friend access to Ray
29 : class TraceRay;
30 : class TestRayLots;
31 : // Friend access to ChangeDirectionKey for accessing changeDirection()
32 : class RayBoundaryConditionBase;
33 : // Friend access to ChangeStartDirectionKey for accessing changeStartDirection()
34 : class RayKernelBase;
35 : // Friend access to NonResetCountersKey for accessing constructor/reset without counter reset
36 : namespace MooseUtils
37 : {
38 : template <class T>
39 : class SharedPool;
40 : }
41 :
42 : /// Type for a Ray's ID
43 : typedef unsigned long int RayID;
44 : /// Type for a Ray's data
45 : #ifdef SINGLE_PRECISION_RAY
46 : typedef float RayData;
47 : #else
48 : typedef libMesh::Real RayData;
49 : #endif
50 : /// Type for the index into the data and aux data on a Ray
51 : typedef unsigned int RayDataIndex;
52 :
53 : /**
54 : * Basic datastructure for a ray that will traverse the mesh.
55 : */
56 10797249 : class Ray
57 : {
58 : public:
59 : /**
60 : * Class that is used as a parameter to changeDirection() that allows only
61 : * RayBC methods to call changeDirection()
62 : */
63 : class ChangeDirectionKey
64 : {
65 : friend class RayBoundaryConditionBase;
66 : ChangeDirectionKey() {}
67 : ChangeDirectionKey(const ChangeDirectionKey &) {}
68 : };
69 :
70 : /**
71 : * Class that is used as a parameter to changeStartDirection() that allows only
72 : * RayKernelBase methods to call changeStartDirection()
73 : */
74 : class ChangeStartDirectionKey
75 : {
76 : friend class RayKernelBase;
77 : ChangeStartDirectionKey() {}
78 : ChangeStartDirectionKey(const ChangeStartDirectionKey &) {}
79 : };
80 :
81 : /**
82 : * Class that is used as a parameter to the public constructors/reset methods.
83 : *
84 : * We explicitly do not allow construction of Rays except through the
85 : * acquire{}() methods in the RayTracingStudy, which necessitates this class.
86 : */
87 : class ConstructRayKey
88 : {
89 : friend class RayTracingStudy;
90 : friend class MooseUtils::SharedPool<Ray>;
91 : friend class TestRayLots;
92 : ConstructRayKey() {}
93 : ConstructRayKey(const ConstructRayKey &) {}
94 : };
95 :
96 : /**
97 : * Ray constructor for internal use only.
98 : *
99 : * Even though this method is public, it in general CANNOT be used publicly. This is
100 : * ONLY used internally and is protected by the ConstructRayKey. In order to construct
101 : * a Ray as a user, use the RayTracingStudy::acquire{}() methods, such as
102 : * RayTracingStudy::acquireRay().
103 : *
104 : * @param study The study that owns the Ray
105 : * @param id ID for the Ray
106 : * @param data_size Size of data to initialize with zeros
107 : * @param aux_data_size Size of aux data to initialize with zeros
108 : * @param reset Whether or not to reset the Ray information
109 : */
110 : Ray(RayTracingStudy * study,
111 : const RayID id,
112 : const std::size_t data_size,
113 : const std::size_t aux_data_size,
114 : const bool reset,
115 : const ConstructRayKey &);
116 :
117 : /**
118 : * Resets a Ray for internal use only. Used by the SharedPool to reset a Ray with
119 : * these forwarded arguments.
120 : *
121 : * Even though this method is public, it in general CANNOT be used publicly. This is
122 : * ONLY used internally and is protected by the ConstructRayKey. In order to construct
123 : * a Ray as a user, use the RayTracingStudy::acquire{}() methods, such as
124 : * RayTracingStudy::acquireRay().
125 : *
126 : * @param study The study that owns the Ray
127 : * @param id ID for the Ray
128 : * @param data_size Size of data to initialize with zeros
129 : * @param aux_data_size Size of aux data to initialize with zeros
130 : * @param reset Whether or not to reset the Ray information
131 : */
132 : void reset(RayTracingStudy * study,
133 : const RayID id,
134 : const std::size_t data_size,
135 : const std::size_t aux_data_size,
136 : const bool reset,
137 : const ConstructRayKey &);
138 :
139 : /**
140 : * Copy constructor for internal use only.
141 : *
142 : * Even though this method is public, it in general CANNOT be used publicly. This is
143 : * ONLY used internally and is protected by the ConstructRayKey. In order to construct
144 : * a Ray as a user, use the RayTracingStudy::acquire{}() methods, such as
145 : * RayTracingStudy::acquireRay().
146 : *
147 : * Resets the counters.
148 : */
149 : Ray(const Ray * const other, const ConstructRayKey &);
150 :
151 : /**
152 : * Resets a Ray from another Ray for internal use only. Used by the SharedPool
153 : * to reset a Ray from another.
154 : *
155 : * Even though this method is public, it in general CANNOT be used publicly. This is
156 : * ONLY used internally and is protected by the ConstructRayKey. In order to construct
157 : * a Ray as a user, use the RayTracingStudy::acquire{}() methods, such as
158 : * RayTracingStudy::acquireRay().
159 : *
160 : * Resets the counters.
161 : */
162 : void reset(const Ray * const other, const ConstructRayKey &);
163 :
164 : /**
165 : * Deleted copy operator.
166 : *
167 : * General Ray modification is handled internally within the RayTracingStudy
168 : * via the RayTracingStudy::acquire{}() methods.
169 : */
170 : Ray & operator=(const Ray &) = delete;
171 : /**
172 : * Deleted default constructor.
173 : *
174 : * All Ray construction is handled internally within the RayTracingStudy
175 : * via the RayTracingStudy::acquire{}() methods.
176 : */
177 : Ray() = delete;
178 : /**
179 : * Deleted copy constructor.
180 : *
181 : * All Ray construction is handled internally within the RayTracingStudy
182 : * via the RayTracingStudy::acquire{}() methods.
183 : */
184 : Ray(const Ray & other) = delete;
185 :
186 : /**
187 : * Equality operator.
188 : *
189 : * This will perform "fuzzy" equals checks on the points and data.
190 : */
191 38760 : bool operator==(const Ray & other) const { return equalityHelper(other, true); }
192 : /**
193 : * Non-equal operator.
194 : *
195 : * This will perform "fuzzy" equals checks on the points and data.
196 : */
197 40140 : bool operator!=(const Ray & other) const { return equalityHelper(other, false); }
198 :
199 : /// Invalid index into a Ray's data
200 : static const RayDataIndex INVALID_RAY_DATA_INDEX = static_cast<RayDataIndex>(-1);
201 : /// Invalid Ray ID
202 : static const RayID INVALID_RAY_ID = static_cast<RayID>(-1);
203 :
204 : /**
205 : * Gets the Ray's ID
206 : */
207 11728260 : RayID id() const { return _id; }
208 : /**
209 : * Whether or not the Ray's ID is invalid
210 : */
211 37 : bool invalidID() const { return _id == INVALID_RAY_ID; }
212 :
213 : /**
214 : * Gets the point that the Ray is currently at.
215 : *
216 : * Before a Ray is traced, this is the starting point of the Ray.
217 : * While a Ray is being traced, this is the furthest point that the Ray
218 : * has travelled. During RayKernel execution, this is the end of the segment.
219 : * After a Ray has been traced, this is the point where the Ray was killed.
220 : */
221 384915 : const Point & currentPoint() const { return _current_point; }
222 : /**
223 : * Whether or not the point that the Ray is currently at is valid.
224 : */
225 31189147 : bool invalidCurrentPoint() const { return _current_point == RayTracingCommon::invalid_point; }
226 :
227 : /**
228 : * This method is for internal use only. It is intended to be called only by
229 : * RayBoundaryConditionBase::changeRayDirection().
230 : *
231 : * If you wish to change a Ray's direction mid-trace in a RayBC, see
232 : * RayBoundaryConditionBase::changeRayDirection() instead.
233 : *
234 : * ChangeDirectionKey is constructable only by RayBC objects on purpose to limit usage of this
235 : * method.
236 : */
237 : void changeDirection(const Point & direction, const ChangeDirectionKey);
238 :
239 : /**
240 : * This method is for internal use only. It is intended to be called only by
241 : * RayKernelBase::changeRay().
242 : *
243 : * If you wish to change a Ray's direction mid-trace in a RayKernel, see
244 : * RayKernelBase::changeRay() instead.
245 : *
246 : * ChangeStartDirectionKey is constructable only by RayKernelBase objects on purpose to limit
247 : * usage of this method.
248 : */
249 : void
250 : changeStartDirection(const Point & start, const Point & direction, const ChangeStartDirectionKey);
251 :
252 : /**
253 : * Gets the Ray's direction
254 : */
255 52925160 : const Point & direction() const { return _direction; }
256 : /**
257 : * Whether or not the Ray's direction is set to invalid.
258 : */
259 14941568 : bool invalidDirection() const { return _direction == RayTracingCommon::invalid_point; }
260 :
261 : /**
262 : * Gets a writeable reference to the Ray's data.
263 : *
264 : * If the data is not sized to the size as required by the study, this will
265 : * resize the data.
266 : */
267 : std::vector<RayData> & data();
268 : /**
269 : * Gets a read only reference to the Ray's data.
270 : *
271 : * If the data is not sized to the size as required by the study, this will
272 : * resize the data.
273 : */
274 : const std::vector<RayData> & data() const;
275 : /**
276 : * Gets a writeable reference to the Ray's data at an index.
277 : *
278 : * If the data is not sized to the size as required by the study, this will
279 : * resize the data.
280 : */
281 : RayData & data(const std::size_t i);
282 : /**
283 : * Gets a read only reference to the Ray's data at an index.
284 : *
285 : * If the data is not sized to the size as required by the study, this will
286 : * resize the data.
287 : */
288 : const RayData & data(const std::size_t i) const;
289 :
290 : /**
291 : * Gets a writeable reference to the Ray's auxilary data
292 : *
293 : * If the aux data is not sized to the size as required by the study, this will
294 : * resize the aux data.
295 : */
296 : std::vector<RayData> & auxData();
297 : /**
298 : * Gets a read only reference to the Ray's auxilary data
299 : *
300 : * If the aux data is not sized to the size as required by the study, this will
301 : * resize the aux data.
302 : */
303 : const std::vector<RayData> & auxData() const;
304 : /**
305 : * Gets a writeable reference to a component of the Ray's auxilary data
306 : *
307 : * If the aux data is not sized to the size as required by the study, this will
308 : * resize the aux data.
309 : */
310 : RayData & auxData(const std::size_t i);
311 : /**
312 : * Gets a read only reference to a component of the Ray's auxilary data
313 : *
314 : * If the aux data is not sized to the size as required by the study, this will
315 : * resize the aux data.
316 : */
317 : const RayData & auxData(const std::size_t i) const;
318 :
319 : /**
320 : * Sets the information pretaining to the start point for the Ray.
321 : *
322 : * This MUST be called before setStartingDirection(), setStartingEndPoint(),
323 : * or setStartingMaxDistance(). It cannot be called after a Ray has
324 : * begun tracing.
325 : *
326 : * @param starting_point The starting point
327 : * @param starting_elem The starting element (if known)
328 : * @param starting_incoming_side The starting incoming side (if known and if
329 : * the Ray starts on a side of \p starting_elem
330 : */
331 : void setStart(const Point & starting_point,
332 : const Elem * starting_elem = nullptr,
333 : const unsigned short starting_incoming_side = RayTracingCommon::invalid_side);
334 : /**
335 : * Sets the starting direction to \p starting_direction for a Ray.
336 : *
337 : * This MUST be called after setStart(). It cannot be used with
338 : * setStartingEndPoint(), which sets the direction internally.
339 : * It cannot be called after a Ray has begun tracing.
340 : */
341 : void setStartingDirection(const Point & starting_direction);
342 : /**
343 : * Sets the starting end point to \p starting_point for a Ray.
344 : *
345 : * This MUST be called after setStart(). It cannot be used with
346 : * setStartingDirection(). It cannot be called after a Ray has begun tracing.
347 : *
348 : * Internally, this sets the direction to be
349 : * currentPoint() -> \p starting_direction, and sets the maximum
350 : * distance to || \p starting_direction - currentPoint() ||.
351 : */
352 : void setStartingEndPoint(const Point & starting_end_point);
353 : /**
354 : * Sets the maximum distance this Ray should travel to \p starting_max_distance.
355 : *
356 : * This MUST be called after setStart(). It cannot be used with
357 : * setStartingEndPoint(). It cannot be called after a Ray has begun tracing.
358 : *
359 : * If setting a Ray's trajectory with setStartingEndPoint(), the max distance
360 : * is set internally to be || end - start ||.
361 : *
362 : * Can only be called before a Ray has started to be traced!
363 : */
364 : void setStartingMaxDistance(const Real starting_max_distance);
365 : /**
366 : * Sets the Ray to be stationary (max distance = 0).
367 : *
368 : * This MUST be called after setStart(). It cannot be used with
369 : * setStartingEndPoint(). It cannot be called after a Ray has begun tracing.
370 : *
371 : * Can only be called before a Ray has started to be traced!
372 : */
373 : void setStationary();
374 :
375 : /**
376 : * Invalidates a Ray's starting element.
377 : *
378 : * This is useful after the mesh has changed due to adaptivity,
379 : * in which the starting element may no longer be valid.
380 : *
381 : * This can only be called before a Ray has begun tracing.
382 : */
383 : void invalidateStartingElem();
384 : /**
385 : * Invalidates a Ray's starting incoming side.
386 : *
387 : * This is useful after the mesh has changed due to adaptivity,
388 : * in which the incoming side may no longer be valid.
389 : *
390 : * This can only be called before a Ray has begun tracing.
391 : */
392 : void invalidateStartingIncomingSide();
393 : /**
394 : * Clears the starting information set on the Ray:
395 : * - Starting point
396 : * - Starting element
397 : * - Starting incoming side
398 : * - Starting direction
399 : * - Starting maximum distance
400 : *
401 : * This can only be called before a Ray has begun tracing.
402 : */
403 : void clearStartingInfo();
404 :
405 : /**
406 : * Clears the internal counters on the Ray so that the Ray can be traced again.
407 : *
408 : * Can only be used within generateRays().
409 : */
410 : void resetCounters();
411 :
412 : /**
413 : * Gets the current element that the Ray is in.
414 : *
415 : * Before tracing, this is the starting element for the Ray.
416 : *
417 : * During tracing:
418 : * - It is valid within RayKernels, because a Ray can only operate on a
419 : * single element per segment.
420 : * - When used on boundaries (RayBCs), it is the element that the
421 : * Ray actually traced through. When on a boundary, a RayBC may be
422 : * applied to multiple elements when hitting a vertex or edge.
423 : * Therefore, this will be only one of said elements.
424 : */
425 14688265 : const Elem * currentElem() const { return _current_elem; }
426 :
427 : /**
428 : * Get a Ray's current incoming side
429 : *
430 : * Before tracing, this is the starting incoming side (if any).
431 : *
432 : * During and after tracing, this is ONLY guaranteed to be valid
433 : * while executing RayKernels!
434 : */
435 5380196 : unsigned short currentIncomingSide() const { return _current_incoming_side; }
436 : /**
437 : * Whether or not the Ray's current incoming side is invalid
438 : *
439 : * Before tracing, this is the starting incoming side (if any).
440 : *
441 : * During and after tracing, this is ONLY guaranteed to be valid
442 : * while executing RayKernels!
443 : */
444 : bool invalidCurrentIncomingSide() const
445 : {
446 13581349 : return _current_incoming_side == RayTracingCommon::invalid_side;
447 : }
448 :
449 : /**
450 : * Whether or not the user has set an end point for this Ray.
451 : *
452 : * This is done by limiting the distance of the Ray in its set direction.
453 : */
454 12255 : bool endSet() const { return _end_set; }
455 : /**
456 : * Whether or not the Ray is at the user-defined end point.
457 : *
458 : * This is only valid when the user set the trajectory of the Ray
459 : * with setStartingEndPoint(), which internally set its maximum distance
460 : * to the straight-line distance between start and end and set
461 : * endSet() == true.
462 : */
463 : bool atEnd() const;
464 : /**
465 : * Gets the user-set end point for the Ray, if set.
466 : *
467 : * Internally, we do not keep track of the end point. Instead,
468 : * we set a maximum straight-line distance the Ray can travel
469 : * until it hits its endpoint. With the current point, the distance,
470 : * the maximum distance, and the direction, we can infer the
471 : * user-set end point.
472 : */
473 : Point endPoint() const;
474 :
475 : /**
476 : * Gets the number of times this Ray has crossed a processor
477 : */
478 4138396 : unsigned int processorCrossings() const { return _processor_crossings; }
479 :
480 : /**
481 : * Gets the number of intersections this Ray has done
482 : */
483 4138396 : unsigned int intersections() const { return _intersections; }
484 :
485 : /**
486 : * Gets the distance this Ray has traveled
487 : */
488 4385969 : Real distance() const { return _distance; }
489 : /**
490 : * Gets the max distance this Ray is allowed to travel
491 : *
492 : * This may be set internally to || end - start || in the case that
493 : * the user initialized the Ray with setStartingEndPoint().
494 : */
495 37739939 : Real maxDistance() const { return _max_distance; }
496 : /**
497 : * Whether or not the distance has been set via setStartingMaxDistance()
498 : */
499 6710454 : bool maxDistanceSet() const { return _max_distance != std::numeric_limits<Real>::max(); }
500 :
501 : /**
502 : * @return Whether or not the Ray is set to be stationary
503 : */
504 : inline bool stationary() const;
505 :
506 : /**
507 : * Whether or not this Ray should continue
508 : */
509 42183573 : bool shouldContinue() const { return _should_continue; }
510 : /**
511 : * Sets whether or not this Ray should continue
512 : */
513 1520633 : void setShouldContinue(const bool should_continue) { _should_continue = should_continue; }
514 :
515 : /**
516 : * Whether or not this Ray has had its trajectory changed
517 : */
518 36788482 : bool trajectoryChanged() const { return _trajectory_changed; }
519 : /**
520 : * Gets the number of trajectory changes this Ray has had
521 : */
522 4138396 : unsigned int trajectoryChanges() const { return _trajectory_changes; }
523 :
524 : /**
525 : * Helper function for getting information about the Ray
526 : */
527 : std::string getInfo() const;
528 :
529 : /**
530 : * Whether or not a Ray has begun tracing
531 : */
532 : bool hasTraced() const
533 : {
534 31231482 : return (bool)_distance || (bool)_processor_crossings || (bool)_intersections;
535 : }
536 :
537 : /**
538 : * Get the RayTracingStudy associated with this Ray
539 : */
540 : const RayTracingStudy & study() const { return _study; }
541 :
542 : private:
543 : /**
544 : * Changes the Ray's ID
545 : */
546 : void changeID(const RayID id) { _id = id; }
547 :
548 : /**
549 : * Invalidates the Ray's current element
550 : */
551 93312 : void invalidateCurrentElem() { _current_elem = nullptr; }
552 :
553 : /**
554 : * Sets the Ray's current point
555 : */
556 34677926 : void setCurrentPoint(const Point & current_point) { _current_point = current_point; }
557 : /**
558 : * Invalidates the Ray's current point
559 : */
560 56241 : void invalidateCurrentPoint() { _current_point = RayTracingCommon::invalid_point; }
561 :
562 : /**
563 : * Sets the Ray's direction
564 : */
565 : void setDirection(const Point & direction) { _direction = direction; }
566 : /**
567 : * Invalidates the Ray's current direction
568 : */
569 56241 : void invalidateDirection() { _direction = RayTracingCommon::invalid_point; }
570 :
571 : /**
572 : * Change a Ray's current elem
573 : */
574 31504165 : void setCurrentElem(const Elem * current_elem) { _current_elem = current_elem; }
575 :
576 : /**
577 : * Change a Ray's incoming side
578 : */
579 : void setCurrentIncomingSide(const unsigned short current_incoming_side)
580 : {
581 34977168 : _current_incoming_side = current_incoming_side;
582 405 : }
583 : /**
584 : * Invalidates the Ray's current incoming side
585 : */
586 93312 : void invalidateCurrentIncomingSide() { _current_incoming_side = RayTracingCommon::invalid_side; }
587 :
588 : /**
589 : * Set whether or not this Ray has had its trajectory changed
590 : */
591 : void setTrajectoryChanged(const bool trajectory_changed)
592 : {
593 4392 : _trajectory_changed = trajectory_changed;
594 : }
595 :
596 : /**
597 : * Increment the Ray's processor crossing counter
598 : */
599 1259326 : void addProcessorCrossing() { ++_processor_crossings; }
600 :
601 : /**
602 : * Increment the Ray's intersection counter
603 : */
604 35292332 : void addIntersection() { ++_intersections; }
605 :
606 : /**
607 : * Increment the Ray's trajectory change counter
608 : */
609 4392 : void addTrajectoryChange() { ++_trajectory_changes; }
610 :
611 : /**
612 : * Adds to the distance this Ray has traveled
613 : */
614 37988072 : void addDistance(const Real add_distance) { _distance += add_distance; }
615 : /**
616 : * Changes the Ray's max distance to be traveled
617 : */
618 : void changeMaxDistance(const Real max_distance) { _max_distance = max_distance; }
619 : /**
620 : * Invalidates the Ray's max distance
621 : */
622 56241 : void invalidateMaxDistance() { _max_distance = std::numeric_limits<Real>::max(); }
623 :
624 : /**
625 : * Produces a useful error if a Ray has started tracing
626 : */
627 : void errorIfTracing(const std::string & reason) const;
628 : /**
629 : * Produces a useful error for use when initializing a Ray
630 : */
631 : void errorWhenInitializing(const std::string & reason) const;
632 :
633 : /**
634 : * Reset all of the internal counters
635 : */
636 : void resetCountersInternal();
637 :
638 : /**
639 : * Helper for the equality operators.
640 : */
641 : bool equalityHelper(const Ray & other, const bool equal) const;
642 :
643 : /**
644 : * Clears the starting information.
645 : */
646 : void clearStartingInfoInternal();
647 :
648 : /// A unique ID for this Ray
649 : RayID _id;
650 :
651 : /**
652 : * Current point of the Ray.
653 : *
654 : * Before tracing, this is the starting point for the Ray.
655 : * During tracing, this is the furthest ahead that a Ray has traced. For example,
656 : * when on a segment in a RayKernel, this will be end of said segment.
657 : * After tracing, this is where the Ray ended.
658 : */
659 : Point _current_point;
660 :
661 : /// Direction of the Ray
662 : Point _direction;
663 :
664 : /**
665 : * Current element that the Ray is in.
666 : *
667 : * Before tracing, this is the starting element for the Ray.
668 : *
669 : * During tracing:
670 : * - It is valid within RayKernels, because a Ray can only operate on a
671 : * single element per segment.
672 : * - When used on boundaries (RayBCs), it is the element that the
673 : * Ray actually traced through. When on a boundary, a RayBC may be
674 : * applied to multiple elements when hitting a vertex or edge.
675 : * Therefore, this will be only one of said elements.
676 : */
677 : const Elem * _current_elem;
678 :
679 : /**
680 : * The side of _current_elem that the Ray is incoming on (if any).
681 : *
682 : * Before tracing, this is the starting incoming side (if any).
683 : *
684 : * During tracing, this is ONLY guaranteed to be valid during
685 : * the execution of RayKernels!
686 : */
687 : unsigned short _current_incoming_side;
688 :
689 : /// Whether or not the user has set an end point for this Ray (via limiting its
690 : /// distance with setStartingEndPoint())
691 : bool _end_set;
692 :
693 : /// Number of times this Ray has been communicated
694 : unsigned int _processor_crossings;
695 :
696 : /// Number of intersections done for this Ray
697 : unsigned int _intersections;
698 :
699 : /// Number of times this Ray has had its trajectory changed
700 : unsigned int _trajectory_changes;
701 : /// Whether or not this Ray had its trajectory changed (not sent in parallel)
702 : bool _trajectory_changed;
703 :
704 : /// Total distance this Ray has traveled
705 : Real _distance;
706 : /// Maximum distance the Ray is allowed to travel
707 : Real _max_distance;
708 :
709 : /// Wether or not the Ray should continue to be traced (not sent in parallel)
710 : bool _should_continue;
711 :
712 : /// The data that is carried with the Ray
713 : /// This is mutable so that we can resize it if needed within const accessors
714 : mutable std::vector<RayData> _data;
715 :
716 : /// Auxiliary data that is carried with the ray
717 : /// This is mutable so that we can resize it if needed within const accessors
718 : mutable std::vector<RayData> _aux_data;
719 :
720 : /// The RayTracingStudy that owns this Ray (not sent in parallel)
721 : RayTracingStudy & _study;
722 :
723 : /// Extra padding to avoid false sharing
724 : long padding[8];
725 :
726 : // TraceRay is the only object that should be executing Rays and therefore needs access
727 : friend class TraceRay;
728 : // Packing needs access to changing the internal counters during the trace
729 : friend class Parallel::Packing<std::shared_ptr<Ray>>;
730 : // Allows for testing of equality methods
731 : friend class TestRayLots;
732 : // Data helpers needs to be able to access the internal methods for a Ray for store/load
733 : friend void dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray, void * context);
734 : friend void dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray, void * context);
735 : };
736 :
737 : bool
738 : Ray::stationary() const
739 : {
740 35541892 : const bool stationary = _max_distance == 0;
741 : if (stationary)
742 : mooseAssert(_intersections == 0, "Should be zero");
743 : return stationary;
744 : }
745 :
746 : /**
747 : * The following methods are specializations for using the Parallel::packed_range_* routines
748 : * for a vector of Rays
749 : */
750 : namespace libMesh
751 : {
752 : namespace Parallel
753 : {
754 : template <>
755 : class Packing<std::shared_ptr<Ray>>
756 : {
757 : public:
758 : typedef Real buffer_type;
759 :
760 : static unsigned int packed_size(typename std::vector<Real>::const_iterator in);
761 : static unsigned int packable_size(const std::shared_ptr<Ray> & ray, const void *);
762 : static unsigned int size(const std::size_t data_size, const std::size_t aux_data_size);
763 :
764 : template <typename Iter, typename Context>
765 : static void pack(const std::shared_ptr<Ray> & object, Iter data_out, const Context * context);
766 :
767 : template <typename BufferIter, typename Context>
768 : static std::shared_ptr<Ray> unpack(BufferIter in, Context * context);
769 : };
770 :
771 : } // namespace Parallel
772 :
773 : } // namespace libMesh
774 :
775 : void dataStore(std::ostream & stream, std::shared_ptr<Ray> & ray, void * context);
776 : void dataLoad(std::istream & stream, std::shared_ptr<Ray> & ray, void * context);
|