Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
ParallelRayStudy.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 "ParallelRayStudy.h"
11 
12 // Local includes
13 #include "TraceRay.h"
14 #include "RayTracingStudy.h"
15 
17  RayTracingStudy & ray_tracing_study,
18  const std::vector<std::shared_ptr<TraceRay>> & threaded_trace_ray)
19  : ParallelStudy<std::shared_ptr<Ray>, Ray>(
20  ray_tracing_study.comm(), ray_tracing_study.parameters(), "ParallelRayStudy"),
21  _ray_tracing_study(ray_tracing_study),
22  _threaded_trace_ray(threaded_trace_ray)
23 {
24 }
25 
26 void
28 {
29  for (auto it = begin; it != end; ++it)
30  {
31  std::shared_ptr<Ray> & ray = *it;
32 
33  // The Ray is done tracing
34  if (!ray->shouldContinue())
35  {
37  continue;
38  }
39 
40  // Going to another processor
41  mooseAssert(ray->currentElem()->processor_id() != _pid,
42  "Continuing Ray not going to another processor");
43  moveParallelDataToBuffer(ray, ray->currentElem()->processor_id());
44  }
45 }
46 
47 bool
48 ParallelRayStudy::workIsComplete(const std::shared_ptr<Ray> & ray)
49 {
50  // "Work" (a Ray) is considered complete in the parallel algorithm when it is done tracing
51  return !ray->shouldContinue();
52 }
53 
54 void
56  const parallel_data_iterator end)
57 {
58  // Move all of the parallel data (Rays that are continuing to be traced on this processor)
59  // directly into the work buffer
60  moveContinuingWorkToBuffer(begin, end);
61 }
62 
63 void
64 ParallelRayStudy::executeWork(const std::shared_ptr<Ray> & ray, const THREAD_ID tid)
65 {
66  mooseAssert(ray->shouldContinue(), "Tracing Ray that should not continue");
67 
68  // If this is false, it means we have a Ray that is banked to go onto another processor
69  if (ray->currentElem()->processor_id() == _pid)
70  _threaded_trace_ray[tid]->trace(ray);
71 }
72 
73 void
74 ParallelRayStudy::moveWorkError(const MoveWorkError error, const std::shared_ptr<Ray> * ray) const
75 {
76  std::stringstream oss;
77  oss << "In method " << _ray_tracing_study.type() << "::addRay(s)ToBuffer:\n";
78 
79  if (error == MoveWorkError::DURING_EXECUTION_DISABLED)
80  {
81  oss << "Rays are being added to the buffer during propagation.\n\n";
82  oss << "This capability must be enabled by setting the parameter\n";
83  oss << "'allow_new_work_during_execution' to true.";
84  }
85  else if (error == MoveWorkError::PRE_EXECUTION_AND_EXECUTION_ONLY)
86  oss << "Rays can only be added to the buffer during generateRays() and tracing.";
87  else if (error == MoveWorkError::PRE_EXECUTION_ONLY)
88  oss << "Rays can only be added to the buffer during generateRays().";
89  else if (error == MoveWorkError::PRE_EXECUTION_THREAD_0_ONLY)
90  oss << "Rays can only be added on thread 0 during generateRays() (not thread safe)";
91  else if (error == CONTINUING_DURING_EXECUTING_WORK)
93 
94  if (ray)
95  oss << "\n\n" << (*ray)->getInfo();
96 
97  mooseError(oss.str());
98 }
virtual void onCompleteRay(const std::shared_ptr< Ray > &ray)
Entry point for acting on a ray when it is completed (shouldContinue() == false)
void mooseError(Args &&... args)
const std::vector< std::shared_ptr< TraceRay > > & _threaded_trace_ray
The TraceRay objects that do the tracing for each thread.
const processor_id_type _pid
This rank.
void moveParallelDataToBuffer(std::shared_ptr< Ray > &data, const processor_id_type dest_pid)
Moves parallel data objects to the send buffer to be communicated to processor dest_pid.
bool workIsComplete(const std::shared_ptr< Ray > &ray) override
Can be overridden to denote if a piece of work is not complete yet.
void moveContinuingWorkToBuffer(std::shared_ptr< Ray > &Work)
Moves work that is considered continuing for the purposes of the execution algorithm into the buffer...
MoveWorkError
Enum for providing useful errors during work addition in moveWorkError().
void moveWorkError(const MoveWorkError error, const std::shared_ptr< Ray > *ray) const override
const std::string & type() const
Basic datastructure for a ray that will traverse the mesh.
Definition: Ray.h:56
RayTracingStudy & _ray_tracing_study
The RayTracingStudy.
ParallelRayStudy(RayTracingStudy &study, const std::vector< std::shared_ptr< TraceRay >> &threaded_trace_ray)
MooseUtils::Buffer< std::shared_ptr< Ray > >::iterator work_iterator
Definition: ParallelStudy.h:32
MooseUtils::Buffer< std::shared_ptr< Ray > >::iterator parallel_data_iterator
Definition: ParallelStudy.h:34
void executeWork(const std::shared_ptr< Ray > &ray, const THREAD_ID tid) override
Pure virtual to be overridden that executes a single object of work on a given thread.
void postReceiveParallelData(const parallel_data_iterator begin, const parallel_data_iterator end) override
void postExecuteChunk(const work_iterator begin, const work_iterator end) override
unsigned int THREAD_ID
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...