Computers do love physics...
(Just not always the simulation code)
I began my journey into programming physics engines and solvers about 7 years ago now, whilst an active Senior Mechanical Engineer in London, UK.
It was excruciatingly painful but equally rewarding in a variety of ways…
(It definitely tested my resolve and commitment to learn!)
It led me down various rabbit holes (which I’ve not quite climbed out of years on!):
Computational mechanics
Geometry mathematics
Graphics pipelines
CPU and GPU architecture
Software patterns
Debugging code
Performance tuning
…
Honestly, it’s a lot to take on, especially when balancing a full-time job and family commitments.
But I did it anyway and I’m glad I did.
Here’s an earlier engine I built for granular physics in C++, (click to view the video):
I’ve always looked at the career change as more of an adaptation and augmentation of my Engineering design skills.
I can now develop useful digital tools, potentially improving the design and simulation tools out there!
This was and is still a huge plus for me.
A little coding experiment…
I keep pushing myself to keep learning and developing my skills as a professional Software Engineer in this space.
This week I wrote a small program, just to highlight the difference optimised code makes to a theoretical solver code.
Program 1 (Unoptimised memory layout)
Total time for 100 time steps: 636.793 ms
Sample Particle [0] Position: (5, 45.046)
Program 2 (Optimised memory layout)
Total time for 100 time steps: 136.881 ms
Sample Particle [0] Position: (5, 45.046)
That’s a 4.5x speed-up by considering how to layout particle data in RAM!
OpenFOAM code

It’s was released over 20 years ago and written in an C++ object-oriented.
For a variety of reasons It’s slow, but remember the fundamental physics don’t really change.
I love the code for what it is and it’s very good as a generalised system solving fluid dynamics problems in Research and Engineering.
It reminds us that the period of invention, state of technology and collaborative efforts push human community forward.
Here’s a shout-out to OpenFOAM and all those involved…Kudos for bringing a much-loved and respected code-base to the people that need it!
See you soon. 👋
Nasser


