Issue 115 – September 24, 2022

Three Tiny Tips: Part 08

Hey there,

It’s Robin from CFD Engine & it’s Tiny Tips time again – three OpenFOAM features that you might’ve missed, but are worth adding to your toolbox.

On the menu this week, we have a great option for comparing dictionaries, an easy way to generate mesh-quality fields that can be plotted in ParaView & a feature that identifies (& removes) those pesky bits of mesh where a single cell bridges the gap between two surfaces.

Let’s get into it…

blockLevel

I think it was snappyHexMesh that said…

“If you no longer go for a gap which exists you are no longer a meshing tool.”

Or maybe it was Ayrton Senna 🤔 but if there’s a gap, then snappyHexMesh will find it & mesh it. Unfortunately, it doesn’t always leave nice mesh behind.

We can use refinement zones (or add some gap refinement rules) to capture the bits we’re interested in. But what about the gaps we wish weren’t there?

Especially the ones where we end up with a single cell bridging between two surfaces – a recipe for divergence & really hard to identify using checkMesh.

Thankfully snappyHexMesh has a feature to help 🙏

By adding the blockLevel keyword to our snappyHexMeshDict (in the refinementSurfaces section) we can get SHM to check for areas where the mesh bridges across a gap & block off any gaps that don’t have at least 2 cells across them.

It doesn’t seem to add too much to the run time (YMMV) plus it received a tweak in v2206 to reduce its memory usage.

It’s a useful feature that helps us avoid some tricky-to-spot bad cells – check out the little demonstration case in the tutorials directory to get started.

checkMesh fields

Did you know that checkMesh can write field data for pretty much all of the quality checks it performs?

checkMesh -writeAllFields

You can plot the data in ParaView (just like you would with p or U) & use it to see where your mesh might need some work. You get all of the usual suspects (non-orthogonality, skewness, aspect-ratios etc) plus a few handy extras.

Those extras include fields for cellZone, faceZone & region which allow you to colour cells by their zone/region – great for troubleshooting any zoning problems in your mesh recipe.

There’s also a handy wallDistance field (only written out if you have a wallDist method in your fvSchemes file) which can be used to develop/troubleshoot distance-based refinement zones.

A useful collection of fields which can really help you visualise (& improve) your mesh quality.

Spot the difference

Ever want a quick (readable) summary of the difference between two OpenFOAM dictionaries?

You could do it with the Unix diff command, but foamDictionary does it much better.

Rather than just comparing the contents of two files, foamDictionary parses & understands them, allowing it to flag functional differences & ignore things that don’t affect your simulation (like changes to formatting or a different version number in a file header).

What am I on about? Here’s a (trivial) example. Below are snippets from two functionally equivalent fvSchemes – the first one is written out in full & the second one uses a local variable to set the turbulence schemes (‘cos, why not?).

A pair of functionally equivalent fvSchemes snippets

diff -w fvSchemesB fvSchemesA would flag that these files differ & show us the following changes 🤔

Output from the Unix diff utility

Whereas foamDictionary -diff fvSchemesB fvSchemesA wouldn’t output anything, they’re functionally equivalent after all 👍

It’s directional too, if I swapped the order foamDictionary -diff fvSchemesA fvSchemesB then we’d get this output:

Sample foamDictionary -diff output

Where it’s showing us the new variable, along with the additional context that it’s in the divSchemes section 👏

I tend to use these two diff tools in combination when checking cases.

I use diff to compare the files between two cases, flagging those which have changed, & then I use foamDictionary -diff to see if those changes were important.

Great for when your colleague has been improving cases in your absence.

That’s a wrap

Another trio of tiny OpenFOAM tips – two that help you improve your mesh quality & one that helps you to spot the difference between OF dictionaries.

Are they new to you? Do you think they might be useful? Or are they already part of your toolkit?

Let me know if you try them & feel free to send me any tiny OpenFOAM tips of your own so that I can share them with the class.

Until next week, stay safe,

Signed Robin K