https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 MOOSE_LIBTORCH_ENABLED
11
12#pragma once
13
15#include "Control.h"
16
26{
27public:
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
59protected:
67 void conditionalParameterError(const std::string & param_name,
68 const std::vector<std::string> & conditional_param,
69 bool should_be_defined = true);
70
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
Base class for Control objects.
Definition Control.h:44
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
A time-dependent, neural network-based control of multiple input parameters.
const std::vector< Real > _action_scaling_factors
Multipliers for the actions.
virtual void execute() override
Execute neural network to determine the controllable parameter values.
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.
bool hasControlNeuralNet() const
Return true if the object already has a neural netwok.
const unsigned int _input_timesteps
Number of timesteps to use as input data from the reporters (this influences how many past results ar...
void loadControlNeuralNet(const Moose::LibtorchArtificialNeuralNet &input_nn)
Function responsible for loading the neural network for the controller.
Real getSignal(const unsigned int signal_index) const
Get the (signal_index)-th signal of the control neural net.
unsigned int numberOfControlSignals() const
Get the number of controls this object is computing.
const std::vector< Real > _response_scaling_factors
Scaling constants (multipliers) for the responses.
std::vector< Real > _current_response
The values of the current observed postprocessor values.
const std::vector< PostprocessorName > & _response_names
Names of the postprocessors which contain the observations of the system.
std::vector< std::vector< Real > > & _old_responses
This variable is populated if the controller needs acess to older values of the observed postprocesso...
static InputParameters validParams()
std::vector< Real > _current_control_signals
The control signals from the last evaluation of the controller.
const std::vector< Real > _response_shift_factors
Shifting constants for the responses.
const std::vector< std::string > & _control_names
The names of the controllable parameters.
torch::Tensor prepareInputTensor()
Function that prepares the input tensor for the controller neural network.
std::vector< const Real * > _response_values
Links to the current response postprocessor values.
std::shared_ptr< Moose::LibtorchNeuralNetBase > _nn
Pointer to the neural net object which is supposed to be used to control the parameter values.
void updateCurrentResponse()
Function that updates the values of the current response.
const Moose::LibtorchNeuralNetBase & controlNeuralNet() const
Return a reference to the stored neural network.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
This base class is meant to gather the functions and members common in every neural network based on ...