Mesh

Mesh

class flatiron_tk.mesh.mesh.Boundary(mesh, boundary_id, **kwargs)[source]

Bases: object

A simple class to represent and store properties of a mesh boundary. :param mesh: The mesh object containing the boundary. :type mesh: flatiron_tk.Mesh :param boundary_id: The identifier for the specific boundary. :type boundary_id: int :param **kwargs: Additional attributes to be set for the boundary. :type **kwargs: dict :param Default Attributes: :param ——————: :param id: The boundary identifier. :type id: int :param area: The area of the boundary. :type area: float :param radius: The equivalent radius of the boundary (assuming circular shape). :type radius: float :param centroid: The centroid coordinates of the boundary. :type centroid: np.ndarray :param normal: The mean outward normal vector of the boundary. :type normal: np.ndarray

set_new_attributes(**kwargs)[source]

Sets new attributes or updates existing ones for the Boundary instance. :param **kwargs: Key-value pairs representing the attributes to be set or updated. :type **kwargs: dict

class flatiron_tk.mesh.mesh.Mesh(**kwargs)[source]

Bases: object

A base class for creating and managing computational meshes using Dolfinx. :param comm: :type comm: MPI communicator, default is MPI.COMM_WORLD :param mesh: :type mesh: dolfinx mesh object, default is None :param mesh_file: :type mesh_file: mesh file name, default is None :param boundary: :type boundary: dolfinx mesh tags for boundary, default is None :param subdomain: :type subdomain: dolfinx mesh tags for subdomain, default is None :param gdim: :type gdim: geometric dimension of the mesh, optional, used when loading from file

get_boundary_area(boundary_id)[source]

Calculate the area of a given boundary. :param boundary_id (int): :type boundary_id (int): The id of the boundary for which to compute the area.

Returns:

float

Return type:

The area of the boundary.

get_boundary_centroid(boundary_id)[source]

Calculate the centroid of a given boundary. :param boundary_id (int): :type boundary_id (int): The id of the boundary for which to compute the centroid.

Returns:

np.ndarray

Return type:

A point representing the centroid of the boundary.

get_cell_diameter()[source]

Returns the ufl cell diameter of the mesh.

get_facet_normal()[source]

Returns the ufl facet normal of the mesh.

get_fdim()[source]

Returns the facet dimension of the mesh; the dimension of the mesh boundary.

get_gdim()[source]

Returns the geometric dimension of the mesh.

get_mean_boundary_normal(boundary_id)[source]

Calculate the mean normal vector of a given boundary. :param boundary_id (int): :type boundary_id (int): The id of the boundary for which to compute the mean normal.

Returns:

np.ndarray

Return type:

A unit vector representing the mean outward normal of the boundary.

get_mean_cell_diameter()[source]

Get mean cell diameter. :returns: float :rtype: the average length of the cell diameters within the mesh.

get_num_facets_local()[source]

Returns the number of facets in the local mesh partition.

get_tdim()[source]

Returns the topological dimension of the mesh.

mark_boundary(marking_dict)[source]

Mark the boundary of the mesh with user-defined markers. :param marking_dict: indicating which facets to mark. :type marking_dict: dict, A dictionary where keys are marker ids and values are functions that return boolean arrays

mark_subdomain(marking_dict)[source]

Mark the subdomains of the mesh with user-defined markers. :param marking_dict: indicating which cells to mark. :type marking_dict: dict, A dictionary where keys are marker ids and values are functions that return boolean arrays

Built-In Meshes

class flatiron_tk.mesh.basic_mesh.CuboidMesh(x0, y0, z0, x1, y1, z1, dx, comm=mpi4py.MPI.COMM_WORLD, **kwargs)[source]

Bases: Mesh

Create a 3D cuboid mesh between (x0, y0, z0) and (x1, y1, z1) with a given element size. :param x0: :type x0: Start point of the mesh in the x-direction. :param y0: :type y0: Start point of the mesh in the y-direction. :param z0: :type z0: Start point of the mesh in the z-direction. :param x1: :type x1: End point of the mesh in the x-direction. :param y1: :type y1: End point of the mesh in the y-direction. :param z1: :type z1: End point of the mesh in the z-direction. :param dx: :type dx: Element size in each direction (can be a single float or a list/tuple of three floats). :param comm: :type comm: MPI communicator, default is MPI.COMM_WORLD. :param **kwargs: :type **kwargs: Additional keyword arguments passed to dolfinx.mesh.create_box (e.g., cell_type).

class flatiron_tk.mesh.basic_mesh.LineMesh(x0, x1, dx, comm=mpi4py.MPI.COMM_WORLD, **kwargs)[source]

Bases: Mesh

Create a 1D line mesh between x0 and x1 with a given element size. :param x0: :type x0: Start point of the mesh. :param x1: :type x1: End point of the mesh. :param dx: :type dx: Element size. :param comm: :type comm: MPI communicator, default is MPI.COMM_WORLD. :param **kwargs: :type **kwargs: Additional keyword arguments passed to dolfinx.mesh.create_interval.

class flatiron_tk.mesh.basic_mesh.RectMesh(x0, y0, x1, y1, dx, comm=mpi4py.MPI.COMM_WORLD, **kwargs)[source]

Bases: Mesh

Create a 2D rectangular mesh between (x0, y0) and (x1, y1) with a given element size. :param x0: :type x0: Start point of the mesh in the x-direction. :param y0: :type y0: Start point of the mesh in the y-direction. :param x1: :type x1: End point of the mesh in the x-direction. :param y1: :type y1: End point of the mesh in the y-direction. :param dx: :type dx: Element size in each direction (can be a single float or a list/tuple of two floats). :param comm: :type comm: MPI communicator, default is MPI.COMM_WORLD. :param **kwargs: :type **kwargs: Additional keyword arguments passed to dolfinx.mesh.create_rectangle (e.g., cell_type).