24 "data_file",
"",
"File holding csv data for use with PiecewiseBilinear");
25 params.
addParam<std::vector<Real>>(
"x",
"The x abscissa values");
26 params.
addParam<std::vector<Real>>(
"y",
"The y abscissa values");
27 params.
addParam<std::vector<Real>>(
"z",
"The ordinate values");
28 params.
addParam<
int>(
"axis", -1,
"The axis used (0, 1, or 2 for x, y, or z).");
30 "xaxis", -1,
"The coordinate used for x-axis data (0, 1, or 2 for x, y, or z).");
32 "yaxis", -1,
"The coordinate used for y-axis data (0, 1, or 2 for x, y, or z).");
34 "scale_factor", 1.0,
"Scale factor to be applied to the axis, yaxis, or xaxis values");
37 "Set to true if you want to interpolate along a radius " 38 "rather that along a specific axis, and note that you " 39 "have to define xaxis and yaxis in the input file");
46 _data_file_name(getParam<FileName>(
"data_file")),
47 _axis(getParam<
int>(
"axis")),
48 _yaxis(getParam<
int>(
"yaxis")),
49 _xaxis(getParam<
int>(
"xaxis")),
50 _axisValid(_axis > -1 && _axis < 3),
51 _yaxisValid(_yaxis > -1 && _yaxis < 3),
52 _xaxisValid(_xaxis > -1 && _xaxis < 3),
53 _scale_factor(getParam<
Real>(
"scale_factor")),
54 _radial(getParam<bool>(
"radial"))
60 ": None of axis, yaxis, or xaxis properly defined. Allowable range is 0-2");
63 mooseError(
"In PiecewiseBilinear ",
_name,
": Cannot define axis with either yaxis or xaxis");
67 "In PiecewiseBilinear ",
_name,
": yaxis and xaxis must be defined when radial = true");
72 std::vector<Real> z_vec;
78 mooseError(
"In PiecewiseBilinear: Cannot specify 'data_file' and 'x', 'y', or 'z' together.");
85 mooseError(
"In PiecewiseBilinear: 'x' and 'y' and 'z' must be specified if any one is " 86 "specified or no 'data_file' is specified.");
90 x = getParam<std::vector<Real>>(
"x");
91 y = getParam<std::vector<Real>>(
"y");
92 z_vec = getParam<std::vector<Real>>(
"z");
95 if (z_vec.size() != x.size() * y.size())
96 mooseError(
"In PiecewiseBilinear: Size of z should be the size of x times the size of y.");
101 for (
unsigned int i = 0; i < y.size(); i++)
102 for (
unsigned int j = 0; j < x.size(); j++)
104 z(i, j) = z_vec[
idx];
126 template <
typename T,
typename P>
155 std::vector<Real> & x,
156 std::vector<Real> & y,
158 const std::string & object_name)
160 std::ifstream file(data_file_name.c_str());
162 ::
mooseError(object_name,
" : Error opening file '", data_file_name,
"'.");
164 std::size_t num_lines = 0;
166 std::vector<Real> data;
169 std::vector<Real> line_data;
170 while (std::getline(file, line))
173 if (!MooseUtils::tokenizeAndConvert<double>(line, line_data,
", "))
174 ::
mooseError(object_name,
" : Error parsing file '", data_file_name,
"' on line ", num_lines);
176 data.insert(data.end(), line_data.begin(), line_data.end());
179 num_cols = line_data.size();
180 else if (line_data.size() != num_cols + 1)
184 " columns of data but expected ",
191 y.resize(num_lines - 1);
192 z.
reshape(num_lines - 1, num_cols);
193 std::size_t offset = 0;
196 for (
unsigned int j = 0; j < num_cols; ++j)
197 x[j] = data[offset++];
199 for (
unsigned int i = 0; i < num_lines - 1; ++i)
202 y[i] = data[offset++];
205 for (
unsigned int j = 0; j < num_cols; ++j)
206 z(i, j) = data[offset++];
209 if (data.size() != offset)
210 ::
mooseError(object_name,
" : Inconsistency in data read from '", data_file_name,
"'.");
Base class for function objects.
const unsigned int invalid_uint
const std::string & _name
The name of this class, reference to value stored in InputParameters.
static InputParameters validParams()
registerMooseObject("MooseApp", PiecewiseBilinear)
void reshape(const unsigned int rows, const unsigned int cols)
Change the shape of the tensor.
static void parse(const std::string &data_file_name, std::vector< Real > &x, std::vector< Real > &y, ColumnMajorMatrix &z, const std::string &object_name)
Parse a text/CSV file to fill two-dimensional data.
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
virtual const std::string & name() const
Get the name of the class.
T valueInternal(T t, const P &p) const
virtual Real value(Real t, const Point &pt) const override
This function will return a value based on the first input argument only.
std::unique_ptr< BilinearInterpolation > _bilinear_interp
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PiecewiseBilinear reads from a file the information necessary to build the vectors x and y and the Co...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
virtual ~PiecewiseBilinear()
static InputParameters validParams()
Class constructor.
const std::string _data_file_name
PiecewiseBilinear(const InputParameters ¶meters)
void ErrorVector unsigned int