diff --git a/.github/prerelease_bodyFile.md b/.github/prerelease_bodyFile.md new file mode 100644 index 00000000..7422b8e2 --- /dev/null +++ b/.github/prerelease_bodyFile.md @@ -0,0 +1,7 @@ +This release is automatically updated whenever a pull request is merged to `main`. + +For stable releases of `ThermoPack`, see releases named `vX.Y.Z`. + +To install this release, download and unzip the appropriate zip file, then install with `pip install thermopack -f wheel--/`, where `wheel--` is the directory created by unzipping the file. + +Documentation and user guides for the latest version are found at [thermotools.github.io/thermopack](thermotools.github.io/thermopack), but are likely not as well maintained as the documentation and guides for stable releases. \ No newline at end of file diff --git a/.github/scripts/before_windows_build.ps1 b/.github/scripts/before_windows_build.ps1 new file mode 100644 index 00000000..cf9e496a --- /dev/null +++ b/.github/scripts/before_windows_build.ps1 @@ -0,0 +1,17 @@ +#Set-PSDebug -Trace 1 +echo "Running before_build on windows ..." +mkdir build +echo "Created build dir ..." +cd build +echo "Moved into build dir ..." +cmake .. -G Ninja -DCMAKE_Fortran_COMPILER=ifort -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release +echo "cmake finished ..." +cmake --build . --config=Release --target install +echo "build finished ..." +# python -c "import sys; sys.path.insert(0, '../addon/pycThermopack'); import makescript; makescript.windows_make('v3')" +python ../addon/pycThermopack/map_platform_specifics.py --diffs=v3 --ifort=True +echo "--- pycThermopack contents ---" +dir ../addon/pycThermopack +echo "--- pycThermopack/thermopack contents ---" +dir ../addon/pycThermopack/thermopack +#Set-PSDebug -Off \ No newline at end of file diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml new file mode 100644 index 00000000..d0566c7d --- /dev/null +++ b/.github/workflows/cibuildwheel.yml @@ -0,0 +1,131 @@ +name: cibuildwheel + +on: [] + +jobs: + build_wheels: + name: Build ${{ matrix.tp_version }} wheels on ${{ matrix.os }}-${{ matrix.version }} + runs-on: ${{ matrix.os }}-${{ matrix.version }} + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + os: [macOS, ubuntu, windows] + version: [latest] + tp_version: [v2, v3] + include: + - version: 12 + os: macOS + tp_version: v2 + - version: 12 + os: macOS + tp_version: v3 + + steps: + - uses: actions/checkout@v4 + - name: checkout submodules + run: git submodule update --init --recursive + + - name: Setup Linux env + if: matrix.os == 'ubuntu' + run: | + echo "gfortran=gfortran" >> $GITHUB_ENV + echo "libinspector=ls ../addon/pycThermopack/thermopack/libthermopack* | xargs ldd" >> $GITHUB_ENV + + - name: Setup macOS env + if: matrix.os == 'macOS' + run: | + echo "gfortran=$(which gfortran-13)" >> $GITHUB_ENV + echo "libinspector=otool -L ../addon/pycThermopack/thermopack/libthermopack*" >> $GITHUB_ENV + echo "MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion | cut -d '.' -f 1)" >> $GITHUB_ENV + + - name: Setup Windows env + if: matrix.os == 'windows' + uses: fortran-lang/setup-fortran@v1 + with: + compiler: intel-classic + version: '2021.12' + + - name: Check macOS deployment target + if: matrix.os == 'macOS' + run: echo "Deployment target version is ${{ env.MACOSX_DEPLOYMENT_TARGET }} / ${MACOSX_DEPLOYMENT_TARGET}" + + - name: Build wheel + uses: pypa/cibuildwheel@v2.19.2 # run: python -m cibuildwheel --output-dir wheelhouse + env: + CIBW_ARCHS: auto64 + CIBW_BEFORE_ALL_LINUX: | + yum install -y blas blas-devel + yum install -y lapack lapack-devel + + CIBW_BEFORE_BUILD_WINDOWS: powershell -ExecutionPolicy Bypass -File .github/scripts/before_windows_build.ps1 + + CIBW_BEFORE_BUILD: | + ${{ env.gfortran }} --version + export FC=${{ env.gfortran }} + mkdir build + cd build + cmake .. + make -j4 install + python ../addon/pycThermopack/map_platform_specifics.py --diffs=${{ matrix.tp_version }} + echo "--- pycThermopack contents ---" + ls ../addon/pycThermopack + echo "--- pycThermopack/thermopack contents ---" + ls ../addon/pycThermopack/thermopack + echo "--- Inspecting libthermopack ---" + ${{ env.libinspector }} + + CIBW_BUILD: "*cp311*" + CIBW_SKIP: "*musllinux*" + CIBW_TEST_SKIP: "*x86_64* thermopack-2*" + CIBW_BUILD_VERBOSITY: 1 + with: + package-dir: "./addon/pycThermopack" + output-dir: "./wheelhouse" + config-file: "{package}/pyproject.toml" + + - uses: actions/upload-artifact@v4 + with: + name: wheel-${{ matrix.tp_version }}-${{ matrix.os }}-${{ matrix.version }} + path: ./wheelhouse/*.whl + + release_wheels: # Create or update the release tagged Latest-beta, and upload wheels to that release. + name: Update prerelease + if: github.ref == 'refs/heads/main' + needs: build_wheels + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v3 + + - name: Download created wheels + uses: actions/download-artifact@v4 + with: + pattern: wheel-* + + - name: Display full directory status + run: ls -R . + + - name: zip wheels + run: | + for dir in wheel-*; do + zip -r "${dir}.zip" ${dir} + done + + - name: Display current directory status + run: ls + + - uses: ncipollo/release-action@v1 + with: + allowUpdates: true + prerelease: true + updateOnlyUnreleased: true + removeArtifacts: true + name: "Latest (beta)" + tag: Latest-beta + commit: main + makeLatest: true + bodyFile: ".github/prerelease_bodyFile.md" + artifacts: "wheel-*.zip" diff --git a/.github/workflows/dummy_build.yml b/.github/workflows/dummy_build.yml new file mode 100644 index 00000000..dce40870 --- /dev/null +++ b/.github/workflows/dummy_build.yml @@ -0,0 +1,25 @@ +name: Dummy Build + +on: + push: + branches: + - main + pull_request: + +jobs: + build_wheels: + if: github.ref == 'refs/heads/main' || github.event_name != 'push' + name: Dummy build + runs-on: ubuntu-latest + steps: + - name: Build + run: echo "Building ... but not a PR" + + release_wheels: + name: Dummy release + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - name: Release + run: echo "Releasing ..." + diff --git a/.github/workflows/dummy_test.yml b/.github/workflows/dummy_test.yml new file mode 100644 index 00000000..0f0cdfc1 --- /dev/null +++ b/.github/workflows/dummy_test.yml @@ -0,0 +1,15 @@ +name: Dummy Test + +on: + push: + branches: + - main + pull_request: + +jobs: + run_tests: + name: Dummy test + runs-on: ubuntu-latest + steps: + - name: Test + run: echo "Testing ..." \ No newline at end of file diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml new file mode 100644 index 00000000..8beb8f4c --- /dev/null +++ b/.github/workflows/unittests.yml @@ -0,0 +1,187 @@ +name: unittests + +on: [] + +jobs: + run-tests: + name: Test on ${{ matrix.os }} with ${{ matrix.toolchain.compiler }} ${{ matrix.toolchain.version }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, macos-12] + toolchain: + - {compiler: gcc, version: 13} + include: + # - os: ubuntu-latest + # toolchain: {nvidia-hpc, version: '23.11'} + # - os: windows-2022 + # toolchain: {compiler: intel, version: '2024.1'} + - os: windows-2022 + toolchain: {compiler: intel-classic, version: '2021.12'} + # exclude: + # - os: windows-latest + # toolchain: {compiler: gcc, version: 13} + + steps: + - uses: actions/checkout@v4 + - name: checkout submodules + run: git submodule update --init --recursive + + # - name: Setup Visual Studio 2022 + # if: matrix.os == 'windows-2022' + # uses: microsoft/setup-msbuild@v1.0.2 + + - name: Install ninja-build tool + if: matrix.os == 'windows-2022' + uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 + + - uses: fortran-lang/setup-fortran@v1 + id: setup-fortran + if: matrix.os != 'macos-12' + with: + compiler: ${{ matrix.toolchain.compiler }} + version: ${{ matrix.toolchain.version }} + + - name: Setup gfortran macos-12 + if: matrix.os == 'macos-12' + run: | + export FC=$(which gfortran-13) + echo FC=$FC >> $GITHUB_ENV + + - name: Build ThermoPack + if: matrix.os != 'windows-2022' + run: | + mkdir build + cd build + cmake -Dtest=ON -DCMAKE_BUILD_TYPE=Debug .. + make -j4 install + + # - name: Build LAPACK Windows + # if: matrix.os == 'windows-2022' + # run: | + # cd external + # cd lapack + # cmake -B build -G Ninja -DCMAKE_Fortran_COMPILER=${{ env.FC }} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx + # cmake --build build --target install + + - name: Build ThermoPack Windows + if: ${{ runner.os == 'Windows' }} + run: | + echo "Building on ${{ matrix.os }}" + $FC = ${{ env.FC }} + $FC_PATH = $((Get-Command ${{ env.FC }} | Select-Object -ExpandProperty Path) -replace '\\', '/') + echo "Using compiler $env:FC / ${{ env.FC }}" + echo "Fortran compiler at: $(Get-Command ${{ env.FC }} | Select-Object -ExpandProperty Path) / $FC_PATH" + cmake -B build -G Ninja -DCMAKE_Fortran_COMPILER=${{ env.FC }} -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release + cmake --build build --config Release --target install --verbose + # cmake -B build -G "Visual Studio 17 2022" -DCMAKE_Fortran_COMPILER=${{ env.FC }} + + - name: Inspect thermopack Linux + if: ${{ runner.os == 'Linux' }} + run: | + echo "--- Inspecting libthermopack ---" + ldd installed/libthermopack.so + nm installed/libthermopack.so | grep " T " + echo "--- Inspecting run_unittests ---" + ldd installed/unittests + + - name: Inspect thermopack MacOS + if: ${{ runner.os == 'macOS' }} + run: | + echo "--- Inspecting libthermopack ---" + otool -L installed/libthermopack.dylib + nm installed/libthermopack.dylib | grep " T " + echo "--- Inspecting run_unittests ---" + otool -L installed/unittests + + - name: Inspect thermopack Windows + if: ${{ runner.os == 'Windows' }} + run: | + echo "--- Inspecting libthermopack.dll ---" + dumpbin /DEPENDENTS installed/libthermopack.dll + dumpbin /EXPORTS installed/libthermopack.dll + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: binary-${{ matrix.os }}-${{ matrix.toolchain.compiler }} + path: ./installed/* + + - id: fortran_test + name: Run unittests + if: matrix.os != 'windows-2022' + continue-on-error: true + run: | + result=$(./installed/unittests) + if echo "$result" | grep -q "OK"; then + statuscode=0 + else + statuscode=1 + fi + echo "$result" + echo "statuscode=$statuscode" >> $GITHUB_OUTPUT + exit $statuscode + + - uses: actions/setup-python@v5 + - id: python_test + name: Run python tests for Linux/MacOS + if: matrix.os != 'windows-2022' + continue-on-error: true + run: | + python addon/pycThermopack/map_platform_specifics.py + pip install addon/pycThermopack/[test] + pytest addon/pyTests + result=$(pytest addon/pyTests) + if echo "$result" | grep -q "FAILED"; then + statuscode=1 + else + statuscode=0 + fi + echo "$result" + echo "statuscode=$statuscode" >> $GITHUB_OUTPUT + exit $statuscode + + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - id: python_test_windows + name: Run python tests for Windows + if: matrix.os == 'windows-2022' + continue-on-error: true + run: | + python -m pip install --upgrade pip + pip install pytest numpy + python -c "import sys; sys.path.insert(0, './addon/pycThermopack'); import makescript; makescript.windows_make('v3')" + pip install ./addon/pycThermopack/[test] + $result = python -m pytest ./addon/pyTests + if ($result -match "FAILED") { + $statuscode = 1 + } else { + $statuscode = 0 + } + Write-Output $result + Add-Content -Path $env:GITHUB_OUTPUT -Value "statuscode=$statuscode" + exit $statuscode + + - name: Check success + if: matrix.os != 'windows-2022' + run: | + echo "Fortran test result : ${{ steps.fortran_test.outputs.statuscode }}" + echo "Python test result : ${{ steps.python_test.outputs.statuscode }}" + if [[ ${{ steps.fortran_test.outputs.statuscode }} -eq 0 ]] && [[ ${{ steps.python_test.outputs.statuscode }} -eq 0 ]]; then + exit 0 + else + exit 1 + fi + + - name: Check success Windows + if: matrix.os == 'windows-2022' + run: | + $statusCode = ${{ steps.python_test_windows.outputs.statuscode }} + Write-Host "Python test result: $statusCode" + if ($statusCode -eq 0) { + exit 0 + } else { + exit 1 + } diff --git a/.gitignore b/.gitignore index ae4e19d5..d7e3179f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ syntax: glob objects bin +installed/ build/ run* doc/dox.out @@ -54,4 +55,5 @@ venv/ venv* *.idea *.vscode -scripts/ \ No newline at end of file +scripts/ +!.github/scripts/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 86784bf3..15ec21ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ +cmake_minimum_required(VERSION 3.19) +project(ThermoPack LANGUAGES Fortran) + string(ASCII 27 Esc) set(ColorRed "${Esc}[31m") set(ColorBlue "${Esc}[34m") -cmake_minimum_required(VERSION 3.5) -project(ThermoPack LANGUAGES Fortran) - if(NOT MSVC) execute_process(COMMAND bash -c "arch" OUTPUT_VARIABLE PROC) set(tp_flags_common "-cpp -fPIC -fdefault-real-8 -fdefault-double-8 -frecursive -fopenmp -Wno-unused-function -Wno-unused-variable") @@ -29,7 +29,7 @@ if(NOT MSVC) endif() else() # Build using: cmake --build . --config Release - set(tp_flags_common "/nologo /fpp /fpe:0 /names:lowercase /assume:underscore /fp:precise /extend-source:132 /iface:cref") + set(tp_flags_common "/nologo /fpp /fpe:0 /names:lowercase /assume:underscore /fp:precise /extend-source:132 /iface:cref /Qdiag-disable:10448") set(tp_optim_flags "${tp_flags_common}") set(tp_debug_flags "${tp_flags_common} /check:bounds /traceback") endif() @@ -39,24 +39,6 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) endif() -# Set FORTRAN compile flags for thermopack and lapack -set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${tp_optim_flags}") -set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${tp_debug_flags}") - -if(MSVC) - if(POLICY CMP0077) - set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) - endif() - # Disable single/complex/complex16 as it is not used by thermopack - set(BUILD_SINGLE OFF) - set(BUILD_COMPLEX OFF) - set(BUILD_COMPLEX16 OFF) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/lapack) - # Add flags not comatible with lapack - set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} /real-size:64 ") - set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} /real-size:64 /warn:all,noexternal /check:all,noarg_temp_created,nopointers") -endif(MSVC) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src "thermopack") option(test "Build test suite" OFF) diff --git a/MSVStudio/thermopack.def b/MSVStudio/thermopack.def index 0fd55b70..402c2f4b 100644 --- a/MSVStudio/thermopack.def +++ b/MSVStudio/thermopack.def @@ -1,231 +1,231 @@ -; File generated by thermopack/addon/pyUtils/exports/export_list.py -; Time stamp: 2024-06-19T23:37:40.701514 -; @NAME@.def : Declares the module parameters. - -LIBRARY - -EXPORTS - thermopack_init_c - thermopack_pressure_c - thermopack_specific_volume_c - thermopack_tpflash_c - thermopack_uvflash_c - thermopack_hpflash_c - thermopack_spflash_c - thermopack_bubt_c - thermopack_bubp_c - thermopack_dewt_c - thermopack_dewp_c - thermopack_zfac_c - thermopack_enthalpy_c - thermopack_entropy_c - thermopack_wilsonk_c - thermopack_wilsonki_c - thermopack_getcriticalparam_c - thermopack_moleweight_c - thermopack_compmoleweight_c - thermopack_puresat_t_c - thermopack_entropy_tv_c - thermopack_twophase_dhdt_c - thermopack_guess_phase_c - thermopack_thermo_c - get_phase_flags_c - thermopack_getkij_ - thermopack_setkijandji_ - thermopack_getlij_ - thermopack_setlijandji_ - thermopack_gethvparam_ - thermopack_sethvparam_ - thermopack_getwsparam_ - thermopack_setwsparam_ - thermopack_get_volume_shift_parameters_ - thermopack_set_volume_shift_parameters_ - thermopack_set_alpha_corr_ - thermopack_set_beta_corr_ - binaryplot_mp_get_bp_term_ - binaryplot_mp_vllebinaryxy_ - binaryplot_mp_global_binary_plot_ - binaryplot_mp_threephaseline_ - compdata_mp_comp_index_active_ - compdata_mp_comp_name_active_ - compdata_mp_comp_structure_ - compdata_mp_get_ideal_cp_correlation_ - compdata_mp_set_ideal_cp_correlation_ - critical_mp_calccriticaltv_ - cubic_eos_mp_get_energy_constants_ - cubic_eos_mp_get_covolumes_ - eos_mp_specificvolume_ - eos_mp_zfac_ - eos_mp_thermo_ - eos_mp_entropy_ - eos_mp_enthalpy_ - eos_mp_compmoleweight_ - eos_mp_moleweight_ - eos_mp_getcriticalparam_ - eos_mp_ideal_enthalpy_single_ - eos_mp_ideal_entropy_single_ - eoslibinit_mp_init_thermo_ - eoslibinit_mp_init_cubic_ - eoslibinit_mp_init_cubic_pseudo_ - eoslibinit_mp_init_cpa_ - eoslibinit_mp_init_pcsaft_ - eoslibinit_mp_init_saftvrmie_ - eoslibinit_mp_init_quantum_cubic_ - eoslibinit_mp_init_tcpr_ - eoslibinit_mp_init_quantum_saftvrmie_ - eoslibinit_mp_init_extcsp_ - eoslibinit_mp_init_lee_kesler_ - eoslibinit_mp_init_multiparameter_ - eoslibinit_mp_init_pets_ - eoslibinit_mp_init_volume_translation_ - eoslibinit_mp_redefine_critical_parameters_ - eoslibinit_mp_init_lj_ - eoslibinit_mp_init_ljs_ - eoslibinit_mp_init_ideal_eos_ - eostv_mp_internal_energy_tv_ - eostv_mp_entropy_tv_ - eostv_mp_pressure_ - eostv_mp_thermo_tv_ - eostv_mp_enthalpy_tv_ - eostv_mp_free_energy_tv_ - eostv_mp_chemical_potential_tv_ - eostv_mp_virial_coefficients_ - eostv_mp_secondvirialcoeffmatrix_ - eostv_mp_binarythirdvirialcoeffmatrix_ - eostv_mp_entropy_tvp_ - eostv_mp_thermo_tvp_ - eostv_mp_enthalpy_tvp_ - fundamental_measure_theory_mp_fmt_energy_density_ - hardsphere_bmcsl_mp_calc_bmcsl_gij_fmt_ - ideal_mp_set_standard_entropy_ - ideal_mp_get_standard_entropy_ - ideal_mp_set_enthalpy_of_formation_ - ideal_mp_get_enthalpy_of_formation_ - isolines_mp_isobar_ - isolines_mp_isotherm_ - isolines_mp_isenthalp_ - isolines_mp_isentrope_ - joule_thompson_inversion_mp_map_jt_inversion_ - lj_splined_mp_ljs_bh_model_control_ - lj_splined_mp_ljs_bh_get_pure_params_ - lj_splined_mp_ljs_bh_set_pure_params_ - lj_splined_mp_calc_ai_reduced_ljs_ex_ - lj_splined_mp_ljs_bh_get_bh_diameter_div_sigma_ - lj_splined_mp_calc_ljs_wca_ai_tr_ - lj_splined_mp_ljs_uv_model_control_ - lj_splined_mp_ljs_wca_model_control_ - lj_splined_mp_ljs_wca_set_pure_params_ - lj_splined_mp_ljs_wca_get_pure_params_ - mut_solver_mp_solve_mu_t_ - mut_solver_mp_solve_lnf_t_ - mut_solver_mp_map_meta_isotherm_ - multipol_mp_fres_multipol_ - multipol_mp_multipol_model_control_ - pc_saft_nonassoc_mp_lng_ii_pc_saft_tvn_ - ph_solver_mp_setphtolerance_ - ph_solver_mp_twophasephflash_ - ps_solver_mp_twophasepsflash_ - saftvrmie_containers_mp_get_saftvrmie_eps_kij_ - saftvrmie_containers_mp_set_saftvrmie_eps_kij_ - saftvrmie_containers_mp_get_saftvrmie_sigma_lij_ - saftvrmie_containers_mp_set_saftvrmie_sigma_lij_ - saftvrmie_containers_mp_get_saftvrmie_lr_gammaij_ - saftvrmie_containers_mp_set_saftvrmie_lr_gammaij_ - saftvrmie_containers_mp_get_saftvrmie_pure_fluid_param_ - saftvrmie_containers_mp_set_saftvrmie_pure_fluid_param_ - saftvrmie_containers_mp_get_feynman_hibbs_order_ - saftvrmie_containers_mp_set_saftvrmie_mass_ - saftvrmie_containers_mp_set_saftvrmie_pure_fluid_deboer_ - saftvrmie_interface_mp_model_control_hs_ - saftvrmie_interface_mp_model_control_a1_ - saftvrmie_interface_mp_model_control_a2_ - saftvrmie_interface_mp_model_control_a3_ - saftvrmie_interface_mp_model_control_chain_ - saftvrmie_interface_mp_hard_sphere_reference_ - saftvrmie_interface_mp_set_temperature_cache_flag_ - saftvrmie_interface_mp_calc_saftvrmie_term_ - saft_interface_mp_printbinarymixturereportsaft_ - saft_interface_mp_print_cpa_report_ - saft_interface_mp_cpa_get_kij_ - saft_interface_mp_cpa_set_kij_ - saft_interface_mp_cpa_set_pure_params_ - saft_interface_mp_cpa_get_pure_params_ - saft_interface_mp_cpa_set_kij_ - saft_interface_mp_pc_saft_get_kij_ - saft_interface_mp_pc_saft_set_kij_asym_ - saft_interface_mp_calc_saft_dispersion_ - saft_interface_mp_calc_saft_chain_ - saft_interface_mp_calc_hard_sphere_diameter_ - saft_interface_mp_calc_hard_sphere_diameter_ij_ - saft_interface_mp_pc_saft_get_pure_params_ - saft_interface_mp_pc_saft_set_pure_params_ - saft_interface_mp_de_broglie_wavelength_ - saft_interface_mp_potential_ - saft_interface_mp_adjust_mass_to_specified_de_boer_parameter_ - saft_interface_mp_de_boer_parameter_ - saft_interface_mp_calc_soft_repulsion_ - saft_interface_mp_pets_get_pure_params_ - saft_interface_mp_pets_set_pure_params_ - saft_interface_mp_truncation_corrections_ - saft_interface_mp_calc_saft_hard_sphere_ - saft_interface_mp_test_fmt_compatibility_ - saft_interface_mp_setcpaformulation_ - saft_interface_mp_get_n_assoc_sites_ - saft_interface_mp_calc_assoc_phi_ - saft_interface_mp_calc_saft_dispersion_ - saft_interface_mp_calc_hard_sphere_diameter_ - saft_interface_mp_pc_saft_get_pure_params_ - saft_interface_mp_pc_saft_set_pure_params_ - saft_interface_mp_de_broglie_wavelength_ - saft_interface_mp_sigma_ij_ - saft_interface_mp_epsilon_ij_ - saft_interface_mp_sigma_eff_ij_ - saft_interface_mp_epsilon_eff_ij_ - saft_interface_mp_alpha_ - saft_interface_mp_getactiveassocparams_ - saft_interface_mp_setactiveassocparams_ - spinodal_mp_map_stability_limit_ - spinodal_mp_initial_stab_limit_point_ - spinodal_mp_map_meta_isentrope_ - spinodal_mp_tv_meta_ps_ - saturation_mp_safe_bubt_ - saturation_mp_safe_bubp_ - saturation_mp_safe_dewt_ - saturation_mp_safe_dewp_ - saturation_curve_mp_envelopeplot_ - saturation_curve_mp_envelope_isentrope_cross_ - saturation_curve_mp_pure_fluid_saturation_wrapper_ - saturation_point_locators_mp_locate_saturation_property_ - saturation_point_locators_mp_property_index_from_string_ - saturation_point_locators_mp_sat_points_based_on_prop_ - solideos_mp_solid_init_ - solideos_mp_solid_specificvolume_ - solideos_mp_solid_enthalpy_ - solideos_mp_solid_entropy_ - solid_saturation_mp_solidenvelopeplot_ - solid_saturation_mp_melting_pressure_correlation_ - solid_saturation_mp_sublimation_pressure_correlation_ - speed_of_sound_mp_sound_velocity_2ph_ - speed_of_sound_mp_speed_of_sound_tv_ - thermo_utils_mp_guessphase_ - thermopack_constants_mp_get_true_ - thermopack_var_mp_set_numerical_robustness_level_ - thermopack_var_mp_get_numerical_robustness_level_ - thermopack_var_mp_get_rgas_ - thermopack_var_mp_set_tmin_ - thermopack_var_mp_get_tmin_ - thermopack_var_mp_set_tmax_ - thermopack_var_mp_get_tmax_ - thermopack_var_mp_set_pmin_ - thermopack_var_mp_get_pmin_ - thermopack_var_mp_set_pmax_ - thermopack_var_mp_get_pmax_ - thermopack_var_mp_set_pmin_ - thermopack_var_mp_get_pmin_ - thermopack_var_mp_add_eos_ - thermopack_var_mp_delete_eos_ - thermopack_var_mp_activate_model_ - thermopack_var_mp_get_eos_identification_ - tp_solver_mp_twophasetpflash_ - sv_solver_mp_twophasesvflash_ - uv_solver_mp_twophaseuvflash_ +; File generated by thermopack/addon/pyUtils/exports/export_list.py +; Time stamp: 2024-06-19T23:37:40.701514 +; @NAME@.def : Declares the module parameters. + +LIBRARY + +EXPORTS + thermopack_init_c + thermopack_pressure_c + thermopack_specific_volume_c + thermopack_tpflash_c + thermopack_uvflash_c + thermopack_hpflash_c + thermopack_spflash_c + thermopack_bubt_c + thermopack_bubp_c + thermopack_dewt_c + thermopack_dewp_c + thermopack_zfac_c + thermopack_enthalpy_c + thermopack_entropy_c + thermopack_wilsonk_c + thermopack_wilsonki_c + thermopack_getcriticalparam_c + thermopack_moleweight_c + thermopack_compmoleweight_c + thermopack_puresat_t_c + thermopack_entropy_tv_c + thermopack_twophase_dhdt_c + thermopack_guess_phase_c + thermopack_thermo_c + get_phase_flags_c + thermopack_getkij_ + thermopack_setkijandji_ + thermopack_getlij_ + thermopack_setlijandji_ + thermopack_gethvparam_ + thermopack_sethvparam_ + thermopack_getwsparam_ + thermopack_setwsparam_ + thermopack_get_volume_shift_parameters_ + thermopack_set_volume_shift_parameters_ + thermopack_set_alpha_corr_ + thermopack_set_beta_corr_ + binaryplot_mp_get_bp_term_ + binaryplot_mp_vllebinaryxy_ + binaryplot_mp_global_binary_plot_ + binaryplot_mp_threephaseline_ + compdata_mp_comp_index_active_ + compdata_mp_comp_name_active_ + compdata_mp_comp_structure_ + compdata_mp_get_ideal_cp_correlation_ + compdata_mp_set_ideal_cp_correlation_ + critical_mp_calccriticaltv_ + cubic_eos_mp_get_energy_constants_ + cubic_eos_mp_get_covolumes_ + eos_mp_specificvolume_ + eos_mp_zfac_ + eos_mp_thermo_ + eos_mp_entropy_ + eos_mp_enthalpy_ + eos_mp_compmoleweight_ + eos_mp_moleweight_ + eos_mp_getcriticalparam_ + eos_mp_ideal_enthalpy_single_ + eos_mp_ideal_entropy_single_ + eoslibinit_mp_init_thermo_ + eoslibinit_mp_init_cubic_ + eoslibinit_mp_init_cubic_pseudo_ + eoslibinit_mp_init_cpa_ + eoslibinit_mp_init_pcsaft_ + eoslibinit_mp_init_saftvrmie_ + eoslibinit_mp_init_quantum_cubic_ + eoslibinit_mp_init_tcpr_ + eoslibinit_mp_init_quantum_saftvrmie_ + eoslibinit_mp_init_extcsp_ + eoslibinit_mp_init_lee_kesler_ + eoslibinit_mp_init_multiparameter_ + eoslibinit_mp_init_pets_ + eoslibinit_mp_init_volume_translation_ + eoslibinit_mp_redefine_critical_parameters_ + eoslibinit_mp_init_lj_ + eoslibinit_mp_init_ljs_ + eoslibinit_mp_init_ideal_eos_ + eostv_mp_internal_energy_tv_ + eostv_mp_entropy_tv_ + eostv_mp_pressure_ + eostv_mp_thermo_tv_ + eostv_mp_enthalpy_tv_ + eostv_mp_free_energy_tv_ + eostv_mp_chemical_potential_tv_ + eostv_mp_virial_coefficients_ + eostv_mp_secondvirialcoeffmatrix_ + eostv_mp_binarythirdvirialcoeffmatrix_ + eostv_mp_entropy_tvp_ + eostv_mp_thermo_tvp_ + eostv_mp_enthalpy_tvp_ + fundamental_measure_theory_mp_fmt_energy_density_ + hardsphere_bmcsl_mp_calc_bmcsl_gij_fmt_ + ideal_mp_set_standard_entropy_ + ideal_mp_get_standard_entropy_ + ideal_mp_set_enthalpy_of_formation_ + ideal_mp_get_enthalpy_of_formation_ + isolines_mp_isobar_ + isolines_mp_isotherm_ + isolines_mp_isenthalp_ + isolines_mp_isentrope_ + joule_thompson_inversion_mp_map_jt_inversion_ + lj_splined_mp_ljs_bh_model_control_ + lj_splined_mp_ljs_bh_get_pure_params_ + lj_splined_mp_ljs_bh_set_pure_params_ + lj_splined_mp_calc_ai_reduced_ljs_ex_ + lj_splined_mp_ljs_bh_get_bh_diameter_div_sigma_ + lj_splined_mp_calc_ljs_wca_ai_tr_ + lj_splined_mp_ljs_uv_model_control_ + lj_splined_mp_ljs_wca_model_control_ + lj_splined_mp_ljs_wca_set_pure_params_ + lj_splined_mp_ljs_wca_get_pure_params_ + mut_solver_mp_solve_mu_t_ + mut_solver_mp_solve_lnf_t_ + mut_solver_mp_map_meta_isotherm_ + multipol_mp_fres_multipol_ + multipol_mp_multipol_model_control_ + pc_saft_nonassoc_mp_lng_ii_pc_saft_tvn_ + ph_solver_mp_setphtolerance_ + ph_solver_mp_twophasephflash_ + ps_solver_mp_twophasepsflash_ + saftvrmie_containers_mp_get_saftvrmie_eps_kij_ + saftvrmie_containers_mp_set_saftvrmie_eps_kij_ + saftvrmie_containers_mp_get_saftvrmie_sigma_lij_ + saftvrmie_containers_mp_set_saftvrmie_sigma_lij_ + saftvrmie_containers_mp_get_saftvrmie_lr_gammaij_ + saftvrmie_containers_mp_set_saftvrmie_lr_gammaij_ + saftvrmie_containers_mp_get_saftvrmie_pure_fluid_param_ + saftvrmie_containers_mp_set_saftvrmie_pure_fluid_param_ + saftvrmie_containers_mp_get_feynman_hibbs_order_ + saftvrmie_containers_mp_set_saftvrmie_mass_ + saftvrmie_containers_mp_set_saftvrmie_pure_fluid_deboer_ + saftvrmie_interface_mp_model_control_hs_ + saftvrmie_interface_mp_model_control_a1_ + saftvrmie_interface_mp_model_control_a2_ + saftvrmie_interface_mp_model_control_a3_ + saftvrmie_interface_mp_model_control_chain_ + saftvrmie_interface_mp_hard_sphere_reference_ + saftvrmie_interface_mp_set_temperature_cache_flag_ + saftvrmie_interface_mp_calc_saftvrmie_term_ + saft_interface_mp_printbinarymixturereportsaft_ + saft_interface_mp_print_cpa_report_ + saft_interface_mp_cpa_get_kij_ + saft_interface_mp_cpa_set_kij_ + saft_interface_mp_cpa_set_pure_params_ + saft_interface_mp_cpa_get_pure_params_ + saft_interface_mp_cpa_set_kij_ + saft_interface_mp_pc_saft_get_kij_ + saft_interface_mp_pc_saft_set_kij_asym_ + saft_interface_mp_calc_saft_dispersion_ + saft_interface_mp_calc_saft_chain_ + saft_interface_mp_calc_hard_sphere_diameter_ + saft_interface_mp_calc_hard_sphere_diameter_ij_ + saft_interface_mp_pc_saft_get_pure_params_ + saft_interface_mp_pc_saft_set_pure_params_ + saft_interface_mp_de_broglie_wavelength_ + saft_interface_mp_potential_ + saft_interface_mp_adjust_mass_to_specified_de_boer_parameter_ + saft_interface_mp_de_boer_parameter_ + saft_interface_mp_calc_soft_repulsion_ + saft_interface_mp_pets_get_pure_params_ + saft_interface_mp_pets_set_pure_params_ + saft_interface_mp_truncation_corrections_ + saft_interface_mp_calc_saft_hard_sphere_ + saft_interface_mp_test_fmt_compatibility_ + saft_interface_mp_setcpaformulation_ + saft_interface_mp_get_n_assoc_sites_ + saft_interface_mp_calc_assoc_phi_ + saft_interface_mp_calc_saft_dispersion_ + saft_interface_mp_calc_hard_sphere_diameter_ + saft_interface_mp_pc_saft_get_pure_params_ + saft_interface_mp_pc_saft_set_pure_params_ + saft_interface_mp_de_broglie_wavelength_ + saft_interface_mp_sigma_ij_ + saft_interface_mp_epsilon_ij_ + saft_interface_mp_sigma_eff_ij_ + saft_interface_mp_epsilon_eff_ij_ + saft_interface_mp_alpha_ + saft_interface_mp_getactiveassocparams_ + saft_interface_mp_setactiveassocparams_ + spinodal_mp_map_stability_limit_ + spinodal_mp_initial_stab_limit_point_ + spinodal_mp_map_meta_isentrope_ + spinodal_mp_tv_meta_ps_ + saturation_mp_safe_bubt_ + saturation_mp_safe_bubp_ + saturation_mp_safe_dewt_ + saturation_mp_safe_dewp_ + saturation_curve_mp_envelopeplot_ + saturation_curve_mp_envelope_isentrope_cross_ + saturation_curve_mp_pure_fluid_saturation_wrapper_ + saturation_point_locators_mp_locate_saturation_property_ + saturation_point_locators_mp_property_index_from_string_ + saturation_point_locators_mp_sat_points_based_on_prop_ + solideos_mp_solid_init_ + solideos_mp_solid_specificvolume_ + solideos_mp_solid_enthalpy_ + solideos_mp_solid_entropy_ + solid_saturation_mp_solidenvelopeplot_ + solid_saturation_mp_melting_pressure_correlation_ + solid_saturation_mp_sublimation_pressure_correlation_ + speed_of_sound_mp_sound_velocity_2ph_ + speed_of_sound_mp_speed_of_sound_tv_ + thermo_utils_mp_guessphase_ + thermopack_constants_mp_get_true_ + thermopack_var_mp_set_numerical_robustness_level_ + thermopack_var_mp_get_numerical_robustness_level_ + thermopack_var_mp_get_rgas_ + thermopack_var_mp_set_tmin_ + thermopack_var_mp_get_tmin_ + thermopack_var_mp_set_tmax_ + thermopack_var_mp_get_tmax_ + thermopack_var_mp_set_pmin_ + thermopack_var_mp_get_pmin_ + thermopack_var_mp_set_pmax_ + thermopack_var_mp_get_pmax_ + thermopack_var_mp_set_pmin_ + thermopack_var_mp_get_pmin_ + thermopack_var_mp_add_eos_ + thermopack_var_mp_delete_eos_ + thermopack_var_mp_activate_model_ + thermopack_var_mp_get_eos_identification_ + tp_solver_mp_twophasetpflash_ + sv_solver_mp_twophasesvflash_ + uv_solver_mp_twophaseuvflash_ diff --git a/addon/pyTests/test_issues.py b/addon/pyTests/test_issues.py index 35c0c945..da43d781 100644 --- a/addon/pyTests/test_issues.py +++ b/addon/pyTests/test_issues.py @@ -5,12 +5,17 @@ When an issue is resolved, a test with code that triggered it before resolution should be added here. """ from tools import ALL_CUBIC, check_eq +from thermopack.platform_specifics import DIFFERENTIAL_RETURN_MODE from pytest import mark @mark.parametrize('eos', ALL_CUBIC) def test_pr_114(eos): T = 300 eos = eos('ETOH,C2') - h1 = eos.idealenthalpysingle(1, T) + if DIFFERENTIAL_RETURN_MODE == 'v3': + h1 = eos.idealenthalpysingle(1, T) + elif DIFFERENTIAL_RETURN_MODE == 'v2': + h1, = eos.idealenthalpysingle(1, T) + h2, dh = eos.idealenthalpysingle(1, T, dhdt=True) assert check_eq(h1, h2) \ No newline at end of file diff --git a/addon/pycThermopack/.gitignore b/addon/pycThermopack/.gitignore index e19f946a..f67aaaff 100644 --- a/addon/pycThermopack/.gitignore +++ b/addon/pycThermopack/.gitignore @@ -3,4 +3,5 @@ LICENSE* build/ thermopack/platform_specifics.py pyctp/platform_specifics.py -setup.py \ No newline at end of file +setup.py +!scripts/ \ No newline at end of file diff --git a/addon/pycThermopack/CMakeLists.txt b/addon/pycThermopack/CMakeLists.txt index e69de29b..2bb6f5c3 100644 --- a/addon/pycThermopack/CMakeLists.txt +++ b/addon/pycThermopack/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.16) +project(pycThermopack) + +option(RECOMPILE_THERMOPACK "Recompile thermopack?" OFF) +if(RECOMPILE_THERMOPACK) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. "thermopack") +endif() \ No newline at end of file diff --git a/addon/pycThermopack/install b/addon/pycThermopack/install deleted file mode 100755 index b12cae95..00000000 --- a/addon/pycThermopack/install +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python -# Support for python2 -from __future__ import print_function -import os -import sys -import shutil - - -# Setting some variables -IN_VIRTUALENV = hasattr(sys, 'real_prefix') -IS_ROOT = (os.getuid() == 0) -ROOT_DIR = os.getcwd() - -if IS_ROOT or IN_VIRTUALENV: - os.system('python setup.py install') - - # Cleaning up after installation. - shutil.rmtree(os.path.join(ROOT_DIR,'dist'), ignore_errors = True) - shutil.rmtree(os.path.join(ROOT_DIR,'build'), ignore_errors = True) - manifest_path = os.path.join(ROOT_DIR,'MANIFEST') - if os.path.isfile(manifest_path): - os.remove(manifest_path) - -else: - print("Please run as root or in a virtualenv") - - diff --git a/addon/pycThermopack/makescript.py b/addon/pycThermopack/makescript.py index c3de07b0..6fefddfd 100755 --- a/addon/pycThermopack/makescript.py +++ b/addon/pycThermopack/makescript.py @@ -7,54 +7,42 @@ import sys import warnings from pathlib import Path +from map_platform_specifics import VERSION_2, VERSION_3, pf_specifics_path import map_platform_specifics -VERSION_2 = '2.2.3' -VERSION_3 = '3.b0' - def windows_make(diffs): - if diffs == 'v2': - version = VERSION_2 - else: - version = VERSION_3 + if diffs != 'v2': diffs = 'v3' - pf_specifics = {} - pf_specifics["os_id"] = "win" - pf_specifics["prefix"] = "" - pf_specifics["module"] = "_mp_" - pf_specifics["postfix"] = "_" - pf_specifics["postfix_no_module"] = "_" - pf_specifics["dyn_lib"] = "thermopack.dll" + + pf_specifics = map_platform_specifics.get_platform_specifics_windows_ifort_whl() pf_specifics["diff_return_mode"] = diffs - pf_specifics_path = os.path.join(os.path.dirname(__file__), "thermopack", "platform_specifics.py") map_platform_specifics.write_platform_specifics_file(pf_specifics, pf_specifics_path) - map_platform_specifics.write_setup_file(f'v{version}') - map_platform_specifics.write_toml_file(version) + map_platform_specifics.set_toml_version(diffs) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("mode", type=str, help="optim or debug") - parser.add_argument("-diffs", default="v3", type=str, help="Old (v2) or new (> v2) return mode for differentials", ) + parser.add_argument("-diffs", default="v3", type=str, help="Old (v2) or new (> v2) return mode for differentials") + parser.add_argument("--install", action=argparse.BooleanOptionalAction, help="Install thermopack from thermopack/bin/dynamic?") args = parser.parse_args() mode = args.mode - # Glob to handle different OS suffixes - libthermo = list( - Path('../../bin/dynamic').glob(f'libthermopack_{mode}_gfortran*.*'))[0] + if args.install: + # Glob to handle different OS suffixes + libthermo = list( + Path('../../bin/dynamic').glob(f'libthermopack_{mode}_gfortran*.*'))[0] + + if not os.path.exists(libthermo): + print(f'{libthermo}does not exist. Have you compiled thermopack?') + sys.exit(1) - if not os.path.exists(libthermo): - print(f'{libthermo}does not exist. Have you compiled thermopack?') - sys.exit(1) + if os.path.exists("./thermopack/libthermopack"+libthermo.suffix): + os.remove("./thermopack/libthermopack"+libthermo.suffix) - if os.path.exists("./thermopack/libthermopack"+libthermo.suffix): - os.remove("./thermopack/libthermopack"+libthermo.suffix) + shutil.copy2(libthermo, "./thermopack/libthermopack"+libthermo.suffix) - shutil.copy2(libthermo, "./thermopack/libthermopack"+libthermo.suffix) - - pf_specifics_path = os.path.join(os.path.dirname( - __file__), "thermopack", "platform_specifics.py") pf_specifics = map_platform_specifics.get_platform_specifics_by_trial_and_error() if args.diffs == 'v2': @@ -62,28 +50,15 @@ def windows_make(diffs): elif args.diffs == 'v3': version = VERSION_3 else: - warnings.warn(f'-diffs={args.diffs} is not a valid value. Valid values are -diffs=[v2.1/v3], treating as -diffs=v3', + warnings.warn(f'-diffs={args.diffs} is not a valid value. Valid values are -diffs=[v2/v3], treating as -diffs=v3', Warning) version = VERSION_3 args.diffs = 'v3' - if args.diffs == 'v2': - warnings.warn('\033[93mYou are building ThermoPack to use the deprecated return pattern using tuples.\n' - 'Future versions of ThermoPack will return differentials using the `Differential` struct found in utils.py. ' - 'To build ThermoPack to use the new return pattern, run \n`python makescript.py [optim/debug]`\n' - 'For more information see PR#102 at https://github.com/thermotools/thermopack/pull/102\033[0m', DeprecationWarning) - else: - warnings.warn('\033[93mYou are building ThermoPack using the "new" return pattern (i.e. the Differential structs found ' - "in utils.py.) \nTHIS IS THE RECOMMENDED BUILD but I'm warning you because it is not backwards compatible.\n" - "The old return pattern will probably be discontinued in the future. To build " - 'ThermoPack with the "old" return pattern (using tuples) run \n`python makescript.py [optim/debug] -diffs=v2`\n\n' - 'For information on how to adapt old code to the new return pattern, see ' - 'PR#102 at https://github.com/thermotools/thermopack/pull/102\033[0m', Warning) + map_platform_specifics.warn_diff_version(args.diffs) pf_specifics['diff_return_mode'] = args.diffs map_platform_specifics.write_platform_specifics_file(pf_specifics, pf_specifics_path) + map_platform_specifics.set_toml_version(version) - map_platform_specifics.write_setup_file(f'v{version}') - map_platform_specifics.write_toml_file(version) - - print(f'\033[92mSuccessfully configured ThermoPack {version}\033[0m') \ No newline at end of file + print(f'\033[92mSuccessfully configured ThermoPack {version}\033[0m') diff --git a/addon/pycThermopack/map_platform_specifics.py b/addon/pycThermopack/map_platform_specifics.py index cbd4f13f..beeb1f6a 100644 --- a/addon/pycThermopack/map_platform_specifics.py +++ b/addon/pycThermopack/map_platform_specifics.py @@ -7,6 +7,8 @@ import sysconfig from datetime import datetime import os +import argparse +import warnings # GNU FORTRAN G_PREFIX = "__" @@ -74,19 +76,24 @@ def get_platform_specifics_by_trial_and_error(): platform_specifics["dyn_lib"] = "" dynlibs = ["libthermopack.so", "thermopack.dll", "libthermopack.dylib"] + thermopack_dir = path.join(path.dirname(__file__), "thermopack") + errors = [] for lib in dynlibs: - dyn_lib_path = path.join(path.dirname(__file__), "thermopack", lib) + dyn_lib_path = path.join(thermopack_dir, lib) try: tp = cdll.LoadLibrary(dyn_lib_path) - except OSError: - tp = None - #print(dyn_lib_path, tp) - if tp is not None: platform_specifics["dyn_lib"] = lib break + except OSError as err: + errors.append(err) + pass else: - raise FileNotFoundError(f'Could not locate ThermoPack binary! Tried ' - f'{[path.join(path.dirname(__file__), "thermopack", lib) for lib in dynlibs]}') + thermopack_contains = os.listdir(thermopack_dir) + load_errors = '\n\t'.join([str(err) for err in errors]) + raise FileNotFoundError(f'Could not load ThermoPack binary!\n' + f'Tried : {[path.join(thermopack_dir, lib) for lib in dynlibs]}.\n' + f'{thermopack_dir} contains files : {thermopack_contains}\n' + f'Errors when attempting to load :\n\t{load_errors}') prefixes = ["__", ""] moduletxt = ["_", "_MOD_", "_mp_"] postfixes = ["", "_"] @@ -159,74 +166,17 @@ def write_platform_specifics_file(pf_specifics, filename): f.write(line) f.write("\n") -def write_setup_file(version): - setup_contents = {'name': "'thermopack'", - 'version': f"'{version}'", - 'description': "'Python interface to thermopack'", - 'long_description': "'readme'", - 'long_description_content_type': "'text/markdown'", - 'author': "'Morten Hammer'", - 'author_email': "'morten.hammer@sintef.no'", - 'url': "'https://github.com/thermotools/thermopack'", - 'packages': "['thermopack']", - 'package_data': "{'thermopack':['*thermopack.*']}", - 'install_requires' : "['numpy~=1.0']"} - - with open(os.path.dirname(__file__) + '/setup.py', 'w') as file: - file.write(f"# This file was automatically generated using the function 'write_setup_file' in \n" - f"# {__file__} \n" - f"# Likely called from {os.path.dirname(__file__)}/makescript.py\n" - f"# Timestamp : {datetime.today().isoformat()}\n\n") - file.write("from distutils.core import setup\n" - "from pathlib import Path\n\n" - "root_dir = Path(__file__).parent # thermopack root directory\n" - "readme = (root_dir / 'README_pypi.md').read_text()\n\n") - file.write('setup(') - - for i, (k, v) in enumerate(setup_contents.items()): - if i > 0: - file.write(',') - file.write(f"{k}={v}\n\t") - - file.write(')\n') - -def write_toml_file(version): - contents = """[build-system] -requires = ["setuptools>=39.0"] -build-backend = "setuptools.build_meta" - -[project] -name = "thermopack" -version = \"""" + version + """\" -authors = [ - { name = "Morten Hammer", email="morten.hammer@ntnu.no" }, -] -maintainers = [ - { name = "Morten Hammer", email="morten.hammer@ntnu.no" }, - { name = "Vegard Gjeldvik Jervell", email="vegard.g.jervell@ntnu.no" }, -] -description = "Python interface to thermopack" -readme = "README_pypi.md" -requires-python = ">=3.6" -classifiers = [ - "Programming Language :: Python :: 3", - "Programming Language :: Fortran", - "Operating System :: MacOS", - "Operating System :: POSIX :: Linux", - "Operating System :: Microsoft :: Windows", - "License :: OSI Approved :: MIT License", -] -keywords = ["physics", "thermodynamics", "equations_of_state", "phase_equilibria", "SAFT"] - -[project.urls] -"Homepage" = "https://github.com/thermotools/thermopack" -"Bug Tracker" = "https://github.com/thermotools/thermopack/issues" - -[dependencies] -numpy = "^1.1" -""" - with open(f'{os.path.dirname(__file__)}/pyproject.toml', 'w') as file: - file.write(contents) +def set_toml_version(version): + contents = '' + with open(f'{os.path.dirname(__file__)}/pyproject.toml', 'r') as ifile: + line = ifile.readline() + while line: + if line == 'version = "0.0.0"\n': + line = f'version = "{version}"\n' + contents += line + line = ifile.readline() + with open(f'{os.path.dirname(__file__)}/pyproject.toml', 'w') as ofile: + ofile.write(contents) def get_platform_specifics_windows_ifort_whl(): pf_specifics = dict() @@ -235,12 +185,42 @@ def get_platform_specifics_windows_ifort_whl(): pf_specifics["module"] = "_mp_" pf_specifics["postfix"] = "_" pf_specifics["postfix_no_module"] = "_" - pf_specifics["dyn_lib"] = "thermopack.dll" - pf_specifics["diff_return_mode"] = "v2" + pf_specifics["dyn_lib"] = "libthermopack.dll" return pf_specifics - + +def warn_diff_version(diffs): + if diffs == 'v2': + warnings.warn('\033[93m\nYou are building ThermoPack to use the deprecated return pattern using tuples.\n' + 'Future versions of ThermoPack will return differentials using the `Differential` struct found in utils.py. ' + 'To build ThermoPack to use the new return pattern, run \n\n\t`python map_platform_specifics.py [--diffs=v3 --ifort=False]`\n' + 'For more information see PR#102 at https://github.com/thermotools/thermopack/pull/102\n\n' + 'For more information on configuration options run \n\n\t`python map_platform_specifics.py --help\n\n\033[0m', DeprecationWarning) + else: + warnings.warn('\033[93m\nYou are building ThermoPack using the "new" return pattern (i.e. the Differential structs found ' + "in utils.py.) \nTHIS IS THE RECOMMENDED BUILD but I'm warning you because it is not backwards compatible.\n" + "The old return pattern will probably be discontinued in the future. To build " + 'ThermoPack with the "old" return pattern (using tuples) run \n\n\t`python map_platform_specifics.py --diffs=v2 [--ifort=False]`\n\n' + 'For information on how to adapt old code to the new return pattern, see ' + 'PR#102 at https://github.com/thermotools/thermopack/pull/102\n\n' + 'For more information on configuration options run \n\n\t`python map_platform_specifics.py --help\n\n\033[0m', Warning) + if __name__ == "__main__": - pf_specifics_path = os.path.join(os.path.dirname( - __file__), "thermopack", "platform_specifics.py") - pf_specifics_ = get_platform_specifics_by_trial_and_error() + VERSION_2 = '2.2.4b0' + VERSION_3 = '3.b0' + + parser = argparse.ArgumentParser() + parser.add_argument('--diffs', default='v3', help="Old (v2) or new (v3) return mode for differentials (Default: v3)") + parser.add_argument('--ifort', default=False, help='Set to True if thermopack has been compiled with intel-fortran (Default: False)') + args = parser.parse_args() + + pf_specifics_path = os.path.join(os.path.dirname( __file__), "thermopack", "platform_specifics.py") + pf_specifics_ = get_platform_specifics_by_trial_and_error() if (args.ifort is False) else get_platform_specifics_windows_ifort_whl() + pf_specifics_['diff_return_mode'] = args.diffs + pf_specifics_['version'] = VERSION_2 if (args.diffs == 'v2') else VERSION_3 + + warn_diff_version(args.diffs) + write_platform_specifics_file(pf_specifics_, pf_specifics_path) + set_toml_version(pf_specifics_['version']) + + print(f'\033[92mSuccessfully configured ThermoPack {pf_specifics_["version"]}\033[0m') diff --git a/addon/pycThermopack/pyproject.toml b/addon/pycThermopack/pyproject.toml index 8bb46ac7..3a12935b 100644 --- a/addon/pycThermopack/pyproject.toml +++ b/addon/pycThermopack/pyproject.toml @@ -3,12 +3,16 @@ requires = ["scikit-build-core"] build-backend = "scikit_build_core.build" [tool.scikit-build] -sdist.include = ["libthermopack*"] +sdist.include = ["libthermopack*", "platform_specifics.py"] wheel.expand-macos-universal-tags = true +wheel.py-api = "py3" + +[tool.scikit-build.cmake.define] +RECOMPILE_THERMOPACK = {env="RECOMPILE_THERMOPACK", default="OFF"} [project] name = "thermopack" -version = "2.3b0" +version = "0.0.0" authors = [ { name = "Morten Hammer", email="morten.hammer@ntnu.no" }, ] @@ -35,6 +39,6 @@ dependencies = ["numpy~=1.20"] test = ["pytest"] [tool.cibuildwheel] -test-command = "pytest {project}/../pyTests" +test-command = "pytest {package}/../pyTests" test-requires = ["pytest"] build-verbosity = 2 \ No newline at end of file diff --git a/addon/pycThermopack/build_whl_linux_x86.sh b/addon/pycThermopack/scripts/build_whl_linux_x86.sh similarity index 100% rename from addon/pycThermopack/build_whl_linux_x86.sh rename to addon/pycThermopack/scripts/build_whl_linux_x86.sh diff --git a/addon/pycThermopack/build_whl_macOS_arm64.sh b/addon/pycThermopack/scripts/build_whl_macOS_arm64.sh similarity index 100% rename from addon/pycThermopack/build_whl_macOS_arm64.sh rename to addon/pycThermopack/scripts/build_whl_macOS_arm64.sh diff --git a/addon/pycThermopack/build_whl_macOS_x86.sh b/addon/pycThermopack/scripts/build_whl_macOS_x86.sh similarity index 100% rename from addon/pycThermopack/build_whl_macOS_x86.sh rename to addon/pycThermopack/scripts/build_whl_macOS_x86.sh diff --git a/addon/pycThermopack/build_whl_windows_amd64.bat b/addon/pycThermopack/scripts/build_whl_windows_amd64.bat similarity index 100% rename from addon/pycThermopack/build_whl_windows_amd64.bat rename to addon/pycThermopack/scripts/build_whl_windows_amd64.bat diff --git a/addon/pycThermopack/build_whl_windows_win32.bat b/addon/pycThermopack/scripts/build_whl_windows_win32.bat similarity index 100% rename from addon/pycThermopack/build_whl_windows_win32.bat rename to addon/pycThermopack/scripts/build_whl_windows_win32.bat diff --git a/addon/pycThermopack/debug_compile.sh b/addon/pycThermopack/scripts/debug_compile.sh similarity index 100% rename from addon/pycThermopack/debug_compile.sh rename to addon/pycThermopack/scripts/debug_compile.sh diff --git a/addon/pycThermopack/setup.cfg b/addon/pycThermopack/setup.cfg deleted file mode 100644 index 7cb85c34..00000000 --- a/addon/pycThermopack/setup.cfg +++ /dev/null @@ -1,13 +0,0 @@ - -[options] -packages = thermopack -python_requires = >=3.6 -install_requires = - numpy ~= 1.0 - -[options.package_data] -* = *.py, *thermopack.* - -[metadata] -license_files = - LICENSE* diff --git a/addon/pycThermopack/thermopack/__init__.py b/addon/pycThermopack/thermopack/__init__.py index afeb489d..e69de29b 100644 --- a/addon/pycThermopack/thermopack/__init__.py +++ b/addon/pycThermopack/thermopack/__init__.py @@ -1,40 +0,0 @@ -"""Initialization code for the thermopack package""" -from . import platform_specifics -from . import thermo -from . import cubic -from . import tcPR -from . import quantum_cubic -from . import cpa -from . import extended_csp -from . import saft -from . import pcsaft -from . import saftvrmie -from . import saftvrqmie -from . import plotutils -from . import utils -from . import multiparameter -from . import pets -from . import thermopack_state -from . import lee_kesler -from . import ljs_bh -from . import ljs_wca - -__all__ = ["platform_specifics", - "thermo", - "cubic", - "tcPR", - "quantum_cubic", - "cpa", - "saft", - "pcsaft", - "extended_csp", - "saftvrmie", - "saftvrqmie", - "plotutils", - "utils", - "multiparameter" - "pets", - "lee_kesler", - "thermopack_state", - "ljs_bh", - "ljs_wca"] diff --git a/docs/vCurrent/getting_started_cpp.md b/docs/vCurrent/getting_started_cpp.md index afab70d1..87b604c1 100644 --- a/docs/vCurrent/getting_started_cpp.md +++ b/docs/vCurrent/getting_started_cpp.md @@ -36,17 +36,33 @@ The header files you will need are found in `thermopack/addon/cppThermoPack/cppT # Including and linking ThermoPack +*Note:* Before including ThermoPack in your project, ensure that you have compiled and installed ThermoPack by following the instructions for [building with cmake](source_build.html). + An example `CMakeLists.txt` is found in `thermopack/addon/cppExamples`. In essence, all that is required to include ThermoPack is to add the following to your `CMakeLists.txt`: ```cmake -set(THERMOPACK_HEADERS "path/to/thermopack/addon/cppThermopack") -set(libthermopack_path "path/to/thermopack/addon/cppThermopack/libthermopack.[so/dylib]") +set(THERMOPACK_DIR "/path/to/thermopack") +find_library(THERMOPACK REQUIRED) + +add_executable( ) +add_library( ) +# etc. -target_link_libraries( ${libthermopack_path}) -target_include_directories( ${THERMOPACK_HEADERS}) +target_link_libraries( thermopack) # find_library ensures that the exported target "thermopack" is available +target_link_libraries( thermopack) +# etc. ``` -where `` is some target previously defined by a call to `add_executable`, `add_library`, etc. +The environment variable `THERMOPACK_DIR` can also be set using +```bash +export THERMOPACK_DIR=/path/to/thermopack +``` +and should point to the top-level directory of the thermopack-package (where `thermopack-config.cmake` is found). After the `find_library` command has been run, several convenience variables will have been defined: +* `THERMOPACK_INSTALLED` : `"TRUE"` if thermopack is installed, `"FALSE"` otherwise +* `THERMOPACK_ROOT` : Path to directory where `thermopack-config.cmake` was found +* `THERMOPACK_LIB` : Path to thermopack dynamic library +* `THERMOPACK_INCLUDE` : Path to thermopack C++ headers +* `thermopack` : Imported shared library target with headers (this is what you want to link to using `target_link_libraries`) # Library structure diff --git a/docs/vCurrent/source_build.md b/docs/vCurrent/source_build.md index a7452a92..c533e27a 100644 --- a/docs/vCurrent/source_build.md +++ b/docs/vCurrent/source_build.md @@ -5,6 +5,19 @@ title: Installing the latest version of ThermoPack permalink: /vcurrent/source_build.html --- +- [Using pip](#using-pip) +- [Installing from wheels](#installing-from-wheels) +- [Building from source](#building-from-source) + - [Prerequisites](#prerequisites) + - [CMake setup (macOS and Linux)](#cmake-setup-macos-and-linux) + - [CMake setup (Windows)](#cmake-setup-windows) +- [Legacy build system (without CMake)](#legacy-build-system-without-cmake) + - [Linux setup](#linux-setup) + - [MacOS setup](#macos-setup) + - [Windows setup](#windows-setup) + - [MSYS2/Mingw-W64 setup](#msys2mingw-w64-setup) + - [Docker setup](#docker-setup) + ## Using pip Thermopack has been compiled for Windows, Linux and macOS and made available on the [Python Package Index](https://pypi.org/project/thermopack/) (pypi), and can be @@ -16,6 +29,9 @@ pip3 install thermopack For documentation on the version available on pypi, refer to the appropriate version number in the sidebar. +## Installing from wheels +Pre-built wheels for the latest version of ThermoPack on GitHub are available for download [here](). Refer to the linked page for instructions on how to install packages directly from a python wheel. Please note that the latest version on GitHub may be less stable, tested, and well documented than the versions distributed on PyPI. + ## Building from source The following sections show how to fetch, compile and install Thermopack and the Python frontend pycThermopack. When things are properly installed, it may @@ -34,6 +50,62 @@ Studio](https://visualstudio.microsoft.com/vs/). A solution file is found in assuming that the Intel Fortran compiler is integrated with Microsoft Visual Studio. +For macOS and Linux, Lapack and Blas can likely be installed using `apt`, `brew`, or similar. For windows, Lapack will need to be built from source. The [CMake setup for Windows](#cmake-setup-windows) is configured to handle this automatically. + +### CMake setup (macOS and Linux) + +The `cmake`-based build system assumes that you have Lapack and gfortran installed, see above instructions for more on that. + +Build and install thermopack by running +```bash +mkdir build +cd build +cmake .. +make install +``` + +This will ensure that the thermopack dynamic library is properly installed to `thermopack/installed` and `thermopack/addon/pycThermopack/thermopack`. + +To set up the python wrapper, +```bash +python addon/pycThermopack/map_platform_specifics.py +pip install addon/pycThermopack/ +``` +this will generate the file `addon/pycThermopack/thermopack/platform_specifics.py` and install thermopack to your activated virtual environment. + +ThermoPack can be configured to return computed properties as either tuples (`v2`) or using the `Property` struct (`v3`), this is toggled with +the `-diffs` flag when running `map_platform_specifics.py` as +```bash +python map_platform_specifics.py -diffs=v2 # Use tuples +python map_platform_specifics.py -diffs=v3 # use Property +``` +the default value is `-diffs=v3`. + +### CMake setup (Windows) + +To compile thermopack (and Lapack) with intel fortran, run +``` +mkdir build +cd build +cmake .. -G Ninja -DCMAKE_Fortran_COMPILER=ifort -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release +cmake --build . --config=Release --target install +``` +Compile and install Lapack, and install the thermopack dynamic library to `thermopack/installed` and `thermopack/addon/pycThermopack/thermopack`. + +To configure and install the python-wrapper, run +``` +python addon/pycThermopack/map_platform_specifics.py +pip install addon/pycThermopack/ +``` + +*Note:* If your thermopack dynamic library is called `libthermopack.dll`, and not `thermopack.dll`, you will instead need to run +``` +python addon/pycThermopack/map_platform_specifics.py --ifort=True +pip install addon/pycThermopack/ +``` + +## Legacy build system (without CMake) + ### Linux setup The Thermopack source code is downloaded by cloning the library to your local computer. The following commands assume that you have a local installation of @@ -131,7 +203,4 @@ how to install pycThermopack for the MSYS2 environment. ### Docker setup See [addon/docker/README.md](https://github.com/thermotools/thermopack/tree/main/addon/docker) for -available Dockerfiles to run Thermopack with docker. - -### CMake setup -See [thermopack_cmake](https://github.com/morteham/thermopack_cmake) for prototype CMake scripts to compile Thermopack. \ No newline at end of file +available Dockerfiles to run Thermopack with docker. \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f1dc662..b6b655fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,7 @@ +# Set FORTRAN compile flags for thermopack and lapack +set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${tp_optim_flags}") +set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${tp_debug_flags}") + file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.f90) list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/thermopack.f90) set(TREND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../addon/trend_interface/include) @@ -5,30 +9,47 @@ set(TREND ${TREND_DIR}/trend_interface.f95) if(NOT MSVC) find_package(LAPACK REQUIRED) +else() + if(POLICY CMP0077) + set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) + endif() + # Disable single/complex/complex16 as it is not used by thermopack + set(BUILD_SINGLE OFF) + set(BUILD_COMPLEX OFF) + set(BUILD_COMPLEX16 OFF) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../external/lapack "lapack") + # Add flags not comatible with lapack + set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} /real-size:64 ") + set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} /real-size:64 /warn:all,noexternal /check:all,noarg_temp_created,nopointers") endif() -# Define the executable in terms of the source files add_library(libthermopack STATIC ${SOURCES}) if(MSVC) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") add_library(thermopack SHARED ${SOURCES}) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /libs:static /threads") + set_target_properties(thermopack PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dynamic OUTPUT_NAME libthermopack) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEF:${CMAKE_SOURCE_DIR}/MSVStudio/thermopack.def") + target_link_options(thermopack PRIVATE "/NODEFAULTLIB:libmmd" "/NODEFAULTLIB:MSVCRT" "/NODEFAULTLIB:libifcoremd" "/NODEFAULTLIB:svml_dispmd") else(MSVC) if(APPLE) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -exported_symbols_list ${CMAKE_SOURCE_DIR}/libthermopack_export.symbols") + # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -exported_symbols_list ${CMAKE_SOURCE_DIR}/libthermopack_export.symbols") else(APPLE) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/libthermopack_export.version") + # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/libthermopack_export.version") endif(APPLE) add_library(thermopack SHARED $) + set_target_properties(thermopack PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif(MSVC) - -set_target_properties(libthermopack PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +message(STATUS "Linker: ${CMAKE_LINKER}") +set_target_properties(libthermopack PROPERTIES + Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + OUTPUT_NAME thermopack_static) target_include_directories(libthermopack PUBLIC ${TREND_DIR}) -set_target_properties(thermopack PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + target_include_directories(thermopack PUBLIC ${TREND_DIR}) +install(TARGETS thermopack DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../installed/) +install(TARGETS libthermopack DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../installed/) install(TARGETS thermopack DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../addon/pycThermopack/thermopack) -install(TARGETS thermopack DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../addon/cppThermopack) add_executable(run_thermopack ${CMAKE_CURRENT_SOURCE_DIR}/thermopack.f90) target_include_directories(run_thermopack PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) @@ -37,6 +58,9 @@ if(NOT MSVC) target_link_libraries(thermopack ${LAPACK_LIBRARIES}) target_link_libraries(run_thermopack libthermopack ${LAPACK_LIBRARIES}) else() - target_link_libraries(thermopack PRIVATE lapack blas) + target_link_options(run_thermopack PRIVATE "/NODEFAULTLIB:MSVCRT") + target_link_libraries(thermopack PUBLIC lapack blas) target_link_libraries(run_thermopack libthermopack lapack blas) endif() + +install(TARGETS run_thermopack DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../installed/) diff --git a/src/eos.f90 b/src/eos.f90 index d0c5e2db..2e5a738e 100644 --- a/src/eos.f90 +++ b/src/eos.f90 @@ -847,7 +847,7 @@ end subroutine ideal_entropy_single !> !> \author MH, 2014-01 !---------------------------------------------------------------------- - subroutine ideal_enthalpy_single(t,j,h,dhdt,dhdp) + subroutine ideal_enthalpy_single(t,j,h,dhdt) use ideal, only: Hideal_apparent, Cpideal_apparent use eos_parameters, only: single_eos implicit none @@ -856,7 +856,6 @@ subroutine ideal_enthalpy_single(t,j,h,dhdt,dhdp) integer, intent(in) :: j !< Component index real, intent(out) :: h !< J/mol - Ideal enthalpy real, optional, intent(out) :: dhdt !< J/mol/K - Temperature differential of ideal enthalpy - real, optional, intent(out) :: dhdp !< J/mol/Pa - Pressure differential of ideal enthalpy ! Locals type(thermo_model), pointer :: act_mod_ptr class(base_eos_param), pointer :: act_eos_ptr @@ -892,9 +891,6 @@ subroutine ideal_enthalpy_single(t,j,h,dhdt,dhdp) write(*,*) 'EoSlib error in eos::idealEnthalpySingle: No such EoS libray:',act_mod_ptr%EosLib call stoperror('') end select - if (present(dhdp)) then - dhdp=0.0 - end if end subroutine ideal_enthalpy_single !---------------------------------------------------------------------- diff --git a/thermopack-config.cmake b/thermopack-config.cmake index 11b3a081..e778b434 100644 --- a/thermopack-config.cmake +++ b/thermopack-config.cmake @@ -8,7 +8,7 @@ message(STATUS "ThermoPack found at: ${CMAKE_CURRENT_LIST_DIR}") -set(THERMOPACK_LIB ${CMAKE_CURRENT_LIST_DIR}/addon/cppThermopack/libthermopack${CMAKE_SHARED_LIBRARY_SUFFIX}) +set(THERMOPACK_LIB ${CMAKE_CURRENT_LIST_DIR}/installed/libthermopack${CMAKE_SHARED_LIBRARY_SUFFIX}) set(THERMOPACK_ROOT ${CMAKE_CURRENT_LIST_DIR}) if(NOT EXISTS ${THERMOPACK_LIB}) @@ -18,6 +18,8 @@ if(NOT EXISTS ${THERMOPACK_LIB}) return() endif() +set(THERMOPACK_STATIC_LIB ${CMAKE_CURRENT_LIST_DIR}/installed/libthermopack${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(THERMOPACK_FOUND TRUE) set(THERMOPACK_INSTALLED TRUE) set(THERMOPACK_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/addon/cppThermopack) diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index e54361ae..a3b8d1fb 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -1,8 +1,17 @@ -set(CMAKE_Fortran_FLAGS ${tp_fortran_flags}) +set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${tp_optim_flags}") +set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${tp_debug_flags}") enable_testing() file(GLOB UNITTEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.pf) list(REMOVE_ITEM UNITTEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/test_trend.pf) add_pfunit_ctest(unittests TEST_SOURCES ${UNITTEST_SRC} LINK_LIBRARIES thermopack) -target_include_directories(unittests PRIVATE ${CMAKE_BINARY_DIR}/thermopack) \ No newline at end of file +target_include_directories(unittests PRIVATE ${CMAKE_BINARY_DIR}/thermopack) + +if (NOT MSVC AND NOT APPLE) + set_target_properties(unittests PROPERTIES + INSTALL_RPATH ${CMAKE_CURRENT_SOURCE_DIR}/../installed + INSTALL_RPATH_USE_LINK_PATH TRUE) +endif() + +install(TARGETS unittests DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../installed/) \ No newline at end of file diff --git a/unittests/README.md b/unittests/README.md index 51df9e94..658e8058 100644 --- a/unittests/README.md +++ b/unittests/README.md @@ -2,6 +2,23 @@ ## Compiling and Running tests +### With `cmake` + +The project is set up to search for `pFUnit` and use your installation if you have it installed. Set the environment variable `PFUNIT_DIR` before building if you have already installed `pFUnit`. If `pFUnit` is not found, the version of `pFUnit` under `external/pFUnit` will be built and used. + +Build and run unittests by executing + +```bash +mkdir build +cd build +cmake -Dtest=ON .. +make +./unittests/run_unittests +``` + +from the ThermoPack root directory (`..`). Note that the value of the `test` option is cached, so if you have previously built ThermoPack, you may need to clear the `CMakeCache.txt` in the build directory. + +### With only `make` The test-suite is set up and maintained to be compatible with the [`pFUnit` fork under the ThermoTools project](https://github.com/thermotools/pFUnit). To build the test suite you must first clone and build `pFUnit`. To compile the test-suite the environment variable `PFUNIT_DIR` must be set to the path of the directory containing the directories `PFUNIT-4.x` and `FARGPARSE-1.x`, where `x` is some subversion number. This corresponds to running