# 4.2.6 pde.grids.cylindrical module

Cylindrical grids with azimuthal symmetry

class CylindricalSymGrid(radius, bounds_z, shape, periodic_z=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 &= R_\mathrm{inner} + \left(i + \frac12\right) \Delta r &&\quad \text{for} \quad i = 0, \ldots, N_r - 1 &&\quad \text{with} \quad \Delta r = \frac{R_\mathrm{outer} - R_\mathrm{inner}}{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_\mathrm{outer}$$ is the outer radius of the grid, $$R_\mathrm{inner}$$ corresponds to a possible inner radius (which is zero by default), and $$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.

Warning

The order of components in the vector and tensor fields defined on this grid are still $$(r, \phi, z)$$. To avoid any confusion it might thus be best to access components by name instead of index, e.g., use field['z'] instead of field[2].

Parameters:
• radius (float or tuple of floats) – radius $$R_\mathrm{outer}$$ in case a simple float is given. If a tuple is supplied it is interpreted as the inner and outer radius, $$(R_\mathrm{inner}, R_\mathrm{outer})$$.

• 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.

boundary_names: dict[str, tuple[int, bool]] = {'bottom': (1, False), 'inner': (0, False), 'outer': (0, True), 'top': (1, True)}

Names of boundaries to select them conveniently

Type:

dict

c: CoordinatesBase = CylindricalCoordinates()

Coordinates of the grid

Type:

CoordinatesBase

cell_volume_data: Sequence[FloatNumerical] | None

Information about the size of discretization cells

Type:

list

coordinate_constraints: list[int] = [0, 1]

axes that not described explicitly

Type:

list

difference_vector(p1, p2, *, coords='grid')[source]

return Cartesian vector(s) pointing from p1 to p2

In case of periodic boundary conditions, the shortest vector is returned.

Parameters:
Returns:

The difference vectors between the points with periodic boundary conditions applied.

Return type:

ndarray

classmethod from_bounds(bounds, shape, periodic)[source]
Parameters:
• bounds (tuple) – Give the coordinate range for each axis. This should be a tuple of two number (lower and upper bound) for each axis. The length of bounds must be 2.

• shape (tuple) – The number of support points for each axis. The length of shape needs to be 2.

• periodic (bool or list) – Specifies which axes possess periodic boundary conditions. The first entry is ignored.

Returns:

grid representing the region chosen by bounds

Return type:

CylindricalSymGrid

classmethod from_state(state)[source]

create a field from a stored state.

Parameters:

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

Return type:

CylindricalSymGrid

get_cartesian_grid(mode='valid')[source]

return a Cartesian grid for this Cylindrical one

Parameters:

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.

Returns:

The requested grid

Return type:

pde.grids.cartesian.CartesianGrid

get_image_data(data)[source]

return a 2d-image of the data

Parameters:

data (ndarray) – The values at the grid points

Returns:

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

Return type:

dict

get_line_data(data, extract='auto')[source]

return a line cut for the cylindrical grid

Parameters:
• 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)

Returns:

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

Return type:

dict

get_random_point(*, boundary_distance=0, avoid_center=False, coords='cartesian', rng=None)[source]

return a random point within the grid

Parameters:
• 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())

Returns:

The coordinates of the point

Return type:

ndarray

property has_hole: bool

whether the inner radius is larger than zero

Type:

bool

iter_mirror_points(point, with_self=False, only_periodic=True)[source]

generates all mirror points corresponding to point

Parameters:
• 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

Returns:

A generator yielding the coordinates that correspond to mirrors

Return type:

Generator

property length: float

length of the cylinder

Type:

float

property radius: float | tuple[float, float]

radius of the sphere

Type:

float

slice(indices)[source]

return a subgrid of only the specified axes

Parameters:

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

Returns:

CartesianGrid or PolarSymGrid: The subgrid

Return type:
property state: dict[str, Any]

all information required for reconstructing the grid

Type:

dict

property volume: float

total volume of the grid

Type:

float