magritte.mesher module

class magritte.mesher.Mesh(meshFile)

Bases: object

Magritte custom mesh class (that ignores unconnected points).

__init__(meshFile)

Read the meshFile using meshio and remove unconnected points.

Parameters

meshFile (str) – File name of the mesh file.

magritte.mesher.boundary_cuboid(minVec, maxVec)

Retuns the gmsh script for a cuboid element that can be used as boundary.

Parameters
  • minVec (array_like) – (x_min, y_min, z_min) vector defining the cuboid.

  • maxVec (array_like) – (x_max, y_max, z_max) vector defining the cuboid.

Returns

out – A string containing the gmsh script defining the cuboid.

Return type

str

magritte.mesher.boundary_sphere(centre=array([0., 0., 0.]), radius=1.0)

Returns the gmsh script for a sphere element that can be used as boundary.

Parameters
  • centre (array_like) – (x, y, z) coordinates of the centre of the sphere.

  • radius (float) – Radius of the sphere.

Returns

out – A string containing the gmsh script defining the sphere.

Return type

str

magritte.mesher.boundary_sphere_in_cuboid(centre_in=array([0., 0., 0.]), radius_in=1.0, minVec=array([0., 0., 0.]), maxVec=array([1., 1., 1.]))

Returns the gmsh script for a sphere inside a cuboid that can be used as boundary.

Parameters
  • centre_in (array_like) – (x, y, z) coordinates of the centre of the sphere.

  • radius_in (float) – Radius of the sphere.

  • minVec (array_like) – (x_min, y_min, z_min) vector defining the cuboid.

  • maxVec (array_like) – (x_max, y_max, z_max) vector defining the cuboid.

Returns

out – A string containing the gmsh script defining the sphere in cuboid.

Return type

str

magritte.mesher.boundary_sphere_in_sphere(centre_in=array([0., 0., 0.]), radius_in=1.0, centre_out=array([0., 0., 0.]), radius_out=1.0)

Returns the gmsh script for a sphere inside a sphere that can be used as boundary.

Parameters
  • centre_in (array_like) – (x, y, z) coordinates of the centre of the inner sphere.

  • radius_in (float) – Radius of the inner sphere.

  • centre_out (array_like) – (x, y, z) coordinates of the centre of the outer sphere.

  • radius_out (float) – Radius of the outer sphere.

Returns

out – A string containing the gmsh script defining the sphere in sphere.

Return type

str

magritte.mesher.convert_msh_to_pos(meshName, replace: bool = False)

Convert a .msh file to a .pos file.

Parameters
  • modelName (str) – Path to the .msh file to convert.

  • replace (bool) – Whether or not to remove (and thus replace) the original .msh file.

magritte.mesher.create_mesh_from_background(meshName, boundary, scale_min, scale_max)

Creates a mesh with element sizes defined on a background mesh.

Parameters
  • meshName (str) – File name of the mesh file.

  • boundary (str) – Gmsh script containing the definition of the boundary.

  • scale_min (float) – Minimum desired element size of the mesh.

  • scale_max (float) – Maximum desired element size of the mesh.

magritte.mesher.create_mesh_from_function(meshName, boundary, scale_min, scale_max, scale_function)

Creates a mesh with element sizes defined by a scale function.

Parameters
  • meshName (str) – File name of the mesh file.

  • boundary (str) – Gmsh script containing the definition of the boundary.

  • scale_min (float) – Minimum desired element size of the mesh.

  • scale_max (float) – Maximum desired element size of the mesh.

  • scale_function (str) – Formula for the function describing the desired mesh element sizes.

magritte.mesher.generate_background_from_1D_data(meshName, R, data)

Generate a background mesh from 1D (radial) data.

Parameters
  • meshName (str) – File name of the mesh file.

  • R (array_type) – Array containing the radial positions at which the data is given.

  • data (array_type) – Array containing the data to put a background.

magritte.mesher.get_recursive_remesh(positions: numpy.array, data: numpy.array, depth: int, max_depth: int, threshold: float, remesh_points: numpy.array, remesh_nb_points: int)

Helper function for the point cloud remeshing method. Uses recursion to remesh a given point cloud (uses all data to determine whether to recurse on a smaller scale), by evaluating the total variation in the data (compared against the threshold).

Parameters
  • positions (numpy array of float) – 3D positions of the points (dimension of array N by 3)

  • data (numpy array of float) – Corresponding data for the points, in order to determine the variation. Must be non-zero

  • depth (int) – Current recursion depth

  • max_depth (int) – Maximal recursion depth. Determines the miminal scale in the remeshed point cloud. Must be positive

  • threshold (float) – The threshold to use when deciding the variation to be small enough in order to approximate a region with a single point. Must be positive

  • remesh_points (numpy array (in/out)) – Array holding the remeshed point positions. Must be large enough to contain all remeshed points, Must have at least dimensions N by 3.

  • remesh_nb_points (int (in/out)) – The number of point in the remeshed point cloud. Must be initialized to 0

magritte.mesher.point_cloud_add_spherical_inner_boundary(remeshed_positions, nb_boundary, radius, healpy_order=5, origin=array([0., 0., 0.]))

Function for specifying a spherical inner boundary in a remeshed point cloud. First clears the inner region of points and then constructs a spherical boundary using healpy.

