# sfepy.discrete.fem.meshio module

class sfepy.discrete.fem.meshio.ANSYSCDBMeshIO(filename, **kwargs)
  format = 'ansys_cdb'
  static guess(filename)
  static make_format(format, nchar=1000)
  read(mesh, **kwargs)
  read_bounding_box()
  read_dimension(ret_fd=False)
  write(filename, mesh, out=None, **kwargs)

class sfepy.discrete.fem.meshio.ComsolMeshIO(filename, **kwargs)
  format = 'comsol'
  read(mesh, **kwargs)
  write(filename, mesh, out=None, **kwargs)

class sfepy.discrete.fem.meshio.GmshIO(filename, file_format=None, **kwargs)

  Used to read and write data in .msh format when file_format gmsh-dg is specified. Tailored for use with Discontinous galerking methods, mesh and ElementNodeData with InterpolationScheme can be written and read. It however omits mat_ids and node_groups.

  For details on format see [1].

  For details on representing and visualization of DG FEM data using gmsh see [2].

  [1] http://gmsh.info/doc/texinfo/gmsh.html#File-formats

  [2] Remacle, J.-F., Chevaugeon, N., Marchandise, E., & Geuzaine, C. (2007). Efficient visualization of high-order finite elements. International Journal for Numerical Methods in Engineering, 69(4), 750-771. https://doi.org/10.1002/nme.1787

  format = 'gmshio'
  load_slices = {'all': slice(0, None, None), 'first': slice(0, 1, None), 'last': slice(-1, None, None)}
  read_data(step=None, filename=None, cache=None)

    Reads file or files with basename filename or self.filename. Considers all files to contain data from time steps of solution of single transient problem i.e. all data have the same shape, mesh and same interpolation scheme in case of ElementNodeData. Does not read mulitple NodeData or ElementData. For stationary problems just reads one file with time 0.0 and time step 0.

    Providing filename allows reading multiple files of format basename.*[0-9].msh

    Parameters:
      step String, int, optional

        “all”, “last”, “first” or number of step to read: if “all” read all files with the basename and varying step, if “last” read only last step of all files with the filename, if “first” reads step=0, if None reads file with filename provided or specified in object.

      filename string, optional

        Filename of the files to use, if None filename from object is used. Basename is extracted as basename.*[0-9].msh

      cache has no effect
    Returns:
      out dictionary

        Keys represent name of data, values are Structs with attributes:

        datalist, array

          For ElementNodeData with shape (n_cell, n_cell_dof) contains for each time step. For other contains array of data from last time step.

        timelist

          Contains times.

        time_nlist

          Contains time step numbers.

        schemeStruct

          Interpolation scheme used in data, only one interpolation scheme is allowed.

        scheme_namestr

          Name of the interpolation scheme, repeated fo convenience.

        modestr

          Represents of type of data. cell_nodes : for ElementNodeData; vertex or cell : Note that for vertex and cell data reading multiple time steps does not work yet.

    Notes

    The interpolation scheme Struct contains the following items:
      namestring

        Name of the scheme.

      Farray

        Coefficients matrix as defined in [1] and [2].

      Parray

        Exponents matrix as defined in [1] and [2].

  write(filename, mesh, out=None, ts=None, **kwargs)

    Writes mesh and data, handles cell DOFs data from DGField as ElementNodeData.

    Omits gmsh:ref for cells and vertices i.e. mat_ids and node_groups to prevent cluttering the GMSH postprocessing.

    Parameters:
      filename string

        Path to file.

      mesh sfepy.discrete.fem.mesh.Mesh

        Computational mesh to write.

      out dictionary

        Keys represent name of the data, values are Structs with attributes:

        dataarray

          For ElementNodeData shape is (n_cell, n_cell_dof)

        modestr

          Represents type of data, cell_nodes for ElementNodeData.

        For ElementNodeData:

        schemeStruct

          Interpolation scheme used in data, only one interpolation scheme is allowed.

        scheme_namestr

          Name of the interpolation scheme, associated with data, repeated fo convenience.

      ts sfepy.solvers.ts.TimeStepper instance, optional

        Provides data to write time step.

    Notes

    The interpolation scheme Struct contains the following items:
      namestring

        Name of the scheme.

      Farray

        Coefficients matrix as defined in [1] and [2].

      Parray

        Exponents matrix as defined in [1] and [2].

