https://mooseframework.inl.gov
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 
40 void
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 
48 void
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
std::string name(const ElemQuality q)
A time-dependent, neural network-based control of multiple input parameters.
const Moose::LibtorchNeuralNetBase & controlNeuralNet() const
Return a reference to the stored neural network.
Reporter object that has a single execution of the "execute" method for for each execute flag...
const LibtorchNeuralNetControl * _controller
Pointer to the controller so that we can avoid warehouse lookups in the execute function.
const ReporterMode REPORTER_MODE_ROOT
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
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...
std::shared_ptr< T > getActiveObject(const std::string &name, THREAD_ID tid=0) const
const std::string _control_name
The name of the control objects which hold the neural networks.
const Moose::LibtorchArtificialNeuralNet *& _network
Reference to a neural net pointer declared as a reporter.
LibtorchArtificialNeuralNetParameters(const InputParameters &params)
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:211
registerMooseObject("MooseApp", LibtorchArtificialNeuralNetParameters)
A Reporter which can print the parameter values of a LibtorchArtificialNeuralNetwork from within a Co...
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...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
ExecuteMooseObjectWarehouse< Control > & getControlWarehouse()
Reference to the control logic warehouse.