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 : #pragma once 11 : 12 : #include "GeneralReporter.h" 13 : 14 : class ConstantReporter : public GeneralReporter 15 : { 16 : public: 17 : static InputParameters validParams(); 18 : ConstantReporter(const InputParameters & parameters); 19 1370 : virtual void initialize() override {} 20 1370 : virtual void finalize() override {} 21 1370 : virtual void execute() override {} 22 : 23 : protected: 24 : /// This will add another type of reporter to the params 25 : template <typename T> 26 : static InputParameters addReporterTypeParams(const std::string & prefix, bool add_vector = true); 27 : 28 : ///@{ 29 : /// Helper for declaring constant reporter values 30 : template <typename T> 31 : std::vector<T *> declareConstantReporterValues(const std::string & prefix); 32 : template <typename T> 33 : std::vector<std::vector<T> *> declareConstantVectorReporterValues(const std::string & prefix); 34 : template <typename T> 35 : std::vector<std::vector<std::vector<T>> *> 36 : declareConstantVectorVectorReporterValues(const std::string & prefix); 37 : ///@} 38 : }; 39 : 40 : template <typename T> 41 : InputParameters 42 84735 : ConstantReporter::addReporterTypeParams(const std::string & prefix, bool add_vector) 43 : { 44 84735 : InputParameters params = emptyInputParameters(); 45 : 46 84735 : params.addParam<std::vector<ReporterValueName>>(prefix + "_names", 47 : "Names for each " + prefix + " value."); 48 84735 : params.addParam<std::vector<T>>(prefix + "_values", "Values for " + prefix + "s."); 49 84735 : if (add_vector) 50 : { 51 84735 : params.addParam<std::vector<ReporterValueName>>( 52 : prefix + "_vector_names", "Names for each vector of " + prefix + "s value."); 53 84735 : params.addParam<std::vector<std::vector<T>>>(prefix + "_vector_values", 54 : "Values for vectors of " + prefix + "s."); 55 : 56 84735 : params.addParam<std::vector<ReporterValueName>>(prefix + "_vector_vector_names", 57 : "Names for each vector of vectors of " + 58 : prefix + "s value."); 59 84735 : params.addParam<std::vector<std::vector<std::vector<T>>>>( 60 : prefix + "_vector_vector_values", "Values for vectors of vectors of " + prefix + "s."); 61 : } 62 : 63 84735 : return params; 64 0 : } 65 : 66 : template <typename T> 67 : std::vector<T *> 68 17185 : ConstantReporter::declareConstantReporterValues(const std::string & prefix) 69 : { 70 17185 : std::string names_param(prefix + "_names"); 71 17185 : std::string values_param(prefix + "_values"); 72 17185 : std::vector<T *> data; 73 : 74 17185 : if (isParamValid(names_param) && !isParamValid(values_param)) 75 4 : paramError(names_param, "Must specify values using ", values_param); 76 17181 : else if (!isParamValid(names_param) && isParamValid(values_param)) 77 4 : paramError(values_param, "Use ", names_param, " to specify reporter names."); 78 17177 : else if (!isParamValid(names_param) && !isParamValid(values_param)) 79 14659 : return data; 80 : 81 2518 : auto & names = getParam<std::vector<ReporterValueName>>(names_param); 82 2518 : auto & values = this->getParam<std::vector<T>>(values_param); 83 2518 : if (names.size() != values.size()) 84 4 : paramError(values_param, 85 : "Number of names specified in ", 86 : names_param, 87 : " must match number of values specified in ", 88 : values_param); 89 : 90 5704 : for (unsigned int i = 0; i < names.size(); ++i) 91 3190 : data.push_back(&this->declareValueByName<T>(names[i], values[i])); 92 : 93 2514 : return data; 94 17173 : } 95 : 96 : template <typename T> 97 : std::vector<std::vector<T> *> 98 5284 : ConstantReporter::declareConstantVectorReporterValues(const std::string & prefix) 99 : { 100 5284 : return this->declareConstantReporterValues<std::vector<T>>(prefix + "_vector"); 101 : } 102 : 103 : template <typename T> 104 : std::vector<std::vector<std::vector<T>> *> 105 5284 : ConstantReporter::declareConstantVectorVectorReporterValues(const std::string & prefix) 106 : { 107 : return this->declareConstantReporterValues<std::vector<std::vector<T>>>(prefix + 108 5284 : "_vector_vector"); 109 : }