LCOV - code coverage report
Current view: top level - src/reporters - ParsedVectorVectorRealReductionReporter.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 863ef6 Lines: 44 46 95.7 %
Date: 2025-10-15 18:16:15 Functions: 3 3 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 "ParsedVectorVectorRealReductionReporter.h"
      11             : #include <cstddef>
      12             : 
      13             : registerMooseObject("MooseApp", ParsedVectorVectorRealReductionReporter);
      14             : 
      15             : InputParameters
      16       14979 : ParsedVectorVectorRealReductionReporter::validParams()
      17             : {
      18       14979 :   InputParameters params = ParsedReporterBase::validParams();
      19       29958 :   params.addClassDescription("Use a parsed function to iterate through a rows of a vector of "
      20             :                              "vector and reduce it to a vector.");
      21       59916 :   params.addRequiredParam<ReporterName>("vector_of_vector_reporter_name",
      22             :                                         "Reporter name with vector of vectors to reduce.");
      23             : 
      24       44937 :   params.addRequiredParam<Real>("initial_reduction_value",
      25             :                                 "Value to intialize the reduction with.");
      26             : 
      27             :   // vector_reporter_symbols are the two symbols for reduction value and current value for the
      28             :   // reduction operation, these symbols are enforced in the constructor with a mooseError
      29       29958 :   params.set<std::vector<std::string>>("vector_reporter_symbols") = {"reduction_value",
      30       59916 :                                                                      "indexed_value"};
      31       29958 :   params.suppressParameter<std::vector<std::string>>("vector_reporter_symbols");
      32       14979 :   params.suppressParameter<std::vector<std::string>>("scalar_reporter_symbols");
      33             : 
      34       14979 :   return params;
      35       44937 : }
      36             : 
      37         116 : ParsedVectorVectorRealReductionReporter::ParsedVectorVectorRealReductionReporter(
      38         116 :     const InputParameters & parameters)
      39             :   : ParsedReporterBase(parameters),
      40         116 :     _initial_reduction_value(getParam<Real>("initial_reduction_value")),
      41         232 :     _vec_of_vec_name(getParam<ReporterName>("vector_of_vector_reporter_name")),
      42         116 :     _output_reporter(
      43         348 :         declareValueByName<std::vector<Real>>(getParam<std::string>("name"), REPORTER_MODE_ROOT)),
      44         232 :     _reporter_data(getReporterValueByName<std::vector<std::vector<Real>>>(
      45         116 :         getParam<ReporterName>("vector_of_vector_reporter_name")))
      46             : {
      47             :   // parse function
      48         232 :   std::string function = getParam<std::string>("expression");
      49             :   // make sure the expression has the two required variables, vi and vplus
      50         232 :   if (function.find("reduction_value") == std::string::npos ||
      51         116 :       function.find("indexed_value") == std::string::npos)
      52           0 :     paramError(
      53             :         "expression",
      54             :         "Parsed function must contain the two symbols 'reduction_value' and 'indexed_value'.");
      55         116 : }
      56             : 
      57             : void
      58          68 : ParsedVectorVectorRealReductionReporter::finalize()
      59             : {
      60          68 :   std::size_t ncols = _reporter_data.size();
      61          68 :   std::size_t nrows = 0;
      62          68 :   if (!_reporter_data.empty())
      63          68 :     nrows = _reporter_data[0].size();
      64             : 
      65         268 :   for (auto & reporter_vector : _reporter_data)
      66             :   {
      67         204 :     if (reporter_vector.size() != nrows)
      68           8 :       mooseError("Every vector in 'vector_of_vector_reporter_name=",
      69           4 :                  _vec_of_vec_name,
      70             :                  "' must be the same size.",
      71             :                  "\nFirst Vector size = ",
      72             :                  nrows,
      73             :                  "\nCurrent Vector size = ",
      74           4 :                  reporter_vector.size());
      75             :   }
      76             : 
      77          64 :   _output_reporter.clear();
      78          64 :   _output_reporter.resize(nrows, _initial_reduction_value);
      79         192 :   for (const auto i_row : make_range(nrows))
      80             :   {
      81         128 :     Real reduction = _initial_reduction_value;
      82         512 :     for (const auto j_col : make_range(ncols))
      83             :     {
      84         384 :       _func_params[0] = reduction;
      85         384 :       _func_params[1] = _reporter_data[j_col][i_row];
      86             : 
      87         384 :       if (_use_t)
      88           0 :         _func_params[2] = _t;
      89             : 
      90        1152 :       reduction = evaluate(_func_F);
      91             :     }
      92         128 :     _output_reporter[i_row] = reduction;
      93             :   }
      94          64 : }

Generated by: LCOV version 1.14