class sfepy.discrete.fem.meshio.HDF5MeshIO(filename, **kwargs)
  format = 'hdf5'
  read(mesh=None, **kwargs)
  read_bounding_box(ret_fd=False, ret_dim=False)
  read_data(step, filename=None, cache=None)
  read_data_header(dname, step=None, filename=None)
  read_dimension(ret_fd=False)
  read_last_step(filename=None)

    The default implementation: just return 0 as the last step.

  static read_mesh_from_hdf5(filename, group=None, mesh=None)

    Read the mesh from a HDF5 file.

    filename: str or tables.File

      The HDF5 file to read the mesh from.

    group: tables.group.Group or str, optional

      The HDF5 file group to read the mesh from. If None, the root group is used.

    mesh: sfepy.dicrete.fem.Mesh or None

      If None, the new mesh is created and returned, otherwise content of this argument is replaced by the read mesh.

    Returns:
      sfepy.dicrete.fem.Mesh

        readed mesh

  read_time_history(node_name, indx, filename=None)
  read_time_stepper(filename=None)
  read_times(filename=None)

    Read true time step data from individual time steps.

    Returns:
      steps array

        The time steps.

      times array

        The times of the time steps.

      nts array

        The normalized times of the time steps, in [0, 1].

  read_variables_time_history(var_names, ts, filename=None)
  string = <module 'string' from '/usr/lib/python3.14/string/__init__.py'>
  write(filename, mesh, out=None, ts=None, cache=None, xdmf=False, **kwargs)
  static write_mesh_to_hdf5(filename, group, mesh, force_3d=False)

    Write mesh to a hdf5 file.

    filename: str or tables.File

      The HDF5 file to write the mesh to.

    group: tables.group.Group or None or str

      The HDF5 file group to write the mesh to. If None, the root group is used. The group can be given as a path from root, e.g. /path/to/mesh

    mesh: sfepy.dicrete.fem.Mesh

      The mesh to write.

  static write_xdmf_file(filename, **kwargs)

class sfepy.discrete.fem.meshio.HDF5XdmfMeshIO(filename, **kwargs)
  format = 'hdf5-xdmf'
  write(filename, mesh, out=None, ts=None, cache=None, **kwargs)

class sfepy.discrete.fem.meshio.HypermeshAsciiMeshIO(filename, **kwargs)
  format = 'hmascii'
  read(mesh, **kwargs)
  read_dimension()
  write(filename, mesh, out=None, **kwargs)

class sfepy.discrete.fem.meshio.Mesh3DMeshIO(filename, **kwargs)
  format = 'mesh3d'
  read(mesh, **kwargs)
  read_dimension()

class sfepy.discrete.fem.meshio.MeshIO(filename, **kwargs)

  The abstract class for importing and exporting meshes.

  Read the docstring of the Mesh() class. Basically all you need to do is to implement the read() method:

      def read(self, mesh, **kwargs):
          nodes = ...
          ngroups = ...
          conns = ...
          mat_ids = ...
          descs = ...
          mesh._set_io_data(nodes, ngroups, conns, mat_ids, descs)
          return mesh

  See the Mesh class’ docstring how the nodes, ngroups, conns, mat_ids and descs should look like. You just need to read them from your specific format from disk.

  To write a mesh to disk, just implement the write() method and use the information from the mesh instance (e.g. nodes, conns, mat_ids and descs) to construct your specific format.

  Optionally, subclasses can implement read_data() to read also computation results. This concerns mainly the subclasses with implemented write() supporting the ‘out’ kwarg.

  The default implementation od read_last_step() just returns 0. It should be reimplemented in subclasses capable of storing several steps.

  static any_from_filename(filename, prefix_dir=None, file_format=None, mode='r')

    Create a MeshIO instance according to the kind of filename.

    Parameters:
      filename str, function or MeshIO subclass instance

        The name of the mesh file. It can be also a user-supplied function accepting two arguments: mesh, mode, where mesh is a Mesh instance and mode is one of ‘read’,’write’, or a MeshIO subclass instance.

      prefix_dir str

        The directory name to prepend to filename.

    Returns:
      io MeshIO subclass instance

        The MeshIO subclass instance corresponding to the kind of filename.

  call_msg = 'called an abstract MeshIO instance!'
  format = None
  get_filename_trunk()
  get_vector_format(dim)
  read(mesh, omit_facets=False, **kwargs)
  read_data(step, filename=None, cache=None)
  read_last_step()

    The default implementation: just return 0 as the last step.

  read_times(filename=None)

    Read true time step data from individual time steps.

    Returns:
      steps array

        The time steps.

      times array

        The times of the time steps.

      nts array

        The normalized times of the time steps, in [0, 1].

    Notes

    The default implementation returns empty arrays.

  set_float_format(format=None)
  write(filename, mesh, **kwargs)

