Node inspection

To avoid redoing several times the most commun operations, maia.pytree provide several functions extracting usefull data from a specific kind of CGNSNode.

All these functions are CGNS/SIDS aware, meaning that they are garanteed to succeed only if the input tree is respecting the standard.

They are also read only; i.e. input tree will not be modified by any of these calls.

Overview

Here is a summary of the available functions, depending of the input node:

Tree These functions apply to CGNSTree_t node

find_connected_zones

Gather the zones of the tree into groups connected by 1to1 connectivities

find_periodic_jns

Gather the periodic joins of the tree according to their periodicity values

Zone These functions apply to Zone_t node

Type

Return the kind of a Zone_t node

IndexDimension

Return the IndexDimension of a Zone_t node

VertexSize

Return the number of vertices per direction of a Zone_t node

FaceSize

Return the number of faces per direction of a Zone_t node

CellSize

Return the number of cells per direction of a Zone_t node

VertexBoundarySize

Return the number of boundary vertices per direction of a Zone_t node

IFaceSize

Return the number of I normal faces in each direction for a structured Zone_t node

JFaceSize

Return the number of J normal faces in each direction for a structured Zone_t node

KFaceSize

Return the number of K normal faces in each direction for a structured Zone_t node

NGonNode

Return the Element_t node of kind NGON_n of a Zone_t node

NFaceNode

Return the Element_t node of kind NFACE_n of a Zone_t node

CellDimension

Return the CellDimension of a Zone_t node

n_cell

Return the total number of cells of a Zone_t node

n_face

Return the total number of faces of a Zone_t node

n_vtx

Return the total number of vertices of a Zone_t node

n_vtx_bnd

Return the total number of boundary vertices of a Zone_t node

has_ngon_elements

Return True if some Element_t node of kind NGON_n exists in the Zone_t node

has_nface_elements

Return True if some Element_t node of kind NFACE_n exists in the Zone_t node

coordinates

Return the coordinate arrays of the Zone_t node

get_ordered_elements

Return the Elements under a Zone_t node, sorted according to their ElementRange

get_ordered_elements_per_dim

Return the Elements under a Zone_t node, gathered according to their dimension

get_elt_range_per_dim

Return the min & max element number of each dimension found in a Zone_t node

elt_ordering_by_dim

Return a flag indicating if elements belonging to a Zone_t node are sorted

Element These functions apply to Element_t node

CGNSName

Return the generic name of an Element_t node

Dimension

Return the dimension of an Element_t node

NVtx

Return the number of vertices of an Element_t node

Range

Return the value of the ElementRange of an Element_t node

Size

Return the size (number of elements) of an Element_t node

Type

Return the type of an Element_t node

GridConnectivity These functions apply to GridConnectivity_t and GridConnectivity1to1_t nodes

Type

Return the type of a GridConnectivity node

Transform

Return the Transform specification of a GridConnectivity1to1 node.

is1to1

Return True if the GridConnectivity node is of type 'Abutting1to1'

isperiodic

Return True if the GridConnectivity node is periodic

ZoneDonorPath

Return the path of the opposite zone of a GridConnectivity node

periodic_values

Return the periodic transformation of a GridConnectivity node

Subset These functions apply to nodes having a PointList or a PointRange

getPatch

Return the PointList or PointRange node defining the Subset node

GridLocation

Return the GridLocation value of a Subset node

ZSRExtent

Return the path of the node to which the ZoneSubRegion node maps

n_elem

Return the number of mesh elements included in a Subset node

normal_axis

Return the normal direction of a structured subset.

Miscellaneous

GridLocation

Return the GridLocation value of a BCDataSet_t node.

Note

Functions are displayed below as static methods, gathered into classes. This is an implementation detail to put functions into namespaces : they should be used as usual, with their name prefixed by the label name:

>>> PT.Zone.Type(zone_node) # Apply on a Zone_t node
>>> PT.GridConnectivity.Type(gc_node) #Apply on a GC_t or GC1to1_t node

Methods detail

class Tree

The following functions apply to the top level CGNSTree_t

static find_connected_zones(tree)

Gather the zones of the tree into groups connected by 1to1 connectivities

Only non periodic joins are considered. Output paths start at tree level (Basename/Zonename).

Parameters

tree (CGNSTree) – Input CGNSTree_t node

Returns

List[List[str]] – grouped paths of zones

Example

