LCOV - code coverage report
Current view: top level - src/userobjects - RepeatableRayStudy.C (source / functions) Hit Total Coverage
Test: idaholab/moose ray_tracing: #31405 (292dce) with base fef103 Lines: 93 94 98.9 %
Date: 2025-09-04 07:56:07 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      12             : registerMooseObject("RayTracingApp", RepeatableRayStudy);
      13             : 
      14             : InputParameters
      15        1796 : RepeatableRayStudy::validParams()
      16             : {
      17        1796 :   auto params = RepeatableRayStudyBase::validParams();
      18             : 
      19        1796 :   params.addClassDescription("A ray tracing study that generates rays from vector of user-input "
      20             :                              "start points and end points/directions.");
      21             : 
      22        3592 :   params.addRequiredParam<std::vector<std::string>>("names", "Unique names for the Rays");
      23             : 
      24        3592 :   params.addRequiredParam<std::vector<Point>>("start_points", "The points to start Rays from");
      25        3592 :   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        3592 :   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        3592 :   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        3592 :   params.addParamNamesToGroup("start_points directions end_points max_distances", "Trajectory");
      40             : 
      41        3592 :   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        3592 :   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        3592 :   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        3592 :   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        3592 :   params.addParamNamesToGroup(
      60             :       "ray_data_names initial_ray_data ray_aux_data_names initial_ray_aux_data", "Ray Data");
      61             : 
      62        1796 :   return params;
      63           0 : }
      64             : 
      65         913 : RepeatableRayStudy::RepeatableRayStudy(const InputParameters & parameters)
      66             :   : RepeatableRayStudyBase(parameters),
      67         911 :     _names(getParam<std::vector<std::string>>("names")),
      68        1822 :     _start_points(getParam<std::vector<Point>>("start_points")),
      69        2818 :     _end_points(isParamValid("end_points") ? &getParam<std::vector<Point>>("end_points") : nullptr),
      70        2648 :     _directions(isParamValid("directions") ? &getParam<std::vector<Point>>("directions") : nullptr),
      71        1872 :     _max_distances(isParamValid("max_distances") ? &getParam<std::vector<Real>>("max_distances")
      72             :                                                  : nullptr),
      73        2094 :     _ray_data_indices(isParamValid("ray_data_names")
      74         911 :                           ? registerRayData(getParam<std::vector<std::string>>("ray_data_names"))
      75             :                           : std::vector<RayDataIndex>()),
      76         911 :     _initial_ray_data(isParamValid("initial_ray_data")
      77        1159 :                           ? &getParam<std::vector<std::vector<Real>>>("initial_ray_data")
      78             :                           : nullptr),
      79        1171 :     _ray_aux_data_indices(
      80         911 :         isParamValid("ray_aux_data_names")
      81         911 :             ? registerRayAuxData(getParam<std::vector<std::string>>("ray_aux_data_names"))
      82             :             : std::vector<RayDataIndex>()),
      83         911 :     _initial_ray_aux_data(isParamValid("initial_ray_aux_data")
      84        1175 :                               ? &getParam<std::vector<std::vector<Real>>>("initial_ray_aux_data")
      85         913 :                               : nullptr)
      86             : {
      87         911 :   if (_end_points && _directions)
      88           2 :     paramError("directions", "Can only use 'directions' or 'end_points', but not both");
      89         909 :   if (!_end_points && !_directions)
      90           2 :     mooseError("Must set 'end_points' or 'directions'");
      91         907 :   if (_start_points.size() != _names.size())
      92           2 :     paramError("start_points", "Not the same size as names");
      93         905 :   if (_directions && _names.size() != _directions->size())
      94           2 :     paramError("directions", "Not the same size as names");
      95         903 :   if (_max_distances)
      96             :   {
      97          25 :     if (!_directions)
      98           2 :       paramError("max_distances",
      99             :                  "Can only be used when trajectories are set with the 'directions' parameter");
     100          23 :     if (_max_distances->size() != _start_points.size())
     101           2 :       paramError("max_distances", "Must be the same size as 'start_points'");
     102          97 :     for (const auto val : *_max_distances)
     103          78 :       if (val <= 0)
     104           2 :         paramError("max_distances", "Values must be positive");
     105             :   }
     106         897 :   if (_end_points && _names.size() != _end_points->size())
     107           2 :     paramError("end_points", "Not the same size as names");
     108             : 
     109             :   // Check ray data and aux data
     110        1784 :   const auto check_data = [this](const bool aux)
     111             :   {
     112        1784 :     const auto initial_data = aux ? _initial_ray_aux_data : _initial_ray_data;
     113        2679 :     const std::string param_prefix = aux ? "aux_" : "";
     114             : 
     115        1784 :     if (initial_data)
     116             :     {
     117         256 :       const auto & indices = aux ? _ray_aux_data_indices : _ray_data_indices;
     118         256 :       const std::string initial_data_param = "initial_ray_" + param_prefix + "data";
     119         512 :       const std::string names_param = "ray_" + param_prefix + "data_names";
     120             : 
     121         256 :       if (indices.size())
     122             :       {
     123         374 :         const std::string error_prefix = aux ? "Aux data " : "Data ";
     124         252 :         if (initial_data->size() != _names.size())
     125           4 :           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        1174 :         for (const auto i : index_range(*initial_data))
     133         930 :           if ((*initial_data)[i].size() != indices.size())
     134           4 :             paramError(initial_data_param,
     135             :                        error_prefix,
     136             :                        "for index ",
     137             :                        i,
     138             :                        " (ray '",
     139           4 :                        _names[i],
     140             :                        "') is not the size of '",
     141             :                        names_param,
     142             :                        "'");
     143             :       }
     144             :       else
     145           8 :         paramError(initial_data_param, "Can only be used if '" + names_param + "' is set");
     146             :     }
     147        1772 :   };
     148         895 :   check_data(false);
     149         889 :   check_data(true);
     150         883 : }
     151             : 
     152             : void
     153         647 : RepeatableRayStudy::defineRays()
     154             : {
     155        3162 :   for (std::size_t i = 0; i < _names.size(); ++i)
     156             :   {
     157        2515 :     std::shared_ptr<Ray> ray = acquireRegisteredRay(_names[i]);
     158             : 
     159        2515 :     ray->setStart(_start_points[i]);
     160        2515 :     if (_end_points) // user set end point
     161        1041 :       ray->setStartingEndPoint((*_end_points)[i]);
     162             :     else // user set direction
     163        1474 :       ray->setStartingDirection((*_directions)[i]);
     164             : 
     165             :     // Set the data if the user requested so
     166        5030 :     const auto set_data = [this, &ray, &i](const bool aux)
     167             :     {
     168        5030 :       const auto indices = aux ? _ray_aux_data_indices : _ray_data_indices;
     169        5030 :       const auto data = aux ? _initial_ray_aux_data : _initial_ray_data;
     170        5030 :       if (data)
     171             :       {
     172             :         mooseAssert(data->size() == _names.size(), "Size mismatch");
     173             :         mooseAssert((*data)[i].size() == indices.size(), "Size mismatch");
     174        1496 :         for (const auto index_i : indices)
     175             :         {
     176         804 :           const auto data_index = indices[index_i];
     177         804 :           const auto value = (*data)[i][index_i];
     178         804 :           if (aux)
     179         496 :             ray->auxData(data_index) = value;
     180             :           else
     181         308 :             ray->data(data_index) = value;
     182             :         }
     183             :       }
     184        5030 :     };
     185        2515 :     set_data(false);
     186        2515 :     set_data(true);
     187             : 
     188             :     // User set max-distances
     189        2515 :     if (_max_distances)
     190          56 :       ray->setStartingMaxDistance((*_max_distances)[i]);
     191             : 
     192        2515 :     _rays.emplace_back(std::move(ray));
     193             :   }
     194         647 : }

Generated by: LCOV version 1.14