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 38 : VectorPostprocessorSampler::validParams() 16 : { 17 38 : InputParameters params = Sampler::validParams(); 18 : 19 76 : 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 38 : params.addClassDescription("The sampler uses vector postprocessors as inputs."); 25 38 : return params; 26 0 : } 27 : 28 22 : VectorPostprocessorSampler::VectorPostprocessorSampler(const InputParameters & parameters) 29 22 : : Sampler(parameters) 30 : { 31 88 : for (auto & vpp_vec : getParam<std::vector<ReporterName>>("vectors_names")) 32 44 : _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 22 : setNumberOfRows(1); 37 22 : setNumberOfCols(_data.size()); 38 22 : } 39 : 40 : void 41 22 : VectorPostprocessorSampler::executeSetUp() 42 : { 43 22 : const auto vsize = _data[0]->size(); 44 66 : for (const auto & vec : _data) 45 44 : if (vec->size() != vsize) 46 0 : paramError("vector_names", "Vectors must all be the same size."); 47 : 48 22 : setNumberOfRows(vsize); 49 22 : } 50 : 51 : Real 52 80 : 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 80 : return (*_data[col_index])[row_index]; 60 : }