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 : // MOOSE includes 11 : #include "RayDataValue.h" 12 : 13 : // Local includes 14 : #include "RayTracingStudy.h" 15 : 16 : registerMooseObject("RayTracingApp", RayDataValue); 17 : 18 : InputParameters 19 412 : RayDataValue::validParams() 20 : { 21 412 : InputParameters params = GeneralPostprocessor::validParams(); 22 : 23 412 : params.addClassDescription( 24 : "Obtains a value from the data or aux data of a Ray after tracing has been completed."); 25 : 26 824 : params.addRequiredParam<UserObjectName>("study", "The RayTracingStudy that owns the Ray"); 27 824 : params.addParam<RayID>("ray_id", 28 : "The ID of the Ray to get the value from. This or 'ray_id' must be set."); 29 824 : params.addParam<std::string>( 30 : "ray_name", "Name of the Ray to get the value from. This or 'ray_name' must be set."); 31 824 : params.addRequiredParam<std::string>("data_name", "The name of the data to extract from the Ray"); 32 824 : params.addParam<bool>("aux", false, "Whether or not the data is an auxiliary value"); 33 : 34 412 : return params; 35 0 : } 36 : 37 210 : RayDataValue::RayDataValue(const InputParameters & parameters) 38 : : GeneralPostprocessor(parameters), 39 210 : _study(getUserObject<RayTracingStudy>("study")), 40 420 : _aux(getParam<bool>("aux")), 41 470 : _ray_name(parameters.isParamSetByUser("ray_name") ? &getParam<std::string>("ray_name") 42 : : nullptr), 43 580 : _ray_id(parameters.isParamSetByUser("ray_id") ? &getParam<RayID>("ray_id") : nullptr) 44 : { 45 210 : if (_ray_id && _ray_name) 46 2 : paramError("ray_id", "Either 'ray_id' or 'ray_name' must be set, but not both"); 47 208 : if (!_ray_id && !_ray_name) 48 2 : mooseError("Must have either the 'ray_id' or the 'ray_name' param set."); 49 : 50 206 : if (_ray_name && !_study.useRayRegistration()) 51 2 : paramError("study", 52 2 : _study.typeAndName(), 53 : " does not support Ray registration.\n\nThis is controlled by the " 54 : "'_use_ray_registration' private param within the study."); 55 : 56 204 : if (!_study.bankRaysOnCompletion()) 57 2 : paramError("study", 58 2 : _study.typeAndName(), 59 : " does not bank Rays on completion.\n\nThis is controlled by the " 60 : "'_bank_rays_on_completion' private param within the study."); 61 202 : } 62 : 63 : void 64 148 : RayDataValue::initialize() 65 : { 66 : // Get the index for the data on the ray requested 67 148 : const auto & data_name = getParam<std::string>("data_name"); 68 148 : if (_aux) 69 58 : _ray_data_index = _study.getRayAuxDataIndex(data_name, /* graceful = */ true); 70 : else 71 90 : _ray_data_index = _study.getRayDataIndex(data_name, /* graceful = */ true); 72 148 : if (_ray_data_index == Ray::INVALID_RAY_DATA_INDEX) 73 8 : paramError("ray_name", 74 : "The ", 75 4 : _study.typeAndName(), 76 : " does not have Ray ", 77 4 : (_aux ? "aux " : ""), 78 : "data associated with the name '", 79 : data_name, 80 : "'"); 81 144 : } 82 : 83 : Real 84 144 : RayDataValue::getValue() const 85 : { 86 : RayID id; 87 144 : if (_ray_name) 88 : { 89 86 : id = _study.registeredRayID(*_ray_name, /* graceful = */ true); 90 86 : if (id == Ray::INVALID_RAY_ID) 91 2 : mooseError(type(), 92 : " '", 93 : name(), 94 : "': Could not find a registered Ray with the name '", 95 2 : *_ray_name, 96 : "'"); 97 : } 98 : else 99 58 : id = *_ray_id; 100 : 101 : // This gathers the value from the proc that killed the Ray we're looking for 102 142 : if (_aux) 103 56 : return _study.getBankedRayAuxData(id, _ray_data_index); 104 : else 105 86 : return _study.getBankedRayData(id, _ray_data_index); 106 : }