pyoomph.meshes.gmsh module

class pyoomph.meshes.gmsh.GmshTemplate(loaded_from_mesh_file=None)[source]

Bases: MeshTemplate

A template for creating a mesh using Gmsh as backend. Specify the geometry in an overridden define_geometry() method, using the point(), line(), spline(), circle_arc(), plane_surface() and other methods.

class GmshFakeEntry(my_id, dim_tag)[source]

Bases: object

Just a fake entry to store the dimension and tag of an entity

circle_arc(startpt, endpt, *, center=None, through_point=None, name=None, with_macro_element=True)[source]

Adds a circlular arc to the mesh geometry.

Parameters:
  • startpt (Union[Point, Sequence[Union[Expression, int, float]]]) – The starting point of the circle arc.

  • endpt (Union[Point, Sequence[Union[Expression, int, float]]]) – The ending point of the circle arc.

  • center (Union[Point, Sequence[Union[Expression, int, float]], None]) – The center point of the circle arc. If not provided, it will be calculated based on the through_point argument.

  • through_point (Union[Point, Sequence[Union[Expression, int, float]], None]) – A point that the circle arc should pass through. If not provided, the circle arc requires a center.

  • name (Optional[str]) – The name of the circle arc to identify it later e.g. as boundary.

  • with_macro_element (bool) – Whether to include a macro element. In that case, spatial refinements (on moving meshes only the initial refinement) will be mapped on the circle.

Return type:

Union[Line, CircleArc, None]

Returns:

The created circle arc or a line if the circle arc is degenerate.

Raises:
  • RuntimeError – If the geometry is not defined inside the ‘define_geometry’ function.

  • RuntimeError – If both center and through_point are provided.

create_lines(*args)[source]

Creates multiple lines with different names based on the given arguments. For line loop around a box, you can e.g. do

lines=self.create_lines((0,0), "left", (0,1), "top", (1,1), "right", (1,0), "bottom", (0,0))
self.plane_surface(*lines,name="box") # Create the surface of the box
Parameters:

*args (Union[Point, List[Union[Expression, int, float]], Tuple[Union[Expression, int, float]], str]) – Variable number of arguments representing the points and names of the lines. Each argument should be in the format: p1, <name>, p2, <name>, p3, <name>, p4, … If it stops with a name, not a point, it will close the line loop to the first point

Return type:

List[Line]

Returns:

A list of Line objects representing the created lines.

Raises:

ValueError – If the arguments are not in the correct format.

default_resolution: Optional[float]

The default resolution for the mesh as a nondimensional typical element length scale

define_geometry()[source]

Override specifically to define the geometry of this mesh by adding points, lines, surfaces, etc.

extrude(*args, shift=[0, 0, 1], recombine=False, start_name=<function GmshTemplate.<lambda>>, end_name=<function GmshTemplate.<lambda>>, layers=None)[source]

Extrudes the given entities by the given shift. The bulk surface name will become a volume and the line surfaces will become 2d surfaces. Additionally, the start and end surfaces of the extrusion will be named according to the given functions.

Parameters:
  • *args – Variable length arguments representing the entities to extrude. Can be names or the entities themselves.

  • shift (List[Union[Expression, int, float]]) – The shift to extrude by. Can be a list of expressions or numbers.

  • recombine (bool) – Flag indicating whether to recombine the extruded entities.

  • start_name – Function to generate the start name of the extrusion.

  • end_name – Function to generate the end name of the extrusion.

  • layers (Optional[int]) – Number of layers to extrude. If None, the extrusion will be determined by the mesh size.

extrude_generated_mesh: Optional[Tuple[ExpressionOrNum, int]]

If set, the entire mesh will be extruded in the next dimension. The first entry in the tuple is the dimensional distance, the second the number of layers.

line(*args, name=None)[source]

Create a line (segment-wise) line for the mesh. When given a name, it can be used to identify the line later, e.g. for boundary conditions.

Parameters:
  • *args (Union[Sequence[Union[Expression, int, float]], Point]) – Variable-length argument list of points or sequences of points defining the line.

  • name (Optional[str]) – Name of the line entity.