Parameters
  • remeshed_positions (numpy array of float) – Positions of the points in the point cloud. Assumes the boundary points to lie in front.

  • nb_boundary (unsigned int) – The number of boundary points in the point cloud.

  • radius (positive float) – Radius of the spherical inner boundary

  • healpy_order (unsigned int) – The number of points on the inner boundary is defined as: 12*(healpy_order**2), as the healpy discretization of the sphere is used.

  • origin (1 by 3 numpy vector of float) – Contains x,y,z coordinates of center point of the sphere (by default [0.0,0.0,0.0]^T)

Returns

  • remeshed_positions (numpy array of float) – The positions of the points in the remeshed point cloud. The boundary points lie in front.

  • number of boundary points (unsigned int) – The number of boundary points in the remeshed point cloud.

magritte.mesher.point_cloud_add_spherical_outer_boundary(remeshed_positions, nb_boundary, radius, healpy_order=10, origin=array([0., 0., 0.]))

Function for specifying a spherical outer boundary in a remeshed point cloud. First clears the region outside the sphere and then constructs a spherical boundary using healpy.

Parameters
  • remeshed_positions (numpy array of float) – Positions of the points in the point cloud. Assumes the boundary points to lie in front.

  • nb_boundary (unsigned int) – The number of boundary points in the point cloud.

  • radius (positive float) – Radius of the spherical outer boundary

  • healpy_order (unsigned int) – The number of points on the outer boundary is defined as: 12*(healpy_order**2), as the healpy discretization of the sphere is used.

  • origin (1 by 3 numpy vector of float) – Contains x,y,z coordinates of center point of the sphere (by default [0.0,0.0,0.0]^T)

Returns

  • remeshed_positions (numpy array of float) – The positions of the points in the remeshed point cloud. The boundary points lie in front.

  • number of boundary points (unsigned int) – The number of boundary points in the remeshed point cloud.

magritte.mesher.point_cloud_clear_inner_boundary_generic(remeshed_positions, nb_boundary, numpy_friendly_function, threshold)

General function for consistently clearing an inner boundary region in a remeshed point cloud.

Parameters
  • remeshed_positions (numpy array of float) – Positions of the points in the point cloud. Assumes the boundary points to lie in front.

  • nb_boundary (unsigned int) – The number of boundary points in the point cloud.

  • numpy_friendly_function (lambda function which operates on numpy array) – Function which acts on location for determining the shape of the inner boundary condition region

  • threshold (float) – Cutoff value associate to numpy_friendly_function in order to constrain the shape of the inner boundary region

Returns

  • remeshed_positions (numpy array of float) – The positions of the points in the remeshed point cloud. The boundary points lie in front.

  • number of boundary points (unsigned int) – The number of boundary points in the remeshed point cloud.

magritte.mesher.point_cloud_clear_outer_boundary_generic(remeshed_positions, nb_boundary, numpy_friendly_function, threshold)

General function for consistently clearing all points outside a given region in a remeshed point cloud.

Parameters
  • remeshed_positions (numpy array of float) – Positions of the points in the point cloud. Assumes the boundary points to lie in front.

  • nb_boundary (unsigned int) – The number of boundary points in the point cloud.

  • numpy_friendly_function (lambda function which operates on numpy array) – Function which acts on location for determining the shape of the inner boundary condition region

  • threshold (float) – Cutoff value associate to numpy_friendly_function in order to constrain the shape of the inner boundary region

Returns

  • remeshed_positions (numpy array of float) – The positions of the points in the remeshed point cloud. The boundary points lie in front.

  • number of boundary points (unsigned int) – The number of boundary points in the remeshed point cloud.

magritte.mesher.reduce(meshName, delaunay, tracer, boundary, scale_max=1e+99, scale_min=0.0, threshold=0.21, fmin=1.0, ftarget=2.15)

Reduce a model mesh for a given tracer function.

Parameters
  • meshName (str) – File name of the mesh file.

  • delaunay – scipy.spatial.Delaunay object for the given mesh.

  • tracer (array_like) – 1D array containing the tabulated tracer function.

  • boundary (str) – Gmsh script containing the definition of the boundary.

  • scale_max (float) – Maximum desired element size of the mesh.

  • scale_min (float) – Minimum desired element size of the mesh.

  • threshold (float) – Threashold value for relative difference below which we coarsen.

  • fmin (float) – Multiplication factor of the mesh element size where the relative difference is below the threashold.

  • ftarget (float) – Multiplication factor of the mesh element size where the relative difference is below the threashold.

magritte.mesher.remesh_point_cloud(positions, data, max_depth=9, threshold=0.05, hullorder=3)

Remeshing method by comparing the maximal variation of the data against the threshold. Uses a recursive method with maximal depth max_depth. The hullorder specifies the density of the generated uniform boundary.

Parameters
  • positions (numpy array of float) – 3D positions of the points (dimension of array N by 3)

  • data (numpy array of float) – Corresponding data for the points, in order to determine the variation. Must be non-zero

  • max_depth (int) – Maximal recursion depth. Determines the miminal scale in the remeshed point cloud. Must be positive

  • threshold (float) – The threshold to use when deciding the variation to be small enough in order to approximate a region with a single point. Must be positive

  • hullorder (int) – Determines the amount of boundary points generated in the hull around the remeshed point cloud. Increasing this by 1 results in a 4 times increase in number of boundary points. Must be positive

Returns

  • remeshed_positions (numpy array of float) – The positions of the points in the remeshed point cloud. The boundary points lie in front.

  • number of boundary points (unsigned int) – The number of boundary points in the remeshed point cloud.

magritte.mesher.run(command)

Run command in shell and continuously print its output.

Parameters

command (str) – The command to run in the shell.