>>> tree = PT.yaml.parse_yaml_cgns.to_cgns_tree('''
... Base CGNSBase_t:
...   Zone1 Zone_t:
...     ZoneGridConnectivity ZoneGridConnectivity_t:
...       match GridConnectivity1to1_t "Zone3":
...   Zone2 Zone_t:
...   Zone3 Zone_t:
...     ZoneGridConnectivity ZoneGridConnectivity_t:
...       match GridConnectivity1to1_t "Zone1":
... ''')
>>> PT.Tree.find_connected_zones(tree)
[['Base/Zone2'], ['Base/Zone1', 'Base/Zone3']]
static find_periodic_jns(tree, rtol=1e-05, atol=0.0)

Gather the periodic joins of the tree according to their periodicity values

Returned paths starts at tree level.

Parameters
  • tree (CGNSTree) – Input CGNSTree_t node

  • rtol (float, optional) – relative tolerance for periodicity comparaison

  • atol (float, optional) – absolute tolerance for periodicity comparaison

Returns

Pair of lists – at each indice,

  • first list contains the periodic arrays for the group of joins

  • second list contains the paths of joins related to this value

class Zone

The following functions apply to any Zone_t node

static CellDimension(zone_node)

Return the CellDimension of a Zone_t node

CellDimension is the dimensionality of the cell in the mesh, and should be equal to the first element of related CGNSBase_t value.

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int – CellDimension (1,2 or 3)

Raises

ValueError – if zone has no elements

Example

>>> zone = PT.new_Zone(type='Unstructured')
>>> PT.new_Elements('PYRA', 'PYRA_5', erange=[1,10],  parent=zone)
>>> PT.Zone.CellDimension(zone)
2
static CellSize(zone_node)

Return the number of cells per direction of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int or ndarray of int – number of cells in each direction for structured zones, total number of cells for unstructured zones

Example

>>> zone = PT.new_Zone(type='Unstructured', size=[[11,10,0]])
>>> PT.Zone.CellSize(zone)
10
static FaceSize(zone_node)

Return the number of faces per direction of a Zone_t node

Note that for structured meshes, this is the total number of faces having their normal aligned with I, J and K axis.

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int or array of int – number of faces in each direction for structured zones, total number of faces for unstructured zones

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0]])
>>> PT.Zone.FaceSize(zone)
array([55, 60], dtype=int32)

Warning

Unstructured zones are supported only if they have a NGon connectivity

static IFaceSize(zone_node)

Return the number of I normal faces in each direction for a structured Zone_t node

Parameters

zone_node (CGNSTree) – Input structured Zone_t node

Returns

int or array of int – number of faces in each direction

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0]])
>>> PT.Zone.IFaceSize(zone)
array([11,  5], dtype=int32)
static IndexDimension(zone_node)

Return the IndexDimension of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int – IndexDimension (1,2 or 3)

Example

>>> zone = PT.new_Zone(type='Unstructured', size=[[11,10,0]])
>>> PT.Zone.IndexDimension(zone)
1
static JFaceSize(zone_node)

Return the number of J normal faces in each direction for a structured Zone_t node

Parameters

zone_node (CGNSTree) – Input structured Zone_t node

Returns

int or array of int – number of faces in each direction

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0]])
>>> PT.Zone.JFaceSize(zone)
array([10,  6], dtype=int32)
static KFaceSize(zone_node)

Return the number of K normal faces in each direction for a structured Zone_t node

Parameters

zone_node (CGNSTree) – Input structured Zone_t node

Returns

int or array of int – number of faces in each direction

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0], [4,3,0]])
>>> PT.Zone.KFaceSize(zone)
array([10,  5,  4], dtype=int32)
static NFaceNode(zone_node)

Return the Element_t node of kind NFACE_n of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

CGNSTree – NFace node

Raises

RuntimeError – if not exactly one NFACE_n element node exists in zone

static NGonNode(zone_node)

Return the Element_t node of kind NGON_n of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

CGNSTree – NGon node

Raises

RuntimeError – if not exactly one NGON_n element node exists in zone

static Type(zone_node)

Return the kind of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

str – One of ‘Structured’, ‘Unstructured’, ‘UserDefined’ or ‘Null’

Example

>>> zone = PT.new_Zone(type='Unstructured')
>>> PT.Zone.Type(zone)
'Unstructured'
static VertexBoundarySize(zone_node)

Return the number of boundary vertices per direction of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int or ndarray of int – number of boundary vtx in each direction for structured zones, total number of boundary vtx for unstructured zones

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0],[6,5,0]])
>>> PT.Zone.VertexBoundarySize(zone)
array([0, 0], dtype=int32)
static VertexSize(zone_node)

Return the number of vertices per direction of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int or ndarray of int – number of vertices in each direction for structured zones, total number of vertices for unstructured zones

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0], [2,1,0]])
>>> PT.Zone.VertexSize(zone)
array([11, 6, 2], dtype=int32)
static coordinates(zone_node, name=None)

