https://mooseframework.inl.gov
Loading...
Searching...
No Matches
THMParsedFunctionWrapper.C
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
11#include "Simulation.h"
12#include "FEProblem.h"
13#include "MooseVariableScalar.h"
14#include "Function.h"
15#include "MooseUtils.h"
16
18 FEProblemBase & feproblem,
19 const std::string & function_str,
20 const std::vector<std::string> & vars,
21 const std::vector<std::string> & vals,
22 const THREAD_ID tid)
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}
38
39Real
41{
42 update();
45 return (*_function_ptr)(p, t);
46}
47
48void
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}
88
89void
91{
92 for (unsigned int i = 0; i < _scalar_index.size(); ++i)
93 (*_addr[_scalar_index[i]]) = (*_scalar_vals[i])[0];
94}
95
96void
98{
99 for (unsigned int i = 0; i < _function_index.size(); ++i)
100 (*_addr[_function_index[i]]) = _functions[i]->value(t, pt);
101}
102
103void
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}
const Real p
const double v
unsigned int THREAD_ID
char ** vars
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
Main class for simulation (the driver of the simulation)
Definition Simulation.h:30
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
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.
void update()
Updates scalar values for use in the libMesh::ParsedFunction.
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 > _initial_vals
Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object.
std::vector< ControlData< bool > * > _cd_bool_vals
Vector of pointers to bool 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::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< ControlData< Real > * > _cd_real_vals
Vector of pointers to Real control data values this parsed function is using.
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.
std::vector< Real * > _addr
Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object.
Real evaluate(Real t, const Point &p)
Perform the evaluation of the libMesh::ParsedFunction.
std::vector< const VariableValue * > _scalar_vals
Vector of pointers to scalar variables values.
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.
void updateControlDataValues()
Updates control data values for use in the libMesh::ParsedFunction.
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.
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