Examples of How To Use Some Utilities and Functionobjects
Examples of How To Use Some Utilities and Functionobjects
• It is HIGHLY recommended that you dig through ALL of the UserGuide and
ProgrammersGuide (before complaining that there is not enough OpenFOAM
documentation).
Postprocessing
• Some functionality that was earlier available as utilities for post processing have been
reorganized using functionObjects (discussed more later).
• We will have a look at how to extract data for plotting and visualization in the coming
slides.
• You can list the available options by typing
postProcessing -list
• See http://openfoamwiki.net/index.php/Sig_Turbomachinery_/_Timisoara_Swirl_Generator#Post-processing_using_Python
and http://www.scipy.org/Plotting_Tutorial
• Copy the text below to plotPressure.py (make sure the indentation is correct), type
python plotPressure.py
#!/usr/bin/env python
description = """ Plot the pressure samples."""
import os, sys
import math
from pylab import *
from numpy import loadtxt
def addToPlots( timeName ):
fileName = "cavity/postProcessing/singleGraph/" + timeName + "/line_p.xy"
i=[]
time=[]
abc =loadtxt(fileName, skiprows=4)
for z in abc:
time.append(z[0])
i.append(z[1])
legend = "Pressure at " + timeName
plot(time,i,label="Time " + timeName )
figure(1);
ylabel(" p/rho "); xlabel(" Distance (m) "); title(" Pressure along sample line ")
grid()
hold(True)
for dirStr in os.listdir("cavity/postProcessing/singleGraph/"):
addToPlots( dirStr )
legend(loc="upper left")
savefig("myPlot.jpeg")
show() #Problems with ssh
This file includes a selection of example surfaces, each of which the user
should configure and/or remove.
\*---------------------------------------------------------------------------*/
#includeEtc "caseDicts/postProcessing/visualization/surfaces.cfg"
fields (p U);
surfaces
(
zNormal
{
$cuttingPlane;
pointAndNormalDict
{
basePoint (0.05 0.05 0.005); // Overrides default basePoint (0 0 0)
normalVector $z; // $y: macro for (0 0 1)
}
}
p0
{
$isosurface;
isoField p;
isoValue 0;
}
movingWall
{
$patchSurface;
patches (movingWall);
}
);
// ************************************************************************* //
• Execute by:
postProcess -func 'div(U)' -case cavity
The first line sais that the name of the top patch has different names in the cases.
The second line sais that the fixedWalls patch is cutting through the cavity case.
• The flags -parallelSource and -parallelTarget are used if any, or both, of the
cases are decomposed for parallel simulations.
- A boxToCell bounding box is used to define a set of cells where the fieldValues
should be different than the defaultFieldValues.
• The above have now been merged into swak4Foam (Swiss Army Knife For Foam):
http://openfoamwiki.net/index.php/Contrib/swak4Foam
www.openfoamworkshop.org
• The two empty sides of a 2D mesh must have the same mesh distribution. Add 0.0001
to the z-position of one of the constant/polyMesh/points of the cavity case.
• The checkMesh utility can be used to verify this. If not, it will complain:
***Number of edges not aligned with or perpendicular to non-empty directions: ????
Writing ???? points on non-aligned edges to set nonAlignedEdges
• Take the opportunity to visualize the point set in paraFoam: First open the cavity case
in paraFoam, then use File/Open <case>.OpenFOAM to read in the same case again.
This time mark Include Sets, mark only Mesh Parts/NonAlignedEdges, and visualize
using box glyphs.
• The flattenMesh utility can sometimes fix the problem, like in this case.
• Example:
cd $FOAM_RUN/icoFoam/cavity; blockMesh -case cavity
cp -r cavity cavityMoved
transformPoints -case cavityMoved -translate "(0.1 0 0)"
• mergeMeshes reads the system/controlDict of both cases and uses the startTime,
so be careful if you have a moving mesh for example. The first case that you specify
will be the master, and a new time (startTime+deltaT) will be written in which a new
polymesh is located. Move it to the correct position (constant/polyMesh), and you
have a case with the merged mesh.
• Example (start from clean cases):
run
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity cavityMerged
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity cavityTransformed
blockMesh -case cavityMerged
blockMesh -case cavityTransformed
transformPoints -case cavityTransformed -translate "(0.1 0 0)"
mergeMeshes cavityMerged cavityTransformed
mv cavityMerged/0.005/polyMesh/* cavityMerged/constant/polyMesh
• Note that the two meshes will keep all their original boundary conditions, so they are
not automatically coupled. Try icoFoam! To couple the meshes, use stitchMesh...
• You should have a patch in one region of the mesh (masterPatch) that fits with a cor-
responding patch in the other region of the mesh (slavePatch). If you have that, then
the command is:
stitchMesh masterPatch slavePatch
• After stitchMesh, masterPatch and slavePatch are still present in the new
polymesh/boundary, but they are empty so just delete them. The same thing can be
done as well for the boundary conditions in the 0 folder.
• We have to re-organize the patches for this to work with our cavityMerged case, so we
will do it for another case.
• Run and visualize (use Surface With Edges representation to see the stitching):
setFields -case damBreakLeft
interFoam -case damBreakLeft >& log
paraFoam -case damBreakLeft
• Use flag -force if you have already decomposed, but want to do it again.
• This is usually done for post-processing, although it is also possible to post-process each
domain separately by treating an individual processor directory as a separate case when
starting paraFoam, or using the paraFoam flag \verb-builtin+.
• Try reconstructing our case:
reconstructPar -case damBreakLeft
functionObjects
• functionObjects are general libraries that can be attached run-time to any
solver, without having to re-compile the solver.
• Use sed and gnuplot to plot, removing headerline and unwanted char-
acters (U, (, and )):
plot '<sed "s/U//g;s/(//g;s/)//g" damBreakLeft/postProcessing/minMaxU/0/fieldMinMax.dat'\
using 1:7 every ::2 with lines title "X-position of maximum velocity magnitude"
• Note that the values are the cell center values, i.e. not interpolated!
First example:
surfaceSampling
{
type surfaces;
libs ("libsampling.so"); Two more examples:
enabled true;
atmosphere
writeControl outputTime;
{
interpolationScheme cellPoint;
type patch;
surfaceFormat vtk;
patches ( atmosphere );
fields ( U );
triangulate false;
surfaces
}
(
plane
nearWall
{
{
type plane;
type patchInternalField;
normalVector (0 0 1);
patches ( leftWall );
basePoint (0 0 0.005);
distance 1E-6;
}
interpolate true;
triangulate false;
}
);
}
More functionObjects
• http://openfoamwiki.net/index.php/Contrib_simpleFunctionObjects
• http://openfoamwiki.net/index.php/Sig_Turbomachienry_/_ERCOFTAC_centrifugal_pump_with_a_vaned_diffuser#Optional_tools
• http://openfoamwiki.net/index.php/Contrib/swak4Foam