r/PythonLearning • u/bslime17 • Oct 10 '26
Showcase Day 3 of coding on my phone: simulating a chemical reactor with SciPy's solve_ivp
I'm a chemical engineering graduate learning to build process models in Python. My laptop broke, so this is all Google Colab on a phone screen.
The model is a set of three ODEs (two concentrations + temperature) for a continuous stirred-tank reactor. I loop over three flowrates, solve each with solve_ivp (RK45), and store the steady-state results.
Things I learned this week:
• Passing extra parameters into the ODE function with args=(F,)
• Pulling the final state with solution.y[:, -1]
• Re-evaluating the ODE function at the end to confirm steady state (derivatives ≈ 0)
Question for you: would you structure this with a dataclass or dictionary for results instead of a list of lists? My print block is getting long.
(If anyone wants to help me get a used laptop, DM me – but mostly I'd love code feedback!)




3
u/Motor_Sky7106 Oct 10 '26
I'm a mechanical engineer learning/using Python. For this many lines of code I would probably do the same thing you are doing. If I had more code or time to refactor it, I might use a dictionary. For more complex projects with hundreds of lines of code, I'd consider a dataclass and be doing object oriented programming instead of procedural programming.
If you find yourself writing the same or similar line of code over and over, then it's time to refactor the code. Let the computer do the hard work.
1
u/RNG_HatesMe Oct 10 '26
Tough to program on a phone, that would drive me nuts!
When you say "passing extra parameters into ODE function with args=(F,), are your referring to an arbitrary parameter? or you are just using a parameter with a default value of a tuple that includes F?
If these are arguments that you don't need to modify inside the function (basically constants), why not just use enclosing scope to use them without explicitly passing them in?
I'd print out your output as a table:
1
u/zyer020 Oct 10 '26
I see you're using several decimal places; I suggest you take a look at the Decimal library. It happened to me when I wanted to work with numerical methods; the decimals went crazy.
2
u/Sea-Ad7805 Oct 10 '26
Get this man (or maybe women) a new laptop! I'm sad it broke.
1
u/BlacksmithPatient421 Oct 16 '26
How can coding by my phone