From 0da0f97857515ad070bf0d0b136a606f2c4f5e24 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 08:53:20 +0100 Subject: [PATCH 01/10] TST: Remove temporary tests for R797. --- fpm.toml | 6 +++--- test/{test_r797.f90 => test_r797.f90.txt} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename test/{test_r797.f90 => test_r797.f90.txt} (100%) diff --git a/fpm.toml b/fpm.toml index 5aa76be..47ac18d 100644 --- a/fpm.toml +++ b/fpm.toml @@ -39,6 +39,6 @@ main = "test_g704.f90" name = "test_g704_capi" main = "test_g704_capi.c" -[[test]] -name = "test_r797" -main = "test_r797.f90" \ No newline at end of file +# [[test]] +# name = "test_r797" +# main = "test_r797.f90" \ No newline at end of file diff --git a/test/test_r797.f90 b/test/test_r797.f90.txt similarity index 100% rename from test/test_r797.f90 rename to test/test_r797.f90.txt From c403d0f6de865b70f3db0103b416ad445184875e Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 08:53:50 +0100 Subject: [PATCH 02/10] BUG: Fix names in pywrapper for r283. --- pywrapper/pyiapws/iapws_r283.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pywrapper/pyiapws/iapws_r283.c b/pywrapper/pyiapws/iapws_r283.c index 7f26136..448031f 100644 --- a/pywrapper/pyiapws/iapws_r283.c +++ b/pywrapper/pyiapws/iapws_r283.c @@ -45,10 +45,10 @@ PyMODINIT_FUNC PyInit_r283(void) Py_INCREF(v); v = PyFloat_FromDouble(iapws_r283_capi_rhoc_H2O); - PyDict_SetItemString(d, "rho_H2O", v); + PyDict_SetItemString(d, "rhoc_H2O", v); Py_INCREF(v); v = PyFloat_FromDouble(iapws_r283_capi_rhoc_D2O); - PyDict_SetItemString(d, "rho_D2O", v); + PyDict_SetItemString(d, "rhoc_D2O", v); Py_INCREF(v); From ccf4b3eb194747466c5da483604993c509e4d39b Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 08:54:22 +0100 Subject: [PATCH 03/10] TST: Add tests for R283 and minor refractoring for G704. --- pywrapper/pyiapws/tests/test_g704.py | 12 +++++----- pywrapper/pyiapws/tests/test_r283.py | 35 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 pywrapper/pyiapws/tests/test_r283.py diff --git a/pywrapper/pyiapws/tests/test_g704.py b/pywrapper/pyiapws/tests/test_g704.py index 77ff254..ae18d0a 100644 --- a/pywrapper/pyiapws/tests/test_g704.py +++ b/pywrapper/pyiapws/tests/test_g704.py @@ -1,4 +1,4 @@ -r"""Tests""" +r"""Tests G704.""" import unittest from .. import g704 import numpy as np @@ -6,8 +6,8 @@ T_KELVIN = 273.15 class TestkH(unittest.TestCase): - r"""Test pyiawps library.""" - def test_H2O(self): + r"""Test module G704 from pyiawps library.""" + def test_kh_H2O(self): T = np.asarray((300.0-T_KELVIN,)) m = g704.kh(T, "He", False) k = np.asarray(m) @@ -15,7 +15,7 @@ def test_H2O(self): expected = 2.6576 self.assertAlmostEqual(value, expected, places=4) - def test_D2O(self): + def test_kh_D2O(self): T = np.asarray((300.0-T_KELVIN,)) m = g704.kh(T, "He", True) k = np.asarray(m) @@ -26,7 +26,7 @@ def test_D2O(self): class TestkD(unittest.TestCase): r"""Test pyiawps library.""" - def test_H2O(self): + def test_kd_H2O(self): T = np.asarray((300.0-T_KELVIN,)) m = g704.kd(T, "He", False) k = np.asarray(m) @@ -34,7 +34,7 @@ def test_H2O(self): expected = 15.2250 self.assertAlmostEqual(value, expected, places=4) - def test_D2O(self): + def test_kd_D2O(self): T = np.asarray((300.0-T_KELVIN,)) m = g704.kd(T, "He", True) k = np.asarray(m) diff --git a/pywrapper/pyiapws/tests/test_r283.py b/pywrapper/pyiapws/tests/test_r283.py new file mode 100644 index 0000000..a79ac1c --- /dev/null +++ b/pywrapper/pyiapws/tests/test_r283.py @@ -0,0 +1,35 @@ +r"""Test R283""" +import unittest +from .. import r283 + + +class TestH2O(unittest.TestCase): + r"""Test module r283 from pyiapws library.""" + def test_Tc_H2O(self): + expected = 647.096 + value = r283.Tc_H2O + self.assertAlmostEqual(value, expected, places=3) + def test_pc_H2O(self): + expected = 22.064 + value = r283.pc_H2O + self.assertAlmostEqual(value, expected, places=3) + def test_rhoc_H2O(self): + expected = 322.0 + value = r283.rhoc_H2O + self.assertAlmostEqual(value, expected, places=1) + +class TestD2O(unittest.TestCase): + r"""Test module r283 from pyiapws library.""" + def test_Tc_D2O(self): + expected = 643.847 + value = r283.Tc_D2O + self.assertAlmostEqual(value, expected, places=3) + def test_pc_D2O(self): + expected = 21.671 + value = r283.pc_D2O + self.assertAlmostEqual(value, expected, places=3) + def test_rhoc_D2O(self): + expected = 356.0 + value = r283.rhoc_D2O + self.assertAlmostEqual(value, expected, places=1) + From 53ab85efbca90343db41065c1352e94279e39f42 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 09:22:41 +0100 Subject: [PATCH 04/10] BLD: Fix list of python extensions in setup file. --- pywrapper/setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pywrapper/setup.py b/pywrapper/setup.py index c4b46aa..3be8846 100644 --- a/pywrapper/setup.py +++ b/pywrapper/setup.py @@ -23,18 +23,18 @@ if __name__ == "__main__": - mod_ext = Extension(name="pyiapws.g704", + mod_g704 = Extension(name="pyiapws.g704", sources=["./pyiapws/iapws_g704.c"], libraries=libraries, library_dirs=library_dirs, runtime_library_dirs=runtime_library_dirs, extra_objects=extra_objects) - mod_ext = Extension(name="pyiapws.r283", + mod_r283 = Extension(name="pyiapws.r283", sources=["./pyiapws/iapws_r283.c"], libraries=libraries, library_dirs=library_dirs, runtime_library_dirs=runtime_library_dirs, extra_objects=extra_objects) - setup(ext_modules=[mod_ext]) + setup(ext_modules=[mod_g704, mod_r283]) \ No newline at end of file From 28c591eab67c3d95fcf69204d05a33e7cc6c5642 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 09:22:56 +0100 Subject: [PATCH 05/10] DOC: Fix header 2 markers. --- documentation/sphinx/source/getting_started/examples.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/sphinx/source/getting_started/examples.rst b/documentation/sphinx/source/getting_started/examples.rst index 49544be..0b86397 100644 --- a/documentation/sphinx/source/getting_started/examples.rst +++ b/documentation/sphinx/source/getting_started/examples.rst @@ -3,20 +3,20 @@ Examples Example in Fortran -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +------------------------------------------ .. literalinclude:: ../../../../example/example_in_f.f90 :language: fortran Example in C -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +------------------------------------------ .. literalinclude:: ../../../../example/example_in_c.c :language: C Example in Python -^^^^^^^^^^^^^^^^^^^^^^ +------------------------------------------ .. literalinclude:: ../../../../example/example_in_py.py :language: python From d239ab75f281747be0b24d8c7688882d9783933c Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 09:23:48 +0100 Subject: [PATCH 06/10] BLD: Add support for MINGW32. --- include/iapws_r283.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/iapws_r283.h b/include/iapws_r283.h index 8242174..1675f59 100644 --- a/include/iapws_r283.h +++ b/include/iapws_r283.h @@ -6,7 +6,7 @@ #ifndef IAPWS_R283_H #define IAPWS_R283_H -#if _MSC_VER +#if _MSC_VER || __MINGW32__ || __MINGW64__ #define ADD_IMPORT __declspec(dllimport) #else #define ADD_IMPORT From 201501db5952fde29b5129e2f3dbd45ac9174ca7 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 11:44:31 +0100 Subject: [PATCH 07/10] BLD: Fix missing extern declaration for header r283. --- include/iapws_r283.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/iapws_r283.h b/include/iapws_r283.h index 1675f59..0165a83 100644 --- a/include/iapws_r283.h +++ b/include/iapws_r283.h @@ -6,19 +6,19 @@ #ifndef IAPWS_R283_H #define IAPWS_R283_H -#if _MSC_VER || __MINGW32__ || __MINGW64__ +#if _MSC_VER #define ADD_IMPORT __declspec(dllimport) #else #define ADD_IMPORT #endif -ADD_IMPORT const double iapws_r283_capi_Tc_H2O; -ADD_IMPORT const double iapws_r283_capi_Tc_D2O; +ADD_IMPORT extern const double iapws_r283_capi_Tc_H2O; +ADD_IMPORT extern const double iapws_r283_capi_Tc_D2O; -ADD_IMPORT const double iapws_r283_capi_pc_H2O; -ADD_IMPORT const double iapws_r283_capi_pc_D2O; +ADD_IMPORT extern const double iapws_r283_capi_pc_H2O; +ADD_IMPORT extern const double iapws_r283_capi_pc_D2O; -ADD_IMPORT const double iapws_r283_capi_rhoc_H2O; -ADD_IMPORT const double iapws_r283_capi_rhoc_D2O; +ADD_IMPORT extern const double iapws_r283_capi_rhoc_H2O; +ADD_IMPORT extern const double iapws_r283_capi_rhoc_D2O; #endif From fffb4e4cc71918a6766b283d7e80c00da300967b Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 12:23:47 +0100 Subject: [PATCH 08/10] ENH: Add examples for R283. --- example/example_in_c.c | 13 +++++++++++++ example/example_in_f.f90 | 11 +++++++++++ example/example_in_py.py | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/example/example_in_c.c b/example/example_in_c.c index fb47207..711fa6f 100644 --- a/example/example_in_c.c +++ b/example/example_in_c.c @@ -13,6 +13,19 @@ int main(void){ int i; int heavywater = 0; + printf("%s\n", "########################## IAPWS R2-83 ##########################"); + printf("%s %10.3f %s\n", "Tc in H2O", iapws_r283_capi_Tc_H2O, "K"); + printf("%s %10.3f %s\n", "pc in H2O", iapws_r283_capi_pc_H2O, "MPa"); + printf("%s %10.3f %s\n", "rhoc in H2O", iapws_r283_capi_rhoc_H2O, "kg/m3"); + + printf("%s %10.3f %s\n", "Tc in D2O", iapws_r283_capi_Tc_D2O, "K"); + printf("%s %10.3f %s\n", "pc in D2O", iapws_r283_capi_pc_D2O, "MPa"); + printf("%s %10.3f %s\n", "rhoc in D2O", iapws_r283_capi_rhoc_D2O, "kg/m3"); + + printf("\n"); + + + printf("%s\n", "########################## IAPWS R2-83 ##########################"); /* Compute kh and kd in H2O*/ iapws_g704_capi_kh(&T, gas, heavywater, &kh, strlen(gas), 1); printf("Gas=%s\tT=%fC\tkh=%+10.4f\n", gas, T, kh); diff --git a/example/example_in_f.f90 b/example/example_in_f.f90 index 71c0f06..438de68 100644 --- a/example/example_in_f.f90 +++ b/example/example_in_f.f90 @@ -9,6 +9,17 @@ program example_in_f type(iapws_g704_gas_t), pointer :: gases_list(:) character(len=:), pointer :: gases_str + print *, '########################## IAPWS R2-83 ##########################' + print "(a, f10.3, a)", "Tc in h2o=", iapws_r283_Tc_H2O, " k" + print "(a, f10.3, a)", "pc in h2o=", iapws_r283_pc_H2O, " mpa" + print "(a, f10.3, a)", "rhoc in h2o=", iapws_r283_rhoc_H2O, " kg/m3" + + print "(a, f10.3, a)", "Tc in D2O=", iapws_r283_tc_D2O, " k" + print "(a, f10.3, a)", "pc in D2O=", iapws_r283_pc_D2O, " mpa" + print "(a, f10.3, a)", "rhoc in D2O=", iapws_r283_rhoc_D2O, " kg/m3" + print *, '' + + print *, '########################## IAPWS G7-04 ##########################' ! Compute kh and kd in H2O T(1) = 25.0d0 call iapws_g704_kh(T, gas, heavywater, kh) diff --git a/example/example_in_py.py b/example/example_in_py.py index 8ff6afe..0bf3da0 100644 --- a/example/example_in_py.py +++ b/example/example_in_py.py @@ -2,6 +2,18 @@ import array import pyiapws +print("########################## IAPWS R2-83 ##########################") +print("Tc in H2O", pyiapws.r283.Tc_H2O, "K") +print("pc in H2O", pyiapws.r283.pc_H2O, "MPa") +print("rhoc in H2O", pyiapws.r283.rhoc_H2O, "kg/m3") + +print("Tc in D2O", pyiapws.r283.Tc_D2O, "K") +print("pc in D2O", pyiapws.r283.pc_D2O, "MPa") +print("rhoc in D2O", pyiapws.r283.rhoc_D2O, "kg/m3") + +print("") + +print("########################## IAPWS G7-04 ##########################") gas = "O2" T = array.array("d", (25.0,)) From 1659e11554f6f16c8c78f48289b47e2757686ae1 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 12:24:07 +0100 Subject: [PATCH 09/10] DOC: Add documentation for R283. --- documentation/sphinx/source/api/iapws.rst | 25 ++++++++++++++++++++- documentation/sphinx/source/api/pyiapws.rst | 9 ++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/documentation/sphinx/source/api/iapws.rst b/documentation/sphinx/source/api/iapws.rst index 06d2db4..b7dc75a 100644 --- a/documentation/sphinx/source/api/iapws.rst +++ b/documentation/sphinx/source/api/iapws.rst @@ -14,6 +14,19 @@ Fortran .. literalinclude:: ../../../../src/iapws_g704.f90 :language: Fortran + + IAPWS R283: Critical Constants + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + * `iapws_r283.f90`: Module for IAPWS R2-83 + + .. literalinclude:: ../../../../src/iapws_r283.f90 + :language: Fortran + + * `iapws_r283_capi.f90`: C API for IAPWS R2-83. + + .. literalinclude:: ../../../../src/iapws_r283_capi.f90 + :language: Fortran IAPWS G704: Gas solubilities ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +36,7 @@ Fortran .. literalinclude:: ../../../../src/iapws_g704.f90 :language: Fortran - * `iapws_g704_capi.f90`: C API for the IAPWS module. + * `iapws_g704_capi.f90`: C API for IAPWS G7-04. .. literalinclude:: ../../../../src/iapws_g704_capi.f90 :language: Fortran @@ -36,6 +49,16 @@ C .. literalinclude:: ../../../../include/iapws.h :language: C +.. _iapws_r283_capi: + +IAPWS R283: Critical Constants +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* `iapws_r283.h`: C header. + +.. literalinclude:: ../../../../include/iapws_r283.h + :language: C + IAPWS G704: Gas solubilities ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/documentation/sphinx/source/api/pyiapws.rst b/documentation/sphinx/source/api/pyiapws.rst index f9c12be..ae2e269 100644 --- a/documentation/sphinx/source/api/pyiapws.rst +++ b/documentation/sphinx/source/api/pyiapws.rst @@ -1,6 +1,15 @@ pyipaws ================ +IAPWS R283: Critical Constants +---------------------------------- + +.. automodule:: pyiapws.r283 + :members: + +The constants are defined as in the :ref:`C header ` without +the prefix *iapws_r283_capi_*. + IAPWS G704: Gas solubilities ------------------------------- From 718c6e0bdd021418157a4fbebc7b4c32161f8bd6 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Mon, 27 Nov 2023 12:24:23 +0100 Subject: [PATCH 10/10] DOC: Add explanation for memory view. --- pywrapper/README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pywrapper/README.rst b/pywrapper/README.rst index 58c138b..9d96575 100644 --- a/pywrapper/README.rst +++ b/pywrapper/README.rst @@ -8,6 +8,9 @@ Python wrapper around the The Fortran library does not need to be installed, the python wrapper embeds all needed dependencies. On linux, you might have to install `libgfortran` if it is not distributed with your linux distribution. +All functions that operate on arrays, more precisely on objects with the buffer protocol, return memory views +in order to avoid compilation dependencies on 3rd party packages. + .. readme_inclusion_end