https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RepeatableRayStudy.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 "RepeatableRayStudy.h"
11
13
16{
18
19 params.addClassDescription("A ray tracing study that generates rays from vector of user-input "
20 "start points and end points/directions.");
21
22 params.addRequiredParam<std::vector<std::string>>("names", "Unique names for the Rays");
23
24 params.addRequiredParam<std::vector<Point>>("start_points", "The points to start Rays from");
25 params.addParam<std::vector<Point>>("directions",
26 "The directions to spawn Rays in (they do not need to be "
27 "normalized to 1). Use either this parameter "
28 "or the end_points parameter, but not both!");
29 params.addParam<std::vector<Point>>("end_points",
30 "The points where Rays should end. Use either this parameter "
31 "or the directions parameter, but not both!");
32 params.addParam<std::vector<Real>>(
33 "max_distances",
34 "The maximum distances that each Ray can travel before it is killed internally after "
35 "RayKernel execution. This can ONLY be used when the 'directions' parameter is used. "
36 "When this is not set, the Rays must be killed by RayKernels, RayBCs, or the global "
37 " max distance parameter, 'ray_max_distance' (applies to all Rays)");
38
39 params.addParamNamesToGroup("start_points directions end_points max_distances", "Trajectory");
40
41 params.addParam<std::vector<std::string>>(
42 "ray_data_names",
43 "The Ray data names to register. If 'initial_ray_data' is set, these data names will be "
44 "associated with said initial values. Otherwise, they will be set to zero.");
45 params.addParam<std::vector<std::vector<Real>>>(
46 "initial_ray_data",
47 "The initial Ray data to set for each Ray. You must have size(ray_data_names) entries for "
48 "each Ray defined by 'names'. The data for each Ray should be separated by ';'.");
49 params.addParam<std::vector<std::string>>(
50 "ray_aux_data_names",
51 "The Ray aux data names to register. If 'initial_ray_aux_data' is set, these aux data names "
52 "will be associated with said initial values. Otherwise, they will be set to zero.");
53 params.addParam<std::vector<std::vector<Real>>>(
54 "initial_ray_aux_data",
55 "The initial Ray aux data to set for each Ray. You must have size(ray_aux_data_names) "
56 "entries "
57 "for each Ray defined by 'names'. The data for each Ray should be separated by ';'.");
58
59 params.addParamNamesToGroup(
60 "ray_data_names initial_ray_data ray_aux_data_names initial_ray_aux_data", "Ray Data");
61
62 return params;
63}
64
66 : RepeatableRayStudyBase(parameters),
67 _names(getParam<std::vector<std::string>>("names")),
68 _start_points(getParam<std::vector<Point>>("start_points")),
69 _end_points(isParamValid("end_points") ? &getParam<std::vector<Point>>("end_points") : nullptr),
70 _directions(isParamValid("directions") ? &getParam<std::vector<Point>>("directions") : nullptr),
71 _max_distances(isParamValid("max_distances") ? &getParam<std::vector<Real>>("max_distances")
72 : nullptr),
73 _ray_data_indices(isParamValid("ray_data_names")
74 ? registerRayData(getParam<std::vector<std::string>>("ray_data_names"))
75 : std::vector<RayDataIndex>()),
76 _initial_ray_data(isParamValid("initial_ray_data")
77 ? &getParam<std::vector<std::vector<Real>>>("initial_ray_data")
78 : nullptr),
79 _ray_aux_data_indices(
80 isParamValid("ray_aux_data_names")
81 ? registerRayAuxData(getParam<std::vector<std::string>>("ray_aux_data_names"))
82 : std::vector<RayDataIndex>()),
83 _initial_ray_aux_data(isParamValid("initial_ray_aux_data")
84 ? &getParam<std::vector<std::vector<Real>>>("initial_ray_aux_data")
85 : nullptr)
86{
88 paramError("directions", "Can only use 'directions' or 'end_points', but not both");
89 if (!_end_points && !_directions)
90 mooseError("Must set 'end_points' or 'directions'");
91 if (_start_points.size() != _names.size())
92 paramError("start_points", "Not the same size as names");
93 if (_directions && _names.size() != _directions->size())
94 paramError("directions", "Not the same size as names");
96 {
97 if (!_directions)
98 paramError("max_distances",
99 "Can only be used when trajectories are set with the 'directions' parameter");
100 if (_max_distances->size() != _start_points.size())
101 paramError("max_distances", "Must be the same size as 'start_points'");
102 for (const auto val : *_max_distances)
103 if (val <= 0)
104 paramError("max_distances", "Values must be positive");
105 }
106 if (_end_points && _names.size() != _end_points->size())
107 paramError("end_points", "Not the same size as names");
108
109 // Check ray data and aux data
110 const auto check_data = [this](const bool aux)
111 {
112 const auto initial_data = aux ? _initial_ray_aux_data : _initial_ray_data;
113 const std::string param_prefix = aux ? "aux_" : "";
114
115 if (initial_data)
116 {
117 const auto & indices = aux ? _ray_aux_data_indices : _ray_data_indices;
118 const std::string initial_data_param = "initial_ray_" + param_prefix + "data";
119 const std::string names_param = "ray_" + param_prefix + "data_names";
120
121 if (indices.size())
122 {
123 const std::string error_prefix = aux ? "Aux data " : "Data ";
124 if (initial_data->size() != _names.size())
125 paramError(initial_data_param,
126 error_prefix,
127 "for ",
128 initial_data->size(),
129 " ray(s) was provided, but ",
130 _names.size(),
131 " ray(s) were defined");
132 for (const auto i : index_range(*initial_data))
133 if ((*initial_data)[i].size() != indices.size())
134 paramError(initial_data_param,
135 error_prefix,
136 "for index ",
137 i,
138 " (ray '",
139 _names[i],
140 "') is not the size of '",
141 names_param,
142 "'");
143 }
144 else
145 paramError(initial_data_param, "Can only be used if '" + names_param + "' is set");
146 }
147 };
148 check_data(false);
149 check_data(true);
150}
151
152void
154{
155 for (std::size_t i = 0; i < _names.size(); ++i)
156 {
157 std::shared_ptr<Ray> ray = acquireRegisteredRay(_names[i]);
158
159 ray->setStart(_start_points[i]);
160 if (_end_points) // user set end point
161 ray->setStartingEndPoint((*_end_points)[i]);
162 else // user set direction
163 ray->setStartingDirection((*_directions)[i]);
164
165 // Set the data if the user requested so
166 const auto set_data = [this, &ray, &i](const bool aux)
167 {
168 const auto indices = aux ? _ray_aux_data_indices : _ray_data_indices;
169 const auto data = aux ? _initial_ray_aux_data : _initial_ray_data;
170 if (data)
171 {
172 mooseAssert(data->size() == _names.size(), "Size mismatch");
173 mooseAssert((*data)[i].size() == indices.size(), "Size mismatch");
174 for (const auto index_i : indices)
175 {
176 const auto data_index = indices[index_i];
177 const auto value = (*data)[i][index_i];
178 if (aux)
179 ray->auxData(data_index) = value;
180 else
181 ray->data(data_index) = value;
182 }
183 }
184 };
185 set_data(false);
186 set_data(true);
187
188 // User set max-distances
189 if (_max_distances)
190 ray->setStartingMaxDistance((*_max_distances)[i]);
191
192 _rays.emplace_back(std::move(ray));
193 }
194}
unsigned int RayDataIndex
Type for the index into the data and aux data on a Ray.
Definition Ray.h:52
registerMooseObject("RayTracingApp", RepeatableRayStudy)
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
std::shared_ptr< Ray > acquireRegisteredRay(const std::string &name)
Acquires a Ray with a given name within generateRays().
A RayTracingStudy that generates and traces Rays repeatedly that a user defines only once.
std::vector< std::shared_ptr< Ray > > & _rays
Vector of Rays that the user will fill into in defineRays() (restartable)
static InputParameters validParams()
A RayTracingStudy in which the user defines a set of Rays that can be traced repeatedly.
const std::vector< Point > _start_points
The points to start the Rays from.
const std::vector< RayDataIndex > _ray_data_indices
The Ray data indices (if defined)
const std::vector< Real > *const _max_distances
The Ray max distances (if defined)
static InputParameters validParams()
RepeatableRayStudy(const InputParameters &parameters)
const std::vector< Point > *const _directions
The Ray directions (if defined)
const std::vector< Point > *const _end_points
The Ray end points (if defined)
const std::vector< std::string > _names
The Ray names.
const std::vector< RayDataIndex > _ray_aux_data_indices
The Ray aux data indices (if defined)
const std::vector< std::vector< Real > > *const _initial_ray_aux_data
The initial Ray data to set (if defined)
virtual void defineRays() override
Entry point for the user to create Rays.
const std::vector< std::vector< Real > > *const _initial_ray_data
The initial Ray data to set (if defined)