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
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 writeMeshToFile (const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > output_variable_names, bool const use_compression, int const data_mode)
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, std::set< std::string > const &output_variable_names, 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 getLocalTopologyType (MeshLib::Mesh const &mesh)
ParentDataType getTopologyType (MeshLib::Mesh const &mesh)
std::pair< std::vector< std::size_t >, 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< std::size_t > 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 &output_variable_names)

Variables

constexpr auto elem_type_ogs2xdmf = elemOGSTypeToXDMFType()
constexpr char const * mesh_item_type_strings []
auto ogs_to_xdmf_type_fn = meshPropertyDatatypeSize()
constexpr std::array constant_output_names

Typedef Documentation

◆ Hdf5DimType

using MeshLib::IO::Hdf5DimType = hsize_t

Definition at line 15 of file HdfData.h.

◆ HDFAttributes

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

Definition at line 16 of file HdfWriter.h.

◆ XdmfDimType

using MeshLib::IO::XdmfDimType = unsigned int

Definition at line 17 of file XdmfData.h.

Function Documentation

◆ cellTypeOGS2XDMF()

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

Definition at line 81 of file transformData.cpp.

82{
83 return elem_type_ogs2xdmf[to_underlying(cell_type)];
84}
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
Definition cpp23.h:22
constexpr auto elem_type_ogs2xdmf

References elem_type_ogs2xdmf, and BaseLib::to_underlying().

Referenced by getLocalTopologyType(), and transformToXDMFTopology().

◆ createFile()

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

Definition at line 28 of file mpi/fileIO.cpp.

30{
31 auto const communicator = getCommunicator(n_files);
32 MPI_Comm const comm = communicator.mpi_communicator;
33 MPI_Info const info = MPI_INFO_NULL;
34 hid_t const plist_id = H5Pcreate(H5P_FILE_ACCESS);
35
36 H5Pset_fapl_mpio(plist_id, comm, info);
37 H5Pset_coll_metadata_write(plist_id, true);
38
39 std::filesystem::path const partition_filename =
40 partitionFilename(filepath, communicator.color);
41 hid_t file = H5Fcreate(partition_filename.string().c_str(), H5F_ACC_TRUNC,
42 H5P_DEFAULT, plist_id);
43 H5Pclose(plist_id);
44
45 return file;
46}
std::filesystem::path partitionFilename(std::filesystem::path const &basic_filepath, int const file_group)
FileCommunicator getCommunicator(unsigned int const n_files)

References getCommunicator(), and partitionFilename().

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

◆ createHDF5TransferPolicy()

int64_t MeshLib::IO::createHDF5TransferPolicy ( )

Definition at line 60 of file mpi/fileIO.cpp.

61{
62 // property list for collective dataset write
63 hid_t io_transfer_property = H5Pcreate(H5P_DATASET_XFER);
64 H5Pset_dxpl_mpio(io_transfer_property, H5FD_MPIO_COLLECTIVE);
65 return io_transfer_property;
66}

Referenced by writeDataSet().

◆ elemOGSTypeToXDMFType()

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

Definition at line 36 of file transformData.cpp.

37{
39 elem_type{};
67 ParentDataType::WEDGE, 6}; // parallel triangle wedge
76 return elem_type;
77}

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 32 of file getCommunicator.cpp.

33{
34 int num_procs;
35 MPI_Comm_size(BaseLib::MPI::OGS_COMM_WORLD, &num_procs);
36 int rank_id;
37 MPI_Comm_rank(BaseLib::MPI::OGS_COMM_WORLD, &rank_id);
38 int const file_group_id = getGroupIndex(rank_id, num_procs, n_files);
39 MPI_Comm new_communicator;
40 MPI_Comm_split(BaseLib::MPI::OGS_COMM_WORLD, file_group_id, rank_id,
41 &new_communicator);
42 return FileCommunicator{std::move(new_communicator),
43 std::move(file_group_id), ""};
44}
MPI_Comm OGS_COMM_WORLD
Definition MPI.cpp:9
int getGroupIndex(int const input_index, int const input_size, int const new_group_size)

