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 1540 : virtual void initialize() override {} 20 1540 : virtual void finalize() override {} 21 1540 : 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, 27 : bool add_vector = true, 28 : bool multiple_entries = true); 29 : 30 : ///@{ 31 : /// Helper for declaring constant reporter values 32 : template <typename T> 33 : T * declareConstantReporterValue(const std::string & prefix); 34 : template <typename T> 35 : std::vector<T *> declareConstantReporterValues(const std::string & prefix); 36 : template <typename T> 37 : std::vector<std::vector<T> *> declareConstantVectorReporterValues(const std::string & prefix); 38 : template <typename T> 39 : std::vector<std::vector<std::vector<T>> *> 40 : declareConstantVectorVectorReporterValues(const std::string & prefix); 41 : ///@} 42 : }; 43 : 44 : template <typename T> 45 : InputParameters 46 120785 : ConstantReporter::addReporterTypeParams(const std::string & prefix, 47 : bool add_vector, 48 : bool multiple_entries) 49 : { 50 120785 : InputParameters params = emptyInputParameters(); 51 : 52 120785 : if (!multiple_entries) 53 : { 54 : mooseAssert(!add_vector, "Should be creating vector of singular entry."); 55 34510 : params.addParam<ReporterValueName>(prefix + "_name", "Name of " + prefix + " value."); 56 34510 : params.addParam<T>(prefix + "_value", "Value of " + prefix + "."); 57 34510 : return params; 58 : } 59 : 60 86275 : params.addParam<std::vector<ReporterValueName>>(prefix + "_names", 61 : "Names for each " + prefix + " value."); 62 86275 : params.addParam<std::vector<T>>(prefix + "_values", "Values for " + prefix + "s."); 63 86275 : if (add_vector) 64 : { 65 86275 : params.addParam<std::vector<ReporterValueName>>( 66 : prefix + "_vector_names", "Names for each vector of " + prefix + "s value."); 67 86275 : params.addParam<std::vector<std::vector<T>>>(prefix + "_vector_values", 68 : "Values for vectors of " + prefix + "s."); 69 : 70 86275 : params.addParam<std::vector<ReporterValueName>>(prefix + "_vector_vector_names", 71 : "Names for each vector of vectors of " + 72 : prefix + "s value."); 73 86275 : params.addParam<std::vector<std::vector<std::vector<T>>>>( 74 : prefix + "_vector_vector_values", "Values for vectors of vectors of " + prefix + "s."); 75 : } 76 : 77 86275 : return params; 78 0 : } 79 : 80 : template <typename T> 81 : T * 82 2950 : ConstantReporter::declareConstantReporterValue(const std::string & prefix) 83 : { 84 2950 : std::string names_param(prefix + "_name"); 85 2950 : std::string values_param(prefix + "_value"); 86 2950 : if (isParamValid(names_param) != isParamValid(values_param)) 87 4 : paramError((isParamValid(names_param) ? names_param : values_param), 88 : "'", 89 : names_param, 90 : "' and '", 91 : values_param, 92 : "' must be set together."); 93 2946 : else if (isParamValid(names_param)) 94 37 : return &declareValue<T>(names_param, getParam<T>(values_param)); 95 : 96 2909 : return nullptr; 97 2946 : } 98 : 99 : template <typename T> 100 : std::vector<T *> 101 19187 : ConstantReporter::declareConstantReporterValues(const std::string & prefix) 102 : { 103 19187 : std::string names_param(prefix + "_names"); 104 19187 : std::string values_param(prefix + "_values"); 105 19187 : std::vector<T *> data; 106 : 107 19187 : if (isParamValid(names_param) && !isParamValid(values_param)) 108 4 : paramError(names_param, "Must specify values using ", values_param); 109 19183 : else if (!isParamValid(names_param) && isParamValid(values_param)) 110 4 : paramError(values_param, "Use ", names_param, " to specify reporter names."); 111 19179 : else if (!isParamValid(names_param) && !isParamValid(values_param)) 112 16357 : return data; 113 : 114 2822 : auto & names = getParam<std::vector<ReporterValueName>>(names_param); 115 2822 : auto & values = this->getParam<std::vector<T>>(values_param); 116 2822 : if (names.size() != values.size()) 117 4 : paramError(values_param, 118 : "Number of names specified in ", 119 : names_param, 120 : " must match number of values specified in ", 121 : values_param); 122 : 123 6359 : for (unsigned int i = 0; i < names.size(); ++i) 124 3541 : data.push_back(&this->declareValueByName<T>(names[i], values[i])); 125 : 126 2818 : return data; 127 19175 : } 128 : 129 : template <typename T> 130 : std::vector<std::vector<T> *> 131 5900 : ConstantReporter::declareConstantVectorReporterValues(const std::string & prefix) 132 : { 133 5900 : return this->declareConstantReporterValues<std::vector<T>>(prefix + "_vector"); 134 : } 135 : 136 : template <typename T> 137 : std::vector<std::vector<std::vector<T>> *> 138 5900 : ConstantReporter::declareConstantVectorVectorReporterValues(const std::string & prefix) 139 : { 140 : return this->declareConstantReporterValues<std::vector<std::vector<T>>>(prefix + 141 5900 : "_vector_vector"); 142 : }