26 "convergence_expression",
"FunctionExpression",
"Expression to parse for convergence");
28 "divergence_expression",
"FunctionExpression",
"Expression to parse for divergence");
29 params.
addParam<std::vector<std::string>>(
30 "symbol_names", {},
"Symbol names to use in the parsed expressions");
31 params.
addParam<std::vector<std::string>>(
34 "Values (Convergence names, Postprocessor names, Function names, and constants) "
35 "corresponding to each entry in 'symbol_names'");
43 _fe_problem(*getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base")),
44 _symbol_names(getParam<
std::vector<
std::string>>(
"symbol_names")),
45 _symbol_values(getParam<
std::vector<
std::string>>(
"symbol_values")),
46 _convergence_function_params(_symbol_names.size(), 0.0),
47 _divergence_function_params(_symbol_names.size(), 0.0)
50 mooseError(
"The parameters 'symbol_names' and 'symbol_values' must have the same size.");
60 const auto convergence_expression = getParam<std::string>(
"convergence_expression");
63 const auto divergence_expression =
isParamValid(
"divergence_expression")
64 ? getParam<std::string>(
"divergence_expression")
66 if (divergence_expression.size())
117 const Real value = MooseUtils::convert<Real>(
_symbol_values[i],
true);
121 catch (
const std::invalid_argument & e)
124 "The 'symbol_values' entry '",
126 "' is not a constant value or the name of a Convergence, Postprocessor, or Function.",
135 auto sym_function = std::make_shared<SymFunction>();
140 {std::to_string(
libMesh::pi), std::to_string(std::exp(Real(1)))},
152 const Real diverged_real =
187 const Real function_value =
_functions[i]->value(
_t, Point(0, 0, 0));
198 const auto status =
_convergences[i]->checkConvergence(n_iter);
209 if (MooseUtils::absoluteFuzzyEqual(value, 1.0))
211 else if (MooseUtils::absoluteFuzzyEqual(value, 0.0))
216 "' evaluated to the value ",
218 ", but it must only evaluate to either 0 or 1.");
Real PostprocessorValue
various MOOSE typedefs
registerMooseObject("MooseApp", ParsedConvergence)
Base class for convergence criteria.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
static InputParameters validParams()
MooseConvergenceStatus
Status returned by calls to checkConvergence.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name, std::size_t t_index=0) const
Get a read-only reference to the value associated with a Postprocessor that exists.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
virtual bool hasConvergence(const std::string &name, const THREAD_ID tid=0) const
Returns true if the problem has a Convergence object of the given name.
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
std::shared_ptr< SymFunction > SymFunctionPtr
Shorthand for an smart pointer to an autodiff function parser object.
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
Performs setup steps on a SymFunction.
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
static InputParameters validParams()
Base class for function objects.
const std::string & name() const
Get the name of the class.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Evaluates convergence from a parsed expression.
bool convertRealToBool(Real value, const std::string ¶m) const
Converts a Real value to a bool.
std::vector< unsigned int > _pp_indices
void updatePostprocessorSymbolValues()
std::vector< const PostprocessorValue * > _pp_values
Post-processor values in the provided symbols.
void initializeFunctionSymbol(unsigned int i)
std::vector< std::string > _symbol_names
User-defined symbols to use in parsed expression.
std::vector< Convergence * > _convergences
Convergences in the provided symbols.
std::vector< unsigned int > _function_indices
std::vector< Real > _convergence_function_params
Convergence function parameters.
void updateFunctionSymbolValues()
SymFunctionPtr _divergence_function
Parsed function for divergence.
virtual MooseConvergenceStatus checkConvergence(unsigned int n_iter) override
Returns convergence status.
void initializePostprocessorSymbol(unsigned int i)
std::vector< std::string > _convergence_symbol_names
void updateConvergenceSymbolValues(unsigned int n_iter)
std::vector< unsigned int > _convergence_indices
void updateSymbolValues(unsigned int n_iter)
Updates non-constant symbol values.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
std::vector< Function * > _functions
Functions in the provided symbols.
void initializeConstantSymbol(unsigned int i)
ParsedConvergence(const InputParameters ¶meters)
SymFunctionPtr _convergence_function
Parsed function for convergence.
void initializeSymbols()
Initializes symbols used in the parsed expression.
void initializeConvergenceSymbol(unsigned int i)
std::vector< Real > _divergence_function_params
Divergence function parameters.
SymFunctionPtr makeParsedFunction(const std::string &expression)
Makes a parsed function.
FEProblemBase & _fe_problem
static InputParameters validParams()
std::vector< std::string > _symbol_values
Corresponding symbol values (Convergence, Function, Postprocessor, or constant)
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
The Reporter system is comprised of objects that can contain any number of data values.
const Parallel::Communicator & comm() const
std::string stringify(const T &t)
conversion to string