API

Module for fluid property diagram creation.

This file is part of project fluprodia (github.com/fwitte/fluprodia). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location src/fluprodia/fluid_property_diagram.py

SPDX-License-Identifier: MIT

class fluprodia.fluid_property_diagram.FluidPropertyDiagram(fluid)[source]

Bases: object

Short summary.

Parameters:
  • fluid (str) – Fluid for diagram.

  • width (float) – Width of all diagrams (default value: width=16.0).

  • height (float) – Height of all diagrams (default value: height=10.0).

Example

This is a small example of how to create a fluid property dataset for water and export to Ts-, hs- and logph-diagram.

>>> from fluprodia import FluidPropertyDiagram
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> diagram = FluidPropertyDiagram('water')

After object creation it is possible to specify isolines. There are deault isolines available, but these might not suit your requirements. We will define temperature and enthalpy isolines for this case. Before that, we need to specify the units if we do not want to use SI units. For available units see the fluprodia.fluid_property_diagram.FluidPropertyDiagram.set_unit_system() documentation.

>>> diagram.set_unit_system(T='°C', p='MPa', s='kJ/kgK', h='kJ/kg')
>>> iso_T = np.arange(50, 701, 50)
>>> iso_h = np.arange(0, 3601, 200)
>>> diagram.set_isolines(T=iso_T, h=iso_h)

Now we can calculate the diagram data and create the diagram, the data should be plotted to. If you want to plot additional data to your diagram, first call the draw_isolines method, and then plot your data.

>>> diagram.calc_isolines()

After that it is possible to specify the view range of the plot and draw the isolines of a specific type of diagram. Last step is to export your diagram. Any file format supported by matplotlib is possible.

>>> fig, ax = plt.subplots(1)
>>> diagram.draw_isolines(diagram_type='Ts', fig=fig, ax=ax, x_min=0, x_max=8, y_min=0, y_max=700)
>>> plt.tight_layout()
>>> fig.savefig('Ts_Diagramm.pdf')

If we want to create a different diagram, e.g. hs-diagram, it is not necessary to recalculate the isolines. Instead, create a new figure and draw the isolines for a different diagram.

>>> fig, ax = plt.subplots(1, figsize=(8, 5))
>>> diagram.draw_isolines(diagram_type='hs', fig=fig, ax=ax, x_min=0, x_max=8, y_min=0, y_max=3600)
>>> plt.tight_layout()
>>> fig.savefig('hs_Diagramm.pdf')
>>> fig, ax = plt.subplots(1, figsize=(8, 5))
>>> diagram.draw_isolines(diagram_type='logph', fig=fig, ax=ax, x_min=0, x_max=3600, y_min=1e-2, y_max=5e2)
>>> plt.tight_layout()
>>> fig.savefig('logph_Diagramm.pdf')

It is also possible to specify/modify the isolines to plot. For example, the lines of constant specific enthalpy should be plotted in red color and with a linewidth of 2. Also, the lines of constant specific volumen should not be plotted at all. For more information see the fluprodia.fluid_property_diagram.FluidPropertyDiagram.draw_isolines() method.

>>> fig, ax = plt.subplots(1)
>>> diagram.draw_isolines(
...     diagram_type='Ts', fig=fig, ax=ax,
...     isoline_data={
...         'h': {
...            'values': iso_h,
...            'style': {'linewidth': 2, 'color': '#ff0000'}
...         }, 'v': {'values': np.array([])}},
...     x_min=0, x_max=8, y_min=0, y_max=700
... )
>>> plt.tight_layout()
>>> fig.savefig('Ts_Diagramm.pdf')
calc_individual_isoline(isoline_property=None, isoline_value=None, isoline_value_end=None, starting_point_property=None, ending_point_property=None, starting_point_value=None, ending_point_value=None)[source]

Return data points of an individual isoline within.

Pass the isoline type, its value in the diagrams unit system, as well as the start and the endpoint of the line. Styling can be changed using the line_style property.

Parameters:
  • isoline_property (str) – Type of the isoline. Choose from line_type='...':

    • pressure ('p')

    • specific volume ('v')

    • temperature ('T')

    • enthalpy ('h')

    • entropy ('s')

  • isoline_value (float) – Value of the isoline specified in the respective unit.

  • starting_point (dict) – Dictionary holding the starting property and its value in the unit used for plotting the diagram, e.g. starting_property{'p': 1e5}

  • ending_point (dict) – Dictionary holding the ending property and its value in the unit used for plotting the diagram, e.g. ending_property{'p': 1e4}

