Issue 018 – October 24, 2020

Delta plots & the joy of figuring stuff out

Hey there,

It’s Robin from CFD Engine, back with your weekly CFD note. I want to share a little CFD win this week – delta plots – let’s go…

You know when people show you their baby/pet/baking pictures & you have to respond like it’s the cutest/cleverest/tastiest little specimen you ever did see? Well, this email is just like that.

I figured something out, something that’s been niggling me for a decade & I’m going to tell you about it…1) ‘cos I’m super-happy that I figured it out & 2) ‘cos that’s what this email is all about – sharing stuff that you might find useful.

Indulge me 🙏

Let me rewind to my first CFD job. We had a small team of developers who could conjure up new CFD tools as if by magic. We had all sorts of cool stuff. Admittedly, some things were more useful than others, but nevertheless, it was still like magic.

Fast-forward to me going solo. I’m not a developer, so rolling my own versions of those tools wasn’t quite so magical. I had to get creative. Duct taping standard OpenFOAM/ParaView/Unix tools together in new & imaginative ways was (& still is) the order of the day.

Some things were a doddle. Some things were rendered obsolete by new OpenFOAM functionality. But some things eluded me. One of the most elusive was “the delta plot”.

The delta what?

I’m guessing you already know, but just in case – a delta plot takes common(ish) surfaces from two different cases, calculates the difference between their two flow fields & uses this “delta” to illustrate where the flow has changed.

It’s a useful alternative to playing spot-the-difference with two almost identical plots 🧐

It’s not restricted to surfaces, you can also do it with volumes. But let’s not walk before we can run. Surface deltas will do for me, for now.

ParaView

You can get pretty close using ParaView, combining the Resample with Dataset & Append Attributes filters, but I never got great results. I always ended up with lots of faces that couldn’t be matched & very blotchy-looking plots.

mapFields to the rescue (sort of)

The mapFields utility in OpenFOAM is intended (AFAIK) to be a PRE-processing tool, used to map results from one mesh to another. Think, transferring the results from a coarse-mesh onto a finer-mesh, to be used as the starting point for a new run. Could it be used to delta surfaces? 🤔

Turns out, it can. But it’s super-slow on a “big” mesh (whatever “big” means). You can make (& drink) several cups of tea while it crawls over your whole volume. A bit much if you just want surface deltas.

So, I tweaked the workflow to give it less to do & now your deltas will be done & dusted before the kettle’s even boiled. It goes like this…

Pseudocode

  • Choose two solved cases (they can have different volume meshes)
    • A Baseline case that will be your Source
    • A Changed case that will be your Target
    • Delta = Changed – Baseline = Target – Source
  • In your baseline/source case:
    • Use topoSet to select the cells that border the surfaces you’re interested in, using its patchToSet action
    • Subset your volume mesh –subSetMesh– so that only those selected cells remain (don’t use -overwrite 😬)
    • Reconstruct this new little mesh & the data (this isn’t strictly necessary, but it speeds up mapFields, later on).
  • Rinse & Repeat in your changed/target case.
  • Use mapFields to subtract the baseline/source fields from the changed/target fields, leaving you with a delta for each of the variables in your case.
  • Export the surfaces &/or post-process your changed/target case as normal – now with delta flow fields 🤩

Could it be slicker? Definitely.

Is it as nice as having a custom-built tool? Nope.

But…it’s quick, it’s easily scripted, there are no new tools to install or maintain & the output looks great – I’ll take it.

Drop me a note if you want details about the actual commands & dictionaries involved.

The joy of figuring stuff out

One of the great pleasures of working with OpenFOAM is the joy of figuring stuff out. Those days where you sit down with a goal & the briefest idea of how you’re going to get there. Then, after a bit of noodling (& a bit of Googling) you’ve figured it out & it’s working like a charm. Winner.

The flip side, the days where you lose, when you’re unable to beat your CFD toolkit into submission, they’re not so great.

All the more reason for us to celebrate our little wins 🎉

Have you felt the joy of figuring it out? Or are you on a losing streak at the moment? Let me know your last little win, so we can celebrate together. I’m always interested to hear about a nifty new workflow or a function that I’ve missed. I stumbled across 3 new-to-me OpenFOAM functions this week alone – they’ll be in future emails if they work out as hoped 🤞

Until next week, celebrate your little wins,

Signed Robin K