https://mooseframework.inl.gov
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ParsedMaterialBase Class Reference

Helper class for ParsedMaterial and DerivativeParsedMaterial to declare and read the input parameters. More...

#include <ParsedMaterialBase.h>

Inheritance diagram for ParsedMaterialBase:
[legend]

Public Member Functions

 ParsedMaterialBase (const InputParameters &parameters, const MooseObject *obj)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

void validateVectorNames (const std::set< std::string > &reserved_names={})
 Function to ensure that the names of constants, tolerances, and functors do not overlap with each other and (optional) additional names. More...
 

Protected Attributes

const MooseObject *const _derived_object
 Pointer to the MooseObject (to call paramError) More...
 
std::string _function
 function expression More...
 
std::vector< std::string > _constant_names
 constant vectors More...
 
std::vector< std::string > _constant_expressions
 
std::vector< std::string > _tol_names
 tolerance vectors More...
 
std::vector< Real_tol_values
 
std::vector< MooseFunctorName > _functor_names
 Functor vectors (names, count, and symbols) More...
 
std::vector< std::string > _functor_symbols
 

Detailed Description

Helper class for ParsedMaterial and DerivativeParsedMaterial to declare and read the input parameters.

Definition at line 18 of file ParsedMaterialBase.h.

Constructor & Destructor Documentation

◆ ParsedMaterialBase()

ParsedMaterialBase::ParsedMaterialBase ( const InputParameters parameters,
const MooseObject obj 
)

Definition at line 77 of file ParsedMaterialBase.C.

78  : _derived_object(obj)
79 {
80  // get function expression
81  _function = parameters.isParamValid("function") ? parameters.get<std::string>("function")
82  : parameters.get<std::string>("expression");
83 
84  // get constant vectors
85  _constant_names = parameters.get<std::vector<std::string>>("constant_names");
86  _constant_expressions = parameters.get<std::vector<std::string>>("constant_expressions");
87 
88  // get tolerance vectors
89  _tol_names = parameters.get<std::vector<std::string>>("tol_names");
90  _tol_values = parameters.get<std::vector<Real>>("tol_values");
91 
92  // get functor vectors
93  _functor_names = parameters.get<std::vector<MooseFunctorName>>("functor_names");
94  _functor_symbols = parameters.get<std::vector<std::string>>("functor_symbols");
95 
96  // validate all vector names (constants, tolerances, and functors)
98 }
std::vector< std::string > _constant_expressions
std::vector< std::string > _constant_names
constant vectors
std::string _function
function expression
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
std::vector< std::string > _tol_names
tolerance vectors
void validateVectorNames(const std::set< std::string > &reserved_names={})
Function to ensure that the names of constants, tolerances, and functors do not overlap with each oth...
std::vector< std::string > _functor_symbols
const MooseObject *const _derived_object
Pointer to the MooseObject (to call paramError)
std::vector< MooseFunctorName > _functor_names
Functor vectors (names, count, and symbols)
std::vector< Real > _tol_values
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

Member Function Documentation

◆ validateVectorNames()

void ParsedMaterialBase::validateVectorNames ( const std::set< std::string > &  reserved_names = {})
protected

Function to ensure that the names of constants, tolerances, and functors do not overlap with each other and (optional) additional names.

Parameters
reserved_namesoptional set of names additionaly not to be allowed.

Definition at line 101 of file ParsedMaterialBase.C.

Referenced by ParsedMaterialBase(), and ParsedMaterialTempl< is_ad >::ParsedMaterialTempl().

102 {
103  // helper method to raise an paramError
104  auto raiseErr = [this](std::string param_name, std::string msg)
105  {
106  if (_derived_object != nullptr)
107  _derived_object->paramError(param_name, msg);
108  else
109  mooseException(msg);
110  };
111 
112  auto hasDuplicates = [](const std::vector<std::string> & values)
113  {
114  std::set<std::string> s(values.begin(), values.end());
115  return values.size() != s.size();
116  };
117 
118  // helper function to check if the name given is one of the constants
119  auto isKnownConstantName = [this](const std::string & name)
120  {
121  return (
122  _constant_names.size() &&
123  (std::find(_constant_names.begin(), _constant_names.end(), name) != _constant_names.end()));
124  };
125 
126  // helper function to check if the name given is one of the reserved_names
127  auto isReservedName = [reserved_names](const std::string & name)
128  { return reserved_names.find(name) != reserved_names.end(); };
129 
130  // check constants
131  if (hasDuplicates(_constant_names))
132  raiseErr("constant_names", "In the constants duplicate names are not permitted.");
133  for (const auto & name : _constant_names)
134  {
135  if (isReservedName(name))
136  raiseErr("constant_names", "In constants, the name '" + name + "' is not permitted.");
137  }
138 
139  // check tolerance vectors
140  if (hasDuplicates(_tol_names))
141  raiseErr("tol_names", "In the tolerances duplicate names are not permitted.");
142 
143  // check functor vectors
144  if (_functor_symbols.empty())
145  {
146  if (!_functor_names.empty())
147  raiseErr("functor_names", "functor_symbols must be the same length as functor_names.");
148  }
149  else
150  {
151  if (_functor_symbols.size() != _functor_names.size())
152  raiseErr("functor_names", "functor_symbols must be the same length as functor_names.");
153  std::vector<std::string> names;
154  if (_functor_symbols.empty())
155  std::copy(_functor_names.begin(), _functor_names.end(), std::back_inserter(names));
156  else
157  std::copy(_functor_symbols.begin(), _functor_symbols.end(), std::back_inserter(names));
158  if (hasDuplicates(names))
159  raiseErr(_functor_symbols.empty() ? "functor_names" : "functor_symbols",
160  "In functors, duplicate names are not permitted.");
161  for (const auto & name : names)
162  {
163  if (isKnownConstantName(name))
164  raiseErr(_functor_symbols.empty() ? "functor_names" : "functor_symbols",
165  "In functors, the name '" + name + "' is already in use as a constant.");
166  if (isReservedName(name))
167  raiseErr(_functor_symbols.empty() ? "functor_names" : "functor_symbols",
168  "In functors, the name '" + name + "' is not permitted.");
169  }
170  }
171 }
std::string name(const ElemQuality q)
std::vector< std::string > _constant_names
constant vectors
std::vector< std::string > _tol_names
tolerance vectors
std::vector< std::string > _functor_symbols
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 ...
const MooseObject *const _derived_object
Pointer to the MooseObject (to call paramError)
std::vector< MooseFunctorName > _functor_names
Functor vectors (names, count, and symbols)

