Hey there,
It’s Robin from CFD Engine & it’s “three tiny tips” time again – no deep dives or tutorials, just three little nuggets of OpenFOAM goodness that might be useful to you.
They’re relatively old features this time, ones that had passed me by, oldies, but goodies.
We have a couple of functionObject
features & a layering tweak for snappyHexMesh
, so let’s go…
Using mean values in pressure calcs
This one has been around for as long as functionObjects
, but it’s a little bit hidden, so maybe you missed it (like me).
If you’ve gone to the trouble of averaging your fields, then you’d probably like to use those averaged fields in your static & total pressure calculations.
Easily done, with the addition of a couple of keywords to your total (or static) pressure functionObject
.
Here’s an example for total pressure, from v2106
:
First, run foamGetDict totalPressureIncompressible
(choose Option 1
) & it will copy a dictionary like this to your system
directory.
Then add those last two lines, telling OF that we want to use pMean
& UMean
fields in our total pressure calc (instead of the usual suspects).
Now, we just need to make sure we load these fields when running the postProcess
command:
postProcess -func totalPressureIncompressible -fields "(UMean pMean)" -latestTime
And we’re done – our nice averaged total pressure field awaits.
It’s slightly different in the .com version – try foamGet
instead of foamGetDict
& use field
instead of p
when specifying which pressure field you want to use, i.e field pMean;
🤞
firstAndRelativeFinal
Layers
CFD people can be very particular when it comes to their boundary layer meshes (rightly so) & it’s where many people fall out with snappyHexMesh
. This tip doesn’t fix layering, but it does give you a useful new option that might help.
We’ve always had plenty of options for describing our dream layer recipe in snappyHexMesh
. By pairing two parameters from expansionRatio
, finalLayerThickness
, firstLayerThickness
& thickness
we have loads of scope to get what we need.
But…we’ve always had to choose between whether we want to specify our layer sizes relative to the local cell size (great for flexibility, less so for yPlus
) or in absolute dimensions (great for chasing a yPlus
target, less so for blending into the surrounding mesh) – choose one or the other, but not both.
With the introduction of the thicknessModel
keyword we can now have a little bit of both.
We can now specify an absolute first layer thickness (smash that yPlus
target) and a relative final layer thickness (ensuring there isn’t a huge step between the size of our final layer & the surrounding mesh) – nice.
It’s been in the OpenCFD release since v2012
(see the announcement) – maybe give it a try?
Triggers
This one extends the usefulness of the runTimeControl
functionObject
, mentioned in a previous “tiny tips” email.
runTimeControl
allows you to define a series of conditions which, if satisfied, will end your simulation early.
For example, you could configure it to monitor your forces & end the simulation once your average drag is steady, within a given range.
But wait, there’s more…
I hadn’t noticed that there’s also an option to trigger other events, not just to end your simulation.
Configure your runTimeControl
to fire a named trigger
when a particular condition is satisfied (instead of ending the simulation). Then reference that named trigger
in other functionObjects
to control their start &/or end points.
There are all sorts of automations you could build using this technique:
-
Do you want to start averaging fields, but only once your residuals are below a certain threshold?
-
Maybe you’d like to report locations for
minMax
pressure & velocity, just before your simulation blows up? -
Or perhaps you’d like to do a few extra iterations once your forces have converged (just to be on the safe side)?
Time to let your imagination run wild & automate all the things.
Check the v1906
release notes for more information & a worked example.
Over to you
That’s three more tiny tips for the collection – using averaged fields in your pressure calculations, another way to specify your layer mesh recipe & a method to automate all the things – I don’t think the last two are in the Foundation version unfortunately 😳
They’re not new, so perhaps you already knew these three? Do you use them? Have you got any creative automations you’d care to share?
Always keen to hear back from you, especially if you have a neat trick that I can include in the next edition of “three tiny tips.”
Until next week, stay safe,