Hey there,
It’s Robin from CFD Engine & after last week’s email I reckon we’re all set to deliver nicely-named .obj
files to snappyHexMesh
.
But what about when things go wrong? Someone’s made a typo in one of our patch names & we only spotted it after meshing 🤦♂️ It’s going to mess up our BCs, forces & post-pro, we can’t just leave it.
Do you know how to quickly change the name of a patch (or patches), on any sized mesh, even in parallel?
Yes? Awesome, see you next week 👋
No? Let’s go…
What’s in a name?
I wrote about the importance of naming things a while ago, it’s the foundation of automating your process. You can use part names to…
- control edge lengths, volume refinement & layering in
snappyHexMesh
; - automatically assign boundary conditions;
- define your monitors (forces, mass-flows, moments etc);
- determine which bits are shown/hidden/exported in your post-pro;
You can build a really slick CFD process around a consistent naming convention, which makes it all the more annoying when a typo gets in the way – let’s fix it.
Easy Mode
If you’re working with a serial (non-decomposed) mesh, then just open /constant/polyMesh/boundary
in your text editor, fix that typo & you’re done 👏
Hard Mode
But, if you’re dealing with a decomposed case spread across loads of processors (& you don’t fancy grappling with sed
) then you might appreciate an alternative method.
Unfortunately, there’s no “rename my patch” functionality in OpenFOAM (AFAIK). Instead, we need to create a new patch, move the faces over from the misnamed patch & then delete it 😬
But don’t worry, createPatch
has us covered…
Save the above text in /system/createPatchDict
& run createPatch -overwrite
in parallel (here’s a copy-&-paste-able version to save you some typing).
Take it for a quick test run on any old blockMesh
– just edit your createPatchDict
to change one (or more) of its boundary names & see what happens.
Note: You can check patch names any time using patchSummary -expand
Gotchas
A couple of things to remember…
Our new patch doesn’t inherit anything from the old one, so we need to specify its type
(at a minimum) & whether it should be in any groups
(optional).
You might also need to reset your boundary conditions after a name change. It depends how you manage your BCs, but it’s always worth checking.
Finally, if you want to leave out the -overwrite
switch until you’re happy it’s all working nicely, then go for it.
There you have it
That’s how to rename a patch in OpenFOAM using createPatch
.
Keep this for when your colleague next makes a typo, so that you can swoop in & save the day.
As an aside, this is exactly the kind of thing that gives people the hump with OpenFOAM. Should I be able to write an email about something as simple as changing a patch name? Probably not, but here we are.
Any other “simple” ops I should write about?
Or do you have a better way of renaming patches?
Drop me a note – I’m always keen to learn so that I can share it with everyone else 🙏
Until next week, stay safe,