References getGroupIndex(), and BaseLib::MPI::OGS_COMM_WORLD.

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 18 of file getCommunicator.cpp.

20{
21 // A grouping algorithm that determines the number of groups and return the
22 // group idx of the specified input_index
23 assert(input_size >= new_group_size);
24 int const minimum_output_group_size =
25 std::lround(input_size / new_group_size);
26 int const maximum_output_group_size = (input_size % new_group_size)
27 ? minimum_output_group_size + 1
28 : minimum_output_group_size;
29 return std::lround(input_index / maximum_output_group_size);
30};

Referenced by getCommunicator().

◆ getLocalTopologyType()

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

Definition at line 321 of file transformData.cpp.

322{
323 auto const& elements = mesh.getElements();
324
325 if (elements.empty())
326 {
328 }
329 auto const ogs_cell_type = elements[0]->getCellType();
330
331 if (std::any_of(elements.begin(), elements.end(), [&](auto const& cell)
332 { return cell->getCellType() != ogs_cell_type; }))
333 {
335 }
336
337 return cellTypeOGS2XDMF(ogs_cell_type).id;
338}
constexpr auto cellTypeOGS2XDMF(MeshLib::CellType const &cell_type)

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

Referenced by getTopologyType().

◆ getPartitionInfo()

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

Definition at line 25 of file mpi/partition.cpp.

27{
29
30 std::vector<std::size_t> const partition_sizes =
31 BaseLib::MPI::allgather(size, mpi);
32
33 // the first partition's offset is zero, offsets for subsequent
34 // partitions are the accumulated sum of all preceding size.
35 std::vector<std::size_t> const partition_offsets =
36 BaseLib::sizesToOffsets(partition_sizes);
37
38 // chunked
39 std::size_t longest_partition =
40 *max_element(partition_sizes.begin(), partition_sizes.end());
41
42 // local_offset, local_length, longest_local_length, global_length
43 return {partition_offsets[mpi.rank], size, longest_partition,
44 partition_offsets.back()};
45}
static std::vector< T > allgather(T const &value, Mpi const &mpi)
Definition MPI.h:87
std::vector< ranges::range_value_t< R > > sizesToOffsets(R const &sizes)
Definition Algorithm.h:276

References BaseLib::MPI::allgather(), getCommunicator(), MeshLib::IO::FileCommunicator::mpi_communicator, BaseLib::MPI::Mpi::rank, and BaseLib::sizesToOffsets().

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

◆ getPropertyDataTypeSize()

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

Definition at line 93 of file writeXdmf.cpp.

95{
96 return fmt::format("{}", ogs_to_xdmf_type_fn[to_underlying(ogs_data_type)]);
97}
auto ogs_to_xdmf_type_fn
Definition writeXdmf.cpp:90

References ogs_to_xdmf_type_fn, and BaseLib::to_underlying().

Referenced by write_xdmf().

◆ getPropertyDataTypeString()

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

Definition at line 68 of file writeXdmf.cpp.

70{
71 return meshPropertyDatatypeString()[to_underlying(ogs_data_type)];
72}
static auto meshPropertyDatatypeString()
Definition writeXdmf.cpp:50

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

Referenced by write_xdmf().

◆ getTopologyType()

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

Definition at line 346 of file transformData.cpp.

347{
348 auto const local_topology_type = getLocalTopologyType(mesh);
349 // get the topology_type from other partitions
350 BaseLib::MPI::Mpi const mpi;
351
352 std::vector<int> const topology_types =
353 BaseLib::MPI::allgather(static_cast<int>(local_topology_type), mpi);
354
355 auto const common_topology_type =
356 std::all_of(topology_types.begin(), topology_types.end(),
357 [&local_topology_type](int other)
358 { return other == static_cast<int>(local_topology_type); })
359 ? local_topology_type
361 return common_topology_type;
362}
ParentDataType getLocalTopologyType(MeshLib::Mesh const &mesh)

References BaseLib::MPI::allgather(), getLocalTopologyType(), and MIXED.

Referenced by transformToXDMFTopology().

◆ getVtuFileNameForPetscOutputWithoutExtension()

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

