https://mooseframework.inl.gov
ParsedReporterBase.C
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 #include "ParsedReporterBase.h"
11 
12 // registerMooseObject("OptimizationApp", ParsedReporterBase);
13 
16 {
19  params.addRequiredCustomTypeParam<std::string>(
20  "expression", "FunctionExpression", "function expression");
21  params.addParam<std::string>("name", "result", "Name of output reporter.");
22  params.addRequiredParam<std::vector<std::string>>("reporter_symbols",
23  "Expression symbol for each reporter");
24  params.addParam<std::vector<std::string>>(
25  "constant_names",
26  {},
27  "Vector of constants used in the parsed function (use this for kB etc.)");
28  params.addParam<std::vector<std::string>>(
29  "constant_expressions",
30  {},
31  "Vector of values for the constants in constant_names (can be an FParser expression)");
32  params.addParam<bool>(
33  "use_t", false, "Make time (t) variables available in the function expression.");
34  return params;
35 }
36 
38  : GeneralReporter(parameters),
39  FunctionParserUtils(parameters),
40  _use_t(getParam<bool>("use_t")),
41  _reporter_symbols(getParam<std::vector<std::string>>("reporter_symbols"))
42 {
43  // build reporters argument
44  std::string symbol_str;
45  for (const auto i : index_range(_reporter_symbols))
46  symbol_str += (i == 0 ? "" : ",") + _reporter_symbols[i];
47 
48  // add time if required
49  if (_use_t)
50  symbol_str += (symbol_str.empty() ? "" : ",") + std::string("t");
51 
52  // Create parsed function
53  _func_F = std::make_shared<SymFunction>();
55  getParam<std::string>("expression"),
56  symbol_str,
57  getParam<std::vector<std::string>>("constant_names"),
58  getParam<std::vector<std::string>>("constant_expressions"),
59  comm());
60 
61  // reserve storage for parameter passing buffer
62  _func_params.resize(_reporter_symbols.size() + _use_t);
63 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const Parallel::Communicator & comm() const
static InputParameters validParams()
SymFunctionPtr _func_F
function parser object
void addRequiredParam(const std::string &name, const std::string &doc_string)
const T & getParam(const std::string &name) const
static InputParameters validParams()
const std::vector< std::string > _reporter_symbols
Get symbols to corresponding reporter names need symbols because reporter names have a "/" and that w...
void parsedFunctionSetup(SymFunctionPtr &function, const std::string &expression, const std::string &variables, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions, const libMesh::Parallel::Communicator &comm) const
std::vector< GenericReal< is_ad > > _func_params
const bool _use_t
whether time is part of the parsed expression
ParsedReporterBase(const InputParameters &parameters)
void addRequiredCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string)
static InputParameters validParams()
auto index_range(const T &sizable)