pymech.meshtools#
Contents of meshtools.py#
- pymech.meshtools.delete_internal_bcs(mesh)[source]#
Deletes the internal boundary conditions ‘E’ in a Nek5000 mesh. Those are present in .rea files but do not need to be valid, and are completely absent from .re2 files. Returns the number of deleted conditions.
- Parameters:
mesh (
pymech.core.HexaData
) – The mesh to modify in-place.
- pymech.meshtools.edge_circle(el, iedge, midpoint)[source]#
Finds the radius of curvature and circle center based on the midsize-node of edge iedge of element el:
- Parameters:
el (
pymech.core.HexaData
) – element of mesh (usually, el=mesh.elem[i])iedge (int) – index of edge
midpoint (float) – list of coordinates of midsize-node (in other words, if the curvature were type ‘m’, the values of el.curv[iedge][:3])
- pymech.meshtools.edge_mid(el, iedge)[source]#
Finds the coordinates of the midsize-node of edge iedge of element el (in other words, if the curvature were type ‘m’, the values of el.curv[iedge][:3]):
- Parameters:
el (
pymech.core.HexaData
) – element of mesh (usually, el=mesh.elem[i])iedge (int) – index of edge
- pymech.meshtools.exponential_refinement_parameter(l0, ltot, n, tol=1e-14)[source]#
In a 1D exponential mesh spacing where n elements of lengths l0, alpha*l0, …, alpha^(n-1)*l0 add up to a total length ltot, return the parameter alpha given l0, ltot, and n.
- pymech.meshtools.extrude(mesh: HexaData, z, bc1='P', bc2='P', internal_bcs=True)[source]#
Extrudes a 2D mesh into a 3D one
- Parameters:
mesh (
pymech.core.HexaData
) – 2D mesh structure to extrudezmin (float) – min value of the z coordinate to extrude to
zmax (float) – max value of the z coordinate to extrude to
z (float 1d array) – z coordinates at which to extrude the mesh
bc1 (str) – the boundary conditions to use at each end
bc2 (str) – the boundary conditions to use at each end
internal_bcs (bool) – if True, build mesh connectivity using internal ‘E’ boundary conditions (note that those are not used by Nek5000 and will not be written to binary .re2 files).
- pymech.meshtools.extrude_mid(mesh, z, bc1, bc2, fun, funpar=0.0, internal_bcs=True)[source]#
Extrudes the mid elments of the 2D mesh into a 3D one. Following the pattern:
_____ _____ _____ _____ |1 /|\ 4| /|\ | |__ / | \ __|__ / | \ __| (fun (with parameter funpar) should change change sign in the mid element) |0 |2 |3 | 5| | | | | (half of the mid elements are also divided in 2 in (x, y)-plane) |__|__|__|__|__|__|__|__| (numbers in the figure indicate the indices (iel + 0; iel + 1; etc))
- Parameters:
mesh (
pymech.core.HexaData
) – 2D mesh structure to extrudez (float) – list of z values of the nodes of the elements of the extruded mesh in the high discretization region (len(z)-1 must be divide by 4)
bc (str) – the boundary condition to use at the ends
fun (function) – function that define the splitting lines for different discretization meshes
funpar (not defined, depends on the function) – parameter for functions that define the splitting lines for different discretization meshes (default: zero, can be used for when funpar is not needed inside fun)
Suggestion (see function extrude_split to understand how to call extrude_mid) –
- pymech.meshtools.extrude_refine(mesh2D, z, bc1='P', bc2='P', fun=None, funpar=None, imesh_high=0, internal_bcs=True)[source]#
Extrudes a 2D mesh into a 3D one, following the pattern
_____ _____ _____ _____ | | | | | | | | | | | | | | | |_____|_____|_____|_____| | /|\ | /|\ | |__ / | \ __|__ / | \ __| (fun (with parameter funpar) should change change sign in the mid element) | | | | | | | | | (half of the mid elements are also divided in 2 in (x,y)-plane) |__|__|__|__|__|__|__|__| | | | | | | | | | | | | | | | | | | | | | | | | | | | (imesh_high is the index of mesh with higher intended discretization in z) |__|__|__|__|__|__|__|__|
The pattern is similar to “Picture Frame” of an ancient NEKTON manual (https://www.mcs.anl.gov/~fischer/Nek5000/nekmanual.pdf). If the mid elements have curvature, the extrusion might modify it. Do not split in regions where the value of curvature parameters is very important.
- Parameters:
mesh2D (
pymech.core.HexaData
) – 2D mesh structure to extrudez (float array) – list of z values of the most refined zones of the extruded mesh
bc (str) – the boundary condition to use at the ends
fun (function) – list of functions that define the splitting lines for different discretization meshes (default: empty, in which case the simple extrusion function extrude is called instead)
funpar (list) – list of parameters for functions that define the splitting lines for different discretization meshes (default: None, equivalent to an array of zeroes)
imesh_high (int) – index of fun that defines the mesh with higher discretization. Example: 0, is the most internal mesh; 1 is the second most internal mesh, etc (default: the most internal mesh, imesh_high=0)
- pymech.meshtools.gen_circle(r: float, s: float, ns: int, no: int, curvature_fun=None, bl_fun=None, var=[2, 2, 1, 0, 0], nbc=1, bc=['W'], internal_bcs=True)[source]#
Generates a 2D circular mesh with a square at the center surrounded by an O mesh.
- Parameters:
r (float) – radius of the mesh
s (float) – relative length of the diagonal of the centre square mesh to the circle diameter
ns (int) – number of elements in the side of the square and in a quarter of the circumference of the circle
no (int) – number of elements in the O mesh part in the radial direction
internal_bcs (bool) – if True, builds the internal connectivity information of the elements
curvature_fun ([0, 1] -> [0, 1] function or None) – Function defining the evolution of the relative curvature of the edges between the straight side of the square and the circular edge. Defaults to x -> sin(pi/2 x) if None. A constant 1 means concentric circles, a constant zero means only straight edges inside the domain, but ideally you want a continuous function with f(0) = 0 and f(1) = 1.
bl_fun ([0, 1] -> [0, 1] function or None) – Function defining the evolution of the grid location between the edge of the square at 0 and the edge of the circle at 1. Defaults to an exponential grid spacing with a uniform spacing around the square if None.
var (integer list) – Number of geometry, velocity, pressure, temperature and scalar variables to define in the mesh
bc (str list) – boundary conditions to use for each field
internal_bcs – whether to build internal connectivity information
- pymech.meshtools.generate_internal_bcs(mesh, tol=0.001)[source]#
Generates internal boundary conditions ‘E’ in a Nek5000 mesh based on geometric proximity of faces. This will loop over all pairs of faces and connect them if their centres are closer than some specified relative tolerance. This function returns the number of internal connections found.
- Parameters:
mesh (
pymech.core.HexaData
) – The mesh to modify in-placetol (float) – the tolerance within which the centres of two faces are considered the same, relative to the smallest edge of the elements
- pymech.meshtools.keep_elements(mesh: HexaData, elems, external_bc='')[source]#
Reduce the mesh to a subset of its elements
- Parameters:
mesh (
pymech.core.HexaData
) – mesh to modifyelems (int array) – list of element numbers (zero indexed) to keep
external_bc (string) – if an element was connected to another which is removed from the mesh, replace that condition with external_bc
- pymech.meshtools.rotate_2d(mesh, x0, y0, theta)[source]#
Rotate a mesh around an axis aligned with z passing through (x0, y0, 0) by an angle theta.
- Parameters:
mesh (
pymech.core.HexaData
) – the mesh to modify in placex0 (float) – x-coordinate of the center of rotation
y0 (float) – y-coordinate of the center of rotation
theta (rotation angle) –