Revision 5f6623a9e0dfc5c7ed37718bb6e1c1f66e0f2e82 authored by Dmitri Naumov on 08 June 2021, 18:57:27 UTC, committed by Dmitri Naumov on 09 June 2021, 11:55:47 UTC
1 parent 19e3e0b
writeMeshToFile.cpp
/**
* \file
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#include "writeMeshToFile.h"
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/StringTools.h"
#include "MeshLib/IO/Legacy/MeshIO.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#ifdef OGS_USE_XDMF
#include "MeshLib/IO/XDMF/XdmfHdfWriter.h"
#endif
#include "MeshLib/Mesh.h"
namespace MeshLib::IO
{
int writeMeshToFile(const MeshLib::Mesh& mesh,
std::filesystem::path const& file_path,
[[maybe_unused]] std::set<std::string>
variable_output_names)
{
if (file_path.extension().string() == ".msh")
{
MeshLib::IO::Legacy::MeshIO meshIO;
meshIO.setMesh(&mesh);
BaseLib::IO::writeStringToFile(meshIO.writeToString(), file_path);
return 0;
}
if (file_path.extension().string() == ".vtu")
{
MeshLib::IO::VtuInterface writer(&mesh);
auto const result = writer.writeToFile(file_path);
if (!result)
{
ERR("writeMeshToFile(): Could not write mesh to '{:s}'.",
file_path.string());
return -1;
}
return 0;
}
#ifdef OGS_USE_XDMF
if (file_path.extension().string() == ".xdmf")
{
MeshLib::IO::XdmfHdfWriter(
mesh, file_path, 0, variable_output_names, true);
return 0;
}
#endif
ERR("writeMeshToFile(): Unknown mesh file format in file {:s}.",
file_path.string());
return -1;
}
} // namespace MeshLib::IO
Computing file changes ...