20 #ifndef __DOLFIN_XDMFFILE_H
21 #define __DOLFIN_XDMFFILE_H
35 #include <dolfin/common/MPI.h>
36 #include <dolfin/common/Variable.h>
37 #include <dolfin/mesh/CellType.h>
63 template<
typename T>
class MeshFunction;
64 template<
typename T>
class MeshValueCollection;
93 :
XDMFFile(MPI_COMM_WORLD, filename) {}
96 XDMFFile(MPI_Comm comm,
const std::string filename);
154 std::string function_name,
155 double time_step = 0.0,
292 void write(
const std::vector<Point>& points,
305 void write(
const std::vector<Point>& points,
306 const std::vector<double>& values,
336 std::int64_t counter=-1);
397 template <
typename T>
402 template <
typename T>
407 template <
typename T>
409 const std::vector<std::int64_t>& topology_data,
410 const std::vector<T>& value_data);
413 static void build_mesh(
Mesh& mesh,
const CellType& cell_type,
414 std::int64_t num_points, std::int64_t num_cells,
416 const pugi::xml_node& topology_dataset_node,
417 const pugi::xml_node& geometry_dataset_node,
418 const boost::filesystem::path& parent_path);
424 std::int64_t num_points, std::int64_t num_cells,
426 const pugi::xml_node& topology_dataset_node,
427 const pugi::xml_node& geometry_dataset_node,
428 const boost::filesystem::path& parent_path);
430 static void build_mesh_quadratic(
Mesh& mesh,
const CellType& cell_type,
431 std::int64_t num_points, std::int64_t num_cells,
433 const pugi::xml_node& topology_dataset_node,
434 const pugi::xml_node& geometry_dataset_node,
435 const boost::filesystem::path& relative_path);
441 static void add_mesh(MPI_Comm comm, pugi::xml_node& xml_node,
442 hid_t h5_id,
const Mesh& mesh,
443 const std::string path_prefix);
446 static void add_function(MPI_Comm comm, pugi::xml_node& xml_node,
447 hid_t h5_id, std::string h5_path,
448 const Function& u, std::string function_name,
452 static void add_points(MPI_Comm comm, pugi::xml_node& xml_node,
453 hid_t h5_id,
const std::vector<Point>& points);
458 static void add_topology_data(MPI_Comm comm, pugi::xml_node& xml_node,
459 hid_t h5_id,
const std::string path_prefix,
460 const Mesh& mesh,
int tdim);
463 static void add_geometry_data(MPI_Comm comm, pugi::xml_node& xml_node,
464 hid_t h5_id,
const std::string path_prefix,
472 static void add_data_item(MPI_Comm comm, pugi::xml_node& xml_node,
473 hid_t h5_id,
const std::string h5_path,
const T& x,
474 const std::vector<std::int64_t> dimensions,
475 const std::string number_type=
"");
480 static std::set<unsigned int> compute_nonlocal_entities(
const Mesh& mesh,
485 static std::vector<T> compute_topology_data(
const Mesh& mesh,
int cell_dim);
489 static std::vector<T> compute_quadratic_topology(
const Mesh& mesh);
493 std::vector<T> compute_value_data(
const MeshFunction<T>& meshfunction);
496 static std::pair<std::string, int>
497 get_cell_type(
const pugi::xml_node& topology_node);
500 static std::vector<std::int64_t>
501 get_dataset_shape(
const pugi::xml_node& dataset_node);
504 static std::int64_t get_num_cells(
const pugi::xml_node& topology_node);
507 template <
typename T>
508 static std::vector<T> get_dataset(MPI_Comm comm,
509 const pugi::xml_node& dataset_node,
510 const boost::filesystem::path& parent_path,
511 std::pair<std::int64_t, std::int64_t> range={0, 0});
515 static std::array<std::string, 2> get_hdf5_paths(
const pugi::xml_node& dataitem_node);
517 static std::string get_hdf5_filename(std::string xdmf_filename);
521 void read_mesh_function(MeshFunction<T>& meshfunction, std::string
name=
"");
525 void write_mesh_function(
const MeshFunction<T>& meshfunction,
531 static std::int64_t get_padded_width(
const Function& u);
534 static bool has_cell_centred_data(
const Function& u);
538 static std::vector<double> get_point_data_values(
const Function& u);
542 static std::vector<double> get_p2_data_values(
const Function& u);
545 static std::vector<double> get_cell_data_values(
const Function& u);
548 void check_encoding(
Encoding encoding)
const;
551 void check_function_name(std::string function_name);
555 static std::string xdmf_format_str(
Encoding encoding)
556 {
return (encoding == XDMFFile::Encoding::HDF5) ?
"HDF" :
"XML"; }
558 static std::string vtk_cell_type_str(
CellType::Type cell_type,
int order);
561 template <
typename X,
typename Y>
562 static std::string to_string(X x, Y y);
566 template <
typename T>
567 static std::vector<T> string_to_vector(
const std::vector<std::string>& x_str);
571 static std::string rank_to_string(std::size_t value_rank);
575 static std::string time_step_to_string(
const double time_step);
582 std::unique_ptr<HDF5File> _hdf5_file;
586 const std::string _filename;
589 std::size_t _counter;
593 std::unique_ptr<pugi::xml_document> _xml_doc;
597 #ifndef DOXYGEN_IGNORE
600 void XDMFFile::add_data_item(MPI_Comm comm, pugi::xml_node& xml_node,
601 hid_t h5_id,
const std::string h5_path,
602 const std::vector<bool>& x,
603 const std::vector<std::int64_t> shape,
604 const std::string number_type)
607 std::vector<int> x_int(x.size());
608 for (std::size_t i = 0; i < x.size(); ++i)
609 x_int[i] = (
int)x[i];
610 add_data_item(comm, xml_node, h5_id, h5_path, x_int, shape, number_type);