LCOV - code coverage report
Current view: top level - src/libtorch/reporters - LibtorchArtificialNeuralNetParameters.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 20 21 95.2 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include "LibtorchNeuralNetControl.h"
      13             : #include "LibtorchArtificialNeuralNetParameters.h"
      14             : 
      15             : registerMooseObject("MooseApp", LibtorchArtificialNeuralNetParameters);
      16             : 
      17             : InputParameters
      18        1563 : LibtorchArtificialNeuralNetParameters::validParams()
      19             : {
      20        1563 :   InputParameters params = GeneralReporter::validParams();
      21             : 
      22        1563 :   params.addClassDescription("Outputs the parameters of a LibtorchArtificialNeuralNetwork within a "
      23             :                              "LibtorchNeuralNetControl.");
      24             : 
      25        1563 :   params.addRequiredParam<std::string>("control_name",
      26             :                                        "The control object holding the neural network.");
      27             : 
      28        1563 :   return params;
      29           0 : }
      30             : 
      31           1 : LibtorchArtificialNeuralNetParameters::LibtorchArtificialNeuralNetParameters(
      32           1 :     const InputParameters & params)
      33             :   : GeneralReporter(params),
      34           1 :     _control_name(getParam<std::string>("control_name")),
      35           1 :     _network(
      36           2 :         declareValueByName<const Moose::LibtorchArtificialNeuralNet *>(name(), REPORTER_MODE_ROOT))
      37             : {
      38           1 : }
      39             : 
      40             : void
      41           1 : LibtorchArtificialNeuralNetParameters::initialSetup()
      42             : {
      43           1 :   auto & control_warehouse = _fe_problem.getControlWarehouse();
      44           1 :   const auto & control_ref = control_warehouse.getActiveObject(_control_name);
      45           1 :   _controller = dynamic_cast<const LibtorchNeuralNetControl *>(control_ref.get());
      46           1 : }
      47             : 
      48             : void
      49           1 : LibtorchArtificialNeuralNetParameters::execute()
      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           1 :   _network =
      54           1 :       dynamic_cast<const Moose::LibtorchArtificialNeuralNet *>(&(_controller->controlNeuralNet()));
      55           1 : }
      56             : 
      57             : #endif

Generated by: LCOV version 1.14