Hey there,
It’s Robin from CFD Engine & it’s tiny tips time again – the one where I share three handy OpenFOAM features that you might’ve missed.
On the cards today, we have a switch that tells foamToVTK
to bundle all of your surfaces into a single file, a way to offset, scale & transform surface data during export & a function object called norm
that normalises stuff 🤓
I think these are ESI/OpenCFD-only features, but I might be wrong.
Anyway, on to the tips…
foamToVTK
switches
If you have A LOT of named boundaries in your model (like I do) then a regular foamToVTK
export will generate just as many .vtp
files. Not a problem for everyday use, but less than ideal for sending to clients, or for archiving.
Not to worry, foamToVTK
has us covered – just add -one-boundary
to your foamToVTK
command-line & it will merge all of your boundaries into a single .vtp
file.
But what if you don’t want ALL of the boundaries. What if you want to ignore inlets, outlets, farfield etc? Or if you just want a subset of your boundaries?
In that case we can use -patches
(&/or the hidden -exclude-patches
) to filter our selection. So, something like…
foamToVTK -patches '(motorBike.*)' -one-boundary -latestTime -no-internal
…would export all of the motorBike
surfaces (squished into a single .vtp
file) using the latest time step, without exporting the volume data.
It’s pretty quick, it works in parallel & there’s no dictionary required.
5/5 – would recommend 👍
Offsetting, Scaling & Transforming
Do you want your temperatures in Celsius, your pressures in Bar & your streamlines in inches? Well you can do all of that at export time and still use “proper” units for your simulation 😉
It’s all handled by the formatOptions
sub-dictionary, which can be added to any function that exports surfaces (streamlines, cutting planes, sampled surfaces etc).
The example below would offset the temperature field & scale the pressure field for any surfaces exported in VTK
format, as well as scaling the geometry of anything exported as an OBJ
.
Offsets are by subtraction & are applied first, followed by the field scaling, followed by the geometry transforms. You can mix & match which ones you use, but they’re always in that order.
Find out more here including how to rotate surfaces as well as scale them. Rotations also include any vectors &/or tensors, so your results will look right, even after you’ve re-oriented them 👍
Finally, an easy way to accommodate those clients that refuse to accept that air only flows in the X-direction & that Z is up 😉
Normalised Fields
Did you know you can normalise fields in OpenFOAM before exporting them, rather than having to do it in ParaView afterwards?
Meet norm
, our normalisation specialist 🤓
Here’s a simple example of using norm
to normalise a UNear
field by a constant (in this case 20).
You could save the above as system/norm
in the motorBike
tutorial & run it (in serial or parallel) using something like…
postProcess -func norm -latestTime -fields "(UNear)"
This is the simplest normalisation flavour (dividing by a constant), but there are several other options that might suit you better (Taxicab, Euclidean, dividing by the maximum value, plus the ability to normalise one field by another). Find out more here & check out the cavity tutorial for a worked example.
That’s all folks
There you have it – a couple of foamToVTK
switches, a way to transform data during export & a function object called norm
. Three little bits of OpenFOAM functionality that are bound to come in handy (one day).
As trailed, this is probably the last in the tiny tips series – I’ve got a replacement in mind, but more on that as it takes shape.
The previous ones are in the archive if you need them. Here’s hoping you got at least one golden nugget from the series 🤞
Until next week, stay safe,