https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
LibtorchNeuralNetControlTransfer Class Reference

#include <LibtorchNeuralNetControlTransfer.h>

Inheritance diagram for LibtorchNeuralNetControlTransfer:
[legend]

Public Types

enum  DIRECTION
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 LibtorchNeuralNetControlTransfer (const InputParameters &parameters)
 
virtual void execute () override
 
void variableIntegrityCheck (const AuxVariableName &var_name, bool is_from_multiapp) const
 
void initialSetup () override
 
const std::shared_ptr< MultiAppgetMultiApp () const
 
const std::shared_ptr< MultiAppgetFromMultiApp () const
 
const std::shared_ptr< MultiAppgetToMultiApp () const
 
std::string getFromName () const
 
std::string getToName () const
 
bool hasFromMultiApp () const
 
bool hasToMultiApp () const
 
virtual void getAppInfo ()
 
const MultiMooseEnumdirections ()
 
void setCurrentDirection (const int direction)
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
PerfGraphperfGraph ()
 
MooseEnum direction ()
 
MooseEnum direction ()
 
MooseEnum currentDirection ()
 
MooseEnum currentDirection ()
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
template<>
SurrogateModelgetSurrogateModel (const std::string &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainer (const std::string &name) const
 
template<>
SurrogateModelgetSurrogateModelByName (const UserObjectName &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainerByName (const UserObjectName &name) const
 
template<typename T = SurrogateModel>
T & getSurrogateModel (const std::string &name) const
 Get a SurrogateModel/Trainer with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainer (const std::string &name) const
 
template<typename T = SurrogateModel>
T & getSurrogateModelByName (const UserObjectName &name) const
 Get a sampler with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainerByName (const UserObjectName &name) const
 

Static Public Member Functions

static InputParameters validParams ()
 
static void addSkipCoordCollapsingParam (InputParameters &params)
 
static libMesh::Systemfind_sys (libMesh::EquationSystems &es, const std::string &var_name)
 
static std::string possibleDirections ()
 

Public Attributes

 TO_MULTIAPP
 
 FROM_MULTIAPP
 
 BETWEEN_MULTIAPP
 
const ConsoleStream _console
 

Static Public Attributes

static const libMesh::Number OutOfMeshValue
 

Protected Member Functions

std::vector< unsigned intgetFromsPerProc ()
 
libMesh::NumericVector< Real > & getTransferVector (unsigned int i_local, std::string var_name)
 
unsigned int getGlobalSourceAppIndex (unsigned int i_from) const
 
unsigned int getGlobalTargetAppIndex (unsigned int i_to) const
 
unsigned int getLocalSourceAppIndex (unsigned int i_from) const
 
virtual void checkSiblingsTransferSupported () const
 
void errorIfObjectExecutesOnTransferInSourceApp (const std::string &object_name) const
 
Point getPointInTargetAppFrame (const Point &p, unsigned int local_i_to, const std::string &phase) const
 
void checkMultiAppExecuteOn ()
 
void checkVariable (const FEProblemBase &fe_problem, const VariableName &var_name, const std::string &param_name="") const
 
void extendBoundingBoxes (const Real factor, std::vector< libMesh::BoundingBox > &bboxes) const
 
T & declareRestartableData (const std::string &data_name, Args &&... args)
 
ManagedValue< T > declareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
const T & getRestartableData (const std::string &data_name) const
 
T & declareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
T & declareRecoverableData (const std::string &data_name, Args &&... args)
 
T & declareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 
T & declareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 
std::string restartableName (const std::string &data_name) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
std::vector< libMesh::BoundingBoxgetFromBoundingBoxes ()
 
std::vector< libMesh::BoundingBoxgetFromBoundingBoxes (BoundaryID boundary_id)
 
std::vector< libMesh::BoundingBoxgetFromBoundingBoxes ()
 
std::vector< libMesh::BoundingBoxgetFromBoundingBoxes (BoundaryID boundary_id)
 

Static Protected Member Functions

static void addBBoxFactorParam (InputParameters &params)
 
static void transformBoundingBox (libMesh::BoundingBox &box, const MultiAppCoordTransform &transform)
 

Protected Attributes

const std::string _control_name
 The name of the control object on the other app where we want to copy our neural net. More...
 
const LibtorchDRLControlTrainer_trainer
 The trainer object which will contains the control neural net. More...
 
std::shared_ptr< MultiApp_multi_app
 
std::vector< FEProblemBase *> _to_problems
 
std::vector< FEProblemBase *> _from_problems
 
std::vector< libMesh::EquationSystems *> _to_es
 
std::vector< libMesh::EquationSystems *> _from_es
 
std::vector< MooseMesh *> _to_meshes
 
std::vector< MooseMesh *> _from_meshes
 
std::vector< Point > _to_positions
 
std::vector< Point > _from_positions
 
std::vector< std::unique_ptr< MultiAppCoordTransform > > _to_transforms
 
std::vector< std::unique_ptr< MultiAppCoordTransform > > _from_transforms
 
const bool _skip_coordinate_collapsing
 
bool _displaced_source_mesh
 
bool _displaced_target_mesh
 
Real _bbox_factor
 
std::vector< unsigned int_to_local2global_map
 
std::vector< unsigned int_from_local2global_map
 
SubProblem_subproblem
 
FEProblemBase_fe_problem
 
SystemBase_sys
 
THREAD_ID _tid
 
MultiMooseEnum _directions
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const ExecFlagEnum_execute_enum
 
const ExecFlagType_current_execute_flag
 
MooseApp_restartable_app
 
const std::string _restartable_system_name
 
const THREAD_ID _restartable_tid
 
const bool _restartable_read_only
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
MooseEnum _direction
 
MooseEnum _current_direction
 
const Parallel::Communicator & _communicator
 

Detailed Description

Definition at line 20 of file LibtorchNeuralNetControlTransfer.h.

Constructor & Destructor Documentation

◆ LibtorchNeuralNetControlTransfer()

LibtorchNeuralNetControlTransfer::LibtorchNeuralNetControlTransfer ( const InputParameters parameters)

Definition at line 37 of file LibtorchNeuralNetControlTransfer.C.

41  _control_name(getParam<std::string>("control_name")),
42  _trainer(getSurrogateTrainerByName<LibtorchDRLControlTrainer>(
43  getParam<UserObjectName>("trainer_name")))
44 {
45 }
const LibtorchDRLControlTrainer & _trainer
The trainer object which will contains the control neural net.
MultiAppTransfer(const InputParameters &parameters)
const std::string _control_name
The name of the control object on the other app where we want to copy our neural net.
const InputParameters & parameters() const
SurrogateModelInterface(const MooseObject *moose_object)

Member Function Documentation

◆ execute()

void LibtorchNeuralNetControlTransfer::execute ( )
overridevirtual

Implements MultiAppTransfer.

Definition at line 48 of file LibtorchNeuralNetControlTransfer.C.

49 {
50  // Get the control neural net from the trainer
52 
53  // Get the control object from the other app
54  FEProblemBase & app_problem = _multi_app->appProblemBase(0);
55  auto & control_warehouse = app_problem.getControlWarehouse();
56  std::shared_ptr<Control> control_ptr = control_warehouse.getActiveObject(_control_name);
57  LibtorchNeuralNetControl * control_object =
58  dynamic_cast<LibtorchNeuralNetControl *>(control_ptr.get());
59 
60  if (!control_object)
61  paramError("control_name", "The given gontrol is not a LibtorchNeuralNetrControl!");
62 
63  // Copy and the neural net and execute it to get the initial values
64  control_object->loadControlNeuralNet(trainer_nn);
65  control_object->execute();
66 }
const LibtorchDRLControlTrainer & _trainer
The trainer object which will contains the control neural net.
std::shared_ptr< MultiApp > _multi_app
std::shared_ptr< Control > getActiveObject(const std::string &name, THREAD_ID tid=0) const
const Moose::LibtorchArtificialNeuralNet & controlNeuralNet() const
const std::string _control_name
The name of the control object on the other app where we want to copy our neural net.
void paramError(const std::string &param, Args... args) const
virtual void execute() override
ExecuteMooseObjectWarehouse< Control > & getControlWarehouse()
void loadControlNeuralNet(const Moose::LibtorchArtificialNeuralNet &input_nn)

◆ getSurrogateModel() [1/2]

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

Definition at line 46 of file SurrogateModelInterface.C.

47 {
48  return getSurrogateModelByName<SurrogateModel>(_smi_params.get<UserObjectName>(name));
49 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModel() [2/2]

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

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.

Referenced by SurrogateTrainer::initialize().

82 {
83  return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModelByName() [1/2]

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

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 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateModelByName() [2/2]

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

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.

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

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 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateTrainer() [1/2]

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

Definition at line 104 of file SurrogateModelInterface.h.

105 {
106  return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainer() [2/2]

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

Definition at line 60 of file SurrogateModelInterface.C.

61 {
62  return getSurrogateTrainerByName<SurrogateTrainerBase>(_smi_params.get<UserObjectName>(name));
63 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainerByName() [1/2]

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

Definition at line 53 of file SurrogateModelInterface.C.

54 {
56 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
This is the base trainer class whose main functionality is the API for declaring model data...

◆ getSurrogateTrainerByName() [2/2]

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

Definition at line 111 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainerOutput::output().

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
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
const THREAD_ID _smi_tid
Thread ID.
This is the base trainer class whose main functionality is the API for declaring model data...

◆ validParams()

InputParameters LibtorchNeuralNetControlTransfer::validParams ( )
static

Definition at line 18 of file LibtorchNeuralNetControlTransfer.C.

19 {
22 
23  params.addClassDescription("Copies a neural network from a trainer object on the main app to a "
24  "LibtorchNeuralNetControl object on the subapp.");
25 
26  params.suppressParameter<MultiAppName>("from_multi_app");
27  params.suppressParameter<MultiAppName>("multi_app");
28  params.suppressParameter<MultiMooseEnum>("direction");
29 
30  params.addRequiredParam<UserObjectName>("trainer_name",
31  "Trainer object that contains the neural networks."
32  " for different samples.");
33  params.addRequiredParam<std::string>("control_name", "Controller object name.");
34  return params;
35 }
void addRequiredParam(const std::string &name, const std::string &doc_string)
void suppressParameter(const std::string &name)
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()

Member Data Documentation

◆ _control_name

const std::string LibtorchNeuralNetControlTransfer::_control_name
protected

The name of the control object on the other app where we want to copy our neural net.

Definition at line 31 of file LibtorchNeuralNetControlTransfer.h.

Referenced by execute().

◆ _trainer

const LibtorchDRLControlTrainer& LibtorchNeuralNetControlTransfer::_trainer
protected

The trainer object which will contains the control neural net.

Definition at line 34 of file LibtorchNeuralNetControlTransfer.h.

Referenced by execute().


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