https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SurrogateModelInterface Class Reference

Interface for objects that need to use samplers. More...

#include <SurrogateModelInterface.h>

Inheritance diagram for SurrogateModelInterface:
[legend]

Public Member Functions

 SurrogateModelInterface (const MooseObject *moose_object)
 
template<>
SurrogateModelgetSurrogateModelByName (const UserObjectName &name) const
 
template<>
SurrogateModelgetSurrogateModel (const std::string &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainerByName (const UserObjectName &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainer (const std::string &name) const
 
template<typename T = SurrogateModel>
TgetSurrogateModel (const std::string &name) const
 Get a SurrogateModel/Trainer with a given name.
 
template<typename T = SurrogateTrainerBase>
TgetSurrogateTrainer (const std::string &name) const
 
template<typename T = SurrogateModel>
TgetSurrogateModelByName (const UserObjectName &name) const
 Get a sampler with a given name.
 
template<typename T = SurrogateTrainerBase>
TgetSurrogateTrainerByName (const UserObjectName &name) const
 

Static Public Member Functions

static InputParameters validParams ()
 

Private Attributes

const InputParameters_smi_params
 Parameters of the object with this interface.
 
FEProblemBase_smi_feproblem
 Reference to FEProblemBase instance.
 
const THREAD_ID _smi_tid
 Thread ID.
 

Detailed Description

Interface for objects that need to use samplers.

This practically adds two methods for getting SurrogateModel objects:

  1. Call getSurrogateModel or getSurrogateModelByName without a template parameter and you will get a SurrogateModel base object (see SurrogateModelInterface.C for the template specialization).
  2. Call getSurrogateModel<MySurrogateModel> or getSurrogateModelByName<MySurrogateModel> to perform a cast to the desired type, as done for UserObjects.

Definition at line 31 of file SurrogateModelInterface.h.

Constructor & Destructor Documentation

◆ SurrogateModelInterface()

SurrogateModelInterface::SurrogateModelInterface ( const MooseObject moose_object)
Parameters
paramsThe parameters used by the object being instantiated. This class needs them so it can get the sampler named in the input file, but the object calling getSurrogateModel only needs to use the name on the left hand side of the statement "sampler = sampler_name"

Definition at line 22 of file SurrogateModelInterface.C.

23 : _smi_params(moose_object->parameters()),
24 _smi_feproblem(*_smi_params.get<FEProblemBase *>("_fe_problem_base")),
26{
27}
unsigned int THREAD_ID
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
bool have_parameter(std::string_view name) const
const InputParameters & parameters() const
const InputParameters & _smi_params
Parameters of the object with this interface.
const THREAD_ID _smi_tid
Thread ID.
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.

Member Function Documentation

◆ getSurrogateModel() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const

Get a SurrogateModel/Trainer with a given name.

Parameters
nameThe name of the parameter key of the sampler to retrieve
Returns
The sampler with name associated with the parameter 'name'

Definition at line 81 of file SurrogateModelInterface.h.

82{
83 return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84}
const std::string name
Definition Setup.h:21

Referenced by SurrogateTrainer::initialize().

◆ getSurrogateModel() [2/2]

template<>
SurrogateModel & SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const

Definition at line 46 of file SurrogateModelInterface.C.

47{
48 return getSurrogateModelByName<SurrogateModel>(_smi_params.get<UserObjectName>(name));
49}

◆ getSurrogateModelByName() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const

Get a sampler with a given name.

Parameters
nameThe name of the sampler to retrieve
Returns
The sampler with name 'name'

Definition at line 88 of file SurrogateModelInterface.h.

89{
90 std::vector<T *> models;
92 .query()
93 .condition<AttribName>(name)
94 .condition<AttribSystem>("SurrogateModel")
95 .queryInto(models);
96 if (models.empty())
97 mooseError("Unable to find a SurrogateModel object of type " + std::string(typeid(T).name()) +
98 " with the name '" + name + "'");
99 return *(models[0]);
100}
const double T
void mooseError(Args &&... args)
TheWarehouse & theWarehouse() const
Query query()

Referenced by CrossValidationScores::CrossValidationScores(), EvaluateSurrogate::EvaluateSurrogate(), and InverseMapping::initialSetup().

◆ getSurrogateModelByName() [2/2]

template<>
SurrogateModel & SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const

Definition at line 31 of file SurrogateModelInterface.C.

32{
33 std::vector<SurrogateModel *> models;
35 .query()
36 .condition<AttribName>(name)
37 .condition<AttribSystem>("SurrogateModel")
38 .queryInto(models);
39 if (models.empty())
40 mooseError("Unable to find a SurrogateModel object with the name '" + name + "'");
41 return *(models[0]);
42}

◆ getSurrogateTrainer() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const

Definition at line 104 of file SurrogateModelInterface.h.

105{
106 return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107}

◆ getSurrogateTrainer() [2/2]

template<>
SurrogateTrainerBase & SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const

Definition at line 60 of file SurrogateModelInterface.C.

61{
62 return getSurrogateTrainerByName<SurrogateTrainerBase>(_smi_params.get<UserObjectName>(name));
63}

◆ getSurrogateTrainerByName() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const

Definition at line 111 of file SurrogateModelInterface.h.

112{
113 SurrogateTrainerBase * base_ptr =
115 T * obj_ptr = dynamic_cast<T *>(base_ptr);
116 if (!obj_ptr)
117 mooseError("Failed to find a SurrogateTrainer object of type " + std::string(typeid(T).name()) +
118 " with the name '",
119 name,
120 "' for the desired type.");
121 return *obj_ptr;
122}
T & getUserObject(const std::string &name, unsigned int tid=0) const
This is the base trainer class whose main functionality is the API for declaring model data.

Referenced by SurrogateTrainerOutput::output().

◆ getSurrogateTrainerByName() [2/2]

template<>
SurrogateTrainerBase & SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const

Definition at line 53 of file SurrogateModelInterface.C.

◆ validParams()

InputParameters SurrogateModelInterface::validParams ( )
static

Member Data Documentation

◆ _smi_feproblem

FEProblemBase& SurrogateModelInterface::_smi_feproblem
private

Reference to FEProblemBase instance.

Definition at line 73 of file SurrogateModelInterface.h.

Referenced by getSurrogateModelByName(), and getSurrogateTrainerByName().

◆ _smi_params

const InputParameters& SurrogateModelInterface::_smi_params
private

Parameters of the object with this interface.

Definition at line 70 of file SurrogateModelInterface.h.

Referenced by getSurrogateModel(), and getSurrogateTrainer().

◆ _smi_tid

const THREAD_ID SurrogateModelInterface::_smi_tid
private

Thread ID.

Definition at line 76 of file SurrogateModelInterface.h.

Referenced by getSurrogateTrainerByName().


The documentation for this class was generated from the following files: