Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected interface to idealenthalpysingle #144

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions addon/pyTests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Python side Test-Suite for ThermoPack

* [Running tests](#running-tests)
* [Adding tests](#tools-for-adding-tests)
* [Test modules](#test-modules)

## Running tests
This directory contains test modules to be run with [`pytest`](https://docs.pytest.org/en/8.1.x/), which can be installed with
```bash
pip install pytest
```

To run the entire test suite,
```bash
pytest addon/pyTests/
```

To run a specific test module,
```bash
pytest addon/pyTests/my_module.py
```

To run a specific test function,
```bash
pytest addon/pyTests/my_module.py::my_function
```

## Tools for adding tests
The module `./tools.py` contains various utility methods and variables that can be convenient when writing new tests, such as
`check_eq(a, b, tol)`, and `ALL_EOS`, which can be convenient to use with `pytest.mark.parametrize`

## Test modules

* `test_issues.py` - Tests to ensure that previously resolved issues
16 changes: 16 additions & 0 deletions addon/pyTests/test_issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Test module to ensure that previously resolved issues remain resolved. Test functions are named test_issue_XXX, where XXX is
the number of the issue, or test_pr_YYY, where YYY is the number of the relevant PR if there is no issue to reference.

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 pytest import mark

@mark.parametrize('eos', ALL_CUBIC)
def test_pr_114(eos):
T = 300
eos = eos('ETOH,C2')
h1 = eos.idealenthalpysingle(1, T)
h2, dh = eos.idealenthalpysingle(1, T, dhdt=True)
assert check_eq(h1, h2)
23 changes: 23 additions & 0 deletions addon/pyTests/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from thermopack.cubic import SoaveRedlichKwong, SchmidtWensel, PengRobinson, PengRobinson78, PatelTeja, VanDerWaals
from thermopack.saftvrmie import saftvrmie
from thermopack.pcsaft import PCP_SAFT, SPC_SAFT
from thermopack.saftvrqmie import saftvrqmie
from thermopack.cpa import SRK_CPA, PR_CPA
from thermopack.quantum_cubic import qcubic
from thermopack.extended_csp import ext_csp
from thermopack.lee_kesler import lee_kesler
from thermopack.ljs_bh import ljs_bh
from thermopack.ljs_wca import ljs_uv, ljs_wca, ljs_wca_base
from thermopack.pets import pets
from thermopack.tcPR import tcPR

ALL_CUBIC = [SoaveRedlichKwong, SchmidtWensel, PengRobinson, PengRobinson78, PatelTeja, VanDerWaals, tcPR, lee_kesler,
qcubic]
ALL_SAFT = [saftvrmie, saftvrqmie, PCP_SAFT, SPC_SAFT]

# List of all eos that can be initialized with eos(comps), for easy use with pytest.mark.parametrize
ALL_NO_CPA = [*ALL_CUBIC, *ALL_SAFT, qcubic]
ALL_COMP_EOS = [*ALL_NO_CPA, SRK_CPA, PR_CPA]

def check_eq(a, b, tol=1e-10):
return abs(a - b) < tol
4 changes: 2 additions & 2 deletions addon/pycThermopack/thermopack/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ def idealenthalpysingle(self, temp, j, dhdt=None):
if not dhdt is None:
return_tuple += (dhdt_c[0], )

prop = utils.Property.from_return_tuple(return_tuple, (dhdt, False, False), 'tpn')
prop = utils.Property.from_return_tuple(return_tuple, (dhdt, None, None), 'tpn')
return prop.unpack()

def idealentropysingle(self,temp,press,j,dsdt=None,dsdp=None):
Expand Down Expand Up @@ -1585,7 +1585,7 @@ def idealentropysingle(self,temp,press,j,dsdt=None,dsdp=None):
if not dsdp is None:
return_tuple += (dsdp_c[0], )

prop = utils.Property.from_return_tuple(return_tuple, (dsdt, dsdp, False), 'tpn')
prop = utils.Property.from_return_tuple(return_tuple, (dsdt, dsdp, None), 'tpn')
return prop.unpack()

def set_standard_entropy(self, j, s0, reference_pressure="1BAR"):
Expand Down
3 changes: 1 addition & 2 deletions src/eos.f90
Original file line number Diff line number Diff line change
Expand Up @@ -847,13 +847,12 @@ end subroutine ideal_entropy_single
!>
!> \author MH, 2014-01
!----------------------------------------------------------------------
subroutine ideal_enthalpy_single(t,p,j,h,dhdt,dhdp)
subroutine ideal_enthalpy_single(t,j,h,dhdt,dhdp)
use ideal, only: Hideal_apparent, Cpideal_apparent
use eos_parameters, only: single_eos
implicit none
! Transferred variables
real, intent(in) :: t !< K - Temperature
real, intent(in) :: p !< Pa - Pressure
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
Expand Down