LCOV - code coverage report
Current view: top level - src/reporters - StochasticMatrix.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 35 36 97.2 %
Date: 2025-07-25 05:00:46 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             : #include "StochasticMatrix.h"
      11             : 
      12             : registerMooseObject("StochasticToolsApp", StochasticMatrix);
      13             : 
      14             : InputParameters
      15        1000 : StochasticMatrix::validParams()
      16             : {
      17        1000 :   InputParameters params = StochasticReporter::validParams();
      18        1000 :   params.addClassDescription(
      19             :       "Tool for extracting Sampler object data and storing data from stochastic simulations.");
      20        2000 :   params.addRequiredParam<SamplerName>("sampler",
      21             :                                        "The sample from which to extract distribution data.");
      22        2000 :   params.addParam<std::vector<ReporterValueName>>(
      23             :       "sampler_column_names",
      24             :       "Prescribed names of sampler columns, used to assign names of outputted vectors.");
      25        1000 :   return params;
      26           0 : }
      27             : 
      28         502 : StochasticMatrix::StochasticMatrix(const InputParameters & parameters)
      29         502 :   : StochasticReporter(parameters), _sampler(getSampler("sampler"))
      30             : {
      31             :   std::vector<ReporterValueName> names;
      32        1004 :   if (isParamValid("sampler_column_names"))
      33        1320 :     names = getParam<std::vector<ReporterValueName>>("sampler_column_names");
      34             :   else
      35             :   {
      36          62 :     names.resize(_sampler.getNumberOfCols());
      37          62 :     const int padding = MooseUtils::numDigits(_sampler.getNumberOfCols());
      38         310 :     for (dof_id_type j = 0; j < _sampler.getNumberOfCols(); ++j)
      39             :     {
      40         248 :       std::stringstream nm;
      41         744 :       nm << getParam<SamplerName>("sampler") << "_" << std::setw(padding) << std::setfill('0') << j;
      42         248 :       names[j] = nm.str();
      43         248 :     }
      44             :   }
      45             : 
      46         502 :   if (names.size() != _sampler.getNumberOfCols())
      47           4 :     paramError("sampler_column_names",
      48             :                "The number of column names specified (",
      49             :                names.size(),
      50             :                ") does not match the number of sampler columns (",
      51           4 :                _sampler.getNumberOfCols(),
      52             :                ").");
      53             : 
      54        1882 :   for (const auto & nm : names)
      55        2768 :     _sample_vectors.push_back(&declareStochasticReporter<Real>(nm, _sampler));
      56         498 : }
      57             : 
      58             : void
      59         494 : StochasticMatrix::execute()
      60             : {
      61        4964 :   for (dof_id_type i = 0; i < _sampler.getNumberOfLocalRows(); ++i)
      62             :   {
      63        4470 :     std::vector<Real> data = _sampler.getNextLocalRow();
      64       17130 :     for (std::size_t j = 0; j < data.size(); ++j)
      65       12660 :       (*_sample_vectors[j])[i] = data[j];
      66             :   }
      67         494 : }
      68             : 
      69             : ReporterName
      70         660 : StochasticMatrix::declareStochasticReporterClone(const Sampler & sampler,
      71             :                                                  const ReporterData & from_data,
      72             :                                                  const ReporterName & from_reporter,
      73             :                                                  std::string prefix)
      74             : {
      75         660 :   if (sampler.name() != _sampler.name())
      76           8 :     paramError("sampler",
      77             :                "Attempting to create a stochastic vector with a different sampler (",
      78           4 :                sampler.name(),
      79             :                ") than the one specified at input (",
      80           4 :                _sampler.name(),
      81             :                ").");
      82             : 
      83             :   return StochasticReporter::declareStochasticReporterClone(
      84        1312 :       sampler, from_data, from_reporter, prefix);
      85             : }

Generated by: LCOV version 1.14