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 vals for use by the libMesh::ParsedFunction object allocated in the constructor. More...
 
void update ()
 Updates postprocessor 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 > _vals
 Storage for the values. More...
 
std::unique_ptr< ParsedFunction< Real > > _function_ptr
 Pointer to the libMesh::ParsedFunction object. More...
 
std::vector< unsigned int > _pp_index
 Stores the relative location of variables (in _vars) that are connected to Postprocessors. More...
 
std::vector< const Real * > _pp_vals
 Vector of pointers to PP values. More...
 
std::vector< unsigned int > _scalar_index
 Stores the relative location of variables (in _vars) that are connected to Scalar Variables. More...
 
std::vector< Real * > _scalar_vals
 Vector of pointers to PP values. More...
 
std::vector< Real * > _addr
 Vector of pointers to the variables in libMesh::ParsedFunction. 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 38 of file MooseParsedFunctionWrapper.h.

Constructor & Destructor Documentation

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 20 of file MooseParsedFunctionWrapper.C.

25  : _feproblem(feproblem), _function_str(function_str), _vars(vars), _vals_input(vals), _tid(tid)
26 {
27  // Initialize (prepares Postprocessor values)
28  initialize();
29 
30  // Create the libMesh::ParsedFunction
32  libmesh_make_unique<ParsedFunction<Real, RealGradient>>(_function_str, &_vars, &_vals);
33 
34  // Loop through the Postprocessor and Scalar variables and point the libMesh::ParsedFunction to
35  // the PostprocessorValue
36  for (const auto & index : _pp_index)
37  _addr.push_back(&_function_ptr->getVarAddress(_vars[index]));
38 
39  for (const auto & index : _scalar_index)
40  _addr.push_back(&_function_ptr->getVarAddress(_vars[index]));
41 }
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.
const std::string & _function_str
Reference to the string containing the function to evaluate.
std::vector< Real * > _addr
Vector of pointers to the variables in libMesh::ParsedFunction.
std::vector< unsigned int > _pp_index
Stores the relative location of variables (in _vars) that are connected to Postprocessors.
FEProblemBase & _feproblem
Reference to the FEProblemBase object.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.
std::vector< unsigned int > _scalar_index
Stores the relative location of variables (in _vars) that are connected to Scalar Variables...
void initialize()
Initialization method that prepares the vars and vals for use by the libMesh::ParsedFunction object a...
std::vector< Real > _vals
Storage for the values.
MooseParsedFunctionWrapper::~MooseParsedFunctionWrapper ( )
virtual

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

Definition at line 43 of file MooseParsedFunctionWrapper.C.

43 {}

Member Function Documentation

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

Definition at line 47 of file MooseParsedFunctionWrapper.C.

48 {
49  // Update the postprocessor / libMesh::ParsedFunction references for the desired function
50  update();
51 
52  // Evalute the function that returns a scalar
53  return (*_function_ptr)(p, t);
54 }
void update()
Updates postprocessor values for use in the libMesh::ParsedFunction.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.
template<>
DenseVector<Real> MooseParsedFunctionWrapper::evaluate ( Real  t,
const Point &  p 
)

Definition at line 58 of file MooseParsedFunctionWrapper.C.

59 {
60  update();
61  DenseVector<Real> output(LIBMESH_DIM);
62  (*_function_ptr)(p, t, output);
63  return output;
64 }
void update()
Updates postprocessor values for use in the libMesh::ParsedFunction.
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.

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

Definition at line 68 of file MooseParsedFunctionWrapper.C.

69 {
70  DenseVector<Real> output = evaluate<DenseVector<Real>>(t, p);
71 
72  return RealVectorValue(output(0)
73 #if LIBMESH_DIM > 1
74  ,
75  output(1)
76 #endif
77 #if LIBMESH_DIM > 2
78  ,
79  output(2)
80 #endif
81  );
82 }
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
Real MooseParsedFunctionWrapper::evaluateDot ( Real  t,
const Point &  p 
)

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

Definition at line 95 of file MooseParsedFunctionWrapper.C.

96 {
97  // Update the postprocessor / libMesh::ParsedFunction references for the desired function
98  update();
99 
100  // Evalute the time derivative
101  return _function_ptr->dot(p, t);
102 }
void update()
Updates postprocessor values for use in the libMesh::ParsedFunction.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.
RealGradient MooseParsedFunctionWrapper::evaluateGradient ( Real  t,
const Point &  p 
)

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

Definition at line 85 of file MooseParsedFunctionWrapper.C.

86 {
87  // Update the postprocessor / libMesh::ParsedFunction references for the desired function
88  update();
89 
90  // Evalute the gradient of the function
91  return _function_ptr->gradient(p, t);
92 }
void update()
Updates postprocessor values for use in the libMesh::ParsedFunction.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.
void MooseParsedFunctionWrapper::initialize ( )
private

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

Definition at line 105 of file MooseParsedFunctionWrapper.C.

Referenced by MooseParsedFunctionWrapper().

