OGS
MeshLib::IO Namespace Reference

Namespaces

namespace  Legacy
 

Classes

struct  FileCommunicator
 
struct  HdfData
 
class  HdfWriter
 
struct  MeshHdfData
 
struct  NodeData
 struct NodeData used for parallel reading and also partitioning More...
 
class  NodePartitionedMeshReader
 
struct  PartitionInfo
 
struct  PropertyVectorMetaData
 
struct  PropertyVectorPartitionMetaData
 
class  PVDFile
 
struct  TransformedMeshData
 
class  VtuInterface
 Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures. This class is currently not inherited from Writer because VTK will implement writing to a string from 6.2 onwards. More...
 
struct  XdmfData
 
struct  XdmfHdfData
 
struct  XdmfHdfMesh
 
class  XdmfHdfWriter
 
struct  XdmfTopology
 
class  XdmfWriter
 

Typedefs

using Hdf5DimType = hsize_t
 
using HDFAttributes = std::vector<HdfData>
 
using XdmfDimType = unsigned int
 

Functions

void writePropertyVectorMetaData (std::ostream &os, PropertyVectorMetaData const &pvmd)
 
void writePropertyVectorMetaData (PropertyVectorMetaData const &pvmd)
 
std::optional< PropertyVectorMetaDatareadPropertyVectorMetaData (std::istream &is)
 
void writePropertyVectorPartitionMetaData (std::ostream &os, PropertyVectorPartitionMetaData const &pvpmd)
 
std::optional< PropertyVectorPartitionMetaDatareadPropertyVectorPartitionMetaData (std::istream &is)
 
MeshLib::MeshreadMeshFromFile (const std::string &file_name, bool const compute_element_neighbors)
 
std::string getVtuFileNameForPetscOutputWithoutExtension (std::string const &file_name)
 
int writeVtu (MeshLib::Mesh const &mesh, std::string const &file_name, int const data_mode)
 
int writeMeshToFile (const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
 
int64_t createFile (std::filesystem::path const &filepath, unsigned int n_files)
 
int64_t openHDF5File (std::filesystem::path const &filepath, unsigned int n_files)
 
int64_t createHDF5TransferPolicy ()
 
static hid_t meshPropertyType2HdfType (MeshPropertyDataType const ogs_data_type)
 
std::filesystem::path partitionFilename (std::filesystem::path const &basic_filepath, int const file_group)
 
int getGroupIndex (int const input_index, int const input_size, int const new_group_size)
 
FileCommunicator getCommunicator (unsigned int const n_files)
 
bool isFileManager ()
 
PartitionInfo getPartitionInfo (std::size_t const size, unsigned int const n_files)
 
int64_t openHDF5File (std::filesystem::path const &filepath)
 
static constexpr auto elemOGSTypeToXDMFType ()
 
constexpr auto cellTypeOGS2XDMF (MeshLib::CellType const &cell_type)
 
std::optional< XdmfHdfDatatransformAttribute (std::pair< std::string, PropertyVectorBase * > const &property_pair, unsigned int const n_files, unsigned int const chunk_size_bytes)
 
std::vector< XdmfHdfDatatransformAttributes (MeshLib::Mesh const &mesh, unsigned int n_files, unsigned int chunk_size_bytes)
 Create meta data for attributes used for hdf5 and xdmf.
 
std::vector< double > transformToXDMFGeometry (MeshLib::Mesh const &mesh)
 Copies all node points into a new vector. Contiguous data used for writing. Conform with XDMF standard in https://xdmf.org/index.php/XDMF_Model_and_Format.
 
XdmfHdfData transformGeometry (MeshLib::Mesh const &mesh, double const *data_ptr, unsigned int n_files, unsigned int chunk_size_bytes)
 Create meta data for geometry used for hdf5 and xdmf.
 
ParentDataType getTopologyType (MeshLib::Mesh const &mesh)
 
std::pair< std::vector< int >, ParentDataTypetransformToXDMFTopology (MeshLib::Mesh const &mesh, std::size_t const offset)
 Copies all cells into a new vector. Contiguous data used for writing. The topology is specific to xdmf because it contains the xdmf cell types!! See section topology in https://xdmf.org/index.php/XDMF_Model_and_Format.
 
XdmfHdfData transformTopology (std::vector< int > const &values, ParentDataType const parent_data_type, unsigned int n_files, unsigned int chunk_size_bytes)
 Create meta data for topology used for HDF5 and XDMF.
 
static std::string meshItemTypeString (std::optional< MeshItemType > const &item_type)
 
static auto meshPropertyDatatypeString ()
 
static std::string getPropertyDataTypeString (MeshPropertyDataType const &ogs_data_type)
 
static constexpr auto meshPropertyDatatypeSize ()
 
static std::string getPropertyDataTypeSize (MeshPropertyDataType const &ogs_data_type)
 
std::function< std::string(std::vector< double >)> write_xdmf (XdmfData const &geometry, XdmfData const &topology, std::vector< XdmfData > const &constant_attributes, std::vector< XdmfData > const &variable_attributes, std::string const &h5filename, std::string const &ogs_version, std::string const &mesh_name)
 Generator function that creates a function capturing the spatial data of a mesh Temporal data can later be passed as argument.
 
template<typename Data >
std::function< bool(Data)> isVariableAttribute (std::set< std::string > const &variable_output_names)
 

Variables

constexpr auto elem_type_ogs2xdmf = elemOGSTypeToXDMFType()
 
constexpr char const * mesh_item_type_strings []
 
auto ogs_to_xdmf_type_fn = meshPropertyDatatypeSize()
 

Typedef Documentation

◆ Hdf5DimType

using MeshLib::IO::Hdf5DimType = hsize_t

Definition at line 24 of file HdfData.h.

◆ HDFAttributes

using MeshLib::IO::HDFAttributes = std::vector<HdfData>

Definition at line 25 of file HdfWriter.h.

◆ XdmfDimType

using MeshLib::IO::XdmfDimType = unsigned int

Definition at line 27 of file XdmfData.h.

Function Documentation

◆ cellTypeOGS2XDMF()

constexpr auto MeshLib::IO::cellTypeOGS2XDMF ( MeshLib::CellType const & cell_type)
constexpr

Definition at line 86 of file transformData.cpp.

87{
88 return elem_type_ogs2xdmf[to_underlying(cell_type)];
89}
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
Definition cpp23.h:29
constexpr auto elem_type_ogs2xdmf

References elem_type_ogs2xdmf, and BaseLib::to_underlying().

Referenced by getTopologyType(), and transformToXDMFTopology().

◆ createFile()

int64_t MeshLib::IO::createFile ( std::filesystem::path const & filepath,
unsigned int n_files )

Definition at line 38 of file fileIO.cpp.

40{
41 auto const communicator = getCommunicator(n_files);
42 MPI_Comm const comm = communicator.mpi_communicator;
43 MPI_Info const info = MPI_INFO_NULL;
44 hid_t const plist_id = H5Pcreate(H5P_FILE_ACCESS);
45
46 H5Pset_fapl_mpio(plist_id, comm, info);
47 H5Pset_coll_metadata_write(plist_id, true);
48
49 std::filesystem::path const partition_filename =
50 partitionFilename(filepath, communicator.color);
51 hid_t file = H5Fcreate(partition_filename.string().c_str(), H5F_ACC_TRUNC,
52 H5P_DEFAULT, plist_id);
53 H5Pclose(plist_id);
54
55 return file;
56}
std::filesystem::path partitionFilename(std::filesystem::path const &basic_filepath, int const file_group)
Definition fileIO.cpp:24
FileCommunicator getCommunicator(unsigned int const n_files)

References getCommunicator(), and partitionFilename().

◆ createHDF5TransferPolicy()

int64_t MeshLib::IO::createHDF5TransferPolicy ( )

Definition at line 70 of file fileIO.cpp.

71{
72 // property list for collective dataset write
73 hid_t io_transfer_property = H5Pcreate(H5P_DATASET_XFER);
74 H5Pset_dxpl_mpio(io_transfer_property, H5FD_MPIO_COLLECTIVE);
75 return io_transfer_property;
76}

Referenced by writeDataSet().

◆ elemOGSTypeToXDMFType()

static constexpr auto MeshLib::IO::elemOGSTypeToXDMFType ( )
staticconstexpr

Definition at line 41 of file transformData.cpp.

42{
44 elem_type{};
72 ParentDataType::WEDGE, 6}; // parallel triangle wedge
81 return elem_type;
82}

