https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
17class SurrogateModel;
19
32{
33public:
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
68private:
71
74
77};
78
79template <typename T>
80T &
82{
83 return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84}
85
86template <typename T>
87T &
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
102template <typename T>
103T &
105{
106 return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107}
108
109template <typename T>
110T &
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 double T
void mooseError(Args &&... args)
unsigned int THREAD_ID
const std::string name
Definition Setup.h:21
T & getUserObject(const std::string &name, unsigned int tid=0) const
TheWarehouse & theWarehouse() const
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Interface for objects that need to use samplers.
const InputParameters & _smi_params
Parameters of the object with this interface.
T & getSurrogateTrainer(const std::string &name) const
T & getSurrogateTrainerByName(const UserObjectName &name) const
const THREAD_ID _smi_tid
Thread ID.
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
static InputParameters validParams()
T & getSurrogateModel(const std::string &name) const
Get a SurrogateModel/Trainer with a given name.
T & getSurrogateModelByName(const UserObjectName &name) const
Get a sampler with a given name.
This is the base trainer class whose main functionality is the API for declaring model data.
Query query()