Skip to content
Snippets Groups Projects
Commit daf219ef authored by Tobias Meisel's avatar Tobias Meisel
Browse files

[MeL] Write MeshToFile is now able to write xdmf

parent 71b03b6f
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* \file * \file
* \author Tobias Meisel * \author Tobias Meisel
* \date 2020-10-06 * \date 2020-10-06
* \brief Implementation of WriteXdmf function. * \brief Implementation of WriteXdmf3 function.
* *
* \copyright * \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org) * Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "writeXdmf.h" #include "writeXdmf.h"
#include <vtkNew.h> #include <vtkNew.h>
#include <vtkPXdmf3Writer.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>
#include <vtkXdmf3Writer.h> #include <vtkXdmf3Writer.h>
...@@ -23,34 +24,36 @@ namespace MeshLib ...@@ -23,34 +24,36 @@ namespace MeshLib
{ {
namespace IO namespace IO
{ {
bool writeXdmf3(const MeshLib::Mesh& mesh, std::string const &file_name) bool writeXdmf3(const MeshLib::Mesh& mesh, std::string const& file_name)
{ {
#ifdef USE_PETSC #ifdef USE_PETSC
int rank; int rank;
MPI_Comm_rank(PETSC_COMM_WORLD, &rank); MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
int mpi_size; int mpi_size;
MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size); MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size);
vtkSmartPointer<vtkPXdmf3Writer> writer = vtkSmartPointer<vtkPXdmf3Writer>::New(); // open file handle vtkSmartPointer<vtkPXdmf3Writer> writer =
vtkSmartPointer<vtkPXdmf3Writer>::New(); // open file handle
#else #else
vtkSmartPointer<vtkXdmf3Writer> writer = vtkSmartPointer<vtkXdmf3Writer>::New(); // open file handle vtkSmartPointer<vtkXdmf3Writer> writer =
#endif vtkSmartPointer<vtkXdmf3Writer>::New(); // open file handle
#endif
writer->SetFileName(file_name.c_str()); writer->SetFileName(file_name.c_str());
vtkNew<MeshLib::VtkMappedMeshSource> vtkSource; vtkNew<MeshLib::VtkMappedMeshSource> vtkSource;
vtkSource->SetMesh(&mesh); vtkSource->SetMesh(&mesh);
vtkSource->Update(); vtkSource->Update();
writer->SetInputData(vtkSource->GetOutput()); writer->SetInputData(vtkSource->GetOutput());
#ifdef USE_PETSC #ifdef USE_PETSC
writer->SetGhostLevel(1); writer->SetGhostLevel(1);
writer->SetNumberOfPieces(num_partitions); writer->SetNumberOfPieces(num_partitions);
writer->SetStartPiece(rank); writer->SetStartPiece(rank);
writer->SetEndPiece(rank); writer->SetEndPiece(rank);
#endif #endif
writer->Write(); writer->Write();
// close file handle // close file handle
return 0; return 0;
} }
} //end namespace IO } // end namespace IO
} //end namespace MeshLib } // end namespace MeshLib
\ No newline at end of file \ No newline at end of file
...@@ -15,20 +15,18 @@ ...@@ -15,20 +15,18 @@
#pragma once #pragma once
#include <string> #include <string>
#include "MeshLib/Mesh.h"
namespace MeshLib {
namespace MeshLib
{
class Mesh;
namespace IO namespace IO
{ {
/// Writes mesh to XDMF file. /// Writes mesh to XDMF file.
/// \return True on success, false on error /// \return True on success, false on error
bool writeXdmf3(const MeshLib::Mesh& mesh, std::string const &file_name);
/// \param mesh Mesh holds all data to be written. /// \param mesh Mesh holds all data to be written.
/// \param file_name File name. /// \param file_name File name.
/// \return True on success, false on error bool writeXdmf3(MeshLib::Mesh const& mesh, std::string const& file_name);
} // end namespace IO } // end namespace IO
} // end namespace MeshLib } // end namespace MeshLib
\ No newline at end of file \ No newline at end of file
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
#include "writeMeshToFile.h" #include "writeMeshToFile.h"
#include "BaseLib/Logging.h" #include "BaseLib/Logging.h"
#include "BaseLib/FileTools.h" #include "BaseLib/FileTools.h"
#include "BaseLib/StringTools.h" #include "BaseLib/StringTools.h"
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
#include "MeshLib/IO/Legacy/MeshIO.h" #include "MeshLib/IO/Legacy/MeshIO.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/XDMF/writeXdmf.h"
namespace MeshLib namespace MeshLib
{ {
...@@ -44,9 +44,19 @@ int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name) ...@@ -44,9 +44,19 @@ int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name)
} }
return 0; return 0;
} }
if (BaseLib::hasFileExtension(".xdmf", file_name))
{
if (auto const result = writeXdmf3(mesh, file_name); !result)
{
ERR("writeMeshToFile(): Could not write mesh to '{:s}'.",
file_name);
return -1;
}
return 0;
}
ERR("writeMeshToFile(): Unknown mesh file format in file {:s}.", file_name); ERR("writeMeshToFile(): Unknown mesh file format in file {:s}.", file_name);
return -1; return -1;
} }
} // end namespace IO } // end namespace IO
......
...@@ -18,4 +18,4 @@ namespace IO ...@@ -18,4 +18,4 @@ namespace IO
{ {
int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name); int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name);
} }
} }
\ No newline at end of file
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "IntegrationPointWriter.h" #include "IntegrationPointWriter.h"
#include "MathLib/LinAlg/LinAlg.h" #include "MathLib/LinAlg/LinAlg.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/XDMF/writeXdmf.h"
#include "NumLib/DOF/LocalToGlobalIndexMap.h" #include "NumLib/DOF/LocalToGlobalIndexMap.h"
/// Copies the ogs_version string containing the release number and the git /// Copies the ogs_version string containing the release number and the git
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment