MeshUtils

The mesh_utils module contains the functions needed to generate a mesh. It also contains several other helper functions that make using the meshing library easier. There are two ways to generate a new mesh, mesh_utils.generate_2dm and mesh_utils.generate_mesh.

The mesh_utils.generate_mesh function takes a MultiPolyMesherIo object and generates the mesh by filling in the points and the cells properties. The cell_polygons property is also generated if you have set the return_cell_polygons property set to true on the MultiPolyMesherIo. This gives you the definition of the mesh in memory so that you can work with it using other python libraries.

The mesh_utils.generate_mesh function takes a MultiPolyMesherIo object and a file_name. While this function does everything that generate_mesh does, it also generates a 2dm file which can be useful if you are working with a product/library that can read 2dm files.

xmsmesh.meshing.mesh_utils.check_mesh_input_topology(mesh_io: xms::MeMultiPolyMesherIo) → iterable

Checks if the input polygons intersect one another

Parameters:mesh_io (MultiPolyMesherIo) – Input polygons and options for generating a mesh.
Returns:true if mesh inputs are topologically correct, and a string of messages.
Return type:tuple
xmsmesh.meshing.mesh_utils.generate_2dm(mesh_io: xms::MeMultiPolyMesherIo, file_name: unicode, precision: int=15L) → tuple

Creates a mesh from the input polygons and writes it to a 2dm file.

Parameters:
  • mesh_io (MultiPolyMesherIo) – Input polygons and options for generating a mesh.
  • file_name (str) – The file name of the output 2dm file.
  • precision (int, optional) – The decimal point precision of the resulting mesh.
Returns:

true if the mesh was generated successfully false otherwise, and a string of messages.

Return type:

tuple

xmsmesh.meshing.mesh_utils.generate_mesh(mesh_io: xms::MeMultiPolyMesherIo) → iterable

Creates a mesh from the input polygons.

Parameters:mesh_io (MultiPolyMesherIo) – Input polygons and options for generating a mesh.
Returns:true if the mesh was generated successfully false otherwise, and a string of messages.
Return type:tuple
xmsmesh.meshing.mesh_utils.redistribute_poly_line(poly_line: iterable, size: float) → iterable

Redistributes the points along a line to a constant spacing

Parameters:
  • poly_lin (iterable) – Input poly line locations.
  • size (Float) – The desired spacing for point redistribution
Returns:

redistributed poly line locations

Return type:

iterable

xmsmesh.meshing.mesh_utils.size_function_from_depth(depths: iterable, min_size: float, max_size: float) → iterable

Creates a size at each point based on the depth at the point and the min and max sizes the equation is min_depth + ( (depth - min_depth) / (max_depth - min_depth) ) * (max_size - min_size). This is often useful for coastal numerical model simulations.

Parameters:
  • depths (iterable) – The measured depths at point locations
  • min_size (float) – The minimum element edge size
  • max_size (float) – The maximum element edge size
Returns:

Array of sizes based on depth

Return type:

iterable

xmsmesh.meshing.mesh_utils.smooth_elev_by_slope(tin: xms::TrTin, elevations: iterable, max_slope: float, anchor_to_max: bool, pts_flag: iterable) → iterable

Smooths a elevations based on max specified slope (max_slope) preserving either the min or max based on anchor_type

Parameters:
  • tin (Tin) – Points and triangles defining the connectivity of the elevations.
  • elevations (iterable) – Array of the current elevations
  • max_slope (Float) – Maximum allowable slope
  • anchor_to_max (Bool) – Indicates if you are anchoring to the max slope.
  • pts_flag (iterable) – Flag to indicate if the value at the point should be adjusted (a value of true will skip the point). Leave the bitset empty to process all points.
Returns:

Array of smoothed elevations

Return type:

iterable

xmsmesh.meshing.mesh_utils.smooth_size_function(tin: xms::TrTin, sizes: iterable, size_ratio: float, min_size: float, anchor_type: int, pts_flag: iterable) → iterable

Smooths a size function. Ensures that the size function transitions over a sufficient distance so that the area change of adjacent elements meets the size ratio passed in.

Parameters:
  • tin (Tin) – Points and triangles defining the connectivity of the size function.
  • sizes (iterable) – Array of the current sizes
  • size_ratio (float) – Allowable size difference between adjacent elements
  • min_size (float) – Minimum specified element size
  • anchor_type (int) – The minimum element edge size
  • pts_flag (iterable) – Flag to indicate if the value at the point should be adjusted (a value of true will skip the point). Leave the bitset empty to process all points.
Returns:

Array of smoothed sizes

Return type:

iterable