Is this the same model. # --- System 1: RO with Retentate Recycle (Generic for any active contaminant) ---
def simulate_system1(q_drain, q_product, q_ro_feed_fixed, c_source_active, ro_rejection_active):
"""
Simulates System 1: RO with retentate recycle, with a fixed RO feed flow rate.
Calculates source flow, product concentration, and drain concentration for a single active contaminant.
code
Args:
q_drain (float): Drain flow rate (ml/min).
q_product (float): Product flow rate (ml/min).
q_ro_feed_fixed (float): Fixed RO feed flow rate (ml/min).
c_source_active (float): Source concentration of the active contaminant.
ro_rejection_active (float): RO rejection rate of the active contaminant (0-1).
Returns:
tuple: (q_source, c_product_active, c_drain_active, q_recycle)
Returns None for any value if a mathematical singularity occurs.
"""
q_source = q_product + q_drain # Overall system flow balance
q_ro_feed = q_ro_feed_fixed
q_ro_retentate = q_ro_feed - q_product # Fixed RO retentate flow based on fixed RO feed and product
# Calculate recycle flow based on fixed RO retentate and drain
q_recycle_calc = q_ro_retentate - q_drain
# Initialize concentration
c_ro_feed_active = 0.0
if q_recycle_calc <= 0:
# Case A: No Recycle (or negative recycle, which means all retentate goes to drain)
q_recycle = 0 # Actual recycle flow is zero
c_ro_feed_active = c_source_active # RO feed concentration is source concentration
else:
# Case B: Recycle Occurs (q_recycle_calc > 0)
q_recycle = q_recycle_calc # Actual recycle flow is the calculated positive value
# Mass Balance for C_RO_Feed_Active
numerator = q_source * c_source_active
denominator = q_ro_feed - q_recycle * (q_ro_feed - q_product * (1 - ro_rejection_active)) / q_ro_retentate
if denominator == 0:
return None, None, None, None # Mathematical singularity
c_ro_feed_active = numerator / denominator
# Calculate concentrations based on RO Feed (common to both cases)
c_product_active = c_ro_feed_active * (1 - ro_rejection_active)
# Calculate retentate concentration from RO unit's mass balance
if q_ro_retentate == 0:
c_retentate_ro_active = c_ro_feed_active
else:
c_retentate_ro_active = (q_ro_feed * c_ro_feed_active - q_product * c_product_active) / q_ro_retentate
c_drain_active = c_retentate_ro_active # The drain concentration is the retentate concentration
return q_source, c_product_active, c_drain_active, q_recycle
--- System 2: MCDI before RO, with another MCDI on Retentate side (Generic for any active contaminant) ---
def simulate_system2(q_drain, q_product, q_ro_feed_fixed, c_source_active, ro_rejection_active,
mcdi1_reject_flow, mcdi2_reject_flow, mcdi1_efficiency_active, mcdi2_efficiency_active):
"""
Simulates System 2 (MCDI before RO, with MCDI on Retentate side) for a single active contaminant.
code
Assistant
No – the two snippets are not the same model.
My first answer is a steady-state, single-pass RO mass-balance that only needs the flows that actually leave the system (permeate and drain).
• It ignores any internal recirculation because that recirculation does not change the final salt balance once the loop has reached steady state.
• It therefore gives 280 µS/cm for the permeate.
simulate_system1 is a recycle-loop model.
• It explicitly tracks the internal recycle flow (q_recycle) and the concentration that develops inside the loop (c_ro_feed_active).
• It uses the fixed RO feed flow (q_ro_feed_fixed = 4000 ml/min) and the fixed product flow (q_product = 500 ml/min) to compute q_recycle = q_ro_retentate – q_drain = 3500 – 200 = 3300 ml/min.
• With that large recycle, the concentration in the loop rises to ≈ 3 111 µS/cm, so the permeate becomes c_product = 3111 × (1 – 0.90) ≈ 311 µS/cm.
Hence the two approaches give different answers because they describe different physical assumptions:
• First model: “black-box” RO, only global flows matter.
• simulate_system1: detailed recycle loop with a specified internal flow.
If your real system has the 4 000 ml/min recirculation, use simulate_system1; if you only care about the overall balance, the simpler 280 µS/cm result is correct.