nesanchezo commited on
Commit
21b4876
·
verified ·
1 Parent(s): 3b71b09

Update app.py

Browse files

more tolerance options

Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -24,7 +24,6 @@ st.markdown(
24
  unsafe_allow_html=True
25
  )
26
 
27
- # Datos iniciales
28
  R = 10.73
29
  components = {
30
  'CO2': {'Tc': 547.91, 'Pc': 1071.0, 'omega': 0.2667, 'vol_shift': 0.0344, 'm_w': 0},
@@ -95,17 +94,15 @@ if selected_components:
95
  # Normalizar concentraciones
96
  ci = np.array([concentrations[comp] for comp in selected_components])
97
  if np.sum(ci) > 0:
98
- ci /= np.sum(ci) # Normalizar para que la suma sea 1
99
  else:
100
  st.error("The sum of the concentrations must be greater than 0.")
101
 
102
- # Entradas para temperatura y presión
103
  T = st.slider("Temperature (°F):", min_value=-100.0, max_value=300.0, value=160.0) + 459.67
104
  P = st.slider("Pressure (psia):", min_value=50.0, max_value=5000.0, value=2000.0)
105
 
106
  # Add a dropdown menu for tolerance selection
107
  def generate_super_script(number):
108
- """Genera una cadena con superíndices para un número dado."""
109
  superscript_map = {
110
  '0': '⁰',
111
  '1': '¹',
@@ -117,11 +114,11 @@ def generate_super_script(number):
117
  '7': '⁷',
118
  '8': '⁸',
119
  '9': '⁹',
120
- '-': '⁻' # Superíndice para el signo menos
121
  }
122
  return ''.join(superscript_map.get(char, char) for char in str(number))
123
 
124
- # Generar opciones de tolerancia desde 10^-1 hasta 10^-14
125
  tolerance_options = {}
126
  for exponent in range(1, 15):
127
  label = f"10{generate_super_script(-exponent)}"
@@ -134,7 +131,6 @@ tolerance = tolerance_options[selected_tolerance_label]
134
  # Display the selected tolerance
135
  st.write(f"Selected Tolerance: {selected_tolerance_label} ({tolerance})")
136
 
137
- # Extraer propiedades críticas
138
  Pci = np.array([components[comp]['Pc'] for comp in selected_components])
139
  Tci = np.array([components[comp]['Tc'] for comp in selected_components])
140
  omega = np.array([components[comp]['omega'] for comp in selected_components])
@@ -239,11 +235,11 @@ def calculate_z_factor(P, T, ci, Pci, Tci, omega):
239
 
240
  def calculate_mixture_density(P, Z, T, mole_fractions, MWs, b_vol_shifts):
241
  molar_density = P / (Z * R * T) # lb-mole/ft³
242
- print(f"Molar Density (without correction): {molar_density:.6f} lb-mole/ft³")
243
 
244
  # Step 2: Mixture volume shift parameter
245
  b_mixture = sum(x * b for x, b in zip(mole_fractions, b_vol_shifts))
246
- print(f"Mixture Volume Shift: {b_mixture:.6f} ft³/lb-mole")
247
 
248
  # Step 3: Corrected molar density
249
  try:
@@ -254,11 +250,11 @@ def calculate_mixture_density(P, Z, T, mole_fractions, MWs, b_vol_shifts):
254
 
255
  # Step 4: Average molecular weight
256
  M_avg = sum(x * mw for x, mw in zip(mole_fractions, MWs))
257
- print(f"Average Molecular Weight (M_avg): {M_avg:.6f} lb/lb-mole")
258
 
259
  # Step 5: Mass density
260
  mass_density = corrected_molar_density * M_avg # lb/ft³
261
- print(f"Mass Density: {mass_density:.6f} lb/ft³")
262
 
263
  return corrected_molar_density, mass_density
264
 
@@ -293,9 +289,6 @@ def calculate_fugacity_coefficients(Z, A, B, ai, bi, a_m, b_m, ci, kij):
293
  return phi
294
 
295
  def ssm_method(P, T, ci, kij, components, tol=1e-3, max_iter=100):
296
- #Pci = np.array([components[comp]['Pc'] for comp in components])
297
- #Tci = np.array([components[comp]['Tc'] for comp in components])
298
- #omega = np.array([components[comp]['omega'] for comp in components])
299
 
300
  Ki = np.exp(5.37 * (1 + omega) * (1 - Tci / T))
301
 
@@ -324,7 +317,7 @@ def ssm_method(P, T, ci, kij, components, tol=1e-3, max_iter=100):
324
  print("Warning: The method did not converge. Last values:")
325
  print(f"Z_liq={Z_liq}, Z_vap={Z_vap}, phi_liq={phi_liq}, phi_vap={phi_vap}")
326
 
327
- print("Advertencia: No se logró la convergencia.")
328
  return Ki, None, None, None, None, max_iter
329
 
330
  if selected_components:
 
24
  unsafe_allow_html=True
25
  )
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},
 
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)
103
 
