6#include <deal.II/base/exceptions.h>
7#include <deal.II/base/point.h>
8#include <deal.II/lac/vector.h>
30template <
unsigned int dim,
typename number>
63 dealii::Vector<number>
78 dealii::Vector<number>
90 dealii::Vector<number>
112template <
unsigned int dim,
typename number>
120 dealii::ExcMessage(
"Dataset format must be FlatBinary"));
124 this->ic_file.simulation_variable_names.size() == 1,
125 dealii::ExcMessage(
"Only one field can be read in from a binary file"));
130 "Only rectangular domains are supported for binary input files"));
133 for (
unsigned int d : std::views::iota(0
U,
dim))
144 dealii::ExcMessage(
"Could not open binary file: " +
151 for (dealii::types::global_dof_index
i : std::views::iota(0
U,
n_values))
155 data.push_back(std::bit_cast<number>(
buffer));
160template <
unsigned int dim,
typename number>
165 auto file_size = std::filesystem::file_size(this->ic_file.filename);
176 "Expected input array size is zero, check that the number of data points "
177 "in each used direction is set correctly in the input file for your binary file. "
178 "You likely have the number of data points set to zero in all directions."));
184 " bytes for vector) does not match actual file size (" +
185 std::to_string(
file_size) +
" bytes)."));
191template <
unsigned int dim,
typename number>
199 dealii::ExcMessage(
"Could not open binary file: " + ic_file.
filename));
202 for (dealii::types::global_dof_index
j : std::views::iota(0
U, data.size()))
210template <
unsigned int dim,
typename number>
211inline dealii::Vector<number>
220 dealii::ExcMessage(
"The number of components requested in the get_value call "
221 "does not match the number of values in the binary file."));
227 dealii::ExcMessage(
"Index out of bounds in ReadBinary::get_vals"));
234template <
unsigned int dim,
typename number>
235inline dealii::Vector<number>
241 "Number of components for interpolation must be 1 (scalar) or dim (vector)"));
247 const auto &spatial_discretization = this->spatial_discretization;
250 std::array<number, dim>
spacing;
251 for (
unsigned int d : std::views::iota(0
U,
dim))
253 spacing[
d] = spatial_discretization.rectangular_mesh.size[
d] /
254 static_cast<number>(this->ic_file.n_data_points[
d]);
258 std::array<dealii::types::global_dof_index, dim>
lower_indices;
259 for (
unsigned int d : std::views::iota(0
U,
dim))
262 static_cast<dealii::types::global_dof_index
>(std::floor(
point[
d] /
spacing[
d]));
271 std::array<number, dim>
weights;
272 for (
unsigned int d : std::views::iota(0
U,
dim))
278 if constexpr (
dim == 1)
304 else if constexpr (
dim == 2)
344 else if constexpr (
dim == 3)
414template <
unsigned int dim,
typename number>
419 Assert(n_values == n_points,
420 dealii::ExcMessage(
"The number of points should match the number of values in a "
421 "binary file for a scalar field. Make sure the file size is "
422 "correct and you are trying to access a scalar field."));
423 return interpolate(
point, 1)[0];
426template <
unsigned int dim,
typename number>
427inline dealii::Vector<number>
432 dealii::ExcMessage(
"The number of points should match the number of values "
433 "divided by the dimension in a binary file for a vector "
434 "field. Make sure the file size is correct and you are "
435 "trying to access a vector field."));
440template <
unsigned int dim,
typename number>
444 for (dealii::types::global_dof_index
i : std::views::iota(0
U, n_values))
447 dealii::ExcMessage(
"Index out of bounds in ReadBinary::print_file"));
static dealii::ConditionalOStream & pout_summary()
Log output stream for writing a summary.log file.
Definition conditional_ostreams.cc:34
Class to read in a flat binary file and provide values at given points.
Definition read_binary.h:32
dealii::Vector< number > get_value(const dealii::types::global_dof_index index, const unsigned int n_components)
Get vector value for a given index.
Definition read_binary.h:212
std::vector< number > data
Data array to hold the read in values.
Definition read_binary.h:109
ReadBinary(const InitialConditionFile &_ic_file, const SpatialDiscretization< dim > &_spatial_discretization)
Constructor.
Definition read_binary.h:113
number get_scalar_value(const dealii::Point< dim > &point, const std::string &scalar_name) override
Get scalar value for a given point.
Definition read_binary.h:416
void check_file_size()
Check the size of the binary file and make sure it matches the expected size (in bytes).
Definition read_binary.h:162
dealii::Vector< number > interpolate(const dealii::Point< dim > &point, const unsigned int n_components)
Get vector value for a given point.
Definition read_binary.h:236
dealii::types::global_dof_index n_values
Number of values (n_points * n_components).
Definition read_binary.h:104
dealii::types::global_dof_index n_points
Number of grid points.
Definition read_binary.h:99
static void write_file(const std::vector< number > &data, const InitialConditionFile &ic_file)
Write a binary file for testing.
Definition read_binary.h:193
void print_file() override
Print the binary file to text for debugging.
Definition read_binary.h:442
dealii::Vector< number > get_vector_value(const dealii::Point< dim > &point, const std::string &vector_name) override
Get vector value for a given point.
Definition read_binary.h:428
Definition read_field_base.h:23
const InitialConditionFile & ic_file
Initial condition file object.
Definition read_field_base.h:86
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
Definition conditional_ostreams.cc:20
@ Rectangular
Definition spatial_discretization.h:27
Struct that store the read-in information for a single file.
Definition load_initial_condition_parameters.h:25
std::array< dealii::types::global_dof_index, 3 > n_data_points
Definition load_initial_condition_parameters.h:39
std::vector< std::string > file_variable_names
Definition load_initial_condition_parameters.h:33
DataFormatType dataset_format
Definition load_initial_condition_parameters.h:30
std::string filename
Definition load_initial_condition_parameters.h:27
Struct that holds spatial discretization parameters.
Definition spatial_discretization.h:230
@ FlatBinary
Definition type_enums.h:112