Difference between revisions of "HowTo postProcMultiregion"

From OpenFOAMWiki
 
m (typos corrected, sentences optimized)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Current versions of [[app_paraFoam|paraFoam]] don't support the postprocessing of simulations that use multiple mesh-regions (like [[contrib_icoStructFoam|icoStructFoam]] or [[HeatTransfer|the conjugated heat transfer solver]]. This discribes ways to cope with that shortcomming.
+
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.
  
== Using [[app_paraview|paraview]] ==
+
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:
  
To write the data of the two regions for [[app_paraview|paraview]] just use [[app_foamToVTK|foamToVTK]]:
+
== Using [[paraFoam]] and the official reader ==
  
  foamToVTK . icoStructFoamTest -mesh region1
+
{{VersionInfo}}{{Version2.0}}{{Version2.1}}{{Version2.3}}{{Version3.0}}{{Version4}}{{VersionOpenFOAMFoundationDev}} and any other modern version/fork.
  foamToVTK . icoStructFoamTest -mesh region2
+
 
 +
For opening a single region, e.g. {{tt|region_name}}, run:
 +
<bash>paraFoam -region region_name</bash>
 +
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>
 +
This is what will allow OpenFOAM's official reader that is loaded into ParaView, to load the mesh for the region {{tt|region_name}}.
 +
 
 +
For opening multiple regions, first create all of the ''stub'' files, then start ParaView, by running:
 +
<bash>paraFoam -touchAll
 +
paraview</bash>
 +
Then open the files that were created by the {{tt|-touchAll}} option inside ParaView.
 +
 
 +
You can also run {{tt|paraFoam}} instead of {{tt|paraview}}, but it may be necessary to delete the entry that is opened by default and then load the desired files.
 +
 
 +
== Using [[paraFoam]] and the built-in/native reader ==
 +
[[Image:Multi-region-built-in-ParaView.png|thumb|200px|right|Example of a region named {{tt|solid}}, beyond the base mesh.]]
 +
 
 +
The built-in reader in ParaView (at least since version 3.12.0) will open files with extension {{tt|.foam}}. This can easily be done by running {{tt|paraFoam}} with the respective option:
 +
* In OpenFOAM: <bash> paraFoam -builtin</bash>
 +
* In foam-extend: <bash>  paraFoam -nativeReader</bash>
 +
 
 +
Once ParaView is open, it should show something similar to the image on the right, where:
 +
* {{tt|internalMesh}} refers to the main internal mesh, i.e. the standard case's mesh;
 +
* {{tt|solid/internalMesh}} refers to the {{tt|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:
 +
* {{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.
 +
 
 +
== Using [[ParaView]] and [[foamToVTK]] ==
 +
 
 +
To write the data of each region for [[ParaView]] just use [[foamToVTK]] respectively:
 +
 
 +
  foamToVTK . ''TestCaseName'' -mesh ''RegionName''
  
 
== Generating pseudo case-directories ==
 
== Generating pseudo case-directories ==
  
An alternative Way was described on [http://openfoam.cfd-online.com/cgi-bin/forum/show.cgi?1/3560 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 21: Line 54:
 
(the last has to be done for every time-step)
 
(the last has to be done for every time-step)
  
Now create a stub in one case (<tt>touch meshCase2/meshCase2.foam</tt>), open the other case from the command line (<tt>paraFoam . meshCase1</tt>), in that [[app_paraFoam|paraFoam]] open the stub you created using the File->Open-dialog.
+
Now create a stub in one case (<tt>touch meshCase2/meshCase2.foam</tt>), open the other case from the command line (<tt>paraFoam . meshCase1</tt>), in that [[paraFoam]] open the stub you created using the File->Open-dialog.
  
 
=== Example script ===
 
=== Example script ===
  
 
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 69: 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]]

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.