Code Monkey home page Code Monkey logo

fluprodia's People

Contributors

fwitte avatar jfreissmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cbkiyanda

fluprodia's Issues

Exception raised when initializing a FluidPropertyDiagram with Ammonia

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

{
    "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)

Triple point for abstract class - density out of range issue

I have some code that works great but I'm trying to add in some fluids that are mixtures and am now getting an error from within set_isoline_defaults.

My fluid is defined as:
self.state = CP.AbstractState('REFPROP','R1234yf&R134a'); self.state.set_mole_fractions([0.56,0.44])

And I get this error upon running:

File "/opt/miniconda3/envs/CondaHP/lib/python3.8/site-packages/fluprodia/fluid_property_diagram.py", line 360, in set_isoline_defaults
    self.p_trip = self.state.trivial_keyed_output(CP.iP_triple)
  File "CoolProp/AbstractState.pyx", line 227, in CoolProp.CoolProp.AbstractState.trivial_keyed_output
  File "CoolProp/AbstractState.pyx", line 229, in CoolProp.CoolProp.AbstractState.trivial_keyed_output
ValueError: [TQFLSH error 2] One or more inputs are out of range; Density above upper limit: D = 14.6560 mol/L, Dmax = 14.4635 mol/L.

this works fine when the state is defined as a single fluid:
self.state = CP.AbstractState('HEOS', self.fluid)

It looks like it's not a problem with any of my inputs but something to do with mixtures and triple points. Any ideas how I can get past this? Thanks!

Successful Build ARM64 Android Termux

Using Python 3.9
Modified setup.py to versions currently installed in my python

python_requires='>=3.9',
    install_requires=[
        'CoolProp>=6.4,<7',
        'matplotlib==3.6.0',
        'numpy==1.23.4'
    ]

& modified pyproject.toml

requires = [
    "setuptools==58.1.0",
    "wheel",
    "setuptools_scm==7.0.5",
]

Successful Build ARM64 Android Termux

Using Python 3.9
Modified setup.py to versions currently installed in my python

python_requires='>=3.9',
    install_requires=[
        'CoolProp>=6.4,<7',
        'matplotlib==3.6.0',
        'numpy==1.23.4'
    ]

& modified pyproject.toml

requires = [
    "setuptools==58.1.0",
    "wheel",
    "setuptools_scm==7.0.5",
]

cannot save diagram

Hi, whenever I try to save a diagram I get the following error:

---> [24](vscode-notebook-cell:/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/calculations.ipynb#X16sZmlsZQ%3D%3D?line=23) diagram.save('test.svg')

File [~\AppData\Roaming\Python\Python310\site-packages\fluprodia\fluid_property_diagram.py:500](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/fluprodia/fluid_property_diagram.py:500), in FluidPropertyDiagram.save(self, filename, **kwargs)
    498 self.ax.grid()
    499 plt.tight_layout()
--> 500 self.fig.savefig(filename, **kwargs)

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\figure.py:3058](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/figure.py:3058), in Figure.savefig(self, fname, transparent, **kwargs)
   3054     for ax in self.axes:
   3055         stack.enter_context(
   3056             ax.patch._cm_set(facecolor='none', edgecolor='none'))
-> 3058 self.canvas.print_figure(fname, **kwargs)

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\backend_bases.py:2319](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/backend_bases.py:2319), in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2315 try:
   2316     # _get_renderer may change the figure dpi (as vector formats
   2317     # force the figure dpi to 72), so we need to set it again here.
   2318     with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2319         result = print_method(
   2320             filename,
   2321             facecolor=facecolor,
   2322             edgecolor=edgecolor,
   2323             orientation=orientation,
   2324             bbox_inches_restore=_bbox_inches_restore,
   2325             **kwargs)
   2326 finally:
   2327     if bbox_inches and restore_bbox:

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\backend_bases.py:1648](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/backend_bases.py:1648), in _check_savefig_extra_args..wrapper(*args, **kwargs)
   1640     _api.warn_deprecated(
   1641         '3.3', name=name, removal='3.6',
   1642         message='%(name)s() got unexpected keyword argument "'
   1643                 + arg + '" which is no longer supported as of '
   1644                 '%(since)s and will become an error '
   1645                 '%(removal)s')
   1646     kwargs.pop(arg)
