OGS
MeshLib::IO Namespace Reference

Namespaces

 Legacy
 

Classes

class  NodePartitionedMeshReader
 
struct  PropertyVectorMetaData
 
struct  PropertyVectorPartitionMetaData
 
class  PVDFile
 
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  HdfData
 
struct  MeshHdfData
 
class  HdfWriter
 
struct  FileCommunicator
 
struct  PartitionInfo
 
struct  XdmfTopology
 
struct  XdmfData
 
struct  XdmfHdfData
 
struct  TransformedMeshData
 
struct  XdmfHdfMesh
 
class  XdmfHdfWriter
 
class  XdmfWriter
 

Typedefs

using Hdf5DimType = unsigned long long
 
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)
 
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, [[maybe_unused]] std::set< std::string > variable_output_names)
 
int writeMeshToFile (MeshLib::Mesh const &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)
 
std::vector< XdmfHdfDatatransformAttributes (MeshLib::Mesh const &mesh, unsigned int n_files)
 Create meta data for attributes used for hdf5 and xdmf. More...
 
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. More...
 
XdmfHdfData transformGeometry (MeshLib::Mesh const &mesh, double const *data_ptr, unsigned int n_files)
 Create meta data for geometry used for hdf5 and xdmf. More...
 
std::vector< int > 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. More...
 
XdmfHdfData transformTopology (std::vector< int > const &values, unsigned int n_files)
 Create meta data for topology used for HDF5 and XDMF. More...
 
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. More...
 

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 = typedef unsigned long long

Definition at line 22 of file HdfData.h.

◆ HDFAttributes

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

Definition at line 25 of file HdfWriter.h.

◆ XdmfDimType

using MeshLib::IO::XdmfDimType = typedef 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 67 of file transformData.cpp.

68 {
69  return elem_type_ogs2xdmf[to_underlying(cell_type)];
70 }
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
Definition: cpp23.h:30
constexpr auto elem_type_ogs2xdmf

References elem_type_ogs2xdmf, and BaseLib::to_underlying().

Referenced by transformToXDMFTopology().

◆ createFile()

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

Definition at line 39 of file fileIO.cpp.

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

References getCommunicator(), and partitionFilename().

◆ createHDF5TransferPolicy()

int64_t MeshLib::IO::createHDF5TransferPolicy ( )

Definition at line 69 of file fileIO.cpp.

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

Referenced by writeDataSet().

◆ elemOGSTypeToXDMFType()

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

Definition at line 39 of file transformData.cpp.

40 {
41  std::array<XdmfTopology, to_underlying(MeshLib::CellType::enum_length)>
42  elem_type{};
43  elem_type[to_underlying(MeshLib::CellType::POINT1)] = {0x1, 1};
44  elem_type[to_underlying(MeshLib::CellType::LINE2)] = {0x2, 2};
45  elem_type[to_underlying(MeshLib::CellType::LINE3)] = {0x2, 3};
46  elem_type[to_underlying(MeshLib::CellType::TRI3)] = {0x4, 3};
47  elem_type[to_underlying(MeshLib::CellType::TRI6)] = {0x24, 6};
48  elem_type[to_underlying(MeshLib::CellType::QUAD4)] = {0x5, 4};
49  elem_type[to_underlying(MeshLib::CellType::QUAD8)] = {0x25, 8};
50  elem_type[to_underlying(MeshLib::CellType::QUAD9)] = {0x23, 9};
51  elem_type[to_underlying(MeshLib::CellType::TET4)] = {0x6, 4};
52  elem_type[to_underlying(MeshLib::CellType::TET10)] = {0x26, 10};
53  elem_type[to_underlying(MeshLib::CellType::HEX8)] = {0x9, 8};
54  elem_type[to_underlying(MeshLib::CellType::HEX20)] = {0x30, 20};
55  elem_type[to_underlying(MeshLib::CellType::HEX27)] = {0x32, 27};
57  0x8, 6}; // parallel triangle wedge
58  elem_type[to_underlying(MeshLib::CellType::PRISM15)] = {0x28, 15};
59  elem_type[to_underlying(MeshLib::CellType::PRISM18)] = {0x29, 18};
60  elem_type[to_underlying(MeshLib::CellType::PYRAMID5)] = {0x7, 5};
61  elem_type[to_underlying(MeshLib::CellType::PYRAMID13)] = {0x27, 13};
62  return elem_type;
63 }

