-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
254 lines (213 loc) · 10.7 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import streamlit as st
import CoolProp.CoolProp as cp
# Título de la aplicación
st.subheader("Tecnología del Calor")
st.title("💧 Calculador de propiedades del agua")
# Separador
st.markdown("---")
# Definir funciones para cálculos específicos
def calcular_propiedades(desde, **kwargs):
t = None
p = None
h = None
s = None
x = None
try:
if desde == 'TP':
t_kelvin = kwargs['t'] + 273.15
p_pascal = kwargs['p'] * 1e5
t = kwargs['t']
p = kwargs['p']
h = cp.PropsSI('H', 'P', p_pascal, 'T', t_kelvin, 'Water') / 1000
s = cp.PropsSI('S', 'P', p_pascal, 'T', t_kelvin, 'Water') / 1000
x = cp.PropsSI('Q', 'P', p_pascal, 'T', t_kelvin, 'Water')
elif desde == 'PH':
h_joules = kwargs['h'] * 1000
p_pascal = kwargs['p'] * 1e5
h = kwargs['h']
p = kwargs['p']
t_kelvin = cp.PropsSI('T', 'P', p_pascal, 'H', h_joules, 'Water')
s = cp.PropsSI('S', 'P', p_pascal, 'H', h_joules, 'Water') / 1000
x = cp.PropsSI('Q', 'P', p_pascal, 'H', h_joules, 'Water')
t = t_kelvin - 273.15
elif desde == 'HS':
h_joules = kwargs['h'] * 1000
s_joules = kwargs['s'] * 1000
h = kwargs['h']
s = kwargs['s']
t_kelvin = cp.PropsSI('T', 'H', h_joules, 'S', s_joules, 'Water')
p_pascal = cp.PropsSI('P', 'H', h_joules, 'S', s_joules, 'Water')
x = cp.PropsSI('Q', 'H', h_joules, 'S', s_joules, 'Water')
t = t_kelvin - 273.15
p = p_pascal / 1e5
elif desde == 'PX':
p_pascal = kwargs['p'] * 1e5
x = kwargs['x']
p = kwargs['p']
t_kelvin = cp.PropsSI('T', 'P', p_pascal, 'Q', x, 'Water')
h = cp.PropsSI('H', 'P', p_pascal, 'Q', x, 'Water') / 1000
s = cp.PropsSI('S', 'P', p_pascal, 'Q', x, 'Water') / 1000
t = t_kelvin - 273.15
elif desde == 'TX':
t_kelvin = kwargs['t'] + 273.15
x = kwargs['x']
t = kwargs['t']
p_pascal = cp.PropsSI('P', 'T', t_kelvin, 'Q', x, 'Water')
h = cp.PropsSI('H', 'T', t_kelvin, 'Q', x, 'Water') / 1000
s = cp.PropsSI('S', 'T', t_kelvin, 'Q', x, 'Water') / 1000
p = p_pascal / 1e5
elif desde == 'PS':
p_pascal = kwargs['p'] * 1e5
s_joules = kwargs['s'] * 1000
p = kwargs['p']
s = kwargs['s']
t_kelvin = cp.PropsSI('T', 'P', p_pascal, 'S', s_joules, 'Water')
h = cp.PropsSI('H', 'P', p_pascal, 'S', s_joules, 'Water') / 1000
x = cp.PropsSI('Q', 'P', p_pascal, 'S', s_joules, 'Water')
t = t_kelvin - 273.15
elif desde == 'TS':
t_kelvin = kwargs['t'] + 273.15
s_joules = kwargs['s'] * 1000
t = kwargs['t']
s = kwargs['s']
p_pascal = cp.PropsSI('P', 'T', t_kelvin, 'S', s_joules, 'Water')
h = cp.PropsSI('H', 'T', t_kelvin, 'S', s_joules, 'Water') / 1000
x = cp.PropsSI('Q', 'T', t_kelvin, 'S', s_joules, 'Water')
p = p_pascal / 1e5
# Devolver todas las propiedades calculadas
return t, p, h, s, x
except Exception as e:
st.error(f"Error en el cálculo: {e}")
return None, None, None, None, None
# Formulario para seleccionar la opción
st.sidebar.title("Seleccioná una opción:")
option = st.sidebar.radio("", ("t y p",
"p y h",
"h y s",
"p y x",
"t y x",
"p y s",
"t y s"
))
# Texto adicional
st.sidebar.write("Desarrollado por Pablo M. Barral para **Tecnología del Calor**.")
st.sidebar.write("Versión: 0.01.")
st.sidebar.write("Contacto: [email protected].")
st.sidebar.write("Powered by CoolProp.")
st.sidebar.markdown("[Readme.md](https://github.com/PabloMBarral/apps/blob/afc6a6ee783080c5d6adcff382cdea83cf95ff6e/README.md)")
if option == 't y p':
# Formulario para Temperatura y Presión
st.write("### Temperatura y Presión")
with st.form(key='tp_form'):
t = st.number_input("Ingrese la temperatura [°C]", value=0.0, step=0.01, format="%.2f", min_value=0.0)
p_t = st.number_input("Ingrese la presión [bar(a)]", value=1.0, step=0.01, format="%.2f", min_value=0.0)
tp_submit_button = st.form_submit_button(label='Calcular desde Temperatura y Presión')
if tp_submit_button:
t, p, h, s, x = calcular_propiedades('TP', t=t, p=p_t)
if t is not None:
st.write(f"Resultados a {t:.2f} °C y {p:.2f} bar(a):")
st.write(f"Entalpía: {h:.2f} kJ/kg")
st.write(f"Entropía: {s:.4f} kJ/(kg·K)")
st.write(f"Título: {x:.2f}")
else:
st.write(f"Revisá que sean coherentes los valores ingresados, y volvé a intentarlo.")
elif option == 'p y h':
# Formulario para Presión y Entalpía
st.write("### Presión y Entalpía")
with st.form(key='ph_form'):
h = st.number_input("Ingrese la entalpía [kJ/kg]", value=0.0, step=0.01, format="%.2f", min_value=0.0)
p_h = st.number_input("Ingrese la presión [bar(a)]", value=1.0, step=0.01, format="%.2f", min_value=0.0)
ph_submit_button = st.form_submit_button(label='Calcular desde Presión y Entalpía')
if ph_submit_button:
t, p, h, s, x = calcular_propiedades('PH', h=h, p=p_h)
if t is not None:
st.write(f"Resultados a {h:.2f} kJ/kg y {p:.2f} bar(a):")
st.write(f"Temperatura: {t:.2f} °C")
st.write(f"Entropía: {s:.4f} kJ/(kg·K)")
st.write(f"Título: {x:.2f}")
else:
st.write(f"Revisá que sean coherentes los valores ingresados, y volvé a intentarlo.")
elif option == 'h y s':
# Formulario para Entalpía y Entropía
st.write("### Entalpía y Entropía")
with st.form(key='hs_form'):
h = st.number_input("Ingrese la entalpía [kJ/kg]", value=0.0, step=0.01, format="%.2f", min_value=0.0)
s = st.number_input("Ingrese la entropía [kJ/(kg·K)]", value=0.0, step=0.01, format="%.4f", min_value=0.0)
hs_submit_button = st.form_submit_button(label='Calcular desde Entalpía y Entropía')
if hs_submit_button:
t, p, h, s, x = calcular_propiedades('HS', h=h, s=s)
if t is not None:
st.write(f"Resultados a {h:.2f} kJ/kg y {s:.4f} kJ/(kg·K):")
st.write(f"Temperatura: {t:.2f} °C")
st.write(f"Presión: {p:.2f} bar(a)")
st.write(f"Título: {x:.2f}")
else:
st.write(f"Revisá que sean coherentes los valores ingresados, y volvé a intentarlo.")
elif option == 'p y x':
# Formulario para Presión y Título
st.write("### Presión y Título")
with st.form(key='px_form'):
p = st.number_input("Ingrese la presión [bar(a)]", value=1.0, step=0.01, format="%.2f", min_value=0.0)
x = st.number_input("Ingrese el título (calidad del vapor) [0-1]", value=0.0, step=0.01, format="%.2f", min_value=0.0, max_value=1.0)
px_submit_button = st.form_submit_button(label='Calcular desde Presión y Título')
if px_submit_button:
t, p, h, s, x = calcular_propiedades('PX', p=p, x=x)
if t is not None:
st.write(f"Resultados a {p:.2f} bar(a) y {x:.2f}:")
st.write(f"Temperatura: {t:.2f} °C")
st.write(f"Entalpía: {h:.2f} kJ/kg")
st.write(f"Entropía: {s:.4f} kJ/(kg·K)")
else:
st.write(f"Revisá que sean coherentes los valores ingresados, y volvé a intentarlo.")
elif option == 't y x':
# Formulario para Temperatura y Título
st.write("### Temperatura y Título")
with st.form(key='tx_form'):
t = st.number_input("Ingrese la temperatura [°C]", value=0.0, step=0.01, format="%.2f", min_value=0.0)
x = st.number_input("Ingrese el título (calidad del vapor) [0-1]", value=0.0, step=0.01, format="%.2f", min_value=0.0, max_value=1.0)
tx_submit_button = st.form_submit_button(label='Calcular desde Temperatura y Título')
if tx_submit_button:
t, p, h, s, x = calcular_propiedades('TX', t=t, x=x)
if t is not None:
st.write(f"Resultados a {t:.2f} °C y {x:.2f}:")
st.write(f"Presión: {p:.2f} bar(a)")
st.write(f"Entalpía: {h:.2f} kJ/kg")
st.write(f"Entropía: {s:.4f} kJ/(kg·K)")
else:
st.write(f"Revisá que sean coherentes los valores ingresados, y volvé a intentarlo.")
elif option == 'p y s':
# Formulario para Presión y Entropía
st.write("### Presión y Entropía")
with st.form(key='ps_form'):
p = st.number_input("Ingrese la presión [bar(a)]", value=1.0, step=0.01, format="%.2f", min_value=0.0)
s = st.number_input("Ingrese la entropía [kJ/(kg·K)]", value=0.0, step=0.01, format="%.4f", min_value=0.0)
ps_submit_button = st.form_submit_button(label='Calcular desde Presión y Entropía')
if ps_submit_button:
t, p, h, s, x = calcular_propiedades('PS', p=p, s=s)
if t is not None:
st.write(f"Resultados a {p:.2f} bar(a) y {s:.4f} kJ/(kg·K):")
st.write(f"Temperatura: {t:.2f} °C")
st.write(f"Entalpía: {h:.2f} kJ/kg")
st.write(f"Título: {x:.2f}")
else:
st.write(f"Revisá que sean coherentes los valores ingresados, y volvé a intentarlo.")
elif option == 't y s':
# Formulario para Temperatura y Entropía
st.write("### Temperatura y Entropía")
with st.form(key='ts_form'):
t = st.number_input("Ingrese la temperatura [°C]", value=0.0, step=0.01, format="%.2f", min_value=0.0)
s = st.number_input("Ingrese la entropía [kJ/(kg·K)]", value=0.0, step=0.01, format="%.4f", min_value=0.0)
ts_submit_button = st.form_submit_button(label='Calcular desde Temperatura y Entropía')
if ts_submit_button:
t, p, h, s, x = calcular_propiedades('TS', t=t, s=s)
if t is not None:
st.write(f"Resultados a {t:.2f} °C y {s:.4f} kJ/(kg·K):")
st.write(f"Presión: {p:.2f} bar(a)")
st.write(f"Entalpía: {h:.2f} kJ/kg")
st.write(f"Título: {x:.2f}")
else:
st.write(f"Revisá que sean coherentes los valores ingresados, y volvé a intentarlo.")
# Separador
#st.markdown("---")
# Texto adicional
#st.write("Desarrollado por Pablo M. Barral para **Tecnología del Calor**. Versión: 0.01. Contacto: [email protected]. Powered by CoolProp. Ver [Readme.md](https://github.com/PabloMBarral/apps/blob/850f68ccf322553bd7eedfdf585b52ca7c1260de/README.md) en Github.")