4.2.5. pde.grids.cylindrical module

Cylindrical grids with azimuthal symmetry

class CylindricalSymGrid(radius: float, bounds_z: Tuple[float, float], shape: Tuple[int, int], periodic_z: bool = False)[source]

Bases: GridBase

3-dimensional cylindrical grid assuming polar symmetry

The polar symmetry implies that states only depend on the radial and axial coordinates \(r\) and \(z\), respectively. These are discretized uniformly as

\begin{align*} r_i &= \left(i + \frac12\right) \Delta r &&\quad \text{for} \quad i = 0, \ldots, N_r - 1 &&\quad \text{with} \quad \Delta r = \frac{R}{N_r} \\ z_j &= z_\mathrm{min} + \left(j + \frac12\right) \Delta z &&\quad \text{for} \quad j = 0, \ldots, N_z - 1 &&\quad \text{with} \quad \Delta z = \frac{z_\mathrm{max} - z_\mathrm{min}}{N_z} \end{align*}

where \(R\) is the radius of the cylindrical grid, \(z_\mathrm{min}\) and \(z_\mathrm{max}\) denote the respective lower and upper bounds of the axial direction, so that \(z_\mathrm{max} - z_\mathrm{min}\) is the total height. The two axes are discretized by \(N_r\) and \(N_z\) support points, respectively.


The order of components in the vector and tensor fields defined on this grid is different than in ordinary math. While it is common to use \((r, \phi, z)\), we here use the order \((r, z, \phi)\). It might thus be best to access components by name instead of index, e.g., use field['z'] instead of field[1].

  • radius (float) – The radius of the cylinder

  • bounds_z (tuple) – The lower and upper bound of the z-axis

  • shape (tuple) – The number of support points in r and z direction, respectively. The same number is used for both if a single value is given.

  • periodic_z (bool) – Determines whether the z-axis has periodic boundary conditions.

axes: List[str] = ['r', 'z']
axes_symmetric: List[str] = ['phi']

The names of the additional axes that the fields do not depend on, e.g. along which they are constant.



cell_volume_data: Sequence[FloatNumerical]

the volumes of all cells



coordinate_constraints: List[int] = [0, 1]
dim: int = 3
classmethod from_state(state: Dict[str, Any]) CylindricalSymGrid[source]

create a field from a stored state.


state (dict) – The state from which the grid is reconstructed.

get_boundary_conditions(bc: BoundariesData = 'auto_periodic_neumann', rank: int = 0) Boundaries[source]

constructs boundary conditions from a flexible data format

  • bc (str or list or tuple or dict) – The boundary conditions applied to the field. Boundary conditions are generally given as a list with one condition for each axis. For periodic axis, only periodic boundary conditions are allowed (indicated by ‘periodic’ and ‘anti-periodic’). For non-periodic axes, different boundary conditions can be specified for the lower and upper end (using a tuple of two conditions). For instance, Dirichlet conditions enforcing a value NUM (specified by {‘value’: NUM}) and Neumann conditions enforcing the value DERIV for the derivative in the normal direction (specified by {‘derivative’: DERIV}) are supported. Note that the special value ‘natural’ imposes periodic boundary conditions for periodic axis and a vanishing derivative otherwise. More information can be found in the boundaries documentation.

  • rank (int) – The tensorial rank of the value associated with the boundary conditions.

  • ValueError – If the data given in bc cannot be read

  • PeriodicityError – If the boundaries are not compatible with the periodic axes of the grid.

get_cartesian_grid(mode: str = 'valid') CartesianGrid[source]

return a Cartesian grid for this Cylindrical one


mode (str) – Determines how the grid is determined. Setting it to ‘valid’ only returns points that are fully resolved in the cylindrical grid, e.g., the cylinder is circumscribed. Conversely, ‘full’ returns all data, so the cylinder is inscribed.


The requested grid

Return type


get_image_data(data: ndarray) Dict[str, Any][source]

return a 2d-image of the data


data (ndarray) – The values at the grid points


A dictionary with information about the image, which is convenient for plotting.

get_line_data(data: ndarray, extract: str = 'auto') Dict[str, Any][source]

return a line cut for the cylindrical grid

  • data (ndarray) – The values at the grid points

  • extract (str) –

    Determines which cut is done through the grid. Possible choices are (default is cut_axial):

    • cut_z or cut_axial: values along the axial coordinate for \(r=0\).

    • project_z or project_axial: average values for each axial position (radial average).

    • project_r or project_radial: average values for each radial position (axial average)


A dictionary with information about the line cut, which is convenient for plotting.

get_random_point(*, boundary_distance: float = 0, avoid_center: bool = False, coords: str = 'cartesian', rng: Optional[Generator] = None, cartesian: Optional[bool] = None) ndarray[source]

return a random point within the grid

Note that these points will be uniformly distributed on the radial axis, which implies that they are not uniformly distributed in the volume.

  • boundary_distance (float) – The minimal distance this point needs to have from all boundaries.

  • avoid_center (bool) – Determines whether the boundary distance should also be kept from the center, i.e., whether points close to the center are returned.

  • coords (str) – Determines the coordinate system in which the point is specified. Valid values are cartesian, cell, and grid; see transform().

  • rng (Generator) – Random number generator (default: default_rng())


The coordinates of the point

Return type


get_subgrid(indices: Sequence[int]) Union[CartesianGrid, PolarSymGrid][source]

return a subgrid of only the specified axes


indices (list) – Indices indicating the axes that are retained in the subgrid


CartesianGrid or PolarSymGrid: The subgrid

iter_mirror_points(point: ndarray, with_self: bool = False, only_periodic: bool = True) Generator[source]

generates all mirror points corresponding to point

  • point (ndarray) – the point within the grid

  • with_self (bool) – whether to include the point itself

  • only_periodic (bool) – whether to only mirror along periodic axes


A generator yielding the coordinates that correspond to mirrors

property length: float

length of the cylinder



num_axes: int = 2
periodic: List[bool]
point_from_cartesian(points: ndarray) ndarray[source]

convert points given in Cartesian coordinates to this grid

This function returns points restricted to the x-z plane, i.e., the y-coordinate will be zero.


points (ndarray) – Points given in Cartesian coordinates.


Points given in the coordinates of the grid

Return type


point_to_cartesian(points: ndarray, *, full: bool = False) ndarray[source]

convert coordinates of a point to Cartesian coordinates

  • points (ndarray) – The grid coordinates of the points

  • full (bool) – Flag indicating whether angular coordinates are specified


The Cartesian coordinates of the point

Return type


polar_coordinates_real(origin: ndarray, *, ret_angle: bool = False) Union[ndarray, Tuple[ndarray, ndarray]][source]

return spherical coordinates associated with the grid

  • origin (ndarray) – Coordinates of the origin at which the polar coordinate system is anchored. Note that this must be of the form [0, 0, z_val], where only z_val can be chosen freely.

  • ret_angle (bool) – Determines whether the azimuthal angle is returned alongside the distance. If False only the distance to the origin is returned for each support point of the grid. If True, the distance and angles are returned.

property radius: float

radius of the cylinder



property state: Dict[str, Any]

the state of the grid



property volume: float

total volume of the grid