diff --git a/CMakeLists.txt b/CMakeLists.txt index 928bf041b43649dc4fdd25e0ffb7a15ed6b3c078..72339dbf4ea83e56b93bac9e3ea64be380d03efd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,7 @@ option(OGS_INSITU "Builds OGS with insitu visualization capabilities." OFF) option(OGS_USE_LIS "Use Lis" OFF) option(OGS_USE_PETSC "Use PETSc routines" OFF) option(OGS_USE_NETCDF "Add NetCDF support." OFF) +option(OGS_USE_XDMF "Add Xdmf file IO support" OFF) # Eigen option(OGS_USE_EIGEN "Use Eigen linear solver" ON) @@ -237,6 +238,10 @@ if(OGS_USE_EIGEN) endif() # End Eigen +if(OGS_USE_XDMF) + add_definitions(-DOGS_USE_XDMF) +endif() + if(OGS_FATAL_ABORT) add_definitions(-DOGS_FATAL_ABORT) endif() diff --git a/MeshLib/CMakeLists.txt b/MeshLib/CMakeLists.txt index c328d33c7cdc5bd1ee1c4b6de71b61d6b78692ee..e73de0542b3b97ff81f9b59122c32ea9a943628c 100644 --- a/MeshLib/CMakeLists.txt +++ b/MeshLib/CMakeLists.txt @@ -12,7 +12,9 @@ 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) +if(OGS_USE_XDMF) + append_source_files(SOURCES IO/XDMF) +endif() append_source_files(SOURCES MeshQuality) append_source_files(SOURCES Vtk) @@ -26,7 +28,9 @@ ogs_add_library(MeshLib ${SOURCES}) target_link_libraries( MeshLib - PUBLIC BaseLib GeoLib GitInfoLib MathLib ${VTK_LIBRARIES} OgsXdmf + PUBLIC + BaseLib GeoLib GitInfoLib MathLib ${VTK_LIBRARIES} + $<$<TARGET_EXISTS:OgsXdmf>:OgsXdmf> PRIVATE spdlog::spdlog) if(OGS_USE_MPI AND TARGET MPI::MPI_CXX) diff --git a/MeshLib/IO/writeMeshToFile.cpp b/MeshLib/IO/writeMeshToFile.cpp index 2d1165e501229483c509c2b4dcce7ea9fefb27b1..86dda37ec86f5b2e141bc1c8ea9ea23d9fbcf8dd 100644 --- a/MeshLib/IO/writeMeshToFile.cpp +++ b/MeshLib/IO/writeMeshToFile.cpp @@ -42,6 +42,7 @@ int writeMeshToFile(const MeshLib::Mesh& mesh, } return 0; } +#ifdef OGS_USE_XDMF if (file_path.extension().string() == ".xdmf") { auto writer = @@ -56,6 +57,7 @@ int writeMeshToFile(const MeshLib::Mesh& mesh, return 0; } +#endif ERR("writeMeshToFile(): Unknown mesh file format in file {:s}.", file_path.string()); return -1; diff --git a/ProcessLib/Output/Output.cpp b/ProcessLib/Output/Output.cpp index bd4035eec1263d0f3ecdb21c4e0efd1af38c9b1c..c2b4e1f9af02d11fbba479e32be5876ce2b200a9 100644 --- a/ProcessLib/Output/Output.cpp +++ b/ProcessLib/Output/Output.cpp @@ -227,6 +227,7 @@ struct Output::OutputFile } }; +#ifdef OGS_USE_XDMF void Output::outputMeshXdmf(OutputFile const& output_file, MeshLib::Mesh const& mesh, int const timestep, @@ -245,6 +246,7 @@ void Output::outputMeshXdmf(OutputFile const& output_file, } _mesh_xdmf_writer->writeStep(timestep, t); } +#endif void Output::outputMesh(OutputFile const& output_file, MeshLib::IO::PVDFile* const pvd_file, @@ -313,12 +315,18 @@ void Output::doOutputAlways(Process const& process, } else if (_output_file_type == ProcessLib::OutputType::xdmf) { +#ifdef OGS_USE_XDMF OutputFile const file(_output_directory, _output_file_type, _output_file_prefix, "", mesh.getName(), timestep, t, _output_file_data_mode, _output_file_compression); outputMeshXdmf(file, mesh, timestep, t); +#else + OGS_FATAL( + "Trying to write Xdmf file but OGS was not built with " + "Xdmf-support."); +#endif } }; diff --git a/ProcessLib/Output/Output.h b/ProcessLib/Output/Output.h index 23d6ceec6eda3de2d877913ba7f841d780b02732..e75f35c88d61b4a33e736e36e0c47a041a71c53a 100644 --- a/ProcessLib/Output/Output.h +++ b/ProcessLib/Output/Output.h @@ -14,7 +14,9 @@ #include <utility> #include "MeshLib/IO/VtkIO/PVDFile.h" +#ifdef OGS_USE_XDMF #include "MeshLib/IO/XDMF/Xdmf3Writer.h" +#endif #include "ProcessOutput.h" namespace ProcessLib @@ -89,13 +91,17 @@ private: MeshLib::Mesh const& mesh, int const timestep, double const t) const; +#ifdef OGS_USE_XDMF void outputMeshXdmf(OutputFile const& output_file, MeshLib::Mesh const& mesh, int const timestep, double const t); +#endif private: +#ifdef OGS_USE_XDMF std::unique_ptr<MeshLib::IO::Xdmf3Writer> _mesh_xdmf_writer; +#endif std::string const _output_directory; OutputType const _output_file_type; std::string const _output_file_prefix; diff --git a/ProcessLib/Output/ProcessOutput.cpp b/ProcessLib/Output/ProcessOutput.cpp index d84278f8a69f175669c9cb465d5b8ea4d75c7a0b..5297b79d2f910547d834b631c2856ad78f663ac5 100644 --- a/ProcessLib/Output/ProcessOutput.cpp +++ b/ProcessLib/Output/ProcessOutput.cpp @@ -285,11 +285,17 @@ void makeOutput(std::string const& file_name, MeshLib::Mesh const& mesh, case OutputType::xdmf: { +#ifdef OGS_USE_XDMF MeshLib::IO::Xdmf3Writer writer( file_name, MeshLib::IO::transformGeometry(mesh), MeshLib::IO::transformTopology(mesh), MeshLib::IO::transformAttributes(mesh), time_step); writer.writeStep(time_step, time); +#else + OGS_FATAL( + "Trying to write Xdmf file but OGS was not built with " + "Xdmf-support."); +#endif } } diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 350ed3570d5377a47e1fd1bbd90a11bf32a5fdca..f3e902b7904e6ae0c71994ad8d9b4a8641109e0d 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1,5 +1,7 @@ ### xdmfdiff ### -add_subdirectory(xdmfdiff) +if(OGS_USE_XDMF) + add_subdirectory(xdmfdiff) +endif() ### testrunner ### include(${PROJECT_SOURCE_DIR}/scripts/cmake/OGSEnabledElements.cmake) diff --git a/ThirdParty/CMakeLists.txt b/ThirdParty/CMakeLists.txt index 14bdd3ae703cd7d0f23a6419af3f17fcd73531d0..c42ad6743d48939f9473c55a927696288fbe18bc 100644 --- a/ThirdParty/CMakeLists.txt +++ b/ThirdParty/CMakeLists.txt @@ -88,42 +88,42 @@ if(OGS_BUILD_UTILS) list(APPEND DISABLE_WARNINGS_TARGETS ogs_metis mpmetis) endif() -# Xdmf -find_package(ZLIB REQUIRED) # ZLIB is a HDF5 dependency -set(XDMF_LIBNAME OgsXdmf CACHE INTERNAL "") -add_subdirectory(xdmf) -target_include_directories(${XDMF_LIBNAME} PUBLIC - ${PROJECT_SOURCE_DIR}/ThirdParty/xdmf - ${PROJECT_BINARY_DIR}/ThirdParty/xdmf -) -if(OGS_USE_CONAN AND UNIX AND APPLE) - find_package(Iconv REQUIRED) +if(OGS_USE_XDMF) + find_package(ZLIB REQUIRED) # ZLIB is a HDF5 dependency + set(XDMF_LIBNAME OgsXdmf CACHE INTERNAL "") + add_subdirectory(xdmf) + target_include_directories(${XDMF_LIBNAME} PUBLIC + ${PROJECT_SOURCE_DIR}/ThirdParty/xdmf + ${PROJECT_BINARY_DIR}/ThirdParty/xdmf + ) + if(OGS_USE_CONAN AND UNIX AND APPLE) + find_package(Iconv REQUIRED) + endif() + + if(MSVC AND OGS_USE_CONAN) + # Hack: Conan HDF5 not found on Windows + target_link_libraries(${XDMF_LIBNAME} ${CONAN_LIBS}) + else() + target_link_libraries(${XDMF_LIBNAME} Boost::boost ${Iconv_LIBRARIES} ZLIB::ZLIB) + endif() + target_include_directories(${XDMF_LIBNAME}Core PUBLIC + ${PROJECT_SOURCE_DIR}/ThirdParty/xdmf/core + ${PROJECT_BINARY_DIR}/ThirdParty/xdmf/core + ) + find_package(LibXml2 REQUIRED) # LibXml2 is a XdmfCore dependency + target_link_libraries(${XDMF_LIBNAME}Core PUBLIC LibXml2::LibXml2) + + set_target_properties(${XDMF_LIBNAME} ${XDMF_LIBNAME}Core PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} + LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} + ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} + ) + if(BUILD_SHARED_LIBS) + install(TARGETS ${XDMF_LIBNAME} ${XDMF_LIBNAME}Core LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + list(APPEND DISABLE_WARNINGS_TARGETS ${XDMF_LIBNAME} ${XDMF_LIBNAME}Core) endif() -if(MSVC AND OGS_USE_CONAN) - # Hack: Conan HDF5 not found on Windows - target_link_libraries(${XDMF_LIBNAME} ${CONAN_LIBS}) -else() - target_link_libraries(${XDMF_LIBNAME} Boost::boost ${Iconv_LIBRARIES} ZLIB::ZLIB) -endif() -target_include_directories(${XDMF_LIBNAME}Core PUBLIC - ${PROJECT_SOURCE_DIR}/ThirdParty/xdmf/core - ${PROJECT_BINARY_DIR}/ThirdParty/xdmf/core -) -find_package(LibXml2 REQUIRED) # LibXml2 is a XdmfCore dependency -target_link_libraries(${XDMF_LIBNAME}Core PUBLIC LibXml2::LibXml2) - -set_target_properties(${XDMF_LIBNAME} ${XDMF_LIBNAME}Core PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} - ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} -) -if(BUILD_SHARED_LIBS) - install(TARGETS ${XDMF_LIBNAME} ${XDMF_LIBNAME}Core LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif() -list(APPEND DISABLE_WARNINGS_TARGETS ${XDMF_LIBNAME} ${XDMF_LIBNAME}Core) -# Xdmf end - foreach(TARGET ${DISABLE_WARNINGS_TARGETS}) target_compile_options(${TARGET} PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-w> diff --git a/scripts/ci/jobs/code-quality.yml b/scripts/ci/jobs/code-quality.yml index d7f4021b5c68c2b5fe3b7a3645b87b59b3a0f6d7..59916cf3f8bb2567e15a94dd0ffc04ee0cae0653 100644 --- a/scripts/ci/jobs/code-quality.yml +++ b/scripts/ci/jobs/code-quality.yml @@ -8,7 +8,7 @@ cppcheck: script: - > cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DOGS_USE_CONAN=OFF - -DOGS_USE_UNITY_BUILDS=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DOGS_USE_UNITY_BUILDS=OFF -DOGS_USE_XDMF=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - bash cppcheck.sh artifacts: reports: diff --git a/scripts/cmake/ConanSetup.cmake b/scripts/cmake/ConanSetup.cmake index a2eab45b23b9e85f24d61ce3f34d5a32c68fb06e..bec3c0476b455de0bb14966f135c2a87fd50596d 100644 --- a/scripts/cmake/ConanSetup.cmake +++ b/scripts/cmake/ConanSetup.cmake @@ -35,8 +35,6 @@ set(CONAN_REQUIRES boost/${ogs.minimum_version.boost}@conan/stable eigen/${ogs.minimum_version.eigen}@conan/stable vtk/${ogs.tested_version.vtk}@bilke/stable - hdf5/${ogs.tested_version.hdf5} - libxml2/${ogs.tested_version.libxml2} CACHE INTERNAL "" ) @@ -47,9 +45,6 @@ set(CONAN_OPTIONS vtk:iolegacy=True CACHE INTERNAL "" ) -if(UNIX AND NOT APPLE) - list(APPEND CONAN_OPTIONS libxml2:iconv=False) -endif() if((UNIX AND NOT APPLE) AND BUILD_SHARED_LIBS) set(CONAN_OPTIONS ${CONAN_OPTIONS} vtk:fPIC=True) @@ -59,6 +54,24 @@ if(OGS_USE_MPI) set(CONAN_OPTIONS ${CONAN_OPTIONS} vtk:mpi_minimal=True) endif() +if(OGS_USE_XDMF) + list(APPEND CONAN_REQUIRES + hdf5/${ogs.tested_version.hdf5} + libxml2/${ogs.tested_version.libxml2} + ) + if(UNIX AND NOT APPLE) + list(APPEND CONAN_OPTIONS libxml2:iconv=False) + endif() + if(MSVC) + # Hack: Conan HDF5 not found on Windows + # Use custom FindHDF5 with forced values from Conan + list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/scripts/cmake/conan/win-hdf5") + else() + # Hack: Suppress hdf5 compiler wrapper checks + set(HDF5_C_COMPILER_EXECUTABLE "OFF" CACHE INTERNAL "") + endif() +endif() + if(OGS_USE_PETSC) set(CONAN_REQUIRES ${CONAN_REQUIRES} petsc/${ogs.minimum_version.petsc}@bilke/testing) if(OGS_CONAN_USE_SYSTEM_OPENMPI) @@ -194,12 +207,3 @@ endif() if(OGS_USE_PETSC) set(PETSC_DIR ${CONAN_PETSC_ROOT} CACHE INTERNAL "") endif() - -if(MSVC) - # Hack: Conan HDF5 not found on Windows - # Use custom FindHDF5 with forced values from Conan - list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/scripts/cmake/conan/win-hdf5") -else() - # Hack: Suppress hdf5 compiler wrapper checks - set(HDF5_C_COMPILER_EXECUTABLE "OFF" CACHE INTERNAL "") -endif()