LCOV - code coverage report
Current view: top level - src/reporters - ParsedVectorReporter.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 34 37 91.9 %
Date: 2026-05-29 20:35:17 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 "ParsedVectorReporter.h"
      11             : 
      12             : registerMooseObject("MooseApp", ParsedVectorReporter);
      13             : 
      14             : InputParameters
      15        3127 : ParsedVectorReporter::validParams()
      16             : {
      17        3127 :   InputParameters params = ParsedReporterBase::validParams();
      18        6254 :   params.addClassDescription("Apply parsed functions to vector entries held in reporters.");
      19        9381 :   params.addRequiredParam<std::vector<ReporterName>>("vector_reporter_names",
      20             :                                                      "Reporter names to apply function to.");
      21        3127 :   return params;
      22           0 : }
      23             : 
      24          36 : ParsedVectorReporter::ParsedVectorReporter(const InputParameters & parameters)
      25             :   : ParsedReporterBase(parameters),
      26          33 :     _output_reporter(
      27         102 :         declareValueByName<std::vector<Real>>(getParam<std::string>("name"), REPORTER_MODE_ROOT))
      28             : {
      29             :   const std::vector<ReporterName> reporter_names(
      30          66 :       getParam<std::vector<ReporterName>>("vector_reporter_names"));
      31          33 :   if (reporter_names.size() != _vector_reporter_symbols.size())
      32           6 :     paramError("vector_reporter_names",
      33             :                "vector_reporter_names and vector_reporter_symbols must be the same size:  Number "
      34             :                "of vector_reporter_names=",
      35             :                reporter_names.size(),
      36             :                ";  Number of vector_reporter_symbols=",
      37             :                _vector_reporter_symbols.size());
      38             : 
      39          30 :   _vector_reporter_data.resize(reporter_names.size());
      40         120 :   for (const auto rep_index : index_range(_vector_reporter_data))
      41         180 :     _vector_reporter_data[rep_index] =
      42          90 :         &getReporterValueByName<std::vector<Real>>(reporter_names[rep_index], REPORTER_MODE_ROOT);
      43          30 : }
      44             : 
      45             : void
      46          47 : ParsedVectorReporter::finalize()
      47             : {
      48             :   // check vector sizes of reporters
      49          47 :   const std::size_t entries(_vector_reporter_data[0]->size());
      50         185 :   for (const auto rep_index : index_range(_vector_reporter_data))
      51         141 :     if (entries != _vector_reporter_data[rep_index]->size())
      52             :     {
      53             :       const std::vector<ReporterName> reporter_names(
      54           6 :           getParam<std::vector<ReporterName>>("vector_reporter_names"));
      55           3 :       mooseError("All vectors being operated on must be the same size.",
      56             :                  "\nsize of ",
      57           3 :                  reporter_names[0].getCombinedName(),
      58             :                  " = ",
      59             :                  entries,
      60             :                  "\nsize of ",
      61           3 :                  reporter_names[rep_index].getCombinedName(),
      62             :                  " = ",
      63           3 :                  _vector_reporter_data[rep_index]->size());
      64           0 :     }
      65             : 
      66          44 :   _output_reporter.resize(entries, 0.0);
      67         176 :   for (const auto i : make_range(entries))
      68             :   {
      69             :     // this is the same order they are added to the symbol string in ParsedReporterBase
      70             :     // first get vector data
      71         528 :     for (const auto rep_index : index_range(_vector_reporter_data))
      72         396 :       _func_params[rep_index] = _vector_reporter_data[rep_index]->at(i);
      73             :     // next get scalar data
      74         363 :     for (const auto rep_index : index_range(_scalar_reporter_data))
      75         231 :       _func_params[_vector_reporter_data.size() + rep_index] = *(_scalar_reporter_data[rep_index]);
      76             : 
      77         132 :     if (_use_t)
      78           0 :       _func_params[_vector_reporter_data.size() + _scalar_reporter_data.size()] = _t;
      79             : 
      80         396 :     _output_reporter[i] = evaluate(_func_F);
      81             :   }
      82          44 : }

Generated by: LCOV version 1.14