Issue 085 – February 26, 2022

Exporting patches with sampledSurfaces

Hey there,

It’s Robin from CFD Engine & this was going to be an email about a new export format in OpenFOAM v2112, but it appears that I can’t actually read 🙈

I’d thought that the new glTF format could be used to export surfaces, it turns out it’s currently just for points & particle tracks.

So, instead of walking you through glTF, I’ll talk about the formats we can actually use when exporting surfaces. I’ll throw in a couple of tips, share why one format is particularly good for transient data & share a simple export gist.

But first, a quick question…

Why export surfaces?

My post-pro workflow is designed to avoid having to reconstruct parallel cases (too slow) & to avoid reading the entire volume mesh into a single machine (a hardware bottleneck).

So, at the end of a simulation, I calculate all the additional fields I need (total pressure, pressure coefficient, wall shear stress etc) & then export any slices, surfaces, streamlines & isosurfaces from OpenFOAM, in parallel, on the cluster.

I then take these lightweight post-pro assets into ParaView and create my images.

I export most of these assets using sampledSurfaces.

sampledSurfaces

The sampledSurfaces functionObject is a big one, able to extract all sorts of surfaces, from cut planes to patches, isosurfaces to faceZones. It’s a bit much to cover it all in one email, so I’ll just stick to exporting patches for today.

For that use case it has two really nice features…

Firstly, it produces serial/reconstructed assets even when run against a parallel/decomposed case – no need to reconstruct anything beforehand 👍

Secondly, you can compress lots of named patches into a single exported surface, which makes subsequent post-pro ops much easier.

There are loads of output formats, but I suggest using vtp or ensight if you’re exporting fields (p,U etc). If you just want to export the meshed geometry, to take into CAD for example, then you could use obj or stl formats.

Nastran, Abaqus & StarCD are other options which might be useful…maybe 🤷‍♂️

The general gist

I’ve uploaded an annotated control file that exports the bike & rider from the motorBike tutorial. It includes exports in obj, vtp & ensight formats & demonstrates a few additional tweaks you can make. It seems to work in v2112 & v2106, but I’ve not tested it in any .org versions.

Check it out here.

Here are a few notes on the tweaks…

VTP Format

VTP exports are ASCII by default, but you can reduce the file size by changing to binary – use this addition to make your files ~25% smaller:

formatOptions { vtp {format binary;} }

VTP also supports data compression, but not via sampledSurfaces.

Files that use compression can be ~50% smaller than the default ASCII VTP export.

To make use of it, you need to read the OpenFOAM exports into ParaView & write them back out with compression activated (set the file type to appended & use zlib to get good compression without taking too long to write). If you have lots of files to convert you could “just write a python script & run it with pvbatch” 😉

EnSight Format

The EnSight format is less space efficient than VTP but really good for transient data, especially if your mesh doesn’t change over time.

Here’s a listing of an EnSight export that includes three time steps – you can see that it comprises several files & directories. There is field data (p) in each time directory, but the geometry is stored only once.

tree listing showing files in an EnSight export

You can read the single ensight.case file into ParaView & press play to watch your time series animate.

The same cannot be said for VTP files, where much shuffling, linking & renaming is required to get that same functionality.

You can also export EnSight data in binary format, but it wouldn’t read into ParaView (for me).

Interpolation

By default, any exported surfaces have cell/face-based data, which can look blocky when plotted. If you want smoother-looking plots you can turn interpolation on & write out point/node-based data (this is a per-surface setting – see here).

interpolate true;

Note: you could do this with the cell data to point data filter in ParaView (if you’d prefer).

We can also set the method we want to use for our interpolation. One interesting option is the cellPointWallModified scheme which tweaks the interpolation near the walls, particularly useful for plotting near-wall velocities rather than just zeros (this is a global setting – see here).

interpolationScheme cellPointWallModified;

Give it a spin

This was a long email & I barely scratched the sampledSurface – if it looks interesting then grab the sample dictionary & take it for a spin with the motorBike data or tweak it to fit your own.

Do you use sampledSurfaces already? Are there any other tricks that I’ve missed? Let me know & I can share them with the class. Or do you do everything in ParaView instead? I’m always keen to learn how you do things, drop me a note 🙏

Until next week, stay safe

Signed Robin K