OGS
writeMeshToFile.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "writeMeshToFile.h"
5
6#include <vector>
7
8#include "BaseLib/FileTools.h"
9#include "BaseLib/Logging.h"
10#include "BaseLib/StringTools.h"
14#include "MeshLib/Mesh.h"
15
16namespace MeshLib::IO
17{
19 std::filesystem::path const& file_path,
20 [[maybe_unused]] std::set<std::string>
21 variable_output_names)
22{
23 if (file_path.extension().string() == ".msh")
24 {
26 meshIO.setMesh(&mesh);
28 return 0;
29 }
30 if (file_path.extension().string() == ".vtu")
31 {
32 MeshLib::IO::VtuInterface writer(&mesh);
33 auto const result = writer.writeToFile(file_path);
34 if (!result)
35 {
36 ERR("writeMeshToFile(): Could not write mesh to '{:s}'.",
37 file_path.string());
38 return -1;
39 }
40 return 0;
41 }
42 if (file_path.extension().string() == ".xdmf")
43 {
44 std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes;
45 const std::reference_wrapper<const MeshLib::Mesh> mr = mesh;
46 meshes.push_back(mr);
47 MeshLib::IO::XdmfHdfWriter(std::move(meshes), file_path, 0, 0.0,
48 variable_output_names, true, 1, 1048576);
49 return 0;
50 }
51 ERR("writeMeshToFile(): Unknown file extension '{:s}'. Can not write file "
52 "'{:s}'.",
53 file_path.extension().string(), file_path.string());
54 return 0;
55}
56} // namespace MeshLib::IO
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
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:34
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)