References EDGE_3, MeshLib::enum_length, MeshLib::HEX20, MeshLib::HEX27, MeshLib::HEX8, HEXAHEDRON, HEXAHEDRON_20, HEXAHEDRON_27, MeshLib::LINE2, MeshLib::LINE3, MeshLib::POINT1, POLYLINE, POLYVERTEX, MeshLib::PRISM15, MeshLib::PRISM18, MeshLib::PRISM6, PYRAMID, MeshLib::PYRAMID13, MeshLib::PYRAMID5, PYRAMID_13, MeshLib::QUAD4, MeshLib::QUAD8, MeshLib::QUAD9, QUADRILATERAL, QUADRILATERAL_8, QUADRILATERAL_9, MeshLib::TET10, MeshLib::TET4, TETRAHEDRON, TETRAHEDRON_10, BaseLib::to_underlying(), MeshLib::TRI3, MeshLib::TRI6, TRIANGLE, TRIANGLE_6, WEDGE, WEDGE_15, and WEDGE_18.

◆ getCommunicator()

FileCommunicator MeshLib::IO::getCommunicator ( unsigned int const n_files)

Definition at line 41 of file getCommunicator.cpp.

42{
43 int num_procs;
44 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
45 int rank_id;
46 MPI_Comm_rank(MPI_COMM_WORLD, &rank_id);
47 int const file_group_id = getGroupIndex(rank_id, num_procs, n_files);
48 MPI_Comm new_communicator;
49 MPI_Comm_split(MPI_COMM_WORLD, file_group_id, rank_id, &new_communicator);
50 return FileCommunicator{std::move(new_communicator),
51 std::move(file_group_id), ""};
52}
int getGroupIndex(int const input_index, int const input_size, int const new_group_size)

References getGroupIndex().

Referenced by createFile(), getPartitionInfo(), and openHDF5File().

◆ getGroupIndex()

int MeshLib::IO::getGroupIndex ( int const input_index,
int const input_size,
int const new_group_size )

Definition at line 27 of file getCommunicator.cpp.

29{
30 // A grouping algorithm that determines the number of groups and return the
31 // group idx of the specified input_index
32 assert(input_size >= new_group_size);
33 int const minimum_output_group_size =
34 std::lround(input_size / new_group_size);
35 int const maximum_output_group_size = (input_size % new_group_size)
36 ? minimum_output_group_size + 1
37 : minimum_output_group_size;
38 return std::lround(input_index / maximum_output_group_size);
39};

Referenced by getCommunicator().

◆ getPartitionInfo()

PartitionInfo MeshLib::IO::getPartitionInfo ( std::size_t const size,
unsigned int const n_files )

Definition at line 33 of file partition.cpp.

35{
36 MPI_Comm const mpi_comm = getCommunicator(n_files).mpi_communicator;
37 int mpi_size;
38 int mpi_rank;
39 MPI_Comm_size(mpi_comm, &mpi_size);
40 MPI_Comm_rank(mpi_comm, &mpi_rank);
41
42 std::vector<std::size_t> partition_sizes;
43 partition_sizes.resize(mpi_size);
44
45 MPI_Allgather(&size,
46 1,
47 MPI_UNSIGNED_LONG,
48 partition_sizes.data(),
49 1,
50 MPI_UNSIGNED_LONG,
51 mpi_comm);
52
53 // the first partition's offset is zero, offsets for subsequent
54 // partitions are the accumulated sum of all preceding size (excluding
55 // own size)
56 std::vector<std::size_t> partition_offsets(1, 0);
57 std::partial_sum(partition_sizes.begin(),
58 partition_sizes.end(),
59 back_inserter(partition_offsets));
60
61 // chunked
62 std::size_t longest_partition =
63 *max_element(partition_sizes.begin(), partition_sizes.end());
64
65 // local_offset, local_length, longest_local_length, global_length
66 return {partition_offsets[mpi_rank], size, longest_partition,
67 partition_offsets.back()};
68}

References getCommunicator(), and MeshLib::IO::FileCommunicator::mpi_communicator.

Referenced by MeshLib::IO::HdfData::HdfData().

◆ getPropertyDataTypeSize()

static std::string MeshLib::IO::getPropertyDataTypeSize ( MeshPropertyDataType const & ogs_data_type)
static

Definition at line 98 of file writeXdmf.cpp.

100{
101 return fmt::format("{}", ogs_to_xdmf_type_fn[to_underlying(ogs_data_type)]);
102}

References ogs_to_xdmf_type_fn, and BaseLib::to_underlying().

Referenced by write_xdmf().

◆ getPropertyDataTypeString()

static std::string MeshLib::IO::getPropertyDataTypeString ( MeshPropertyDataType const & ogs_data_type)
static

Definition at line 73 of file writeXdmf.cpp.

75{
76 return meshPropertyDatatypeString()[to_underlying(ogs_data_type)];
77}
static auto meshPropertyDatatypeString()
Definition writeXdmf.cpp:55

References meshPropertyDatatypeString(), and BaseLib::to_underlying().

Referenced by write_xdmf().

◆ getTopologyType()

ParentDataType MeshLib::IO::getTopologyType ( MeshLib::Mesh const & mesh)

Definition at line 299 of file transformData.cpp.

300{
301 auto const& elements = mesh.getElements();
302
303 if (elements.empty())
304 {
306 }
307 auto const ogs_cell_type = elements[0]->getCellType();
308
309 if (std::any_of(elements.begin(), elements.end(),
310 [&](auto const& cell)
311 { return cell->getCellType() != ogs_cell_type; }))
312 {
314 }
315
316 return cellTypeOGS2XDMF(ogs_cell_type).id;
317}

References cellTypeOGS2XDMF(), MeshLib::Mesh::getElements(), and MIXED.

Referenced by transformToXDMFTopology().

◆ getVtuFileNameForPetscOutputWithoutExtension()

std::string MeshLib::IO::getVtuFileNameForPetscOutputWithoutExtension ( std::string const & file_name)

Definition at line 126 of file VtuInterface.cpp.

