Converter: CFD Data Conversion
Version: 2.4 (29/03/2017)
Author: Onera

Preamble
This module provides functions for CFD data conversion (both file format
and grid topology).
This module is part of Cassiopee, a free open-source
pre- and post-processor for CFD simulations.
This module can manipulate two different data structures:
the first one is called an array, the second one is called
a pyTree.
Name standardisation
Some functions of Converter, Post and other modules perform specific
treatments for given variables.
For instance, the computeVariables function in the Post module can compute
the pressure automatically if density and velocity are defined with
their CGNS names.
Recognised names are CGNS names, but
some alternative names are also recognised.
Names are described in the following table:
Description
|
CGNS
|
Alternative names
|
Coordinate in x direction
|
CoordinateX
|
x, X
|
Coordinate in y direction
|
CoordinateY
|
y, Y
|
Coordinate in z direction
|
CoordinateZ
|
z, Z
|
Density
|
Density
|
ro
|
Momentum in x direction
|
MomentumX
|
rou, rovx
|
Momentum in y direction
|
MomentumY
|
rov, rovy
|
Momentum in z direction
|
MomentumZ
|
row, rovz
|
Density times total energy
|
EnergyStagnationDensity
|
roE
|
Density times turbulence kinetic energy
|
TurbulentEnergyKineticDensity
|
rok
|
Density times dissipation rate of turbulence kinetic energy
|
TurbulentDissipationDensity
|
roeps
|
Static pressure
|
Pressure
|
|
Dynamic pressure
|
PressureDynamic
|
|
Static temperature
|
Temperature
|
|
Enthalpy
|
Enthalpy
|
|
Entropy
|
Entropy
|
|
Stagnation pressure
|
PressureStagnation
|
|
Stagnation temperature
|
TemperatureStagnation
|
|
x-component of the absolute velocity
|
VelocityX
|
|
y-component of the absolute velocity
|
VelocityY
|
|
z-component of the absolute velocity
|
VelocityZ
|
|
Absolute velocity magnitude
|
VelocityMagnitude
|
|
Absolute Mach number
|
Mach
|
|
Molecular viscosity
|
ViscosityMolecular
|
|
Cell Nature Field (0:blanked, 1:discretised, 2:interpolated)
|
|
cellN, cellnf
|
Cell Nature Field (0:blanked, 1:discretised, -Id:-interpolation block Id)
|
|
cellNF, cellnf, cellNF, ichim
|
Cell Status (-1:orphan, 0:blanked, 1:discretised, 2:interpolated explicitly, 3:extrapolated, 4:interpolated implicitly)
|
|
status
|
Array creation and manipulations
C.array:
create a structured array containing variables x,y,z on a nixnjxnk grid:
a = C.array('x,y,z', ni, nj, nk)
Create an unstructured array containing variables x,y,z on a grid
containing np points and ne elements of type ELTTYPE (=NODE, BAR, TRI, QUAD, TETRA, PYRA, PENTA, HEXA, NGON):
a = C.array('x,y,z', np, ne, ELTTYPE)
Example of use: array creation (array).
C.getValue:
return the list of values defined in array a for point of index ind
(for both structured and unstructured arrays). For structured arrays, you
can specify (i,j,k) instead of ind. For unstructured arrays, the index ind
corresponds to the location type of point defining array a: for instance,
if array a describes a field at element vertices, ind is a vertex index
(ind starts at 0 and (i,j,k) start at 1):
v = C.getValue(a, ind)
Example of use: get values for a given grid index (array).
C.setValue:
set the values of one point of index ind in array a. v must be a list corresponding to the variables stored in array a:
C.setValue(a, ind, v)
Example of use: set values for a given grid index (array).
C.addVars:
add variable(s) to an array. Variables argument can be a string
name ('ro') or a list of string names (['ro', 'rou']):
b = C.addVars(a, 'ro') .or. B = C.addVars(A, 'ro')
Example of use: variables adding (array).
C.addVars:
concatenate array fields with the same dimensions.
Variables defined by a list of arrays are put in the same array:
f = C.addVars([a, b, c])
Example of use: many variables adding (array).
C.copy:
copy an array (return a new duplicated array):
b = C.copy(a) .or. B = C.copy(A)
Example of use: array copy (array).
pyTree creation and manipulations
C.newPyTree:
create a new pyTree. You can specify base names, cell dimension in base, and attach zone nodes
eventually:
A = C.newPyTree(['Base1', 2, 'Base2', 3]) .or. A = C.newPyTree(['Base1', z1, z2])
Example of use: pyTree creation (pyTree).
C.getNobOfBase:
get the number of a given base a in topTree base list, such that
topTree[2][nob] = a:
nob = C.getNobOfBase(a, topTree)
Example of use: get base number (pyTree).
C.getNobNozOfZone:
get the number (nob, noz) of a given zone a in topTree base and zone list ,
such that topTree[2][nob][2][noz] = a:
(nob, noz) = C.getNobNozOfZone(a, topTree)
Example of use: get base and zone number (pyTree).
C.breakConnectivity:
break a multi-element zone (unstructured) into single element zones:
B = C.breakConnectivity(a) .or. B = C.breakConnectivity(A)
Example of use: break a multiple connectivity zone into two zones (pyTree).
C.mergeConnectivity:
merge two zones (unstructured) into a single zone with a multiple
connectivity. If boundary=1, b will be a BC connectivity in a (b must be
a subzone of a), if boundary=0, b will be a element connectivity:
a = C.mergeConnectivity(a, b, boundary=0)
Example of use: merge two zones into a multiple connectivity zone (pyTree).
C.mergeTrees:
merge two trees in one. Only basis of B are added to A:
D = C.mergeTrees(A, B)
Example of use: merge of pyTrees (pyTree).
C.deleteEmptyZones:
delete structured zones with a null ni, nj or nk, delete unstructured
zones with a null number of nodes or elements:
B = C.deleteEmptyZones(A)
Example of use: delete empty zones (pyTree).
C.addBase2PyTree:
add a base named 'baseName' to a pyTree. Third argument specifies the
cell dimension (cellDim=3 for volume meshes, cellDim=2 for surface meshes):
B = C.addBase2PyTree(A, baseName, cellDim=3)
Example of use: add a base to pyTree (pyTree).
C.addState:
add a FlowEquation or a ReferenceState data to a base or a zone or a node:
B = C.addState(A, state, value)
Example of use: add a state to a base (pyTree).
Add a full ReferenceState data to a base or a zone or a node:
B = C.addState(A, MInf=0.5, alphaZ=0., alphaY=0., ReInf=1.e8, MutSMuInf=0.2, TurbLevelInf=1.e-4)
Example of use: add a state to a base (pyTree).
C.addChimera2Base:
add Chimera settings data to a base. Settings are added in
a .Solver#Chimera user defined node:
B = C.addChimera2Base(A, setting, value)
Example of use: add Chimera settings to a base (pyTree).
C.addBC2Zone:
add a physical boundary condition (BC) or a grid connectivity (GC) to a structured/basic element/NGON zone
of a PyTree.
Parameter bndName is the name of the BC or GC.
Parameter bndType is the type of BC, according to the CGNS Standard or 'BCMatch' for a 1-to-1 abutting GC,
'BCNearMatch' for 'n-to-m' abutting GC (only for structured grids), 'BCOverlap' for an overset GC, or
'FamilySpecified:FAMILY' for a BC specified in a family BC named FAMILY.
Data is optional data that will be stored in a BCDataSet.
For structured grids, parameter 'range' specifies the window where the BC is applied.
It can be defined by a list of indices [imin, imax, jmin, jmax, kmin, kmax] or by 'imin', 'jmin', ...
if the BC is defined on the whole window ('imin' stands for i=1, 'imax' for i=imax).
A physical BC for a structured grid is defined by:
b = C.addBC2Zone(a, bndName, bndType, range, data=None)
For a 1-to-1 abutting GC, donor zone and range and transformation must be specified:
b = C.addBC2Zone(a, bndName, 'BCMatch', range, zoneDonor=donorZone, rangeDonor=donorRange, trirac=[-1,2,3])
For periodic 1-to-1 GC, you must specify rotationCenter, rotationAngle and translation:
b = C.addBC2Zone(a, bndName, 'BCMatch', range, zoneDonor=donorZone, rangeDonor=donorRange, trirac=[-1,2,3],
rotationCenter=(0,0,0), rotationAngle(0,0,25.), translation=(0,0,0))
For an overlap GC, donor zones can be provided as a list of zones or a list of zone names (optional).
If the window range defines an overset GC and a physical BC, then 'doubly_defined' must be set for the
'rangeDonor' parameter.
b = C.addBC2Zone(a, bndName, 'BCOverlap', range, zoneDonor=donorZones, rangeDonor='doubly_defined')
For basic element unstructured zones, the location of the BC/GC can be specified either by a list of faces
defined by 'faceList', either by 'elementList' or 'elementRange' referencing an existing boundary
connectivity, or by a subzone:
b = C.addBC2Zone(a, bndName, bndType, faceList=[], data=None).or.
b = C.addBC2Zone(a, bndName, bndType, elementList=[], data=None) .or.
b = C.addBC2Zone(a, bndName, bndType, elementRange=[], data=None) .or.
b = C.addBC2Zone(a, bndName, bndType, subzone=z, data=None)
For NGON zones, only faceList or subzone can be used:
b = C.addBC2Zone(a, bndName, bndType, faceList=[], data=None).or.
b = C.addBC2Zone(a, bndName, bndType, subzone=z, data=None)
Example of use: add a boundary condition to a structured zone node of a pyTree.
Example of use: add a boundary condition to a NGON zone node of a pyTree.
C.fillEmptyBCWith:
fill empty boundary conditions of a structured tree/base/list of
zones/zone with the given boundary condition. Parameter dim can be 2 or 3:
b = C.fillEmptyBCWith(a, bndName, bndType, dim=3) .or. B = C.fillEmptyBCWith(A, bndName, bndType, dim=3)
Example of use: fill missing boundary conditions (pyTree).
C.rmBCOfType:
remove all boundaries of a given type from a pyTree. bndType can also
be a family BC name ('FamilySpecified:FAMILY'):
b = C.rmBCOfType(a, 'BCWall') .or. B = C.rmBCOfType(A, 'BCWall')
Example of use: remove wall boundaries from a pyTree (pyTree).
C.rmBCOfName:
remove the boundary of given name from a pyTree. bndName accepts
wildcard and can also be a family BC name ('FamilySpecified:FAMILY'):
b = C.rmBCOfName(a, 'wall*') .or. B = C.rmBCOfName(A, 'wall*')
Example of use: remove boundaries from a pyTree by name (pyTree).
C.extractBCOfType:
extract all boundaries of a given type from a pyTree,
return a list of zones. bndType can also be a family BC name ('FamilySpecified:FAMILY):
Z = C.extractBCOfType(a, 'BCWall') .or. Z = C.extractBCOfType(A, 'BCWall')
Example of use: extract wall boundaries from a pyTree (pyTree).
C.extractBCOfName:
extract all boundaries of a given name from a pyTree, return a list
of zones. bndName accepts wildcards or can be a family name ('FamilySpecified:FAMILY'):
Z = C.extractBCOfName(a, 'wall1') .or. Z = C.extractBCOfName(A, 'wall1')
Example of use: extract given named boundaries from a pyTree (pyTree).
C.getEmptyBC:
return undefined boundary conditions for a zone node, a list
of zone nodes or a complete pyTree, as a list of the range
[imin,imax,jmin,jmax,kmin,kmax] of undefined boundaries for structured
zones and as a list of face indices for unstructured zones.
Lists are empty ([[],...,[]]) if all the boundary conditions
have been defined. Parameter dim can be 2 or 3. For unstructured grids,
undefined boundaries can be split if the angle between neighbouring
elements exceeds splitFactor in degrees (default no split):
wins = C.getEmptyBC(a, dim=3, splitFactor=180.) .or. wins = C.getEmptyBC(A, dim=3, splitFactor=180.)
Example of use: detection of undefined BC in a pyTree (pyTree).
C.getConnectedZones:
get zones connected to a given zone a by 'BCMatch' or 'BCNearMatch' or 'all' (defined in zone GridConnectivity):
Z = C.getConnectedZones(a, topTree, type='all') .or. Z = C.getConnectedZones(A, topTree, type='all')
Example of use: return connected zones (pyTree).
C.addFamily2Base:
add a family node to a base node of a tree. If this node defines
a BC type, bndType must be defined:
B = C.addFamily2Base(A, familyName, bndType=None)
Example of use: add a family name to a Python tree (pyTree).
C.tagWithFamily:
Tag a zone node or a BC node a with a family name:
b = C.tagWithFamily(a, familyName)
Example of use: tag zones with a family name (pyTree).
C.getFamilyZones:
get all zones of a family name:
b = C.getFamilyZones(a, familyName)
Example of use: get all zones of a family name (pyTree).
C.getFamilyBCs:
get all BC nodes of a given familyName:
b = C.getFamilyBCs(a, familyName)
Example of use: get all BC nodes with a BC family name (pyTree).
C.getFamilyZoneNames:
get all family zone names in A (A must be a base node or a tree node):
names = C.getFamilyZoneNames(A)
Example of use: get family BC names in a tree (pyTree).
C.getFamilyBCNamesOfType:
get all family BC names of this type (A must be a base node or a tree node):
names = C.getFamilyBCNamesOfType(A, bndType=None)
Example of use: get family BC names in a tree (pyTree).
C.rmNodes:
remove nodes named 'name' from a for each zone:
b = C.rmNodes(a, name) .or. B = C.rmNodes(A, name)
Example of use: remove specified nodes from a pyTree (pyTree).
C.getValue:
return the list of values defined in a zone a for point of index ind
(for both structured and unstructured zones).
For structured zones, you can specify (i,j,k) instead of ind.
For unstructured zones, the index ind
corresponds to the location type of point defining zone a:
for instance, if
a describes a field at element vertices, ind is a vertex index.
var is the name of the variable:
v = C.getValue(a, var, ind)
ind starts at 0 and (i,j,k) start at 1.
Example of use: get values for a given grid index (pyTree).
C.setValue:
set the values of one point of index ind in a zone a.
var is the name of the variables to be modified, value can be a
float or a list of floats
corresponding to the values of the variables to be modified:
C.setValue(a, var, ind, value)
Example of use: set values for a given grid index (pyTree).
C.setPartialFields:
set the values for a given list of indices. Field values are
given as a list of arrays in F (one array for each zone), indices
are given as a list of numpys in I (one numpy for each zone), loc can
be 'nodes' or 'centers':
b = C.setPartialFields(a, F, I, loc='nodes') .or. B = C.setPartialFields(A, F, I, loc='nodes')
Example of use: set values for a list of indices (pyTree).
C.setPartialFields1:
set the values for a given list of indices. Field values are
given as a list of numpys in F (a list of numpys for each zone and for
each field), indices are given as a list of numpys in I (one numpy
for each zone), loc can be 'nodes' or 'centers':
b = C.setPartialFields1(a, F, I, loc='nodes') .or. B = C.setPartialFields1(A, F, I, loc='nodes')
Example of use: set values for a list of indices (pyTree).
C.addVars:
add a variable(s) to a zone. var is a string name or a list
of string names (e.g. 'Density',...), variable localisation
('nodes' or 'centers') can be specified in var:
b = C.addVars(a, var) .or. B = C.addVars(A, var)
Example of use: variables adding (pyTree).
C.fillMissingVariables:
fill FlowSolution_t nodes with variables defined in a zone, such that all the zones have the same variables:
b = C.fillMissingVariables(a)
Example of use: variable filling (pyTree).
C.cpVars:
copy a variable from zone a1, with name var1, to zone a2, with name var2.
The var location must be coherent:
b = C.cpVars(a1, var1, a2, var2)
Example of use: copy a variable (pyTree).
C.printTree:
pretty print a pyTree to screen or in a file:
C.printTree(A, file=None)
Example of use: print a pyTree to screen (pyTree).
Array / pyTree common manipulations
C.getVarNames:
return the list of variable names contained in a. Localization of variables can be specified ('nodes', 'centers', 'both'):
V = C.getVarNames(a, excludeXYZ=False, loc='both') .or. V = C.getVarNames(A)
Example of use: get variable names (array),
get variable names (pyTree).
C.isNamePresent:
return -1 if A doesn't contain varName, 0 if at least one zone in A
contains varName, 1 if all zones in A contain varName:
ret = C.isNamePresent(a, varName) .or. ret = C.isNamePresent(A, varName)
Example of use: is variable present? (array),
is variable present? (pyTree).
C.getNPts:
return the number of points in a:
npts = C.getNpts(a) .or. npts = C.getNpts(A)
Example of use: get the number of points of a given array (array), get the number of points of a given pyTree (pyTree).
C.getNCells:
return the number of cells in a:
ncells = C.getNCells(a) .or. ncells = C.getNCells(A)
Example of use: get the number of cells of a given array (array), get the number of cells of a given pyTree (pyTree).
C.initVars:
init variable given by a string to a constant value val:
b = C.initVars(a, 'cellN', val) .or. B = C.initVars(A, 'cellN', val)
Example of use: variable initialisation (array),
variable initialisation (pyTree).
Init a variable (named 'x') with a function f. Function f has two arguments here, named 'x','y'. Variables location can not be mixed:
b = C.initVars(a, 'x', f, ['x','y']) .or. B = C.initVars(A, 'x', f, ['x','y'])
Example of use: variable initialisation by a function.
Init a variable by a formula string. Variables must be separated by {}.
Variables location can not be mixed:
b = C.initVars(a, '{Density} = 3 * {x}') .or. B = C.initVars(A, '{Density} = 3 * {x}')
Example of use: variable initialisation by a formula (array). ,
variable initialisation by a formula (pyTree).
C.extractVars:
extract variables named 'F','G' from a (other variables are removed):
b = C.extractVars(a, ['F','G']) .or. B = C.extractVars(A, ['F','G'])
Example of use: variables extraction (array),
variables extraction (pyTree).
C.rmVars:
remove a variable(s). var is a string name or a list of string names:
b = C.rmVars(a, var) .or. B = C.rmVars(A, var)
Example of use: remove a variable (array),
remove a variable (pyTree).
C.convertArray2Tetra:
create tetra unstructured array from an array. 2D elements are made triangular, else they are made tetrahedral.
If split='simple', conversion does not create new points. If split='withBarycenters', barycenters of elements and faces are added:
b = C.convertArray2Tetra(a, split='simple') .or. B = C.convertArray2Tetra(A, split='simple')
Example of use: tetrahedral array creation from structured array (array),
tetrahedral zone creation from structured zone (pyTree).
Example of use: tetrahedral array creation from hexahedral array (array).
Example of use: tetrahedral array creation from prismatic array (array).
C.convertArray2Hexa:
Create hexa unstructured array from an array. 2D elements are made quadrangular, else they are made hexahedral:
b = C.convertArray2Hexa(a) .or. B = C.convertArray2Hexa(A)
Example of use: hexahedral array creation from a structured array (array),
hexahedral zone creation from a structured zone (pyTree).
C.convertArray2NGon:
create an NGON array from an array:
b = C.convertArray2NGon(a) .or. B = C.convertArray2NGon(A)
Example of use: NGON array creation from a structured array (array),
NGON zone creation from a structured zone (pyTree).
C.convertArray2Node:
create a node array from an array (discarding any connectivity):
b = C.convertArray2Node(a) .or. B = C.convertArray2Node(A)
Example of use: node array creation from a structured array (array),
node zone creation from a structured zone (pyTree).
C.convertBAR2Struct:
create a structured 1D array from a BAR array. The BAR array must not contain branches:
b = C.convertBAR2Struct(a) .or. B = C.convertBAR2Struct(A)
Example of use: conversion from a BAR to an i-array (array),
conversion from a BAR zone to a structured zone (pyTree).
C.convertTri2Quad:
convert a TRI-array to a QUAD-array. Neighbouring cells with an
angle lower than alpha can be merged.
It returns the QUAD-array b and
the rest of not merged cells in a TRI-array c:
b, c = C.convertTri2Quad(a, alpha=30.) .or. B, C = C.convertTri2Quad(A, alpha=30.)
Example of use: conversion from a TRI to QUAD (array),
conversion from TRI zone to QUAD zone (pyTree).
C.conformizeNGon:
conformize the cell faces of a NGon, such that a face of a cell corresponds
to a unique face of another cell:
b = C.conformizeNGon(a, tol=1.e-6) .or. B = C.conformizeNGon(A, tol=1.e-6)
Example of use: NGon conformization (array),
NGon conformization (pyTree).
C.node2Center:
convert data (grid coordinates and solution), defined at nodes in a,
to centers:
b = C.node2Center(a) .or. B = C.node2Center(A)
When using the pyTree interface, a varname can be additionaly specified.
Then, only the variable 'varname'
is computed at centers and set in returned zone
FlowSolution#Centers location:
b = C.node2Center(a, 'Density') .or. B = C.node2Center(A, 'Density')
Example of use: node to center conversion (array),
node to center conversion (pyTree).
C.center2Node:
Change data, defined at centers in a, to nodes. cellNType indicates the
treatement for blanked points when cellN field is present. cellNType=0, means that, if a node receives at least one cellN=0 value from a center, its cellN is set to 0. cellNType=1 means that, only if all values of neighbouring centers are cellN=0, its cellN is set to 0:
b = C.center2Node(a, cellNType=0) .or. B = C.center2Node(A, cellNType=0)
When using the pyTree interface, a varname can be additionaly specified.
Then, only the variable 'varname' is computed at nodes and set in zone
FlowSolution location:
b = C.center2Node(a, 'centers:Density') .or. B = C.center2Node(A, 'centers:Density')
Example of use: center to node conversion (array),
center to node conversion (pyTree).
C.node2ExtCenters:
Convert grid coordinates, defined at nodes in a, to extended centers:
b = C.node2ExtCenter(a) .or. B = C.node2ExtCenter(A)
Example of use: node to extended centers conversion (array),
nodes to extended centers conversion (pyTree).
Array / pyTree analysis
C.diffArrays:
given a solution A and a solution B both defined on the same mesh,
return the differences:
C = C.diffArrays(A, B)
Example of use: diffing (array),
diffing (pyTree).
C.getArgMin:
return the field value where variable 'ro' is minimum:
min = C.getArgMin(a, 'ro') .or. min = C.getArgMin(A, 'ro')
Example of use: get the field value where x is minimum (array),
get the field value where x is minimum (pyTree).
C.getArgMax:
Return the field value where variable 'ro' is maximum:
max = C.getArgMax(a, 'ro') .or. max = C.getArgMax(A, 'ro')
Example of use: get the field value where x is maximum (array),
get the field value where x is maximum (pyTree).
C.getMinValue:
return the min value of variable 'ro':
min = C.getMinValue(a, 'ro') .or. min = C.getMinValue(A, 'ro')
Example of use: get the min value of x in a mesh (array),
get the min value of x in a mesh (pyTree).
C.getMaxValue:
return the max value of variable 'ro':
max = C.getMaxValue(a, 'ro') .or. max = C.getMaxValue(A, 'ro')
Example of use: get the max value of x in a mesh (array),
get the max value of x in a mesh (pyTree).
C.getMeanValue:
return the mean value of variable 'ro':
mean = C.getMeanValue(a, 'ro') .or. mean = C.getMeanValue(A, 'ro')
Example of use: get the mean value of x in a mesh (array),
get the mean value of x in a mesh (pyTree).
C.getMeanRangeValue:
return the mean value of variable 'ro' for the 20% biggest values (between 80% and 100%):
mean = C.getMeanRangeValue(a, 'ro', 0.8, 1.) .or. mean = C.getMeanRangeValue(A, 'ro', 0.8, 1.)
Example of use: get the mean value of x in a sorted range of values (array),
get the mean value of x in a sorted range of values (pyTree).
C.normL0, C.normL2:
L0 and L2 norms of a field defined in an array can be extracted. If cellnature field is defined in the array, then blanked points are not taken into account into the computation of the norm:
L0norm = C.normL0(a, 'ro') .or. L0norm = C.normL0(A, 'ro')
Example of use: get the L0 norm of variable x (array),
get the L0 norm of variable x (pyTree).
L2norm = C.normL2(a, 'ro') .or. L2norm = C.normL2(A, 'ro')
Example of use: get the L2 norm of a field (array),
get the L2 norm of a field (pyTree).
C.normalize:
Normalize a vector defined by its 3 vector coordinates. The vector component values are modified:
b = C.normalize(a, ['sx', 'sy', 'sz']) .or. B = C.normalize(A, ['sx', 'sy', 'sz'])
Example of use: normalize a vector (array),
normalize a vector located at centers (pyTree).
C.magnitude:
get the magnitude of a vector for each point of array:
b = C.magnitude(a, ['sx', 'sy', 'sz']) .or. B = C.magnitude(A, ['sx', 'sy', 'sz'])
Example of use: get the magnitude of a vector (array),
get the magnitude of a vector (pyTree).
C.randomizeVar:
randomize a variable of name varname. The modified field is bounded by [f-deltamin,f+deltamax] where f is the local field.
b = C.randomizeVar(a, varname, deltamin, deltamax) .or. B = C.randomizeVar(A, varname, deltamin,deltamax)
Example of use: randomize a field (array),
randomize a field (pyTree).
Array / pyTree conversion
C.convertPyTree2ZoneNames:
return the list of zone paths (strings) contained in a Python tree:
P = C.convertPyTree2ZoneNames(T)
Example of use: zone name extraction from a Python tree (pyTree).
C.convertPyTree2Array:
convert a Python tree node to an array.
One have to provide
the path of the corresponding node and the Python tree:
a = C.convertPyTree2Array("Zone-001/GridCoordinates/CoordinateX", T)
Example of use: node of Python tree to array conversion (pyTree).
File / arrays or File / pyTree conversion
C.convertFile2Arrays:
read a file and return a list of arrays:
A = C.convertFile2Arrays(fileName, format=None, options)
For format needing multiple files (for ex: plot3d), multiple files can
be specified in file name string as: "file.gbin,file.qbin".
In file format where variables name are undefined, the following one is
adopted: x, y, z, ro, rou, rov, row, roE, cellN.
If format is unspecified, the format is guessed from file extension.
Several options are available to specify the discretization
of vector elements (as defined in xfig or svg):
Option name
|
Meaning
|
Default value
|
nptsCurve
|
Number of discretization points for curved vector elements
|
20
|
nptsLine
|
Number of discretization points for line vector elements
|
2
|
density
|
Number of discretization points per unit length in the output curve
|
No default value (nptsLine, nptsCurve are used by default)
|
C.convertArrays2File:
write a list of arrays to a file:
C.convertArrays2File(A, fileName, format=None, options)
The following additionnal options are available:
Option name
|
Meaning
|
Possible values
|
Default value
|
int
|
size of integer
|
4, 8
|
4
|
real
|
size of real
|
4, 8
|
8
|
endian
|
endianess
|
'little', 'big'
|
'big'
|
colormap (pov)
|
colormap style
|
1, 2,...
|
0
|
dataFormat
|
'printf' compatible data format (%[width][.precision]specifier)
|
'%f ', '%.9e ', '%16.9e' ...
|
'%.9e '
|
zoneNames
|
list of zone names (struct zones, then unstruct zones)
|
['Zone1','Zone2','ZoneTampon']
|
[]
|
C.convertFile2PyTree:
read a file to a pyTree:
A = C.convertFile2PyTree('in.cgns', 'bin_cgns')
Example of use: read a file in a tree.
C.convertPyTree2File:
write a Python tree to a file:
C.convertPyTree2File(A, 'out.cgns', 'bin_cgns')
Example of use: write a Python tree to a file.
Recognised formats are:
Conversion to elsA profile
Following functions are specific to the elsA CGNS profile.
C.elsAProfile.convert2elsAxdt:
convert a pyTree a to a pyTree b usable with elsA. If pyTree contains periodic matching joins, elsA parameter 'axis_ang_2' is set to 1.:
import Converter.elsAProfile
b = Converter.elsAProfile.convert2elsAxdt(a)
Example of use: convert a pyTree to a tree compatible with elsA.
C.elsAProfile.addReferenceState:
add a reference state node in each base. You must specify conservative as
a list of reference conservative values. You can optionaly specify
temp, a reference temperature, turbmod, the turbulence model
in 'komega', 'kkl', 'smith', 'spalart', 'keps', 'rsm', and reference
values for k and eps.
Name of node and comments can also be specified:
B = Converter.elsAProfile.addReferenceState(A, conservative=[1.,...],
temp=None,
turbmod='spalart', name='ReferenceState', comments=None, k=None, eps=None)
Example of use: add a reference state compatible with elsA.
C.elsAProfile.addGlobalConvergenceHistory:
add a convergence node in each base. The type of norm used in
residual computation can be specified (0: L0, 1: L2):
B = Converter.elsAProfile.addGlobalConvergenceHistory(A, normValue=0)
Example of use: add a convergence node compatible with elsA.
C.elsAProfile.addFlowSolution:
add a FlowSolution node for each zone. name is a suffix that can be appened to the 'FlowSolution' name. loc must be 'Vertex' or 'CellCenter' or 'cellfict'. governingEquation is the name of the 'GoverningEquation' node. output
can be optionaly a dictionary specifying the '.Solver#Output' node data.
If addBCExtract is true, the boundary windows are also extracted. protocol
is an optional string in 'iteration', 'end', 'after', specifying when extraction is performed:
B = Converter.elsAProfile.addFlowSolution(A, name='', loc='CellCenter', variables=None,
governingEquations=None, writingMode=None,
writingFrame='relative', period=None, output=None,
addBCExtract=False, protocol="end")
B = Converter.elsAProfile.addFlowSolutionEoR(A, name='', loc='CellCenter', variables=None,
governingEquations=None, writingMode=None,
writingFrame='relative', period=None, output=None,
addBCExtract=False, protocol="end")
Example of use: add a flow solution extraction node.
C.elsAProfile.addOutputForces:
add an output forces node to a BC or a family BC node. name is an optional
string to complete output node name, var is a list of variables to extract,
writingmode specifies the elsA writing mode. period specifies the number of
iterations between two extractions. pinf is the value of infinite
stagnation pressure. fluxcoeff is an optional value used to correct
the extracted value. torquecoeff is an optional value used to
correct the extracted value. xyz torque is the origin for torque.
frame must be in ['relative','absolute']:
B = Converter.elsAProfile.addOutputForces(A, name="", var=None,
loc=4, writingmode=1, period=None, pinf=None, fluxcoef=None,
torquecoef=None, xyztorque=None, frame=None,
governingEquations="NSTurbulent", xtorque=None,
ytorque=None, ztorque=None)
Example of use: add a forces output node.
C.elsAProfile.addOutputFriction:
add an output friction node to a BC or a family BC node. name is an optional
string to complete output node name, var is a list of variables to extract.
loc specifies the location of extraction.
writingmode specifies the elsA writing mode. period specifies the number of
iterations between two extractions.
fluxcoeff is an optional value used to correct the extracted value:
B = Converter.elsAProfile.addOutputFriction(A, name="", var=None,
loc=4, writingmode=1, period=None, fluxcoef=None,
torquecoef=None, writingframe=None)
Example of use: add a friction output node.
Preconditionning (hook)
C.createHook:
create a hook for each zone in a. The hook is used to store pre-computed data on a,
and can be reused by a function if the zones defined in a are not modified.
Parameter 'function' can be:
function name
|
Type of storage
|
Usage
|
'extractMesh'
|
Bounding boxes of cells stored in an ADT.
Valid for structured and TETRA zones.
|
Post.extractMesh, Post.extractPoint functions
|
'adt'
|
Bounding boxes of cells stored in an ADT.
Valid for 3D structured and TETRA and 2D structured zones (nk=1 and z constant).
|
Connector.setInterpData, Connector.setIBCData functions
|
'nodes'
|
Mesh nodes stored in a k-d tree
|
Converter.identifyNodes, Converter.nearestNodes
|
'faceCenters'
|
Mesh face centers stored in a k-d tree
|
Converter.identifyFaces, Converter.nearestFaces
|
'elementCenters'
|
Element centers stored in a k-d tree
|
Converter.identifyElements, Converter.nearestElements
|
Function usage:
hook = C.createHook(a, function)
Example of use: create a hook for extractMesh (array),
create a hook for extractMesh (pyTree).
C.createGlobalHook:
create a global hook on a preconditioning tree.
If extended=0, returns the hook in a list.
If extended=1, returns the hook and an indirection numpy array of block number for each point stored in the preconditioning tree defined in the hook.
Parameter 'function' can be:
function name
|
Type of storage
|
Usage
|
'nodes'
|
Mesh nodes stored in a global k-d tree
|
Converter.identifySolutions
|
'faceCenters'
|
Mesh face centers stored in a global k-d tree
|
Converter.identifySolutions
|
'elementCenters'
|
Element centers stored in a global k-d tree
|
Converter.identifySolutions
|
hook = C.createGlobalHook(A, function='None')
Example of use: create a global hook (array),
create a global hook (pyTree).
C.freeHook:
free a hook created by createHook:
C.freeHook(hook)
Example of use: free hook (array),
free hook (pyTree).
Geometrical identification
C.identifyNodes:
identify nodes of a with points stored in hook. Return the indices
of hook corresponding to the nodes of a:
C.identifyNodes(hook, a, tol=1.e-12)
Example of use: identify nodes in hook (array),
identify nodes in hook (pyTree).
C.identifyFaces:
identify face centers of a with points stored in hook. Return the indices
of hook corresponding to the faces of a:
C.identifyFaces(hook, a, tol=1.e-12)
Example of use: identify faces in hook (array),
identify faces in hook (pyTree).
C.identifyElements:
identify element centers of a with points stored in hook. Return the
indices of hook corresponding to the elements of a:
C.identifyElements(hook, a, tol=1.e-12)
Example of use: identify elements in hook (array),
identify elements in hook (pyTree).
C.identifySolutions:
Copy the field defined on given donor zones to
receptor zones where points are at a distance inferior to tol.
This function doesn't perform interpolation but directly copy
the field of the nearest donor points, if it is nearer than tol.
Otherwise the field is set to 0.
The array interface returns the arrays corresponding to fields
defined in solDnr. The arrays coordsRcv
are the receptor coordinate arrays. Donor coordinates are
stored in a kdtree hook:
b = C.identifySolutions(coordsRcv, solDnr, hookDnr, vars=[], tol=1.e-12)
The pyTree interface requires a donor and a receptor pyTree.
hookN can store the coordinates of donor nodes,
and hookC can store the coordinates of donor cell centers.
If hookN=None or hookC=None, then solution is not identified for nodes
or centers respectively.
The variables that must be identified can be specified by the list of
string vars. If vars=[], then all the variables of tDnr are set to tRcv:
t = C.identifySolutions(tRcv, tDnr, hookN=None, hookC=None, vars=[], tol=1.e-12)
Example of use: copy solution to a mesh (array),
copy solution to a mesh (pyTree).
C.nearestNodes:
find nearest points stored in hook to nodes of a. Return the indices
of hook nearest to the nodes of a and the corresponding distance:
C.nearestNodes(hook, a)
Example of use: find nearest points to nodes in hook (array),
find nearest points to nodes in hook (pyTree).
C.nearestFaces:
find nearest points stored in hook to face centers of a. Return the indices
of hook nearest to the faces of a and the corresponding distance:
C.nearestFaces(hook, a)
Example of use: find nearest points to faces in hook (array),
find nearest points to faces in hook (pyTree).
C.nearestElements:
find nearest points stored in hook to element centers of a. Return the
indices of hook nearest to the elements of a and the corresponding distance:
C.nearestElements(hook, a)
Example of use: find nearest points to elements in hook (array),
find nearest points to elements in hook (pyTree).
Distributed trees
Converter can also manage distributed trees, that is trees where
zones are distributed over different processors.
Three new concepts are introduced in addition of
standard pyTrees: the skeleton tree, the loaded skeleton tree and
the partial tree.
A skeleton tree (S) is a full pyTree where float numpy arrays with
more than 100 elements are replaced by None.
A loaded skeleton tree (LS) is a skeleton tree with zones attributed
to the current processor fully loaded.
A partial tree (P) is a pyTree with only zones attributed
to the current processor fully loaded. It can be viewed as a "cleaned"
loaded skeleton tree.
Access to distributed tree functions is provided by:
import Converter.Mpi as Cmpi
Cmpi.convertFile2SkeletonTree:
return a skeleton tree from a file (only ADF or HDF). If float data array size is lower than maxFloatSize then the array is loaded. If maxDepth is
specified, load is limited to maxDepth levels:
A = Cmpi.convertFile2SkeletonTree('in.cgns', maxFloatSize=5, maxDepth=-1)
Example of use: return a skeleton tree from a file (pyTree).
Cmpi.readZones:
load zones of a skeleton tree referenced by proc number in a
.Solver#Param/proc node (only ADF or HDF):
B = Cmpi.readZones(A, 'in.cgns', proc=0)
Example of use: read zones to a skeleton tree (pyTree).
Cmpi.convertPyTree2File:
write a loaded skeleton tree or a partial tree to a file:
Cmpi.convertPyTree2File(A, 'in.cgns', proc=0)
Cmpi.convert2PartialTree:
convert a loaded skeleton tree to a partial tree
If rank=-1, get rid of skeleton zones. If rank>=0, get rid of
zones with a proc different of rank:
B = Cmpi.convert2PartialTree(A, rank=-1)
Example of use: convert a loaded skeleton tree to a partial tree (pyTree).
Cmpi.createBBoxTree:
from a partial tree or a loaded skeleton tree, create a full tree
containing bbox of zones (identical on all processors). Argument method can be
'AABB' (axis aligned bbox) or 'OBB' (oriented bbox):
B = Cmpi.createBBoxTree(A, method='AABB')
Example of use: create a bbox tree (pyTree).
Cmpi.getProc:
return the proc of a zone (can be a skeleton zone). If zone has not
been affected, return -1:
proc = Cmpi.getProc(z)
Example of use: get the proc of a zone (pyTree).
Cmpi.setProc:
set proc to a (can be skeleton):
b = Cmpi.setProc(a) .or. B = Cmpi.setProc(A)
Example of use: set the proc in a tree (pyTree).
Cmpi.getProcDict:
return the dictionary proc['zoneName'] from a skeleton, loaded skeleton or
partial tree:
procDict = Cmpi.getProcDict(A)
Example of use: get the proc dictionary (pyTree).
Cmpi.computeGraph:
compute a graph. The graph is a dictionary
such that graph[proc1][proc2] contains the names of zones
of proc1 that are "connected" to at least one zone on proc2.
If type='bbox', a zone is connected to another if their bbox intersects.
A must be a bbox tree.
If type='bbox2', a zone is connected to another if their bbox intersects
and are not in the same base. A must be a bbox tree.
If type='bbox3', a zone is connected to another of another tree
if their bbox intersects. A and t2 must be a bbox tree.
If type='match' (S/LS/P), a zone is connected to another if they have a
match between them. A can be a skeleton, loaded skeleton or a partial tree.
If type='ID' (S/LS/P), a zone is connected to another if they have
interpolation data between them. A can be a skeleton, a loaded skeleton
or a partial tree.
If type='IBCD' (S/LS/P), a zone is connected to another if they have
IBC data between them. A can be a skeleton, a loaded skeleton
or a partial tree.
If type='ALLD' (S/LS/P), a zone is connected to another if they have
Interpolation or IBC data between them. A can be a skeleton, a loaded
skeleton or a partial tree.
If type='proc', a zone is attributed to another proc than the one
it is loaded on. A can be a skeleton, a loaded skeleton tree or
a partial tree.
graph = Cmpi.computeGraph(A, type='bbox', t2=None)
Example of use: compute communication graph (pyTree).
Cmpi.addXZones:
add zones loaded on a different processor that are connected to local
zones through the graph:
B = Cmpi.addXZones(A, graph)
Example of use: add zones (pyTree).
Cmpi.rmXZones:
remove zones created by addXZones:
B = Cmpi.rmXZones(A)
Example of use: rm zones created by addXZones (pyTree).
Cmpi.center2Node:
center2Node for distributed trees:
B = Cmpi.center2Node(A, 'centers:Density')
Example of use: Pass a variable from centers to node (pyTree).
Client/server to exchange arrays/pyTrees
C.createSockets:
create sockets for receiving arrays/pyTrees. If you are sending
from a MPI run with nprocs, set nprocs accordingly:
sockets = C.createSockets(nprocs=1, port=15555)
C.listen:
listen from created sockets. A is whatever has been sent:
A = C.listen(sockets)
Example of use: listen for arrays.,
listen for pyTrees.
C.send:
send information to server:
C.send(a, 'localhost', rank=0, port=15555)
Example of use: send arrays.,
send pyTrees.
Converter arrays / 3D arrays conversion
In some applications, arrays must be seen as 3D arrays, that is (ni,nj,nk)
numpy arrays instead of (nfld, ni*nj*nk) arrays. A 3D array is defined as
[ ['x','y',...],[ ax, ay, ... ] ] where ax is a (ni,nj,nk) numpy array
corresponding to variable x, and so on...
C.Array3D.convertArrays2Arrays3D:
convert arrays to 3D arrays (ni,nj,nk):
B = C.Array3D.convertArrays2Arrays3D(A)
Example of use: create 3D arrays from classical arrays.
C.Array3D.convertArrays3D2Arrays:
convert 3D arrays to arrays:
B = C.Array3D.convertArrays3D2Arrays(A)
Example of use: create arrays from 3D arrays.
More general examples of use
Return to main userguide