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 ------------------------------- 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 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,)) 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/include/iapws_r283.h b/include/iapws_r283.h index 8242174..0165a83 100644 --- a/include/iapws_r283.h +++ b/include/iapws_r283.h @@ -12,13 +12,13 @@ #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 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 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); 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) + 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 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