Return the coordinate arrays of the Zone_t node

Cartesian, cylindrical, spherical and auxiliary coordinates are supported.

Parameters
  • zone_node (CGNSTree) – Input Zone_t node

  • name (str, optional) – Name of the GridCoordinates node from which coordinates are taken. If not specified, first container found is used.

Returns

Triplet of ndarray or None – for each direction, corresponding coordinate array or None if physicalDimension is != 3, stored in a named tuple.

Example

>>> zone = PT.new_Zone(type='Unstructured')
>>> PT.new_GridCoordinates(fields={'CoordinateX' : [0., 0.5, 1.],
...                                'CoordinateY' : [.5, .5, .5]},
...                        parent=zone)
>>> PT.Zone.coordinates(zone)
CartesianCoordinates(CoordinateX=array([0. , 0.5, 1. ], dtype=float32),
                     CoordinateY=array([0.5, 0.5, 0.5], dtype=float32),
                     CoordinateZ=None)
static elt_ordering_by_dim(zone_node)

Return a flag indicating if elements belonging to a Zone_t node are sorted

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int – Flag indicating how elements are sorted:

  • 1 if elements of lower dimension have lower ElementRange

  • -1 if elements of lower dimension have higher ElementRange

  • 0 if elements are not sorted

If all the elements belonging to the zone have the same dimension, this function returns 1.

Example

>>> zone = PT.new_Zone(type='Unstructured')
>>> PT.new_Elements('TETRA', 'TETRA_4', erange=[1,10], parent=zone)
>>> PT.new_Elements('TRI', 'TRI_3', erange=[11,30], parent=zone)
>>> PT.Zone.elt_ordering_by_dim(zone)
-1
static get_elt_range_per_dim(zone_node)

Return the min & max element number of each dimension found in a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

list of 4 pairs – min and max element id for each dimension

Raises

RuntimeError – if elements of different dimension are interlaced

Example

>>> zone = PT.new_Zone(type='Unstructured')
>>> PT.new_Elements('PYRA', 'PYRA_5', erange=[1,10],  parent=zone)
>>> PT.new_Elements('TRI',  'TRI_3',  erange=[11,30], parent=zone)
>>> PT.new_Elements('BAR',  'BAR_2',  erange=[31,40], parent=zone)
>>> PT.Zone.get_elt_range_per_dim(zone)
[[0, 0], [31, 40], [11, 30], [1, 10]]
static get_ordered_elements(zone_node)

Return the Elements under a Zone_t node, sorted according to their ElementRange

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

list of CGNSTree – Elements_t nodes

Example

>>> zone = PT.new_Zone(type='Unstructured')
>>> PT.new_Elements('TETRA', 'TETRA_4', erange=[1,10], parent=zone)
>>> PT.new_Elements('TRI', 'TRI_3', erange=[11,30], parent=zone)
>>> [PT.get_name(node) for node in PT.Zone.get_ordered_elements(zone)]
['TETRA', 'TRI']
static get_ordered_elements_per_dim(zone_node)

Return the Elements under a Zone_t node, gathered according to their dimension

Within each dimension, Elements are sorted according to their ElementRange

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

list of 4 list of CGNSTree – Elements_t nodes

Example

>>> zone = PT.new_Zone(type='Unstructured')
>>> PT.new_Elements('PYRA', 'PYRA_5', erange=[1,10],  parent=zone)
>>> PT.new_Elements('TRI',  'TRI_3',  erange=[11,30], parent=zone)
>>> PT.new_Elements('QUAD', 'QUAD_4', erange=[31,40], parent=zone)
>>> [len(elts) for elts in PT.Zone.get_ordered_elements_per_dim(zone)]
[0, 0, 2, 1]
static has_nface_elements(zone_node)

Return True if some Element_t node of kind NFACE_n exists in the Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

bool

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0]])
>>> PT.Zone.has_nface_elements(zone)
False
static has_ngon_elements(zone_node)

Return True if some Element_t node of kind NGON_n exists in the Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

bool

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0]])
>>> PT.new_NGonElements(parent=zone)
>>> PT.Zone.has_ngon_elements(zone)
True
static n_cell(zone_node)

Return the total number of cells of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int – number of cells

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0]])
>>> PT.Zone.n_cell(zone)
50
static n_face(zone_node)

Return the total number of faces of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int – number of faces

Example

>>> zone = PT.new_Zone(type='Structured', size=[[11,10,0], [6,5,0]])
>>> PT.Zone.n_face(zone)
115

Warning

Unstructured zones are supported only if they have a NGon connectivity