128{
129 auto const file_name_extension = BaseLib::getFileExtension(file_name);
130 if (file_name_extension != ".vtu")
131 {
132 OGS_FATAL("Expected a .vtu file for petsc output.");
133 }
134
135 auto const file_name_base = boost::erase_last_copy(file_name, ".vtu");
136 auto basename = BaseLib::extractBaseName(file_name_base);
137
138 // Replace dots to underscores since the pvtu writing function drops all
139 // characters starting from a dot.
140 std::replace(basename.begin(), basename.end(), '.', '_');
141
142 // Restore the dirname if any.
143 auto const dirname = BaseLib::extractPath(file_name_base);
144 return BaseLib::joinPaths(dirname, basename);
145}
#define OGS_FATAL(...)
Definition Error.h:26
std::string getFileExtension(const std::string &path)
std::string extractPath(std::string const &pathname)
std::string joinPaths(std::string const &pathA, std::string const &pathB)
std::string extractBaseName(std::string const &pathname)

References BaseLib::extractBaseName(), BaseLib::extractPath(), BaseLib::getFileExtension(), BaseLib::joinPaths(), and OGS_FATAL.

Referenced by ApplicationsLib::TestDefinition::TestDefinition(), MeshLib::IO::PVDFile::addVTUFile(), and MeshLib::IO::VtuInterface::writeToFile().

◆ isFileManager()

bool MeshLib::IO::isFileManager ( )

Definition at line 26 of file partition.cpp.

27{
28 int mpi_rank;
29 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
30 return mpi_rank == 0;
31}

Referenced by MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter(), and MeshLib::IO::XdmfHdfWriter::writeStep().

◆ isVariableAttribute()

template<typename Data >
std::function< bool(Data)> MeshLib::IO::isVariableAttribute ( std::set< std::string > const & variable_output_names)

Definition at line 43 of file XdmfHdfWriter.cpp.

45{
46 if (variable_output_names.empty())
47 {
48 return [](Data const& data) -> bool
49 {
50 constexpr std::array constant_output_names{
51 "MaterialIDs"sv,
52 "topology"sv,
53 "geometry"sv,
54 "OGS_VERSION"sv,
59 return !ranges::contains(constant_output_names, data.name);
60 };
61 }
62 return [&variable_output_names](Data const& data) -> bool
63 { return variable_output_names.contains(data.name); };
64}
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:188

References MeshLib::Cell, MeshLib::Edge, MeshLib::Face, MeshLib::getBulkIDString(), and MeshLib::Node.

◆ meshItemTypeString()

static std::string MeshLib::IO::meshItemTypeString ( std::optional< MeshItemType > const & item_type)
static

Definition at line 43 of file writeXdmf.cpp.

45{
46 if (item_type)
47 {
48 return mesh_item_type_strings[static_cast<int>(item_type.value())];
49 }
50 OGS_FATAL("Cannot convert an empty optional mesh item type.");
51}
constexpr char const * mesh_item_type_strings[]
Definition writeXdmf.cpp:39

References mesh_item_type_strings, and OGS_FATAL.

Referenced by write_xdmf().

◆ meshPropertyDatatypeSize()

static constexpr auto MeshLib::IO::meshPropertyDatatypeSize ( )
staticconstexpr

◆ meshPropertyDatatypeString()

static auto MeshLib::IO::meshPropertyDatatypeString ( )
static

Definition at line 55 of file writeXdmf.cpp.

56{
57 std::array<std::string, to_underlying(MeshPropertyDataType::enum_length)>
58 ogs_to_xdmf_type = {};
59 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::float64)] = "Float";
60 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::float32)] = "Float";
61 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::int32)] = "Int";
62 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::int64)] = "Int";
63 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::uint32)] = "UInt";
64 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::uint64)] = "UInt";
65 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::int8)] = "Int";
66 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::uint8)] = "UInt";
67 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::char_native)] = "Char";
68 ogs_to_xdmf_type[to_underlying(MeshPropertyDataType::uchar)] = "UChar";
69 return ogs_to_xdmf_type;
70}

References char_native, enum_length, float32, float64, int32, int64, int8, BaseLib::to_underlying(), uchar, uint32, uint64, and uint8.

Referenced by getPropertyDataTypeString().

◆ meshPropertyType2HdfType()

static hid_t MeshLib::IO::meshPropertyType2HdfType ( MeshPropertyDataType const ogs_data_type)
static

Definition at line 22 of file HdfData.cpp.

23{
24 std::map<MeshPropertyDataType const, hid_t> ogs_to_hdf_type = {
25 {MeshPropertyDataType::float64, H5T_NATIVE_DOUBLE},
26 {MeshPropertyDataType::float32, H5T_NATIVE_FLOAT},
27 {MeshPropertyDataType::int32, H5T_NATIVE_INT32},
28 {MeshPropertyDataType::int64, H5T_NATIVE_INT64},
29 {MeshPropertyDataType::uint32, H5T_NATIVE_UINT32},
30 {MeshPropertyDataType::uint64, H5T_NATIVE_UINT64},
31 {MeshPropertyDataType::int8, H5T_NATIVE_INT8},
32 {MeshPropertyDataType::uint8, H5T_NATIVE_UINT8},
33 {MeshPropertyDataType::char_native, H5T_NATIVE_CHAR},
34 {MeshPropertyDataType::uchar, H5T_NATIVE_UCHAR}};
35 try
36 {
37 return ogs_to_hdf_type.at(ogs_data_type);
38 }
39 catch (std::exception const& e)
40 {
41 OGS_FATAL("No known HDF5 type for OGS type. {:s}", e.what());
42 }
43}

References char_native, float32, float64, int32, int64, int8, OGS_FATAL, uchar, uint32, uint64, and uint8.

Referenced by MeshLib::IO::HdfData::HdfData().

◆ openHDF5File() [1/2]

int64_t MeshLib::IO::openHDF5File ( std::filesystem::path const & filepath)

Definition at line 25 of file fileIO.cpp.

