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 "VectorPostprocessorSampler.h" 11 : 12 : registerMooseObject("StochasticToolsApp", VectorPostprocessorSampler); 13 : 14 : InputParameters 15 40 : VectorPostprocessorSampler::validParams() 16 : { 17 40 : InputParameters params = Sampler::validParams(); 18 : 19 80 : params.addRequiredParam<std::vector<ReporterName>>( 20 : "vectors_names", 21 : "The names of the vector-postprocessors and/or vector reporter values containing the column " 22 : "data."); 23 : 24 40 : params.addClassDescription("The sampler uses vector postprocessors as inputs."); 25 40 : return params; 26 0 : } 27 : 28 23 : VectorPostprocessorSampler::VectorPostprocessorSampler(const InputParameters & parameters) 29 23 : : Sampler(parameters) 30 : { 31 92 : for (auto & vpp_vec : getParam<std::vector<ReporterName>>("vectors_names")) 32 46 : _data.emplace_back(&getReporterValueByName<std::vector<Real>>(vpp_vec)); 33 : 34 : // set a non-zero value for number of rows to avoid error in rankConfig, the actual value will be 35 : // set in executableSetup() and update via reinit() 36 23 : setNumberOfRows(1); 37 23 : setNumberOfCols(_data.size()); 38 23 : } 39 : 40 : void 41 23 : VectorPostprocessorSampler::executeSetUp() 42 : { 43 23 : const auto vsize = _data[0]->size(); 44 69 : for (const auto & vec : _data) 45 46 : if (vec->size() != vsize) 46 0 : paramError("vector_names", "Vectors must all be the same size."); 47 : 48 23 : setNumberOfRows(vsize); 49 23 : } 50 : 51 : Real 52 88 : VectorPostprocessorSampler::computeSample(dof_id_type row_index, dof_id_type col_index) 53 : { 54 : // Checks to make sure that the row and column indices are not out of bounds 55 : mooseAssert(row_index < _data[0]->size(), "row_index cannot be out of bounds of the data."); 56 : mooseAssert(col_index < _data.size(), "col_index cannot be out of bounds of the data."); 57 : 58 : // Entering samples into the matrix 59 88 : return (*_data[col_index])[row_index]; 60 : }