static n_vtx(zone_node)

Return the total number of vertices of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int – number of vertices

Example

>>> zone = PT.new_Zone(type='Unstructured', size=[[11,10,0]])
>>> PT.Zone.n_vtx(zone)
11
static n_vtx_bnd(zone_node)

Return the total number of boundary vertices of a Zone_t node

Parameters

zone_node (CGNSTree) – Input Zone_t node

Returns

int – number of boundary vertices

Example

>>> zone = PT.new_Zone(type='Unstructured', size=[[11,10,0]])
>>> PT.Zone.n_vtx_bnd(zone)
0
class Element

The following functions apply to any Element_t node

static CGNSName(elt_node)

Return the generic name of an Element_t node

Parameters

elt_node (CGNSTree) – Input Element_t node

Returns

str – CGNS name corresponding to this element kind

Example

>>> elt = PT.new_NFaceElements('MyElements')
>>> PT.Element.CGNSName(elt)
'NFACE_n'
static Dimension(elt_node)

Return the dimension of an Element_t node

Parameters

elt_node (CGNSTree) – Input Element_t node

Returns

int – Dimension of this element kind (0, 1, 2 or 3)

Example

>>> elt = PT.new_Elements(type='TRI_3')
>>> PT.Element.Dimension(elt)
2
static NVtx(elt_node)

Return the number of vertices of an Element_t node

Parameters

elt_node (CGNSTree) – Input Element_t node

Returns

int – Number of vertices for this element kind

Example

>>> elt = PT.new_Elements(type='PYRA_5')
>>> PT.Element.NVtx(elt)
5
static Range(elt_node)

Return the value of the ElementRange of an Element_t node

Parameters

elt_node (CGNSTree) – Input Element_t node

Returns

ndarray – ElementRange of the node

Example

>>> elt = PT.new_Elements(type='PYRA_5', erange=[21,40])
>>> PT.Element.Range(elt)
array([21, 40], dtype=int32)
static Size(elt_node)

Return the size (number of elements) of an Element_t node

Parameters

elt_node (CGNSTree) – Input Element_t node

Returns

int – Number of elements described by the node

Example

>>> elt = PT.new_Elements(type='PYRA_5', erange=[21,40])
>>> PT.Element.Size(elt)
20
static Type(elt_node)

Return the type of an Element_t node

Parameters

elt_node (CGNSTree) – Input Element_t node

Returns

int – CGNS code corresponding to this element kind

Example

>>> elt = PT.new_Elements(type='TETRA_4')
>>> PT.Element.Type(elt)
10
class GridConnectivity
static Transform(gc_node, as_matrix=False)

Return the Transform specification of a GridConnectivity1to1 node.

Parameters
  • gc_node (CGNSTree) – Input GridConnectivity1to1 node

  • as_matrix (bool) – If True, return the transform matrix. Otherwise, return the transform vector.

Returns

ndarray – Transform specification

Example

>>> gc = PT.new_GridConnectivity1to1(transform=[-2,3,1])
>>> PT.GridConnectivity.Transform(gc, True)
array([[ 0,  0,  1],
       [-1,  0,  0],
       [ 0,  1,  0]])
static Type(gc_node)

Return the type of a GridConnectivity node

Parameters

gc_node (CGNSTree) – Input GridConnectivity node

Returns

str – One of ‘Null’, ‘UserDefined’, ‘Overset’, ‘Abutting’ or ‘Abutting1to1’

Example

>>> gc = PT.new_GridConnectivity1to1('GC')
>>> PT.GridConnectivity.Type(gc)
'Abutting1to1'
static ZoneDonorPath(gc_node, cur_base_name)

Return the path of the opposite zone of a GridConnectivity node

Parameters
  • gc_node (CGNSTree) – Input GridConnectivity node

  • cur_base_name (str) – Name of the parent base of this node

Returns

str – Path (Basename/Zonename) of the opposite zone

Example

>>> gc = PT.new_GridConnectivity('GC', donor_name='OtherBase/OppZone')
>>> PT.GridConnectivity.ZoneDonorPath(gc, 'Base')
'OtherBase/OppZone'
static is1to1(gc_node)

Return True if the GridConnectivity node is of type ‘Abutting1to1’

Parameters

gc_node (CGNSTree) – Input GridConnectivity node

Returns

bool

Example

>>> gc = PT.new_GridConnectivity('GC', type='Overset')
>>> PT.GridConnectivity.is1to1(gc)
False
static isperiodic(gc_node)

Return True if the GridConnectivity node is periodic

Parameters

gc_node (CGNSTree) – Input GridConnectivity node

Returns

bool

Example

