13#include "libmesh/parallel_sync.h"
24 params.addPrivateParam<
bool>(
"_define_rays_replicated",
true);
26 params.addPrivateParam<
bool>(
"_claim_after_define_rays",
true);
33 _rays(declareRestartableDataWithContext<
std::vector<
std::shared_ptr<
Ray>>>(
"rays", this)),
34 _define_rays_replicated(getParam<bool>(
"_claim_after_define_rays")
35 ? getParam<bool>(
"_define_rays_replicated")
37 _claim_after_define_rays(getParam<bool>(
"_claim_after_define_rays")),
38 _should_define_rays(declareRestartableData<bool>(
"should_define_rays", true)),
40 declareRestartableDataWithContext<
std::vector<
std::shared_ptr<
Ray>>>(
"local_rays", this)),
44 !_define_rays_replicated),
46 declareRestartableData<bool>(
"claim_after_define_rays", _claim_after_define_rays))
50 "\n '_define_rays_replicated' == true",
51 "\n '_claim_after_define_rays' == false",
52 "\nis not a valid combination.",
53 "\n\n_define_rays_replicated is being set to false.");
125 for (
const auto & ray :
_rays)
127 ray->invalidateStartingElem();
128 ray->invalidateStartingIncomingSide();
132 ray->invalidateStartingElem();
133 ray->invalidateStartingIncomingSide();
140 TIME_SECTION(
"claimRaysInternal", 2,
"Claiming Rays");
149 TIME_SECTION(
"defineRaysInternal", 2,
"Defining Rays");
158 auto num_rays =
_rays.size();
161 mooseError(
"No Rays were moved to _rays in defineRays()");
162 for (
const auto & ray :
_rays)
164 mooseError(
"A nullptr Ray was found in _rays after defineRays().");
173 for (
const std::shared_ptr<Ray> & ray :
_rays)
182 for (
const std::shared_ptr<Ray> & ray :
_rays)
183 if (ray->currentElem() || !ray->invalidCurrentIncomingSide())
185 "A Ray was found in _rays after defineRays() that has a starting element or "
186 "incoming side set.\n\n",
187 "With the mode in which the private param '_claim_after_define_rays' == true,",
188 "\nthe defined Rays at this point should not have their starting elem/side set.\n",
189 "\nTheir starting information will be set internally using a claiming process.\n\n",
201 TIME_SECTION(
"verifyReplicatedRays", 2,
"Verifying Replicated Rays");
203 const std::string error_suffix =
204 "\n\nThe Rays added in defineRays() must be replicated across all processors\nwith the "
205 "private param '_define_rays_replicated' == true.";
211 "in _rays after calling defineRays()." + error_suffix);
219 std::vector<Parallel::Request> requests(
n_processors() - 1);
220 auto request_it = requests.begin();
222 for (processor_id_type pid = 0; pid <
n_processors(); ++pid)
227 Parallel::wait(requests);
233 std::unordered_map<RayID, const Ray *> ray_map;
234 ray_map.reserve(
_rays.size());
235 for (
const auto & ray :
_rays)
236 ray_map.emplace(ray->id(), ray.get());
239 std::vector<std::shared_ptr<Ray>> rank_0_rays;
240 rank_0_rays.reserve(
_rays.size());
242 0,
parallelStudy(), std::back_inserter(rank_0_rays), (std::shared_ptr<Ray> *)
nullptr, tag);
245 if (rank_0_rays.size() !=
_rays.size())
248 " does not match the size of rays on rank 0.",
252 for (
const auto & ray : rank_0_rays)
254 const auto find = ray_map.find(ray->id());
255 if (find == ray_map.end())
258 " with an ID that does not exist on rank 0.",
263 const Ray * root_ray = find->second;
264 if (*root_ray != *ray)
268 " that does not exist on rank 0.",
270 "\n\nLocal ray:\n\n",
272 "\n\nRank 0 ray:\n\n",
void claim()
Claim the Rays.
void mooseError(Args &&... args) const
void mooseWarning(Args &&... args) const
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...
std::shared_ptr< Ray > acquireCopiedRay(const Ray &ray)
Acquires a Ray that that is copied from another Ray within generateRays().
static InputParameters validParams()
void moveRayToBuffer(std::shared_ptr< Ray > &ray)
Moves a ray to the buffer to be traced during generateRays().
void reserveRayBuffer(const std::size_t size)
Reserve size entires in the Ray buffer.
void verifyUniqueRayIDs(const std::vector< std::shared_ptr< Ray > >::const_iterator begin, const std::vector< std::shared_ptr< Ray > >::const_iterator end, const bool global, const std::string &error_suffix) const
Verifies that the Rays in the given range have unique Ray IDs.
bool verifyRays() const
Whether or not to verify if Rays have valid information before being traced.
virtual void meshChanged() override
ParallelStudy< std::shared_ptr< Ray >, Ray > * parallelStudy()
The underlying parallel study: used for the context for calling the packed range routines.
const processor_id_type _pid
The rank of this processor (this actually takes time to lookup - so just do it once)
Basic datastructure for a ray that will traverse the mesh.
std::string getInfo() const
Helper function for getting information about the Ray.
RepeatableRayStudyBase(const InputParameters ¶meters)
ClaimRays _claim_rays
The object used to claim Rays.
std::vector< std::shared_ptr< Ray > > & _rays
Vector of Rays that the user will fill into in defineRays() (restartable)
void verifyReplicatedRays()
Verifies that the Rays in _rays are replicated across processors.
const bool _claim_after_define_rays
Whether or not Rays need to be claimed after defineRays()
virtual void generateRays() override
Subclasses should override this to determine how to generate Rays.
std::vector< std::shared_ptr< Ray > > & _local_rays
Storage for all of the Rays this processor is responsible for (restartable)
void defineRaysInternal()
bool & _should_define_rays
Whether or not we should call defineRays() on the next generateRays() Can be set to true in derived c...
bool & _should_claim_rays
Whether or not we should call claimRays() on the next generateRays() (restartable)
const bool _define_rays_replicated
Whether or not the Rays filled into _rays are replicated across all processors.
static InputParameters validParams()
virtual void meshChanged() override
virtual void defineRays()=0
Entry point for the user to create Rays.
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
void receive_packed_range(const unsigned int dest_processor_id, Context *context, OutputIter out, const T *output_type, const MessageTag &tag=any_tag) const
void send_packed_range(const unsigned int dest_processor_id, const Context *context, Iter range_begin, const Iter range_end, const MessageTag &tag=no_tag, std::size_t approx_buffer_size=1000000) const
const Parallel::Communicator & _communicator
const Parallel::Communicator & comm() const
processor_id_type n_processors() const