Hey there,
It’s Robin from CFD Engine & I’m guessing that you’ve heard plenty about ChatGPT by now – the AI hype-machine that’s read the internet, understood some of it & stands ready to do your homework.
It’s built to generate text. OpenFOAM is text-based. Can we put it to work?
Short answer: Yes, we can – but maybe not in the ways you’d expect.
This is a non-exhaustive, easily-refutable, 4min summary of my experience testing ChatGPT (the free version) to see whether it can be my virtual assistant. Your mileage may vary.
Let’s go…
What is ChatGPT?
Let’s take the “explain it to me like I’m 5” approach here…
GPT is a large language model, essentially an overgrown version of the predictive text on your phone. But, instead of guessing the next word, based on what others have typed, it can generate pages of text, based on everything that has ever been written (or at least the bits that have been digitised).
ChatGPT is a chatbot that makes interacting with GPT feel like texting a know-it-all buddy who has an answer for everything.
You can ask it questions, but you can also prompt it to do longer tasks like writing code, LinkedIn posts, book reports, or Saturday emails 🫢
The output depends on the quality of your question & the quality of the training data it has seen on that subject.
It excels at things like “Write a 250 word synopsis of The Catcher in the Rye at a 9th grade reading level.” It’s a decently defined task & it’s seen tonnes of training data.
Throw in a few follow-up prompts asking about the main characters & their relationship to the protagonist & you have a nice little book report. One that isn’t copy-pasted from a particular source & that’s done in about 5mins – R.I.P. school homework.
But here’s the rub, this thing is confident (just like your know-it-all mate) & it will give you a plausible answer on almost any topic. But you’ll only know if the answer is correct if it’s something you already know (or if you can easily test it) 🤔
Which brings me to the OpenFOAM stuff…
Mind Blown
Before I dunk on it, let me just say that I’m surprised that this thing understands anything at all about OpenFOAM.
The fact that it wrote me a working blockMeshDict
and controlDict
(including some explanation of what the settings do) blows my mind 🤯
Beyond that, things started to get a little messy. The answer to “How do I run snappyHexMesh
in parallel?” was almost right, but it included extra steps & the order was messed up.
Convincing, but not likely to get you meshing in parallel.
I got similar results when I asked it how to use certain function objects, or how to use some snappyHexMesh
features – always plausible, but not quite right.
I’m guessing this is down to a lack of good training data – fishing the right answer out of a 6-page, CFD Online thread is probably as hard for a GPT model as it is for us.
Is it any use?
I currently wouldn’t bother using it for OpenFOAM tasks, but there are plenty of other ways it could boost your CFD productivity…
Scripting: describe what you want your script to do, what language &/or tools you want to use & let it have a go at scripting it up. It’s pretty easy to test whether it works as intended & there’s no real time lost if it doesn’t.
Problem Solving: related to the above, you can ask it how to do a task & provide some extra context. For example: you could ask “How do I average the columns from a text file that looks like this?” & then paste in the first ten lines from a forces.dat
file – boom, instant force averaging script.
Explaining Code: if you’ve ever wondered what the cd "${0%/*}" || exit
does on the first line of the tutorial Allrun
scripts (or what that weird regex does that your ex-colleague wrote) then just ask ChatGPT.
API Fun: You can do all sorts of things from the command-line if you know how to reach out to different APIs. “How do I append data to a Google Sheet from the command-line?” or “How do I send a WhatsApp message from the command-line?” could produce some neat additions for your run scripts.
Finding Libraries, Code or Tools: “What command-line tools can I use to…” or “What libraries can be used to do…in Python?” is much quicker than browsing GitHub repositories or digging through umpteen articles.
And on, and on…
Worth a go?
I reckon it’s definitely worth playing with (if you haven’t already).
It’s a really fast moving space, but these AI tools aren’t coming for your job (yet). That said, getting them to do useful things will be an important skill for all of us, might as well start practising.
Here’s is a fun little story about a fun little game, that demonstrates what ChatGPT can do if you can coax it properly.
Also, check out this neat tool if you want to use ChatGPT from the command-line (h/t Ben 🎩).
Have you tried it? Are you a better AI whisperer than me? Did you discover some OpenFOAM tasks that it’s really good at? Let me know, I’m keen to level-up my prompting skills.
Until next week, stay safe,