Skip to content

Commit f8cec23

Browse files
Merge branch 'glc' of https://github.com/pathsim/pathsim-chem into glc
2 parents b609bc6 + 30f595c commit f8cec23

1 file changed

Lines changed: 84 additions & 55 deletions

File tree

  • src/pathsim_chem/tritium

src/pathsim_chem/tritium/glc.py

Lines changed: 84 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def _calculate_properties(params):
3636
"""
3737
T = params["T"]
3838
D = params["D"]
39-
Flow_l = params["Flow_l"]
40-
Flow_g = params["Flow_g"]
41-
P_0 = params["P_0"]
39+
flow_l = params["flow_l"]
40+
flow_g = params["flow_g"]
41+
P_in = params["P_in"]
4242

4343
# --- Fluid Properties (Temperature Dependent) ---
4444
# TODO add references
@@ -52,8 +52,8 @@ def _calculate_properties(params):
5252

5353
# --- Flow Properties ---
5454
A = np.pi * (D / 2) ** 2 # m^2, Cross-sectional area
55-
Q_l = Flow_l / rho_l # m^3/s, Volumetric liquid flow rate
56-
Q_g = (Flow_g * R * T) / P_0 # m^3/s, Volumetric gas flow rate at inlet
55+
Q_l = flow_l / rho_l # m^3/s, Volumetric liquid flow rate
56+
Q_g = (flow_g * R * T) / P_in # m^3/s, Volumetric gas flow rate at inlet
5757
u_l = Q_l / A # m/s, Superficial liquid velocity
5858
u_g0 = Q_g / A # m/s, Superficial gas velocity at inlet
5959

@@ -112,7 +112,7 @@ def _calculate_dimensionless_groups(params, phys_props):
112112
Calculate the dimensionless groups for the ODE system.
113113
114114
Args:
115-
params (dict): Dictionary of input parameters including L, T, P_0,
115+
params (dict): Dictionary of input parameters including L, T, P_in,
116116
and c_T_inlet.
117117
phys_props (dict): Dictionary of physical properties calculated by
118118
_calculate_properties.
@@ -122,7 +122,12 @@ def _calculate_dimensionless_groups(params, phys_props):
122122
Bo_g, phi_g, psi, nu).
123123
"""
124124
# Unpack parameters
125-
L, T, P_0, c_T_inlet = params["L"], params["T"], params["P_0"], params["c_T_inlet"]
125+
L, T, P_in, c_T_in = (
126+
params["L"],
127+
params["T"],
128+
params["P_in"],
129+
params["c_T_in"],
130+
)
126131

127132
# Unpack physical properties
128133
rho_l, K_s, u_l, u_g0, epsilon_g, epsilon_l, E_l, E_g, a, h_l = (
@@ -139,12 +144,12 @@ def _calculate_dimensionless_groups(params, phys_props):
139144
)
140145

141146
# Calculate dimensionless groups
142-
psi = (rho_l * g * epsilon_l * L) / P_0 # Hydrostatic pressure ratio
143-
nu = ((c_T_inlet / K_s) ** 2) / P_0 # Equilibrium ratio
147+
psi = (rho_l * g * epsilon_l * L) / P_in # Hydrostatic pressure ratio
148+
nu = ((c_T_in / K_s) ** 2) / P_in # Equilibrium ratio
144149
Bo_l = u_l * L / (epsilon_l * E_l) # Bodenstein number, liquid
145-
phi_l = a * h_l * L / u_l # Transfer units, liquid (Eq. 8.11)
150+
phi_l = a * h_l * L / u_l # Transfer units, liquid
146151
Bo_g = u_g0 * L / (epsilon_g * E_g) # Bodenstein number, gas
147-
phi_g = 0.5 * (R * T * c_T_inlet / P_0) * (a * h_l * L / u_g0)
152+
phi_g = 0.5 * (R * T * c_T_in / P_in) * (a * h_l * L / u_g0)
148153

