14 #include "libmesh/int_range.h" 24 "axis", axis,
"The axis used (x, y, or z) if this is to be a function of position");
27 params.
addParam<std::vector<Real>>(
"xy_data",
28 "All function data, supplied in abscissa, ordinate pairs");
29 params.
addParam<std::vector<Real>>(
"x",
"The abscissa values");
30 params.
addParam<std::vector<Real>>(
"y",
"The ordinate values");
33 params.
addParam<FileName>(
"data_file",
"File holding CSV data");
34 params.
addParam<
unsigned int>(
"x_index_in_file", 0,
"The abscissa index in the data file");
35 params.
addParam<
unsigned int>(
"y_index_in_file", 1,
"The ordinate index in the data file");
37 "x_title",
"The title of the column/row containing the x data in the data file");
39 "y_title",
"The title of the column/row containing the y data in the data file");
41 "xy_in_file_only",
true,
"If the data file only contains abscissa and ordinate data");
42 MooseEnum format(
"columns=0 rows=1",
"rows");
44 "format", format,
"Format of csv data file that is in either in columns or rows");
47 params.
addParam<UserObjectName>(
"json_uo",
"JSONFileReader holding the data");
48 params.
addParam<std::vector<std::string>>(
49 "x_keys",
"Ordered vector of keys in the JSON tree to obtain the abscissa");
50 params.
addParam<std::vector<std::string>>(
51 "y_keys",
"Ordered vector of keys in the JSON tree to obtain the ordinate");
55 "data_file x_index_in_file y_index_in_file x_title y_title xy_in_file_only format",
56 "Data from CSV file");
63 std::vector<Real> & data_x,
64 std::vector<Real> & data_y)
65 : _has_axis(object.isParamValid(
"axis")),
67 _parameters(object.parameters()),
81 "Either 'data_file' or 'json_uo' or 'x' and 'y' or 'xy_data' must be specified " 85 "Both 'x' and 'y' parameters or neither (for another input method) must be specified");
92 "A parameter was passed for an option using data from a CSV file but the " 93 "'data_file' parameter has not been set. This is not allowed. Please check the parameter " 94 "groups in the documentation for the list of parameters for each data input method.");
98 "A parameter was passed for a JSON input option but the 'json_uo' parameter has not " 99 "been set. This is not allowed. Please check the parameter groups in the " 100 "documentation for the list of parameters for each data input method.");
107 const auto & data_file_name =
_parameters.
get<FileName>(
"data_file");
119 "When accessing data through 'x_title' or 'y_title' this parameter should not be used");
130 const auto & columns = reader.
getNames();
131 const auto & data = reader.
getData();
133 if (data.size() > 2 && xy_only)
136 ": Read more than two ",
138 " of data from file '",
140 "'. Did you mean to use \"format = ",
141 format ==
"columns" ?
"rows" :
"columns",
142 "\" or set \"xy_in_file_only\" to false?");
146 const auto setIndex = [&](
unsigned int & index,
const std::string & prefix)
152 if (columns[i] ==
name)
159 " in the data file has the title '",
166 if (index >= data.size())
168 "Index out-of-range of the available data in '",
170 "', which contains ",
177 setIndex(x_index,
"x");
178 setIndex(y_index,
"y");
180 if (x_index == y_index)
183 ": 'x_index_in_file' and 'y_index_in_file' are set to the same value.");
210 "Lengths of x (",
_data_x.size(),
") and y (",
_data_y.size(),
") data do not match.");
225 const auto xy_size = xy.size();
226 if (xy_size % 2 != 0)
228 "In ",
_object.
name(),
": Length of data provided in 'xy_data' must be a multiple of 2.");
230 const auto data_size = xy_size / 2;
std::string name(const ElemQuality q)
static InputParameters validParams()
const unsigned int invalid_uint
void setComment(const std::string &value)
std::vector< Real > & _data_y
User object that reads a JSON file and makes its data available to other objects. ...
void buildFromFile(const libMesh::Parallel::Communicator &comm)
Reads data from supplied CSV file.
std::vector< Real > & _data_x
raw function data as read
const std::string & name() const
Get the name of the class.
Every object that can be built by the factory should be derived from this class.
PiecewiseTabularInterface(const MooseObject &object, std::vector< Real > &data_x, std::vector< Real > &data_y)
void getVector(const std::string &vector_name, std::vector< T > &vector_to_fill) const
Getter for vector values.
void setFormatFlag(FormatFlag value)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void read()
Perform the actual data reading.
const std::vector< std::vector< T > > & getData() const
Return the rows/columns of data.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void buildFromXandY()
Builds data from 'x' and 'y' parameters.
Utility class for reading delimited data (e.g., CSV data).
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
const InputParameters & _parameters
Parameters supplied to the object.
unsigned int _axis
if _has_axis is true point component to use as function argument, otherwise use t ...
const MooseObject & _object
The object.
const std::vector< std::string > & getNames() const
Return the column/row names.
void buildFromXY()
Builds data from 'xy_data' parameter.
bool _raw_data_loaded
Boolean to keep track of whether the data has been loaded.
auto index_range(const T &sizable)
void buildFromJSON(const JSONFileReader &json_uo)
Reads data from supplied JSON reader.