https://mooseframework.inl.gov
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 
39 Real
40 THMParsedFunctionWrapper::evaluate(Real t, const Point & p)
41 {
42  update();
45  return (*_function_ptr)(p, t);
46 }
47 
48 void
50 {
51  for (unsigned int i = 0; i < _vals_input.size(); ++i)
52  {
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  {
62  ControlData<bool> * cd_val = _sim.getControlData<bool>(_vals_input[i]);
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  {
69  const VariableValue & scalar_val = _feproblem.getScalarVariable(_tid, _vals_input[i]).sln();
70  _initial_vals.push_back(0);
71  _scalar_vals.push_back(&scalar_val);
72  _scalar_index.push_back(i);
73  }
74  else if (_feproblem.hasFunction(_vals_input[i]))
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 
89 void
91 {
92  for (unsigned int i = 0; i < _scalar_index.size(); ++i)
93  (*_addr[_scalar_index[i]]) = (*_scalar_vals[i])[0];
94 }
95 
96 void
98 {
99  for (unsigned int i = 0; i < _function_index.size(); ++i)
100  (*_addr[_function_index[i]]) = _functions[i]->value(t, pt);
101 }
102 
103 void
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 }
std::unique_ptr< libMesh::ParsedFunction< Real > > _function_ptr
Pointer to the libMesh::ParsedFunction object.
std::vector< unsigned int > _scalar_index
Stores _addr variable indices for each scalar variable value.
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.
Main class for simulation (the driver of the simulation)
Definition: Simulation.h:29
Real evaluate(Real t, const Point &p)
Perform the evaluation of the libMesh::ParsedFunction.
const std::vector< std::string > & _vars
List of variables supplied from the user.
char ** vars
const THREAD_ID _tid
The thread id passed from owning object.
const T & get() const
Definition: ControlData.h:108
std::vector< const Function * > _functions
Vector of Functions this parsed function is using.
virtual bool hasScalarVariable(const std::string &var_name) const override
std::vector< Real > _initial_vals
Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object...
void updateControlDataValues()
Updates control data values for use in the libMesh::ParsedFunction.
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
std::vector< const VariableValue * > _scalar_vals
Vector of pointers to scalar variables values.
bool hasControlData(const std::string &name)
Query if control data with name &#39;name&#39; exists.
Definition: Simulation.h:275
std::vector< Real * > _addr
Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object...
virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid, const std::string &var_name) override
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.
std::vector< unsigned int > _cd_real_index
Stores _addr variable indices for each ControlData<Real> value.
const std::string & _function_str
Reference to the string containing the function to evaluate.
std::vector< unsigned int > _function_index
Stores _addr variable indices for each Function.
FEProblemBase & _feproblem
Reference to the FEProblemBase object.
OutputTools< Real >::VariableValue VariableValue
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
Simulation & _sim
Reference to the Simulation object.
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.
ControlData< T > * getControlData(const std::string &name)
Get control data of type T and name &#39;name&#39;, if it does not exist it will be created.
Definition: Simulation.h:290
void update()
Updates scalar values for use in the libMesh::ParsedFunction.
void initialize()
Initialization method that prepares the _vars and _initial_vals for use by the libMesh::ParsedFunctio...
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
const VariableValue & sln() const
unsigned int THREAD_ID
std::vector< ControlData< Real > * > _cd_real_vals
Vector of pointers to Real control data values this parsed function is using.