Spaces:
Sleeping
Sleeping
Update app.py
Browse filessome corrections on how delete components
app.py
CHANGED
|
@@ -26,14 +26,14 @@ st.markdown(
|
|
| 26 |
|
| 27 |
R = 10.73
|
| 28 |
components = {
|
| 29 |
-
|
| 30 |
'C1': {'Tc': 343.33, 'Pc': 666.4, 'omega': 0.0080, 'vol_shift': -0.0833, 'm_w': 16.0430},
|
| 31 |
-
|
| 32 |
'C3' : {'Tc': 666.06, 'Pc': 616.0, 'omega': 0.1522, 'vol_shift': -0.1000, 'm_w': 44.0970},
|
| 33 |
-
|
| 34 |
'nC4': {'Tc': 765.62, 'Pc': 550.6, 'omega': 0.1930, 'vol_shift': -0.1000, 'm_w': 58.1240},
|
| 35 |
-
|
| 36 |
-
|
| 37 |
'nC6': {'Tc': 913.60, 'Pc': 430.59, 'omega': 0.2960, 'vol_shift': 0.0200, 'm_w': 86.1780},
|
| 38 |
'nC10': {'Tc': 1111.00, 'Pc': 305.2, 'omega': 0.4898, 'vol_shift': 0.2600, 'm_w': 142.2850},
|
| 39 |
}
|
|
@@ -66,25 +66,35 @@ if st.button("Add component"):
|
|
| 66 |
# Display selected components with an option to remove them
|
| 67 |
selected_components = st.session_state["selected_components"]
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
st.write("### Selected Components")
|
| 70 |
if selected_components:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
else:
|
| 80 |
st.info("No components selected yet.")
|
| 81 |
|
| 82 |
-
# Entrada manual de concentraciones
|
| 83 |
concentrations = {}
|
| 84 |
if selected_components:
|
| 85 |
st.write("Enter concentrations for the selected components:")
|
| 86 |
for comp in selected_components:
|
| 87 |
-
input_value = st.text_input(f"
|
| 88 |
try:
|
| 89 |
concentrations[comp] = float(input_value)
|
| 90 |
except ValueError:
|
|
@@ -93,10 +103,10 @@ if selected_components:
|
|
| 93 |
|
| 94 |
# Normalizar concentraciones
|
| 95 |
ci = np.array([concentrations[comp] for comp in selected_components])
|
| 96 |
-
if np.sum(ci) > 0:
|
| 97 |
-
ci /= np.sum(ci)
|
| 98 |
-
else:
|
| 99 |
-
st.error("The sum of the concentrations must be greater than 0.")
|
| 100 |
|
| 101 |
T = st.slider("Temperature (°F):", min_value=-100.0, max_value=300.0, value=160.0) + 459.67
|
| 102 |
P = st.slider("Pressure (psia):", min_value=50.0, max_value=5000.0, value=2000.0)
|
|
@@ -320,40 +330,42 @@ def ssm_method(P, T, ci, kij, components, tol=1e-3, max_iter=100):
|
|
| 320 |
print("Warning: Convergence was not achieved.")
|
| 321 |
return Ki, None, None, None, None, max_iter
|
| 322 |
|
| 323 |
-
if selected_components:
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
|
|
|
|
|
|
| 358 |
else:
|
| 359 |
-
st.info("Please select at least
|
|
|
|
| 26 |
|
| 27 |
R = 10.73
|
| 28 |
components = {
|
| 29 |
+
'CO2': {'Tc': 547.91, 'Pc': 1071.0, 'omega': 0.2667, 'vol_shift': 0.0344, 'm_w': 0},
|
| 30 |
'C1': {'Tc': 343.33, 'Pc': 666.4, 'omega': 0.0080, 'vol_shift': -0.0833, 'm_w': 16.0430},
|
| 31 |
+
'C2': {'Tc': 549.92, 'Pc': 706.5, 'omega': 0.0979, 'vol_shift': 0.0783, 'm_w': 0},
|
| 32 |
'C3' : {'Tc': 666.06, 'Pc': 616.0, 'omega': 0.1522, 'vol_shift': -0.1000, 'm_w': 44.0970},
|
| 33 |
+
'iC4': {'Tc': 734.46, 'Pc': 527.9, 'omega': 0.1852, 'vol_shift': 0.0714, 'm_w': 0},
|
| 34 |
'nC4': {'Tc': 765.62, 'Pc': 550.6, 'omega': 0.1930, 'vol_shift': -0.1000, 'm_w': 58.1240},
|
| 35 |
+
'iC5': {'Tc': 829.10, 'Pc': 490.4, 'omega': 0.2280, 'vol_shift': 0.0679, 'm_w': 0},
|
| 36 |
+
'nC5': {'Tc': 845.80, 'Pc': 488.6, 'omega': 0.2514, 'vol_shift': 0.0675, 'm_w': 0},
|
| 37 |
'nC6': {'Tc': 913.60, 'Pc': 430.59, 'omega': 0.2960, 'vol_shift': 0.0200, 'm_w': 86.1780},
|
| 38 |
'nC10': {'Tc': 1111.00, 'Pc': 305.2, 'omega': 0.4898, 'vol_shift': 0.2600, 'm_w': 142.2850},
|
| 39 |
}
|
|
|
|
| 66 |
# Display selected components with an option to remove them
|
| 67 |
selected_components = st.session_state["selected_components"]
|
| 68 |
|
| 69 |
+
if "selected_components" not in st.session_state:
|
| 70 |
+
st.session_state["selected_components"] = ["Component 1", "Component 2", "Component 3"]
|
| 71 |
+
|
| 72 |
+
selected_components = st.session_state["selected_components"]
|
| 73 |
st.write("### Selected Components")
|
| 74 |
if selected_components:
|
| 75 |
+
# Generar un identificador único para evitar conflictos
|
| 76 |
+
dynamic_key = str(hash(tuple(selected_components)))
|
| 77 |
+
|
| 78 |
+
# Permite seleccionar varios componentes para eliminarlos
|
| 79 |
+
components_to_remove = st.multiselect(
|
| 80 |
+
"Select components to remove:",
|
| 81 |
+
options=selected_components,
|
| 82 |
+
key=dynamic_key
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
if st.button("Remove Selected"):
|
| 86 |
+
for component in components_to_remove:
|
| 87 |
+
st.session_state["selected_components"].remove(component)
|
| 88 |
+
|
| 89 |
+
st.write(f"Remaining components: {st.session_state['selected_components']}")
|
| 90 |
else:
|
| 91 |
st.info("No components selected yet.")
|
| 92 |
|
|
|
|
| 93 |
concentrations = {}
|
| 94 |
if selected_components:
|
| 95 |
st.write("Enter concentrations for the selected components:")
|
| 96 |
for comp in selected_components:
|
| 97 |
+
input_value = st.text_input(f"Concentration of {comp}:", value="0.1")
|
| 98 |
try:
|
| 99 |
concentrations[comp] = float(input_value)
|
| 100 |
except ValueError:
|
|
|
|
| 103 |
|
| 104 |
# Normalizar concentraciones
|
| 105 |
ci = np.array([concentrations[comp] for comp in selected_components])
|
| 106 |
+
#if np.sum(ci) > 0:
|
| 107 |
+
# ci /= np.sum(ci)
|
| 108 |
+
#else:
|
| 109 |
+
# st.error("The sum of the concentrations must be greater than 0.")
|
| 110 |
|
| 111 |
T = st.slider("Temperature (°F):", min_value=-100.0, max_value=300.0, value=160.0) + 459.67
|
| 112 |
P = st.slider("Pressure (psia):", min_value=50.0, max_value=5000.0, value=2000.0)
|
|
|
|
| 330 |
print("Warning: Convergence was not achieved.")
|
| 331 |
return Ki, None, None, None, None, max_iter
|
| 332 |
|
| 333 |
+
if len(selected_components)>1:
|
| 334 |
+
if np.sum(ci)==1:
|
| 335 |
+
# Call the method to calculate results
|
| 336 |
+
Ki, Z_liq, Z_vap, f_liq, f_vap, molar_density_liq, mass_density_liq, molar_density_vap, mass_density_vap, fng, xi, yi, iteration = ssm_method(
|
| 337 |
+
P, T, ci, kij, components, tol=tolerance, max_iter=100
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
# Display unique values outside the table
|
| 341 |
+
st.write("### Global Results")
|
| 342 |
+
st.write(f"**tolerance:** {tolerance}")
|
| 343 |
+
st.write(f"**liquid Mole frac:** {1-fng:.6f}")
|
| 344 |
+
st.write(f"**vapor Mole frac:** {fng:.6f}")
|
| 345 |
+
st.write(f"**Z_liq (liquid):** {Z_liq:.6f}")
|
| 346 |
+
st.write(f"**Z_vap (vapor):** {Z_vap:.6f}")
|
| 347 |
+
st.write(f"**Molar Density (liquid):** {molar_density_liq:.6f} lb-mole/ft³")
|
| 348 |
+
st.write(f"**Mass Density (liquid):** {mass_density_liq:.6f} lb/ft³")
|
| 349 |
+
st.write(f"**Molar Density (vapor):** {molar_density_vap:.6f} lb-mole/ft³")
|
| 350 |
+
st.write(f"**Mass Density (vapor):** {mass_density_vap:.6f} lb/ft³")
|
| 351 |
+
st.write(f"**Iterations:** {iteration}")
|
| 352 |
+
|
| 353 |
+
# Prepare per-component data for the table
|
| 354 |
+
st.write("### Per-Component Results")
|
| 355 |
+
data = {
|
| 356 |
+
"Component": selected_components,
|
| 357 |
+
"K-value": Ki,
|
| 358 |
+
"Liquid Fugacity": f_liq,
|
| 359 |
+
"Vapor Fugacity": f_vap,
|
| 360 |
+
"Liquid component xi": xi,
|
| 361 |
+
"Vapor component yi": yi,
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
# Create DataFrame and display it in Streamlit
|
| 365 |
+
import pandas as pd
|
| 366 |
+
df = pd.DataFrame(data)
|
| 367 |
+
st.table(df)
|
| 368 |
+
else:
|
| 369 |
+
st.info("Please ensure that the sum of the concentrations equals one.")
|
| 370 |
else:
|
| 371 |
+
st.info("Please select at least two component to calculate.")
|