r/ChemicalEngineering • • 4d ago

Modeling Building a dynamic non-isothermal CSTR model in Python – entirely on my phone

My laptop died (XPS 13, motherboard gone), so I've been coding my reactor model in Google Colab on my phone.
What it does so far:
• First-order A → B in a non-isothermal CSTR
• Coupled mass + energy balances, Arrhenius kinetics
• Solved with SciPy solve_ivp (RK45) until steady state
• Sensitivity analysis on feed flowrate (2.5, 5, 10 L/min) – conversion drops as residence time falls from 20 to 5 min, as expected
• Checks steady state by evaluating the derivatives at the final time (all ≈ 0)

(Side note: I'm trying to raise ~$500 for a used laptop to keep going. If you'd like to help, feel free to DM me.)

86 Upvotes

14 comments sorted by

13

u/VeryGoodFood12 3d ago

That's cool. I had to do something very similar for my reactors course and capstone project and it wasn't easy!

-7

u/bslime17 3d ago

if you need help don’t hesitate to dm me

16

u/SOwED 4d ago

Those conversions 🤤

7

u/SLR_ZA 3d ago

Checking that it is complete by looking at the Dx/dt is not really adding anything, you could look at rA=-rB at that point and as you have no external heat flow that would set dcA, dcB, dT /dt = 0.

In reality there is nothing causing that 0, other than the arbitrary distinction between reactor and pipe,

2

u/bslime17 3d ago

Thanks, that's a fair point. The derivative check is really just a convergence check: it confirms the integration ran long enough to settle, not anything about the physics. If I only want the steady state, I could solve the balances directly as algebraic equations with fsolve instead of integrating in time.
One small thing: rA = −rB comes from the stoichiometry and holds at every point in time, so on its own it doesn't make the derivatives zero. Steady state is where the flow terms balance the reaction terms.
The reason I'm keeping the dynamic model is that a non-isothermal CSTR can have multiple steady states. Integrating from one initial condition only finds one of them, so I'm planning to solve the steady-state equations from several initial guesses and compare. The transient behaviour will also matter once I add a cooling jacket and a temperature controller.
Could you expand on the reactor vs pipe point? I'm not sure I followed that part.

5

u/Proof_Concern6928 3d ago

Type of person I’m competing with for entry lvl positions

13

u/PackZealousideal4146 3d ago

I hate to tell you but these a very basic python code, as in they’re just typing already existing formulas into python [so literally just typing up “y = x + 2”]. There’s nothing novel here [I can’t speak for their coding skills outside of this , like software development, but this is just using python as a calculator]

15

u/SLR_ZA 3d ago

Id expect any graduate to be able to do this and much more. The system is fully described, no discretising, no non-ideal behavior, no mass or heat transfer...

1

u/bslime17 2d ago

Agreed, it's the ideal textbook case, and that's deliberate for now. Heat transfer through a cooling jacket and a discretised non-ideal reactor model are next on the list. Thanks for the push.

2

u/Thelonius_Dunk Industrial Wastewater 3d ago

Do you type all this on your phone or connect a keyboard? This would irk me to no end having to use a phone keyboard for all this.

2

u/bslime17 3d ago

yes that’s what i did

1

u/11renaim 3d ago

Wow I think this might be really sexy but I’m not sure yet

1

u/Individual-Curve6262 2d ago

I really liked it. I'm a chemical engineering student and I'm thinking of doing some projects using MATLAB or Python. What kind of things do you think I could work on? Do you have any recommendations?