https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MooseParsedFunctionWrapper.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
23class FEProblemBase;
24class Function;
25
34{
35public:
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
76private:
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<libMesh::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
142template <typename T>
143T
144evaluate(Real /*t*/, const Point & /*p*/)
145{
146 mooseError("The evaluate method is not defined for this type.");
147}
148
149template <>
150Real MooseParsedFunctionWrapper::evaluate(Real t, const Point & p);
151
152template <>
153DenseVector<Real> MooseParsedFunctionWrapper::evaluate(Real t, const Point & p);
154
155template <>
156RealVectorValue MooseParsedFunctionWrapper::evaluate(Real t, const Point & p);
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
T evaluate(Real, const Point &)
The general evaluation method is not defined.
unsigned int THREAD_ID
Definition MooseTypes.h:237
char ** vars
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Base class for function objects.
Definition Function.h:30
A wrapper class for creating and evaluating parsed functions via the libMesh::ParsedFunction interfac...
const std::vector< std::string > & _vars
List of variables supplied from the user.
void update()
Updates postprocessor and scalar values for use in the libMesh::ParsedFunction.
T evaluate(Real t, const Point &p)
A template method for performing the evaluation of the libMesh::ParsedFunction Within the source two ...
const std::string & _function_str
Reference to the string containing the function to evaluate.
std::unique_ptr< libMesh::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...
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 Function 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.
virtual ~MooseParsedFunctionWrapper()
Class destruction Deletes the pointer to the dynamically allocated instance of the underlying libMesh...
RealGradient evaluateGradient(Real t, const Point &p)
Evaluate the gradient of the function which libMesh provides through automatic differentiation.
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.
FEProblemBase & _feproblem
Reference to the FEProblemBase object.
std::vector< const Function * > _functions
Vector of Functions this parsed function is using.
Real evaluateDot(Real t, const Point &p)
Evaluate the time derivative of the function which libMesh provides through automatic differentiation...
void updateFunctionValues(Real t, const Point &pt)
Updates function values for use in the libMesh::ParsedFunction.
std::vector< const Real * > _pp_vals
Vector of pointers to postprocessor values this parsed function is using.
std::vector< unsigned int > _pp_index
Stores indices into _addr variable that are connected to Postprocessors.
std::vector< const Real * > _scalar_vals
Vector of pointers to scalar variables values.