Check out the code for this project here
Building a Chemical Reactor Model in C sharp
Before I started my degree I wanted to give myself a taste of chemical engineering so I decided to undertake a simple project of simulating a continuous flow chemical reactor with hydrochloric acid and sodium hydroxide. I decided to use C# as it was a language that I had very little experience with so wanted to try and learn more how to use it as a developed the project.
(credit)
The Architecture of the Simulation
As C# is an object oriented language I decided to make classes for each of the components in the simulation:
TankandFinalTankPipePumpReactor
To model how the fluids behave, the Pump class calculates the mass flow rate by solving a quadratic equation based on the simple Bernoulli equation and the pumps power. It calculates the gravitational resistance (based on elevation changes) and the fluid friction inside the pipes (based on an assumed friction factor).
The program uses a custom TimeStep class to calculate how the system changes over time. It iteratively calculates the fluid volumes in the tanks, pipes, and the reactor.
In the reactor are simulating a classic simple neutralisation reaction:
At the moment the code calculates the concentration of the products and reactants based on the reaction rate constant (), I am just assuming this remains constant which is highly inaccurate.
Current Limitations
At the moment the simulation is just numerical. All it outputs is a large list of arrays. While this is functional and could still be useful it is not very entertaining or engaging to use. Therefore something that would be good for me to add would be some kind of visualisation. Even if this is just a simple graph to help visualise it that would be good. However, something like a diagram of the pipes and tanks filling up with different colours for the different chemicals could be more engaging.
What's Next?
Here are the primary ways I would improve and expand upon this project if I go back to it:
- Graphical Visualizations: As spoken about before adding something to visualise the output. To create the fancier visualisation that I mentioned using a game engine like Unity of Godot would probably be the best. This is also ideal as these platforms support C# well.
- Thermodynamics: In reality this reaction releases alot of heat so including some thermodynamics calculations would make it much more accurate. Currently I am just assuming the temperature remains constant and therefore also which it wouldn't do.
As well as being very enjoyable and giving me a good standing in the basics of Chemical Engineering helping to prepare me for my degree this helped me to develop my understanding of C# and also programming in general.