>>> gc = PT.new_GridConnectivity('GC', type='Overset')
>>> PT.GridConnectivity.isperiodic(gc)
False
static periodic_values(gc_node)

Return the periodic transformation of a GridConnectivity node

Parameters

gc_node (CGNSTree) – Input GridConnectivity node

Returns

Triplet of ndarray or None – values of RotationCenter, RotationAngle and Translation, stored in a named tuple

Example

>>> gc = PT.new_GridConnectivity('GC')
>>> PT.new_GridConnectivityProperty({'translation' : [1., 0, 0]}, parent=gc)
>>> PT.GridConnectivity.periodic_values(gc)
PeriodicValues(RotationCenter=array([0., 0., 0.], dtype=float32),
               RotationAngle=array([0., 0., 0.], dtype=float32),
               Translation=array([1., 0., 0.], dtype=float32))
class Subset

A subset is a node having a PointList or a PointRange

static GridLocation(subset_node)

Return the GridLocation value of a Subset node

Parameters

subset_node (CGNSTree) – Input Subset node

Returns

str – One of ‘Null’, ‘UserDefined’, ‘Vertex’, ‘CellCenter’, ‘FaceCenter’, ‘IFaceCenter’, ‘JFaceCenter’, ‘KFaceCenter’, or ‘EdgeCenter’

Example

>>> bc = PT.new_BC('BC', loc='FaceCenter')
>>> PT.Subset.GridLocation(bc)
'FaceCenter'
static ZSRExtent(zsr_node, zone_node)

Return the path of the node to which the ZoneSubRegion node maps

Path start from zone_node and can point to a BC, a GC or the ZSR itself. This function only make sense for ZoneSubRegion_t nodes.

Parameters
  • zsr_node (CGNSTree) – Input ZoneSubRegion_t node

  • zone_node (CGNSTree) – Parent Zone_t node

Returns

str – path of zone defining the ZSR extent

Example

>>> zone = PT.new_Zone('Zone')
>>> bc   = PT.new_BC('RelevantBC', parent=PT.new_ZoneBC(parent=zone))
>>> zsr  = PT.new_ZoneSubRegion('ZSR', bc_name='RelevantBC')
>>> PT.Subset.ZSRExtent(zsr, zone)
'ZoneBC/RelevantBC'
static getPatch(subset_node)

Return the PointList or PointRange node defining the Subset node

Parameters

subset_node (CGNSTree) – Input Subset node

Returns

CGNSTree – PointList or PointRange node

Example

>>> bc = PT.new_BC('BC', loc='FaceCenter', point_list=[[1,2,3,4]])
>>> PT.Subset.getPatch(bc)
['PointList', array([[1, 2, 3, 4]], dtype=int32), [], 'IndexArray_t']
static n_elem(subset_node)

Return the number of mesh elements included in a Subset node

Parameters

subset_node (CGNSTree) – Input Subset node

Returns

int – Number of elements

Example

>>> gc = PT.new_GridConnectivity1to1('GC', point_range=[[10,1],[1,10]])
>>> PT.Subset.n_elem(gc)
100
>>> bc = PT.new_BC('BC', loc='FaceCenter', point_list=[[1,2,3,4]])
>>> PT.Subset.n_elem(bc)
4
static normal_axis(subset_node)

Return the normal direction of a structured subset.

This function is only relevant for subsets defining a 2d or 1d structured region (having a PointRange node).

Parameters

subset_node (CGNSTree) – Input Subset node

Returns

int – Normal axis of the subset (0,1 or 2)

Raises

ValueError – if normal axis can not be determined

Example

>>> bc = PT.new_BC(point_range=[[1,10], [5,5], [1,100]], loc='Vertex')
>>> PT.Subset.normal_axis(bc)
1
class BCDataSet
static GridLocation(bcds_node, bc_node)

Return the GridLocation value of a BCDataSet_t node.

This differs from Subset.GridLocation() in the management of default value: BCDataSet_t nodes inherit the value of their parent BC_t node, while other subset nodes have a default value of 'Vertex'.

Parameters
  • bcds_node (CGNSTree) – Input BCDataSet node

  • bc_node (CGNSTree) – Related BC node

Returns

str – One of ‘Null’, ‘UserDefined’, ‘Vertex’, ‘CellCenter’, ‘FaceCenter’, ‘IFaceCenter’, ‘JFaceCenter’, ‘KFaceCenter’, or ‘EdgeCenter’

Example

>>> bc = PT.new_BC('BC', loc='FaceCenter')
>>> bcds = PT.new_BCDataSet(parent=bc)
>>> PT.BCDataSet.GridLocation(bcds, bc)
'FaceCenter'