diff --git a/MeshLib/CMakeLists.txt b/MeshLib/CMakeLists.txt index 572180a9cebc55df420f57dc935db2756a829f4f..da1d83bc77338536ff48aa11a59030dfe54502d6 100644 --- a/MeshLib/CMakeLists.txt +++ b/MeshLib/CMakeLists.txt @@ -12,6 +12,7 @@ append_source_files(SOURCES Elements) append_source_files(SOURCES IO) append_source_files(SOURCES IO/Legacy) append_source_files(SOURCES IO/VtkIO) +append_source_files(SOURCES IO/XDMF) append_source_files(SOURCES MeshQuality) append_source_files(SOURCES Vtk) diff --git a/MeshLib/IO/VtkIO/writeXdmf.cpp b/MeshLib/IO/VtkIO/writeXdmf.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c106443ea1ab608321d40181a588456b740a993 --- /dev/null +++ b/MeshLib/IO/VtkIO/writeXdmf.cpp @@ -0,0 +1,56 @@ +/** + * \file + * \author Tobias Meisel + * \date 2020-10-06 + * \brief Implementation of WriteXdmf function. + * + * \copyright + * Copyright (c) 2012-2020, 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 "writeXdmf.h" + +#include <vtkNew.h> +#include <vtkSmartPointer.h> +#include <vtkXdmf3Writer.h> + +#include "MeshLib/Vtk/VtkMappedMeshSource.h" + +namespace MeshLib +{ +namespace IO +{ +bool writeXdmf3(const MeshLib::Mesh& mesh, std::string const &file_name) +{ + #ifdef USE_PETSC + int rank; + MPI_Comm_rank(PETSC_COMM_WORLD, &rank); + int mpi_size; + MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size); + vtkSmartPointer<vtkPXdmf3Writer> writer = vtkSmartPointer<vtkPXdmf3Writer>::New(); // open file handle + + #else + vtkSmartPointer<vtkXdmf3Writer> writer = vtkSmartPointer<vtkXdmf3Writer>::New(); // open file handle + #endif + + writer->SetFileName(file_name.c_str()); + vtkNew<MeshLib::VtkMappedMeshSource> vtkSource; + vtkSource->SetMesh(&mesh); + vtkSource->Update(); + writer->SetInputData(vtkSource->GetOutput()); + + #ifdef USE_PETSC + writer->SetGhostLevel(1); + writer->SetNumberOfPieces(num_partitions); + writer->SetStartPiece(rank); + writer->SetEndPiece(rank); + #endif + writer->Write(); + // close file handle + return 0; +} +} //end namespace IO +} //end namespace MeshLib \ No newline at end of file diff --git a/MeshLib/IO/VtkIO/writeXdmf.h b/MeshLib/IO/VtkIO/writeXdmf.h new file mode 100644 index 0000000000000000000000000000000000000000..71c6f5f5766b98972de32668e3fe6fe255c454b2 --- /dev/null +++ b/MeshLib/IO/VtkIO/writeXdmf.h @@ -0,0 +1,34 @@ +/** + * \file + * \author Tobias Meisel + * \date 2020-10-06 + * \brief Writes MeshLib:Mesh to a Xdmf formated file + * + * \copyright + * Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#pragma once + +#include <string> +#include "MeshLib/Mesh.h" + +namespace MeshLib { + + +namespace IO +{ + +/// Writes mesh to XDMF file. +/// \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 file_name File name. +/// \return True on success, false on error + +} // end namespace IO +} // end namespace MeshLib \ No newline at end of file