References MeshLib::enum_length, MeshLib::HEX20, MeshLib::HEX27, MeshLib::HEX8, MeshLib::LINE2, MeshLib::LINE3, MeshLib::POINT1, MeshLib::PRISM15, MeshLib::PRISM18, MeshLib::PRISM6, MeshLib::PYRAMID13, MeshLib::PYRAMID5, MeshLib::QUAD4, MeshLib::QUAD8, MeshLib::QUAD9, MeshLib::TET10, MeshLib::TET4, BaseLib::to_underlying(), MeshLib::TRI3, and MeshLib::TRI6.

◆ getCommunicator()

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

Definition at line 43 of file getCommunicator.cpp.

44 {
45  int num_procs;
46  MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
47  int rank_id;
48  MPI_Comm_rank(MPI_COMM_WORLD, &rank_id);
49  int const file_group_id = getGroupIndex(rank_id, num_procs, n_files);
50  MPI_Comm new_communicator;
51  MPI_Comm_split(MPI_COMM_WORLD, file_group_id, rank_id, &new_communicator);
52  return FileCommunicator{std::move(new_communicator),
53  std::move(file_group_id), ""};
54 }
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 29 of file getCommunicator.cpp.

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

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 100 of file writeXdmf.cpp.

102 {
103  return fmt::format("{}", ogs_to_xdmf_type_fn[to_underlying(ogs_data_type)]);
104 }
std::string format(const char *format_str,...)
Definition: StringTools.cpp:85
auto ogs_to_xdmf_type_fn
Definition: writeXdmf.cpp:97

References BaseLib::format(), 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 75 of file writeXdmf.cpp.

77 {
78  return meshPropertyDatatypeString()[to_underlying(ogs_data_type)];
79 }
static auto meshPropertyDatatypeString()
Definition: writeXdmf.cpp:59

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

Referenced by write_xdmf().

◆ getVtuFileNameForPetscOutputWithoutExtension()

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

Definition at line 116 of file VtuInterface.cpp.

118 {
119  auto const file_name_extension = BaseLib::getFileExtension(file_name);
120  if (file_name_extension != ".vtu")
121  {
122  OGS_FATAL("Expected a .vtu file for petsc output.");
123  }
124 
125  auto const file_name_base = boost::erase_last_copy(file_name, ".vtu");
126  auto basename = BaseLib::extractBaseName(file_name_base);
127 
128  // Replace dots to underscores since the pvtu writing function drops all
129  // characters starting from a dot.
130  std::replace(basename.begin(), basename.end(), '.', '_');
131 
132  // Restore the dirname if any.
133  auto const dirname = BaseLib::extractPath(file_name_base);
134  return BaseLib::joinPaths(dirname, basename);
135 }
#define OGS_FATAL(...)
Definition: Error.h:26
std::string getFileExtension(const std::string &path)
Definition: FileTools.cpp:186
std::string extractPath(std::string const &pathname)
Definition: FileTools.cpp:207
std::string joinPaths(std::string const &pathA, std::string const &pathB)
Definition: FileTools.cpp:212
std::string extractBaseName(std::string const &pathname)
Definition: FileTools.cpp:175

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().

◆ meshItemTypeString()

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

Definition at line 47 of file writeXdmf.cpp.

49 {
50  if (item_type)
51  {
52  return mesh_item_type_strings[static_cast<int>(item_type.value())];
53  }
54  OGS_FATAL("Cannot convert an empty optional mesh item type.");
55 }
constexpr char const * mesh_item_type_strings[]
Definition: writeXdmf.cpp:43

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 59 of file writeXdmf.cpp.

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

References enum_length, float32, float64, int32, int64, int8, BaseLib::to_underlying(), 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  try
34  {
35  return ogs_to_hdf_type.at(ogs_data_type);
36  }
37  catch (std::exception const& e)
38  {
39  OGS_FATAL("No known HDF5 type for OGS type. {:s}", e.what());
40  }
41 }

