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 "ParsedVectorReporter.h" 11 : 12 : registerMooseObject("MooseApp", ParsedVectorReporter); 13 : 14 : InputParameters 15 14823 : ParsedVectorReporter::validParams() 16 : { 17 14823 : InputParameters params = ParsedReporterBase::validParams(); 18 29646 : params.addClassDescription("Apply parsed functions to vector entries held in reporters."); 19 44469 : params.addRequiredParam<std::vector<ReporterName>>("vector_reporter_names", 20 : "Reporter names to apply function to."); 21 14823 : return params; 22 0 : } 23 : 24 42 : ParsedVectorReporter::ParsedVectorReporter(const InputParameters & parameters) 25 : : ParsedReporterBase(parameters), 26 38 : _output_reporter( 27 118 : declareValueByName<std::vector<Real>>(getParam<std::string>("name"), REPORTER_MODE_ROOT)) 28 : { 29 : const std::vector<ReporterName> reporter_names( 30 76 : getParam<std::vector<ReporterName>>("vector_reporter_names")); 31 38 : if (reporter_names.size() != _vector_reporter_symbols.size()) 32 8 : paramError("vector_reporter_names", 33 : "vector_reporter_names and vector_reporter_symbols must be the same size: Number " 34 : "of vector_reporter_names=", 35 : reporter_names.size(), 36 : "; Number of vector_reporter_symbols=", 37 : _vector_reporter_symbols.size()); 38 : 39 34 : _vector_reporter_data.resize(reporter_names.size()); 40 136 : for (const auto rep_index : index_range(_vector_reporter_data)) 41 204 : _vector_reporter_data[rep_index] = 42 102 : &getReporterValueByName<std::vector<Real>>(reporter_names[rep_index], REPORTER_MODE_ROOT); 43 34 : } 44 : 45 : void 46 52 : ParsedVectorReporter::finalize() 47 : { 48 : // check vector sizes of reporters 49 52 : const std::size_t entries(_vector_reporter_data[0]->size()); 50 204 : for (const auto rep_index : index_range(_vector_reporter_data)) 51 156 : if (entries != _vector_reporter_data[rep_index]->size()) 52 : { 53 : const std::vector<ReporterName> reporter_names( 54 8 : getParam<std::vector<ReporterName>>("vector_reporter_names")); 55 4 : mooseError("All vectors being operated on must be the same size.", 56 : "\nsize of ", 57 4 : reporter_names[0].getCombinedName(), 58 : " = ", 59 : entries, 60 : "\nsize of ", 61 4 : reporter_names[rep_index].getCombinedName(), 62 : " = ", 63 4 : _vector_reporter_data[rep_index]->size()); 64 0 : } 65 : 66 48 : _output_reporter.resize(entries, 0.0); 67 192 : for (const auto i : make_range(entries)) 68 : { 69 : // this is the same order they are added to the symbol string in ParsedReporterBase 70 : // first get vector data 71 576 : for (const auto rep_index : index_range(_vector_reporter_data)) 72 432 : _func_params[rep_index] = _vector_reporter_data[rep_index]->at(i); 73 : // next get scalar data 74 396 : for (const auto rep_index : index_range(_scalar_reporter_data)) 75 252 : _func_params[_vector_reporter_data.size() + rep_index] = *(_scalar_reporter_data[rep_index]); 76 : 77 144 : if (_use_t) 78 0 : _func_params[_vector_reporter_data.size() + _scalar_reporter_data.size()] = _t; 79 : 80 432 : _output_reporter[i] = evaluate(_func_F); 81 : } 82 48 : }