https://mooseframework.inl.gov
LibtorchNeuralNetControl.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 #ifdef LIBTORCH_ENABLED
11 
12 #pragma once
13 
15 #include "Control.h"
16 
26 {
27 public:
29 
32 
34  virtual void execute() override;
35 
41  Real getSignal(const unsigned int signal_index) const;
42 
44  unsigned int numberOfControlSignals() const { return _control_names.size(); }
45 
52 
55 
57  bool hasControlNeuralNet() const { return (_nn != NULL); };
58 
59 protected:
67  void conditionalParameterError(const std::string & param_name,
68  const std::vector<std::string> & conditional_param,
69  bool should_be_defined = true);
70 
72  void updateCurrentResponse();
73 
75  torch::Tensor prepareInputTensor();
76 
78  std::vector<Real> _current_response;
81  std::vector<std::vector<Real>> & _old_responses;
82 
84  const std::vector<std::string> & _control_names;
86  std::vector<Real> _current_control_signals;
87 
89  const std::vector<PostprocessorName> & _response_names;
90 
93  std::vector<const Real *> _response_values;
94 
97  const unsigned int _input_timesteps;
98 
100  const std::vector<Real> _response_shift_factors;
102  const std::vector<Real> _response_scaling_factors;
104  const std::vector<Real> _action_scaling_factors;
105 
109  std::shared_ptr<Moose::LibtorchNeuralNetBase> _nn;
110 };
111 
112 #endif
unsigned int numberOfControlSignals() const
Get the number of controls this object is computing.
A time-dependent, neural network-based control of multiple input parameters.
const std::vector< PostprocessorName > & _response_names
Names of the postprocessors which contain the observations of the system.
const std::vector< Real > _action_scaling_factors
Multipliers for the actions.
std::vector< Real > _current_response
The values of the current observed postprocessor values.
const std::vector< Real > _response_scaling_factors
Scaling constants (multipliers) for the responses.
LibtorchNeuralNetControl(const InputParameters &parameters)
Construct using input parameters.
const Moose::LibtorchNeuralNetBase & controlNeuralNet() const
Return a reference to the stored neural network.
static InputParameters validParams()
std::shared_ptr< Moose::LibtorchNeuralNetBase > _nn
Pointer to the neural net object which is supposed to be used to control the parameter values...
Real getSignal(const unsigned int signal_index) const
Get the (signal_index)-th signal of the control neural net.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
torch::Tensor prepareInputTensor()
Function that prepares the input tensor for the controller neural network.
const std::vector< std::string > & _control_names
The names of the controllable parameters.
bool hasControlNeuralNet() const
Return true if the object already has a neural netwok.
std::vector< std::vector< Real > > & _old_responses
This variable is populated if the controller needs acess to older values of the observed postprocesso...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned int _input_timesteps
Number of timesteps to use as input data from the reporters (this influences how many past results ar...
This base class is meant to gather the functions and members common in every neural network based on ...
Base class for Control objects.
Definition: Control.h:33
const InputParameters & parameters() const
Get the parameters of the object.
virtual void execute() override
Execute neural network to determine the controllable parameter values.
std::vector< const Real * > _response_values
Links to the current response postprocessor values.
void updateCurrentResponse()
Function that updates the values of the current response.
void loadControlNeuralNet(const Moose::LibtorchArtificialNeuralNet &input_nn)
Function responsible for loading the neural network for the controller.
std::vector< Real > _current_control_signals
The control signals from the last evaluation of the controller.
void conditionalParameterError(const std::string &param_name, const std::vector< std::string > &conditional_param, bool should_be_defined=true)
Function responsible for checking for potential user errors in the input file.
const std::vector< Real > _response_shift_factors
Shifting constants for the responses.