LCOV - code coverage report
Current view: top level - src/postprocessors - ThermocoupleSensorPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose misc: #31405 (292dce) with base fef103 Lines: 45 48 93.8 %
Date: 2025-09-04 07:54:05 Functions: 5 5 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             : #include "ThermocoupleSensorPostprocessor.h"
      11             : #include "GeneralSensorPostprocessor.h"
      12             : #include "Function.h"
      13             : #include "MooseRandom.h"
      14             : #include "LinearInterpolation.h"
      15             : #include "SplineInterpolation.h"
      16             : 
      17             : registerMooseObject("MiscApp", ThermocoupleSensorPostprocessor);
      18             : 
      19             : InputParameters
      20          72 : ThermocoupleSensorPostprocessor::validParams()
      21             : {
      22          72 :   InputParameters params = GeneralSensorPostprocessor::validParams();
      23          72 :   params.addClassDescription("This is a ThermocoupleSensorPostprocessor for various classes of "
      24             :                              "thermocouples, described by the 'thermocouple_type' parameter");
      25         144 :   params.addParam<Real>("proportional_weight", 0, "The weight assigned to the proportional term");
      26         144 :   params.addParam<Real>("integral_weight", 1, "The weight assigned to the integral term");
      27          72 :   return params;
      28           0 : }
      29             : 
      30          36 : ThermocoupleSensorPostprocessor::ThermocoupleSensorPostprocessor(const InputParameters & parameters)
      31          36 :   : GeneralSensorPostprocessor(parameters)
      32             : {
      33          72 :   if (isParamSetByUser("R_function"))
      34           0 :     mooseError("In thermocouple postprocessor R function is fixed. If you want to change it, use "
      35             :                "GeneralSensorPostprocessor.");
      36          36 : }
      37             : 
      38             : void
      39         664 : ThermocoupleSensorPostprocessor::initialize()
      40             : {
      41             :   // setting seed for random number generator
      42         664 :   _rng.seed(_seed);
      43         664 :   Real drift_value = _drift_function.value(_t);
      44         664 :   Real efficiency_value = _efficiency_function.value(_t);
      45         664 :   Real signalToNoise_value = _signalToNoise_function.value(_t);
      46         664 :   Real noise_std_dev = _noise_std_dev_function.value(_t);
      47             :   Real noise_value = _rng.randNormal(0, noise_std_dev);
      48         664 :   Real uncertainty_std_dev = _uncertainty_std_dev_function.value(_t);
      49             :   Real uncertainty_value = _rng.randNormal(0, uncertainty_std_dev);
      50             : 
      51             :   // if the problem is steady-state
      52         664 :   if (!_fe_problem.isTransient())
      53          13 :     _sensor_value = drift_value +
      54          13 :                     efficiency_value * (_input_signal + signalToNoise_value * noise_value) +
      55             :                     uncertainty_value;
      56             : 
      57             :   // if the problem is transient
      58             :   else
      59             :   {
      60             :     // Remove last element if we are repeating the timestep
      61             :     mooseAssert(_t_step_old <= _t_step,
      62             :                 "The old time step needs to be behind or the same as the current time step.");
      63         651 :     if (_t_step_old == _t_step)
      64             :     {
      65           1 :       _time_values.pop_back();
      66           1 :       _input_signal_values.pop_back();
      67           1 :       _integrand.pop_back();
      68             :     }
      69             : 
      70         651 :     _delay_value = _delay_function.value(_t);
      71         651 :     _time_values.push_back(_t);
      72         651 :     _input_signal_values.push_back(_input_signal);
      73             : 
      74             :     // Check if the size is greater than 500
      75         651 :     if (_time_values.size() > 500 && _input_signal_values.size() > _vector_size)
      76             :     {
      77             :       // Remove the first 10 elements
      78             :       _time_values.erase(_time_values.begin(), _time_values.begin() + 10);
      79           0 :       _input_signal_values.erase(_input_signal_values.begin(), _input_signal_values.begin() + 10);
      80             :     }
      81         651 :     Real _input_signal_delayed = getDelayedInputSignal();
      82             : 
      83             :     // computing integral term
      84         651 :     Real term_for_integration = _input_signal + signalToNoise_value * noise_value;
      85         651 :     _integrand.push_back(term_for_integration);
      86         651 :     _integration_value = getIntegral(_integrand);
      87             : 
      88             :     // output
      89         651 :     Real proportional_value = _input_signal_delayed + signalToNoise_value * noise_value;
      90         651 :     _sensor_value = drift_value +
      91         651 :                     efficiency_value * (_proportional_weight * proportional_value +
      92         651 :                                         _integral_weight * _integration_value) +
      93             :                     uncertainty_value;
      94             : 
      95             :     // Update old time step
      96         651 :     _t_step_old = _t_step;
      97             :   }
      98         664 : }
      99             : 
     100             : PostprocessorValue
     101         664 : ThermocoupleSensorPostprocessor::getValue() const
     102             : {
     103         664 :   return _sensor_value;
     104             : }
     105             : 
     106             : vector<Real>
     107         651 : ThermocoupleSensorPostprocessor::getRVector()
     108             : {
     109         651 :   _R_function_values.clear();
     110             :   // computing vector of exponential term
     111       17251 :   for (const auto i : index_range(_time_values))
     112       16600 :     _R_function_values.push_back(exp(-(_t - _time_values[i]) / _delay_value) / _delay_value);
     113         651 :   return _R_function_values;
     114             : }

Generated by: LCOV version 1.14