70 std::copy(
_axes.begin(),
_axes.end(), axes.begin());
77 for (
unsigned int i = 0; i <
_dim; ++i)
79 grid[i].resize(
_grid[i].size());
80 std::copy(
_grid[i].begin(),
_grid[i].end(), grid[i].begin());
87 fcn.resize(
_fcn.size());
88 std::copy(
_fcn.begin(),
_fcn.end(), fcn.begin());
94 if (ijk.size() !=
_dim)
96 "Gridded data evaluateFcn called with ", ijk.size(),
" arguments, but expected ",
_dim);
97 unsigned int index = ijk[0];
98 for (
unsigned int i = 1; i <
_dim; ++i)
99 index += ijk[i] *
_step[i];
100 if (index >=
_fcn.size())
101 mooseError(
"Gridded data evaluateFcn attempted to access index ",
103 " of function, but it contains only ",
111 std::vector<int> & axes,
112 std::vector<std::vector<Real>> & grid,
113 std::vector<Real> & f,
114 std::vector<unsigned int> & step,
115 std::string file_name)
124 std::ifstream file(file_name.c_str());
126 mooseError(
"Error opening file '" + file_name +
"' from GriddedData.");
128 bool reading_grid_data =
false;
129 bool reading_value_data =
false;
135 reading_grid_data =
false;
136 if (line.compare(
"AXIS X") == 0)
139 reading_grid_data =
true;
142 else if (line.compare(
"AXIS Y") == 0)
145 reading_grid_data =
true;
148 else if (line.compare(
"AXIS Z") == 0)
151 reading_grid_data =
true;
154 else if (line.compare(
"AXIS T") == 0)
157 reading_grid_data =
true;
162 if (reading_grid_data)
165 grid[
dim - 1].resize(0);
172 if (reading_value_data)
176 if (line.compare(
"DATA") == 0)
177 reading_value_data =
true;
184 mooseError(
"No valid AXIS lines found by GriddedData");
189 for (
unsigned int i = 1; i <
dim; ++i)
190 step[i] = step[i - 1] * grid[i - 1].size();
193 unsigned int num_data_points = 1;
194 for (
unsigned int i = 0; i <
dim; ++i)
196 if (grid[i].size() == 0)
197 mooseError(
"Axis ", i,
" in your GriddedData has zero size");
198 num_data_points *= grid[i].size();
200 if (num_data_points != f.size())
201 mooseError(
"According to AXIS statements in GriddedData, number of data points is ",
205 " function values were read from file");
211 while (std::getline(file_stream, line))
213 if (line.size() == 0)
227 std::vector<Real> values;
228 bool status = MooseUtils::tokenizeAndConvert<Real>(input_string, values,
" ");
231 mooseError(
"GriddedData: Failed to convert string into Real when reading line ", input_string);
233 for (
auto val : values)
234 output_vec.push_back(val);
static bool getSignificantLine(std::ifstream &file_stream, std::string &line)
Extracts the next line from file_stream that is:
std::vector< std::vector< Real > > _grid
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Utility class template for a semidynamic vector with a maximum size N and a chosen dynamic size...
Real evaluateFcn(const GridIndex &ijk)
Evaluates the function at a given grid point.
void getAxes(std::vector< int > &axes)
Yields axes information.
std::vector< unsigned int > _step
static void splitToRealVec(const std::string &input_string, std::vector< Real > &output_vec)
Splits an input_string using space as the separator Converts the resulting items to Real...
GriddedData(std::string file_name)
Construct with a file name.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int getDim()
Returns the dimensionality of the grid.
static void parse(unsigned int &dim, std::vector< int > &axes, std::vector< std::vector< Real >> &grid, std::vector< Real > &f, std::vector< unsigned int > &step, std::string file_name)
parse the file_name extracting information.
void getFcn(std::vector< Real > &fcn)
Yields the values defined at the grid points.
void getGrid(std::vector< std::vector< Real >> &grid)
Yields the grid.