26{
27 return H5Fopen(filepath.string().c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
28}

◆ openHDF5File() [2/2]

hid_t MeshLib::IO::openHDF5File ( std::filesystem::path const & filepath,
unsigned int n_files )

Definition at line 58 of file fileIO.cpp.

60{
61 MPI_Comm const comm = getCommunicator(n_files).mpi_communicator;
62 MPI_Info info = MPI_INFO_NULL;
63 hid_t const plist_id = H5Pcreate(H5P_FILE_ACCESS);
64 H5Pset_fapl_mpio(plist_id, comm, info);
65 hid_t file = H5Fopen(filepath.string().c_str(), H5F_ACC_RDWR, plist_id);
66 H5Pclose(plist_id);
67 return file;
68}

References getCommunicator(), and MeshLib::IO::FileCommunicator::mpi_communicator.

◆ partitionFilename()

std::filesystem::path MeshLib::IO::partitionFilename ( std::filesystem::path const & basic_filepath,
int const file_group )

Definition at line 24 of file fileIO.cpp.

26{
27 std::string const filename = (file_group > 0)
28 ? basic_filepath.stem().string() + '_' +
29 std::to_string(file_group) +
30 basic_filepath.extension().string()
31 : basic_filepath.filename().string();
32 std::filesystem::path const filepathwithextension =
33 basic_filepath.parent_path() / filename;
34 DBUG("HDF Filepath: {:s}.", filepathwithextension.string());
35 return filepathwithextension;
36};
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30

References DBUG().

Referenced by createFile().

◆ readMeshFromFile()

MeshLib::Mesh * MeshLib::IO::readMeshFromFile ( const std::string & file_name,
bool const compute_element_neighbors )

Definition at line 67 of file readMeshFromFile.cpp.

69{
70#ifdef USE_PETSC
71 int mpi_init;
72 MPI_Initialized(&mpi_init);
73 if (mpi_init == 1)
74 {
75 int world_size;
76 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
77 if (world_size > 1)
78 {
79 MeshLib::IO::NodePartitionedMeshReader read_pmesh(MPI_COMM_WORLD);
80 const std::string file_name_base =
82 return read_pmesh.read(file_name_base);
83 }
84 if (world_size == 1)
85 {
86 std::unique_ptr<Mesh> mesh{
87 readMeshFromFileSerial(file_name, compute_element_neighbors)};
88
89 if (!mesh)
90 {
91 return nullptr;
92 }
93
94 return new MeshLib::NodePartitionedMesh(*mesh);
95 }
96 return nullptr;
97 }
98#endif
99 return readMeshFromFileSerial(file_name, compute_element_neighbors);
100}
std::string dropFileExtension(std::string const &filename)
MeshLib::Mesh * readMeshFromFileSerial(const std::string &file_name, bool const compute_element_neighbors)

References BaseLib::dropFileExtension(), and MeshLib::IO::NodePartitionedMeshReader::read().

Referenced by createGeometries(), FileIO::createSurface(), MainWindow::loadFile(), main(), main(), MainWindow::mapGeometry(), anonymous_namespace{postLIE.cpp}::postVTU(), FileIO::XmlPrjInterface::readFile(), readMeshes(), and anonymous_namespace{ProjectData.cpp}::readSingleMesh().

◆ readPropertyVectorMetaData()

std::optional< PropertyVectorMetaData > MeshLib::IO::readPropertyVectorMetaData ( std::istream & is)
inline

Definition at line 85 of file PropertyVectorMetaData.h.

87{
88 // read the size of the name of the PropertyVector
89 std::string::size_type s = 0;
90 if (!is.read(reinterpret_cast<char*>(&s), sizeof(std::string::size_type)))
91 {
92 return std::optional<PropertyVectorMetaData>();
93 }
94
95 PropertyVectorMetaData pvmd;
96 char *dummy = new char[s];
97 if (!is.read(dummy, s))
98 {
99 return std::nullopt;
100 }
101 pvmd.property_name = std::string(dummy, s);
102 delete [] dummy;
103
104 if(!is.read(reinterpret_cast<char*>(&pvmd.is_int_type), sizeof(bool)))
105 return std::nullopt;
106 if(!is.read(reinterpret_cast<char*>(&pvmd.is_data_type_signed), sizeof(bool)))
107 return std::nullopt;
108 if(!is.read(reinterpret_cast<char*>(&pvmd.data_type_size_in_bytes),
109 sizeof(unsigned long)))
110 return std::nullopt;
111 if(!is.read(reinterpret_cast<char*>(&pvmd.number_of_components),
112 sizeof(unsigned long)))
113 return std::nullopt;
114 if(!is.read(reinterpret_cast<char*>(&pvmd.number_of_tuples),
115 sizeof(unsigned long)))
116 return std::nullopt;
117 return std::optional<PropertyVectorMetaData>(pvmd);
118}

References MeshLib::IO::PropertyVectorMetaData::data_type_size_in_bytes, MeshLib::IO::PropertyVectorMetaData::is_data_type_signed, MeshLib::IO::PropertyVectorMetaData::is_int_type, MeshLib::IO::PropertyVectorMetaData::number_of_components, MeshLib::IO::PropertyVectorMetaData::number_of_tuples, and MeshLib::IO::PropertyVectorMetaData::property_name.

Referenced by MeshLib::IO::NodePartitionedMeshReader::readProperties().

◆ readPropertyVectorPartitionMetaData()

std::optional< PropertyVectorPartitionMetaData > MeshLib::IO::readPropertyVectorPartitionMetaData ( std::istream & is)
inline

Definition at line 140 of file PropertyVectorMetaData.h.

141{
143 if (!is.read(reinterpret_cast<char*>(&pvpmd.offset), sizeof(unsigned long)))
144 {
145 return std::optional<PropertyVectorPartitionMetaData>();
146 }
147 if (!is.read(reinterpret_cast<char*>(&pvpmd.number_of_tuples),
148 sizeof(unsigned long)))
149 {
150 return std::optional<PropertyVectorPartitionMetaData>();
151 }
152 return std::optional<PropertyVectorPartitionMetaData>(pvpmd);
153}

References MeshLib::IO::PropertyVectorPartitionMetaData::number_of_tuples, and MeshLib::IO::PropertyVectorPartitionMetaData::offset.

Referenced by MeshLib::IO::NodePartitionedMeshReader::readProperties().

◆ transformAttribute()

std::optional< XdmfHdfData > MeshLib::IO::transformAttribute ( std::pair< std::string, PropertyVectorBase * > const & property_pair,
unsigned int const n_files,
unsigned int const chunk_size_bytes )

Definition at line 91 of file transformData.cpp.

94{
95 // 3 data that will be captured and written by lambda f below
97 std::size_t num_of_tuples = 0;
98 void const* data_ptr = 0;
99
100 // lambda f : Collects properties from the propertyVectorBase. It captures
101 // (and overwrites) data that can only be collected via the typed property.
102 // It has boolean return type to allow kind of pipe using || operator.
103 auto f = [&data_type, &num_of_tuples, &data_ptr,
104 &property_pair](auto basic_type) -> bool
105 {
106 auto const property_base = property_pair.second;
107 auto const typed_property =
108 dynamic_cast<PropertyVector<decltype(basic_type)> const*>(
109 property_base);
110 if (typed_property == nullptr)
111 {
112 return false;
113 }
114 // overwrite captured data
115 num_of_tuples = typed_property->getNumberOfTuples();
116 data_ptr = typed_property->data();
117
118 if constexpr (std::is_same_v<double, decltype(basic_type)>)
119 {
120 // The standard 64-bit IEEE 754 floating-point type
121 // (double-precision) has a 53 bit fractional part (52 bits written,
122 // one implied)
123 static_assert((std::numeric_limits<double>::digits == 53),
124 "Double has 52 bits fractional part");
126 }
127 else if constexpr (std::is_same_v<float, decltype(basic_type)>)
128 {
129 // The standard 32-bit IEEE 754 floating-point type
130 // (single-precision) has a 24 bit fractional part (23 bits written,
131 // one implied)
132 static_assert((std::numeric_limits<float>::digits == 24),
133 "Float has 23 bits fractional part");
135 }
136 else if constexpr (std::is_same_v<int, decltype(basic_type)>)
137 {
138 static_assert((std::numeric_limits<int>::digits == 31),
139 "Signed int has 32-1 bits");
140 data_type = MeshPropertyDataType::int32;
141 }
142 // ToDo (tm) These tests are platform specific and currently fail on
143 // Windows else if constexpr (std::is_same_v<long,
144 // decltype(basic_type)>)
145 //{
146 // static_assert((std::numeric_limits<long>::digits == 63),
147 // "Signed int has 64-1 bits");
148 // data_type = MeshPropertyDataType::int64;
149 //}
150 // else if constexpr (std::is_same_v<unsigned long,
151 // decltype(basic_type)>)
152 //{
153 // static_assert((std::numeric_limits<unsigned long>::digits == 64),
154 // "Unsigned long has 64 bits");
155 // data_type = MeshPropertyDataType::uint64;
156 //}
157 else if constexpr (std::is_same_v<unsigned int, decltype(basic_type)>)
158 {
159 static_assert((std::numeric_limits<unsigned int>::digits == 32),
160 "Unsigned int has 32 bits");
162 }
163 else if constexpr (std::is_same_v<std::size_t, decltype(basic_type)>)
164 {
165 static_assert((std::numeric_limits<std::size_t>::digits == 64),
166 "size_t has 64 bits");
168 }
169 else if constexpr (std::is_same_v<char, decltype(basic_type)>)
170 {
172 }
173 else if constexpr (std::is_same_v<unsigned char, decltype(basic_type)>)
174 {
175 static_assert((std::numeric_limits<unsigned char>::digits == 8),
176 "Unsigned char has 8 bits");
177 data_type = MeshPropertyDataType::uchar;
178 }
179 else
180 {
181 return false;
182 }
183 return true;
184 };
185
186 f(double{}) || f(float{}) || f(int{}) || f(long{}) || f(unsigned{}) ||
187 f(long{}) || f(static_cast<unsigned long>(0)) || f(std::size_t{}) ||
188 f(char{}) || f(static_cast<unsigned char>(0));
189
190 if (data_type == MeshPropertyDataType::unknown)
191 {
192 return std::nullopt;
193 }
194
195 auto const& property_base = property_pair.second;
196 auto const& global_components =
197 property_base->getNumberOfGlobalComponents();
198 // TODO (tm) property_pair vector::getNumberOfGlobalComponents should return
199 // unsigned value. Then explicit cast from signed to unsigned int and
200 // assert can be removed here. Implicit cast to long long is fine and
201 // can be kept
202 assert(global_components >= 0);
203 auto const ui_global_components =
204 static_cast<unsigned int>(global_components);
205
206 MeshLib::MeshItemType const mesh_item_type =
207 property_base->getMeshItemType();
208
209 std::string const& name = property_base->getPropertyName();
210
211 HdfData hdf = {data_ptr, num_of_tuples, ui_global_components, name,
212 data_type, n_files, chunk_size_bytes};
213
214 XdmfData xdmf{num_of_tuples, ui_global_components, data_type,
215 name, mesh_item_type, 0,
216 n_files, std::nullopt};
217
218 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
219}
MeshPropertyDataType
std::size_t getNumberOfTuples() const
MeshItemType
Definition Location.h:21

References char_native, float32, float64, MeshLib::PropertyVector< PROP_VAL_TYPE >::getNumberOfTuples(), int32, uchar, uint32, uint64, and unknown.

Referenced by transformAttributes().

◆ transformAttributes()

std::vector< XdmfHdfData > MeshLib::IO::transformAttributes ( MeshLib::Mesh const & mesh,
unsigned int n_files,
unsigned int chunk_size_bytes )

Create meta data for attributes used for hdf5 and xdmf.

Parameters
meshOGS mesh can be mesh or partitionedMesh
n_filesspecifies the number of files. If greater than 1 it groups the data of each process to n_files
chunk_size_bytesData will be split into chunks. The parameter specifies the size (in bytes) of the largest chunk.
Returns
vector of meta data

Definition at line 221 of file transformData.cpp.

224{
225 MeshLib::Properties const& properties = mesh.getProperties();
226
227 // \TODO (tm) use c++20 ranges
228 // a = p | filter (first!=OGS_VERSION) | filter null_opt | transformAttr |
229 std::vector<XdmfHdfData> attributes;
230 for (auto const& [name, property_base] : properties)
231 {
233 {
234 continue;
235 }
236
237 if (!property_base->is_for_output)
238 {
239 continue;
240 }
241
242 if (auto const attribute = transformAttribute(
243
244 std::pair(std::string(name), property_base), n_files,
245 chunk_size_bytes))
246
247 {
248 attributes.push_back(attribute.value());
249 }
250 else
251 {
252 WARN("Could not create attribute meta of {:s}.", name);
253 }
254 }
255 return attributes;
256}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:36
const std::string OGS_VERSION
Definition GitInfo.cpp:20

References MeshLib::Mesh::getProperties(), GitInfoLib::GitInfo::OGS_VERSION, transformAttribute(), and WARN().

Referenced by MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter().

◆ transformGeometry()

XdmfHdfData MeshLib::IO::transformGeometry ( MeshLib::Mesh const & mesh,
double const * data_ptr,
unsigned int n_files,
unsigned int chunk_size_bytes )

Create meta data for geometry used for hdf5 and xdmf.

Parameters
meshOGS mesh can be mesh or partitionedMesh
data_ptrMemory location of geometry values.
n_filesspecifies the number of files. If greater than 1 it groups the data of each process to n_files
chunk_size_bytesData will be split into chunks. The parameter specifies the size (in bytes) of the largest chunk.
Returns
Geometry meta data

Definition at line 274 of file transformData.cpp.

277{
278 std::string const name = "geometry";
279 std::vector<MeshLib::Node*> const& nodes = mesh.getNodes();
280
281 int const point_size = 3;
282 auto const& partition_dim = nodes.size();
283
284 HdfData const hdf = {data_ptr,
285 partition_dim,
286 point_size,
287 name,
289 n_files,
290 chunk_size_bytes};
291 XdmfData const xdmf = {
292 partition_dim, point_size, MeshPropertyDataType::float64,
293 name, std::nullopt, 2,
294 n_files, std::nullopt};
295
296 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
297}

References float64, and MeshLib::Mesh::getNodes().

Referenced by MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter().

◆ transformTopology()

XdmfHdfData MeshLib::IO::transformTopology ( std::vector< int > const & values,
ParentDataType const parent_data_type,
unsigned int n_files,
unsigned int chunk_size_bytes )

Create meta data for topology used for HDF5 and XDMF.

Parameters
valuesactual topology values to get size and memory location
parent_data_typeXDMF topological element data types as listed in the enum ParentDataTypei
n_filesspecifies the number of files. If greater than 1 it groups the data of each process to n_files
chunk_size_bytesData will be split into chunks. The parameter specifies the size (in bytes) of the largest chunk.
Returns
Topology meta data

Definition at line 370 of file transformData.cpp.

374{
375 std::string const name = "topology";
376 HdfData const hdf = {
377 values.data(), values.size(), 1, name, MeshPropertyDataType::int32,
378 n_files, chunk_size_bytes};
379 XdmfData const xdmf{values.size(),
380 1,
382 name,
383 std::nullopt,
384 3,
385 n_files,
386 parent_data_type};
387
388 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
389}

References int32.

Referenced by MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter().

◆ transformToXDMFGeometry()

std::vector< double > MeshLib::IO::transformToXDMFGeometry ( MeshLib::Mesh const & mesh)

Copies all node points into a new vector. Contiguous data used for writing. Conform with XDMF standard in https://xdmf.org/index.php/XDMF_Model_and_Format.

Parameters
meshOGS mesh can be mesh or partitionedMesh
Returns
vector containing a copy of the data

Definition at line 258 of file transformData.cpp.

259{
260 std::vector<MeshLib::Node*> const& nodes = mesh.getNodes();
261
262 int const point_size = 3;
263 std::vector<double> values;
264 values.reserve(nodes.size() * point_size);
265 for (auto const& n : nodes)
266 {
267 const double* x = n->data();
268 values.insert(values.cend(), x, x + point_size);
269 }
270
271 return values;
272}

References MeshLib::Mesh::getNodes().

Referenced by MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter().

◆ transformToXDMFTopology()

std::pair< std::vector< int >, ParentDataType > MeshLib::IO::transformToXDMFTopology ( MeshLib::Mesh const & mesh,
std::size_t const offset )

Copies all cells into a new vector. Contiguous data used for writing. The topology is specific to xdmf because it contains the xdmf cell types!! See section topology in https://xdmf.org/index.php/XDMF_Model_and_Format.

Parameters
meshOGS mesh can be mesh or partitionedMesh
offsetLocal offset to transform local to global cell ID. Offset must be zero in serial and must be defined for each process in parallel execution.
Returns
vector containing a copy of the data and the computed ParentDataType

Definition at line 319 of file transformData.cpp.

321{
322 std::vector<MeshLib::Element*> const& elements = mesh.getElements();
323 std::vector<int> values;
324
325 auto const push_cellnode_ids_to_vector =
326 [&values, &offset](auto const& cell)
327 {
328 values |= ranges::actions::push_back(
329 cell->nodes() | MeshLib::views::ids |
330 ranges::views::transform([&offset](auto const node_id) -> int
331 { return node_id + offset; }));
332 };
333
334 auto const topology_type = getTopologyType(mesh);
335 if (topology_type == ParentDataType::MIXED)
336 {
337 values.reserve(elements.size() * 2); // each cell has at least two
338 // numbers
339 for (auto const& cell : elements)
340 {
341 auto const ogs_cell_type = cell->getCellType();
342 auto const xdmf_cell_id = cellTypeOGS2XDMF(ogs_cell_type).id;
343 values.push_back(to_underlying(xdmf_cell_id));
344 push_cellnode_ids_to_vector(cell);
345 }
346 }
347 else if (topology_type == ParentDataType::POLYVERTEX ||
348 topology_type == ParentDataType::POLYLINE)
349 {
350 // '+ 1' for number of nodes of the cell
351 values.reserve(elements.size() * (elements[0]->getNumberOfNodes() + 1));
352 for (auto const& cell : elements)
353 {
354 values.push_back(cell->getNumberOfNodes());
355 push_cellnode_ids_to_vector(cell);
356 }
357 }
358 else
359 {
360 values.reserve(elements.size() * elements[0]->getNumberOfNodes());
361 for (auto const& cell : elements)
362 {
363 push_cellnode_ids_to_vector(cell);
364 }
365 }
366
367 return {values, topology_type};
368}
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:225

References cellTypeOGS2XDMF(), MeshLib::Mesh::getElements(), getTopologyType(), MeshLib::views::ids, MIXED, POLYLINE, POLYVERTEX, and BaseLib::to_underlying().

Referenced by MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter().

◆ write_xdmf()

std::function< std::string(std::vector< double >)> MeshLib::IO::write_xdmf ( XdmfData const & geometry,
XdmfData const & topology,
std::vector< XdmfData > const & constant_attributes,
std::vector< XdmfData > const & variable_attributes,
std::string const & h5filename,
std::string const & ogs_version,
std::string const & mesh_name )

Generator function that creates a function capturing the spatial data of a mesh Temporal data can later be passed as argument.

Parameters
geometryMetadata for the geometry (points) of the mesh
topologyMetadata for the topology of the mesh
variable_attributesMeta data for attributes changing over time
constant_attributesMeta data for attributes NOT changing over time
h5filenameName of the file where the actual data was written
ogs_versionOGS Version to be added to XdmfInformation tag
mesh_nameName of the output mesh
Returns
unary function with vector of time step values, returning XDMF string

Definition at line 106 of file writeXdmf.cpp.

112{
113 // Generates function that writes <DataItem>. Late binding needed because
114 // maximum number of steps unknown. Time step and h5filename are captured to
115 // return a unary function
116 // _a suffix is a user defined literal for fmt named arguments
117 auto const time_dataitem_genfn =
118 [](unsigned long long const time_step, int const max_step,
119 std::string const& h5filename, std::string const& mesh_name)
120 {
121 return
122 [time_step, max_step, h5filename, mesh_name](auto const& xdmfdata)
123 {
124 return fmt::format(
125 fmt::runtime("\n\t\t<DataItem DataType=\"{datatype}\" "
126 "Dimensions=\"{local_dimensions}\" "
127 "Format=\"HDF\" "
128 "Precision=\"{precision}\">"
129 "{filename}:/meshes/{meshname}/{datasetname}|"
130 "{time_step} {starts}:1 {strides}:1 "
131 "{local_dimensions}:{max_step} "
132 "{global_dimensions}</"
133 "DataItem>"),
134 "datatype"_a = getPropertyDataTypeString(xdmfdata.data_type),
135 "local_dimensions"_a =
136 fmt::join(xdmfdata.global_block_dims, " "),
137 "precision"_a = getPropertyDataTypeSize(xdmfdata.data_type),
138 "filename"_a = h5filename,
139 "meshname"_a = mesh_name,
140 "datasetname"_a = xdmfdata.name,
141 "starts"_a = fmt::join(xdmfdata.starts, " "),
142 "strides"_a = fmt::join(xdmfdata.strides, " "),
143 "global_dimensions"_a =
144 fmt::join(xdmfdata.global_block_dims, " "),
145 "time_step"_a = fmt::format("{}", time_step),
146 "max_step"_a = fmt::format("{}", max_step));
147 };
148 };
149
150 // string_join could be moved to ogs lib if used more
151 auto const string_join_fn = [](auto const& collection)
152 { return fmt::to_string(fmt::join(collection, "")); };
153
154 // m_bind could be moved to ogs lib if used more
155 auto const m_bind_fn = [](auto const& transform, auto const& join)
156 {
157 return [join, transform](auto const& collection)
158 {
159 std::vector<std::string> temp;
160 temp.reserve(collection.size());
161 std::transform(collection.begin(), collection.end(),
162 std::back_inserter(temp), transform);
163 return join(temp);
164 };
165 };
166
167 // XDMF if part of the data that is already written in any previous step
168 // subsequent steps can refer to this data collection of elements navigates
169 // the xml tree (take first child, then in child take 2nd child ...)
170 auto const pointer_transfrom = [](auto const& elements)
171 {
172 return fmt::format(
173 fmt::runtime("\n\t<xi:include xpointer=\"element(/{elements})\"/>"),
174 "elements"_a = fmt::join(elements, "/"));
175 };
176
177 // Defines content of <Attribute> in XDMF, child of Attribute is a single
178 // <DataItem>
179 auto const attribute_transform =
180 [](XdmfData const& attribute, auto const& dataitem_transform)
181 {
182 return fmt::format(
183 "\n\t<Attribute Center=\"{center}\" ElementCell=\"\" "
184 "ElementDegree=\"0\" "
185 "ElementFamily=\"\" ItemType=\"\" Name=\"{name}\" "
186 "Type=\"None\">{dataitem}\n\t</Attribute>",
187 "center"_a = meshItemTypeString(attribute.attribute_center),
188 "name"_a = attribute.name,
189 "dataitem"_a = dataitem_transform(attribute));
190 };
191
192 // Define content of <Geometry> in XDMF, same as attribute_transform
193 auto const geometry_transform =
194 [](XdmfData const& geometry, auto const& dataitem_transform)
195 {
196 return fmt::format(
197 fmt::runtime("\n\t<Geometry Origin=\"\" "
198 "Type=\"XYZ\">{dataitem}\n\t</Geometry>"),
199 "dataitem"_a = dataitem_transform(geometry));
200 };
201
202 auto tag_string = [](auto const& topology, int nodes_per_element,
203 auto const& dataitem_transform)
204 {
205 return fmt::format(
206 fmt::runtime("\n\t<Topology Dimensions=\"{dimensions}\" "
207 "Type=\"{topology_type}\" "
208 "NodesPerElement=\"{nodes_per_element}\">{dataitem}"
209 "\n\t</Topology>"),
210 "topology_type"_a =
211 ParentDataType2String(*topology.parent_data_type),
212 "dataitem"_a = dataitem_transform(topology),
213 "dimensions"_a = fmt::join(topology.global_block_dims, " "),
214 "nodes_per_element"_a = nodes_per_element);
215 };
216
217 // Define content of <Topology> in XDMF, same as attribute_transform
218 auto const topology_transform =
219 [&tag_string](XdmfData const& topology, auto const& dataitem_transform)
220 {
221 switch (*topology.parent_data_type)
222 {
224 return tag_string(topology, 1, dataitem_transform);
226 return tag_string(topology, 2, dataitem_transform);
244 return fmt::format(
245 fmt::runtime(
246 "\n\t<Topology Dimensions=\"{dimensions}\" "
247 "Type=\"{topology_type}\">{dataitem}\n\t</Topology>"),
248 "topology_type"_a =
249 ParentDataType2String(*topology.parent_data_type),
250 "dataitem"_a = dataitem_transform(topology),
251 "dimensions"_a =
252 fmt::join(topology.global_block_dims, " "));
253 }
254 OGS_FATAL("Could not transform unknown XDMF topology type");
255 return std::string{};
256 };
257
258 // Defines content of <Grid> of a single time step, takes specific transform
259 // functions for all of its child elements
260 auto const grid_transform =
261 [](double const& time_value, auto const& geometry, auto const& topology,
262 auto const& constant_attributes, auto const& variable_attributes)
263 {
264 return fmt::format(
265 R"(
266<Grid Name="Grid" GridType="Uniform">
267 <Time Value="{time_value:.{precision}g}"/>
268{geometry}
269{topology}
270{fix_attributes}
271{variable_attributes}
272</Grid>)",
273 "time_value"_a = time_value,
274 // Output of "Time Value" with sufficient precision.
275 "precision"_a = std::numeric_limits<double>::max_digits10,
276 "geometry"_a = geometry,
277 "topology"_a = topology,
278 "fix_attributes"_a = constant_attributes,
279 "variable_attributes"_a = variable_attributes);
280 };
281
282 // An attribute may change over time (variable) or stay constant
283 enum class time_attribute
284 {
285 constant,
286 variable
287 };
288
289 // Generates a function that either writes the data or points to existing
290 // data
291 auto const time_step_fn = [time_dataitem_genfn, pointer_transfrom,
292 h5filename,
293 mesh_name](auto const& component_transform,
294 unsigned long long const time_step,
295 int const max_step,
296 time_attribute const variable)
297 {
298 return [component_transform, time_dataitem_genfn, pointer_transfrom,
299 variable, time_step, max_step, h5filename,
300 mesh_name](XdmfData const& attr)
301 {
302 // new data arrived
303 bool const changed =
304 ((time_step > 0 && (variable == time_attribute::variable)) ||
305 time_step == 0);
306 if (changed)
307 {
308 auto dataitem = time_dataitem_genfn(time_step, max_step,
309 h5filename, mesh_name);
310 return component_transform(attr, dataitem);
311 }
312 else
313 {
314 std::array<unsigned int, 5> position = {1, 1, 2, 1, attr.index};
315 return pointer_transfrom(position);
316 };
317 };
318 };
319
320 // Top-Level transform function (take spatial and temporal transform
321 // functions) and return the time depended grid transform function
322 // ToDo (tm) Remove capturing m_bind and string_join as helper function
323
324 auto const time_grid_transform =
325 [time_step_fn, m_bind_fn, string_join_fn, grid_transform,
326 geometry_transform, topology_transform, attribute_transform](
327 double const time, int const step, int const max_step,
328 auto const& geometry, auto const& topology,
329 auto const& constant_attributes, auto const& variable_attributes)
330 {
331 auto const time_step_geometry_transform = time_step_fn(
332 geometry_transform, step, max_step, time_attribute::constant);
333 auto const time_step_topology_transform = time_step_fn(
334 topology_transform, step, max_step, time_attribute::constant);
335 auto const time_step_const_attribute_fn = time_step_fn(
336 attribute_transform, step, max_step, time_attribute::constant);
337 auto const time_step_variable_attribute_fn = time_step_fn(
338 attribute_transform, step, max_step, time_attribute::variable);
339
340 // lift both functions from handling single attributes to work with
341 // collection of attributes
342 auto const variable_attributes_transform =
343 m_bind_fn(time_step_variable_attribute_fn, string_join_fn);
344 auto const constant_attributes_transform =
345 m_bind_fn(time_step_const_attribute_fn, string_join_fn);
346
347 return grid_transform(
348 time, time_step_geometry_transform(geometry),
349 time_step_topology_transform(topology),
350 constant_attributes_transform(constant_attributes),
351 variable_attributes_transform(variable_attributes));
352 };
353
354 // Function that combines all the data from spatial (geometry, topology,
355 // attribute) and temporal domain (time) with the time domain
356 // (time_step_fn). And writes <Grid CollectionType="Temporal">
357 auto const temporal_grid_collection_transform =
358 [time_grid_transform](
359 auto const& times, auto const& geometry, auto const& topology,
360 auto const& constant_attributes, auto const& variable_attributes)
361 {
362 // c++20 ranges zip missing
363 auto const max_step = times.size();
364 std::vector<std::string> grids;
365 grids.reserve(max_step);
366 for (size_t time_step = 0; time_step < max_step; ++time_step)
367 {
368 grids.push_back(time_grid_transform(
369 times[time_step], time_step, max_step, geometry, topology,
370 constant_attributes, variable_attributes));
371 }
372 return fmt::format(
373 fmt::runtime(
374 "\n<Grid CollectionType=\"Temporal\" GridType=\"Collection\" "
375 "Name=\"Collection\">{grids}\n</Grid>\n"),
376 "grids"_a = fmt::join(grids, ""));
377 };
378
379 // Generator function that return a function that represents complete xdmf
380 // structure
381 auto const xdmf_writer_fn = [temporal_grid_collection_transform](
382 auto ogs_version, auto geometry,
383 auto topology, auto constant_attributes,
384 auto variable_attributes)
385 {
386 // This function will be the return of the surrounding named function
387 // capture by copy - it is the function that will survive this scope!!
388 // Use generalized lambda capture to move for optimization
389 return [temporal_grid_collection_transform,
390 ogs_version = std::move(ogs_version),
391 geometry = std::move(geometry), topology = std::move(topology),
392 constant_attributes = std::move(constant_attributes),
393 variable_attributes = std::move(variable_attributes)](
394 std::vector<double> const& times)
395 {
396 return fmt::format(
397 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Xdmf "
398 "xmlns:xi=\"http://www.w3.org/2001/XInclude\" "
399 "Version=\"3.0\">\n<Domain>\n<Information Name=\"OGS_VERSION\" "
400 "Value=\"{ogs_version}\"/>{grid_collection}</Domain>\n</Xdmf>",
401 "ogs_version"_a = ogs_version,
402 "grid_collection"_a = temporal_grid_collection_transform(
403 times, geometry, topology, constant_attributes,
std::string ParentDataType2String(ParentDataType p)
GITINFOLIB_EXPORT const std::string ogs_version
static std::string getPropertyDataTypeString(MeshPropertyDataType const &ogs_data_type)
Definition writeXdmf.cpp:73
static std::string meshItemTypeString(std::optional< MeshItemType > const &item_type)
Definition writeXdmf.cpp:43
static std::string getPropertyDataTypeSize(MeshPropertyDataType const &ogs_data_type)
Definition writeXdmf.cpp:98

References MeshLib::IO::XdmfData::attribute_center, EDGE_3, getPropertyDataTypeSize(), getPropertyDataTypeString(), MeshLib::IO::XdmfData::global_block_dims, HEXAHEDRON, HEXAHEDRON_20, HEXAHEDRON_27, meshItemTypeString(), MIXED, MeshLib::IO::XdmfData::name, OGS_FATAL, MeshLib::IO::XdmfData::parent_data_type, ParentDataType2String(), POLYLINE, POLYVERTEX, PYRAMID, PYRAMID_13, QUADRILATERAL, QUADRILATERAL_8, QUADRILATERAL_9, TETRAHEDRON, TETRAHEDRON_10, TRIANGLE, TRIANGLE_6, WEDGE, WEDGE_15, and WEDGE_18.

Referenced by MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter().

◆ writeMeshToFile()

int MeshLib::IO::writeMeshToFile ( const MeshLib::Mesh & mesh,
std::filesystem::path const & file_path,
std::set< std::string > variable_output_names )

Definition at line 24 of file writeMeshToFile.cpp.

28{
29 if (file_path.extension().string() == ".msh")
30 {
32 meshIO.setMesh(&mesh);
34 return 0;
35 }
36 if (file_path.extension().string() == ".vtu")
37 {
38 MeshLib::IO::VtuInterface writer(&mesh);
39 auto const result = writer.writeToFile(file_path);
40 if (!result)
41 {
42 ERR("writeMeshToFile(): Could not write mesh to '{:s}'.",
43 file_path.string());
44 return -1;
45 }
46 return 0;
47 }
48 if (file_path.extension().string() == ".xdmf")
49 {
50 std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes;
51 const std::reference_wrapper<const MeshLib::Mesh> mr = mesh;
52 meshes.push_back(mr);
53 MeshLib::IO::XdmfHdfWriter(std::move(meshes), file_path, 0, 0.0,
54 variable_output_names, true, 1, 1048576);
55 return 0;
56 }
57 ERR("writeMeshToFile(): Unknown file extension '{:s}'. Can not write file "
58 "'{:s}'.",
59 file_path.extension().string(), file_path.string());
60 return 0;
61}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:31
Interface for handling mesh files from OGS-5 and below. (*.msh files)
Definition MeshIO.h:37
void setMesh(const MeshLib::Mesh *mesh)
Set mesh for writing.
Definition MeshIO.cpp:439
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45

References ERR(), MeshLib::IO::Legacy::MeshIO::setMesh(), BaseLib::IO::writeStringToFile(), MeshLib::IO::VtuInterface::writeToFile(), and BaseLib::IO::Writer::writeToString().

Referenced by FileIO::Gocad::generateFaceSets(), identifyAndWriteBoundaryMeshes(), main(), main(), anonymous_namespace{postLIE.cpp}::postVTU(), and FileIO::XmlPrjInterface::write().

◆ writePropertyVectorMetaData() [1/2]

void MeshLib::IO::writePropertyVectorMetaData ( PropertyVectorMetaData const & pvmd)
inline

Definition at line 74 of file PropertyVectorMetaData.h.

75{
76 DBUG(
77 "name: '{:s}':\t is_int_data_type: {:d}, is_data_type_signed: "
78 "{:d}, data_type_size_in_bytes: {:d}, number of components / "
79 "tuples: {:d} / {:d}",
80 pvmd.property_name, pvmd.is_int_type, pvmd.is_data_type_signed,
81 pvmd.data_type_size_in_bytes, pvmd.number_of_components,
82 pvmd.number_of_tuples);
83}

References MeshLib::IO::PropertyVectorMetaData::data_type_size_in_bytes, DBUG(), MeshLib::IO::PropertyVectorMetaData::is_data_type_signed, MeshLib::IO::PropertyVectorMetaData::is_int_type, MeshLib::IO::PropertyVectorMetaData::number_of_components, MeshLib::IO::PropertyVectorMetaData::number_of_tuples, and MeshLib::IO::PropertyVectorMetaData::property_name.

◆ writePropertyVectorMetaData() [2/2]

void MeshLib::IO::writePropertyVectorMetaData ( std::ostream & os,
PropertyVectorMetaData const & pvmd )
inline

Definition at line 47 of file PropertyVectorMetaData.h.

49{
50 std::string::size_type s(pvmd.property_name.length());
51 os.write(reinterpret_cast<char*>(&s), sizeof(std::string::size_type));
52
53 os.write(
54 const_cast<char*>(
55 const_cast<PropertyVectorMetaData&>(pvmd).property_name.data()),
56 s);
57 os.write(reinterpret_cast<char*>(
58 &const_cast<PropertyVectorMetaData&>(pvmd).is_int_type),
59 sizeof(bool));
60 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
61 pvmd).is_data_type_signed),
62 sizeof(bool));
63 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
64 pvmd).data_type_size_in_bytes),
65 sizeof(unsigned long));
66 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
67 pvmd).number_of_components),
68 sizeof(unsigned long));
69 os.write(reinterpret_cast<char*>(
70 &const_cast<PropertyVectorMetaData&>(pvmd).number_of_tuples),
71 sizeof(unsigned long));
72}

