https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
THMParsedFunctionWrapper Class Reference

A wrapper class for creating and evaluating parsed functions via the libMesh::ParsedFunction interface for fparser. More...

#include <THMParsedFunctionWrapper.h>

Public Member Functions

 THMParsedFunctionWrapper (Simulation &sim, FEProblemBase &feproblem, const std::string &function_str, const std::vector< std::string > &vars, const std::vector< std::string > &vals, const THREAD_ID tid=0)
 Class constructor.
 
Real evaluate (Real t, const Point &p)
 Perform the evaluation of the libMesh::ParsedFunction.
 
const std::vector< ControlData< Real > * > getRealControlData ()
 Get list of Real-valued control data objects.
 
const std::vector< ControlData< bool > * > getBoolControlData ()
 Get list of boolean-valued control data objects.
 

Private Member Functions

void initialize ()
 Initialization method that prepares the _vars and _initial_vals for use by the libMesh::ParsedFunction object allocated in the constructor.
 
void update ()
 Updates scalar values for use in the libMesh::ParsedFunction.
 
void updateFunctionValues (Real t, const Point &pt)
 Updates function values for use in the libMesh::ParsedFunction.
 
void updateControlDataValues ()
 Updates control data values for use in the libMesh::ParsedFunction.
 

Private Attributes

Simulation_sim
 Reference to the Simulation object.
 
FEProblemBase_feproblem
 Reference to the FEProblemBase object.
 
const std::string & _function_str
 Reference to the string containing the function to evaluate.
 
const std::vector< std::string > & _vars
 List of variables supplied from the user.
 
const std::vector< std::string > & _vals_input
 List of the values for the variables supplied by the user.
 
std::vector< Real > _initial_vals
 Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object.
 
std::unique_ptr< libMesh::ParsedFunction< Real > > _function_ptr
 Pointer to the libMesh::ParsedFunction object.
 
std::vector< unsigned int_cd_real_index
 Stores _addr variable indices for each ControlData<Real> value.
 
std::vector< ControlData< Real > * > _cd_real_vals
 Vector of pointers to Real control data values this parsed function is using.
 
std::vector< unsigned int_cd_bool_index
 Stores _addr variable indices for each ControlData<bool> value.
 
std::vector< ControlData< bool > * > _cd_bool_vals
 Vector of pointers to bool control data values this parsed function is using.
 
std::vector< unsigned int_scalar_index
 Stores _addr variable indices for each scalar variable value.
 
std::vector< const VariableValue * > _scalar_vals
 Vector of pointers to scalar variables values.
 
std::vector< unsigned int_function_index
 Stores _addr variable indices for each Function.
 
std::vector< const Function * > _functions
 Vector of Functions this parsed function is using.
 
std::vector< Real * > _addr
 Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object.
 
const THREAD_ID _tid
 The thread id passed from owning object.
 

Detailed Description

A wrapper class for creating and evaluating parsed functions via the libMesh::ParsedFunction interface for fparser.

It has the same capability as MooseParsedFunctionWrapper but adds ability to use control data values

Definition at line 28 of file THMParsedFunctionWrapper.h.

Constructor & Destructor Documentation

◆ THMParsedFunctionWrapper()

THMParsedFunctionWrapper::THMParsedFunctionWrapper ( Simulation sim,
FEProblemBase feproblem,
const std::string &  function_str,
const std::vector< std::string > &  vars,
const std::vector< std::string > &  vals,
const THREAD_ID  tid = 0 
)

Class constructor.

Parameters
simReference to the Simulation object (provides access to ControlData)
feproblemReference to the FEProblemBase object (provides access to Postprocessors)
function_strA string that contains the function to evaluate
varsA vector of variable names contained within the function
valsA vector of variable initial values, matching the variables defined in vars

Definition at line 17 of file THMParsedFunctionWrapper.C.

