OGS
writeMeshToFile.cpp
Go to the documentation of this file.
1
10#include "writeMeshToFile.h"
11
12#include <vector>
13
14#include "BaseLib/FileTools.h"
15#include "BaseLib/Logging.h"
16#include "BaseLib/StringTools.h"
20#include "MeshLib/Mesh.h"
21
22namespace MeshLib::IO
23{
25 std::filesystem::path const& file_path,
26 [[maybe_unused]] std::set<std::string>
27 variable_output_names)
28{
29 if (file_path.extension().string() == ".msh")
30 {
32 meshIO.setMesh(&mesh);
34 return 0;
35 }
36 if (file_path.extension().string() == ".vtu")
37 {
38 MeshLib::IO::VtuInterface writer(&mesh);
39 auto const result = writer.writeToFile(file_path);
40 if (!result)
41 {
42 ERR("writeMeshToFile(): Could not write mesh to '{:s}'.",
43 file_path.string());
44 return -1;
45 }
46 return 0;
47 }
48 if (file_path.extension().string() == ".xdmf")
49 {
50 std::vector<std::reference_wrapper<const MeshLib::Mesh>> meshes;
51 const std::reference_wrapper<const MeshLib::Mesh> mr = mesh;
52 meshes.push_back(mr);
53 MeshLib::IO::XdmfHdfWriter(std::move(meshes), file_path, 0, 0.0,
54 variable_output_names, true, 1, 1048576);
55 return 0;
56 }
57 ERR("writeMeshToFile(): Unknown file extension '{:s}'. Can not write file "
58 "'{:s}'.",
59 file_path.extension().string(), file_path.string());
60 return 0;
61}
62} // namespace MeshLib::IO
Filename manipulation routines.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Definition of the MeshIO class.
Definition of the Mesh class.
Definition of string helper functions.
Implementation of the VtuInterface class.
XdmfWriter which create contiguous data for geometry and topology and writes this and all attributes ...
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:31
Interface for handling mesh files from OGS-5 and below. (*.msh files)
Definition MeshIO.h:37
void setMesh(const MeshLib::Mesh *mesh)
Set mesh for writing.
Definition MeshIO.cpp:439
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)