149154
return {
150155
"Bo_l": Bo_l,
@@ -237,31 +242,39 @@ def _process_results(solution, params, phys_props, dim_params):
237242
Returns:
238243
list: A list containing the results dictionary and the solution object.
239244
"""
240-
if not solution.success:
241-
raise RuntimeError("BVP solver failed to converge.")
242245

243246
# Unpack parameters
244-
c_T_inlet, P_0, T = params["c_T_inlet"], params["P_0"], params["T"]
247+
c_T_in, P_in, T = params["c_T_in"], params["P_in"], params["T"]
245248
y_T2_in = params["y_T2_in"]
246249

250+
########### Debugging ##########
251+
print("c_T_in: ",c_T_in)
252+
print("y_T2_in :", y_T2_in)
253+
print("flow_l: ",params["flow_l"])
254+
print("flow_g: ",params["flow_g"])
255+
256+
257+
if not solution.success:
258+
raise RuntimeError("BVP solver failed to converge.")
259+
247260
# Dimensionless results
248261
x_T_outlet_dimless = solution.y[0, 0]
249262
Q_l, Q_g = phys_props["Q_l"], phys_props["Q_g"]
250-
y_T2_outlet_gas = solution.y[2, -1]
263+
y_T2_out = solution.y[2, -1]
251264
efficiency = 1 - x_T_outlet_dimless
252265

253266
# Dimensional results
254-
c_T_outlet = x_T_outlet_dimless * c_T_inlet
255-
P_outlet = P_0 * (1 - dim_params["psi"])
256-
P_T2_out = y_T2_outlet_gas * P_outlet
257-
P_T2_in = y_T2_in * P_0
267+
c_T_out = x_T_outlet_dimless * c_T_in
268+
P_out = P_in * (1 - dim_params["psi"])
269+
P_T2_out = y_T2_out * P_out
270+
P_T2_in = y_T2_in * P_in
258271

259272
# Mass balance check
260-
n_T_in_liquid = c_T_inlet * Q_l # mol/s
261-
n_T_out_liquid = c_T_outlet * Q_l # mol/s
273+
n_T_in_liquid = c_T_in * Q_l # mol/s
274+
n_T_out_liquid = c_T_out * Q_l # mol/s
262275
n_T2_in_gas = P_T2_in * Q_g / (R * T) # mol/s
263276
n_T_in_gas = n_T2_in_gas * 2 # mol/s
264-
Q_g_out = (P_0 * Q_g) / P_outlet # m3/s
277+
Q_g_out = Q_g * (P_in / P_out) # m3/s
265278
n_T2_out_gas = P_T2_out * Q_g_out / (R * T) # mol/s
266279
n_T_out_gas = n_T2_out_gas * 2 # mol/s
267280

@@ -276,15 +289,14 @@ def _process_results(solution, params, phys_props, dim_params):
276289
"tritium_out_liquid [mol/s]": n_T_out_liquid,
277290
"tritium_out_gas [mol/s]": n_T_out_gas,
278291
"extraction_efficiency [fraction]": efficiency,
279-
"c_T_inlet [mol/m^3]": c_T_inlet,
280-
"c_T_outlet [mol/m^3]": c_T_outlet,
292+
"c_T_outlet [mol/m^3]": c_T_out,
281293
"P_T2_inlet_gas [Pa]": P_T2_in,
282294
"P_T2_outlet_gas [Pa]": P_T2_out,
283-
"y_T2_outlet_gas": y_T2_outlet_gas,
284-
"total_gas_P_inlet [Pa]": P_0,
285-
"total_gas_P_outlet [Pa]": P_outlet,
295+
"y_T2_outlet_gas": y_T2_out,
296+
"total_gas_P_inlet [Pa]": P_in,
297+
"total_gas_P_outlet [Pa]": P_out,
286298
"liquid_vol_flow [m^3/s]": Q_l,
287-
"gas_vol_flow [m^3/s]": Q_g,
299+
"gas_vol_flow_outlet [m^3/s]": Q_g_out,
288300
}
289301

290302
# Add all calculated parameters to the results dictionary
@@ -315,13 +327,13 @@ def solve(params):
315327
phys_props = _calculate_properties(params)
316328

317329
# Pre-solver check for non-physical outlet pressure
318-
P_outlet = params["P_0"] - (
330+
P_out = params["P_in"] - (
319331
phys_props["rho_l"] * (1 - phys_props["epsilon_g"]) * g * params["L"]
320332
)
321-
if P_outlet <= 0:
333+
if P_out <= 0:
322334
raise ValueError(
323-
f"Calculated gas outlet pressure is non-positive ({P_outlet:.2e} Pa). "
324-
"Check input parameters P_0, L, etc."
335+
f"Calculated gas outlet pressure is non-positive ({P_out:.2e} Pa). "
336+
"Check input parameters P_in, L, etc."
325337
)
326338

327339
# 2. Calculate dimensionless groups for the ODE system
@@ -343,63 +355,80 @@ class GLC(pathsim.blocks.Function):
343355
More details about the model can be found in: https://doi.org/10.13182/FST95-A30485
344356
345357
Args:
346-
P_0: Inlet operating pressure [Pa]
358+
P_in: Inlet operating pressure [Pa]
347359
L: Column height [m]
348-
flow_g: Gas mass flow rate [kg/s]
349-
flow_l: Liquid mass flow rate [kg/s]
350360
D: Column diameter [m]
351361
T: Temperature [K]
352362
g: Gravitational acceleration [m/s^2], default is 9.81
363+
initial_nb_of_elements: Initial number of elements for BVP solver
364+
BCs: Boundary conditions type, "C-C" (Closed-Closed) or "O-C" (Open-Closed), default is "C-C"
353365
"""
354366

355367
_port_map_in = {
356-
"c_T_inlet": 0,
357-
"y_T2_in": 1,
368+
"c_T_in": 0,
369+
"flow_l":1,
370+
"y_T2_in": 2,
371+
"flow_g":3,
358372
}
373+
359374
_port_map_out = {
360-
"c_T_outlet": 0,
375+
"c_T_out": 0,
361376
"y_T2_out": 1,
362-
"P_out_gas": 2,
363-
"efficiency": 3,
364-
"n_T_out_gas": 4,
377+
"eff": 2,
378+
"P_out": 3,
379+
"Q_l": 4,
380+
"Q_g_out": 5,
381+
"n_T_out_liquid": 6,
382+
"n_T_out_gas": 7,
365383
}
366384

367385
def __init__(
368386
self,
369-
P_0,
387+
P_in,
370388
L,
371-
flow_g,
372-
flow_l,
373389
D,
374390
T,
391+
BCs,
375392
g=const.g,
376393
initial_nb_of_elements=20,
377394
):
378395
self.params = {
379-
"P_0": P_0,
396+
"P_in": P_in,
380397
"L": L,
381-
"Flow_l": flow_l,
382-
"Flow_g": flow_g,
383398
"g": g,
384399
"D": D,
385400
"T": T,
386401
"elements": initial_nb_of_elements,
387-
"BCs": "C-C", # hard coded for now
402+
"BCs": BCs,
388403
}
389404
super().__init__(func=self.func)
390405

391-
def func(self, c_T_inlet, y_T2_inlet):
406+
def func(self, c_T_in, flow_l, y_T2_inlet, flow_g):
392407
new_params = self.params.copy()
393-
new_params["c_T_inlet"] = c_T_inlet
408+
new_params["c_T_in"] = c_T_in
409+
new_params["flow_l"] = flow_l
394410
new_params["y_T2_in"] = y_T2_inlet
411+
new_params["flow_g"] = flow_g
412+
395413

396414
res, _ = solve(new_params)
397415

398-
c_T_outlet = res["c_T_outlet [mol/m^3]"]
399-
y_T2_outlet = res["y_T2_outlet_gas"]
416+
c_T_out = res["c_T_outlet [mol/m^3]"]
417+
y_T2_out = res["y_T2_outlet_gas"]
418+
eff = res["extraction_efficiency [fraction]"]
400419
P_total_outlet = res["total_gas_P_outlet [Pa]"]
420+
Q_l = res["liquid_vol_flow [m^3/s]"]
421+
Q_g_out = res["gas_vol_flow_outlet [m^3/s]"]
422+
n_T_out_liquid = res["tritium_out_liquid [mol/s]"]
401423
n_T_out_gas = res["tritium_out_gas [mol/s]"]
402424

403-
eff = res["extraction_efficiency [fraction]"]
404-
405-
return c_T_outlet, y_T2_outlet, P_total_outlet, eff, n_T_out_gas
425+
return (
426+
c_T_out,
427+
y_T2_out,
428+
eff,
429+
P_total_outlet,
430+
Q_l,
431+
Q_g_out,
432+
n_T_out_liquid,
433+
n_T_out_gas,
434+
)

0 commit comments

Comments
 (0)