https://mooseframework.inl.gov
Loading...
Searching...
No Matches
InputMatrixSampler.C
Go to the documentation of this file.
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 "InputMatrixSampler.h"
11
12registerMooseObjectAliased("StochasticToolsApp", InputMatrixSampler, "InputMatrix");
13
16{
18 params.addClassDescription("Sampler that utilizes a sampling matrix defined at input.");
19 params.addRequiredParam<RealEigenMatrix>("matrix", "Sampling matrix.");
20 params.declareControllable("matrix");
21 return params;
22}
23
25 : Sampler(parameters), _data(getParam<RealEigenMatrix>("matrix"))
26{
27 setNumberOfRows(_data.rows());
28 setNumberOfCols(_data.cols());
29}
30
31void
33{
34 if ((dof_id_type)_data.cols() != getNumberOfCols())
35 paramError("matrix",
36 "Input matrix changed the number of columns from ",
38 " to ",
39 _data.cols());
40
41 if ((dof_id_type)_data.rows() != getNumberOfRows())
42 setNumberOfRows(_data.rows());
43}
44
45Real
46InputMatrixSampler::computeSample(dof_id_type row_index, dof_id_type col_index)
47{
48 // Checks to make sure that the row and column indices are not out of bounds
49 // Static cast to avoid compiler warning and not lose information
50 mooseAssert(static_cast<Real>(row_index) < static_cast<Real>(_data.rows()),
51 "row_index cannot be out of bounds of the data.");
52 mooseAssert(static_cast<Real>(col_index) < static_cast<Real>(_data.cols()),
53 "col_index cannot be out of bounds of the data.");
54
55 return _data(row_index, col_index);
56}
registerMooseObjectAliased("StochasticToolsApp", InputMatrixSampler, "InputMatrix")
A class used to construct a sampling matrix from input.
InputMatrixSampler(const InputParameters &parameters)
void executeSetUp() override
Update number of rows if the controllable parameter has changed.
virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) override
Return the sample for the given row and column.
static InputParameters validParams()
const RealEigenMatrix & _data
Data read from input.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
void setNumberOfCols(dof_id_type n_cols)
dof_id_type getNumberOfRows() const
static InputParameters validParams()
dof_id_type getNumberOfCols() const
void setNumberOfRows(dof_id_type n_rows)