20 template <
typename ComputeValueType>
27 params.
addRequiredParam<UserObjectName>(
"model",
"Name of surrogate models.");
30 "Parameter values at which the surrogate is evaluated. These can be post-processors, " 31 "functions, variables, or constant numbers.");
32 params.
addParam<std::vector<std::string>>(
34 std::vector<std::string>(),
35 "Parameters in 'parameters' that are post-processors or functions.");
37 "Parameters in 'parameters' that are standard variables.");
39 "Parameters in 'parameters' that are array variables.");
40 if constexpr (!std::is_same<ComputeValueType, RealEigenVector>::value)
45 template <
typename ComputeValueType>
50 _model(getSurrogateModel(
"model")),
51 _n_params(this->template getParam<
std::vector<
std::string>>(
"parameters").size())
53 const auto & params = this->
template getParam<std::vector<std::string>>(
"parameters");
54 const auto & scalar_params =
55 this->
template getParam<std::vector<std::string>>(
"scalar_parameters");
56 const auto var_params = this->
coupledNames(
"coupled_variables");
57 const auto array_var_params = this->
coupledNames(
"coupled_array_variables");
61 const auto & param = params[p];
64 auto sit = std::find(scalar_params.begin(), scalar_params.end(), param);
65 auto vit = std::find(var_params.begin(), var_params.end(), param);
66 auto ait = std::find(array_var_params.begin(), array_var_params.end(), param);
69 if (sit != scalar_params.end())
79 "scalar_parameters",
"'", param,
"' is not a postprocessor or a function.");
82 else if (vit != var_params.end())
84 auto index = std::distance(var_params.begin(), vit);
88 else if (ait != array_var_params.end())
90 auto index = std::distance(array_var_params.begin(), ait);
92 const auto & cvar = *this->
getArrayVar(
"coupled_array_variables", index);
95 "The number of components in '",
99 ") does not match the number of components in '",
110 val = MooseUtils::convert<Real>(param,
true);
112 catch (
const std::invalid_argument &)
117 "' is not listed in 'scalar_parameters', 'coupled_variables', or " 118 "'coupled_array_variables'.");
124 template <
typename ComputeValueType>
128 std::vector<Real>
x(_n_params);
130 for (
const auto & [p, pp_ptr] : _pp_params)
133 for (
const auto & [p, fun_ptr] : _function_params)
134 x[p] = fun_ptr->value(this->_t, this->_q_point[this->_qp]);
136 for (
const auto & [p, var_ptr] : _var_params)
137 x[p] = (*var_ptr)[this->_qp];
139 for (
const auto & [p,
v] : _constant_params)
142 return _model.evaluate(
x);
149 std::vector<Real>
x(_n_params);
152 for (
const auto & [p, pp_ptr] : _pp_params)
155 for (
const auto & [p, fun_ptr] : _function_params)
156 x[p] = fun_ptr->value(this->_t, this->_q_point[this->_qp]);
158 for (
const auto & [p, var_ptr] : _var_params)
159 x[p] = (*var_ptr)[this->_qp];
161 for (
const auto & [p,
v] : _constant_params)
167 for (
const auto & [p, avar_ptr] : _array_var_params)
168 x[p] = (*avar_ptr)[this->_qp](
c);
169 val(
c) = _model.evaluate(
x);
virtual ComputeValueType computeValue() override
SurrogateModelAuxKernelTempl(const InputParameters ¶meters)
unsigned int count() const
const std::string & name() const override
std::vector< VariableName > coupledNames(const std::string &var_name) const
registerMooseObject("StochasticToolsApp", SurrogateModelAuxKernel)
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0) const
const std::vector< double > x
bool hasPostprocessorByName(const PostprocessorName &name) const
virtual const ArrayVariableValue & coupledArrayValue(const std::string &var_name, unsigned int comp=0) const
bool hasFunctionByName(const FunctionName &name) const
std::map< unsigned int, const PostprocessorValue * > _pp_params
The pp parameters that _model is evaluated at.
static InputParameters validParams()
std::map< unsigned int, const Function * > _function_params
The function parameters that _model is evaluated at.
void paramError(const std::string ¶m, Args... args) const
const unsigned int _n_params
number of parameters
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name) const
std::map< unsigned int, const ArrayVariableValue * > _array_var_params
The array variable parameters that _model is evaluated at.
std::map< unsigned int, Real > _constant_params
Constant parameters that _model is evaluated at.
Sets a value of auxiliary variables based on a surrogate model.
MooseVariableField< ComputeValueType > & _var
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
const Function & getFunctionByName(const FunctionName &name) const
Interface for objects that need to use samplers.
ArrayMooseVariable * getArrayVar(const std::string &var_name, unsigned int comp)
IntRange< T > make_range(T beg, T end)
static InputParameters validParams()
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
std::map< unsigned int, const VariableValue * > _var_params
The standard variable parameters that _model is evaluated at.
static InputParameters validParams()