3.1.5.2. c3po.multi1D.Grid module

Inheritance diagram of c3po.multi1D.Grid

Contain the classes Grid, MEDGrid, CartesianGrid, HexagonalGrid and MultiLevelGrid.

class c3po.multi1D.Grid.CartesianGrid(xSizes, ySizes)

Bases: MEDGrid

CartesianGrid allows to define and handle a cartesian 2D mesh.

Cells are numbered along the x axis first, then along the y axis ( loop(yDim){ loop(xDim) {i++}} ). The mesh is centered on (0., 0.).

__init__(xSizes, ySizes)

Build a cartesian grid (centered on (0., 0.)) from the sizes of the cells.

Parameters:
  • xSizes (list) – List with the sizes of the cells in the x direction.

  • ySizes (list) – List with the sizes of the cells in the y direction.

clone()

see Grid.clone()

setCorrespondenceCartesian(xIndex, yIndex, correspondence)

Set one correspondence from the indexes of the cell in the cartesian grid.

Note

Use c3po.multi1D.NO_CORRESPONDENCE as correspondence value in empty positions.

Parameters:
  • xIndex – Index of the cell along the x axis.

  • yIndex – Index of the cell along the y axis.

  • correspondence – Value to associate with the cell.

class c3po.multi1D.Grid.Grid

Bases: ABC

Grid is an abstract class defining a 2D mesh to be used by MEDInterface.

Each cell is associated with an integer (correspondence) that will be used to identify a 1D object.

abstractmethod clone()

Return a clone of self.

Returns:

A clone of self.

Return type:

Grid

abstractmethod getCorrespondence(cellId)

Return the correspondence associated with the required cell.

Parameters:

cellId – Index of the cell in the mesh.

Return type:

Correspondence associated with the cell.

abstractmethod getMEDMesh()

Return a MEDCoupling mesh image of the grid (but without correspondences).

Note

It should be the same result than toMED().getMesh().

Return type:

A MEDCoupling 2D mesh.

abstractmethod getNodeCoordinates(cellId)

Return the coordinate of the nodes of one cell.

Parameters:

cellId – Index of the cell in the mesh.

Returns:

A list with the 2D coordinates of the nodes of the cell.

Return type:

list

abstractmethod getNumberOfCells()

Return the number of cells in the grid.

Return type:

The number of cells in the grid.

abstractmethod setCorrespondence(cellId, correspondence)

Set one correspondence in one cell.

Note

Use c3po.multi1D.NO_CORRESPONDENCE as correspondence value in empty positions.

Parameters:
  • cellId – Index of the cell in the mesh.

  • correspondence – Value to set in the cell.

abstractmethod setCorrespondences(correspondences)

Set the whole table of correspondences.

Note

Use c3po.multi1D.NO_CORRESPONDENCE as correspondence value in empty positions.

Parameters:

correspondences – Table of correspondence to be copied. correspondences[i] will be associated with the cell i.

abstractmethod shift(xShift, yShift)

Shift (geometric translation) the grid.

Parameters:
  • xShift – Shift to be applied on x coordinate.

  • yShift – Shift to be applied on y coordinate.

toMED()

Return a MEDCoupling field image of self.

Return type:

A MEDCoupling field image of self.

class c3po.multi1D.Grid.HexagonalGrid(numRings, pitch)

Bases: MEDGrid

HexagonalGrid allows to define and handle an hexagonal 2D mesh.

Cells are numbered in a “snail” way, from inside to outside. The central cell is numbered 0. The first cell of each ring makes an angle of -pi/6 with x axis. The mesh is centered on (0., 0.).

__init__(numRings, pitch)

Build a hexagonal grid (centered on (0., 0.)).

Parameters:
  • numRings – Number of rings (use 0 for only one cell, 1 to get 7 etc.)

  • pitch – flat-to-flat distance.

clone()

see Grid.clone()

setCorrespondenceHexagonal(ringIndex, positionIndex, correspondence)

Set one correspondence from the indexes of the cell in the hexagonal grid.

Note

Use c3po.multi1D.NO_CORRESPONDENCE as correspondence value in empty positions.

Parameters:
  • ringIndex – Index of the ring.

  • positionIndex – Index of the cell on the ring.

  • correspondence – Value to associate with the cell.

class c3po.multi1D.Grid.MEDGrid(field)

Bases: Grid

MEDGrid allows to handle a 2D grid defined with a MEDCoupling mesh or field.

__init__(field)

Build a MEDgrid from the provided MEDCoupling field. This field could have been written by Grid.toMED().

Parameters:

field – MEDCoupling field (should be a MEDCouplingFieldInt). It may have one component providing the correspondences (see Grid).

clone()

See Grid.clone().

getCorrespondence(cellId)

See Grid.getCorrespondence().

getMEDMesh()

Return a MEDCoupling mesh image of the grid (but without correspondences).

Note

It should be the same result than toMED().getMesh().

Return type:

A MEDCoupling 2D mesh.

getNodeCoordinates(cellId)

See Grid.getNodeCoordinates().

getNumberOfCells()

See Grid.getNumberOfCells().

setCorrespondence(cellId, correspondence)

See Grid.setCorrespondence().

setCorrespondences(correspondences)

See Grid.setCorrespondences().

shift(xShift, yShift)

See Grid.translate().

class c3po.multi1D.Grid.MultiLevelGrid(rootGrid, leafGrids)

Bases: Grid

MultiLevelGrid allows to define and handle grids inside other grids.

__init__(rootGrid, leafGrids)

Build a multi-level grid.

Note

We store and use clones of the provided leaf grids.

Parameters:
  • rootGrid – Root level Grid. Cannot be a MultiLevelGrid.

  • leafGrids (list) – List of second level grids. There must be as many leaf grids than cells in the rootGrid. Leaf grids can be MultiLevelGrid: in this case, all of them should be MultiLevelGrid, and those that are non-empty should all have the same number of levels.

clone()

see Grid.clone()

getCorrespondence(cellId)

See Grid.getCorrespondence()

getCurrentLevel()

Return the current level (see setCurrentLevel()).

Return type:

The current level.

getMEDMesh()

Return a MEDCoupling mesh image of the grid (but without correspondences).

Note

It should be the same result than toMED().getMesh().

Return type:

A MEDCoupling 2D mesh.

getNodeCoordinates(cellId)

See Grid.getNodeCoordinates()

getNumLevels()

Return the number of level.

Note

level = 0 if empty (rootGrid with no cells), 1 if leaf grids are not themselves MultiLevelGrid, and n + 1 with n the level of leaf grids otherwise.

Return type:

Number of level.

getNumberOfCells()

See Grid.getNumberOfCells()

setCorrespondence(cellId, correspondence)

See Grid.setCorrespondence()

setCorrespondences(correspondences)

See Grid.setCorrespondences()

setCurrentLevel(level)

Set the current level.

Note

All methods inherited from Grid will address this level. At level 0, the MultiLevelGrid behaves like the rootGrid. At level n > 0, it behaves like the juxtaposition of leaf grids with current level n - 1. Defaut : the value returned be getNumLevels().

Parameters:

level – Level New current level.

shift(xShift, yShift)

See Grid.shift()