Issue 088 – March 19, 2022

Three Tiny Tips: Part 06

Hey there,

It’s Robin from CFD Engine & it’s “three tiny tips” time again – if you don’t know the drill, it’s three snippets of OpenFOAM esoterica that might be useful in your day-to-day work.

File them away in your mind palace for later (or share them with your colleagues for extra geek points).

This time we’re looking at a quick way to generate points for your blockMeshDict, a(nother) way to average forces & foamDictionary -expand (again).

Let’s go…

surfaceGenerateBoundingBox

A neat tool from cfMesh that snappyHexMesh users can borrow to create points for their blockMeshDict.

For context: cfMesh doesn’t use blockMesh – instead, you include the outer bounds of your domain with your input geometry & it figures out the background mesh for you. This tool helps with that – it takes an input geometry (plus some offsets), creates surfaces for the outer domain & bundles everything into a new file.

We’re not going to use that new file, but we will steal its bounding box calculation. You run it like this:

surfaceGenerateBoundingBox <input> <output> <x-offset> <x+offset> <y-offset> <y+offset> <z-offset> <z+offset>

Give it an input geometry, an output file and 6 offsets (positive distances from your input geometry). For example:

surfaceGenerateBoundingBox aThing.obj outputBBox.obj 1 1 1 1 1 1

would produce a bounding box, centred about aThing.obj, with a 1m offset in all directions.

You could read the output file into ParaView & pick off the corner points for your blockMeshDict, but my preference is just to use the Generated bounding box info that it prints to the terminal, e.g.

Generated bounding box (-5.5 -4.0 0.0) (18.8 4.0 3.5)

Note:

  • It doesn’t do negative offsets, so you can’t create a domain boundary that intersects your input geometry.
  • The output surfaces are always Cartesian aligned.
  • It’s a cfMesh tool (it ships with ESI/OpenCFD releases, but it’s also available from cfMesh.com)

Give it a try next time you need some quick points for a blockMeshDict.

Averaging Forces

This one has been bugging me for a while…

I’ve written about using valueAverage to calculate rolling averages during a run, but I could never figure out how to average the output of the forces functionObject (as opposed to the coefficients from forceCoeffs).

I get it, they’re the same forces, but I prefer Newtons in reports so this is a nice-to-have (for me). It turns out it’s pretty straightforward, it’s just the names that were throwing me off.

When you’re telling valueAverage what to average you need these keywords:

  • use normalForce to average the pressure forces;
  • use tangentialForce to average the viscous forces;
  • use porousForce to average (good guess) the porous forces;
  • they’re all available as moments too, i.e. normalMoment etc

It’s a shame there’s no totalForce option, but I can just about manage that calc 🤔

If you get warnings of Unprocessed fields in your log files then you’ve made a mistake somewhere. Check your force functionObject is referenced in your valueAverage definition & that you haven’t made a typo in your variable names.

It’s only in the ESI/OpenCFD release (AFAIK) but I think it’s a welcome alternative to wrangling the output of forces into Excel, Awk or Python.

foamDictionary -expand

Use foamDictionary -expand to turn a series of interlinked files into a single dictionary to see what’s actually going on &/or customise it.

OpenFOAM ships with a directory full of sample dictionaries for doing common tasks – $FOAM_ETC/caseDicts – many of which are broken down into simple, re-usable files that reference each other using #include statements.

For example, take pressureDifferencePatch from the ESI/OpenCFD release – it’s a simple 3-line file that asks for the names of two patches so that it can calculate the pressure difference.

That calculation needs a lot more info than just two patch names, and it pulls that info from four other files.

You don’t need to know that to use it, but if you want the full picture of what’s going on behind the scenes (or you want to customise it) then you have to visit all five files 🤯

Or maybe not…

foamDictionary -expand will make that round trip for you, outputting the end result & showing you exactly what’s going on after all the #include references have been parsed.

It’s a great way to reveal the true structure of complex functions & to use the output as a base for your own custom functions.

That’s all folks

There you have it, three tiny tips that might make their way into your CFD toolbox – a quick bounding box, how to average forces in Newtons & a way to expand nested function files 👍

Did you know them? Do you use them? Do you have some gems of your own?

If there’s something you’d like me to share with the class, then drop me a note & I’ll add it to the list for the next instalment.

Until next week, stay safe,

Signed Robin K