◆ validParams()

InputParameters ParsedMaterialBase::validParams ( )
static

Definition at line 15 of file ParsedMaterialBase.C.

Referenced by DerivativeParsedMaterialTempl< is_ad >::validParams(), and ParsedMaterialTempl< is_ad >::validParams().

16 {
18  params.addCoupledVar("args", "Vector of variables used in the parsed function");
19  params.deprecateCoupledVar("args", "coupled_variables", "02/07/2024");
20 
21  // Constants and their values
22  params.addParam<std::vector<std::string>>(
23  "constant_names",
24  std::vector<std::string>(),
25  "Vector of constants used in the parsed function (use this for kB etc.)");
26  params.addParam<std::vector<std::string>>(
27  "constant_expressions",
28  std::vector<std::string>(),
29  "Vector of values for the constants in constant_names (can be an FParser expression)");
30 
31  // Variables with applied tolerances and their tolerance values
32  params.addParam<std::vector<std::string>>("tol_names",
33  std::vector<std::string>(),
34  "Vector of variable names to be protected from "
35  "being 0 or 1 within a tolerance (needed for log(c) "
36  "and log(1-c) terms)");
37  params.addParam<std::vector<Real>>("tol_values",
38  std::vector<Real>(),
39  "Vector of tolerance values for the variables in tol_names");
40 
41  // Functors and their symbols
42  params.addParam<std::vector<MooseFunctorName>>(
43  "functor_names", {}, "Functors to use in the parsed expression");
44  params.addParam<std::vector<std::string>>(
45  "functor_symbols",
46  {},
47  "Symbolic name to use for each functor in 'functor_names' in the parsed expression. If not "
48  "provided, then the actual functor names will be used in the parsed expression.");
49 
50  // Material properties
51  params.addParam<std::vector<std::string>>(
52  "material_property_names",
53  std::vector<std::string>(),
54  "Vector of material properties used in the parsed function");
55 
56  // Postprocessors
57  params.addParam<std::vector<PostprocessorName>>(
58  "postprocessor_names",
59  std::vector<PostprocessorName>(),
60  "Vector of postprocessor names used in the parsed function");
61 
62  // Function expression
63  params.addDeprecatedCustomTypeParam<std::string>(
64  "function",
65  "FunctionExpression",
66  "Parsed function (see FParser) expression for the parsed material",
67  "'function' is deprecated, use 'expression' instead");
68  // TODO Make required once deprecation is handled, see #19119
69  params.addCustomTypeParam<std::string>(
70  "expression",
71  "FunctionExpression",
72  "Parsed function (see FParser) expression for the parsed material");
73 
74  return params;
75 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()
void deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
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...

Member Data Documentation

◆ _constant_expressions

std::vector<std::string> ParsedMaterialBase::_constant_expressions
protected

◆ _constant_names

std::vector<std::string> ParsedMaterialBase::_constant_names
protected

◆ _derived_object

const MooseObject* const ParsedMaterialBase::_derived_object
protected

Pointer to the MooseObject (to call paramError)

Definition at line 27 of file ParsedMaterialBase.h.

Referenced by validateVectorNames().

◆ _function

std::string ParsedMaterialBase::_function
protected

◆ _functor_names

std::vector<MooseFunctorName> ParsedMaterialBase::_functor_names
protected

◆ _functor_symbols

std::vector<std::string> ParsedMaterialBase::_functor_symbols
protected

◆ _tol_names

std::vector<std::string> ParsedMaterialBase::_tol_names
protected

◆ _tol_values

std::vector<Real> ParsedMaterialBase::_tol_values
protected

The documentation for this class was generated from the following files: