| name | chemical-engineering |
| description | Chemical engineering fundamentals including reaction engineering, separation processes, thermodynamics, process control, and plant design |
| license | MIT |
| compatibility | opencode |
| metadata | {"audience":"engineers","category":"engineering"} |
What I do
- Design chemical reactors and reaction systems
- Calculate mass and energy balances
- Design separation processes and equipment
- Model thermodynamic properties and phase equilibria
- Specify process equipment and piping
- Design process control systems
- Optimize chemical processes for efficiency
When to use me
When designing chemical processes, reactors, separation systems, or any process involving chemical transformations and separations.
Core Concepts
- Mass and energy balances
- Chemical reaction kinetics and reactor design
- Thermodynamics and phase equilibria
- Heat and mass transfer
- Separation processes (distillation, absorption, extraction)
- Process control and instrumentation
- Process safety and hazard analysis
- Equipment sizing and selection
- Process economics and optimization
- Transport phenomena
Code Examples
Mass and Energy Balances
from dataclasses import dataclass
from typing import List, Tuple
import numpy as np
@dataclass
class Stream:
name: str
mass_flow: float
component: str
mass_fraction: float
def mass_balance(
inlet_streams: List[Stream],
outlet_streams: List[Stream]
) -> Tuple[float, float]:
"""Calculate total inlet/outlet and component balances."""
m_in = sum(s.mass_flow for s in inlet_streams)
m_out = sum(s.mass_flow for s in outlet_streams)
return m_in, m_out
def component_balance(
streams: List[Stream],
component: str
) -> Tuple[float, float]:
"""Calculate component mass flow."""
inlet = sum(s.mass_flow * s.mass_fraction
for s in streams if "inlet" in s.name.lower())
outlet = sum(s.mass_flow * s.mass_fraction
for s streams s.name.lower())
inlet, outlet
() -> :
O2_stoich = * fuel_carbon + * fuel_hydrogen + fuel_sulfur
O2_actual = O2_stoich * ( + excess_air)
air_required = O2_actual /
{
: O2_stoich / ,
: air_required,
: air_required + - fuel_carbon - fuel_hydrogen - fuel_sulfur
}
fuel = {: , : , : , : }
air = combustion_air_requirement(fuel[], fuel[], fuel[], )
()
()
Reactor Design
@dataclass
class Reaction:
A: float
Ea: float
dH: float
order: float
def arrhenius_rate(
T: float,
A: float,
Ea: float,
R: float = 8.314
) -> float:
"""Calculate rate constant using Arrhenius equation."""
return A * np.exp(-Ea / (R * T))
def cstr_design(
Fa_in: float,
X: float,
rA: float
) -> float:
"""Calculate CSTR volume."""
Fa_out = Fa_in * (1 - X)
Fa_avg = (Fa_in + Fa_out) / 2
return Fa_in * X / rA
def pfr_design(
Fa_in: float,
X1: float,
X2: float,
k: float,
order: int
) -> float:
"""Calculate PFR volume using numerical integration."""
from scipy.integrate import quad
if order == :
():
/ (k * ( - X))
:
():
/ (k * ( - X)**order)
V, _ = quad(integrand, X1, X2)
Fa_in * V
() -> :
T_in - X * dH * MW_avg / Cp_avg
Fa_in =
X =
T =
reaction = Reaction(A=, Ea=, dH=-, order=)
k = arrhenius_rate(T, reaction.A, reaction.Ea)
V = cstr_design(Fa_in, X, k * ( - X) * )
()
()
Distillation Design
def mccabe_thiele_stages(
xD: float,
xB: float,
xF: float,
q: float,
alpha: float,
reflux_ratio: float
) -> dict:
"""McCabe-Thiele stage calculation."""
R = reflux_ratio
R_min = (xD - yF) / (yF - xF) if alpha > 1 else float('inf')
yF = alpha * xF / (1 + (alpha - 1) * xF)
N_min = np.log((xD / (1 - xD)) * ((1 - xB) / xB)) / np.log(alpha)
stages = N_min * (R / (R - R_min + 0.01)) if R > R_min else 1
return {
"minimum_reflux_ratio": R_min,
"minimum_stages": N_min,
"actual_stages": int(stages)
}
def heat_reboiler_duty(
L: float,
lambda_v: float,
) -> float:
"""Calculate reboiler heat duty."""
return L * lambda_v
def diameter_column(
V: float,
rho_v: ,
rho_l: ,
F_factor: =
) -> :
V_surf = V / / (np.pi / )
D = np.sqrt( * V_surf / (F_factor * np.sqrt(rho_v / (rho_l - rho_v))))
D
column = mccable_thiele_stages(
xD=, xB=, xF=, q=, alpha=, reflux_ratio=
)
()
()
Heat Exchanger Design
def lmtd(
Th_in: float,
Th_out: float,
Tc_in: float,
Tc_out: float
) -> float:
"""Calculate log mean temperature difference."""
dT1 = Th_in - Tc_out
dT2 = Th_out - Tc_in
if abs(dT1 - dT2) < 0.01:
return (dT1 + dT2) / 2
return (dT1 - dT2) / np.log(dT1 / dT2)
def heat_exchanger_area(
Q: float,
U: float,
lmtd: float
) -> float:
"""Calculate heat exchanger area."""
return Q / (U * lmtd)
def overall_heat_transfer(
hi: float,
ho: float,
k: float,
t: float,
fouling: float = 0.0001
) -> float:
"""Calculate overall U value."""
return 1 / (1/hi + fouling + t/k + fouling + 1/ho)
def shell_and_tube_pressure_drop(
N: int,
L: ,
V: ,
rho: ,
f: =
) -> :
* f * (L / ) * (N * V** / ( * rho))
Q =
U =
LMTD = lmtd(, , , )
A = heat_exchanger_area(Q, U, LMTD)
()
()
Process Safety Calculations
def relief_valve_sizing(
P_set: float,
P_atm: float,
A_required: float,
Kb: float = 1.0,
Kd: float = 0.975,
Kv: float = 1.0
) -> float:
"""Calculate relief valve orifice area (API 520)."""
A = (m * Kb) / (C * Kd * Kv * P_set) if P_set > P_atm else A_required
return A
def toxicity_limit(
LC50: float,
exposure_time: float,
LCLo: float = LC50
) -> float:
"""Calculate acceptable exposure limit (AEL)."""
return LC50 * (8 / exposure_time)**0.5
def flammable_limit(
LFL: float,
UFL: float,
concentration: float
) -> str:
"""Check if mixture is flammable."""
if LFL <= concentration <= UFL:
return "FLAMMABLE"
elif concentration < LFL:
return "TOO LEAN"
() -> :
mass * efficiency * /
mixture = flammable_limit(LFL=, UFL=, concentration=)
()
Best Practices
- Always include safety factors in equipment sizing
- Perform HAZOP analysis for new process designs
- Consider environmental regulations in plant design
- Use simulation software (Aspen, HYSYS) for complex calculations
- Account for worst-case scenarios in relief system design
- Consider operability and maintainability in equipment layout
- Document all design basis and assumptions
- Use standard equipment sizes to reduce costs
- Consider energy integration and pinch analysis
- Validate calculations with hand calculations and simulations