104
  # Add a dropdown menu for tolerance selection
105
  def generate_super_script(number):
 
106
  superscript_map = {
107
  '0': '⁰',
108
  '1': '¹',
 
114
  '7': '⁷',
115
  '8': '⁸',
116
  '9': '⁹',
117
+ '-': '⁻'
118
  }
119
  return ''.join(superscript_map.get(char, char) for char in str(number))
120
 
121
+ # tolerance from 10^-1 to 10^-14
122
  tolerance_options = {}
123
  for exponent in range(1, 15):
124
  label = f"10{generate_super_script(-exponent)}"
 
131
  # Display the selected tolerance
132
  st.write(f"Selected Tolerance: {selected_tolerance_label} ({tolerance})")
133
 
 
134
  Pci = np.array([components[comp]['Pc'] for comp in selected_components])
135
  Tci = np.array([components[comp]['Tc'] for comp in selected_components])
136
  omega = np.array([components[comp]['omega'] for comp in selected_components])
 
235
 
236
  def calculate_mixture_density(P, Z, T, mole_fractions, MWs, b_vol_shifts):
237
  molar_density = P / (Z * R * T) # lb-mole/ft³
238
+ #print(f"Molar Density (without correction): {molar_density:.6f} lb-mole/ft³")
239
 
240
  # Step 2: Mixture volume shift parameter
241
  b_mixture = sum(x * b for x, b in zip(mole_fractions, b_vol_shifts))
242
+ #print(f"Mixture Volume Shift: {b_mixture:.6f} ft³/lb-mole")
243
 
244
  # Step 3: Corrected molar density
245
  try:
 
250
 
251
  # Step 4: Average molecular weight
252
  M_avg = sum(x * mw for x, mw in zip(mole_fractions, MWs))
253
+ #print(f"Average Molecular Weight (M_avg): {M_avg:.6f} lb/lb-mole")
254
 
255
  # Step 5: Mass density
256
  mass_density = corrected_molar_density * M_avg # lb/ft³
257
+ #print(f"Mass Density: {mass_density:.6f} lb/ft³")
258
 
259
  return corrected_molar_density, mass_density
260
 
 
289
  return phi
290
 
291
  def ssm_method(P, T, ci, kij, components, tol=1e-3, max_iter=100):
 
 
 
292
 
293
  Ki = np.exp(5.37 * (1 + omega) * (1 - Tci / T))
294
 
 
317
  print("Warning: The method did not converge. Last values:")
318
  print(f"Z_liq={Z_liq}, Z_vap={Z_vap}, phi_liq={phi_liq}, phi_vap={phi_vap}")
319
 
320
+ print("Warning: Convergence was not achieved.")
321
  return Ki, None, None, None, None, max_iter
322
 
323
  if selected_components: