Difference between revisions of "HowTo postProcMultiregion"

From OpenFOAMWiki
(Added more details)
m (typos corrected, sentences optimized)
 
Line 1: Line 1:
 
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.
 
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 [[contrib_icoStructFoam|icoStructFoam]] or [[Tut Small Study on Conjugate Heat Transfer|the conjugated heat transfer solver]]. This is why both old and modern ways to process multi-regions are documented here:
+
Old versions of [[paraFoam]] didn't support the post-processing of simulations that use multiple mesh-regions (like [[contrib_icoStructFoam|icoStructFoam]] or [[Tut Small Study on Conjugate Heat Transfer|the conjugated heat transfer solver]]. This is why both old and modern ways to process multi-regions are documented here:
  
 
== Using [[paraFoam]] and the official reader ==
 
== Using [[paraFoam]] and the official reader ==
Line 9: Line 9:
 
For opening a single region, e.g. {{tt|region_name}}, run:
 
For opening a single region, e.g. {{tt|region_name}}, run:
 
<bash>paraFoam -region region_name</bash>
 
<bash>paraFoam -region region_name</bash>
In the command line, it should show a message that indicates the ''stub'' file that was created:
+
In the command line, it should show a message that indicates the ''stub'' file was created:
 
<bash>created temporary 'case_name{region_name}.OpenFOAM'</bash>
 
<bash>created temporary 'case_name{region_name}.OpenFOAM'</bash>
 
This is what will allow OpenFOAM's official reader that is loaded into ParaView, to load the mesh for the region {{tt|region_name}}.
 
This is what will allow OpenFOAM's official reader that is loaded into ParaView, to load the mesh for the region {{tt|region_name}}.
Line 31: Line 31:
 
* {{tt|solid/internalMesh}} refers to the {{tt|solid}} internal mesh region.
 
* {{tt|solid/internalMesh}} refers to the {{tt|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:
+
Depending on the type of case you've run, the main internal mesh may or may not be useful to be post-processed. For example:
 
* {{tt|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.
 
* {{tt|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 {{tt|solid}} region for the solid.
 
* FSI solvers in [[Extend-bazaar/Toolkits/Fluid-structure interaction]] use the main mesh for the fluid region and the {{tt|solid}} region for the solid.
Line 37: Line 37:
 
== Using [[ParaView]] and [[foamToVTK]] ==
 
== Using [[ParaView]] and [[foamToVTK]] ==
  
To write the data of the two regions for [[ParaView]] just use [[foamToVTK]]:
+
To write the data of each region for [[ParaView]] just use [[foamToVTK]] respectively:
  
  foamToVTK . icoStructFoamTest -mesh region1
+
  foamToVTK . ''TestCaseName'' -mesh ''RegionName''
foamToVTK . icoStructFoamTest -mesh region2
+
  
 
== Generating pseudo case-directories ==
 
== Generating pseudo case-directories ==
  
An alternative Way was described on [https://www.cfd-online.com/Forums/openfoam-paraview/61103-postprocessing-tworegion-mesh.html the Message board]:
+
An alternative way was described on [https://www.cfd-online.com/Forums/openfoam-paraview/61103-postprocessing-tworegion-mesh.html the Message board]:
  
Basically what you do is create two cases that point to the real data.
+
Basically what you do is creating two cases that point to the real data.
  
 
Suppose you have your case in <tt>aTaleOfTwoMeshes</tt>. Create two directories <tt>meshCase1</tt>, <tt>meshCase2</tt>. For each directory create these links:
 
Suppose you have your case in <tt>aTaleOfTwoMeshes</tt>. Create two directories <tt>meshCase1</tt>, <tt>meshCase2</tt>. For each directory create these links:
Line 60: Line 59:
  
 
An example for the implementation of this strategy would be this script written in [http://www.python.org Python] using the [[Contrib_PyFoam|PyFoam]]-library:
 
An example for the implementation of this strategy would be this script written in [http://www.python.org Python] using the [[Contrib_PyFoam|PyFoam]]-library:
 
 
<python>
 
<python>
 
#! /usr/bin/python
 
#! /usr/bin/python
Line 103: Line 101:
 
</python>
 
</python>
  
It can be used like this (if it saved to <tt>buildRegionPseudocases.py</tt>):
+
It can be used like this (if it is saved to <tt>buildRegionPseudocases.py</tt>):
 
  python buildRegionPseudocases.py thingOnAStick
 
  python buildRegionPseudocases.py thingOnAStick
 
It builds the directories for the regions it finds.
 
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
+
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.
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Latest revision as of 16:27, 23 January 2018

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 didn'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:

1 Using paraFoam and the official reader

Valid versions: OF Version 20.png OF Version 21.png OF Version 23.png OF Version 30.png OF Version 4.pngOF Version FoundationDev.png 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 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

Example of a region named solid, beyond the base mesh.

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 run, the main internal mesh may or may not be useful to be post-processed. For example:

3 Using ParaView and foamToVTK

To write the data of each region for ParaView just use foamToVTK respectively:

foamToVTK . TestCaseName -mesh RegionName

4 Generating pseudo case-directories

An alternative way was described on the Message board:

Basically what you do is creating 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 is 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.