Hey there,
It’s Robin from CFD Engine & I’ve got a handful of streamline tips & hacks for you today. They all make use of OpenFOAM function objects, but we’ll also get a little help from ParaView here & there.
Think “Tiny Tips: The streamLine Edition”.
Plotting streamlines interactively in ParaView is great & you could do all of the following things just using ParaView, but I’ve got a soft spot for OpenFOAM streamLines.
They might not be as user-friendly, but they’re quick to generate, lightweight & perfect for using in unattended/batch post-pro.
So, here are a few bits & bobs that might come in handy one day – go go streamlines…
Streamlines in CAD
It can be really useful to have streamlines in CAD when you’re trying to align a feature to the local flow direction – aligning a NACA duct on a surface, for example.
It’s also dead easy to do – setup the streamlines you need, set their write format to vtk
& export them as usual. Then read them into ParaView & use File > Save Data to write them out in OBJ format. Most CAD packages can read OBJ files & many will convert the streamlines to curves automatically.
Go forth & align your ducts.
Oilflow
For that classic “oilflow” look we can release streamlines that are restricted to the surfaces of the model. For this we’ll need to use a function object called wallBoundedStreamLine & we’ll (likely) need to define a pseudo or near-wall velocity (unless we have slippy surfaces).
There’s a great example in the motorBike tutorial which should get you set up in no time.
You can specify all of the usual streamline settings & select which patches to release from using patchGroups
&/or wildcard/regular-expressions.
You might want to set the lifeTime
of the streamlines to be shorter than usual to stop your lines from running too far & looking a bit like you scribbled them on.
In my experience, it’s much faster than the equivalent filter in ParaView & gives a pretty nice result.
It should be available in .org & .com versions (although it didn’t work in v8 for me) 🤷♂️
Warp Surfaces
While we’re on the topic of surface streamline/oilflow plots, here’s a little hack if you’re using ParaView 5.6.x (the one that ships with the .org version of OpenFOAM).
As the streamlines & the surfaces are co-incident they can sometimes get “lost” in each other, where the surfaces obscure some of the detail in your streamlines. If this happens, you can workaround it by applying the Warp By Vector
filter to your surfaces in ParaView.
First off, apply the Generate Surface Normals
filter to your surfaces & then apply the Warp By Vector
filter, selecting Normals
as the vector & setting the scale factor to something pretty small (but positive) – a fraction of a mm usually does the trick.
This will offset the surfaces inward, away from the streamlines, just enough so that they’re no longer coincident, but not enough that things look weird (unless your geom is small in which case offset an even smaller amount).
BTW you don’t need to to this if you’re using ParaView 5.9.x as it seems to deal with it automagically ✨
Release from a grid
The streamline
function object has plenty of options for seeding your streamlines (& they differ between .com & .org versions). But one option that’s particularly useful is to release from points defined in an STL/OBJ file.
A quick way to generate a simple grid of points for this is to use our friend ParaView & its geometric shape sources. The equivalent operations in CAD tend to produce grids with far too many points.
To start…
Add a Plane
source in ParaView (defined by three points) & adjust its X-Y resolution as required. Display it using Surface with Edges
or Wireframe
to see the grid, or use Point Gaussian
to see the future streamline release points.
With the plane selected, click File > Save Data, select OBJ (accept defaults) & write it to your constant/triSurface
directory.
Add it to your streamLine
dictionary as your seed sample set & trace those streamlines.
Direction
You probably already know that you can track streamlines upstream, downstream or both, using a single function object. But you might not have noticed that the keywords are different depending which version you’re using. So, if you use more than one flavour of OpenFOAM (or you’re migrating from one to another), it’s…
direction bidirectional;
in the .com/ESI versiondirection both;
in the .org/Foundation version
There are a surprising number of differences in the streamLine
function object between versions, this is just a cheeky little one.
One thing to note when using bidirectional/both
tracking, there’s a discontinuity between the upstream & downstream streamlines that shows up when you use the Tube
filter in ParaView. You might need to change the location of your release points so it isn’t visible in your final plots.
Bounding
Speaking of differences between the .com & .org versions of streamLine
, there’s a neat additional feature in the .com/ESI version to stop runaway streamlines – bounds
.
Add the following to your streamline dictionary (replacing the mins & maxs to define your region of interest) & your streamlines will be cropped when they leave the box.
bounds (MinX MinY MinZ)(MaxX MaxY MaxZ);
No more boring straight streamlines that run all the way to the outlet 👍
Before you go…
Here’s hoping you’ll try out some of these tips 🤞 but before you go I wanted to ask a quick question.
Are you enjoying the tip-style emails? Are they too light? Too narrow? Would you prefer a deeper dive on a single tip? Or are they about right?
I’m not going to do them every week, but I value your feedback.
If you’ve got this far, please drop me a note so that I can make these emails better for everyone.
Until next week, stay safe,