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