Definition at line 129 of file VtuInterface.cpp.

131{
132 auto const file_name_extension = BaseLib::getFileExtension(file_name);
133 if (file_name_extension != ".vtu")
134 {
135 OGS_FATAL("Expected a .vtu file for petsc output.");
136 }
137
138 auto const file_name_base = boost::erase_last_copy(file_name, ".vtu");
139 auto basename = BaseLib::extractBaseName(file_name_base);
140
141 // Replace dots to underscores since the pvtu writing function drops all
142 // characters starting from a dot.
143 std::replace(basename.begin(), basename.end(), '.', '_');
144
145 // Restore the dirname if any.
146 auto const dirname = BaseLib::extractPath(file_name_base);
147 return BaseLib::joinPaths(dirname, basename);
148}
#define OGS_FATAL(...)
Definition Error.h:19
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 18 of file mpi/partition.cpp.

19{
20 int mpi_rank;
21 MPI_Comm_rank(BaseLib::MPI::OGS_COMM_WORLD, &mpi_rank);
22 return mpi_rank == 0;
23}

References BaseLib::MPI::OGS_COMM_WORLD.

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 & output_variable_names)

Definition at line 47 of file XdmfHdfWriter.cpp.

49{
50 if (output_variable_names.empty())
51 {
52 return [](Data const& data) -> bool
53 { return !ranges::contains(constant_output_names, data.name); };
54 }
55 return [&output_variable_names](Data const& data) -> bool
56 {
57 if (ranges::contains(constant_output_names, data.name))
58 {
59 return false;
60 }
61 return output_variable_names.contains(data.name);
62 };
63}
constexpr std::array constant_output_names

References constant_output_names.

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

◆ meshItemTypeString()

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

Definition at line 38 of file writeXdmf.cpp.

40{
41 if (item_type)
42 {
43 return mesh_item_type_strings[static_cast<int>(item_type.value())];
44 }
45 OGS_FATAL("Cannot convert an empty optional mesh item type.");
46}
constexpr char const * mesh_item_type_strings[]
Definition writeXdmf.cpp:34

References mesh_item_type_strings, and OGS_FATAL.

Referenced by write_xdmf().

◆ meshPropertyDatatypeSize()

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

◆ meshPropertyDatatypeString()

auto MeshLib::IO::meshPropertyDatatypeString ( )
static

Definition at line 50 of file writeXdmf.cpp.

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

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

Referenced by getPropertyDataTypeString().

◆ meshPropertyType2HdfType()

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

Definition at line 16 of file HdfData.cpp.

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

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 15 of file posix/fileIO.cpp.

