Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
SurrogateModelScalarAux.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 
12 registerMooseObject("StochasticToolsApp", SurrogateModelScalarAux);
13 
16 {
19  params.addClassDescription("Sets a value of a scalar variable based on a surrogate model.");
20  params.addRequiredParam<UserObjectName>("model", "Name of surrogate models.");
21  params.addRequiredParam<std::vector<std::string>>(
22  "parameters",
23  "Parameter values at which the surrogate is evaluated. Accepts scalar variables, "
24  "postprocessors, and real numbers.");
25  return params;
26 }
27 
29  : AuxScalarKernel(parameters), SurrogateModelInterface(this), _model(getSurrogateModel("model"))
30 {
31 }
32 
33 void
35 {
36  const auto parameter_names = getParam<std::vector<std::string>>("parameters");
37  _n_params = parameter_names.size();
38  for (unsigned int j = 0; j < _n_params; ++j)
39  {
40  const auto name = parameter_names[j];
41 
42  // name can be a postprocessor, scalar var, or real number
44  {
45  auto & scalar_val = _sc_fe_problem.getScalarVariable(_tid, name).sln()[0];
46  _scalar_var_params.push_back(&scalar_val);
47  _scalar_var_indices.push_back(j);
48  }
50  {
51  _pp_indices.push_back(j);
53  }
54  else
55  {
56  // first check if the entry is a real
57  std::stringstream ss(name);
58  Real v;
59  ss >> v;
60 
61  if (ss.fail())
62  paramError("parameters",
63  "Parameter ",
64  name,
65  " is not a scalar variable, postprocessor, or real number");
66 
67  _real_params.push_back(v);
68  _real_indices.push_back(j);
69  }
70  }
72  _n_pp = _pp_indices.size();
73  _n_real = _real_indices.size();
74 }
75 
76 Real
78 {
79  std::vector<Real> x(_n_params);
80  // insert scalar variables
81  for (unsigned int j = 0; j < _n_scalar; ++j)
83  // insert postprocessors
84  for (unsigned int j = 0; j < _n_pp; ++j)
85  x[_pp_indices[j]] = *_pp_params[j];
86  // insert real values
87  for (unsigned int j = 0; j < _n_real; ++j)
89  return _model.evaluate(x);
90 }
THREAD_ID _tid
std::vector< unsigned int > _scalar_var_indices
const SurrogateModel & _model
Pointers to surrogate model.
SurrogateModelScalarAux(const InputParameters &parameters)
virtual bool hasScalarVariable(const std::string &var_name) const override
FEProblemBase & _sc_fe_problem
std::vector< unsigned int > _pp_indices
static InputParameters validParams()
virtual const std::string & name() const
registerMooseObject("StochasticToolsApp", SurrogateModelScalarAux)
void addRequiredParam(const std::string &name, const std::string &doc_string)
const std::vector< double > x
virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid, const std::string &var_name) override
bool hasPostprocessorValueByName(const PostprocessorName &name) const
virtual Real evaluate(const std::vector< Real > &x) const
Evaluate surrogate model given a row of parameters.
void paramError(const std::string &param, Args... args) const
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
Interface for objects that need to use samplers.
static InputParameters validParams()
unsigned int _n_params
number of parameters
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
Sets a value of a scalar variable based on a surrogate model.
virtual Real computeValue() override
std::vector< const PostprocessorValue * > _pp_params
the pp parameters that _model is evaluated at
std::vector< Real > _real_params
the real parameters that _model is evaluated at
static InputParameters validParams()
const VariableValue & sln() const
std::vector< unsigned int > _real_indices
std::vector< const Real * > _scalar_var_params
the real parameters that _model is evaluated at