(Some) LLMs (with some help) can now do a toy simulation of a droplet in shear

One area where LLMs like OpenAI’s ChatGPT, Anthropic’s Claude etc are already making a splash, is coding. But scientific coding is tricky, even small errors can result in the code crashing or producing nonsense. Last year, a student working with me found that even for a relatively simple code, the results were often very wrong. But that was last year.

This year, ChatGPT, with some prompting but only minimal tweaks by me, produced the code that simulated the liquid droplet shown in the YouTube. The code uses the Lattice Boltzmann (LB) technique, together with the approach of Swift and coworkers to model the separation of one liquid in another.

I am pretty impressed, LB simulations can be tricky for humans like me to get right. The code* imposes shear by a simple but unphysical hand-of-God shearing motion but apart from looks pretty good. Interestingly, it did not produce the code all in one go but started with simple code, told me to run it (which I did) to check it worked, and then built on it. The first attempt to introduce shear failed but second attempt worked. This problem was easier to fix as I had already checked the earlier simple code.

I also tried Google Gemini but that code was hopeless, the LB simulation crashed. Anthropic’s Claude went all agentic and did some checks by running the code, which I thought was impressive. But although the very simplest code worked, to add shear it then complicated the code greatly and that code never worked. I also tried Z.AI but that code also did not work.

So, when the LLM follows good programming practice and starts simple then builds up, while asking you to check as you and it go along, then LLMs are getting pretty capable at producing simple scientific codes. And although I did not check, maybe with the right prompts you can persuade Gemini, Claude etc to go step by step, and so get the right answer.

* The code is here in a little zipped folder. Note that I don’t guarantee it is bug free, and I don’t think ChatGPT does either…..

Leave a Comment