https://mooseframework.inl.gov
TestRayLots.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 "TestRayLots.h"
11 
12 registerMooseObject("RayTracingTestApp", TestRayLots);
13 
16 {
17  auto params = LotsOfRaysRayStudy::validParams();
18 
19  params.addParam<bool>("get_info", false, "Tests Ray::getInfo()");
20  params.addParam<bool>("equality", false, "Tests the equality and inequality operators for Ray");
21 
22  return params;
23 }
24 
26 {
27  registerRayData("data");
28  registerRayAuxData("aux_data");
29 }
30 
31 void
33 {
34  if (getParam<bool>("get_info"))
35  for (const auto & ray : rayBank())
36  libMesh::err << ray->getInfo() << std::endl;
37 
38  if (getParam<bool>("equality"))
39  {
40  std::size_t same_passes = 0, duplicate_passes = 0;
41 
42  std::vector<UserObject *> uos;
43  _fe_problem.theWarehouse().query().condition<AttribSystem>("UserObject").queryInto(uos);
44  RayTracingStudy * other_study = nullptr;
45  for (auto & uo : uos)
46  if (auto study = dynamic_cast<RayTracingStudy *>(uo))
47  if (study != this)
48  {
49  other_study = study;
50  break;
51  }
52  mooseAssert(other_study, "Failed to find other study");
53 
54  for (const auto & ray : rayBank())
55  {
56  std::vector<std::shared_ptr<Ray>> duplicate_rays;
57 
58  auto duplicate_ray = [&ray, &duplicate_rays](RayTracingStudy * study = nullptr)
59  {
60  auto duplicate = std::make_shared<Ray>(study != nullptr ? study : &ray->_study,
61  ray->id(),
62  ray->data().size(),
63  ray->auxData().size(),
64  false,
66  duplicate->_current_point = ray->_current_point;
67  duplicate->_direction = ray->_direction;
68  duplicate->_current_elem = ray->_current_elem;
69  duplicate->_current_incoming_side = ray->_current_incoming_side;
70  duplicate->_end_set = ray->_end_set;
71  duplicate->_processor_crossings = ray->_processor_crossings;
72  duplicate->_intersections = ray->_intersections;
73  duplicate->_trajectory_changes = ray->_trajectory_changes;
74  duplicate->_trajectory_changed = ray->_trajectory_changed;
75  duplicate->_distance = ray->_distance;
76  duplicate->_max_distance = ray->_max_distance;
77  duplicate->_should_continue = ray->_should_continue;
78  duplicate->_data = ray->_data;
79  duplicate->_aux_data = ray->_aux_data;
80 
81  duplicate_rays.push_back(duplicate);
82 
83  return duplicate;
84  };
85 
86  if (*ray != *ray || !(*ray == *ray))
87  mooseError("Same ray equality failed");
88  else
89  ++same_passes;
90 
91  ++duplicate_ray()->_id;
92  duplicate_ray()->_current_point = RayTracingCommon::invalid_point;
93  duplicate_ray()->_direction = RayTracingCommon::invalid_point;
94  bool found_other_elem = false;
95  for (const auto & elem : meshBase().active_local_element_ptr_range())
96  if (elem != ray->currentElem())
97  {
98  found_other_elem = true;
99  duplicate_ray()->_current_elem = elem;
100  break;
101  }
102  if (!found_other_elem) // might not have another elem with high proc counts
103  ++duplicate_passes;
104  if (ray->invalidCurrentIncomingSide())
105  duplicate_ray()->_current_incoming_side = 0;
106  else
107  ++duplicate_ray()->_current_incoming_side;
108  duplicate_ray()->_end_set = !ray->_end_set;
109  ++duplicate_ray()->_processor_crossings;
110  ++duplicate_ray()->_intersections;
111  ++duplicate_ray()->_trajectory_changes;
112  duplicate_ray()->_trajectory_changed = !ray->_trajectory_changed;
113  duplicate_ray()->_distance += 1;
114  duplicate_ray()->_max_distance = 0;
115  duplicate_ray()->_should_continue = !ray->_should_continue;
116  duplicate_ray()->_data.resize(ray->_data.size() + 1);
117  duplicate_ray()->_data[0] += 1;
118  duplicate_ray()->_aux_data.resize(ray->_aux_data.size() + 1);
119  duplicate_ray()->_aux_data[0] += 1;
120  duplicate_ray(other_study);
121 
122  for (const auto & duplicate : duplicate_rays)
123  {
124  const auto equal = *duplicate == *ray;
125  if (equal)
126  mooseError("Unequal rays are equal");
127 
128  const auto inequal = *duplicate != *ray;
129  if (!inequal)
130  mooseError("Unequal rays are not unequal");
131 
132  if (equal != !inequal)
133  mooseError("Ray Equality != !inequality");
134 
135  ++duplicate_passes;
136  }
137  }
138 
139  comm().sum(same_passes);
140  comm().sum(duplicate_passes);
141  if (processor_id() == 0)
142  _console << "Ray equality test: same_passes = " << same_passes
143  << ", duplicate_passes = " << duplicate_passes << std::endl;
144  }
145 }
RayDataIndex registerRayData(const std::string &name)
Register a value to be filled in the data on a Ray with a given name.
const std::vector< std::shared_ptr< Ray > > & rayBank() const
Get the Ray bank.
RayDataIndex registerRayAuxData(const std::string &name)
Register a value to be filled in the aux data on a Ray with a given name.
Class that is used as a parameter to the public constructors/reset methods.
Definition: Ray.h:87
TestRayLots(const InputParameters &parameters)
Definition: TestRayLots.C:25
const Parallel::Communicator & comm() const
static InputParameters validParams()
TheWarehouse & theWarehouse() const
void postExecuteStudy() override final
Entry point after study execution.
Definition: TestRayLots.C:32
OStreamProxy err(std::cerr)
static InputParameters validParams()
Definition: TestRayLots.C:15
registerMooseObject("RayTracingTestApp", TestRayLots)
FEProblemBase & _fe_problem
Query query()
void mooseError(Args &&... args) const
MeshBase & meshBase() const
Access to the libMesh MeshBase.
static const libMesh::Point invalid_point(invalid_distance, invalid_distance, invalid_distance)
Identifier for an invalid point.
const ConsoleStream _console
A RayTracingStudy used for generating a lot of rays for testing purposes.
processor_id_type processor_id() const
Base class for Ray tracing studies that will generate Rays and then propagate all of them to terminat...