-> 1648 return func(*args, **kwargs)

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\_api\deprecation.py:389](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/_api/deprecation.py:389), in delete_parameter..wrapper(*inner_args, **inner_kwargs)
    384 @functools.wraps(func)
    385 def wrapper(*inner_args, **inner_kwargs):
    386     if len(inner_args) <= name_idx and name not in inner_kwargs:
    387         # Early return in the simple, non-deprecated case (much faster than
    388         # calling bind()).
--> 389         return func(*inner_args, **inner_kwargs)
    390     arguments = signature.bind(*inner_args, **inner_kwargs).arguments
    391     if is_varargs and arguments.get(name):

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\_api\deprecation.py:415](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/_api/deprecation.py:415), in delete_parameter..wrapper(*inner_args, **inner_kwargs)
    405     deprecation_addendum = (
    406         f"If any parameter follows {name!r}, they should be passed as "
    407         f"keyword, not positionally.")
    408     warn_deprecated(
    409         since,
    410         name=repr(name),
   (...)
    413                  else deprecation_addendum,
    414         **kwargs)
--> 415 return func(*inner_args, **inner_kwargs)

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\backends\backend_svg.py:1321](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/backends/backend_svg.py:1321), in FigureCanvasSVG.print_svg(self, filename, dpi, bbox_inches_restore, metadata, *args)
   1285 @_check_savefig_extra_args
   1286 @_api.delete_parameter("3.4", "dpi")
   1287 @_api.delete_parameter("3.5", "args")
   1288 def print_svg(self, filename, *args, dpi=None, bbox_inches_restore=None,
   1289               metadata=None):
   1290     """
   1291     Parameters
   1292     ----------
   (...)
   1319         __ DC_
   1320     """
-> 1321     with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh:
   1322         if not cbook.file_requires_unicode(fh):
   1323             fh = codecs.getwriter('utf-8')(fh)

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\cbook\__init__.py:465](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/cbook/__init__.py:465), in open_file_cm(path_or_file, mode, encoding)
    463 def open_file_cm(path_or_file, mode="r", encoding=None):
    464     r"""Pass through file objects and context-manage path-likes."""
--> 465     fh, opened = to_filehandle(path_or_file, mode, True, encoding)
    466     return fh if opened else contextlib.nullcontext(fh)

File [~\AppData\Roaming\Python\Python310\site-packages\matplotlib\cbook\__init__.py:451](https://file+.vscode-resource.vscode-cdn.net/g%3A/.shortcut-targets-by-id/1mFf5ldec48ktee-8P2arcKW5E_WRwTWe/Ecalia/Technology/Theory/~/AppData/Roaming/Python/Python310/site-packages/matplotlib/cbook/__init__.py:451), in to_filehandle(fname, flag, return_opened, encoding)
    449         fh = bz2.BZ2File(fname, flag)
    450     else:
--> 451         fh = open(fname, flag, encoding=encoding)
    452     opened = True
    453 elif hasattr(fname, 'seek'):

OSError: [Errno 22] Invalid argument: 'test.svg'

New feature: Draw simple processes

It would be very benefitial, if the user could highlight specific simple processes and draw the respective lines into his diagram. Therefore I suggest the following addition:

  • Add a calc_inidividual_isolines() or draw_individual_isolines() method.
  • The user passes the property of the isoline(s) as well as inlet and outlet state (second property)
  • The method draws the specified isoline into the diagram, coloring, linestyle, etc. can be passed similarly to the linespecs of the diagram lines.
  • The lines are:
    • isenthalps
    • isobars
    • isochors
    • isentropics
    • isotherms
  • The method needs to check
    • whether the input properties are a valid valuepair and
    • whether the starting point and the ending point are at different phases. If this is the case, the intersection with the saturation line(s) must be considered, too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.