diff --git a/MeshLib/IO/VtkIO/writeXdmf.cpp b/MeshLib/IO/VtkIO/writeXdmf.cpp deleted file mode 100644 index 8c106443ea1ab608321d40181a588456b740a993..0000000000000000000000000000000000000000 --- a/MeshLib/IO/VtkIO/writeXdmf.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \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/XDMF/writeXdmf.cpp b/MeshLib/IO/XDMF/writeXdmf.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f7f1ba601ae402f2efa178abc2c7ea5dc6c8020c --- /dev/null +++ b/MeshLib/IO/XDMF/writeXdmf.cpp @@ -0,0 +1,59 @@ +/** + * \file + * \author Tobias Meisel + * \date 2020-10-06 + * \brief Implementation of WriteXdmf3 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 <vtkPXdmf3Writer.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/XDMF/writeXdmf.h similarity index 75% rename from MeshLib/IO/VtkIO/writeXdmf.h rename to MeshLib/IO/XDMF/writeXdmf.h index 71c6f5f5766b98972de32668e3fe6fe255c454b2..b723cde680734b62d18c4603253082176379eb91 100644 --- a/MeshLib/IO/VtkIO/writeXdmf.h +++ b/MeshLib/IO/XDMF/writeXdmf.h @@ -15,20 +15,18 @@ #pragma once #include <string> -#include "MeshLib/Mesh.h" - -namespace MeshLib { +namespace MeshLib +{ +class Mesh; 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 +bool writeXdmf3(MeshLib::Mesh const& mesh, std::string const& file_name); -} // end namespace IO -} // end namespace MeshLib \ No newline at end of file +} // end namespace IO +} // end namespace MeshLib \ No newline at end of file diff --git a/MeshLib/IO/writeMeshToFile.cpp b/MeshLib/IO/writeMeshToFile.cpp index debc78c3bd7caee1d1aa78616e9135722b589693..256680b6a6d24f0693200aba83470483602658fc 100644 --- a/MeshLib/IO/writeMeshToFile.cpp +++ b/MeshLib/IO/writeMeshToFile.cpp @@ -10,14 +10,14 @@ #include "writeMeshToFile.h" #include "BaseLib/Logging.h" - #include "BaseLib/FileTools.h" #include "BaseLib/StringTools.h" #include "MeshLib/Mesh.h" - #include "MeshLib/IO/Legacy/MeshIO.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" +#include "MeshLib/IO/XDMF/writeXdmf.h" + namespace MeshLib { @@ -44,9 +44,19 @@ int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name) } 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); return -1; + } } // end namespace IO diff --git a/MeshLib/IO/writeMeshToFile.h b/MeshLib/IO/writeMeshToFile.h index 223a2a0d31f6f663d3ec710458d027d44859546e..d2751c7a6675f61d89623bf2e481520f29043115 100644 --- a/MeshLib/IO/writeMeshToFile.h +++ b/MeshLib/IO/writeMeshToFile.h @@ -18,4 +18,4 @@ namespace IO { int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name); } -} +} \ No newline at end of file diff --git a/ProcessLib/Output/ProcessOutput.cpp b/ProcessLib/Output/ProcessOutput.cpp index ae067ab9f937d6cfee92e0218ba9a8fc2fca4a67..f6b0f1495ceccacb5c131d5e89ff11dd70f77a07 100644 --- a/ProcessLib/Output/ProcessOutput.cpp +++ b/ProcessLib/Output/ProcessOutput.cpp @@ -20,6 +20,7 @@ #include "IntegrationPointWriter.h" #include "MathLib/LinAlg/LinAlg.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" +#include "MeshLib/IO/XDMF/writeXdmf.h" #include "NumLib/DOF/LocalToGlobalIndexMap.h" /// Copies the ogs_version string containing the release number and the git