https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ConstantReporter.h
Go to the documentation of this file.
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
15{
16public:
19 virtual void initialize() override {}
20 virtual void finalize() override {}
21 virtual void execute() override {}
22
23protected:
25 template <typename T>
26 static InputParameters addReporterTypeParams(const std::string & prefix,
27 bool add_vector = true,
28 bool multiple_entries = true);
29
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);
42};
43
44template <typename T>
46ConstantReporter::addReporterTypeParams(const std::string & prefix,
47 bool add_vector,
48 bool multiple_entries)
49{
51
52 if (!multiple_entries)
53 {
54 mooseAssert(!add_vector, "Should be creating vector of singular entry.");
55 params.addParam<ReporterValueName>(prefix + "_name", "Name of " + prefix + " value.");
56 params.addParam<T>(prefix + "_value", "Value of " + prefix + ".");
57 return params;
58 }
59
60 params.addParam<std::vector<ReporterValueName>>(prefix + "_names",
61 "Names for each " + prefix + " value.");
62 params.addParam<std::vector<T>>(prefix + "_values", "Values for " + prefix + "s.");
63 if (add_vector)
64 {
65 params.addParam<std::vector<ReporterValueName>>(
66 prefix + "_vector_names", "Names for each vector of " + prefix + "s value.");
67 params.addParam<std::vector<std::vector<T>>>(prefix + "_vector_values",
68 "Values for vectors of " + prefix + "s.");
69
70 params.addParam<std::vector<ReporterValueName>>(prefix + "_vector_vector_names",
71 "Names for each vector of vectors of " +
72 prefix + "s value.");
73 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 return params;
78}
79
80template <typename T>
81T *
83{
84 std::string names_param(prefix + "_name");
85 std::string values_param(prefix + "_value");
86 if (isParamValid(names_param) != isParamValid(values_param))
87 paramError((isParamValid(names_param) ? names_param : values_param),
88 "'",
89 names_param,
90 "' and '",
91 values_param,
92 "' must be set together.");
93 else if (isParamValid(names_param))
94 return &declareValue<T>(names_param, getParam<T>(values_param));
95
96 return nullptr;
97}
98
99template <typename T>
100std::vector<T *>
102{
103 std::string names_param(prefix + "_names");
104 std::string values_param(prefix + "_values");
105 std::vector<T *> data;
106
107 if (isParamValid(names_param) && !isParamValid(values_param))
108 paramError(names_param, "Must specify values using ", values_param);
109 else if (!isParamValid(names_param) && isParamValid(values_param))
110 paramError(values_param, "Use ", names_param, " to specify reporter names.");
111 else if (!isParamValid(names_param) && !isParamValid(values_param))
112 return data;
113
114 auto & names = getParam<std::vector<ReporterValueName>>(names_param);
115 auto & values = this->getParam<std::vector<T>>(values_param);
116 if (names.size() != values.size())
117 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 for (unsigned int i = 0; i < names.size(); ++i)
124 data.push_back(&this->declareValueByName<T>(names[i], values[i]));
125
126 return data;
127}
128
129template <typename T>
130std::vector<std::vector<T> *>
132{
133 return this->declareConstantReporterValues<std::vector<T>>(prefix + "_vector");
134}
135
136template <typename T>
137std::vector<std::vector<std::vector<T>> *>
139{
140 return this->declareConstantReporterValues<std::vector<std::vector<T>>>(prefix +
141 "_vector_vector");
142}
InputParameters emptyInputParameters()
std::array< Real, 2 > values
Definition MortarUtils.C:52
static InputParameters addReporterTypeParams(const std::string &prefix, bool add_vector=true, bool multiple_entries=true)
This will add another type of reporter to the params.
std::vector< T * > declareConstantReporterValues(const std::string &prefix)
static InputParameters validParams()
virtual void finalize() override
Finalize.
std::vector< std::vector< std::vector< T > > * > declareConstantVectorVectorReporterValues(const std::string &prefix)
T * declareConstantReporterValue(const std::string &prefix)
virtual void execute() override
Execute method.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
std::vector< std::vector< T > * > declareConstantVectorReporterValues(const std::string &prefix)
Reporter object that has a single execution of the "execute" method for each execute flag.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199