www.mooseframework.org
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
MooseParsedFunctionWrapper Class Reference

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

#include <MooseParsedFunctionWrapper.h>

Public Member Functions

 MooseParsedFunctionWrapper (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. More...
 
virtual ~MooseParsedFunctionWrapper ()
 Class destruction Deletes the pointer to the dynamically allocated instance of the underlying libMesh::ParsedFunction. More...
 
template<typename T >
evaluate (Real t, const Point &p)
 A template method for performing the evaluation of the libMesh::ParsedFunction Within the source two specializations exists for returning a scalar or vector; template specialization was utilized to allow for generic expansion. More...
 
RealGradient evaluateGradient (Real t, const Point &p)
 Evaluate the gradient of the function which libMesh provides through automatic differentiation. More...
 
Real evaluateDot (Real t, const Point &p)
 Evaluate the time derivative of the function which libMesh provides through automatic differentiation. More...
 
template<>
Real evaluate (Real t, const Point &p)
 
template<>
DenseVector< Real > evaluate (Real t, const Point &p)
 
template<>
RealVectorValue evaluate (Real t, const Point &p)
 

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. More...
 
void update ()
 Updates postprocessor and scalar values for use in the libMesh::ParsedFunction. More...
 
void updateFunctionValues (Real t, const Point &pt)
 Updates function values for use in the libMesh::ParsedFunction. More...
 

Private Attributes

FEProblemBase_feproblem
 Reference to the FEProblemBase object. More...
 
const std::string & _function_str
 Reference to the string containing the function to evaluate. More...
 
const std::vector< std::string > & _vars
 List of variables supplied from the user. More...
 
const std::vector< std::string > & _vals_input
 List of the values for the variables supplied by the user. More...
 
std::vector< Real > _initial_vals
 Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object. More...
 
std::unique_ptr< ParsedFunction< Real > > _function_ptr
 Pointer to the libMesh::ParsedFunction object. More...
 
std::vector< unsigned int > _pp_index
 Stores indices into _addr variable that are connected to Postprocessors. More...
 
std::vector< const Real * > _pp_vals
 Vector of pointers to postprocessor values this parsed function is using. More...
 
std::vector< unsigned int > _scalar_index
 Stores indicies into _addr variable that are connected to Scalar Variables. More...
 
std::vector< Real * > _scalar_vals
 Vector of pointers to scalar variables values. More...
 
std::vector< unsigned int > _function_index
 Stores indices into _addr that are connected to Functions this libMesh::ParsedFunction is using. More...
 
std::vector< Function * > _functions
 Vector of Functions this parsed function is using. More...
 
std::vector< Real * > _addr
 Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object. More...
 
const THREAD_ID _tid
 The thread id passed from owning Function object. More...
 

Friends

class ParsedFunctionTest
 

Detailed Description

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

See also
MooseParsedFunction
MooseParsedGradFunction
MooseParsedVectorFunction

Definition at line 34 of file MooseParsedFunctionWrapper.h.

Constructor & Destructor Documentation

◆ MooseParsedFunctionWrapper()

MooseParsedFunctionWrapper::MooseParsedFunctionWrapper ( 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
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 values, matching the variables defined in vars

Definition at line 16 of file MooseParsedFunctionWrapper.C.

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

◆ ~MooseParsedFunctionWrapper()

MooseParsedFunctionWrapper::~MooseParsedFunctionWrapper ( )
virtual

Class destruction Deletes the pointer to the dynamically allocated instance of the underlying libMesh::ParsedFunction.

Definition at line 32 of file MooseParsedFunctionWrapper.C.

32 {}

Member Function Documentation

◆ evaluate() [1/4]

template<typename T >
T MooseParsedFunctionWrapper::evaluate ( Real  t,
const Point &  p 
)

A template method for performing the evaluation of the libMesh::ParsedFunction Within the source two specializations exists for returning a scalar or vector; template specialization was utilized to allow for generic expansion.

◆ evaluate() [2/4]

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

Definition at line 36 of file MooseParsedFunctionWrapper.C.

37 {
38  update();
40  return (*_function_ptr)(p, t);
41 }
void updateFunctionValues(Real t, const Point &pt)
Updates function values for use in the libMesh::ParsedFunction.
void update()
Updates postprocessor and scalar values for use in the libMesh::ParsedFunction.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.

◆ evaluate() [3/4]

DenseVector< Real > MooseParsedFunctionWrapper::evaluate ( Real  t,
const Point &  p 
)

Definition at line 45 of file MooseParsedFunctionWrapper.C.

46 {
47  update();
49  DenseVector<Real> output(LIBMESH_DIM);
50  (*_function_ptr)(p, t, output);
51  return output;
52 }
void updateFunctionValues(Real t, const Point &pt)
Updates function values for use in the libMesh::ParsedFunction.
void update()
Updates postprocessor and scalar values for use in the libMesh::ParsedFunction.

◆ evaluate() [4/4]

RealVectorValue MooseParsedFunctionWrapper::evaluate ( Real  t,
const Point &  p 
)

Definition at line 56 of file MooseParsedFunctionWrapper.C.

57 {
58  DenseVector<Real> output = evaluate<DenseVector<Real>>(t, p);
59 
60  return RealVectorValue(output(0)
61 #if LIBMESH_DIM > 1
62  ,
63  output(1)
64 #endif
65 #if LIBMESH_DIM > 2
66  ,
67  output(2)
68 #endif
69  );
70 }

◆ evaluateDot()

Real MooseParsedFunctionWrapper::evaluateDot ( Real  t,
const Point &  p 
)

Evaluate the time derivative of the function which libMesh provides through automatic differentiation.

Definition at line 81 of file MooseParsedFunctionWrapper.C.

82 {
83  update();
85  return _function_ptr->dot(p, t);
86 }
void updateFunctionValues(Real t, const Point &pt)
Updates function values for use in the libMesh::ParsedFunction.
void update()
Updates postprocessor and scalar values for use in the libMesh::ParsedFunction.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.

◆ evaluateGradient()

RealGradient MooseParsedFunctionWrapper::evaluateGradient ( Real  t,
const Point &  p 
)

Evaluate the gradient of the function which libMesh provides through automatic differentiation.

Definition at line 73 of file MooseParsedFunctionWrapper.C.

74 {
75  update();
77  return _function_ptr->gradient(p, t);
78 }
void updateFunctionValues(Real t, const Point &pt)
Updates function values for use in the libMesh::ParsedFunction.
void update()
Updates postprocessor and scalar values for use in the libMesh::ParsedFunction.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.

◆ initialize()

void MooseParsedFunctionWrapper::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 89 of file MooseParsedFunctionWrapper.C.

Referenced by MooseParsedFunctionWrapper().

90 {
91  // Loop through all the input values supplied by the users.
92  for (unsigned int i = 0; i < _vals_input.size(); ++i)
93  {
94  // Case when a Postprocessor is found by the name given in the input values
96  {
97  Real & pp_val = _feproblem.getPostprocessorValue(_vals_input[i]);
98  _initial_vals.push_back(pp_val);
99  _pp_vals.push_back(&pp_val);
100  _pp_index.push_back(i);
101  }
102 
103  // Case when a scalar variable is found by the name given in the input values
105  {
106  Real & scalar_val = _feproblem.getScalarVariable(_tid, _vals_input[i]).sln()[0];
107  _initial_vals.push_back(scalar_val);
108  _scalar_vals.push_back(&scalar_val);
109  _scalar_index.push_back(i);
110  }
111 
112  // Case when a function is found by the name given in the input values
113  else if (_feproblem.hasFunction(_vals_input[i]))
114  {
116  _initial_vals.push_back(0);
117  _functions.push_back(&fn);
118  _function_index.push_back(i);
119  }
120 
121  // Case when a Real is supplied
122  else
123  {
124  Real val = MooseUtils::convert<Real>(_vals_input[i], true);
125  _initial_vals.push_back(val);
126  }
127  }
128 }
Base class for function objects.
Definition: Function.h:41
const THREAD_ID _tid
The thread id passed from owning Function object.
VariableValue & sln()
bool hasPostprocessor(const std::string &name)
Check existence of the postprocessor.
const std::vector< std::string > & _vals_input
List of the values for the variables supplied by the user.
virtual bool hasScalarVariable(const std::string &var_name) const override
Returns a Boolean indicating whether any system contains a variable with the name provided...
virtual bool hasFunction(const std::string &name, THREAD_ID tid=0)
virtual Function & getFunction(const std::string &name, THREAD_ID tid=0)
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
std::vector< Real > _initial_vals
Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object...
std::vector< Real * > _scalar_vals
Vector of pointers to scalar variables values.
std::vector< unsigned int > _pp_index
Stores indices into _addr variable that are connected to Postprocessors.
FEProblemBase & _feproblem
Reference to the FEProblemBase object.
std::vector< unsigned int > _function_index
Stores indices into _addr that are connected to Functions this libMesh::ParsedFunction is using...
PostprocessorValue & getPostprocessorValue(const PostprocessorName &name)
Get a reference to the value associated with the postprocessor.
std::vector< unsigned int > _scalar_index
Stores indicies into _addr variable that are connected to Scalar Variables.
std::vector< const Real * > _pp_vals
Vector of pointers to postprocessor values this parsed function is using.
std::vector< Function * > _functions
Vector of Functions this parsed function is using.

◆ update()

void MooseParsedFunctionWrapper::update ( )
private

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

Definition at line 131 of file MooseParsedFunctionWrapper.C.

Referenced by evaluate(), evaluateDot(), and evaluateGradient().

132 {
133  for (unsigned int i = 0; i < _pp_index.size(); ++i)
134  (*_addr[_pp_index[i]]) = (*_pp_vals[i]);
135 
136  for (unsigned int i = 0; i < _scalar_index.size(); ++i)
137  (*_addr[_scalar_index[i]]) = (*_scalar_vals[i]);
138 }
std::vector< Real * > _scalar_vals
Vector of pointers to scalar variables values.
std::vector< Real * > _addr
Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object...
std::vector< unsigned int > _pp_index
Stores indices into _addr variable that are connected to Postprocessors.
std::vector< unsigned int > _scalar_index
Stores indicies into _addr variable that are connected to Scalar Variables.
std::vector< const Real * > _pp_vals
Vector of pointers to postprocessor values this parsed function is using.

◆ updateFunctionValues()

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

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

Definition at line 141 of file MooseParsedFunctionWrapper.C.

Referenced by evaluate(), evaluateDot(), and evaluateGradient().

142 {
143  for (unsigned int i = 0; i < _function_index.size(); ++i)
144  (*_addr[_function_index[i]]) = _functions[i]->value(t, pt);
145 }
std::vector< Real * > _addr
Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object...
std::vector< unsigned int > _function_index
Stores indices into _addr that are connected to Functions this libMesh::ParsedFunction is using...
std::vector< Function * > _functions
Vector of Functions this parsed function is using.

Friends And Related Function Documentation

◆ ParsedFunctionTest

friend class ParsedFunctionTest
friend

Definition at line 137 of file MooseParsedFunctionWrapper.h.

Member Data Documentation

◆ _addr

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

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

Definition at line 115 of file MooseParsedFunctionWrapper.h.

Referenced by MooseParsedFunctionWrapper(), update(), and updateFunctionValues().

◆ _feproblem

FEProblemBase& MooseParsedFunctionWrapper::_feproblem
private

Reference to the FEProblemBase object.

Definition at line 79 of file MooseParsedFunctionWrapper.h.

Referenced by initialize().

◆ _function_index

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

Stores indices into _addr that are connected to Functions this libMesh::ParsedFunction is using.

Definition at line 109 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and updateFunctionValues().

◆ _function_ptr

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

Pointer to the libMesh::ParsedFunction object.

Definition at line 94 of file MooseParsedFunctionWrapper.h.

Referenced by evaluate(), evaluateDot(), evaluateGradient(), and MooseParsedFunctionWrapper().

◆ _function_str

const std::string& MooseParsedFunctionWrapper::_function_str
private

Reference to the string containing the function to evaluate.

Definition at line 82 of file MooseParsedFunctionWrapper.h.

Referenced by MooseParsedFunctionWrapper().

◆ _functions

std::vector<Function *> MooseParsedFunctionWrapper::_functions
private

Vector of Functions this parsed function is using.

Definition at line 112 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and updateFunctionValues().

◆ _initial_vals

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

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

Definition at line 91 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and MooseParsedFunctionWrapper().

◆ _pp_index

std::vector<unsigned int> MooseParsedFunctionWrapper::_pp_index
private

Stores indices into _addr variable that are connected to Postprocessors.

Definition at line 97 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and update().

◆ _pp_vals

std::vector<const Real *> MooseParsedFunctionWrapper::_pp_vals
private

Vector of pointers to postprocessor values this parsed function is using.

Definition at line 100 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and update().

◆ _scalar_index

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

Stores indicies into _addr variable that are connected to Scalar Variables.

Definition at line 103 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and update().

◆ _scalar_vals

std::vector<Real *> MooseParsedFunctionWrapper::_scalar_vals
private

Vector of pointers to scalar variables values.

Definition at line 106 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and update().

◆ _tid

const THREAD_ID MooseParsedFunctionWrapper::_tid
private

The thread id passed from owning Function object.

Definition at line 118 of file MooseParsedFunctionWrapper.h.

Referenced by initialize().

◆ _vals_input

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

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

Definition at line 88 of file MooseParsedFunctionWrapper.h.

Referenced by initialize().

◆ _vars

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

List of variables supplied from the user.

Definition at line 85 of file MooseParsedFunctionWrapper.h.

Referenced by MooseParsedFunctionWrapper().


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