https://mooseframework.inl.gov
TestRayDataStudy.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 "TestRayDataStudy.h"
11 
12 registerMooseObject("RayTracingTestApp", TestRayDataStudy);
13 
16 {
17  auto params = LotsOfRaysRayStudy::validParams();
18  params.addRequiredParam<unsigned int>("data_size", "Size for the test Ray data");
19  params.addRequiredParam<unsigned int>("aux_data_size", "Size for the test aux Ray data");
20  return params;
21 }
22 
24  : LotsOfRaysRayStudy(parameters),
25  _data_size(getParam<unsigned int>("data_size")),
26  _aux_data_size(getParam<unsigned int>("aux_data_size"))
27 {
28  _data_indices.resize(_data_size);
29  for (unsigned int i = 0; i < _data_size; ++i)
30  _data_indices[i] = registerRayData("test_data_" + std::to_string(i));
31 
33  for (unsigned int i = 0; i < _aux_data_size; ++i)
34  _aux_data_indices[i] = registerRayAuxData("test_aux_data_" + std::to_string(i));
35 
36  _actual_start_indices.resize(3);
37  for (unsigned int i = 0; i < 3; ++i)
38  _actual_start_indices[i] = registerRayAuxData("actual_start_" + std::to_string(i));
39 }
40 
41 RayData
42 TestRayDataStudy::dataValue(const unsigned int i, const Ray & ray) const
43 {
44  Point actual_start;
45  actual_start(0) = ray.auxData(_actual_start_indices[0]);
46  actual_start(1) = ray.auxData(_actual_start_indices[1]);
47  actual_start(2) = ray.auxData(_actual_start_indices[2]);
48 
49  const Point bounding_box_centroid = 0.5 * (boundingBox().min() + boundingBox().max());
50  const RayData data_start =
51  (actual_start - bounding_box_centroid).norm() * (RayData)(i + 1) / (RayData)_data_size;
52 
53  return data_start + dataValueChange(i, ray.distance());
54 }
55 
56 RayData
57 TestRayDataStudy::dataValueChange(const unsigned int i, const Real distance) const
58 {
59  return 0.3 * (RayData)(i + 1) * (RayData)_data_size * distance;
60 }
61 
62 RayData
63 TestRayDataStudy::auxDataValue(const unsigned int i, const Ray & ray) const
64 {
65  Point actual_start;
66  actual_start(0) = ray.auxData(_actual_start_indices[0]);
67  actual_start(1) = ray.auxData(_actual_start_indices[1]);
68  actual_start(2) = ray.auxData(_actual_start_indices[2]);
69 
70  return (actual_start - boundingBox().min()).norm() * (RayData)(i + 1) * (RayData)_data_size;
71 }
72 
73 void
75 {
76  for (const std::shared_ptr<Ray> & ray : _rays)
77  {
78  for (unsigned int i = 0; i < 3; ++i)
79  ray->auxData(_actual_start_indices[i]) = ray->currentPoint()(i);
80 
81  for (unsigned int i = 0; i < _data_size; ++i)
82  ray->data(_data_indices[i]) = dataValue(i, *ray);
83 
84  for (unsigned int i = 0; i < _aux_data_size; ++i)
85  ray->auxData(_aux_data_indices[i]) = auxDataValue(i, *ray);
86  }
87 }
88 
89 void
90 TestRayDataStudy::onCompleteRay(const std::shared_ptr<Ray> & ray)
91 {
93 
94  const Ray & const_ray = *ray;
95 
96  for (unsigned int i = 0; i < _data_size; ++i)
97  if (!MooseUtils::absoluteFuzzyEqual(const_ray.data(_data_indices[i]), dataValue(i, const_ray)))
98  mooseError(_name, ": Incorrect expected data");
99 
100  for (unsigned int i = 0; i < _aux_data_size; ++i)
102  auxDataValue(i, const_ray)))
103  mooseError(_name, ": Incorrect expected aux data");
104 }
RayDataIndex registerRayData(const std::string &name)
Register a value to be filled in the data on a Ray with a given name.
virtual void onCompleteRay(const std::shared_ptr< Ray > &ray)
Entry point for acting on a ray when it is completed (shouldContinue() == false)
std::vector< RayData > & data()
Gets a writeable reference to the Ray&#39;s data.
Definition: Ray.C:403
TestRayDataStudy(const InputParameters &parameters)
virtual void modifyRays() override
Insertion point for after _rays is defined for other derived test studies to modify the Rays...
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
RayData dataValueChange(const unsigned int i, const Real distance) const
RayDataIndex registerRayAuxData(const std::string &name)
Register a value to be filled in the aux data on a Ray with a given name.
const std::size_t _aux_data_size
std::vector< RayDataIndex > _actual_start_indices
std::vector< RayData > & auxData()
Gets a writeable reference to the Ray&#39;s auxilary data.
Definition: Ray.C:437
registerMooseObject("RayTracingTestApp", TestRayDataStudy)
static InputParameters validParams()
Real distance(const Point &p)
Test Ray study that generates a lot of Rays and sets data/aux data with a predictable pattern in conj...
const BoundingBox & boundingBox() const
Get the nodal bounding box for the domain.
virtual void onCompleteRay(const std::shared_ptr< Ray > &ray) override
Entry point for acting on a ray when it is completed (shouldContinue() == false)
std::vector< RayDataIndex > _data_indices
Basic datastructure for a ray that will traverse the mesh.
Definition: Ray.h:56
auto norm(const T &a) -> decltype(std::abs(a))
const std::string _name
static InputParameters validParams()
Real distance() const
Gets the distance this Ray has traveled.
Definition: Ray.h:488
RayData auxDataValue(const unsigned int i, const Ray &ray) const
void mooseError(Args &&... args) const
std::vector< std::shared_ptr< Ray > > & _rays
Vector of Rays that the user will fill into in defineRays() (restartable)
const std::size_t _data_size
float RayData
Type for a Ray&#39;s data.
Definition: Ray.h:46
A RayTracingStudy used for generating a lot of rays for testing purposes.
auto min(const L &left, const R &right)
RayData dataValue(const unsigned int i, const Ray &ray) const
void ErrorVector unsigned int
std::vector< RayDataIndex > _aux_data_indices