chmarti1 / PYroMat

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

Code from Live-Page of PYroMat #85

Open jettrich opened 6 months ago

jettrich commented 6 months ago

Dear chmarti1,

I'm highly interested in using PYroMat for creating state diagrams and illustrating thermodynamic processes and cycles for my students, and I'd love to see the source code used to draw the T,s-diagram on the live site of the PYroMat website. Please, could you provide me with the code, in order to ease my point of entry in using PYroMat?

Kind Regards Jörg

chmarti1 commented 6 months ago

I'll refer you to (and tremendous credit is due to) my colleague, Joe Ranalli (@jranalli), who currently maintains all of the live code. In the meantime, there are various versions of development of the website that have historically been housed here.

jranalli commented 6 months ago

@jettrich thanks for your interest! It turns out that the code that draws that graph is pretty extensive, because there's a lot of fiddling that goes into figuring out exactly which lines will have decent spacing. It also depends a bit on how perfect you'd like it to look. For example, some of the phase transitions on enthalpy isolines in my plot do not show the exact intersection with the steam dome.

So that said, I put together a demo file that will plot a similar diagram to the live page. You can see it here. There are several helper functions that only exist to quickly gather data for the steam dome and isolines, while the real plotting happens in this section.

if __name__ == "__main__":
    water = pm.get("mp.H2O")
    sd_data = compute_steam_dome(water)

    plt.figure()
    plt.xlabel('s (kJ/kg-K)')
    plt.ylabel('T (K)')

    # Steam Dome
    for line in ['liquid', 'vapor']:
        plt.plot(sd_data[line]['s'], sd_data[line]['T'], 'k-')

    # P isolines
    for line in compute_iso_line(water, p=0, n=25, default=True):
        plt.plot(line['s'], line['T'], 'r-')

    # v isolines
    for line in compute_iso_line(water, v=0, n=25, default=True):
        plt.plot(line['s'], line['T'], 'b-')

    # h isolines
    for line in compute_iso_line(water, h=0, n=25, default=True):
        plt.plot(line['s'], line['T'], 'g-')

    plt.show()

I'm not sure what your starting point is as far as python knowledge goes, but if this is too much of a mess to jump right into, please say so and I can try to make a simpler introduction.