https://mooseframework.inl.gov
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 
12 registerMooseObjectAliased("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 
31 void
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 
45 Real
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 }
void setNumberOfRows(dof_id_type n_rows)
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
void executeSetUp() override
Update number of rows if the controllable parameter has changed.
registerMooseObjectAliased("StochasticToolsApp", InputMatrixSampler, "InputMatrix")
static InputParameters validParams()
const RealEigenMatrix & _data
Data read from input.
void addRequiredParam(const std::string &name, const std::string &doc_string)
virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) override
Return the sample for the given row and column.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
A class used to construct a sampling matrix from input.
dof_id_type getNumberOfRows() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void setNumberOfCols(dof_id_type n_cols)
void addClassDescription(const std::string &doc_string)
InputMatrixSampler(const InputParameters &parameters)
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
dof_id_type getNumberOfCols() const
uint8_t dof_id_type