Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/MilanSkocic/iapws into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Nov 27, 2023
2 parents 16afa60 + 718c6e0 commit 8420831
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 24 deletions.
25 changes: 24 additions & 1 deletion documentation/sphinx/source/api/iapws.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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
Expand All @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
9 changes: 9 additions & 0 deletions documentation/sphinx/source/api/pyiapws.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
pyipaws
================

IAPWS R283: Critical Constants
----------------------------------

.. automodule:: pyiapws.r283
:members:

The constants are defined as in the :ref:`C header <iapws_r283_capi>` without
the prefix *iapws_r283_capi_*.

IAPWS G704: Gas solubilities
-------------------------------

Expand Down
6 changes: 3 additions & 3 deletions documentation/sphinx/source/getting_started/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions example/example_in_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions example/example_in_f.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions example/example_in_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,))

Expand Down
6 changes: 3 additions & 3 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
# [[test]]
# name = "test_r797"
# main = "test_r797.f90"
12 changes: 6 additions & 6 deletions include/iapws_r283.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions pywrapper/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pywrapper/pyiapws/iapws_r283.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
12 changes: 6 additions & 6 deletions pywrapper/pyiapws/tests/test_g704.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
r"""Tests"""
r"""Tests G704."""
import unittest
from .. import g704
import numpy as np

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)
value = np.log(k[0]/1000.0)
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)
Expand All @@ -26,15 +26,15 @@ 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)
value = np.log(k[0])
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)
Expand Down
35 changes: 35 additions & 0 deletions pywrapper/pyiapws/tests/test_r283.py
Original file line number Diff line number Diff line change
@@ -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)

6 changes: 3 additions & 3 deletions pywrapper/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

File renamed without changes.

0 comments on commit 8420831

Please sign in to comment.