Skip to content

Commit

Permalink
Merge pull request #34 from thermotools/prep_merge
Browse files Browse the repository at this point in the history
New functionality
  • Loading branch information
vegardjervell authored Nov 8, 2024
2 parents f03d317 + d088835 commit 529cc57
Show file tree
Hide file tree
Showing 151 changed files with 18,269 additions and 2,939 deletions.
File renamed without changes.
44 changes: 33 additions & 11 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ jobs:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macOS-latest]

os: [windows-latest, macOS-latest, ubuntu-latest]
env:
THERMOPACK_DIR: thermopack-${{ matrix.os }}
THERMOPACK_DIR_WINDOWS: "D:/a/KineticGas/KineticGas/thermopack-windows-latest/thermopack-windows-latest"
THERMOPACK_URL: https://github.com/vegardjervell/thermopack/releases/download/Latest-beta
steps:
- uses: actions/checkout@v4
- name: checkout submodules
Expand All @@ -18,20 +22,38 @@ jobs:
# 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: Fetch Thermopack
if: matrix.os != 'windows-latest'
run: |
curl -L -o thermopack.zip ${{ env.THERMOPACK_URL }}/thermopack-${{ matrix.os }}.zip
unzip thermopack.zip
export THERMOPACK_DIR=${PWD}/${{ env.THERMOPACK_DIR }}/
curl -L -o thermopack_whl.zip ${{ env.THERMOPACK_URL }}/wheel-v2-${{ matrix.os }}.zip
unzip thermopack_whl.zip
pip install wheel-v2-${{ matrix.os }}/*
- name: Build sdist
run: pipx run build --sdist --outdir wheelhouse
if: runner.os == 'Windows'
- name: Fetch Thermopack (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Invoke-WebRequest -Uri "${{ env.THERMOPACK_URL }}/thermopack-${{ matrix.os }}.zip" -OutFile "thermopack.zip"
Expand-Archive -Path "thermopack.zip" -DestinationPath "${{ env.THERMOPACK_DIR }}"
$THERMOPACK_DIR = "${PWD}/${{ env.THERMOPACK_DIR }}/${{ env.THERMOPACK_DIR }}"
[System.Environment]::SetEnvironmentVariable("THERMOPACK_DIR", $THERMOPACK_DIR)
"$THERMOPACK_DIR=$THERMOPACK_DIR" | Out-File -FilePath $env:GITHUB_ENV -Append
Invoke-WebRequest -Uri "${{ env.THERMOPACK_URL }}/wheel-v2-${{ matrix.os }}.zip" -OutFile "thermopack_whl.zip"
Expand-Archive -Path "thermopack_whl.zip" -DestinationPath "wheel-v2-${{ matrix.os }}"
cd wheel-v2-${{ matrix.os }}
pip install (Get-ChildItem wheel-v2-windows-latest\*.whl).FullName
- name: Build wheels
uses: pypa/[email protected] # run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_ARCHS: auto64
CIBW_ARCHS_MACOS: "universal2"
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=11.0
CIBW_ENVIRONMENT_LINUX: CXXFLAGS='-fconcepts'
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=11.0 THERMOPACK_DIR=${PWD}/${{ env.THERMOPACK_DIR }}
CIBW_ENVIRONMENT_LINUX: CXXFLAGS='-fconcepts' THERMOPACK_DIR=${PWD}/${{ env.THERMOPACK_DIR }}
CIBW_ENVIRONMENT_WINDOWS: THERMOPACK_DIR=${{ env.THERMOPACK_DIR_WINDOWS}}
CIBW_BUILD_VERBOSITY_WINDOWS: 2
CIBW_SKIP: "*pypy* *pp* *cp36* *cp37* *musl*"
with:
Expand All @@ -56,7 +78,7 @@ jobs:
pattern: wheels-*

release_wheels: # Create or update the release tagged Latest-beta, and upload wheels to that release.
if: ${{ github.event.pull_request.merged }}
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: build_wheels
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -91,7 +113,7 @@ jobs:
tag: Latest-beta
commit: main
makeLatest: true
bodyFile: "release_bodyFile.md"
bodyFile: ".github/release_bodyFile.md"
artifacts: "wheels-*.zip"


85 changes: 85 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Run Tests
on: push

jobs:
test:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macOS-latest, macOS-12, ubuntu-latest, windows-latest]
env:
THERMOPACK_DIR: thermopack-${{ matrix.os }}
THERMOPACK_URL: https://github.com/vegardjervell/thermopack/releases/download/Latest-beta
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 thermopack
if: matrix.os != 'windows-latest'
run: |
curl -L -o thermopack.zip ${{ env.THERMOPACK_URL }}/thermopack-${{ matrix.os }}.zip
unzip thermopack.zip
export THERMOPACK_DIR=${PWD}/thermopack-${{ matrix.os }}/
curl -L -o thermopack_whl.zip ${{ env.THERMOPACK_URL }}/wheel-v2-${{ matrix.os }}.zip
unzip thermopack_whl.zip
pip install wheel-v2-${{ matrix.os }}/*
- name: Build KineticGas
if: matrix.os != 'windows-latest'
run: |
echo "THERMOPACK_DIR (GH_ENV) : ${{ env.THERMOPACK_DIR }} / (ENV) ${THERMOPACK_DIR}"
export THERMOPACK_DIR=${PWD}/${{ env.THERMOPACK_DIR }}
ls -R ${THERMOPACK_DIR}
mkdir build
cd build
cmake ..
make -j4 install
- name: Install thermopack Windows
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Invoke-WebRequest -Uri "${{ env.THERMOPACK_URL }}/wheel-v2-${{ matrix.os }}.zip" -OutFile "thermopack_whl.zip"
Expand-Archive -Path "thermopack_whl.zip" -DestinationPath "wheel-v2-${{ matrix.os }}"
cd wheel-v2-${{ matrix.os }}
pip install (Get-ChildItem wheel-v2-windows-latest\*.whl).FullName
- name: Build KineticGas Windows
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Invoke-WebRequest -Uri "${{ env.THERMOPACK_URL }}/thermopack-${{ matrix.os }}.zip" -OutFile "thermopack.zip"
Expand-Archive -Path "thermopack.zip" -DestinationPath "${{ env.THERMOPACK_DIR }}"
$THERMOPACK_DIR = "$PWD\${{ env.THERMOPACK_DIR }}\thermopack-${{ matrix.os }}"
[System.Environment]::SetEnvironmentVariable("THERMOPACK_DIR", $THERMOPACK_DIR)
ls -R ${THERMOPACK_DIR}
mkdir build
cd build
cmake ..
cmake --build . --config=Release --target install
- name: Build KineticGas Windows
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
pip install .
$THERMOPACK_DIR = "$PWD/${{ env.THERMOPACK_DIR }}"
mkdir build
cd build
cmake ..
cmake --build . --config=Release --target install
- name: Inspect libpykingas
if: matrix.os != 'ubuntu-latest' && matrix.os != 'windows-latest'
run: otool -L pykingas/libpykingas.*

- name: Run pytests
run: |
pip install .[test]
pytest tests/
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ venv/
venv*/
pypi_release/wheelhouse/*.whl
*__pycache__/
pypi_release/dist/

build/
pykingas/fluids/
pykingas.egg-info/
venv*
rebuild.sh
Expand All @@ -19,4 +21,5 @@ rebuild.sh
*.mplstyle
sandbox/*
sandbox/archive/*
*.so
*.so
*.dylib
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
[submodule "cpp/external/pybind11"]
path = cpp/external/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "cpp/external/json"]
path = cpp/external/json
url = https://github.com/nlohmann/json.git
[submodule "cpp/external/eigen"]
path = cpp/external/eigen
url = https://gitlab.com/libeigen/eigen.git
[submodule "cpp/external/autodiff"]
path = cpp/external/autodiff
url = https://github.com/autodiff/autodiff.git
[submodule "cpp/external/thermopack"]
path = cpp/external/thermopack
url = https://github.com/thermotools/thermopack.git
103 changes: 94 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,110 @@ cmake_minimum_required(VERSION 3.16)
cmake_policy(VERSION 3.12)
project(KineticGas LANGUAGES C CXX)

string(ASCII 27 Esc)
set(ColorDefault "${Esc}[0m")
set(ColorBlue "${Esc}[34m")
set(ColorYellow "${Esc}[93m")
set(ColorRed "${Esc}[31m")
set(ColorDefault "${Esc}[0m")

option(build "Recompile KineticGas?" ON) # If set to off, assumes that KineticGas is installed and does nothing. Useful in combination with pip
if(NOT build)
message(STATUS "Assuming KineticGas is already built and installed. Exiting ...")
message(STATUS "${ColorBlue}To disable this behaviour, clear the CMakeCache and re-run cmake.${ColorDefault}")
return()
endif()

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type specified, defaulting to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
endif()

SET(CMAKE_CXX_STANDARD 17)

# Find the module development requirements (requires FindPython from 3.17 or scikit-build-core's built-in backport)
set(Python_FIND_VIRTUALENV ONLY)

if(NOT MSVC)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter -Wno-sign-compare -pthread")
set(CMAKE_CXX_FLAGS "-Wfatal-errors -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter -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)

file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/*.cpp)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cpp/external)

set(JSON_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/external/json/include/)
set(EIGEN_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/external/eigen/)
set(AUTODIFF_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/external/autodiff)
set(PYBIND11_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/cpp/external/pybind11)

set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp)
file(GLOB COMMON_SRC ${SRC_DIR}/*.cpp)
list(REMOVE_ITEM COMMON_SRC ${SRC_DIR}/bindings.cpp ${SRC_DIR}/run_kineticgas.cpp)
list(APPEND COMMON_SRC ${SRC_DIR}/Integration/Integration.cpp)

if (DEFINED ENV{THERMOPACK_DIR})
set(THERMOPACK_DIR $ENV{THERMOPACK_DIR})
message(STATUS "Searching for thermopack in THERMOPACK_DIR: $ENV{THERMOPACK_DIR}")
else()
message(STATUS "THERMOPACK_DIR is not defined!")
set(THERMOPACK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp/external/thermopack)
message(STATUS "Setting THERMOPACK_DIR: ${THERMOPACK_DIR}")
endif()

find_package(THERMOPACK REQUIRED)
if(NOT THERMOPACK_INSTALLED)
message(STATUS "${ColorRed}ThermoPack was found, but is not installed. If you have installed ThermoPack,
set the environment variable 'THERMOPACK_DIR=</path/to/thermopack>' to help cmake find your installation.${ColorDefault}")
message(STATUS "${ColorBlue}Target 'thermopack' created from the files found at ${THERMOPACK_ROOT}.${ColorDefault}")
message(STATUS "${ColorBlue}Try Running `make install` to build and install thermopack, before re-running `cmake .. && make install` to build KineticGas.${ColorDefault}")
add_subdirectory(${THERMOPACK_ROOT}) # We need to build thermopack, because it has not been installed.
return() # Hoping that thermopack target has been created by thermopack, exiting ...
endif()

if(NOT DEFINED(FLUID_DIR))
set(FLUID_DIR "../fluids" CACHE STRING "Default search path for fluid files")
endif()
message(STATUS "Default search path for fluid files (relative to dynamic library): ${FLUID_DIR}")

option(purecpp "Build pure cpp lib" OFF)
if (purecpp)
message(STATUS "${ColorBlue}Generating C++ library targets. Run `cmake [-Dpurecpp=OFF] ..` to skip this target (you will need to clear the CMakeCache first).${ColorDefault}")
set(libTARGET kineticgas)
add_library(${libTARGET} SHARED ${COMMON_SRC})
target_include_directories(${libTARGET} PUBLIC ${JSON_INCLUDE} ${EIGEN_INCLUDE} ${AUTODIFF_INCLUDE})
target_compile_definitions(${libTARGET} PUBLIC "-DFLUID_DIR=${FLUID_DIR}")
target_link_libraries(${libTARGET} thermopack)
install(TARGETS ${libTARGET} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/lib)

set(runTARGET run_kineticgas)
add_executable(${runTARGET} ${SRC_DIR}/run_kineticgas.cpp)
target_link_libraries(${runTARGET} ${libTARGET})
else()
message(STATUS "${ColorYellow}Not generating C++ library targets. Run `cmake -Dpurecpp=ON ..` to generate these targets (you will need to clear the CMakeCache first).${ColorDefault}")
endif()

option(pylib "Build library for pykingas" ON)
if (pylib)
message(STATUS "${ColorBlue}Generating libpykingas target. Run `cmake -Dpylib=OFF ..` to skip this target (you will need to clear the CMakeCache first).${ColorDefault}")
set(pyTARGET libpykingas)
set(pykingas_path ${CMAKE_CURRENT_SOURCE_DIR}/pykingas)
add_subdirectory(${PYBIND11_ROOT})
pybind11_add_module(${pyTARGET} ${COMMON_SRC} ${SRC_DIR}/bindings.cpp)

if(NOT MSVC)
set_target_properties(${pyTARGET} PROPERTIES
INSTALL_RPATH ${THERMOPACK_ROOT}/installed
INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

project(pykingas)
set(TARGET libpykingas)
set(pyFLUID_DIR "./fluids" CACHE STRING "Default search path for fluid files (pykingas)")
message(STATUS "pykingas search path for fluids (relative to pykingas directory): ${pyFLUID_DIR}")

# Add a library using FindPython's tooling (pybind11 also provides a helper like this)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/cpp/external/pybind11")
pybind11_add_module(${TARGET} ${SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/cpp/Integration/Integration.cpp")
target_include_directories(${pyTARGET} PUBLIC ${JSON_INCLUDE} ${EIGEN_INCLUDE} ${AUTODIFF_INCLUDE})
target_link_libraries(${pyTARGET} PRIVATE thermopack)
target_compile_definitions(${pyTARGET} PUBLIC "-DPYLIB -DFLUID_DIR=${pyFLUID_DIR}")

# The install directory is the output (wheel) directory
install(TARGETS ${TARGET} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/pykingas)
install(TARGETS ${pyTARGET} DESTINATION ${pykingas_path})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/fluids DESTINATION ${pykingas_path})
endif()
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,12 @@ The `frame_of_reference` kwarg works as normal when setting `use_independent=Fal

A standalone C++ library, that does not depend upon the Python wrapper, is currently under development. See branches under `pure_cpp/` for the most up to date information on that.

# Advanced usage
---
layout: default
version:
title: Advanced usage
permalink: /vcurrent/advanced.html
---

## Modifying and adding fluids

Expand Down Expand Up @@ -542,7 +547,7 @@ Functionality making it simple to implement new potentials is at the core of `Ki

### Implementing the C++ side

All classes that inherit from `KineticGas` must implement the methods `omega`, which returns the collision integrals, the method `model_rdf`, which returns the radial distribution function at contact, and the method `get_contact_diameters`, which returns the collision diameters.
All classes that inherit from `KineticGas` must implement the methods `omega`, which returns the collision integrals, the method `model_rdf`, which returns the radial distribution function at contact, and the method `get_collision_diameters`, which returns the collision diameters.

Out of these, the `omega` method is implemented in the `Spherical` class which instead requires that inheritting classes implement the methods `potential`, `potential_derivative_r` and `potential_dblderivative_rr`, corresponding to the pair potential, and its first and second derivative wrt. distance.

Expand All @@ -551,13 +556,13 @@ The options for implementing a new potential are then
* Inherit `KineticGas`
* Implement `omega` (The collision integrals)
* Implement `model_rdf` (The radial distribution function at contact)
* Implement `get_contact_diameters` (The collision diameters)
* Implement `get_collision_diameters` (The collision diameters)
* Inherit `Spherical`
* Implement `potential` (The pair-potential)
* Implement `potential_derivative_r` (Derivative of the pair-potential)
* Implement `potential_dblderivative_rr` (Second derivative of the pair-potential)
* Implement `model_rdf` (The radial distribution function at contact)
* Implement `get_contact_diameters` (The collision diameters)
* Implement `get_collision_diameters` (The collision diameters)

### Implementing the Python side

Expand All @@ -574,7 +579,12 @@ class MyNewPotential(py_KineticGas)
self.eos = <Some ThermoPack EoS>(comps)
```

# Structure
---
layout: default
version:
title: Structure
permalink: /vcurrent/structure.html
---

See the [structure docs](https://github.com/thermotools/KineticGas/blob/main/docs/structure/structure.pdf) for more information.

Expand Down Expand Up @@ -626,7 +636,12 @@ Stuff is illustrated here as well:

`docs/` : Documentation

# Fluid identifiers
---
layout: default
version:
title: Fluid identifiers
permalink: /vcurrent/fluid_identifiers.html
---

*Note* : Many of these fluid parameters have been pulled directly from the [ThermoPack](https://github.com/thermotools/thermopack) fluid database for SAFT-VR Mie parameters. In the cases where SAFT-VR Mie uses segment numbers $>1$ to describe the fluids, the parameter sets cannot be expected to be suitable for use with RET-Mie.

Expand Down
Loading

0 comments on commit 529cc57

Please sign in to comment.