https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ChainControlParsedFunctionWrapper.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 "MooseApp.h"
12#include "FEProblem.h"
13#include "MooseVariableScalar.h"
14#include "Function.h"
15#include "MooseUtils.h"
17
19 MooseApp & moose_app,
20 FEProblemBase & fe_problem,
21 const std::string & function_str,
22 const std::vector<std::string> & symbol_names,
23 const std::vector<std::string> & symbol_values,
24 const THREAD_ID tid)
25 : _moose_app(moose_app),
26 _fe_problem(fe_problem),
27 _function_str(function_str),
28 _symbol_names(symbol_names),
29 _symbol_values(symbol_values),
30 _tid(tid),
31 _chain_control_data_system(_moose_app.getChainControlDataSystem())
32{
34
35 _function_ptr = std::make_unique<ParsedFunction<Real, RealGradient>>(
37
38 for (const auto & symbol_name : _symbol_names)
39 _input_values.push_back(&_function_ptr->getVarAddress(symbol_name));
40}
41
42Real
50
51void
53{
54 for (const auto i : index_range(_symbol_values))
55 {
57 {
59 _initial_values.push_back(data.get());
60 _real_control_data_values.push_back(&data);
61 _real_control_data_indices.push_back(i);
62 }
64 {
66 _initial_values.push_back(data.get());
67 _bool_control_data_values.push_back(&data);
68 _bool_control_data_indices.push_back(i);
69 }
71 {
72 const VariableValue & scalar_val =
74 _initial_values.push_back(0);
75 _scalar_values.push_back(&scalar_val);
76 _scalar_indices.push_back(i);
77 }
79 {
80 const Function & function = _fe_problem.getFunction(_symbol_values[i], _tid);
81 _initial_values.push_back(0);
82 _function_values.push_back(&function);
83 _function_indices.push_back(i);
84 }
85 else if (MooseUtils::isFloat(_symbol_values[i]))
86 {
87 _initial_values.push_back(MooseUtils::convert<Real>(_symbol_values[i], true));
88 }
89 else
90 mooseError("Invalid 'symbol_values' entry '",
92 "'. Valid entries:\n"
93 " - chain control data values (bool or Real)\n"
94 " - function names\n"
95 " - scalar variable names\n"
96 " - constant values");
97 }
98}
99
100void
106
107void
109{
110 for (const auto i : index_range(_function_indices))
111 (*_input_values[_function_indices[i]]) = _function_values[i]->value(t, pt);
112}
113
114void
116{
117 for (const auto i : index_range(_real_control_data_indices))
119
120 for (const auto i : index_range(_bool_control_data_indices))
122 static_cast<Real>(_bool_control_data_values[i]->get());
123}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
OutputTools< Real >::VariableValue VariableValue
Definition MooseTypes.h:348
unsigned int THREAD_ID
Definition MooseTypes.h:237
ChainControlData< T > & getChainControlData(const std::string &data_name)
Gets the chain control data of the given name and type and creates if it does not exist.
bool hasChainControlDataOfType(const std::string &data_name) const
Queries if the chain control data of the given name and type exists.
std::vector< unsigned int > _scalar_indices
_input_values index for each scalar variable value
std::vector< ChainControlData< bool > * > _bool_control_data_values
bool control data values
void updateFunctionValues(Real t, const Point &pt)
Updates function values in wrapped function.
std::vector< ChainControlData< Real > * > _real_control_data_values
Real control data values.
const std::vector< std::string > & _symbol_names
Symbols used in the function expression string.
const THREAD_ID _tid
Thread id passed from owning object.
void updateChainControlDataValues()
Updates control data values in wrapped function.
std::vector< unsigned int > _real_control_data_indices
_input_values index for each Real control data value
void initializeFunctionInputs()
Gets initial value, address, and input index for each function input.
std::vector< Real > _initial_values
Initial value for each function input.
Real evaluate(Real t, const Point &p)
Evaluates the libMesh::ParsedFunction.
const std::string & _function_str
Function expression.
ChainControlDataSystem & _chain_control_data_system
Chain control data system.
void updateScalarVariableValues()
Updates scalar values in wrapped function.
std::vector< const Function * > _function_values
Function values.
std::vector< Real * > _input_values
libMesh::ParsedFunction input values
std::vector< const VariableValue * > _scalar_values
Scalar variable values.
std::vector< unsigned int > _function_indices
_input_values index for each function value
const std::vector< std::string > & _symbol_values
Values pairing with symbol_names.
std::unique_ptr< ParsedFunction< Real > > _function_ptr
Wrapped libMesh::ParsedFunction.
std::vector< unsigned int > _bool_control_data_indices
_input_values index for each bool control data value
ChainControlParsedFunctionWrapper(MooseApp &moose_app, FEProblemBase &fe_problem, const std::string &function_str, const std::vector< std::string > &symbol_names, const std::vector< std::string > &symbol_values, const THREAD_ID tid=0)
Constructor.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual bool hasScalarVariable(const std::string &var_name) const override
Returns a Boolean indicating whether any system contains a variable with the name provided.
virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
Base class for function objects.
Definition Function.h:30
Base class for MOOSE-based applications.
Definition MooseApp.h:110
const VariableValue & sln() const