https://mooseframework.inl.gov
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ChainControlParsedFunctionWrapper Class Reference

Wraps libMesh::ParsedFunction for use in ChainControls. More...

#include <ChainControlParsedFunctionWrapper.h>

Public Member Functions

 ChainControlParsedFunctionWrapper (MooseApp &moose_app, FEProblemBase &fe_problem, const std::string &function_str, const std::vector< std::string > &symbol_names, const std::vector< std::string > &symbol_values, const THREAD_ID tid=0)
 Constructor. More...
 
Real evaluate (Real t, const Point &p)
 Evaluates the libMesh::ParsedFunction. More...
 
std::vector< ChainControlData< Real > * > getRealChainControlData ()
 Get list of Real-valued control data objects. More...
 
std::vector< ChainControlData< bool > * > getBoolChainControlData ()
 Get list of boolean-valued control data objects. More...
 

Private Member Functions

void initializeFunctionInputs ()
 Gets initial value, address, and input index for each function input. More...
 
void updateScalarVariableValues ()
 Updates scalar values in wrapped function. More...
 
void updateFunctionValues (Real t, const Point &pt)
 Updates function values in wrapped function. More...
 
void updateChainControlDataValues ()
 Updates control data values in wrapped function. More...
 

Private Attributes

MooseApp_moose_app
 App. More...
 
FEProblemBase_fe_problem
 Problem. More...
 
const std::string & _function_str
 Function expression. More...
 
const std::vector< std::string > & _symbol_names
 Symbols used in the function expression string. More...
 
const std::vector< std::string > & _symbol_values
 Values pairing with symbol_names. More...
 
std::vector< Real_initial_values
 Initial value for each function input. More...
 
std::unique_ptr< ParsedFunction< Real > > _function_ptr
 Wrapped libMesh::ParsedFunction. More...
 
std::vector< unsigned int_real_control_data_indices
 _input_values index for each Real control data value More...
 
std::vector< ChainControlData< Real > * > _real_control_data_values
 Real control data values. More...
 
std::vector< unsigned int_bool_control_data_indices
 _input_values index for each bool control data value More...
 
std::vector< ChainControlData< bool > * > _bool_control_data_values
 bool control data values More...
 
std::vector< unsigned int_scalar_indices
 _input_values index for each scalar variable value More...
 
std::vector< const VariableValue * > _scalar_values
 Scalar variable values. More...
 
std::vector< unsigned int_function_indices
 _input_values index for each function value More...
 
std::vector< const Function * > _function_values
 Function values. More...
 
std::vector< Real * > _input_values
 libMesh::ParsedFunction input values More...
 
const THREAD_ID _tid
 Thread id passed from owning object. More...
 
ChainControlDataSystem_chain_control_data_system
 Chain control data system. More...
 

Detailed Description

Wraps libMesh::ParsedFunction for use in ChainControls.

Definition at line 27 of file ChainControlParsedFunctionWrapper.h.

Constructor & Destructor Documentation

◆ ChainControlParsedFunctionWrapper()

ChainControlParsedFunctionWrapper::ChainControlParsedFunctionWrapper ( MooseApp moose_app,
FEProblemBase fe_problem,
const std::string &  function_str,
const std::vector< std::string > &  symbol_names,
const std::vector< std::string > &  symbol_values,
const THREAD_ID  tid = 0 
)

Constructor.

Parameters
moose_appApp
fe_problemProblem
function_strFunction expression
symbol_namesSymbols used in the function expression string
symbol_valuesValues pairing with symbol_names

Definition at line 18 of file ChainControlParsedFunctionWrapper.C.

