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 inmeshio
- 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 . 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 cellsw (
Union
[ndarray
,Sequence
[float
]]) – The South-West point of the cellse (
Union
[ndarray
,Sequence
[float
]]) – The South-East point of the cellne (
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 . 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 facep1 (
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 facep1 (
Union
[ndarray
,Sequence
[float
]]) – The second point of the faceReturns – 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 cellsw (
Union
[ndarray
,Sequence
[float
]]) – The South-West point of the cellse (
Union
[ndarray
,Sequence
[float
]]) – The South-East point of the cellne (
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
- Type
np.ndarray
- volumes¶
An array containing the volumes of the cells. It has the dimensions of
- Type
np.ndarray
- normals¶
A
np.ndarray
that has the dimensions 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 where depends on the
Cell
type provided- Type
np.ndarray
- centroids: np.ndarray¶
- 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
- volumes¶
An array containing the volumes of the cells. It has the dimensions of
- normals¶
A
np.ndarray
that has the dimensions 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 where :math`N_text{points}` depends on the
Cell
type provided
- values¶
An array of dimensions storing the value of the
State
for each cell of theMesh
- min_length¶
The minimal 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
- create_neighbours()¶
- init_bcs(boundaries)¶
Inits the data structures used by the
BoundaryCondition
objects attached to eachBoundary
- Parameters
boundaries (Iterable[Boundary]) – The
Boundary
objects holding theBoundaryCondition
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 theBoundaryCondition
callablest (float) – The time instant to evaluate time dependent
BoundaryCondition
- 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 atuple
index to slice all the internal data structure and an additionalnormal_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
- 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 sliceMeshCellSet
- 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¶
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 (BoundaryCurve) – The left
BoundaryCurve
bottom (BoundaryCurve) – The bottom
BoundaryCurve
right (BoundaryCurve) – The right
BoundaryCurve
top (BoundaryCurve) – The right
BoundaryCurve
cell_type (Type[Cell]) – A
Cell
class that implements acreate_connectivity()
- 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 acreate_connectivity()
- dimensionality¶
The mesh dimensionality (i.e. 1 for 1D, 2 for 2D…)
- num_cells_x¶
The number of cells in the -direction
- num_cells_y¶
The number of cells in the -direction
- cells¶
A
MeshCellSet
storing cell data (centroids coordinates, normals to each face, face surface area, cell volume, field values)- Type
- points¶
An array containing the points that constitute a cell. It has the dimensions of where is the number of points specific to a cell (e.g. for a
SimpleCell
, that is 2D quadrangle, the points are 4) and is the dimensionality of the mesh, currently 2D ()- 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¶
- 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 -directionnum_cells_y (
int
) – Number of cells in -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 dependentBoundaryCondition
- 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 bymeshio
to decide wich output file to use