chmarti1 / PYroMat

PYroMat thermodynamic properties in Python
http://pyromat.org
Other
71 stars 13 forks source link

Create a state class #81

Open chmarti1 opened 1 year ago

chmarti1 commented 1 year ago

This was originally posted by @DanielSarmiento04 as a comment in #77. I've re-posted it here because it's an interesting idea.

         I have been using the library for the past few months in parallel to a thermodynamics course

I like the piromat ecosystem

I made this repository when I used for solve Brayton, Rankine and >combine Cicle, these example you can use for tutorials.

Another suggestion that I found is the next

  • Simply code Normally, for optimize time processed and debugger I use
    state_x = 'fluid'.state('propierties')

this return a dictionary and for mapping the information we have to use .get dictionary method h_x = state_x.get('h') something to improve is use the status type objects

  • Example
    class State(object):
    h
    s
    T
    v
    # Some propierties

and then use h_x = state_x.h

Originally posted by @DanielSarmiento04 in https://github.com/chmarti1/PYroMat/issues/77#issuecomment-1397545933

chmarti1 commented 1 year ago

I thought about doing this when I wrote the state methods. There are a couple of reasons I decided not to do it yet, but that doesn't mean it will never happen

  1. It is awkward to write a single state class that can represent data from all substances. For example, quality and saturation properties are meaningless for an ideal gas. These are issues that can be dealt with, but they can also be dealt with by a dictionary.
  2. In my opinion, promoting a dictionary to a class is best done only when implementing class methods is important. The state class would merely be a container for the property values.
  3. There are plans to add additional properties soon, which would make this an awkward time to design a class that could represent all properties.

Still, I think this is still a good idea, so it's worth opening it for discussion.

jranalli commented 1 year ago
2. In my opinion, promoting a dictionary to a class is best done only when implementing class methods is important.  The state class would merely be a container for the property values.

Thinking out loud here, so please excuse. One method that would maybe be of value is wrappers for quickly converting the units for all properties an already computed state. But that doesn't necessarily have to be a class function as opposed to a function that can operate on the dict. The one advantage I could see for a class approach would be to carry the units along with the values as an extra field. In principle that could happen with the dict but might be messier?