https://mooseframework.inl.gov
SurrogateModelInterface.h
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 
10 #pragma once
11 
12 #include "ParallelUniqueId.h"
13 #include "InputParameters.h"
14 #include "FEProblemBase.h"
15 
16 // Forward declarations
17 class SurrogateModel;
19 
32 {
33 public:
35 
42  SurrogateModelInterface(const MooseObject * moose_object);
43 
45 
50  template <typename T = SurrogateModel>
51  T & getSurrogateModel(const std::string & name) const;
52  template <typename T = SurrogateTrainerBase>
53  T & getSurrogateTrainer(const std::string & name) const;
55 
57 
62  template <typename T = SurrogateModel>
63  T & getSurrogateModelByName(const UserObjectName & name) const;
64  template <typename T = SurrogateTrainerBase>
65  T & getSurrogateTrainerByName(const UserObjectName & name) const;
66 
68 private:
71 
74 
77 };
78 
79 template <typename T>
80 T &
82 {
83  return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84 }
85 
86 template <typename T>
87 T &
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 }
101 
102 template <typename T>
103 T &
105 {
106  return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107 }
108 
109 template <typename T>
110 T &
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 }
const InputParameters & _smi_params
Parameters of the object with this interface.
T & getUserObject(const std::string &name, unsigned int tid=0) const
void mooseError(Args &&... args)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
T & getSurrogateModelByName(const UserObjectName &name) const
Get a sampler with a given name.
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
T & getSurrogateModel(const std::string &name) const
Get a SurrogateModel/Trainer with a given name.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
T & getSurrogateTrainer(const std::string &name) const
Interface for objects that need to use samplers.
Query query()
const THREAD_ID _smi_tid
Thread ID.
T & getSurrogateTrainerByName(const UserObjectName &name) const
This is the base trainer class whose main functionality is the API for declaring model data...
static InputParameters validParams()
SurrogateModelInterface(const MooseObject *moose_object)
unsigned int THREAD_ID