πŸ₯š Numerical Egg Boiling Simulation

You take an egg. You put it into hot water. You wait.

Why do all that hard work when you can simply write an overly engineered but still low-performing algorithm to numerically solve a set of partial differential equations so that your computer can simulate the same process for you?

That is exactly what I was wondering when I set off to write this thing.

The good news is that I made it available on the internet, so now your computer can boil an egg for you too! You get to experience the unfathomable joy of pressing a button instead of having to deal with all the unpleasantness of the real world β€” fetching and cleaning the pot, burning your fingers while peeling the egg, taking the trash out.

Oh, and yes, sadly, you do not get to taste the egg in the end.

πŸ”¬The geeky details

Solving the PDE

The set of partial differential equation (PDE) that describe how an egg is boiled comes from the delightful paper Periodic Cooking of Eggs (Nature Communications Engineering). Here they are:

ρcpβˆ‚Tβˆ‚t+βˆ‡β‹…(βˆ’kβˆ‡T)=0

βˆ‚Xβˆ‚t=Aeβˆ’EaRT(1βˆ’X)

T is the temperature, and X is the degree of cooking variable, which ranges from 0 (raw) to 1 (fully cooked).

The PDEs are decoupled, they can be solved independently. My algorithm first solves for the temperature, then computes the degree of cooking.

The temperature equation is the hard one. It is solved by using a Crank-Nicolson scheme in a custom made unstructured, rectangular mesh. You can inspect the code here. Due to the symmetry of the problem, only half of the egg is simulated (although for plotting purposes, the full egg is later shown).

Putting it in the browser

If you have run the simulation by clicking the button below, you may have noticed your computer struggling.

That is because it is indeed your computer the one doing the computations (as opposed to a computer in a server somewhere else).

But the code for the algorithm is written in Python, and it makes use of a couple of handy libraries (NumPy and SciPy) to be able to solve systems of sparse matrices. And I don't know if you knew, but browsers do not speak Python, they only speak Javascript. So how is your computer understanding the Python code at all? By using Pyodide.

Things to notice

  • The yolk cooks at a lower temperature than the white. For this reason, part of the white is still not completely cooked when the yolk is done.
  • This ideal, numerical egg gets cooked slightly faster than the real world eggs do. This is partly because this egg has no shell, and so the initial state of the egg in the simulation is one in which the temperature of the water bath the is immediately transferred to the egg white.

βš™οΈ Simulation Parameters

7
1.5
20
0.05
100
4
Installing the boil-an-egg Python package...

🌑️ Temperature Distribution

🍳 Degree of Cooking