diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml new file mode 100644 index 0000000..5f7cb65 --- /dev/null +++ b/.github/workflows/cibuildwheel.yml @@ -0,0 +1,54 @@ +name: cibuildwheel + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + + steps: + - uses: actions/checkout@v4 + - name: checkout submodules + run: git submodule update --init --recursive + + # Used to host cibuildwheel + - uses: actions/setup-python@v4 + + - name: Install cibuildwheel and other dependencies + run: python -m pip install cibuildwheel==2.17.0 build wheel setuptools + + - name: Build sdist + run: pipx run build --sdist --outdir wheelhouse + if: runner.os == 'Windows' + + - name: Build wheels + run: python -m cibuildwheel --output-dir wheelhouse + # to supply options, put them in 'env', like: + env: + CIBW_ARCHS: auto64 + CIBW_ARCHS_MACOS: "universal2" + # CIBW_BEFORE_BUILD: bash cpp/build.sh + CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=11.0 + CIBW_ENVIRONMENT_LINUX: CXXFLAGS='-fconcepts' + CIBW_BUILD_VERBOSITY_WINDOWS: 2 + CIBW_SKIP: "*pypy* *pp* *cp36* *cp37* *musl*" + + - uses: actions/upload-artifact@v4 + with: + name: binary-${{ matrix.os }}-${{ matrix.version }} + path: | + ./wheelhouse/*.whl + ./wheelhouse/*.tar.gz + merge: + runs-on: ubuntu-latest + needs: build_wheels + steps: + - name: Merge Artifacts + uses: actions/upload-artifact/merge@v4 + with: + name: artifact + pattern: binary-* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e69de29 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fe2097c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.16) +cmake_policy(VERSION 3.12) +project(KineticGas LANGUAGES C CXX) + +SET(CMAKE_CXX_STANDARD 17) + +if(NOT MSVC) + set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -pthread") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wno-unused-parameter") + set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DDEBUG -Wno-unused-parameter -Wno-unused-const-variable") +endif(NOT MSVC) + +set(SOURCES cpp/KineticGas.cpp cpp/KineticGas_mthr.cpp cpp/Spherical.cpp cpp/MieKinGas.cpp + cpp/Integration/Integration.cpp cpp/Factorial.cpp cpp/bindings.cpp) + +if (CMAKE_BUILD_TYPE MATCHES Release) + project(pykingas) + set(TARGET pykingas) +else() + project(pykingas_d) + set(TARGET pykingas_d) +endif() + +# Find the module development requirements (requires FindPython from 3.17 or +# scikit-build-core's built-in backport) +find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) +find_package(pybind11 CONFIG REQUIRED) + +# Add a library using FindPython's tooling (pybind11 also provides a helper like +# this) +python_add_library(${TARGET} MODULE ${SOURCES} WITH_SOABI) +target_link_libraries(${TARGET} PRIVATE pybind11::headers) + +# The install directory is the output (wheel) directory +install(TARGETS ${TARGET} DESTINATION pykingas) \ No newline at end of file diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt deleted file mode 100644 index f1cfbb3..0000000 --- a/cpp/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_policy(VERSION 3.12) -project(KineticGas LANGUAGES C CXX) - -cmake_minimum_required(VERSION 3.12) -set(PYBIND11_PYTHON_VERSION "3") -string(ASCII 27 Esc) -message("${Esc}[34mPYBIND11_PYTHON_VERSION is : ${PYBIND11_PYTHON_VERSION}") -message("${Esc}[34mPYTHON_EXECUTABLE is : ${PYTHON_EXECUTABLE}") - -set(PYBIND11_ROOT "/usr/local/include/pybind11") # This path must contain the pybind11 root dir. - -if(NOT MSVC) - # set(CMAKE_CXX_COMPILER /usr/bin/g++) # Setting these can, on some systems, cause cmake to go into an infinite loop (see: build.sh to set the compiler) - # set(CMAKE_C_COMPILER /usr/bin/gcc) # Setting these can, on some systems, cause cmake to go into an infinite loop (see: build.sh to set the compiler) - if(APPLE) - set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -std=c++17 -pthread -arch arm64") - else() - set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -std=c++17 -pthread") - endif(APPLE) - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wno-unused-parameter") - set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -DDEBUG -Wno-unused-parameter -Wno-unused-const-variable") -endif(NOT MSVC) - -set(SOURCES KineticGas.cpp KineticGas_mthr.cpp Spherical.cpp MieKinGas.cpp - Integration/Integration.cpp Factorial.cpp bindings.cpp) - -if (CMAKE_BUILD_TYPE MATCHES Release) - project(KineticGas_r) - set(TARGET KineticGas_r) -else() - project(KineticGas_d) - set(TARGET KineticGas_d) -endif() - -add_subdirectory(${PYBIND11_ROOT} release) -pybind11_add_module(${TARGET} ${SOURCES}) \ No newline at end of file diff --git a/cpp/MieKinGas.h b/cpp/MieKinGas.h index ba40542..6a80a35 100644 --- a/cpp/MieKinGas.h +++ b/cpp/MieKinGas.h @@ -95,7 +95,7 @@ class MieKinGas : public Spherical { // Contact diameter related methods // bmax[i][j] is in units of sigma[i][j] // bmax = The maximum value of the impact parameter at which deflection angle (chi) is positive - std::vector> get_b_max(double T); + std::vector> get_b_max (double T) override; std::vector> get_collision_diameters(double rho, double T, const std::vector& x) override; virtual std::vector> get_BH_diameters(double T); std::vector> get_vdw_alpha(){return alpha;} diff --git a/cpp/bindings.cpp b/cpp/bindings.cpp index 4bea8c3..541793d 100644 --- a/cpp/bindings.cpp +++ b/cpp/bindings.cpp @@ -67,9 +67,9 @@ using vector2d = std::vector; #ifndef DEBUG -PYBIND11_MODULE(KineticGas_r, handle){ +PYBIND11_MODULE(pykingas, handle){ #else -PYBIND11_MODULE(KineticGas_d, handle){ +PYBIND11_MODULE(pykingas_d, handle){ #endif handle.doc() = "Is this documentation? This is documentation."; handle.def("ipow", &ipow); diff --git a/cpp/build.sh b/cpp/build.sh deleted file mode 100644 index 41248e6..0000000 --- a/cpp/build.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Script to build the KineticGas module and run tests. Can be used with options -set -e - -py_version=${1-"-DPYBIND11_PYTHON_VERSION=3 -DPYTHON_EXECUTABLE=$(which python)"} - -export CC=/opt/homebrew/bin/gcc-13 # Modify as needed, commonly set to /usr/bin/gcc -export CXX=/opt/homebrew/bin/g++-13 # Modify as needed, commonly set to /usr/bin/g++ - -echo "Building KineticGas Release" - -[ ! -d "cpp/release" ] && mkdir cpp/release -cd cpp/release -cmake -DCMAKE_BUILD_TYPE=Release "${py_version}" .. -make -cd ../.. -echo "Copying binary to ${PWD}/pykingas/KineticGas_r.so" -[ -f "pykingas/KineticGas_r.so" ] && rm pykingas/KineticGas_r.so -cp cpp/release/KineticGas_r.* pykingas/KineticGas_r.so \ No newline at end of file diff --git a/pykingas/__init__.py b/pykingas/__init__.py index 520c117..96ba81d 100644 --- a/pykingas/__init__.py +++ b/pykingas/__init__.py @@ -24,9 +24,9 @@ class bcolors: # For fancy (readable) printing during tests args = sys.argv if '-debug' in args or 'debug' in args or '-d' in args: - from . import KineticGas_d as __cpp_Module__ + from . import pykingas_d as __cpp_Module__ else: - from . import KineticGas_r as __cpp_Module__ + from . import pykingas as __cpp_Module__ # Expose everything in the __cpp_Module__ through the pykingas module for _attr in dir(__cpp_Module__): diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3a36c37 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,40 @@ +[build-system] +requires = ["scikit-build-core>=0.9.3", "pybind11"] +build-backend = "scikit_build_core.build" + + +[project] +name = "pykingas" +version = "2.0.0" +description="Revised Enskog theory for Mie fluids, and other spherical potentials. Allows prediction of transport coefficients such as diffusion coefficients, viscosities, thermal diffusion coefficients and thermal conductivities. In dense, multicomponent gas mixtures and supercritical mixtures." +readme = "README.md" +authors = [ + { name = "Vegard Gjeldvik Jervell", email = "vegard.g.j@icloud.com" }, +] +requires-python = ">=3.7" +classifiers = [ + "Development Status :: 4 - Beta", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] + +[project.optional-dependencies] +test = ["pytest"] + + +[tool.scikit-build] +wheel.expand-macos-universal-tags = true + + +[tool.cibuildwheel] +#test-command = "pytest {project}/tests" +#test-requires = ["pytest", "numpy~=1.22", "scipy~=1.7", "thermopack~=2.2"] +#test-extras = ["test"] +#test-skip = ["*universal2:arm64"] +build-verbosity = 1 \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 0dbe6a3..0000000 --- a/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -from setuptools import setup -from pathlib import Path - -this_dir = Path(__file__).parent -readme = (this_dir / 'pykingas/README.md').read_text() -setup( - name='pykingas', - version='2.0.0', - packages=['pykingas'], - package_data={'pykingas': ['KineticGas*', 'fluids/*']}, - description='Revised Enskog theory for Mie fluids, and other spherical potentials. Allows prediction of transport ' - 'coefficients such as diffusion coefficients, viscosities, thermal diffusion coefficients' - ' and thermal conductivities. In dense, multicomponent gas mixtures and supercritical mixtures.', - long_description=readme, - long_description_content_type='text/markdown', - author='Vegard Gjeldvik Jervell', - author_email='vegard.g.j@icloud.com', - url='https://github.com/thermotools/KineticGas', - install_requires=["numpy~=1.22", - "scipy~=1.7", - "thermopack~=2.1"] -) \ No newline at end of file