23 : _sim(sim),
24 _feproblem(feproblem),
25 _function_str(function_str),
26 _vars(vars),
27 _vals_input(vals),
28 _tid(tid)
29{
30 initialize();
31
32 _function_ptr = std::make_unique<libMesh::ParsedFunction<Real, RealGradient>>(
34
35 for (auto & v : _vars)
36 _addr.push_back(&_function_ptr->getVarAddress(v));
37}
const double v
FEProblemBase & _feproblem
Reference to the FEProblemBase object.
const std::vector< std::string > & _vals_input
List of the values for the variables supplied by the user.
std::vector< Real > _initial_vals
Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object.
std::unique_ptr< libMesh::ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.
Simulation & _sim
Reference to the Simulation object.
void initialize()
Initialization method that prepares the _vars and _initial_vals for use by the libMesh::ParsedFunctio...
std::vector< Real * > _addr
Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object.
const std::vector< std::string > & _vars
List of variables supplied from the user.
const THREAD_ID _tid
The thread id passed from owning object.
const std::string & _function_str
Reference to the string containing the function to evaluate.

Member Function Documentation

◆ evaluate()

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

Perform the evaluation of the libMesh::ParsedFunction.

Definition at line 40 of file THMParsedFunctionWrapper.C.

41{
42 update();
45 return (*_function_ptr)(p, t);
46}
const Real p
void update()
Updates scalar values for use in the libMesh::ParsedFunction.
void updateFunctionValues(Real t, const Point &pt)
Updates function values for use in the libMesh::ParsedFunction.
void updateControlDataValues()
Updates control data values for use in the libMesh::ParsedFunction.

◆ getBoolControlData()

const std::vector< ControlData< bool > * > THMParsedFunctionWrapper::getBoolControlData ( )
inline

Get list of boolean-valued control data objects.

Definition at line 59 of file THMParsedFunctionWrapper.h.

59{ return _cd_bool_vals; }
std::vector< ControlData< bool > * > _cd_bool_vals
Vector of pointers to bool control data values this parsed function is using.

◆ getRealControlData()

const std::vector< ControlData< Real > * > THMParsedFunctionWrapper::getRealControlData ( )
inline

Get list of Real-valued control data objects.

Definition at line 54 of file THMParsedFunctionWrapper.h.

54{ return _cd_real_vals; }
std::vector< ControlData< Real > * > _cd_real_vals
Vector of pointers to Real control data values this parsed function is using.

◆ initialize()

void THMParsedFunctionWrapper::initialize ( )
private

Initialization method that prepares the _vars and _initial_vals for use by the libMesh::ParsedFunction object allocated in the constructor.

Definition at line 49 of file THMParsedFunctionWrapper.C.

50{
51 for (unsigned int i = 0; i < _vals_input.size(); ++i)
52 {
53 if (_sim.hasControlData<Real>(_vals_input[i]))
54 {
56 _initial_vals.push_back(cd_val->get());
57 _cd_real_vals.push_back(cd_val);
58 _cd_real_index.push_back(i);
59 }
60 else if (_sim.hasControlData<bool>(_vals_input[i]))
61 {
63 _initial_vals.push_back(cd_val->get());
64 _cd_bool_vals.push_back(cd_val);
65 _cd_bool_index.push_back(i);
66 }
68 {
70 _initial_vals.push_back(0);
71 _scalar_vals.push_back(&scalar_val);
72 _scalar_index.push_back(i);
73 }
75 {
77 _initial_vals.push_back(0);
78 _functions.push_back(&fn);
79 _function_index.push_back(i);
80 }
81 else
82 {
83 Real val = MooseUtils::convert<Real>(_vals_input[i], true);
84 _initial_vals.push_back(val);
85 }
86 }
87}
Concrete definition of a parameter value for a specified type.
Definition ControlData.h:92
const T & get() const
virtual bool hasScalarVariable(const std::string &var_name) const override
virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid, const std::string &var_name) override
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
const VariableValue & sln() const
bool hasControlData(const std::string &name)
Query if control data with name 'name' exists.
Definition Simulation.h:275
ControlData< T > * getControlData(const std::string &name)
Get control data of type T and name 'name', if it does not exist it will be created.
Definition Simulation.h:290
std::vector< unsigned int > _function_index
Stores _addr variable indices for each Function.
std::vector< const Function * > _functions
Vector of Functions this parsed function is using.
std::vector< unsigned int > _cd_bool_index
Stores _addr variable indices for each ControlData<bool> value.
std::vector< const VariableValue * > _scalar_vals
Vector of pointers to scalar variables values.
std::vector< unsigned int > _cd_real_index
Stores _addr variable indices for each ControlData<Real> value.
std::vector< unsigned int > _scalar_index
Stores _addr variable indices for each scalar variable value.
VariableValueTempl< false > VariableValue
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Referenced by THMParsedFunctionWrapper().

◆ update()

void THMParsedFunctionWrapper::update ( )
private

Updates scalar values for use in the libMesh::ParsedFunction.

Definition at line 90 of file THMParsedFunctionWrapper.C.

91{
92 for (unsigned int i = 0; i < _scalar_index.size(); ++i)
93 (*_addr[_scalar_index[i]]) = (*_scalar_vals[i])[0];
94}

Referenced by evaluate().

◆ updateControlDataValues()

void THMParsedFunctionWrapper::updateControlDataValues ( )
private

Updates control data values for use in the libMesh::ParsedFunction.

Definition at line 104 of file THMParsedFunctionWrapper.C.

105{
106 for (unsigned int i = 0; i < _cd_real_index.size(); ++i)
107 (*_addr[_cd_real_index[i]]) = _cd_real_vals[i]->get();
108
109 for (unsigned int i = 0; i < _cd_bool_index.size(); ++i)
110 (*_addr[_cd_bool_index[i]]) = static_cast<Real>(_cd_bool_vals[i]->get());
111}

Referenced by evaluate().

◆ updateFunctionValues()

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

