HowTo postProcMultiregion
There are several ways to post-process multi-region cases, although it may depend on the ParaView version that is available and which OpenFOAM version/fork is being used.
Old versions of paraFoam dind't support the post-processing of simulations that use multiple mesh-regions (like icoStructFoam or the conjugated heat transfer solver. This is why both old and modern ways to process multi-regions are documented here:
Contents
1 Using paraFoam and the official reader
Valid versions:
and any other modern version/fork.
For opening a single region, e.g. region_name, run:
paraFoam -region region_name
In the command line, it should show a message that indicates the stub file that was created:
created temporary 'case_name{region_name}.OpenFOAM'
This is what will allow OpenFOAM's official reader that is loaded into ParaView, to load the mesh for the region region_name.
For opening multiple regions, first create all of the stub files, then start ParaView, by running:
paraFoam -touchAll paraview
Then open the files that were created by the -touchAll option inside ParaView.
You can also run paraFoam instead of paraview, but it may be necessary to delete the entry that is opened by default and then load the desired files.
2 Using paraFoam and the built-in/native reader
The built-in reader in ParaView (at least since version 3.12.0) will open files with extension .foam. This can easily be done by running paraFoam with the respective option:
- In OpenFOAM:
paraFoam -builtin
- In foam-extend:
paraFoam -nativeReader
Once ParaView is open, it should show something similar to the image on the right, where:
- internalMesh refers to the main internal mesh, i.e. the standard case's mesh;
- solid/internalMesh refers to the solid internal mesh region.
Depending on the type of case you've ran, the main internal mesh may or may not be useful to be post-processed. For example:
- chtMultiRegion*Foam solvers, such as demonstrated in Getting started with chtMultiRegionSimpleFoam - planeWall2D, do not rely on the main mesh, because it's only using the region meshes.
- FSI solvers in Extend-bazaar/Toolkits/Fluid-structure interaction use the main mesh for the fluid region and the solid region for the solid.
3 Using ParaView and foamToVTK
To write the data of the two regions for ParaView just use foamToVTK:
foamToVTK . icoStructFoamTest -mesh region1 foamToVTK . icoStructFoamTest -mesh region2
4 Generating pseudo case-directories
An alternative Way was described on the Message board:
Basically what you do is create two cases that point to the real data.
Suppose you have your case in aTaleOfTwoMeshes. Create two directories meshCase1, meshCase2. For each directory create these links:
meshCaseX/system -> aTaleOfTwoMeshes/system meshCaseX/constant/polyMesh -> aTaleOfTwoMeshes/constant/regionX/polyMesh meshCaseX/0 -> aTaleOfTwoMeshes/0/regionX
(the last has to be done for every time-step)
Now create a stub in one case (touch meshCase2/meshCase2.foam), open the other case from the command line (paraFoam . meshCase1), in that paraFoam open the stub you created using the File->Open-dialog.
4.1 Example script
An example for the implementation of this strategy would be this script written in Python using the PyFoam-library:
#! /usr/bin/python from os import mkdir,path,symlink,system,listdir import sys from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory def buildCase(original,region): dirName=original+"."+region case=path.basename(original) print "Creating pseudocase",dirName system("rm -rf "+dirName) mkdir(dirName) mkdir(path.join(dirName,"constant")) symlink(path.join(path.pardir,path.pardir,case,"constant",region,"polyMesh"), path.join(dirName,"constant","polyMesh")) symlink(path.join(path.pardir,case,"system"), path.join(dirName,"system")) sol=SolutionDirectory(original) for t in sol.getTimes(): symlink(path.join(path.pardir,case,t,region), path.join(dirName,t)) return dirName caseName=sys.argv[1] if caseName[-1]==path.sep: caseName=caseName[:-1] firstRegion=None for region in listdir(path.join(caseName,"constant")): name=buildCase(caseName,region) if not firstRegion: firstRegion=name else: f=open(path.join(name,path.basename(name)+".foam"),"w") f.close() print "\n\n Open first region with \"paraFoam %s %s\".\n All others from the File menu" % (path.normpath(path.dirname(firstRegion)),path.basename(firstRegion))
It can be used like this (if it saved to buildRegionPseudocases.py):
python buildRegionPseudocases.py thingOnAStick
It builds the directories for the regions it finds.
Note: I'm well aware that there are shorter ways to write this script, but I like the thought that it should work on Windows should I ever have the misfortune to work on that OS