106 {
107  // Loop through all the input values supplied by the users.
108  for (unsigned int i = 0; i < _vals_input.size(); ++i)
109  {
110  Real tmp; // desired type
111  std::istringstream ss(
112  _vals_input[i]); // istringstream object for conversion from std::string to Real
113 
114  // Case when a Postprocessor is found by the name given in the input values
116  {
117  // The PP value
118  Real & pp_val = _feproblem.getPostprocessorValue(_vals_input[i]);
119 
120  // Store a pointer to the Postprocessor value
121  _pp_vals.push_back(&pp_val);
122 
123  // Store the value for passing to the the libMesh::ParsedFunction
124  _vals.push_back(pp_val);
125 
126  // Store the location of this variable
127  _pp_index.push_back(i);
128  }
129 
130  // Case when a scalar variable is bound by the name given in the input values
132  {
133  // The scalar variable
134  Real & scalar_val = _feproblem.getScalarVariable(_tid, _vals_input[i]).sln()[0];
135 
136  // Store a pointer to the scalar value
137  _scalar_vals.push_back(&scalar_val);
138 
139  // Store the value for passing to the the libMesh::ParsedFunction
140  _vals.push_back(scalar_val);
141 
142  // Store the location of this variable
143  _scalar_index.push_back(i);
144  }
145 
146  // Case when a Real is supplied, convert std::string to Real
147  else
148  {
149  // Use istringstream to convert, if it fails produce an error, otherwise add the variable to
150  // the _vals variable
151  if (!(ss >> tmp) || !ss.eof())
152  mooseError(
153  "The input value '",
154  _vals_input[i],
155  "' was not understood, it must be a Real Number, Postprocessor, or Scalar Variable");
156  else
157  _vals.push_back(tmp);
158  }
159  }
160 }
const THREAD_ID _tid
The thread id passed from owning Function object.
VariableValue & sln()
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
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 MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
std::vector< Real * > _scalar_vals
Vector of pointers to PP values.
std::vector< unsigned int > _pp_index
Stores the relative location of variables (in _vars) that are connected to Postprocessors.
FEProblemBase & _feproblem
Reference to the FEProblemBase object.
virtual bool hasScalarVariable(const std::string &var_name) override
Returns a Boolean indicating whether any system contains a variable with the name provided...
PostprocessorValue & getPostprocessorValue(const PostprocessorName &name)
Get a reference to the value associated with the postprocessor.
std::vector< unsigned int > _scalar_index
Stores the relative location of variables (in _vars) that are connected to Scalar Variables...
std::vector< Real > _vals
Storage for the values.
std::vector< const Real * > _pp_vals
Vector of pointers to PP values.
void MooseParsedFunctionWrapper::update ( )
private

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

Definition at line 163 of file MooseParsedFunctionWrapper.C.

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

164 {
165  for (unsigned int i = 0; i < _pp_index.size(); ++i)
166  (*_addr[i]) = (*_pp_vals[i]);
167 
168  for (unsigned int i = 0; i < _scalar_index.size(); ++i)
169  (*_addr[i]) = (*_scalar_vals[i]);
170 }
std::vector< Real * > _scalar_vals
Vector of pointers to PP values.
std::vector< Real * > _addr
Vector of pointers to the variables in libMesh::ParsedFunction.
std::vector< unsigned int > _pp_index
Stores the relative location of variables (in _vars) that are connected to Postprocessors.
std::vector< unsigned int > _scalar_index
Stores the relative location of variables (in _vars) that are connected to Scalar Variables...
std::vector< const Real * > _pp_vals
Vector of pointers to PP values.

Friends And Related Function Documentation

friend class ParsedFunctionTest
friend

Definition at line 130 of file MooseParsedFunctionWrapper.h.

Member Data Documentation

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

Vector of pointers to the variables in libMesh::ParsedFunction.

Definition at line 113 of file MooseParsedFunctionWrapper.h.

Referenced by MooseParsedFunctionWrapper(), and update().

FEProblemBase& MooseParsedFunctionWrapper::_feproblem
private

Reference to the FEProblemBase object.

Definition at line 83 of file MooseParsedFunctionWrapper.h.

Referenced by initialize().

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

Pointer to the libMesh::ParsedFunction object.

Definition at line 98 of file MooseParsedFunctionWrapper.h.

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

const std::string& MooseParsedFunctionWrapper::_function_str
private

Reference to the string containing the function to evaluate.

Definition at line 86 of file MooseParsedFunctionWrapper.h.

Referenced by MooseParsedFunctionWrapper().

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

Stores the relative location of variables (in _vars) that are connected to Postprocessors.

Definition at line 101 of file MooseParsedFunctionWrapper.h.

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

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

Vector of pointers to PP values.

Definition at line 104 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and update().

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

Stores the relative location of variables (in _vars) that are connected to Scalar Variables.

Definition at line 107 of file MooseParsedFunctionWrapper.h.

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

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

Vector of pointers to PP values.

Definition at line 110 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and update().

const THREAD_ID MooseParsedFunctionWrapper::_tid
private

The thread id passed from owning Function object.

Definition at line 116 of file MooseParsedFunctionWrapper.h.

Referenced by initialize().

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

Storage for the values.

Definition at line 95 of file MooseParsedFunctionWrapper.h.

Referenced by initialize(), and MooseParsedFunctionWrapper().

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

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

Definition at line 92 of file MooseParsedFunctionWrapper.h.

Referenced by initialize().

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

List of variables supplied from the user.

Definition at line 89 of file MooseParsedFunctionWrapper.h.

Referenced by MooseParsedFunctionWrapper().


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