References float32, float64, int32, int64, int8, OGS_FATAL, 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 57 of file fileIO.cpp.

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

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 25 of file fileIO.cpp.

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

References DBUG(), and MathLib::s.

Referenced by createFile().

◆ readMeshFromFile()

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

Definition at line 68 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 =
81  BaseLib::dropFileExtension(file_name);
82  return read_pmesh.read(file_name_base);
83  }
84  if (world_size == 1)
85  {
86  std::unique_ptr<Mesh> mesh{readMeshFromFileSerial(file_name)};
87  return new MeshLib::NodePartitionedMesh(*mesh);
88  }
89  return nullptr;
90  }
91 #endif
92  return readMeshFromFileSerial(file_name);
93 }
std::string dropFileExtension(std::string const &filename)
Definition: FileTools.cpp:169
MeshLib::Mesh * readMeshFromFileSerial(const std::string &file_name)

References BaseLib::dropFileExtension(), MeshLib::IO::NodePartitionedMeshReader::read(), and anonymous_namespace{readMeshFromFile.cpp}::readMeshFromFileSerial().

Referenced by createGeometries(), FileIO::createSurface(), MainWindow::loadFile(), 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 81 of file PropertyVectorMetaData.h.

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

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, MeshLib::IO::PropertyVectorMetaData::property_name, and MathLib::s.

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

◆ readPropertyVectorPartitionMetaData()

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

Definition at line 136 of file PropertyVectorMetaData.h.

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

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 
)

Definition at line 72 of file transformData.cpp.

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

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

Referenced by transformAttributes().

◆ transformAttributes()

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

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
Returns
vector of meta data

Definition at line 204 of file transformData.cpp.

206 {
207  MeshLib::Properties const& properties = mesh.getProperties();
208 
209  // \TODO (tm) use c++20 ranges
210  // a = p | filter (first!=OGS_VERSION) | filter null_opt | transformAttr |
211  std::vector<XdmfHdfData> attributes;
212  for (auto const& [name, property_base] : properties)
213  {
215  {
216  continue;
217  }
218 
219  if (auto const attribute =
220  transformAttribute(std::pair(name, property_base), n_files))
221  {
222  attributes.push_back(attribute.value());
223  }
224  else
225  {
226  WARN("Could not create attribute meta of {:s}.", name);
227  }
228  }
229  return attributes;
230 }
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
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
std::optional< XdmfHdfData > transformAttribute(std::pair< std::string, PropertyVectorBase * > const &property_pair, unsigned int const n_files)

References MeshLib::Mesh::getProperties(), MaterialPropertyLib::name, 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 
)

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
Returns
Geometry meta data

Definition at line 248 of file transformData.cpp.

251 {
252  std::string const name = "geometry";
253  std::vector<MeshLib::Node*> const& nodes = mesh.getNodes();
254 
255  int const point_size = 3;
256  auto const& partition_dim = nodes.size();
257 
258  HdfData const hdf = {data_ptr,
259  partition_dim,
260  point_size,
261  name,
263  n_files};
264  XdmfData const xdmf = {
265  partition_dim, point_size, MeshPropertyDataType::float64,
266  name, std::nullopt, 2,
267  n_files};
268 
269  return XdmfHdfData{std::move(hdf), std::move(xdmf)};
270 }

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

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

◆ transformTopology()

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

Create meta data for topology used for HDF5 and XDMF.

Parameters
valuesactual topology values to get size and memory location
n_filesspecifies the number of files. If greater than 1 it groups the data of each process to n_files
Returns
Topology meta data

Definition at line 299 of file transformData.cpp.

301 {
302  std::string const name = "topology";
303  HdfData const hdf = {
304  values.data(), values.size(), 1, name, MeshPropertyDataType::int32,
305  n_files};
306  XdmfData const xdmf = {
307  values.size(), 1, MeshPropertyDataType::int32, name, std::nullopt, 3,
308  n_files};
309 
310  return XdmfHdfData{std::move(hdf), std::move(xdmf)};
311 }

References int32, and MaterialPropertyLib::name.

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

