https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LibtorchArtificialNeuralNetParameters.C
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
14
16
19{
21
22 params.addClassDescription("Outputs the parameters of a LibtorchArtificialNeuralNetwork within a "
23 "LibtorchNeuralNetControl.");
24
25 params.addRequiredParam<std::string>("control_name",
26 "The control object holding the neural network.");
27
28 return params;
29}
30
32 const InputParameters & params)
33 : GeneralReporter(params),
34 _control_name(getParam<std::string>("control_name")),
35 _network(
36 declareValueByName<const Moose::LibtorchArtificialNeuralNet *>(name(), REPORTER_MODE_ROOT))
37{
38}
39
40void
42{
43 auto & control_warehouse = _fe_problem.getControlWarehouse();
44 const auto & control_ref = control_warehouse.getActiveObject(_control_name);
45 _controller = dynamic_cast<const LibtorchNeuralNetControl *>(control_ref.get());
46}
47
48void
50{
51 // We update the network link in the reporter so it always prints the latest network, this matters
52 // when the network in the controller is trained on the fly
53 _network =
55}
56
57#endif
registerMooseObject("MooseApp", LibtorchArtificialNeuralNetParameters)
const ReporterMode REPORTER_MODE_ROOT
ExecuteMooseObjectWarehouse< Control > & getControlWarehouse()
Reference to the control logic warehouse.
Reporter object that has a single execution of the "execute" method for each execute flag.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
A Reporter which can print the parameter values of a LibtorchArtificialNeuralNetwork from within a Co...
LibtorchArtificialNeuralNetParameters(const InputParameters &params)
const Moose::LibtorchArtificialNeuralNet *& _network
Reference to a neural net pointer declared as a reporter.
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
const std::string _control_name
The name of the control objects which hold the neural networks.
const LibtorchNeuralNetControl * _controller
Pointer to the controller so that we can avoid warehouse lookups in the execute function.
A time-dependent, neural network-based control of multiple input parameters.
const Moose::LibtorchNeuralNetBase & controlNeuralNet() const
Return a reference to the stored neural network.
std::shared_ptr< T > getActiveObject(const std::string &name, THREAD_ID tid=0) const
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...