Post: Solution Post-processing
Version: 2.5 (20/09/2017)
Author: Onera

Preamble
This module provides post-processing tools for CFD simulations.
It manipulates arrays (as defined in Converter documentation)
or CGNS/Python trees (pyTrees) as data
structures.
This module is part of Cassiopee, a free open-source
pre- and post-processor for CFD simulations.
When using the Converter array interface,
a (or b) denotes an array, and A (or B) denotes a list of arrays.
Then, Post module must be imported:
import Post as P
When using the pyTree interface, import the module:
import Post.PyTree as P
In that case, a is a zone node. A is a list of zone nodes or a
complete pyTree.
Changing variable names
P.renameVars:
Rename a list of variables with new variable names:
t = P.renameVars(t, oldVarNameList, newVarNameList)
Example of use: rename variables (array),
rename variables (pyTree).
Variables import
P.importVariables:
variables located at nodes and/or centers can be imported from a pyTree t1
to a pyTree t2.
If one variable already exists in t2, it is replaced by the same
variable from t1.
If method=0, zone are matched from names, if method=1, zones are
matched from coordinates with a tolerance eps, if method=2, zones
are taken in the given order of t1 and t2 (must match one by one).
If addExtra=1, unmatched zones are added to a EXTRA base:
t = P.importVariables(t1, t2, method=0, eps=1.e-6, addExtra=1)
Example of use: import variables (pyTree).
Variables computation
P.computeVariables:
new variables can be computed from conservative variables.
The list of the names of the variables to compute must be provided.
The computation of some variables (e.g. viscosity) require some constants as input data.
In the pyTree version, if a reference state node is defined in the pyTree, then the corresponding reference
constants are used. Otherwise, they must be specified as an argument of the function.
These constants are:
- 'gamma' for the specific heat ratio,
- 'rgp' for the perfect gas constant (rgp = (gamma-1) * cv),
- 'betas' and 'Cs' (Sutherland's law constants), or 'Cs','Ts' and 'mus'
- 's0' for a constant entropy, defined by:
s0 = sref - rgp gamma/(gamma-1) ln(Tref) + rgp ln(Pref),
where sref, Tref and Pref are defined for a reference state.
Computed variables are defined by their CGNS names:
- 'VelocityX', 'VelocityY', 'VelocityZ' for components of the absolute velocity,
- 'VelocityMagnitude' for the absolute velocity magnitude,
- 'Pressure' for the static pressure (requires: gamma),
- 'Temperature' for the static temperature (requires: gamma, rgp),
- 'Enthalpy' for the enthalpy (requires: gamma),
- 'Entropy' for the entropy (requires: gamma, rgp, s0),
- 'Mach' for the Mach number (requires: gamma),
- 'ViscosityMolecular' for the fluid molecular viscosity (requires: gamma, rgp, Ts, mus, Cs),
- 'PressureStagnation' for stagnation pressure(requires: gamma),
- 'TemperatureStagnation' for stagnation temperature (requires: gamma, rgp),
- 'PressureDynamic' for dynamic pressure (requires: gamma).
b = P.computeVariables(a, ['varname1', 'varname2'], gamma=1.4, rgp=287.053, s0=0., betas=1.458e-6, Cs=110.4, mus=1.76e-5, Ts=273.15)
.or. B = P.computeVariables(A, ...)
In the pyTree version, if the variable name is prefixed by 'centers:' then the variable is computed at centers only (e.g. 'centers:Pressure'), and if it is not prefixed, then the variable is computed at nodes.
Example of use: pressure calculation (array),
pressure calculation (pyTree).
P.computeExtraVariable:
compute more advanced variables from conservative variables.
'varName' can be 'Vorticity', 'VorticityMagnitude', 'QCriterion',
'ShearStress' (requires: gamma, rgp, Ts, mus, Cs), 'SkinFriction', 'SkinFrictionTangential':
The computation of the shear stress requires gamma, rgp, Ts, mus, Cs as input data.
In the pyTree version, if a reference state node is defined in the pyTree, then the corresponding reference
constants are used. Otherwise, they must be specified as an argument of the function.
b = P.computeExtraVariable(a, 'varName', gamma=1.4, rgp=287.053, Cs=110.4, mus=1.76e-5, Ts=273.15)
.or. B = P.computeExtraVariable(A, 'varName', gamma=1.4, rgp=287.053, Cs=110.4, mus=1.76e-5, Ts=273.15)
Example of use: extra variable computation (array),
extra variable computation (pyTree).
P.computeWallShearStress:
compute the shear stress at wall boundaries provided the velocity gradient is already computed.
The problem dimension and the reference state must be provided in t, defining the skin mesh.
The function is only available in the pyTree version.
t = P.computeWallShearStress(t)
.or. P._computeWallShearStress(t) for the in place version.
Example of use: wall shear stress (pyTree)..
P.computeGrad:
compute the gradient (gradx,grady,gradz) of a field of name varname
defined in a. The returned field is located at cell centers:
b = P.computeGrad(a, varname) .or. B = P.computeGrad(A, varname)
Example of use: gradient of density field (array),
gradient of density field (pyTree).
P.computeGrad2:
compute the gradient (gradx,grady,gradz) at cell centers for a field located at cell centers.
Using Converter.array interface, a(A) denotes the mesh, ac(AC) denotes the fields located at centers.
indices is a numpy 1D-array of face list, BCField is the corresponding numpy array of face fields. They
are used to force a value at some faces before computing the gradient.
b = P.computeGrad2(a, ac, indices=None, BCField=None) .or. B = P.computeGrad2(A, AC, indices=None, BCField=None)
Example of use: gradient of density field (array).
Using the pyTree version, the variable name must be located at cell centers.
Indices and BCFields are automatically extracted from BCDataSet nodes:
if a BCDataSet node is defined for a BC of the pyTree, the corresponding face fields
are imposed when computing the gradient:
b = P.computeGrad2(a,varname) .or. B = P.computeGrad2(A, varname)
Example of use: gradient of density field (pyTree).
P.computeNormGrad:
compute the norm of gradient (gradx,grady,gradz) of a field of name varname defined in a.
The returned field 'grad'+varname and is located at cell centers:
b = P.computeNormGrad(a, varname) .or. B = P.computeNormGrad(A, varname)
Example of use: norm of gradient of density (array),
norm of gradient of density (pyTree).
P.computeCurl:
compute curl of a 3D vector defined by its variable names
['vectx','vecty','vectz'] in a.
The returned field is defined at cell centers for structured grids and elements centers for unstructured grids:
b = P.computeCurl(a, ['vectx','vecty','vectz']) .or. B = P.computeCurl(A, ['vectx','vecty','vectz'] )
Example of use: curl of momentum field (array),
curl of momentum field (pyTree).
P.computeNormCurl:
compute the norm of the curl of a 3D vector defined by its variable names
['vectx','vecty','vectz'] in a:
b = P.computeNormCurl(a, ['vectx','vecty','vectz']) .or. B = P.computeNormCurl(A, ['vectx','vecty','vectz'] )
Example of use: norm of the curl of a momentum field (array),
norm of the curl of a momentum field (pyTree).
P.computeDiff:
compute the difference between neighbouring cells of a scalar field defined by its variable varname in a.
The maximum of the absolute difference among all directions is kept:
b = P.computeDiff(a, varname) .or. B = P.computeDiff(A,varname)
Example of use: difference of density field (array),
difference of density field (pyTree).
Solution selection
P.selectCells:
select cells with respect to a given criterion.
If strict=0, the cell is selected if at least one of the cell vertices satisfies the criterion.
If strict=1, the cell is selected if all the cell vertices satisfy the criterion.
The criterion can be defined as a python function returning True (=selected) or False (=not selected):
b = P.selectCells(a, F, ['var1', 'var2'], strict=0) .or. B = P.selectCells(A, F, ['var1', 'var2'], strict=0)
or by a formula:
b = P.selectCells(a, '{x}+{y}>2', strict=0) .or. B = P.selectCells(A, '{x}+{y}>2', strict=0)
Example of use: cell selection in a mesh (array),
cell selection in a mesh (pyTree).
P.selectCells2:
select cells according to a field defined by a variable 'tag' (=1 if selected, =0 if not selected).
If 'tag' is located at centers, only cells of tag=1 are selected.
If 'tag' is located at nodes and 'strict'=0, the cell is selected if at least one of the cell vertices is tag=1.
If 'tag' is located at nodes and 'strict'=1, the cell is selected if all the cell vertices is tag=1.
In the array version, the tag is an array. In the pyTree version, the tag must be defined in a 'FlowSolution_t' type node
located at cell centers or nodes.
b = P.selectCells2(a, tag, strict=0) .or. B = P.selectCells2(A, TAG, strict=0)
Example of use: cell selection in a mesh (array),
cell selection in a mesh (pyTree).
P.interiorFaces:
select the interior faces of a mesh. Interior faces are faces with
two neighbours. If 'strict' is set to 1, select the interior faces
that have only interior nodes:
b = P.interiorFaces(a, strict=0)
Example of use: select interior faces (array),
select interior faces (pyTree).
P.exteriorFaces:
Select the exterior faces of a mesh, and return them in a single unstructured zone. If indices=[], the indices of the original exterior faces are stored.
b = P.exteriorFaces(a,indices=None)
Example of use: select exterior faces (array),
select exterior faces (pyTree).
P.exteriorFacesStructured:
Select the exterior faces of a structured mesh as a list of structured meshes:
b = P.exteriorFacesStructured(a)
Example of use: select structured exterior faces (array),
select structured exterior faces (pyTree).
P.exteriorElts:
select the exterior elements of a mesh, that is the first border fringe of cells:
b = P.exteriorElts(a)
Example of use: select exterior elements (array),
select exterior elements (pyTree).
P.frontFaces:
select faces that are located at the boundary where a tag indicator
change from 0 to 1:
b = P.frontFaces(a, tag)
Example of use: select a front in a tag (array),
select a front in a tag (pyTree).
P.sharpEdges:
return sharp edges arrays starting from surfaces or contours.
Adjacent cells having an angle deviating from more than alphaRef to 180 degrees are considered as sharp:
res = P.sharpEdges(A, alphaRef=30.)
Example of use: detect sharp edges of a surface (array),
detect sharp edges of a surface (pyTree).
P.silhouette:
return silhouette arrays starting from surfaces or contours, according to a direction vector.
res = P.silhouette(A, vector=[1.,0.,0.])
Example of use: detect silhouette of a surface (array),
detect silhouette of a surface (pyTree).
P.coarsen:
coarsen a triangle mesh by providing a coarsening indicator, which is 1 if the element must be coarsened, 0 elsewhere.
Triangles are merged by edge contraction, if tagged to be coarsened
by indic and if new triangles deviate less than tol to the original triangle.
Required mesh quality is controled by argqual: argqual equal to 0.5
corresponds to an equilateral triangle,
whereas a value near zero corresponds to a bad triangle shape.
Array version: an indic i-array must be provided, whose dimension ni
is equal to the number of elements in the initial triangulation:
b = P.coarsen(a, indic, argqual=0.1, tol=1.e6)
Example of use: coarsen all cells in a 2D mesh (array).
PyTree version: indic is stored as a solution located at centers:
b = P.coarsen(a, indicName='indic', argqual=0.25, tol=1.e-6)
Example of use: coarsen all cells in a 2D mesh (pyTree).
P.refine:
refine a triangle mesh by providing a refinement indicator, which is 1 if the element must be refined, 0 elsewhere.
Array version: an indic i-array must be provided, whose dimension ni
is equal to the number of elements in the initial triangulation:
b = P.refine(a, indic)
Example of use: refine all cells in a 2D mesh (array).
PyTree version: indic is stored as a solution located at centers:
b = P.refine(a, indicName='indic')
Example of use: refine all cells in a 2D mesh (pyTree).
P.refine:
refine a triangle mesh every where using butterfly interpolation with coefficient w:
b = P.refine(a, w=1./64.)
Example of use: refine all cells with butterfly interpolation (array),
refine all cells with butterfly interpolation (pyTree).
P.computeIndicatorValue:
compute the indicator value on the unstructured octree mesh a based on the absolute maximum
value of a varName field defined in the corresponding structured octree t.
In the array version, t is a list of zones, and in the pyTree version, it can be a tree or a base or a list of bases
or a zone or a list of zones.
Variable varName can be located at nodes or centers.
The resulting projected field is stored at centers in the octree mesh:
b = P.computeIndicatorValue(a, t, varName)
Example of use: project the maximum value of the indicator field on the octree mesh (array),
project the maximum value of the indicator field on the octree mesh (pyTree).
P.computeIndicatorField:
compute an indicator field to adapt an octree mesh with respect to the
required number of points nbTargetPts, a field, and bodies.
If refineFinestLevel=1, the finest level of the octree o is refined.
If coarsenCoarsestLevel=1, the coarsest level of the octree o is
coarsened provided the balancing is respected.
This function computes epsInf, epsSup, indicator such that when
indicVal < valInf, the octree is coarsened (indicator=-1), when
indicVal > valSup, the octree is refined (indicator=1).
For an octree defined in an array o, and the field in indicVal:
indicator, valInf, valSup = P.computeIndicatorField(o, indicVal, nbTargetPts=-1, bodies=[], refineFinestLevel=1, coarsenCoarsestLevel=1)
For the pyTree version, the name varname of the field on which is based
the indicator must be specified:
o, valInf, valSup = P.computeIndicatorField(o, varname, nbTargetPts=-1, bodies=[], refineFinestLevel=1, coarsenCoarsestLevel=1)
Example of use: compute the adaptation indicator (array),
compute the adaptation indicator (pyTree).
Solution extraction
P.extractPoint:
extract the field in one or several points, given a solution defined by A.
The extracted field(s) is returned as a list of values for each point.
If the point (x,y,z) is not interpolable from a grid, then 0 for all fields is returned.
In the pyTree version, extractPoint returns the extracted solution
from solutions located at nodes followed by the solution extracted from solutions at centers.
If 'cellN', 'ichim', 'cellnf', 'status', or 'cellNF' variable is defined,
it is returned in the last position in the output array.
The interpolation order can be 2, 3, or 5.
constraint is a thresold for extrapolation to occur. To enable more
extrapolation, rise this value.
If some blocks in A define surfaces, a tolerance 'tol' for interpolation cell search can be defined.
A hook can be defined in order to keep in memory the ADT on the
interpolation cell search.
It can be built and deleted by createHook and freeHook functions in Converter module, using 'extractMesh' function:
field = P.extractPoint(A, (x,y,z), order=2, constraint=40., tol=1.e-6, hook=None).or. F = P.extractPoint(A, [(x1,y1,z1),(x2,y2,z2)], order=2, constraint=40., tol=1.e-6, hook=None)
Example of use: extraction in one point (array),
extraction in one point (pyTree).
P.extractPlane:
slice a solution A with a plane.
The extracted solution is interpolated from A.
Interpolation order can be 2, 3, or 5
(but the 5th order is very time-consuming for the moment).
The best solution is kept. Plane is defined
by c1 x + c2 y + c3 z + c4 = 0:
b = P.extractPlane(A, (c1, c2, c3, c4), order=2, tol=1.e-6)
Example of use: extraction on a given plane (array),
extraction on a given plane (pyTree).
P.extractMesh:
Interpolate a solution from a set of donor zones defined by A to an extraction zone a.
Parameter order can be 2, 3 or 5, meaning that 2nd, 3rd and 5th order interpolations are performed.
Parameter constraint>0 enables to extrapolate from A if interpolation is not possible for some points.
Extrapolation order can be 0 or 1 and is defined by extrapOrder.
If mode='robust', extract from the node mesh (solution in centers is first
put to nodes, resulting interpolated solution is located in nodes).
If mode='accurate', extract node solution from node mesh and center solution
from center mesh (variables don't change location).
A preconditioning tree for the interpolation cell search can be built prior to extractMesh
(if is used several times for instance) and is stored in a hook. It can be created and deleted by C.createHook
and C.freeHook (see Converter module userguide):
b = P.extractMesh(A, a, order=2, extrapOrder=1, constraint=40., tol=1.e-6, mode='robust', hook=None)
Example of use: extraction on an extraction zone (array),
extraction on an extraction zone (pyTree).
P.projectCloudSolution:
Project the solution by a Least-Square Interpolation defined on a set of points pts defined as a 'NODE' zone
to a body defined by a 'TRI' mesh in 3D and 'BAR' mesh in 2D.:
b = P.projectCloudSolution(pts, t, dim=3)
Example of use: projectCloudSolution (array),
projectCloudSolution (pyTree).
P.zipper:
build an unstructured unique surface mesh, given a list of structured
overlapping surface grids A.
Cell nature field is used to find blanked (0) and interpolated (2) cells:
a = P.zipper(A, options=[])
The options argument is a list of arguments such as ["argName", argValue]. Option names can be:
- 'overlapTol' for tolerance required between two overlapping grids : if the projection distance between them
is under this value then the grids are considered to be overset. Default value is 1.e-5.
- For some cases, 'matchTol' can be set to modify the matching boundaries tolerance. Default value is set 1e-6.
In most cases, one needn't modify this parameter.
Example of use: zipping of an overset surface (array),
zipping an overset surface (pyTree).
P.usurp*:
an alternative to "zipper" is "usurp". Result is a ratio field
located at cell centers.
In case of no overset, ratio are set to 1, otherwise ratio represents
the percentage of overlap of a cell by another mesh.
When using the array interface, the input arrays are a
list of grid arrays A, defining nodes coordinates and a
corresponding list of arrays defining the chimera nature of cells at cell centers B. Blanked cells must be flagged by a null value.
Other values are equally considered as computed or interpolated cells:
C = P.usurp(A, B)
When using the pyTree interface, chimera cell nature field must be defined
as a center field in A:
B = P.usurp(A)
Warning: normal of surfaces grids defined by A must be
oriented in the same direction.
Example of use: ratio generation for the surface elements (array),
ratio generation for the surface elements (pyTree).
Streams
P.streamLine:
compute the stream line with N points starting from point (x0,y0,z0), given a solution A and a vector defined by 3 variables
['v1','v2,'v3'].
Parameter 'dir' can be set to 1 (streamline follows velocity), -1
(streamline follows -velocity), or 2
(streamline expands in both directions).
The output yields the set of N extracted points on the streamline,
and the input fields at these points. The streamline computation
stops when the current point is not interpolable from the input grids:
b = P.streamLine(A, (x0,y0,z0), ['v1','v2,'v3'], N=2000, dir=2)
Example of use: streamline extraction (array),
streamline extraction (pyTree) .
P.streamRibbon:
compute the stream ribbon starting from point (x0,y0,z0), of width and direction given by the vector (nx,ny,nz).
This vector must be roughly orthogonal to the vector ['v1', 'v2', 'v3'] at point (x0,y0,z0).
The output yields the set of N extracted points on the stream ribbon,
and the input fields at these points. The stream ribbon computation
stops when the current point is not interpolable from the input grids:
b = P.streamRibbon(A, (x0,y0,z0), (nx,ny,nz), ['v1', 'v2', 'v3'], N=2000, dir=2)
Example of use: stream ribbon extraction (array),
stream ribbon extraction (pyTree).
P.streamSurf:
compute the stream surface starting from a BAR array c:
b = P.streamSurf(A, c, ['v1','v2,'v3'], N=2000, dir=1)
Example of use: stream surface extraction (array),
stream surface extraction (pyTree).
Isos
P.isoLine:
compute an isoline correponding to value val of field:
b = P.isoLine(A, field, val)
Example of use: isoline (array),
isoline (pyTree).
P.isoSurf:
compute an isosurface correponding to value val of field (using marching
tetrahedra). Resulting solution is always located in nodes.
Return a list of two zones (one TRI and one BAR, if relevant):
B = P.isoSurf(A, field, val)
Example of use: isosurface (array),
isosurface (pyTree).
P.isoSurfMC:
compute an isosurface correponding to value val of field (using marching
cubes). Resulting solution is always located in nodes:
b = P.isoSurfMC(A, field, val)
Example of use: isosurface (array),
isosurface (pyTree).
Solution integration
For all integration functions, the interface is different when using
Converter arrays interface or pyTree interface. For arrays, fields
must be input separately, for pyTree, they must be defined in
each zone.
P.integ:
compute the integral of a scalar field (whose name is varString) over
the geometry defined
by arrays containing the coordinates + field ( + an optional ratio ).
Solution and ratio can be located at nodes or at centers.
For array interface:
res = P.integ([coord], [field], [ratio]=[])
For pyTree interface, the variable to be integrated can be specified. If no variable
is specified, all the fields located at nodes and centers are integrated:
res = P.integ(A, var='')
Example of use: scalar integration (array),
scalar integration (pyTree).
P.integNorm:
compute the integral of each scalar field times the surface normal
over the geometry defined by coord. For array interface:
res = P.integNorm([coord], [field], [ratio]=[])
For pyTree interface, the variable to be integrated can be specified. If no variable
is specified, all the fields located at nodes and centers are integrated:
res = P.integNorm(A, var='')
Example of use: integration dot the surface normal (array),
integration dot the surface normal (pyTree).
P.integNormProduct:
compute the integral of a vector field times the surface normal
over the geometry defined by coord. The input field must have 3
variables. For array interface, field must be a vector field:
res = P.integNormProduct([coord], [field], [ratio]=[])
For pyTree interface, the vector field to be integrated must be specified:
res = P.integNormProduct(A, vector=[])
Example of use: integration cross the surface normal (array),
integration cross the surface normal (pyTree).
P.integMoment:
compute the integral of a moment over the geometry defined by coord.
The input field must have 3
variables. (cx,cy,cz) are the center coordinates. For array interface:
res = P.integMoment([coord], [field], [ratio]=[], center=(0.,0.,0.))
For pyTree interface, the vector of variables to be integrated must be specified:
res = P.integMoment(A, center=(0.,0.,0.), vector=[])
Example of use: moment integration (array),
moment integration (pyTree).
P.integMomentNorm:
compute the integral of a moment over the geometry defined by coord, taking into account the surface normal.
The input field is a scalar. For array interface:
res = P.integMomentNorm([coord], [field], [ratio]=[], center=(cx,cy,cz))
For pyTree interface, the variable to be integrated can be specified. If no variable
is specified, all the fields located at nodes and centers are integrated:
res = P.integMomentNorm(A, center=(cx,cy,cz), var='')
Example of use: moment integration with normal (array),
moment integration with normal (pyTree).
Return to main userguide