fwitte / fluprodia

Fluid property diagrams
https://fluprodia.readthedocs.io
MIT License
27 stars 2 forks source link

Exception raised when initializing a FluidPropertyDiagram with Ammonia #7

Closed jfreissmann closed 1 year ago

jfreissmann commented 1 year ago

Issue description

When I try to initialize a FluidPropertyDiagram with Ammonia as the fluid, an exception is raised. The error occurs within the set_isoline_defaults method, while trying to update the AbstractState CoolProp-object created in the beginning of the initialization. The full exception trace back looks like the following:

Traceback (most recent call last):
  File "C:\...\test.py", line 273, in <module>
    diagram = FluidPropertyDiagram(fluid=fluid)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\Lib\site-packages\fluprodia\fluid_property_diagram.py", line 270, in __init__
    self.set_isoline_defaults()
  File "C:\...\Lib\site-packages\fluprodia\fluid_property_diagram.py", line 370, in set_isoline_defaults
    self.state.update(CP.PQ_INPUTS, self.p_trip + 1, 0)
  File "CoolProp\AbstractState.pyx", line 102, in CoolProp.CoolProp.AbstractState.update
  File "CoolProp\AbstractState.pyx", line 104, in CoolProp.CoolProp.AbstractState.update
ValueError: options.T is not valid in saturation_P_pure_1D_T

Anaylsis of the Issue

As the issue occurs at the initialization of the FluidPropertyDiagram , I wrote a simple test script to see if any other fluids raise the same exception or if other CoolProp aliases for Ammonia yield a different behavior.

from fluprodia import FluidPropertyDiagram
import json

fluids = [
    "R113", "R114", "R123", "R21", "R142b", "R124", "R365mfc", "SES36",
    "R245ca", "R245fa", "R152a", "R227ea", "R134a", "R1234ze(Z)", "R1234ze(E)",
    "R1234yf", "R1233zd(E)", "Pentane", "Butane", "Isobutane", "PROPYLEN",
    "NOVEC649", "DME", "H2O", "NH3", "R717", "AMMONIA", "ammonia"
    ]

test_results = dict()
for fluid in fluids:
    test_results[fluid] = dict()
    try:
        diagram = FluidPropertyDiagram(fluid=fluid)
        test_results[fluid]["status"] = "working"
    except ValueError as e:
        test_results[fluid]["status"] = "failed"
        test_results[fluid]["error"] = str(e)

with open("test_results.json", "w") as file:
    json.dump(test_results, file, indent=4)

As you can see in the result JSON file, all other tested fluids did not recreate the excpetion. Only Ammonia and all its aliases exhibit the erroneous behavior.

test_results.json

```JSON { "R113": { "status": "working" }, "R114": { "status": "working" }, "R123": { "status": "working" }, "R21": { "status": "working" }, "R142b": { "status": "working" }, "R124": { "status": "working" }, "R365mfc": { "status": "working" }, "SES36": { "status": "working" }, "R245ca": { "status": "working" }, "R245fa": { "status": "working" }, "R152a": { "status": "working" }, "R227ea": { "status": "working" }, "R134a": { "status": "working" }, "R1234ze(Z)": { "status": "working" }, "R1234ze(E)": { "status": "working" }, "R1234yf": { "status": "working" }, "R1233zd(E)": { "status": "working" }, "Pentane": { "status": "working" }, "Butane": { "status": "working" }, "Isobutane": { "status": "working" }, "PROPYLEN": { "status": "working" }, "NOVEC649": { "status": "working" }, "DME": { "status": "working" }, "H2O": { "status": "working" }, "NH3": { "status": "failed", "error": "options.T is not valid in saturation_P_pure_1D_T" }, "R717": { "status": "failed", "error": "options.T is not valid in saturation_P_pure_1D_T" }, "AMMONIA": { "status": "failed", "error": "options.T is not valid in saturation_P_pure_1D_T" }, "ammonia": { "status": "failed", "error": "options.T is not valid in saturation_P_pure_1D_T" } } ```

User specifications

OS: Windows 10 Virutal Environment through miniforge3 Python: 3.11.0 fluprodia: 1.6 (pip) CoolProp: 6.4.3.post1 (pip) numpy: 1.24.1 (conda) matplotlib: 3.6.2 (conda)

maltefritz commented 1 year ago

Hey @jfreissmann,

I am able to reproduce the error with the following specifications:

OS: Windows 11 Virutal Environment through Anaconda Python: 3.11.0 fluprodia: 1.6 (pip) CoolProp: 6.4.3.post1 (pip) numpy: 1.24.2 (pip) matplotlib: 3.7.0 (pip)

The error does not occur with an older enviroment using the following specification:

OS: Windows 11 Virutal Environment through Anaconda Python: 3.7.6 fluprodia: 1.3 (pip) CoolProp: 6.4.0 (pip) numpy: 1.19.2 (pip) matplotlib: 3.5.3 (pip)

I hope it helps. To solve the error, it needs further investigation.

fwitte commented 1 year ago

So a CoolProp issue is likely?

jfreissmann commented 1 year ago

So a CoolProp issue is likely?

Very likely. I could get the initialization running with CoolProp version 6.4.0 on my system. Unfurtunately, this version is only available for python versions up to 3.8. Also, we still have no clue what is causing this issue in the first place.

fwitte commented 1 year ago

Closed as resolved with the latest version release