Slice

class Slice(*args)

GetFEM Slice object

Creation of a mesh slice. Mesh slices are very similar to a P1-discontinuous MeshFem on which interpolation is very fast. The slice is built from a mesh object, and a description of the slicing operation, for example:

sl = Slice(('planar',+1,[[0],[0]],[[0],[1]]), m, 5)

cuts the original mesh with the half space {y>0}. Each convex of the original Mesh m is simplexified (for example a quadrangle is splitted into 2 triangles), and each simplex is refined 5 times.

Slicing operations can be:

  • cutting with a plane, a sphere or a cylinder
  • intersection or union of slices
  • isovalues surfaces/volumes
  • “points”, “streamlines” (see below)

If the first argument is a MeshFem mf instead of a Mesh, and if it is followed by a mf-field u, then the deformation u will be applied to the mesh before the slicing operation.

The first argument can also be a slice.

General constructor for Slice objects

  • sl = Slice(sliceop, {Slice sl|{Mesh m| MeshFem mf, vec U}, int refine}[, mat CVfids]) Create a Slice using sliceop operation.

    sliceop operation is specified with Tuple or List, do not forget the extra parentheses!. The first element is the name of the operation, followed the slicing options:

    • (‘none’) : Does not cut the mesh.

    • (‘planar’, int orient, vec p, vec n) : Planar cut. p and n define a half-space, p being a point belong to the boundary of the half-space, and n being its normal. If orient is equal to -1 (resp. 0, +1), then the slicing operation will cut the mesh with the “interior” (resp. “boundary”, “exterior”) of the half-space. orient may also be set to +2 which means that the mesh will be sliced, but both the outer and inner parts will be kept.

    • (‘ball’, int orient, vec c, scalar r) : Cut with a ball of center c and radius r.

    • (‘cylinder’, int orient, vec p1, vec p2, scalar r) : Cut with a cylinder whose axis is the line (p1, p2) and whose radius is r.

    • (‘isovalues’, int orient, MeshFem mf, vec U, scalar s) : Cut using the isosurface of the field U (defined on the MeshFem mf). The result is the set {x such that :math:`U(x) leq s}` or {x such that `U`(x)=`s}` or {x such that `U`(x) >= `s}` depending on the value of orient.

    • (‘boundary’[, SLICEOP]) : Return the boundary of the result of SLICEOP, where SLICEOP is any slicing operation. If SLICEOP is not specified, then the whole mesh is considered (i.e. it is equivalent to (‘boundary’,{‘none’})).

    • (‘explode’, mat Coef) : Build an ‘exploded’ view of the mesh: each convex is shrinked (\(0 < \text{Coef} \leq 1\)). In the case of 3D convexes, only their faces are kept.

    • (‘union’, SLICEOP1, SLICEOP2) : Returns the union of slicing operations.

    • (‘intersection’, SLICEOP1, SLICEOP2) : Returns the intersection of slicing operations, for example:

      sl = Slice((intersection',('planar',+1,[[0],[0],[0]],[[0],[0],[1]]),
                                 ('isovalues',-1,mf2,u2,0)),mf,u,5)
      
    • (‘comp’, SLICEOP) : Returns the complementary of slicing operations.

    • (‘diff’, SLICEOP1, SLICEOP2) : Returns the difference of slicing operations.

    • (‘mesh’, Mesh m) : Build a slice which is the intersection of the sliced mesh with another mesh. The slice is such that all of its simplexes are stricly contained into a convex of each mesh.

  • sl = Slice('streamlines', MeshFem mf, mat U, mat S) Compute streamlines of the (vector) field U, with seed points given by the columns of S.

  • sl = Slice('points', Mesh m, mat Pts) Return the “slice” composed of points given by the columns of Pts (useful for interpolation on a given set of sparse points, see gf_compute('interpolate on',sl)).

  • sl = Slice('load', string filename[, Mesh m]) Load the slice (and its linked mesh if it is not given as an argument) from a text file.

area()

Return the area of the slice.

char()

Output a (unique) string representation of the Slice.

This can be used to perform comparisons between two different Slice objects. This function is to be completed.

cvs()

Return the list of convexes of the original mesh contained in the slice.

dim()

Return the dimension of the slice (2 for a 2D mesh, etc..).

display()

displays a short summary for a Slice object.

edges()

Return the edges of the linked mesh contained in the slice.

P contains the list of all edge vertices, E1 contains the indices of each mesh edge in P, and E2 contains the indices of each “edges” which is on the border of the slice. This function is useless except for post-processing purposes.

export_to_dx(filename, *args)

Synopsis: Slice.export_to_dx(self, string filename, …)

Export a slice to OpenDX.

Following the filename, you may use any of the following options:

  • if ‘ascii’ is not used, the file will contain binary data (non portable, but fast).
  • if ‘edges’ is used, the edges of the original mesh will be written instead of the slice content.
  • if ‘append’ is used, the opendx file will not be overwritten, and the new data will be added at the end of the file.

More than one dataset may be written, just list them. Each dataset consists of either:

  • a field interpolated on the slice (scalar, vector or tensor), followed by an optional name.
  • a mesh_fem and a field, followed by an optional name.
export_to_pos(filename, name=None, *args)

Synopsis: Slice.export_to_pos(self, string filename[, string name][[,MeshFem mf1], mat U1, string nameU1[[,MeshFem mf1], mat U2, string nameU2,…])

Export a slice to Gmsh.

More than one dataset may be written, just list them. Each dataset consists of either:

  • a field interpolated on the slice (scalar, vector or tensor).
  • a mesh_fem and a field.
export_to_pov(filename)

Export a the triangles of the slice to POV-RAY.

export_to_vtk(filename, *args)

Synopsis: Slice.export_to_vtk(self, string filename, …)

Export a slice to VTK.

Following the filename, you may use any of the following options:

  • if ‘ascii’ is not used, the file will contain binary data (non portable, but fast).
  • if ‘edges’ is used, the edges of the original mesh will be written instead of the slice content.

More than one dataset may be written, just list them. Each dataset consists of either:

  • a field interpolated on the slice (scalar, vector or tensor), followed by an optional name.
  • a mesh_fem and a field, followed by an optional name.

Examples:

  • Slice.export_to_vtk(‘test.vtk’, Usl, ‘first_dataset’, mf, U2, ‘second_dataset’)
  • Slice.export_to_vtk(‘test.vtk’, ‘ascii’, mf,U2)
  • Slice.export_to_vtk(‘test.vtk’, ‘edges’, ‘ascii’, Uslice)
interpolate_convex_data(Ucv)

Interpolate data given on each convex of the mesh to the slice nodes.

The input array Ucv may have any number of dimensions, but its last dimension should be equal to Mesh.max_cvid().

Example of use: Slice.interpolate_convex_data(Mesh.quality()).

linked_mesh()

Return the mesh on which the slice was taken.

memsize()

Return the amount of memory (in bytes) used by the slice object.

mesh()

Return the mesh on which the slice was taken (identical to ‘linked mesh’)

nbpts()

Return the number of points in the slice.

nbsplxs(dim=None)

Return the number of simplexes in the slice.

Since the slice may contain points (simplexes of dim 0), segments (simplexes of dimension 1), triangles etc., the result is a vector of size Slice.dim()+1, except if the optional argument dim is used.

pts()

Return the list of point coordinates.

set_pts(P)

Replace the points of the slice.

The new points P are stored in the columns the matrix. Note that you can use the function to apply a deformation to a slice, or to change the dimension of the slice (the number of rows of P is not required to be equal to Slice.dim()).

splxs(dim)

Return the list of simplexes of dimension dim.

On output, S has ‘dim+1’ rows, each column contains the point numbers of a simplex. The vector CV2S can be used to find the list of simplexes for any convex stored in the slice. For example ‘S[:,CV2S[4]:CV2S[5]]’ gives the list of simplexes for the fourth convex.