Return type:

Optional[Line]

Returns:

The created line entity, or None if the line is degenerate.

Raises:

RuntimeError – If the geometry is not defined inside the ‘define_geometry’ function.

mesh_mode: Literal['quads', 'tris', 'SV', 'only_quads']

Selects the default element type of the mesh. Can be "quads" (try to create quads if possible), "tris" (only triangles), "SV" (Scott-Vogelius elements) or "only_quads" (only quadrilateral elements by splitting triangles)

mesh_size_factor: float

This factor is used to scale all size arguments (including the default resolution) by the given factor. Useful to e.g. increase the mesh resolution by a factor.

mirror_mesh: Optional[Union[Literal['mirror_x', 'mirror_y'], List[Literal['mirror_x', 'mirror_y']]]]

If set, the input mesh will be mirrored and copied along the given axis or axes. Useful to generate symmetric meshes for e.g. pitchfork tracking

order

The default order of the elements. Can be 1 or 2. Note that if only first order ("C1") elements are created, the mesh will be reduced to first order, even if the mesh is set to second order. Likewise, a first order mesh will be split to second order if second order elements ("C2") are created on it.

plane_surface(*args, name=None, holes=None, reversed_order=False)[source]

Creates a planar surface in the mesh. You must supply the enclosing boundaries (either by name or the line/circle_arc/spline/bspline objects) as arguments. If you give it a name, it can be used to add equations to the domain.

Parameters:
  • *args (Union[str, Line, Spline, BSpline, CircleArc, None]) – Variable length arguments representing the lines or curves that define the boundary of the surface, in any order.

  • name (Optional[str]) – Name of the surface for e.g. adding equations later on by the name.

  • holes (Optional[List[Sequence[Union[str, Line, Spline, BSpline, CircleArc]]]]) – List of holes within the surface, where each hole is defined by a sequence of lines or curves.

  • reversed_order (bool) – Flag indicating whether to reverse the order of the lines or curves.

Return type:

List[PlaneSurface]

Returns:

List of created plane surfaces. Can be multiple, if you have e.g. multiple disjunct domains circumscripted by the given lines/splines/circle_arcs.

point(x, y=0.0, z=0.0, size=None, *, name=None, consider_spatial_scale=None)[source]

Add a point to the geometry. Coordinates must be given in the spatial unit, e.g. in meter if the problem has a metric set_scaling(spatial=…) set. The size controls the mesh size and will default to self.default_resolution if not given. By a name, the point can be identified later, e.g. for a boundary condition.

Parameters:
  • x (Union[Expression, int, float]) – The x-coordinate of the point.

  • y (Union[Expression, int, float]) – The y-coordinate of the point. Defaults to 0.0.

  • z (Union[Expression, int, float]) – The z-coordinate of the point. Defaults to 0.0.

  • size (Union[Expression, int, float, None]) – The size of the point. Defaults to None, which means default_resolution. Negative sizes are in terms of default_resolution

  • name (Optional[str]) – The name of the point. Defaults to None.

  • consider_spatial_scale (Optional[bool]) – Whether to consider spatial scaling. Defaults to None.

Returns:

The created point. Can be used for e.g. creating lines, circle_arcs or splines.

Return type:

Point

Raises:
  • RuntimeError – If geometry is added outside the ‘define_geometry’ function.

  • RuntimeError – If the mesh resolution (size argument) is not a float.

spline(ptlistIn, *, name=None, with_macro_element=True)[source]

Create a spline curve given by a list of points. If a name is supplied, it can be used for e.g. boundary conditions.

Parameters:
  • ptlistIn (Sequence[Union[Point, Sequence[Union[Expression, int, float]]]]) – List of points defining the spline curve.

  • name (Optional[str]) – Name of the spline curve. Default is None.

  • with_macro_element (bool) – Flag indicating whether to include a macro element for the spline curve. Default is True.

Returns:

The created spline curve.

Return type:

Spline

use_macro_elements: bool

If True, macro elements will be used for the mesh, i.e. curved elements will be considered