oemof / tespy

Thermal Engineering Systems in Python (TESPy). This package provides a powerful simulation toolkit for thermal engineering plants such as power plants, district heating systems or heat pumps.
https://tespy.readthedocs.io
MIT License
256 stars 80 forks source link

Fluid property range with different unit than SI in log file #417

Closed tboussaid closed 1 year ago

tboussaid commented 1 year ago

Hi, First of all, thanks for the amazing work put in this library. I am using it for my PhD project. For convergence reasons, it's often better to set fluid properties ranges. However, I was going over the logg file, and I just noticed a small 'mistake' when the unit of the property is not the SI one. For example, when initiliazing Network as follows:

# THE PLANT
# let's create a network object with water as the fluid
fluid_list = ['HEOS::Water']
my_plant = Network(fluids=fluid_list)
# set the unit system for temperatures to °C and for pressure to bar
my_plant.set_attr(
    T_unit='C', 
    p_unit='bar', 
    h_unit='kJ / kg',
    m_range=[0.0, 3.0],
    p_range=[1, 16]
)

The logs file shows (pressure unit is not consistent with the values):

...
2023-05-17 11:17:17,040 - DEBUG - network - Setting pressure unit: bar.
...
2023-05-17 11:17:17,040 - DEBUG - network - Setting pressure limits
min: 100000.0 bar
max: 1600000.0 bar
...

The log files shows the limit range in SI unit. A quick fix, in lines 340-to-346 in /network.py would be either:

  1. Show the range in SI unit regardless of the unit specified by the user (which correspond to the values shown currently):
    limits = self.get_attr(prop + '_range_SI')
    msg = (
    'Setting ' + fpd[prop]['text'] +
    ' limits\nmin: ' + str(limits[0]) + ' ' +
    fpd[prop]['SI_unit'] + '\n'
    'max: ' + str(limits[1]) + ' ' +
    fpd[prop]['SI_unit'] 
    )
    logger.debug(msg)
  2. Show the range in the unit specified by the user:
    limits = self.get_attr(prop + '_range')
fwitte commented 1 year ago

Hi @tboussaid,

thanks a lot for letting me know and your suggestions. Are you familar with pull request, and do you want to open one yourself and contribute the changes? If not I can do that no problem. Just let me know.

Thank you for your contribution and have a nice weekend

Francesco

tboussaid commented 1 year ago

Hi @fwitte, Thanks for your reply. Yes I am, I'll do that by the end of the day. Best, Taha

fwitte commented 1 year ago

Resolved in #420