References MeshLib::IO::PropertyVectorMetaData::property_name.

Referenced by MeshLib::IO::NodePartitionedMeshReader::readProperties(), and ApplicationUtils::writePropertyVector().

◆ writePropertyVectorPartitionMetaData()

void MeshLib::IO::writePropertyVectorPartitionMetaData ( std::ostream & os,
PropertyVectorPartitionMetaData const & pvpmd )
inline

Definition at line 126 of file PropertyVectorMetaData.h.

128{
129 os.write(reinterpret_cast<char*>(
130 &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
131 .offset),
132 sizeof(unsigned long));
133 os.write(reinterpret_cast<char*>(
134 &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
135 .number_of_tuples),
136 sizeof(unsigned long));
137}

Referenced by ApplicationUtils::writeProperties().

◆ writeVtu()

int MeshLib::IO::writeVtu ( MeshLib::Mesh const & mesh,
std::string const & file_name,
int const data_mode )

Definition at line 172 of file VtuInterface.cpp.

174{
175 MeshLib::IO::VtuInterface writer(&mesh, data_mode);
176 auto const result = writer.writeToFile(file_name);
177 if (!result)
178 {
179 ERR("writeMeshToFile(): Could not write mesh to '{:s}'.", file_name);
180 return -1;
181 }
182 return 0;
183}

References ERR(), and MeshLib::IO::VtuInterface::writeToFile().

Referenced by main().

Variable Documentation

◆ elem_type_ogs2xdmf

constexpr auto MeshLib::IO::elem_type_ogs2xdmf = elemOGSTypeToXDMFType()
constexpr

Definition at line 84 of file transformData.cpp.

Referenced by cellTypeOGS2XDMF().

◆ mesh_item_type_strings

constexpr char const* MeshLib::IO::mesh_item_type_strings[]
constexpr
Initial value:
= {"Node", "Edge", "Face",
"Cell", "Other"}

Definition at line 39 of file writeXdmf.cpp.

39 {"Node", "Edge", "Face",
40 "Cell", "Other"};

Referenced by meshItemTypeString().

◆ ogs_to_xdmf_type_fn

auto MeshLib::IO::ogs_to_xdmf_type_fn = meshPropertyDatatypeSize()
inline

Definition at line 95 of file writeXdmf.cpp.

Referenced by getPropertyDataTypeSize().