www.mooseframework.org
MooseParsedFunctionWrapper.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "MooseError.h"
14 #include "MooseTypes.h"
15 
16 #include "libmesh/parsed_function.h"
17 
18 // C++ includes
19 #include <string>
20 #include <vector>
21 
22 // Forward declarations
23 class FEProblemBase;
24 class Function;
25 
34 {
35 public:
44  const std::string & function_str,
45  const std::vector<std::string> & vars,
46  const std::vector<std::string> & vals,
47  const THREAD_ID tid = 0);
48 
55 
61  template <typename T>
62  T evaluate(Real t, const Point & p);
63 
68  RealGradient evaluateGradient(Real t, const Point & p);
69 
74  Real evaluateDot(Real t, const Point & p);
75 
76 private:
79 
81  const std::string & _function_str;
82 
84  const std::vector<std::string> & _vars;
85 
87  const std::vector<std::string> & _vals_input;
88 
90  std::vector<Real> _initial_vals;
91 
93  std::unique_ptr<ParsedFunction<Real>> _function_ptr;
94 
96  std::vector<unsigned int> _pp_index;
97 
99  std::vector<const Real *> _pp_vals;
100 
102  std::vector<unsigned int> _scalar_index;
103 
105  std::vector<const Real *> _scalar_vals;
106 
108  std::vector<unsigned int> _function_index;
109 
111  std::vector<const Function *> _functions;
112 
114  std::vector<Real *> _addr;
115 
118 
123  void initialize();
124 
128  void update();
129 
133  void updateFunctionValues(Real t, const Point & pt);
134 
135  // moose_unit needs access
136  friend class ParsedFunctionTest;
137 };
138 
142 template <typename T>
143 T
144 evaluate(Real /*t*/, const Point & /*p*/)
145 {
146  mooseError("The evaluate method is not defined for this type.");
147 }
148 
149 template <>
150 Real MooseParsedFunctionWrapper::evaluate(Real t, const Point & p);
151 
152 template <>
153 DenseVector<Real> MooseParsedFunctionWrapper::evaluate(Real t, const Point & p);
154 
155 template <>
Base class for function objects.
Definition: Function.h:37
const THREAD_ID _tid
The thread id passed from owning Function object.
std::vector< const Real * > _scalar_vals
Vector of pointers to scalar variables values.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
Real evaluateDot(Real t, const Point &p)
Evaluate the time derivative of the function which libMesh provides through automatic differentiation...
const std::vector< std::string > & _vals_input
List of the values for the variables supplied by the user.
void updateFunctionValues(Real t, const Point &pt)
Updates function values for use in the libMesh::ParsedFunction.
const std::vector< std::string > & _vars
List of variables supplied from the user.
RealGradient evaluateGradient(Real t, const Point &p)
Evaluate the gradient of the function which libMesh provides through automatic differentiation.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::vector< const Function * > _functions
Vector of Functions this parsed function is using.
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.
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.
T evaluate(Real, const Point &)
The general evaluation method is not defined.
void update()
Updates postprocessor and scalar values for use in the libMesh::ParsedFunction.
virtual ~MooseParsedFunctionWrapper()
Class destruction Deletes the pointer to the dynamically allocated instance of the underlying libMesh...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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.
FEProblemBase & _feproblem
Reference to the FEProblemBase object.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Pointer to 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< unsigned int > _scalar_index
Stores indicies into _addr variable that are connected to Scalar Variables.
T evaluate(Real t, const Point &p)
A template method for performing the evaluation of the libMesh::ParsedFunction Within the source two ...
void initialize()
Initialization method that prepares the _vars and _initial_vals for use by the libMesh::ParsedFunctio...
std::vector< const Real * > _pp_vals
Vector of pointers to postprocessor values this parsed function is using.
A wrapper class for creating and evaluating parsed functions via the libMesh::ParsedFunction interfac...
unsigned int THREAD_ID
Definition: MooseTypes.h:198