Updates function values for use in the libMesh::ParsedFunction.

Definition at line 97 of file THMParsedFunctionWrapper.C.

98{
99 for (unsigned int i = 0; i < _function_index.size(); ++i)
100 (*_addr[_function_index[i]]) = _functions[i]->value(t, pt);
101}

Referenced by evaluate().

Member Data Documentation

◆ _addr

std::vector<Real *> THMParsedFunctionWrapper::_addr
private

Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object.

Definition at line 108 of file THMParsedFunctionWrapper.h.

Referenced by THMParsedFunctionWrapper(), update(), updateControlDataValues(), and updateFunctionValues().

◆ _cd_bool_index

std::vector<unsigned int> THMParsedFunctionWrapper::_cd_bool_index
private

Stores _addr variable indices for each ControlData<bool> value.

Definition at line 90 of file THMParsedFunctionWrapper.h.

Referenced by initialize(), and updateControlDataValues().

◆ _cd_bool_vals

std::vector<ControlData<bool> *> THMParsedFunctionWrapper::_cd_bool_vals
private

Vector of pointers to bool control data values this parsed function is using.

Definition at line 93 of file THMParsedFunctionWrapper.h.

Referenced by getBoolControlData(), initialize(), and updateControlDataValues().

◆ _cd_real_index

std::vector<unsigned int> THMParsedFunctionWrapper::_cd_real_index
private

Stores _addr variable indices for each ControlData<Real> value.

Definition at line 84 of file THMParsedFunctionWrapper.h.

Referenced by initialize(), and updateControlDataValues().

◆ _cd_real_vals

std::vector<ControlData<Real> *> THMParsedFunctionWrapper::_cd_real_vals
private

Vector of pointers to Real control data values this parsed function is using.

Definition at line 87 of file THMParsedFunctionWrapper.h.

Referenced by getRealControlData(), initialize(), and updateControlDataValues().

◆ _feproblem

FEProblemBase& THMParsedFunctionWrapper::_feproblem
private

Reference to the FEProblemBase object.

Definition at line 66 of file THMParsedFunctionWrapper.h.

Referenced by initialize().

◆ _function_index

std::vector<unsigned int> THMParsedFunctionWrapper::_function_index
private

Stores _addr variable indices for each Function.

Definition at line 102 of file THMParsedFunctionWrapper.h.

Referenced by initialize(), and updateFunctionValues().

◆ _function_ptr

std::unique_ptr<libMesh::ParsedFunction<Real> > THMParsedFunctionWrapper::_function_ptr
private

Pointer to the libMesh::ParsedFunction object.

Definition at line 81 of file THMParsedFunctionWrapper.h.

Referenced by evaluate(), and THMParsedFunctionWrapper().

◆ _function_str

const std::string& THMParsedFunctionWrapper::_function_str
private

Reference to the string containing the function to evaluate.

Definition at line 69 of file THMParsedFunctionWrapper.h.

Referenced by THMParsedFunctionWrapper().

◆ _functions

std::vector<const Function *> THMParsedFunctionWrapper::_functions
private

Vector of Functions this parsed function is using.

Definition at line 105 of file THMParsedFunctionWrapper.h.

Referenced by initialize(), and updateFunctionValues().

◆ _initial_vals

std::vector<Real> THMParsedFunctionWrapper::_initial_vals
private

Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object.

Definition at line 78 of file THMParsedFunctionWrapper.h.

Referenced by initialize(), and THMParsedFunctionWrapper().

◆ _scalar_index

std::vector<unsigned int> THMParsedFunctionWrapper::_scalar_index
private

Stores _addr variable indices for each scalar variable value.

Definition at line 96 of file THMParsedFunctionWrapper.h.

Referenced by initialize(), and update().

◆ _scalar_vals

std::vector<const VariableValue *> THMParsedFunctionWrapper::_scalar_vals
private

Vector of pointers to scalar variables values.

Definition at line 99 of file THMParsedFunctionWrapper.h.

Referenced by initialize(), and update().

◆ _sim

Simulation& THMParsedFunctionWrapper::_sim
private

Reference to the Simulation object.

Definition at line 63 of file THMParsedFunctionWrapper.h.

Referenced by initialize().

◆ _tid

const THREAD_ID THMParsedFunctionWrapper::_tid
private

The thread id passed from owning object.

Definition at line 111 of file THMParsedFunctionWrapper.h.

Referenced by initialize().

◆ _vals_input

const std::vector<std::string>& THMParsedFunctionWrapper::_vals_input
private

List of the values for the variables supplied by the user.

Definition at line 75 of file THMParsedFunctionWrapper.h.

Referenced by initialize().

◆ _vars

const std::vector<std::string>& THMParsedFunctionWrapper::_vars
private

List of variables supplied from the user.

Definition at line 72 of file THMParsedFunctionWrapper.h.

Referenced by THMParsedFunctionWrapper().


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