Revision 9a0807a016c56d4a8524cc7a4bef8f1f575319ff authored by Lars Bilke on 20 July 2021, 10:27:51 UTC, committed by Lars Bilke on 03 August 2021, 12:16:44 UTC
1 parent 21ce1e1
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"
#include "MeshLib/IO/XDMF/XdmfHdfWriter.h"
#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;
}
if (file_path.extension().string() == ".xdmf")
{
MeshLib::IO::XdmfHdfWriter(mesh, file_path, 0, 0.0,
variable_output_names, true);
return 0;
}
ERR("writeMeshToFile(): Unknown file extension '{:s}'. Can not write file "
"'{'s}'.",
file_path.extension().string(), file_path.string());
return 0;
}
} // namespace MeshLib::IO
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...