josie.mesh package

Submodules

josie.mesh.cell module

class josie.mesh.cell.Cell

Bases: object

This is a class interface representing a generic cell of a Mesh.

A cell is defined by the number of points (num_points) that are needed to properly define it and the number of degrees of freedom (num_dofs) actually availbe within it. It needs to provide also the methods to compute geometrical informations (e.g. its volume, normals, face area, etc…).

num_points

The number of points needed to describe the cell

Type

int

num_dofs

The number of degrees of freedom stored in the cell

Type

int

_meshio_cell_type

Which type of cell in meshio Cell is mapped to (e.g. a quadrangular cell is of type quad in meshio

Type

str

abstract classmethod centroid(nw, sw, se, ne)

Compute the centroid of the cell

Return type

Union[ndarray, Sequence[float]]

abstract classmethod create_connectivity(mesh)

This method creates the connectivity from the given points of a mesh. It modifies attributes of the Mesh instance.

By default it just calls Mesh.cells.compute_min_length(). When subclassing, create you connectivity first, than call :meth`super().create_connectivity`

It takes into account the nature of the cell composing the mesh, e.g. quadrangles.

Data Structure

The data structures holding the cell centroids and field values on the mesh are numpy.ndarray of dimensions N_x + 2 \times N_y
+ 2\times \ldots. That is, we have one layer of ghosts per direction. (The corner cells are unused)

Parameters

mesh (Mesh) – An instance of the Mesh of which we need to create the connectivity

abstract classmethod export_connectivity(mesh)

This method exports the connectivity of the mesh in the format accepted by the Mesh.

Return type

MeshIO

abstract classmethod face_normal(p0, p1)

Compute the normal vector to a face.

Return type

ndarray

abstract classmethod face_surface(p0, p1)

Compute the surface of a face from its points.

Return type

float

abstract property num_dofs
abstract property num_points
abstract classmethod volume(nw, sw, se, ne)

Compute the volume of a cell from its points.

Return type

float

class josie.mesh.cell.SimpleCell

Bases: josie.mesh.cell.Cell

This class describes the classical type of 2D quadrangular cell that stores the State value in its centroid. The cell needs 4 points to be defined and has 1 degree of freedom.

nw     ne
*-------*
|       |
|   *   |
|   c   |
*-------*
sw     se
classmethod centroid(nw, sw, se, ne)

This class method computes the centroid of a cell from its points.

The centroid is computed as the mean value of the for points

Parameters
  • nw (Union[ndarray, Sequence[float]]) – The North-West point of the cell

  • sw (Union[ndarray, Sequence[float]]) – The South-West point of the cell

  • se (Union[ndarray, Sequence[float]]) – The South-East point of the cell

  • ne (Union[ndarray, Sequence[float]]) – The North-East point of the cell

Returns

The centroid coordinates

Return type

centroid

classmethod create_connectivity(mesh)

This method creates the connectivity from the given points of a mesh. It modifies attributes of the Mesh instance.

By default it just calls Mesh.cells.compute_min_length(). When subclassing, create you connectivity first, than call :meth`super().create_connectivity`

It takes into account the nature of the cell composing the mesh, e.g. quadrangles.

Data Structure

The data structures holding the cell centroids and field values on the mesh are numpy.ndarray of dimensions N_x + 2 \times N_y
+ 2\times \ldots. That is, we have one layer of ghosts per direction. (The corner cells are unused)

Parameters

mesh (Mesh) – An instance of the Mesh of which we need to create the connectivity

classmethod export_connectivity(mesh)

This method exports the connectivity of the mesh in the format accepted by the Mesh.

Return type

MeshIO

classmethod face_normal(p0, p1)

This class method computes the normal to a face from its points.

The normal is computed as the ortogonal vector to the vector made by the two given points obtained doing a CW rotation of 90 degrees

Parameters
  • p0 (Union[ndarray, Sequence[float]]) – The first point of the face

  • p1 (Union[ndarray, Sequence[float]]) – The second point of the face

Returns

The normal vector to the face

Return type

normal

classmethod face_surface(p0, p1)

This class method computes the surface of a face from its points.

The surface is simply the norm of the vector that is made by the two given points of the face (being in 2D).

Parameters
  • p0 (Union[ndarray, Sequence[float]]) – The first point of the face

  • p1 (Union[ndarray, Sequence[float]]) – The second point of the face

  • Returns – surface: The “surface” (i.e. the length) of the face

Return type

float

num_dofs = 1
num_points = 4
classmethod volume(nw, sw, se, ne)

This class method computes the volume of a cell from its points.

The surface is computed calculating the surface of the two triangles made by the two triplets of its points and summing them up.

Parameters
  • nw (Union[ndarray, Sequence[float]]) – The North-West point of the cell

  • sw (Union[ndarray, Sequence[float]]) – The South-West point of the cell

  • se (Union[ndarray, Sequence[float]]) – The South-East point of the cell

  • ne (Union[ndarray, Sequence[float]]) – The North-East point of the cell

Returns

volume

Return type

The volume of the cell

josie.mesh.cellset module

class josie.mesh.cellset.CellSet(volumes, surfaces, normals, centroids, values, dimensionality, min_length=nan)

Bases: object

A dataclass representing a set of cells. It ships the values of the fields in the cells, together with the cell centroids and cell volumes, the normals to each face, the surface area of each face, and the field values

centroids

An array containing the centroid of the cells. It has the dimensions of N_x \times N_y

Type

np.ndarray

volumes

An array containing the volumes of the cells. It has the dimensions of N_x \times N_y

Type

np.ndarray

normals

A np.ndarray that has the dimensions Nx \times Ny
\times N_\text{centroids} \times N_\text{dim} containing the values of the normals to the faces of the cells

Type

np.ndarray

surfaces

An array containing the surfaces of the cells. It has the dimensions of N_x \times N_y \times N_\text{points} where N_\text{points} depends on the Cell type provided

Type

np.ndarray

values

An array of dimensions N_x \times N_y \times N_\text{fields} storing the value of the State for each cell of the Mesh

Type

State

dimensionality

The Dimensionality of the CellSet

Type

Dimensionality

min_length

The minimal length of the CellSet

Type

float

centroids: np.ndarray
compute_min_length()

This method computes the min dx of the CellSet.

Useful for CFL computations

copy()

Implement a fast copy to avoid using copy.deepcopy

Return type

CellSet

dimensionality: Dimensionality
min_length: float = nan
normals: np.ndarray
surfaces: np.ndarray
values: State
volumes: np.ndarray
class josie.mesh.cellset.MeshCellSet(centroids, volumes, surfaces, normals, dimensionality)

Bases: josie.mesh.cellset.CellSet

A class representing the cells in a Mesh object, i.e. a structured mesh. It stores internally the mesh cells data (centroids, values, etc…) including values for the ghost cells. The non-ghost values are then exposed as views on the internal array

centroids

An array containing the centroid of the cells. It has the dimensions of N_x \times N_y

volumes

An array containing the volumes of the cells. It has the dimensions of N_x \times N_y

normals

A np.ndarray that has the dimensions Nx \times Ny
\times N_\text{centroids} \times N_\text{dim} containing the values of the normals to the faces of the cells

surfaces

An array containing the surfaces of the cells. It has the dimensions of N_x \times N_y \times N_\text{points} where :math`N_text{points}` depends on the Cell type provided

values

An array of dimensions N_x \times N_y \times N_\text{fields} storing the value of the State for each cell of the Mesh

min_length

The minimal \dd{x} of the mesh.

Useful for CFL computations

dimensionality

The Mesh dimensionality

neighbours

A list of NeighboursCellSet representing the neighbours in a direction of all the cells

Type

List[NeighboursCellSet]

property centroids: numpy.ndarray
Return type

ndarray

copy()

Implement a fast copy to avoid using copy.deepcopy

Return type

MeshCellSet

create_neighbours()
init_bcs(boundaries)

Inits the data structures used by the BoundaryCondition objects attached to each Boundary

Parameters

boundaries (Iterable[Boundary]) – The Boundary objects holding the BoundaryCondition callables

neighbours: List[NeighboursCellSet]
property normals: numpy.ndarray
Return type

ndarray

property surfaces: numpy.ndarray
Return type

ndarray

update_ghosts(boundaries, t)

This method updates the ghost cells of the mesh with the current values depending on the specified boundary condition

Parameters
  • boundaries (Iterable[Boundary]) – The Boundary objects holding the BoundaryCondition callables

  • t (float) – The time instant to evaluate time dependent BoundaryCondition

property values: State
Return type

State

property volumes: numpy.ndarray
Return type

ndarray

class josie.mesh.cellset.MeshCellSetIndex(data_index, normal_direction)

Bases: object

A composite index used to slice the internal data structures of MeshCellSet. It features a tuple index to slice all the internal data structure and an additional normal_direction to choose the right normal direction

data_index

The index to slice data structures containing also ghost cells data

Type

Union[Tuple[Union[int, slice, numpy.ndarray], …], numpy.ndarray]

normal_direction

The NormalDirection to index the face-related data structures

Type

josie.mesh.cellset.NormalDirection

data_index: Union[Tuple[Union[int, slice, numpy.ndarray], ...], numpy.ndarray]
normal_direction: josie.mesh.cellset.NormalDirection
class josie.mesh.cellset.NeighbourDirection(value)

Bases: enum.Enum

An Enum incapsulating the indexes for each neighbour direction to be used to slice MeshCellSet

BOTTOM = MeshCellSetIndex(data_index=(slice(1, -1, None), slice(None, -2, None)), normal_direction=<NormalDirection.BOTTOM: 1>)
LEFT = MeshCellSetIndex(data_index=(slice(None, -2, None), slice(1, -1, None)), normal_direction=<NormalDirection.LEFT: 0>)
RIGHT = MeshCellSetIndex(data_index=(slice(2, None, None), slice(1, -1, None)), normal_direction=<NormalDirection.RIGHT: 2>)
TOP = MeshCellSetIndex(data_index=(slice(1, -1, None), slice(2, None, None)), normal_direction=<NormalDirection.TOP: 3>)
class josie.mesh.cellset.NeighboursCellSet(volumes, surfaces, normals, centroids, values, direction, dimensionality)

Bases: josie.mesh.cellset.CellSet

A CellSet that stores also the neighbours direction

centroids: np.ndarray
dimensionality: Dimensionality
normals: np.ndarray
surfaces: np.ndarray
values: State
volumes: np.ndarray
class josie.mesh.cellset.NormalDirection(value)

Bases: enum.IntEnum

An enumeration.

BOTTOM = 1
LEFT = 0
RIGHT = 2
TOP = 3

josie.mesh.mesh module

This module contains the primitives related to the mesh generation

class josie.mesh.mesh.Mesh(left, bottom, right, top, cell_type, Backend=<class 'josie.plot.matplotlib.MatplotlibBackend'>)

Bases: object

This class handles the mesh generation over a domain.

Parameters
left

The left Boundary

bottom

The bottom Boundary

right

The right Boundary

top

The right Boundary

boundaries

An iterable over the boundaries available based on the dimensionality

Type

Iterable[Boundary]

cell_type

A Cell class that implements a create_connectivity()

dimensionality

The mesh dimensionality (i.e. 1 for 1D, 2 for 2D…)

num_cells_x

The number of cells in the x-direction

num_cells_y

The number of cells in the y-direction

cells

A MeshCellSet storing cell data (centroids coordinates, normals to each face, face surface area, cell volume, field values)

Type

MeshCellSet

points

An array containing the points that constitute a cell. It has the dimensions of N_x \times N_y \times N_\text{points} \times
N_\text{dimensions} where N_\text{points} is the number of points specific to a cell (e.g. for a SimpleCell, that is 2D quadrangle, the points are 4) and N_\text{dimensions} is the dimensionality of the mesh, currently 2D (N_\text{dimensions} = 2)

Type

np.ndarray

backend

An instance of PlotBackend used to plot mesh and its values

Note

The centroids coordinates are stored internally in _centroids, an augmented array that also stores the centroids of the ghost cells

boundaries: Iterable[Boundary]
cells: MeshCellSet
copy()

This methods copies the Mesh object into another

create_neighbours()

This is a proxy method to create_neighbours() that creates the internal connectivity for cell neighbours

export()

Export the mesh to a meshio.Mesh object

Return type

Mesh

generate()

Build the geometrical information and the connectivity associated to the mesh using the specific cell type create_connectivity()

init_bcs()

Initializes BoundaryCondition

interpolate(num_cells_x, num_cells_y)

This methods generates the mesh within the four given BoundaryCurve using Transfinite Interpolation

Parameters
  • num_cells_x (int) – Number of cells in x-direction

  • num_cells_y (int) – Number of cells in y-direction

Return type

Tuple[ndarray, ndarray]

min_length: float
plot()

This method shows the mesh in a GUI

points: np.ndarray
update_ghosts(t)

This method updates the ghost cells of the mesh with the current values depending on the specified boundary condition

Parameters

t (float) – The time instant to evaluate time dependent BoundaryCondition

write(filepath)

Save the cell into a file using meshio

Parameters

filepath (PathLike) – The path to the file. The extension of the file is used by meshio to decide wich output file to use

Module contents