16{
17 return H5Fopen(filepath.string().c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
18}

◆ openHDF5File() [2/2]

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

Definition at line 48 of file mpi/fileIO.cpp.

50{
51 MPI_Comm const comm = getCommunicator(n_files).mpi_communicator;
52 MPI_Info info = MPI_INFO_NULL;
53 hid_t const plist_id = H5Pcreate(H5P_FILE_ACCESS);
54 H5Pset_fapl_mpio(plist_id, comm, info);
55 hid_t file = H5Fopen(filepath.string().c_str(), H5F_ACC_RDWR, plist_id);
56 H5Pclose(plist_id);
57 return file;
58}

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 14 of file mpi/fileIO.cpp.

16{
17 std::string const filename = (file_group > 0)
18 ? basic_filepath.stem().string() + '_' +
19 std::to_string(file_group) +
20 basic_filepath.extension().string()
21 : basic_filepath.filename().string();
22 std::filesystem::path const filepathwithextension =
23 basic_filepath.parent_path() / filename;
24 DBUG("HDF Filepath: {:s}.", filepathwithextension.string());
25 return filepathwithextension;
26};
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22

References DBUG().

Referenced by createFile().

◆ readMeshFromFile()

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

Definition at line 58 of file readMeshFromFile.cpp.

60{
61#ifdef USE_PETSC
63 if (mpi.size > 1)
64 {
66 const std::string file_name_base =
68 return read_pmesh.read(file_name_base);
69 }
70 if (mpi.size == 1)
71 {
72 std::unique_ptr<Mesh> mesh{
73 readMeshFromFileSerial(file_name, compute_element_neighbors)};
74
75 if (!mesh)
76 {
77 return nullptr;
78 }
79
80 return new MeshLib::NodePartitionedMesh(*mesh);
81 }
82 return nullptr;
83#endif
84 return readMeshFromFileSerial(file_name, compute_element_neighbors);
85}
std::string dropFileExtension(std::string const &filename)
MeshLib::Mesh * readMeshFromFileSerial(const std::string &file_name, bool const compute_element_neighbors)
MPI_Comm communicator
Definition MPI.h:47

References BaseLib::MPI::Mpi::communicator, BaseLib::dropFileExtension(), MeshLib::IO::NodePartitionedMeshReader::read(), and BaseLib::MPI::Mpi::size.

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 78 of file PropertyVectorMetaData.h.

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

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 144 of file PropertyVectorMetaData.h.

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

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 86 of file transformData.cpp.

89{
90 // 3 data that will be captured and written by lambda f below
92 std::size_t num_of_tuples = 0;
93 void const* data_ptr = 0;
94
95 // lambda f : Collects properties from the PropertyVectorBase. It captures
96 // (and overwrites) data that can only be collected via the typed property.
97 // It has boolean return type to allow kind of pipe using || operator.
98 auto f = [&data_type, &num_of_tuples, &data_ptr,
99 &property_pair](auto basic_type) -> bool
100 {
101 auto const property_base = property_pair.second;
102 auto const typed_property =
103 dynamic_cast<PropertyVector<decltype(basic_type)> const*>(
104 property_base);
105 if (typed_property == nullptr)
106 {
107 return false;
108 }
109 // overwrite captured data
110 num_of_tuples = typed_property->getNumberOfTuples();
111 data_ptr = typed_property->data();
112
113 if constexpr (std::is_same_v<double, decltype(basic_type)>)
114 {
115 // The standard 64-bit IEEE 754 floating-point type
116 // (double-precision) has a 53 bit fractional part (52 bits written,
117 // one implied)
118 static_assert((std::numeric_limits<double>::digits == 53),
119 "Double has 52 bits fractional part");
121 }
122 else if constexpr (std::is_same_v<float, decltype(basic_type)>)
123 {
124 // The standard 32-bit IEEE 754 floating-point type
125 // (single-precision) has a 24 bit fractional part (23 bits written,
126 // one implied)
127 static_assert((std::numeric_limits<float>::digits == 24),
128 "Float has 23 bits fractional part");
130 }
131 else if constexpr (std::is_same_v<int32_t, decltype(basic_type)>)
132 {
133 data_type = MeshPropertyDataType::int32;
134 }
135 else if constexpr (std::is_same_v<uint32_t, decltype(basic_type)>)
136 {
138 }
139 else if constexpr (std::is_same_v<int64_t, decltype(basic_type)>)
140 {
141 data_type = MeshPropertyDataType::int64;
142 }
143 else if constexpr (std::is_same_v<uint64_t, decltype(basic_type)>)
144 {
146 }
147 else if constexpr (std::is_same_v<int8_t, decltype(basic_type)>)
148 {
149 data_type = MeshPropertyDataType::int8;
150 }
151 else if constexpr (std::is_same_v<uint8_t, decltype(basic_type)>)
152 {
153 data_type = MeshPropertyDataType::uint8;
154 }
155 else if constexpr (std::is_same_v<char, decltype(basic_type)>)
156 {
158 }
159 else if constexpr (std::is_same_v<unsigned char, decltype(basic_type)>)
160 {
161 static_assert((std::numeric_limits<unsigned char>::digits == 8),
162 "Unsigned char has 8 bits");
163 data_type = MeshPropertyDataType::uchar;
164 }
165 else if constexpr (std::is_same_v<unsigned long, decltype(basic_type)>)
166 {
167 if (sizeof(unsigned long) == 8 &&
168 std::numeric_limits<unsigned long>::digits == 64)
169 {
171 }
172 else if (sizeof(unsigned long) == 4 &&
173 std::numeric_limits<unsigned long>::digits == 32)
174 {
176 }
177 else
178 {
179 return false;
180 }
181 }
182 else if constexpr (std::is_same_v<std::size_t, decltype(basic_type)>)
183 {
184 if (sizeof(std::size_t) == 8 &&
185 std::numeric_limits<std::size_t>::digits == 64)
186 {
188 }
189 else if (sizeof(std::size_t) == 4 &&
190 std::numeric_limits<std::size_t>::digits == 32)
191 {
193 }
194 else
195 {
196 return false;
197 }
198 }
199 else
200 {
201 return false;
202 }
203 return true;
204 };
205
206 f(double{}) || f(float{}) || f(int{}) || f(long{}) || f(unsigned{}) ||
207 f(long{}) || f(static_cast<unsigned long>(0)) || f(std::size_t{}) ||
208 f(char{}) || f(static_cast<unsigned char>(0));
209
210 if (data_type == MeshPropertyDataType::unknown)
211 {
212 return std::nullopt;
213 }
214
215 auto const& property_base = property_pair.second;
216 auto const& global_components =
217 property_base->getNumberOfGlobalComponents();
218 // TODO (tm) property_pair vector::getNumberOfGlobalComponents should return
219 // unsigned value. Then explicit cast from signed to unsigned int and
220 // assert can be removed here. Implicit cast to long long is fine and
221 // can be kept
222 assert(global_components >= 0);
223 auto const ui_global_components =
224 static_cast<unsigned int>(global_components);
225
226 MeshLib::MeshItemType const mesh_item_type =
227 property_base->getMeshItemType();
228
229 std::string const& name = property_base->getPropertyName();
230
231 HdfData hdf = {data_ptr, num_of_tuples, ui_global_components, name,
232 data_type, n_files, chunk_size_bytes};
233
234 XdmfData xdmf{num_of_tuples, ui_global_components, data_type,
235 name, mesh_item_type, n_files,
236 std::nullopt};
237
238 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
239}
MeshPropertyDataType
constexpr std::size_t getNumberOfTuples() const

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

Referenced by transformAttributes().

◆ transformAttributes()

std::vector< XdmfHdfData > MeshLib::IO::transformAttributes ( MeshLib::Mesh const & mesh,
std::set< std::string > const & output_variable_names,
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
output_variable_namesnames of all variables (attributes) that change over time
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 241 of file transformData.cpp.

246{
247 MeshLib::Properties const& properties = mesh.getProperties();
248
249 // \TODO (tm) use c++20 ranges
250 // a = p | filter (first!=OGS_VERSION) | filter null_opt | transformAttr |
251 std::vector<XdmfHdfData> attributes;
252 for (auto const& [name, property_base] : properties)
253 {
255 {
256 continue;
257 }
258
259 if (!output_variable_names.contains(name))
260 {
261 continue;
262 }
263
264 if (auto const attribute = transformAttribute(
265
266 std::pair(std::string(name), property_base), n_files,
267 chunk_size_bytes))
268
269 {
270 attributes.push_back(attribute.value());
271 }
272 else
273 {
274 WARN("Could not create attribute meta of {:s}.", name);
275 }
276 }
277 return attributes;
278}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
const std::string OGS_VERSION
Definition GitInfo.cpp:11
std::optional< XdmfHdfData > transformAttribute(std::pair< std::string, PropertyVectorBase * > const &property_pair, unsigned int const n_files, unsigned int const chunk_size_bytes)

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 296 of file transformData.cpp.

299{
300 std::string const name = "geometry";
301 std::vector<MeshLib::Node*> const& nodes = mesh.getNodes();
302
303 int const point_size = 3;
304 auto const& partition_dim = nodes.size();
305
306 HdfData const hdf = {data_ptr,
307 partition_dim,
308 point_size,
309 name,
311 n_files,
312 chunk_size_bytes};
313 XdmfData const xdmf = {
314 partition_dim, point_size, MeshPropertyDataType::float64,
315 name, std::nullopt, n_files,
316 std::nullopt};
317
318 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
319}

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

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

◆ transformTopology()

XdmfHdfData MeshLib::IO::transformTopology ( std::vector< std::size_t > 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 ParentDataType
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 409 of file transformData.cpp.

413{
414 std::string const name = "topology";
415 auto const tuple_size = ParentDataType2String(parent_data_type).second;
416 HdfData const hdf = {values.data(),
417 values.size() / tuple_size,
418 tuple_size,
419 name,
421 n_files,
422 chunk_size_bytes};
423 XdmfData const xdmf{values.size() / tuple_size,
424 tuple_size,
426 name,
427 std::nullopt,
428 n_files,
429 parent_data_type};
430
431 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
432}
std::pair< std::string, std::size_t > ParentDataType2String(ParentDataType p)

References ParentDataType2String(), and uint64.

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 280 of file transformData.cpp.

281{
282 std::vector<MeshLib::Node*> const& nodes = mesh.getNodes();
283
284 int const point_size = 3;
285 std::vector<double> values;
286 values.reserve(nodes.size() * point_size);
287 for (auto const& n : nodes)
288 {
289 const double* x = n->data();
290 values.insert(values.cend(), x, x + point_size);
291 }
292
293 return values;
294}

References MeshLib::Mesh::getNodes().

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

◆ transformToXDMFTopology()

std::pair< std::vector< std::size_t >, 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 365 of file transformData.cpp.

367{
368 std::vector<MeshLib::Element*> const& elements = mesh.getElements();
369 std::vector<std::size_t> values;
370
371 auto const push_cellnode_ids_to_vector =
372 [&values, &offset](auto const& cell)
373 {
374 values |= ranges::actions::push_back(
375 cell->nodes() | MeshLib::views::ids |
376 ranges::views::transform([&offset](auto const node_id)
377 { return node_id + offset; }));
378 };
379
380 auto const topology_type = getTopologyType(mesh);
381 if (topology_type == ParentDataType::MIXED)
382 {
383 values.reserve(elements.size() * 2); // each cell has at least two
384 // numbers
385 for (auto const& cell : elements)
386 {
387 auto const ogs_cell_type = cell->getCellType();
388 auto const xdmf_cell_id = cellTypeOGS2XDMF(ogs_cell_type).id;
389 values.push_back(to_underlying(xdmf_cell_id));
390 if (ogs_cell_type == MeshLib::CellType::LINE2)
391 {
392 values.push_back(2);
393 }
394 push_cellnode_ids_to_vector(cell);
395 }
396 }
397 else
398 {
399 values.reserve(elements.size() * elements[0]->getNumberOfNodes());
400 for (auto const& cell : elements)
401 {
402 push_cellnode_ids_to_vector(cell);
403 }
404 }
405
406 return {values, topology_type};
407}
ParentDataType getTopologyType(MeshLib::Mesh const &mesh)
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:218

References cellTypeOGS2XDMF(), MeshLib::Mesh::getElements(), getTopologyType(), MeshLib::views::ids, MeshLib::LINE2, MIXED, 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 101 of file writeXdmf.cpp.

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

References MeshLib::IO::XdmfData::attribute_center, EDGE_3, getPropertyDataTypeSize(), getPropertyDataTypeString(), 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, MeshLib::IO::XdmfData::size_partitioned_dim, 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 > output_variable_names,
bool const use_compression,
int const data_mode )
nodiscard

Definition at line 18 of file writeMeshToFile.cpp.

24{
25 if (file_path.extension().string() == ".msh")
26 {
28 meshIO.setMesh(&mesh);
30 return 0;
31 }
32 if (file_path.extension().string() == ".vtu")
33 {
34 if (output_variable_names.empty())
35 {
36 for (auto const& name :
38 {
39 output_variable_names.insert(name);
40 }
41 }
42 MeshLib::IO::VtuInterface writer(&mesh, output_variable_names,
43 data_mode, use_compression);
44 auto const result = writer.writeToFile(file_path);
45 if (!result)
46 {
47 ERR("writeMeshToFile(): Could not write mesh to '{:s}'.",
48 file_path.string());
49 return -1;
50 }
51 return 0;
52 }
53 if (file_path.extension().string() == ".xdmf")
54 {
55 std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes;
56 const std::reference_wrapper<const MeshLib::Mesh> mr = mesh;
57 meshes.push_back(mr);
58 MeshLib::IO::XdmfHdfWriter(std::move(meshes), file_path, 0, 0.0,
59 output_variable_names, use_compression, 1,
60 1048576);
61 return 0;
62 }
63 ERR("writeMeshToFile(): Unknown file extension '{:s}'. Can not write file "
64 "'{:s}'.",
65 file_path.extension().string(), file_path.string());
66 return -1;
67}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:20
Interface for handling mesh files from OGS-5 and below. (*.msh files)
Definition MeshIO.h:26
void setMesh(const MeshLib::Mesh *mesh)
Set mesh for writing.
Definition MeshIO.cpp:427
Properties & getProperties()
Definition Mesh.h:127
std::vector< std::string > getPropertyVectorNames() const
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:34

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

Referenced by SaveMeshDialog::accept(), convert(), anonymous_namespace{generateStructuredMesh.cpp}::extract1DBoundaryMeshes(), anonymous_namespace{generateStructuredMesh.cpp}::extract2D3DBoundaryMeshes(), FileIO::Gocad::generateFaceSets(), identifyAndWriteBoundaryMeshes(), main(), main(), anonymous_namespace{postLIE.cpp}::postVTU(), FileIO::XmlPrjInterface::write(), and writeMeshOutput().

◆ writePropertyVectorMetaData() [1/2]

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

Definition at line 67 of file PropertyVectorMetaData.h.

68{
69 DBUG(
70 "name: '{:s}':\t is_int_data_type: {:d}, is_data_type_signed: "
71 "{:d}, data_type_size_in_bytes: {:d}, number of components / "
72 "tuples: {:d} / {:d}",
73 pvmd.property_name, pvmd.is_int_type, pvmd.is_data_type_signed,
74 pvmd.data_type_size_in_bytes, pvmd.number_of_components,
75 pvmd.number_of_tuples);
76}

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 40 of file PropertyVectorMetaData.h.

42{
43 std::string::size_type s(pvmd.property_name.length());
44 os.write(reinterpret_cast<char*>(&s), sizeof(std::string::size_type));
45
46 os.write(
47 const_cast<char*>(
48 const_cast<PropertyVectorMetaData&>(pvmd).property_name.data()),
49 s);
50 os.write(reinterpret_cast<char*>(
51 &const_cast<PropertyVectorMetaData&>(pvmd).is_int_type),
52 sizeof(bool));
53 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
54 pvmd).is_data_type_signed),
55 sizeof(bool));
56 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
57 pvmd).data_type_size_in_bytes),
58 sizeof(unsigned long));
59 os.write(reinterpret_cast<char*>(&const_cast<PropertyVectorMetaData&>(
60 pvmd).number_of_components),
61 sizeof(unsigned long));
62 os.write(reinterpret_cast<char*>(
63 &const_cast<PropertyVectorMetaData&>(pvmd).number_of_tuples),
64 sizeof(unsigned long));
65}

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 130 of file PropertyVectorMetaData.h.

132{
133 os.write(reinterpret_cast<char*>(
134 &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
135 .offset),
136 sizeof(unsigned long));
137 os.write(reinterpret_cast<char*>(
138 &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
139 .number_of_tuples),
140 sizeof(unsigned long));
141}

Referenced by ApplicationUtils::writeProperties().

Variable Documentation

◆ constant_output_names

std::array MeshLib::IO::constant_output_names
constexpr

◆ elem_type_ogs2xdmf

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

Definition at line 79 of file transformData.cpp.

Referenced by cellTypeOGS2XDMF().

◆ mesh_item_type_strings

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

Definition at line 34 of file writeXdmf.cpp.

34 {"Node", "Edge", "Face",
35 "Cell", "Other"};

Referenced by meshItemTypeString().

◆ ogs_to_xdmf_type_fn

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

Definition at line 90 of file writeXdmf.cpp.

Referenced by getPropertyDataTypeSize().