25  : _moose_app(moose_app),
26  _fe_problem(fe_problem),
27  _function_str(function_str),
28  _symbol_names(symbol_names),
29  _symbol_values(symbol_values),
30  _tid(tid),
32 {
34 
35  _function_ptr = std::make_unique<ParsedFunction<Real, RealGradient>>(
37 
38  for (const auto & symbol_name : _symbol_names)
39  _input_values.push_back(&_function_ptr->getVarAddress(symbol_name));
40 }
void initializeFunctionInputs()
Gets initial value, address, and input index for each function input.
ChainControlDataSystem & _chain_control_data_system
Chain control data system.
const THREAD_ID _tid
Thread id passed from owning object.
const std::vector< std::string > & _symbol_names
Symbols used in the function expression string.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Wrapped libMesh::ParsedFunction.
std::vector< Real * > _input_values
libMesh::ParsedFunction input values
const std::string & _function_str
Function expression.
ChainControlDataSystem & getChainControlDataSystem()
Gets the system that manages the ChainControls.
Definition: MooseApp.h:872
std::vector< Real > _initial_values
Initial value for each function input.
const std::vector< std::string > & _symbol_values
Values pairing with symbol_names.

Member Function Documentation

◆ evaluate()

Real ChainControlParsedFunctionWrapper::evaluate ( Real  t,
const Point &  p 
)

Evaluates the libMesh::ParsedFunction.

Parameters
tTime
pSpatial point

Definition at line 43 of file ChainControlParsedFunctionWrapper.C.

44 {
48  return (*_function_ptr)(p, t);
49 }
void updateChainControlDataValues()
Updates control data values in wrapped function.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Wrapped libMesh::ParsedFunction.
void updateFunctionValues(Real t, const Point &pt)
Updates function values in wrapped function.
void updateScalarVariableValues()
Updates scalar values in wrapped function.

◆ getBoolChainControlData()

std::vector<ChainControlData<bool> *> ChainControlParsedFunctionWrapper::getBoolChainControlData ( )
inline

Get list of boolean-valued control data objects.

Definition at line 65 of file ChainControlParsedFunctionWrapper.h.

66  {
68  }
std::vector< ChainControlData< bool > * > _bool_control_data_values
bool control data values

◆ getRealChainControlData()

std::vector<ChainControlData<Real> *> ChainControlParsedFunctionWrapper::getRealChainControlData ( )
inline

Get list of Real-valued control data objects.

Definition at line 57 of file ChainControlParsedFunctionWrapper.h.

58  {
60  }
std::vector< ChainControlData< Real > * > _real_control_data_values
Real control data values.

◆ initializeFunctionInputs()

void ChainControlParsedFunctionWrapper::initializeFunctionInputs ( )
private

Gets initial value, address, and input index for each function input.

Definition at line 52 of file ChainControlParsedFunctionWrapper.C.

Referenced by ChainControlParsedFunctionWrapper().

53 {
54  for (const auto i : index_range(_symbol_values))
55  {
57  {
59  _initial_values.push_back(data.get());
60  _real_control_data_values.push_back(&data);
61  _real_control_data_indices.push_back(i);
62  }
64  {
66  _initial_values.push_back(data.get());
67  _bool_control_data_values.push_back(&data);
68  _bool_control_data_indices.push_back(i);
69  }
71  {
72  const VariableValue & scalar_val =
74  _initial_values.push_back(0);
75  _scalar_values.push_back(&scalar_val);
76  _scalar_indices.push_back(i);
77  }
79  {
80  const Function & function = _fe_problem.getFunction(_symbol_values[i], _tid);
81  _initial_values.push_back(0);
82  _function_values.push_back(&function);
83  _function_indices.push_back(i);
84  }
86  {
87  _initial_values.push_back(MooseUtils::convert<Real>(_symbol_values[i], true));
88  }
89  else
90  mooseError("Invalid 'symbol_values' entry '",
91  _symbol_values[i],
92  "'. Valid entries:\n"
93  " - chain control data values (bool or Real)\n"
94  " - function names\n"
95  " - scalar variable names\n"
96  " - constant values");
97  }
98 }
std::vector< ChainControlData< Real > * > _real_control_data_values
Real control data values.
std::vector< const Function * > _function_values
Function values.
std::vector< const VariableValue * > _scalar_values
Scalar variable values.
Base class for function objects.
Definition: Function.h:36
ChainControlDataSystem & _chain_control_data_system
Chain control data system.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::vector< ChainControlData< bool > * > _bool_control_data_values
bool control data values
const THREAD_ID _tid
Thread id passed from owning object.
std::vector< unsigned int > _scalar_indices
_input_values index for each scalar variable value
std::vector< unsigned int > _real_control_data_indices
_input_values index for each Real control data value
virtual bool hasScalarVariable(const std::string &var_name) const override
Returns a Boolean indicating whether any system contains a variable with the name provided...
bool isFloat(const std::string &str)
Courtesy https://stackoverflow.com/a/57163016 and https://stackoverflow.com/questions/447206/c-isfloa...
Definition: MooseUtils.h:1219
ChainControlData< T > & getChainControlData(const std::string &data_name)
Gets the chain control data of the given name and type and creates if it does not exist...
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
bool hasChainControlDataOfType(const std::string &data_name) const
Queries if the chain control data of the given name and type exists.
virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
std::vector< unsigned int > _bool_control_data_indices
_input_values index for each bool control data value
std::vector< unsigned int > _function_indices
_input_values index for each function value
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:314
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > _initial_values
Initial value for each function input.
const std::vector< std::string > & _symbol_values
Values pairing with symbol_names.
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
const VariableValue & sln() const
auto index_range(const T &sizable)

◆ updateChainControlDataValues()

void ChainControlParsedFunctionWrapper::updateChainControlDataValues ( )
private

Updates control data values in wrapped function.

Definition at line 115 of file ChainControlParsedFunctionWrapper.C.

Referenced by evaluate().

116 {
117  for (const auto i : index_range(_real_control_data_indices))
119 
120  for (const auto i : index_range(_bool_control_data_indices))
122  static_cast<Real>(_bool_control_data_values[i]->get());
123 }
std::vector< ChainControlData< Real > * > _real_control_data_values
Real control data values.
std::vector< ChainControlData< bool > * > _bool_control_data_values
bool control data values
std::vector< unsigned int > _real_control_data_indices
_input_values index for each Real control data value
std::vector< unsigned int > _bool_control_data_indices
_input_values index for each bool control data value
std::vector< Real * > _input_values
libMesh::ParsedFunction input values
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto index_range(const T &sizable)

◆ updateFunctionValues()

void ChainControlParsedFunctionWrapper::updateFunctionValues ( Real  t,
const Point &  pt 
)
private

Updates function values in wrapped function.

Parameters
tTime
pSpatial point

Definition at line 108 of file ChainControlParsedFunctionWrapper.C.

Referenced by evaluate().

109 {
110  for (const auto i : index_range(_function_indices))
112 }
std::vector< const Function * > _function_values
Function values.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::vector< Real * > _input_values
libMesh::ParsedFunction input values
std::vector< unsigned int > _function_indices
_input_values index for each function value
auto index_range(const T &sizable)

◆ updateScalarVariableValues()

void ChainControlParsedFunctionWrapper::updateScalarVariableValues ( )
private

Updates scalar values in wrapped function.

Definition at line 101 of file ChainControlParsedFunctionWrapper.C.

Referenced by evaluate().

102 {
103  for (const auto i : index_range(_scalar_indices))
104  (*_input_values[_scalar_indices[i]]) = (*_scalar_values[i])[0];
105 }
std::vector< const VariableValue * > _scalar_values
Scalar variable values.
std::vector< unsigned int > _scalar_indices
_input_values index for each scalar variable value
std::vector< Real * > _input_values
libMesh::ParsedFunction input values
auto index_range(const T &sizable)

Member Data Documentation

◆ _bool_control_data_indices

std::vector<unsigned int> ChainControlParsedFunctionWrapper::_bool_control_data_indices
private

_input_values index for each bool control data value

Definition at line 95 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs(), and updateChainControlDataValues().

◆ _bool_control_data_values

std::vector<ChainControlData<bool> *> ChainControlParsedFunctionWrapper::_bool_control_data_values
private

bool control data values

Definition at line 97 of file ChainControlParsedFunctionWrapper.h.

Referenced by getBoolChainControlData(), initializeFunctionInputs(), and updateChainControlDataValues().

◆ _chain_control_data_system

ChainControlDataSystem& ChainControlParsedFunctionWrapper::_chain_control_data_system
private

Chain control data system.

Definition at line 116 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs().

◆ _fe_problem

FEProblemBase& ChainControlParsedFunctionWrapper::_fe_problem
private

Problem.

Definition at line 74 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs().

◆ _function_indices

std::vector<unsigned int> ChainControlParsedFunctionWrapper::_function_indices
private

_input_values index for each function value

Definition at line 105 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs(), and updateFunctionValues().

◆ _function_ptr

std::unique_ptr<ParsedFunction<Real> > ChainControlParsedFunctionWrapper::_function_ptr
private

◆ _function_str

const std::string& ChainControlParsedFunctionWrapper::_function_str
private

Function expression.

Definition at line 77 of file ChainControlParsedFunctionWrapper.h.

Referenced by ChainControlParsedFunctionWrapper().

◆ _function_values

std::vector<const Function *> ChainControlParsedFunctionWrapper::_function_values
private

◆ _initial_values

std::vector<Real> ChainControlParsedFunctionWrapper::_initial_values
private

Initial value for each function input.

Definition at line 84 of file ChainControlParsedFunctionWrapper.h.

Referenced by ChainControlParsedFunctionWrapper(), and initializeFunctionInputs().

◆ _input_values

std::vector<Real *> ChainControlParsedFunctionWrapper::_input_values
private

◆ _moose_app

MooseApp& ChainControlParsedFunctionWrapper::_moose_app
private

App.

Definition at line 72 of file ChainControlParsedFunctionWrapper.h.

◆ _real_control_data_indices

std::vector<unsigned int> ChainControlParsedFunctionWrapper::_real_control_data_indices
private

_input_values index for each Real control data value

Definition at line 90 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs(), and updateChainControlDataValues().

◆ _real_control_data_values

std::vector<ChainControlData<Real> *> ChainControlParsedFunctionWrapper::_real_control_data_values
private

Real control data values.

Definition at line 92 of file ChainControlParsedFunctionWrapper.h.

Referenced by getRealChainControlData(), initializeFunctionInputs(), and updateChainControlDataValues().

◆ _scalar_indices

std::vector<unsigned int> ChainControlParsedFunctionWrapper::_scalar_indices
private

_input_values index for each scalar variable value

Definition at line 100 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs(), and updateScalarVariableValues().

◆ _scalar_values

std::vector<const VariableValue *> ChainControlParsedFunctionWrapper::_scalar_values
private

Scalar variable values.

Definition at line 102 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs(), and updateScalarVariableValues().

◆ _symbol_names

const std::vector<std::string>& ChainControlParsedFunctionWrapper::_symbol_names
private

Symbols used in the function expression string.

Definition at line 79 of file ChainControlParsedFunctionWrapper.h.

Referenced by ChainControlParsedFunctionWrapper().

◆ _symbol_values

const std::vector<std::string>& ChainControlParsedFunctionWrapper::_symbol_values
private

Values pairing with symbol_names.

Definition at line 81 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs().

◆ _tid

const THREAD_ID ChainControlParsedFunctionWrapper::_tid
private

Thread id passed from owning object.

Definition at line 113 of file ChainControlParsedFunctionWrapper.h.

Referenced by initializeFunctionInputs().


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