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 512 : StochasticMatrix::validParams() 16 : { 17 512 : InputParameters params = StochasticReporter::validParams(); 18 512 : params.addClassDescription( 19 : "Tool for extracting Sampler object data and storing data from stochastic simulations."); 20 1024 : params.addRequiredParam<SamplerName>("sampler", 21 : "The sample from which to extract distribution data."); 22 1024 : params.addParam<std::vector<ReporterValueName>>( 23 : "sampler_column_names", 24 : "Prescribed names of sampler columns, used to assign names of outputted vectors."); 25 512 : return params; 26 0 : } 27 : 28 257 : StochasticMatrix::StochasticMatrix(const InputParameters & parameters) 29 257 : : StochasticReporter(parameters), _sampler(getSampler("sampler")) 30 : { 31 : std::vector<ReporterValueName> names; 32 514 : if (isParamValid("sampler_column_names")) 33 531 : names = getParam<std::vector<ReporterValueName>>("sampler_column_names"); 34 : else 35 : { 36 80 : names.resize(_sampler.getNumberOfCols()); 37 80 : const int padding = MooseUtils::numDigits(_sampler.getNumberOfCols()); 38 487 : for (dof_id_type j = 0; j < _sampler.getNumberOfCols(); ++j) 39 : { 40 407 : std::stringstream nm; 41 1221 : nm << getParam<SamplerName>("sampler") << "_" << std::setw(padding) << std::setfill('0') << j; 42 407 : names[j] = nm.str(); 43 407 : } 44 : } 45 : 46 257 : if (names.size() != _sampler.getNumberOfCols()) 47 2 : paramError("sampler_column_names", 48 : "The number of column names specified (", 49 : names.size(), 50 : ") does not match the number of sampler columns (", 51 2 : _sampler.getNumberOfCols(), 52 : ")."); 53 : 54 1123 : for (const auto & nm : names) 55 1736 : _sample_vectors.push_back(&declareStochasticReporter<Real>(nm, _sampler)); 56 255 : } 57 : 58 : void 59 437 : StochasticMatrix::execute() 60 : { 61 3103 : for (dof_id_type i = 0; i < _sampler.getNumberOfLocalRows(); ++i) 62 : { 63 2666 : std::vector<Real> data = _sampler.getNextLocalRow(); 64 12807 : for (std::size_t j = 0; j < data.size(); ++j) 65 10141 : (*_sample_vectors[j])[i] = data[j]; 66 2666 : } 67 437 : } 68 : 69 : ReporterName 70 339 : StochasticMatrix::declareStochasticReporterClone(const Sampler & sampler, 71 : const ReporterData & from_data, 72 : const ReporterName & from_reporter, 73 : std::string prefix) 74 : { 75 339 : if (sampler.name() != _sampler.name()) 76 2 : paramError("sampler", 77 : "Attempting to create a stochastic vector with a different sampler (", 78 : sampler.name(), 79 : ") than the one specified at input (", 80 : _sampler.name(), 81 : ")."); 82 : 83 : return StochasticReporter::declareStochasticReporterClone( 84 674 : sampler, from_data, from_reporter, prefix); 85 : }