233 {
234  std::vector<MeshLib::Node*> const& nodes = mesh.getNodes();
235 
236  int const point_size = 3;
237  std::vector<double> values;
238  values.reserve(nodes.size() * point_size);
239  for (auto const& n : nodes)
240  {
241  const double* x = n->getCoords();
242  values.insert(values.cend(), x, x + point_size);
243  }
244 
245  return values;
246 }

References MeshLib::Mesh::getNodes().

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

◆ transformToXDMFTopology()

std::vector< int > 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

Definition at line 272 of file transformData.cpp.

274 {
275  std::vector<MeshLib::Element*> const& elements = mesh.getElements();
276  std::vector<int> values;
277  values.reserve(elements.size());
278 
279  for (auto const& cell : elements)
280  {
281  auto const ogs_cell_type = cell->getCellType();
282  auto const xdmf_cell_id = cellTypeOGS2XDMF(ogs_cell_type).id;
283  values.push_back(xdmf_cell_id);
284  if (ogs_cell_type == MeshLib::CellType::LINE2 ||
285  ogs_cell_type == MeshLib::CellType::LINE3)
286  {
287  values.push_back(cellTypeOGS2XDMF(ogs_cell_type).number_of_nodes);
288  }
289 
290  for (std::size_t i = 0; i < cell->getNumberOfNodes(); ++i)
291  {
292  MeshLib::Node const* node = cell->getNode(i);
293  values.push_back(node->getID() + offset);
294  }
295  }
296  return values;
297 }
std::size_t getID() const
Definition: Point3dWithID.h:62
constexpr auto cellTypeOGS2XDMF(MeshLib::CellType const &cell_type)

References cellTypeOGS2XDMF(), MeshLib::Mesh::getElements(), MathLib::Point3dWithID::getID(), MeshLib::LINE2, and MeshLib::LINE3.

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 108 of file writeXdmf.cpp.

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

References MeshLib::IO::XdmfData::attribute_center, BaseLib::format(), getPropertyDataTypeSize(), getPropertyDataTypeString(), MeshLib::IO::XdmfData::global_block_dims, meshItemTypeString(), MeshLib::IO::XdmfData::name, and GitInfoLib::GitInfo::ogs_version.

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

◆ writeMeshToFile() [1/2]

int MeshLib::IO::writeMeshToFile ( const MeshLib::Mesh mesh,
std::filesystem::path const &  file_path,
[[maybe_unused] ] 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);
33  BaseLib::IO::writeStringToFile(meshIO.writeToString(), file_path);
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);
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(char const *fmt, Args const &... args)
Definition: Logging.h:42
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:364
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
Definition: VtuInterface.h:38
int writeStringToFile(std::string 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(), anonymous_namespace{postLIE.cpp}::postVTU(), and FileIO::XmlPrjInterface::write().

◆ writeMeshToFile() [2/2]

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

◆ writePropertyVectorMetaData() [1/2]

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

Definition at line 70 of file PropertyVectorMetaData.h.

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

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

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

References MeshLib::IO::PropertyVectorMetaData::property_name, and MathLib::s.

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

◆ writePropertyVectorPartitionMetaData()

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

Definition at line 122 of file PropertyVectorMetaData.h.

124 {
125  os.write(reinterpret_cast<char*>(
126  &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
127  .offset),
128  sizeof(unsigned long));
129  os.write(reinterpret_cast<char*>(
130  &const_cast<PropertyVectorPartitionMetaData&>(pvpmd)
131  .number_of_tuples),
132  sizeof(unsigned long));
133 }

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 158 of file VtuInterface.cpp.

160 {
161  MeshLib::IO::VtuInterface writer(&mesh, data_mode);
162  auto const result = writer.writeToFile(file_name);
163  if (!result)
164  {
165  ERR("writeMeshToFile(): Could not write mesh to '{:s}'.", file_name);
166  return -1;
167  }
168  return 0;
169 }

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 65 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 43 of file writeXdmf.cpp.

Referenced by meshItemTypeString().

◆ ogs_to_xdmf_type_fn

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

Definition at line 97 of file writeXdmf.cpp.

Referenced by getPropertyDataTypeSize().