diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 798ff428..b12f9c9b 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -55,5 +55,9 @@ runs: shell: bash if: ${{ inputs.os == 'windows-latest' }} run: | + unset VCPKG_ROOT git clone https://github.com/microsoft/vcpkg.git - ./vcpkg/bootstrap-vcpkg.bat + cd vcpkg + git checkout "$VCPKG_COMMIT" + ./bootstrap-vcpkg.bat + echo "VCPKG_ROOT=${GITHUB_WORKSPACE}/vcpkg" >> "$GITHUB_ENV" \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c862270c..ff5a7230 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,6 +35,7 @@ jobs: container: ${{ matrix.container }} env: + VCPKG_COMMIT: c3867e714dd3a51c272826eea77267876517ed99 VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/.vcpkg-bincache name: "๐Ÿงช Test on ${{ matrix.os }} (โš™๏ธ: ${{ matrix.config }}, ๐Ÿ’ฟ: ${{ matrix.container || matrix.os }})" @@ -63,17 +64,18 @@ jobs: uses: actions/cache@v4 with: path: ${{ env.VCPKG_DEFAULT_BINARY_CACHE }} - key: vcpkg-${{ matrix.os }}-${{ matrix.config }} + key: vcpkg-${{ matrix.os }}-${{ matrix.config }}-${{ env.VCPKG_COMMIT }} - name: ๐Ÿ› ๏ธ Build Dependencies (Windows) if: ${{ matrix.os == 'windows-latest' }} + shell: pwsh run: | - ./vcpkg/vcpkg install vtk embree + ./vcpkg/vcpkg install --triplet x64-windows - name: ๐Ÿ—๏ธ Compile (Windows) if: ${{ matrix.os == 'windows-latest' }} run: | - cmake -DVIENNAPS_BUILD_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -B build + cmake -DVIENNAPS_BUILD_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -B build cmake --build build --config ${{ matrix.config }} - name: ๐Ÿ—๏ธ Compile (other) @@ -83,4 +85,5 @@ jobs: cmake --build build --config ${{ matrix.config }} - name: ๐Ÿงช Test - run: ctest --output-on-failure -E "Benchmark|Performance" -C ${{ matrix.config }} --test-dir build + run: | + ctest --output-on-failure -E "Benchmark|Performance" -C ${{ matrix.config }} --test-dir build diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 56e9c161..3968f17b 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -32,6 +32,7 @@ jobs: container: ${{ matrix.container }} env: + VCPKG_COMMIT: c3867e714dd3a51c272826eea77267876517ed99 VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/.vcpkg-bincache name: "๐Ÿ Test Bindings on ${{ matrix.os }}" @@ -60,12 +61,13 @@ jobs: uses: actions/cache@v4 with: path: ${{ env.VCPKG_DEFAULT_BINARY_CACHE }} - key: vcpkg-${{ matrix.os }}-Release + key: vcpkg-${{ matrix.os }}-Release-${{ env.VCPKG_COMMIT }} - name: ๐Ÿ› ๏ธ Build Dependencies (Windows) if: ${{ matrix.os == 'windows-latest' }} + shell: pwsh run: | - ./vcpkg/vcpkg install vtk embree + ./vcpkg/vcpkg install --triplet x64-windows - name: ๐Ÿ› ๏ธ Enable GPU Bindings (Linux) if: ${{ matrix.os == 'ubuntu-latest' }} @@ -81,7 +83,9 @@ jobs: $toolchain = "${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake".Replace('\', '/') .\venv\Scripts\python -m pip install --upgrade pip - .\venv\Scripts\python -m pip install . --config-settings=cmake.args="-DCMAKE_TOOLCHAIN_FILE=$toolchain" + .\venv\Scripts\python -m pip install . ` + --config-settings=cmake.define.CMAKE_TOOLCHAIN_FILE="$toolchain" ` + --config-settings=cmake.define.VCPKG_TARGET_TRIPLET="x64-windows" .\venv\Scripts\python -c "import viennaps; print(viennaps.__doc__)" - name: ๐Ÿ Build and check Python Module (Other) diff --git a/CMakeLists.txt b/CMakeLists.txt index 09af9638..4b540752 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,8 +106,7 @@ include("cmake/cpm.cmake") CPMAddPackage( NAME ViennaCore - VERSION 2.1.1 - GIT_TAG main + VERSION 2.1.2 GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore" EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON} OPTIONS "VIENNACORE_USE_GPU ${VIENNAPS_USE_GPU}") @@ -127,6 +126,7 @@ CPMAddPackage( CPMAddPackage( NAME ViennaLS VERSION 5.7.1 + GIT_TAG master GIT_REPOSITORY "https://github.com/ViennaTools/ViennaLS" EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON} OPTIONS "VIENNALS_PRECOMPILE_HEADERS ${VIENNAPS_PRECOMPILE_HEADERS}") diff --git a/include/viennaps/psDomainSetup.hpp b/include/viennaps/psDomainSetup.hpp index 8164534e..f21e7665 100644 --- a/include/viennaps/psDomainSetup.hpp +++ b/include/viennaps/psDomainSetup.hpp @@ -3,9 +3,13 @@ #include "psPreCompileMacros.hpp" #include "psUtil.hpp" +#include #include #include +#include +#include + namespace viennaps { using namespace viennacore; @@ -167,6 +171,31 @@ template class DomainSetup { VIENNACORE_LOG_ERROR("Domain setup is not correctly initialized."); } } + + void serialize(std::ostream &out) const { + out.write(reinterpret_cast(&gridDelta_), sizeof(gridDelta_)); + + out.write(reinterpret_cast(bounds_), sizeof(double) * 2 * D); + + for (int i = 0; i < D; i++) { + const auto boundary = static_cast(boundaryCons_[i]); + out.write(reinterpret_cast(&boundary), sizeof(boundary)); + } + } + + void deserialize(std::istream &in) { + in.read(reinterpret_cast(&gridDelta_), sizeof(gridDelta_)); + + in.read(reinterpret_cast(bounds_), sizeof(double) * 2 * D); + + for (int i = 0; i < D; i++) { + int32_t boundary = 0; + in.read(reinterpret_cast(&boundary), sizeof(boundary)); + boundaryCons_[i] = static_cast(boundary); + } + + init(); + } }; } // namespace viennaps \ No newline at end of file diff --git a/include/viennaps/psReader.hpp b/include/viennaps/psReader.hpp index f9f179d3..a9d5bdfd 100644 --- a/include/viennaps/psReader.hpp +++ b/include/viennaps/psReader.hpp @@ -64,6 +64,9 @@ VIENNAPS_TEMPLATE_ND(NumericType, D) class Reader { return; } + // Clear existing domain data + domain->clear(); + // Check identifier char identifier[8]; fin.read(identifier, 8); @@ -76,19 +79,34 @@ VIENNAPS_TEMPLATE_ND(NumericType, D) class Reader { // Check format version char formatVersion; fin.read(&formatVersion, 1); - if (formatVersion > 1) { + if (formatVersion > 2) { VIENNACORE_LOG_ERROR("Reading domain of version " + std::to_string(formatVersion) + - " with reader of version 1 failed."); + " with reader of version 2 failed."); return; } - // Clear existing domain data - domain->clear(); + if (formatVersion >= 2) { + // Read dimension and check it matches the reader's dimension + char dimension; + fin.read(&dimension, 1); + if (dimension != D) { + VIENNACORE_LOG_ERROR("Reading domain failed. Domain dimension " + + std::to_string(dimension) + + " does not match reader dimension " + + std::to_string(D) + "."); + return; + } + } // Read domain setup typename Domain::Setup setup; - fin.read(reinterpret_cast(&setup), sizeof(setup)); + if (formatVersion >= 2) { + setup.deserialize(fin); + } else { + // Legacy formats store setup as a raw object dump. + fin.read(reinterpret_cast(&setup), sizeof(setup)); + } domain->setup(setup); // Read number of level sets diff --git a/include/viennaps/psWriter.hpp b/include/viennaps/psWriter.hpp index bf68009c..07bc2448 100644 --- a/include/viennaps/psWriter.hpp +++ b/include/viennaps/psWriter.hpp @@ -23,7 +23,6 @@ VIENNAPS_TEMPLATE_ND(NumericType, D) class Writer { private: SmartPointer> domain = nullptr; std::string fileName; - bool meshOutput = false; public: Writer() = default; @@ -44,8 +43,6 @@ VIENNAPS_TEMPLATE_ND(NumericType, D) class Writer { fileName = std::move(passedFileName); } - void setMeshOutput(bool meshOutputFlag) { meshOutput = meshOutputFlag; } - void apply() { // check domain if (domain == nullptr) { @@ -60,8 +57,7 @@ VIENNAPS_TEMPLATE_ND(NumericType, D) class Writer { } if (fileName.find(".vpsd") != fileName.length() - 5) { - VIENNACORE_LOG_WARNING( - "File name does not end in '.vpsd', appending it."); + VIENNACORE_LOG_INFO("File name does not end in '.vpsd', appending it."); fileName.append(".vpsd"); } @@ -70,19 +66,18 @@ VIENNAPS_TEMPLATE_ND(NumericType, D) class Writer { // Write header identifier fout << "psDomain"; - if (meshOutput) { - fout << "ForMesher"; - } - // Version 1 serializes materials by stable names. - char formatVersion = 1; + // Write format version for future compatibility. + char formatVersion = 2; fout.write(&formatVersion, 1); + // Since version 2: write dimension + char dimension = static_cast(D); + fout.write(&dimension, 1); + // Write domain setup - if (!meshOutput) { - auto &setup = domain->getSetup(); - fout.write(reinterpret_cast(&setup), sizeof(setup)); - } + auto &setup = domain->getSetup(); + setup.serialize(fout); // Write number of level sets auto &levelSets = domain->getLevelSets(); @@ -108,14 +103,7 @@ VIENNAPS_TEMPLATE_ND(NumericType, D) class Writer { // Write each material by canonical name for stable cross-run I/O. for (size_t i = 0; i < numMaterials; i++) { const auto material = materialMap->getMaterialAtIdx(i); - std::string materialName; - if (material.isBuiltIn()) { - materialName = MaterialMap::toString(material); - } else { - materialName = - std::string(MaterialRegistry::instance().getName(material)); - } - + std::string materialName = MaterialMap::toString(material); const auto nameLength = static_cast(materialName.size()); fout.write(reinterpret_cast(&nameLength), sizeof(uint32_t)); diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 7fb7323d..138e3b6f 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -116,9 +116,12 @@ add_dependencies(${PROJECT_NAME} ${VIENNAPS_PYTHON_MODULE_NAME}) set(VIENNAPS_LIB_FOLDER "${VIENNAPS_LIBRARY_OUTPUT_DIR}/${VIENNAPS_PYTHON_PACKAGE_NAME}.libs") -viennacore_setup_embree_env(${VIENNAPS_PYTHON_MODULE_NAME} "${VIENNAPS_LIB_FOLDER}") -viennacore_setup_vtk_env(${VIENNAPS_PYTHON_MODULE_NAME} "${VIENNAPS_LIB_FOLDER}") -viennacore_setup_tbb_env(${VIENNAPS_PYTHON_MODULE_NAME} "${VIENNAPS_LIB_FOLDER}") +if(VIENNAPS_PACKAGE_PYTHON OR MSVC) + # Copy the required libraries to the lib folder, this is required for packaging and on Windows + viennacore_setup_embree_env(${VIENNAPS_PYTHON_MODULE_NAME} "${VIENNAPS_LIB_FOLDER}") + viennacore_setup_vtk_env(${VIENNAPS_PYTHON_MODULE_NAME} "${VIENNAPS_LIB_FOLDER}") + viennacore_setup_tbb_env(${VIENNAPS_PYTHON_MODULE_NAME} "${VIENNAPS_LIB_FOLDER}") +endif() install( DIRECTORY ${VIENNAPS_LIB_FOLDER} diff --git a/python/__init__.py b/python/__init__.py index 3285f0ce..e865f182 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -17,11 +17,11 @@ def _windows_dll_path(): ] for path in additional_paths: - if not os.path.exists(path): - continue - - os.add_dll_directory(path) - os.environ["PATH"] = path + os.pathsep + os.environ["PATH"] + if os.path.isdir(path): + os.add_dll_directory(path) + os.environ["PATH"] = path + os.pathsep + os.environ["PATH"] + else: + print(f"Warning: DLL path {path} does not exist.") def _module_ptx_path(): diff --git a/python/pyWrapDimension.hpp b/python/pyWrapDimension.hpp index 60b85987..78edb46b 100644 --- a/python/pyWrapDimension.hpp +++ b/python/pyWrapDimension.hpp @@ -1437,9 +1437,6 @@ template void bindApi(py::module &module) { "Set the domain to be written to a file.") .def("setFileName", &Writer::setFileName, "Set the output file name (should end with .vpsd).") - .def("setMeshOutput", &Writer::setMeshOutput, - "Set wether Domain should be further processed in the ViennaMesh " - "mesher.") .def("apply", &Writer::apply, "Write the domain to the specified file."); diff --git a/python/viennaps/d2/__init__.pyi b/python/viennaps/d2/__init__.pyi index 001d57de..5731a20c 100644 --- a/python/viennaps/d2/__init__.pyi +++ b/python/viennaps/d2/__init__.pyi @@ -1061,7 +1061,3 @@ class Writer: """ Set the output file name (should end with .vpsd). """ - def setMeshOutput(self, arg0: bool) -> None: - """ - Set wether Domain should be further processed in the ViennaMesh mesher. - """ diff --git a/python/viennaps/d3/__init__.pyi b/python/viennaps/d3/__init__.pyi index 16ad1878..bcd7eec7 100644 --- a/python/viennaps/d3/__init__.pyi +++ b/python/viennaps/d3/__init__.pyi @@ -1061,7 +1061,3 @@ class Writer: """ Set the output file name (should end with .vpsd). """ - def setMeshOutput(self, arg0: bool) -> None: - """ - Set wether Domain should be further processed in the ViennaMesh mesher. - """ diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..855701fa --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,9 @@ +{ + "name": "viennaps-ci", + "version-string": "4.3.0", + "dependencies": [ + "vtk", + "embree" + ], + "builtin-baseline": "c3867e714dd3a51c272826eea77267876517ed99" +} \ No newline at end of file