class sfepy.discrete.fem.meshio.MeshioLibIO(filename, file_format=None, **kwargs)
  cell_types = {('hexahedron', 3): '3_8', ('line', 1): '1_2', ('line', 2): '1_2', ('line', 3): '1_2', ('quad', 2): '2_4', ('quad', 3): '2_4', ('tetra', 3): '3_4', ('triangle', 2): '2_3', ('triangle', 3): '2_3', ('wedge', 3): '3_6'}
  format = 'meshio'
  read(mesh, omit_facets=False, **kwargs)
  read_bounding_box(ret_dim=False)
  read_data(step, filename=None, cache=None)

    Renames cell resp. vertex data with name “*:ref” to mat_id resp. node_groups

    Parameters:
      step: has no effect
      filename string, optional

        The file name to use instead of self.filename.

      cache: has no effect
    Returns:
      out dictionary

        Data loaded from file, keys are names. values are Structs with name repeated, mode (‘vertex’ or ‘cell’) and the data itself.

  read_dimension()
  write(filename, mesh, out=None, ts=None, **kwargs)

class sfepy.discrete.fem.meshio.NEUMeshIO(filename, **kwargs)
  format = 'gambit'
  read(mesh, **kwargs)
  read_dimension(ret_fd=False)
  write(filename, mesh, out=None, **kwargs)

class sfepy.discrete.fem.meshio.UserMeshIO(filename, **kwargs)

  Special MeshIO subclass that enables reading and writing a mesh using a user-supplied function.

  format = 'function'
  get_filename_trunk()
  read(mesh, *args, **kwargs)
  write(filename, mesh, *args, **kwargs)

class sfepy.discrete.fem.meshio.XYZMeshIO(filename, **kwargs)

  Trivial XYZ format working only with coordinates (in a .XYZ file) and the connectivity stored in another file with the same base name and .IEN suffix.

  format = 'xyz'
  read(mesh, omit_facets=False, **kwargs)
  read_bounding_box(ret_fd=False, ret_dim=False)
  read_dimension(ret_fd=False)
  write(filename, mesh, out=None, **kwargs)

sfepy.discrete.fem.meshio.check_format_suffix(file_format, suffix)

  Check compatibility of a mesh file format and a mesh file suffix.

sfepy.discrete.fem.meshio.convert_complex_output(out_in)

  Convert complex values in the output dictionary out_in to pairs of real and imaginary parts.

sfepy.discrete.fem.meshio.mesh_from_groups(mesh, ids, coors, ngroups, tris, mat_tris, quads, mat_quads, tetras, mat_tetras, hexas, mat_hexas, remap=None)

sfepy.discrete.fem.meshio.output_mesh_formats(mode='r')

sfepy.discrete.fem.meshio.split_conns_mat_ids(conns_in)

  Split connectivities (columns except the last ones in conns_in) from cell groups (the last columns of conns_in).

sfepy.discrete.fem.meshio.update_supported_formats(formats)

sfepy.discrete.fem.meshio.var

  alias of `XYZMeshIO`