Returns:

datapoints (dict) – Dictionary holding the isoline datapoints for:

  • pressure (key=:code:’p’)

  • specific volume (key=:code:’v’)

  • temperature (key=:code:’T’)

  • enthalpy (key=:code:’h’)

  • entropy (key=:code:’s’)

Example

A full example can be found in the class documentation.

calc_isolines()[source]

Calculate all isolines.

convert_from_SI(value, property)[source]

Convert a SI value to value in respecive unit system.

convert_to_SI(value, property)[source]

Convert a value to its SI value.

default_label_positioning()[source]

Definition of the default label positioning.

default_line_layout()[source]

Definition of the default isoline layout.

draw_isoline_label(fig, ax, isoline, property, idx, x, y, x_min, x_max, y_min, y_max)[source]

Draw a label for an isoline.

Parameters:
  • isoline (float) – Value of the isoline.

  • property (str) – Fluid property of the isoline.

  • idx (float) – Index in the array holding the isoline data, where the label should be plotted.

  • x (ndarray) – x-values of the isoline.s

  • y (ndarray) – y-values of the isoline.s

draw_isolines(fig, ax, diagram_type, x_min, x_max, y_min, y_max, isoline_data={})[source]

Draw the isolines of a specific diagram type.

Parameters:
  • diagram_type (str) – Which type of diagram should be drawn.

  • isoline_data (dict) – Dictionary holding additional data on the isolines to be drawn. These are

    • the isoline values with key values and

    • the isoline style with key style.

    The islonline style is another dictionary holding keyword arguments of a matplotlib.lines.Line2D object. See https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D for more information.

get_Q_crossings(datapoints, property, rising)[source]

Return data of Q=0 or Q=1 crossings of specified line.

insert_Q_crossings(datapoints, property, data)[source]

Insert data of Q=0 and Q=1 crossings into specified line.

isenthalpic()[source]

Calculate an isoline of constant specific enthalpy.

isentropic()[source]

Calculate an isoline of constant specific entropy.

isobaric()[source]

Calculate an isoline of constant pressure.

isochoric()[source]

Calculate an isoline of constant specific volume.

isoquality()[source]

Calculate an isoline of constant vapor mass fraction.

isothermal()[source]

Calculate an isoline of constant temperature.

set_isoline_defaults()[source]

Calculate the default values for the isolines.

set_isolines(**kwargs)[source]

Set the isolines.

Parameters:
  • p (ndarray) – Isolines for pressure.

  • T (ndarray) – Isolines for temperature.

  • Q (ndarray) – Isolines for vapor mass fraction.

  • s (ndarray) – Isolines for specific entropy.

  • h (ndarray) – Isolines for specific enthalpy.

  • v (ndarray) – Isolines for specific volume.

set_unit_system(**kwargs)[source]

Set the unit system for the fluid properties.

Parameters:
  • p (str) – Unit of pressure, units available are Pa, hPa, mbar, psi, kPa, bar, MPa.

  • T (str) – Unit of temperatur, units available are K, °C, °F.

  • s (str) – Unit of specific entropy, units available are J/kgK, kJ/kgK, MJ/kgK.

  • h (str) – Unit of specific enthalpy, units available are J/kg, kJ/kg, MJ/kg.

  • v (str) – Unit of specific volume, units available are m^3/kg, l/kg.

  • Q (str) – Unit of vapor mass fraction, units available are -, %.

single_isenthalpic(iterator, h)[source]

Calculate an isoline of constant specific enthalpy.

single_isentropic(iterator, s)[source]

Calculate an isoline of constant specific entropy.

single_isobaric(iterator, p)[source]

Calculate an isoline of constant pressure.

single_isochoric(iterator, D)[source]

Calculate an isoline of constant specific volume.

single_isothermal(iterator, T)[source]

Calculate an isoline of constant temperature.

fluprodia.fluid_property_diagram.beautiful_unit_string(unit)[source]

Convert unit fractions to latex.

Parameters:

unit (str) – Value of unit for input, e.g. m^3/kg.

Returns:

unit (str) – Value of unit for output, e.g. $frac{m^3}{kg}$.

fluprodia.fluid_property_diagram.isolines_log(val_min, val_max)[source]

Generate default logarithmic isolines.

Parameters:
  • val_min (float) – Minimum value for isoline range.

  • val_max (float) – Maximum value for isoline range.

Returns:

arr (ndarray) – numpy array with logarithmically spaced values starting from the minimum value going to the maximum value in steps of 1ek, 2ek and 5ek.