edg_acoustics.mesh

This module, based on the GMSH software and meshio package, provide functions and classes to create mesh and to process and access mesh data generated by different mesh generators (e.g., DOLFIN XML (.xml), Netgen (.vol, .vol.gz).

Note that objects enclosed by square brackets (e.g., [dimension1, dimension2]) denotes a matrix of dimension [dimension1, dimension2].

Module Contents

Classes

Mesh

Mesh data structure generated from common mesh file formats or geometry files of GMSH.

Attributes

Nx_default

Default value of the local polynomial basis.

edg_acoustics.mesh.Nx_default = 4[source]

Default value of the local polynomial basis.

Type:

int

class edg_acoustics.mesh.Mesh(filename, BC_labels, Nx=Nx_default, **kwargs)[source]

Mesh data structure generated from common mesh file formats or geometry files of GMSH.

If the mesh file is in .msh format, the mesh data is read and stored in the object. If the mesh file is in .geo format, the mesh is generated iteratively with a characteristic length determined by the bisection method such that the PPW is between 8 and 10.

Data structure containing mesh definition. Mesh data is obtained from data stored in common mesh file format by Gmsh format (versions 2.2, 4.0, and 4.1 .msh). Since mesh reading relies on meshio, other mesh generators can be made available in the future (e.g., DOLFIN XML (.xml), Netgen (.vol, .vol.gz).

Mesh defines the domain discretisation and is used to define the finite element approximation of the solution to the acoustic wave propagation.

Parameters:
  • filename (str) – see filename.

  • BC_labels (dict[str, int]) – see BC_labels.

  • Nx (int) – Local polynomial basis order. Default is Nx_default.

  • freq_max (float) – optional keyword only parameters, maximum resolvable frequency of the simulation.

Raises:

ValueError – If BC_labels[‘my_label’] is not present in the mesh, an error is raised. If a label is present in the mesh but not in BC_labels, an error is raised.

BC_labels

a dictionary containing the human readable label of each boundary condition and the associated lable number used in the mesh generator. BC_labels[‘my_label’] returns the label number of the label named ‘my_label’. If BC_labels[‘my_label’] is not present in the mesh, an error is raised. If a label is present in the mesh but not in BC_labels, an error is raised.

Type:

dict[str, int]

BC_triangles

a dictionary containing the list of triangles that have a certain boundary condition. self.BC_triangles[‘BC_label’] is a numpy.ndarray with the nodes of each triangle where boundary condition of type ‘BC_label’ is to be implemented. The nodes defining each triangle in the numpy.ndarray are stored per row.

Type:

dict[str, numpy.ndarray]

EToE

an [4, N_tets] array containing the information of which elements are neighbors of an element, i.e., EToE[j, i] returns the index of the jth neighbor of element i. The definition of j-th neighbor follows the mesh generator’s convention.

Type:

numpy.ndarray

EToF

an [4 x N_tets] array containing the information of which face is shared between the element and its neighbor, i.e., EToF[j, i] returns the face index of the j-th neighbor of element i. Face indices follow the same convention as neighbor indices.

Type:

numpy.ndarray

EToV

An [4 x self.N_tets] array containing the 4 indices of the vertices of the N_tets tetrahedra that make up the mesh.

Type:

numpy.ndarray

filename

the file (pathlike) to read geometry or mesh data from. Current supported format includes Gmsh (format versions 2.2, 4.0, and 4.1, .msh) or .geo files.

Since mesh reading relies on meshio, the following formats can be made available in the future: Abaqus (.inp), ANSYS msh (.msh), AVS-UCD (.avs), CGNS (.cgns), DOLFIN XML (.xml), Exodus (.e, .exo), FLAC3D (.f3grid), H5M (.h5m), Kratos/MDPA (.mdpa), Medit (.mesh, .meshb), MED/Salome (.med), Nastran (bulk data, .bdf, .fem, .nas), Netgen (.vol, .vol.gz), Neuroglancer precomputed format, Gmsh (format versions 2.2, 4.0, and 4.1, .msh), OBJ (.obj), OFF (.off), PERMAS (.post, .post.gz, .dato, .dato.gz), PLY (.ply), STL (.stl), Tecplot .dat, TetGen .node/.ele, SVG (2D output only) (.svg), SU2 (.su2), UGRID (.ugrid), VTK (.vtk), VTU (.vtu), WKT (TIN) (.wkt), XDMF (.xdmf, .xmf).

Type:

str

N_BC_triangles

the number of triangles on the boundary of the domain associated to each boundary label in self.BC_labels. For example self.N_BC_triangles[‘my_label’] returns the number of boundary triangles associated to lable ‘my_label’. ‘my_label’ must be a key of self.BC_labels.

Type:

dict[str, int]

N_tets

The number of tetrahedra that make up the mesh (number of elements).

Type:

int

N_vertices

The number of vertices that make up the mesh.

Type:

int

vertices

An [3 x self.N_vertices] array containing the 3 coordinates of the N_vertices vertices that make up the mesh.

Type:

numpy.ndarray

Example

An element of this class can be initialized in the following way

>>> import edg_acoustics
>>> BC_labels = {'slip': 11, 'impedance1': 13, 'impedance2': 14, 'impedance3': 15}
>>> filename = "../data/tests/mesh/CoarseMesh.msh"
>>> mesh = edg_acoustics.Mesh(filename, BC_labels)

>>> mesh.N_BC_triangles
{'slip': 5347, 'impedance1': 400, 'impedance2': 3576, 'impedance3': 3294}
static create_mesh_from_geo_file(geo_file, freq_max, Nx)[source]

Create a mesh from a geo file. The mesh is generated iteratively with a characteristic length by the bisection method such that the PPW is between 8 and 10.

Parameters:
  • geo_file (str) – The path to the .geo file.

  • freq_max (float) – Maximum resolvable frequency of the simulation.

  • Nx (int) – Local polynomial basis. Default is Nx_default.

static compute_PPW(msh_file, wavelength, Np, volume)[source]

Compute the points per wavelength (PPW) of the mesh.

Parameters:
Returns:
  • PPW (float) – The points per wavelength of the mesh.

  • N_tetra (int) – The number of tetrahedra in the mesh.

static mesh_geo_file(geo_file, length_of_mesh)[source]

Generate a mesh with a characteristic length of length_of_mesh. Save the mesh to a .msh file, keeping the same name as the .geo file.

Parameters:
  • geo_file (str) – The path to the .geo file.

  • length_of_mesh (float) – The mesh size factor to control the characteristic length.

init_from_mesh_file(filename, BC_labels)[source]

Initializes the Mesh object from a mesh file. The mesh file is read and the relevant data is stored

Parameters:
Raises:

ValueError – If BC_labels[‘my_label’] is not present in the mesh, an error is raised. If a label is present in the mesh but not in BC_labels, an error is raised.

__eq__(other)[source]

Equality operator for the Mesh class.

Parameters:

other (edg_acoustics.Mesh) – The mesh object to compare with.

Returns:

bool – True if the two mesh objects are equal, False otherwise.

static compute_element_connectivity(EToV)[source]

Computes element connectivity.

Given a mesh made up of N_tets tetrahedra, compute the element connectivity. Element connectivity contains the information of the index of the neighbor over each of the four faces of the element and the face index of the neighbor shared. This information is returned in two arrays: EToE and EToF.

Parameters:

EToV (numpy.ndarray) – see EToV.

Returns:
  • EToE (numpy.ndarray) – see EToE.

  • EToF (numpy.ndarray) – see EToF.