https://mooseframework.inl.gov
RayTracingStudyTest.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 "RayTracingStudyTest.h"
11 
12 #include "libmesh/parallel_sync.h"
13 
14 registerMooseObject("RayTracingTestApp", RayTracingStudyTest);
17 
20 {
21  auto params = RayTracingStudy::validParams();
22 
23  params.addParam<bool>("add_duplicate_ray", false, "Add a duplicate Ray to the buffer");
24  params.addParam<bool>(
25  "add_local_non_unique_id_ray", false, "Add two Rays on each processor with the same ID");
26  params.addParam<bool>(
27  "add_global_non_unique_id_ray", false, "Add a Ray on each processor with the same ID");
28 
29  params.addParam<bool>("ray_error_if_tracing", false, "Tests Ray::errorIfTracing()");
30  params.addParam<bool>(
31  "ray_reset_counters", false, "Tests resetting a Ray's counters after it has began tracing");
32 
33  params.addParam<bool>(
34  "register_ray_data_late", false, "Tests registering data late in registerRayDataInternal()");
35  params.addParam<bool>(
36  "register_ray_data_same_name",
37  false,
38  "Tests registering ray data with the same name in registerRayDataInternal()");
39  params.addParam<bool>("ray_data_index_bad_name",
40  false,
41  "Tests requesting ray data index for a name that does not exist in "
42  "getRayDataIndexInternal()");
43  params.addParam<bool>("ray_data_name_bad_index",
44  false,
45  "Tests requesting ray data name for an index that does not exist in "
46  "getRayDataNameInternal()");
47 
48  params.addParam<bool>(
49  "get_ray_kernels_early", false, "Tests getting ray kernels early with getRayKernels()");
50  params.addParam<bool>("get_ray_bcs_early", false, "Tests getting ray bcs early with getRayBCs()");
51 
52  params.addParam<bool>(
53  "get_ray_bank_generating", false, "Tests getting the ray bank when it is not available");
54 
55  params.addParam<bool>("register_ray_no_registration",
56  false,
57  "Tests registering a Ray with Ray registration disabled");
58  params.addParam<bool>("registered_ray_id_no_registration",
59  false,
60  "Tests getting a registered ray id with registration disabled");
61  params.addParam<bool>("registered_ray_name_no_registration",
62  false,
63  "Tests getting a registered ray name with registration disabled");
64 
65  params.addParam<bool>(
66  "reserve_bad", false, "Tests reserving space in the ray buffer outside of registration");
67 
68  params.addParam<bool>("subdomain_hmax_missing",
69  false,
70  "Tests requesting the subdomain hmax for an invalid subdomain");
71 
72  params.addParam<bool>(
73  "get_elem_normals_unimplemented", false, "Tests getElemNormals not being overridden");
74 
75  params.addParam<bool>("elem_extrema_build_edge",
76  false,
77  "Tests building an edge from extrema when the vertices are incorrect");
78 
79  params.addParam<bool>("ray_data_index_other_exists",
80  false,
81  "Tests getting a Ray data index when aux data with the same name exists");
82  params.addParam<bool>("ray_data_aux_index_other_exists",
83  false,
84  "Tests getting a Ray aux data index when data with the same name exists");
85 
86  params.set<bool>("_use_ray_registration") = false;
87 
88  return params;
89 }
90 
92  : RayTracingStudy(parameters)
93 {
94  if (getParam<bool>("register_ray_data_same_name"))
95  {
96  registerRayData("foo");
97  registerRayAuxData("foo");
98  }
99  if (getParam<bool>("ray_data_index_bad_name"))
100  getRayDataIndex("foo");
101  if (getParam<bool>("ray_data_name_bad_index"))
102  getRayDataName(123);
103  if (getParam<bool>("get_ray_kernels_early"))
104  {
105  std::vector<RayKernelBase *> rks;
106  getRayKernels(rks, 0, 0);
107  }
108  if (getParam<bool>("get_ray_bcs_early"))
109  {
110  std::vector<RayBoundaryConditionBase *> rbcs;
111  getRayBCs(rbcs, 0, 0);
112  }
113  if (getParam<bool>("registered_ray_id_no_registration"))
114  registeredRayID("foo");
115  if (getParam<bool>("registered_ray_name_no_registration"))
117  if (getParam<bool>("reserve_bad"))
118  reserveRayBuffer(0);
119  if (getParam<bool>("get_elem_normals_unimplemented"))
120  getElemNormals(meshBase().elem_ptr(0), 0);
121  if (getParam<bool>("elem_extrema_build_edge"))
122  {
123  ElemExtrema extrema(1337, 1338);
124  extrema.buildEdge(meshBase().elem_ptr(0));
125  }
126  if (getParam<bool>("ray_data_index_other_exists"))
127  {
128  registerRayAuxData("foo");
129  getRayDataIndex("foo");
130  }
131  if (getParam<bool>("ray_data_aux_index_other_exists"))
132  {
133  registerRayData("foo");
134  getRayAuxDataIndex("foo");
135  }
136 }
137 
138 void
140 {
141  if (_mesh.getMesh().n_local_elem() != 0)
142  {
143  const Elem * elem = *_mesh.getActiveLocalElementRange()->begin();
144 
145  auto ray = acquireRay();
146 
147  ray->setStart(elem->vertex_average(), elem);
148  ray->setStartingEndPoint(elem->point(0));
149 
150  if (getParam<bool>("add_duplicate_ray"))
151  {
152  std::shared_ptr<Ray> duplicate_ray = ray;
153  moveRayToBuffer(ray);
154  moveRayToBuffer(duplicate_ray);
155  }
156 
157  if (getParam<bool>("add_local_non_unique_id_ray"))
158  {
159  std::shared_ptr<Ray> other_ray = acquireCopiedRay(*ray);
160  moveRayToBuffer(ray);
161  moveRayToBuffer(other_ray);
162  }
163 
164  if (getParam<bool>("add_global_non_unique_id_ray"))
165  {
166  mooseAssert(n_processors() > 1, "Needs multiple ranks");
167 
168  std::map<processor_id_type, std::vector<std::shared_ptr<Ray>>> send_map;
169  if (_pid == 0)
170  {
171  for (processor_id_type pid = 1; pid < n_processors(); ++pid)
172  send_map[pid].push_back(ray);
173  moveRayToBuffer(ray);
174  }
175 
176  auto add_ray_functor = [&](processor_id_type, const std::vector<std::shared_ptr<Ray>> & rays)
177  {
178  std::shared_ptr<Ray> ray = rays[0];
179  ray->clearStartingInfo();
180  ray->setStart(elem->vertex_average());
181  ray->setStartingEndPoint(elem->point(0));
182  moveRayToBuffer(ray);
183  };
184 
185  Parallel::push_parallel_packed_range(comm(), send_map, parallelStudy(), add_ray_functor);
186  }
187 
188  if (getParam<bool>("ray_error_if_tracing") || getParam<bool>("ray_reset_counters"))
189  moveRayToBuffer(ray);
190  }
191 
192  if (getParam<bool>("register_ray_data_late"))
193  registerRayData("foo");
194 
195  if (getParam<bool>("get_ray_bank_generating"))
196  rayBank();
197 
198  if (getParam<bool>("register_ray_no_registration"))
199  acquireRegisteredRay("foo");
200 
201  if (getParam<bool>("subdomain_hmax_missing"))
202  subdomainHmax(1337);
203 }
204 
205 void
207 {
208  if (getParam<bool>("ray_error_if_tracing"))
209  for (auto & ray : rayBank())
210  ray->clearStartingInfo();
211 
212  if (getParam<bool>("ray_reset_counters"))
213  for (auto & ray : rayBank())
214  ray->resetCounters();
215 }
216 
218  : RayTracingStudy(params)
219 {
220  rayBank();
221 }
222 
225 {
226  auto params = RayTracingStudy::validParams();
227  params.set<bool>("_bank_rays_on_completion") = false;
228  return params;
229 }
230 
233 {
234  auto params = RayTracingStudy::validParams();
235 
236  params.addParam<bool>(
237  "registered_ray_id_missing", false, "Tests registeredRayID() with an invalid id");
238  params.addParam<bool>(
239  "registered_ray_name_missing", false, "Tests registeredRayName() with an invalid name");
240 
241  return params;
242 }
243 
245  const InputParameters & params)
246  : RayTracingStudy(params)
247 {
248  if (getParam<bool>("registered_ray_id_missing"))
249  registeredRayID("foo");
250  if (getParam<bool>("registered_ray_name_missing"))
252 }
ParallelStudy< std::shared_ptr< Ray >, Ray > * parallelStudy()
The underlying parallel study: used for the context for calling the packed range routines.
void getRayKernels(std::vector< RayKernelBase *> &result, SubdomainID id, THREAD_ID tid)
Fills the active RayKernels associated with this study and a block into result.
RayDataIndex registerRayData(const std::string &name)
Register a value to be filled in the data on a Ray with a given name.
libMesh::ConstElemRange * getActiveLocalElementRange()
const std::vector< std::shared_ptr< Ray > > & rayBank() const
Get the Ray bank.
RayTracingStudyWithRegistrationTest(const InputParameters &parameters)
RayDataIndex registerRayAuxData(const std::string &name)
Register a value to be filled in the aux data on a Ray with a given name.
MooseMesh & _mesh
The Mesh.
std::shared_ptr< Ray > acquireRay()
User APIs for constructing Rays within the RayTracingStudy.
void generateRays() override
Subclasses should override this to determine how to generate Rays.
Helper for defining if at an element&#39;s edge, vertex, or neither.
Definition: ElemExtrema.h:25
const Parallel::Communicator & comm() const
std::unique_ptr< const libMesh::Elem > buildEdge(const Elem *elem) const
Definition: ElemExtrema.C:22
void postExecuteStudy() override
Entry point after study execution.
std::shared_ptr< Ray > acquireRegisteredRay(const std::string &name)
Acquires a Ray with a given name within generateRays().
RayTracingStudyNoBankingTest(const InputParameters &parameters)
RayDataIndex getRayAuxDataIndex(const std::string &name, const bool graceful=false) const
Gets the index associated with a registered value in the Ray aux data.
Real subdomainHmax(const SubdomainID subdomain_id) const
Get the cached hmax for all elements in a subdomain.
static InputParameters validParams()
uint8_t processor_id_type
processor_id_type n_processors() const
RayTracingStudyTest(const InputParameters &parameters)
MeshBase & getMesh()
const std::string & getRayDataName(const RayDataIndex index) const
Gets the name associated with a registered value in the Ray data.
void reserveRayBuffer(const std::size_t size)
Reserve size entires in the Ray buffer.
static InputParameters validParams()
static InputParameters validParams()
virtual const Point * getElemNormals(const Elem *, const THREAD_ID)
Gets the outward normals for a given element.
void getRayBCs(std::vector< RayBoundaryConditionBase *> &result, BoundaryID id, THREAD_ID tid)
Fills the active RayBCs associated with this study and a boundary into result.
const_iterator begin() const
MeshBase & meshBase() const
Access to the libMesh MeshBase.
const processor_id_type _pid
The rank of this processor (this actually takes time to lookup - so just do it once) ...
const std::string & registeredRayName(const RayID ray_id) const
Gets the name of a registered ray.
void moveRayToBuffer(std::shared_ptr< Ray > &ray)
Moves a ray to the buffer to be traced during generateRays().
RayID registeredRayID(const std::string &name, const bool graceful=false) const
Gets the ID of a registered ray.
registerMooseObject("RayTracingTestApp", RayTracingStudyTest)
RayDataIndex getRayDataIndex(const std::string &name, const bool graceful=false) const
Gets the index associated with a registered value in the Ray data.
std::shared_ptr< Ray > acquireCopiedRay(const Ray &ray)
Acquires a Ray that that is copied from another Ray within generateRays().
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...