From fdefff6750bd0d2da3f1665eeb6b11a45a9ec698 Mon Sep 17 00:00:00 2001 From: ifilot Date: Tue, 18 Aug 2026 10:18:27 +0200 Subject: [PATCH 1/4] Changed filename and added MacOS GIithub ACtion --- .github/workflows/build-macos.yml | 41 +++++++++++++++++++++++++++++++ src/d2o_format.h | 2 +- src/{math.h => den2obj_math.h} | 6 ++--- src/generator_benzene_data.h | 2 +- src/generator_sto3g_data.h | 2 +- src/isosurface.h | 2 +- src/isosurface_mesh.h | 2 +- src/scalar_field.h | 2 +- 8 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/build-macos.yml rename src/{math.h => den2obj_math.h} (96%) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml new file mode 100644 index 0000000..d76f47e --- /dev/null +++ b/.github/workflows/build-macos.yml @@ -0,0 +1,41 @@ +name: macOS build + +on: + push: + branches: [ "master", "develop" ] + pull_request: + branches: [ "master", "develop" ] + +permissions: + contents: read + +jobs: + build-and-test: + name: Apple Silicon with OpenVDB + runs-on: macos-26 + + steps: + - uses: actions/checkout@v4 + + - name: Verify runner architecture + run: | + test "$(uname -m)" = "arm64" + clang++ --version + + - name: Install dependencies + run: brew install cmake tclap boost openvdb tbb pkgconf cppunit eigen xz zstd c-blosc + + # Keep these commands aligned with the macOS reproduction in issue #14. + - name: Configure CMake with OpenVDB + run: | + mkdir build + cd build + cmake -DMOD_OPENVDB=1 ../src + + - name: Build + working-directory: build + run: make -j5 + + - name: Run unit tests + working-directory: build + run: ctest --output-on-failure diff --git a/src/d2o_format.h b/src/d2o_format.h index 703258e..83316f2 100644 --- a/src/d2o_format.h +++ b/src/d2o_format.h @@ -38,7 +38,7 @@ #include #include -#include "math.h" +#include "den2obj_math.h" namespace D2OFormat { diff --git a/src/math.h b/src/den2obj_math.h similarity index 96% rename from src/math.h rename to src/den2obj_math.h index 4621d05..75d80e8 100644 --- a/src/math.h +++ b/src/den2obj_math.h @@ -18,8 +18,8 @@ * * **************************************************************************/ -#ifndef _MATRICES_H -#define _MATRICES_H +#ifndef DEN2OBJ_MATH_H +#define DEN2OBJ_MATH_H #include @@ -33,4 +33,4 @@ template T sgn(T val) { return (T(0) < val) - (val < T(0)); } -#endif // _MATRICES_H +#endif // DEN2OBJ_MATH_H diff --git a/src/generator_benzene_data.h b/src/generator_benzene_data.h index 6b8342c..561c42a 100644 --- a/src/generator_benzene_data.h +++ b/src/generator_benzene_data.h @@ -21,7 +21,7 @@ #ifndef _GENERATOR_BENZENE_DATA_H #define _GENERATOR_BENZENE_DATA_H -#include "math.h" +#include "den2obj_math.h" namespace GeneratorData { diff --git a/src/generator_sto3g_data.h b/src/generator_sto3g_data.h index 1cf79e6..8ebd584 100644 --- a/src/generator_sto3g_data.h +++ b/src/generator_sto3g_data.h @@ -21,7 +21,7 @@ #ifndef _GENERATOR_STO3G_DATA_H #define _GENERATOR_STO3G_DATA_H -#include "math.h" +#include "den2obj_math.h" namespace GeneratorData { diff --git a/src/isosurface.h b/src/isosurface.h index f8b13d0..0488512 100644 --- a/src/isosurface.h +++ b/src/isosurface.h @@ -29,7 +29,7 @@ #include "edgetable.h" #include "triangletable.h" #include "scalar_field.h" -#include "math.h" +#include "den2obj_math.h" #define PRECISION_LIMIT 0.000000001 diff --git a/src/isosurface_mesh.h b/src/isosurface_mesh.h index 0ae6f17..e0a67a8 100644 --- a/src/isosurface_mesh.h +++ b/src/isosurface_mesh.h @@ -27,7 +27,7 @@ #include #include -#include "math.h" +#include "den2obj_math.h" #include "isosurface.h" #include "check_endian.h" diff --git a/src/scalar_field.h b/src/scalar_field.h index 9e6cb27..09e0791 100644 --- a/src/scalar_field.h +++ b/src/scalar_field.h @@ -40,7 +40,7 @@ #include #include -#include "math.h" +#include "den2obj_math.h" #include "float_parser.h" #include "periodic_table.h" #include "d2o_format.h" From 3661e9e859f9ab86ee2d34966b99b12dac659f00 Mon Sep 17 00:00:00 2001 From: ifilot Date: Tue, 18 Aug 2026 11:36:16 +0200 Subject: [PATCH 2/4] Hardening for MacOS --- src/isosurface_mesh.cpp | 38 +++++++++++++++++++++++++++------ src/isosurface_mesh.h | 1 - src/test/CMakeLists.txt | 1 + src/test/test_file_creation.cpp | 6 ++++++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/isosurface_mesh.cpp b/src/isosurface_mesh.cpp index cd089d9..9ae9251 100644 --- a/src/isosurface_mesh.cpp +++ b/src/isosurface_mesh.cpp @@ -20,6 +20,30 @@ #include "isosurface_mesh.h" +#ifdef _OPENMP +#include +#endif + +namespace { + +size_t get_max_thread_count() { +#ifdef _OPENMP + return static_cast(omp_get_max_threads()); +#else + return 1; +#endif +} + +size_t get_thread_number() { +#ifdef _OPENMP + return static_cast(omp_get_thread_num()); +#else + return 0; +#endif +} + +} // namespace + /** * @brief build isosurface mesh object * @@ -176,14 +200,16 @@ void IsoSurfaceMesh::write_obj(const std::string& filename, const std::string& h outfile << "o " << name << std::endl; // calculate number of threads - size_t nrthreads = omp_get_max_threads(); - omp_set_num_threads(nrthreads); // always allocate max threads - std::stringstream local[nrthreads]; + const size_t nrthreads = get_max_thread_count(); +#ifdef _OPENMP + omp_set_num_threads(static_cast(nrthreads)); // always allocate max threads +#endif + std::vector local(nrthreads); // parallel writing vertices #pragma omp parallel { - size_t threadnum = omp_get_thread_num(); + const size_t threadnum = get_thread_number(); // calculate size size_t rem = this->vertices.size() % nrthreads; @@ -215,7 +241,7 @@ void IsoSurfaceMesh::write_obj(const std::string& filename, const std::string& h #pragma omp parallel { - size_t threadnum = omp_get_thread_num(); + const size_t threadnum = get_thread_number(); // calculate size size_t rem = this->normals.size() % nrthreads; @@ -249,7 +275,7 @@ void IsoSurfaceMesh::write_obj(const std::string& filename, const std::string& h #pragma omp parallel { - size_t threadnum = omp_get_thread_num(); + const size_t threadnum = get_thread_number(); // calculate size size_t rem = (this->indices.size() / 3) % nrthreads; diff --git a/src/isosurface_mesh.h b/src/isosurface_mesh.h index e0a67a8..64016e1 100644 --- a/src/isosurface_mesh.h +++ b/src/isosurface_mesh.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "den2obj_math.h" diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 8ab12bc..722a32a 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -21,6 +21,7 @@ pkg_check_modules(CPPUNIT REQUIRED IMPORTED_TARGET cppunit) add_library(unittest STATIC unittest.cpp) target_compile_features(unittest PUBLIC cxx_std_17) +target_link_libraries(unittest PRIVATE PkgConfig::CPPUNIT) set(EXECUTABLES TestIsosurface TestScalarField TestD2OFileFormat TestGenerator) diff --git a/src/test/test_file_creation.cpp b/src/test/test_file_creation.cpp index c265ab8..eb9463d 100644 --- a/src/test/test_file_creation.cpp +++ b/src/test/test_file_creation.cpp @@ -20,6 +20,10 @@ #include "test_file_creation.h" +#ifdef _OPENMP +#include +#endif + CPPUNIT_TEST_SUITE_REGISTRATION( TestFileCreation ); void TestFileCreation::setUp() { @@ -44,8 +48,10 @@ void TestFileCreation::test_obj_file() { } TestFileCreation::MeshReference TestFileCreation::generate_mesh() const { +#ifdef _OPENMP // set number of threads to 1 omp_set_num_threads(1); +#endif // read scalar field ScalarField sf("co_2pi_x.cub", ScalarFieldInputFileType::SFF_CUB); From a5a0388b1ea443be42d7f2254422b26f2c97553e Mon Sep 17 00:00:00 2001 From: ifilot Date: Tue, 18 Aug 2026 11:47:30 +0200 Subject: [PATCH 3/4] Fixing bug in finding OpenVDB libraries --- src/CMakeLists.txt | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2fc8de4..36e6a84 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,8 +65,35 @@ endif() set(OPENVDB_LIBS "") if(MOD_OPENVDB) - set(OPENVDB_LIBS openvdb tbb PkgConfig::BLOSC ZLIB::ZLIB) - message(STATUS "Compiling with OpenVDB module") + # OpenVDB currently installs a Find-module rather than a Config package. + # Locate that module relative to its headers so this works with Homebrew's + # /opt/homebrew prefix as well as Linux multiarch installations. + find_package(OpenVDB CONFIG QUIET) + if(NOT TARGET OpenVDB::openvdb) + find_path(OpenVDB_INCLUDE_DIR NAMES openvdb/openvdb.h) + if(NOT OpenVDB_INCLUDE_DIR) + message(FATAL_ERROR "Could not locate the OpenVDB headers") + endif() + + get_filename_component(_OPENVDB_INSTALL_PREFIX "${OpenVDB_INCLUDE_DIR}" DIRECTORY) + find_path(OpenVDB_CMAKE_MODULE_DIR + NAMES FindOpenVDB.cmake + HINTS "${_OPENVDB_INSTALL_PREFIX}" ${CMAKE_PREFIX_PATH} + PATH_SUFFIXES + lib/cmake/OpenVDB + "lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake/OpenVDB" + share/cmake/OpenVDB + ) + if(NOT OpenVDB_CMAKE_MODULE_DIR) + message(FATAL_ERROR "Could not locate OpenVDB's FindOpenVDB.cmake module") + endif() + + list(PREPEND CMAKE_MODULE_PATH "${OpenVDB_CMAKE_MODULE_DIR}") + find_package(OpenVDB REQUIRED) + endif() + + set(OPENVDB_LIBS OpenVDB::openvdb) + message(STATUS "Compiling with OpenVDB module: ${OpenVDB_VERSION}") endif() file(GLOB SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") From 00503adaecd1c2edc87e4aa081bee79eb063cf2f Mon Sep 17 00:00:00 2001 From: ifilot Date: Tue, 18 Aug 2026 12:32:47 +0200 Subject: [PATCH 4/4] Increment version --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 36e6a84..34677ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,7 @@ #*************************************************************************/ cmake_minimum_required(VERSION 3.16) -project(den2obj VERSION 1.3.0 LANGUAGES CXX) +project(den2obj VERSION 1.3.1 LANGUAGES CXX) option(USE_GCOV "Build with gcov coverage instrumentation" OFF) option(MOD_OPENVDB "Enable OpenVDB support" OFF)