qtcad.device.mesh3d module
3d Mesh and SubMesh classes.
- class Mesh(scaling_factor, filename, verbose=True)
Bases:
MeshClass to store and process mesh properties such as node coordinates and elements.
- Attributes:
- dim (int) – Dimension of the mesh
tetra_number (int) – Number of tetrahedral elements in the mesh
tri_number (int) – Number of triangular elements in the mesh
node_number (int) – Number of global nodes.
glob_nodes (2D array) – Coordinates of the global nodes. First array index: global node index. Second array index: Cartesian direction (x, y, or z).
elem_number (int) – Number of elements in the mesh including boundary elements.
all_connectivity (list) – Global nodes contained by all elements, including boundary elements.
connectivity (2D array) – Global nodes contained by each line element. The row index labels distinct elements, while the column index labels local nodes for each element, so the array shape is Ntetra x 4, where Ntetra is the number of tetrahetral elements. Values stored in the array are global node indices, starting from 0.
- geometry_path (str): Path to the geometry file such as .xao or
.geo_unrolled, to build a coarse mesh.
- __init__(scaling_factor, filename, verbose=True)
Constructor for the mesh class.
- Parameters:
scaling_factor (float) – Factor by which node coordinates are multiplied to correspond to SI units.
filename (str, gmsh.model obj) – If a string is passed it represents the path to the mesh file to build the mesh. If a gmsh.model is passed it represents the gmsh model object to build the mesh.
verbose (bool, optional) – If True, print mesh statistics. Default: True.
- centroids()
Calculate the centroid of each tetrahedral element.
- Returns:
2D array – Centroid of each element, with row index corresponding to elements and column index to x, y, z coordinates.
- loc_node_coords()
Get arrays containing the local-node coordinates for each element.
- Returns:
tuple – a tuple (x_loc_nodes, y_loc_nodes, z_loc_nodes) where x_loc_nodes (y_loc_nodes, z_loc_nodes) is a 2D array containing the x (y, z) coordinate at each local node (column idx) and element (row idx)
- nodes_in_box(coords_min, coords_max)
Gets indices of global nodes within a box.
- Parameters:
coords_min (tuple) – Minimum xyz coordinate values.
coords_max (tuple) – Maximum xyz coordinate values.
- Returns:
1d array of int – The indices of the global nodes within the box.
- save(path, verbose=False)
Saving the mesh into a file
- Parameters:
path (str) – Path to the file where the mesh will be saved.
verbose (bool) – If True, prints additional information during saving.
Note
The file format is determined by the file extension. Supported formats include Gmsh (.msh, .msh2, and .msh4) and HDF5 (.h5, .hdf5)
- set_geometry_path(path)
Set the path to the geometry file defining the device.
- Parameters:
path (str) – Path to the geometry file.
- show()
Plot the mesh using PyVista.
- symmetric_mesh(a, b, c, d, mesh_file=None, geo_file=None, verbose=False)
Reflects the mesh geometry across the plane defined by ax + by + cz + d = 0.
- Parameters:
a, b, c, d (float) – Coefficients of the plane equation.
mesh_file (str) – Whether to save the mirrored mesh to a file in the given path. If None, the mesh is not saved. Default: None
geo_file (str) – Path to the original half-geometry file. If provided, the mirrored geometry will be saved in the same directory as the original file, with _mirrored appended to the filename. If set to None, the mirrored geometry will not be saved. Default: None
verbose (bool) – Whether to print the mesh information. Default: False
- Returns:
Mesh – Mirrored mesh object
- tetra_volumes()
Calculate the volume of all elements assuming that they are all tetrahedral.
- Returns:
1D array – the volume of each element
- toglobal(f_loc: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]]
Maps quantity defined over local nodes onto global nodes.
The mapping is performed by averaging contributions from all local nodes associated with the same global node.
- Parameters:
f_loc – Quantity defined over the mesh in local-node representation. The first index runs over the elements and the second index over the local nodes.
- Returns:
The quantity defined over global nodes. Its first index runs over the global nodes.
- tolocal(field)
Returns field defined over local nodes if input is global or if input is defined over elements only (no local node).
- Parameters:
field (ndarray) – The variable to return.
- Returns:
nd field – Field defined over local nodes.
Note
Can take the following field formats as input. * 1D array over global nodes only. * ND array with element index first, and any number of other
indices along other axes (band, valleys, etc.). In this case, the output array has element index first, local node index second, and all other indices next.
2D array with element index first and local node index second. In this case, the field is not modified.
- class SubMesh(parent, nodes, verbose=True)
Bases:
SubMeshA submesh is a subset of a parent mesh.
- Attributes:
nodes_in_parent (1d array) – Number of each node belonging to the submesh in the parent mesh.
Note
All other attributes are inherited from the parent mesh.
- __init__(parent, nodes, verbose=True)
Constructor of the submesh class.
- Parameters:
parent (mesh object) – The parent mesh.
nodes (1d array, string, or list of strings) – The nodes defining the subset of the parent mesh, or region label, or list of region labels.
verbose (bool, optional) – If True, print submesh statistics. Default: True.
- toglobal(f_loc)
Converts an array from local node to global node representation.
Takes the average of all values given to global nodes that are common to several local nodes.
- Parameters:
f_loc (ndarray) – The field in local node representation with the element number index first and local node index second.
- Returns:
(ndarray) – The field defined over global nodes
Note
It is not generally a good idea to use this method as it will not properly capture discontinuities accross interfaces. Therefore it should only be used in solvers as a last resort. It is often a better idea to compute quantities over local nodes or elements.
- tolocal(field)
Returns field defined over local nodes if input is global or if input is defined over elements only (no local node).
- Parameters:
field (ndarray) – The variable to return.
- Returns:
nd field – Field defined over local nodes.
Note
Can take the following field formats as input. * 1D array over global nodes only. * ND array with element index first, and any number of other
indices along other axes (band, valleys, etc.). In this case, the output array has element index first, local node index second, and all other indices next.
2D array with element index first and local node index second. In this case, the field is not modified.