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 "LibtorchControlValuePostprocessor.h" 13 : 14 : registerMooseObject("MooseApp", LibtorchControlValuePostprocessor); 15 : 16 : InputParameters 17 1569 : LibtorchControlValuePostprocessor::validParams() 18 : { 19 1569 : InputParameters params = GeneralPostprocessor::validParams(); 20 : 21 1569 : params.addClassDescription("Reports the value stored in given controlled parameters."); 22 : 23 1569 : params.addRequiredParam<std::string>("control_name", 24 : "The name of the LibtorchNeuralNetControl object."); 25 4707 : params.addParam<unsigned int>("signal_index", 26 3138 : 0, 27 : "The index of the signal from the LibtorchNeuralNetControl object. " 28 : "This assumes indexing between [0,num_signals)."); 29 1569 : return params; 30 0 : } 31 : 32 4 : LibtorchControlValuePostprocessor::LibtorchControlValuePostprocessor(const InputParameters & params) 33 4 : : GeneralPostprocessor(params), _signal_index(getParam<unsigned int>("signal_index")) 34 : 35 : { 36 4 : } 37 : 38 : void 39 3 : LibtorchControlValuePostprocessor::initialSetup() 40 : { 41 3 : GeneralPostprocessor::initialSetup(); 42 : 43 3 : _libtorch_nn_control = dynamic_cast<LibtorchNeuralNetControl *>( 44 3 : _fe_problem.getControlWarehouse() 45 6 : .getActiveObject(getParam<std::string>("control_name")) 46 3 : .get()); 47 3 : if (!_libtorch_nn_control) 48 0 : paramError("control_name", 49 : "The supplied control object is not derived from LibtorchNeuralNetControl!"); 50 : 51 3 : if (_libtorch_nn_control->numberOfControlSignals() <= _signal_index) 52 0 : paramError("signal_index", 53 : "The given control object only has ", 54 0 : _libtorch_nn_control->numberOfControlSignals(), 55 : " control signals!"); 56 3 : } 57 : 58 : Real 59 78 : LibtorchControlValuePostprocessor::getValue() const 60 : { 61 : // Return the value of the control signal 62 78 : return _libtorch_nn_control->getSignal(_signal_index); 63 : } 64 : 65 : #endif