Issue 045 – May 8, 2021

Slice Movies

Hey there,

It’s Robin from CFD Engine & I’ve been playing with some new (to me) post-pro functionality that might make it a little easier to produce the sweepy-slice movies that we’re all so keen on.

I make a lot of slice movies & I make them using slices exported from OpenFOAM & visualised in ParaView.

I like the speed of doing it this way, what I don’t like is prepping (& subsequently fiddling with) dictionary files to make it all happen, or to make a change.

So, here are some thoughts on using the offsets keyword (introduced in v2012) to generate your slices, along with an idea for animating them in ParaView.

Let’s get after it…

Slice ’em up

You know the kind of animations I’m talking about – sweeping a plane through a region of interest, colouring it by an “insightful” flow property & never looking at it again 😉 You might call them something else, but I’m sure you’ve seen (& made) plenty of them.

You can do it all in ParaView – read in your case, add a slice, make it look nice & then animate its position. Easy peasy. Although with bigger models you can expect the loading & subsequent slicing to be pretty slow.

If your model is on the large side (especially if it’s too large to read into your workstation) then you might need an approach like mine – export the slices from OpenFOAM & visualise them in ParaView.

However, this approach can involve some pretty lengthy export dictionaries – let’s take a look at a basic one.

sampledSurfaces

The snippet below, uses the cuttingPlane option in the sampledSurfaces function object to create a slice for export.

An example OpenFOAM cutting plane dictionary

In this example, the slice is called plane001, it’s located at the origin and its normal is aligned to the X-axis.

We could drop that snippet into a file called system/sliceMovie & run it using postProcess -func sliceMovie -latestTime to get our slice.

It runs quickly & the output is lightweight. But best of all, the exported assets are serial (or reconstructed) even if you’re exporting in parallel, from a decomposed case.

But, if we want more than one slice, we need to add more planes to the surfaces sub-dictionary, one for each slice we want in our movie. That can take a while & there’s a decent chance we’ll muck it up.

But, if you’re careful, name them consistently & sequentially ( _001 _002_101 etc) then ParaView will offer to read them in as a single pseudo time series.

Set up your view, get that rainbow colourmap looking fresh 😎 and use Save Animation to output your results.

Or that’s how it used to be…now you have to faff about editing the slice VTP files, stripping out their TimeValue to make this work (let me know if you’ve had this issue & you want a workaround).

What if we could do it another way?

Offsets

A new keyword was added in v2012 that allows us to specify offsets to our original point, spaced along our normal vector.

    // Additional slices
    offsets (0 0.1 0.2 0.3 0.4 0.5);            

By adding the above to our earlier plane001 sub-dictionary, we’re requesting six slices with just one extra line.

Add all of the slices you need for your movie into this list & you’re away.

Top Tip: Don’t forget to include "0" if you want a slice at your original/base point.

The syntax is easy to read, easy to edit. As a bonus, offsets don’t need to be in order, which makes it easy to add extra slices. It’ll also warn you at runtime if there are duplicates (whilst ignoring the non-unique entries), very useful for debugging long lists.

bounds

While were editing, lets add the bounds keyword to our plane001 definition, so that we’re not exporting acres of slice that we’ll never look at.

Something like:

	// Restrict the extents of the slices
	// (Xmin Ymin Zmin)(Xmax Ymax Zmax)
	bounds  (-2 -1 -5)(5 1 2);

Our sliceMovie dictionary ends up looking like this:

An example OpenFOAM cutting plane dictionary using offsets and bounds

Now we’ll get 6 slices, trimmed to our region of interest, all in the one VTP file.

Where’s the catch?

That is the catch – all of the slices we export using offsets are bundled together into a single VTP file.

When we read them into ParaView, we can’t just press play to animate them. We need to break them apart somehow 🤔

Turns out, its not too difficult. Here’s the “lazy tutorial” version of how to do it:

Use ParaView’s Elevation filter to give your slices a value between 0 & 1, along the stack.

Use a Threshold on that new value to show just a single slice, then animate the threshold values to flick through the slices.

Set up your view, get that rainbow looking nice again and use Save Animation to output your movie 👍

Over to you

I’m guessing you already have a neat way of making slice movies, but it’s nice to have choices & this one looks pretty useful to me.

How do you do yours?

I’m sure you can figure this one out from the above (and puzzling is half of the fun) but let me know if you’d like to see a 60sec “lazy tutorial” screencast on this (or anything else) that I cover.

BTW: If you don’t know about lazy tutorials check out this playlist on YouTube to get the idea, they’re fun.

I’m keen to make these emails as useful as possible, but without getting too “epic”. Let me know if you think the odd screencast, cheatsheet, dictionary or state file would help.

Until next week, stay safe,

Signed Robin K