sfepy.discrete.fem.meshio module

class sfepy.discrete.fem.meshio.ANSYSCDBMeshIO(filename, **kwargs)[source]
format = 'ansys_cdb'
static guess(filename)[source]
static make_format(format, nchar=1000)[source]
read(mesh, **kwargs)[source]
read_bounding_box()[source]
read_dimension(ret_fd=False)[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.AVSUCDMeshIO(filename, **kwargs)[source]
format = 'avs_ucd'
static guess(filename)[source]
read(mesh, **kwargs)[source]
read_dimension()[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.AbaqusMeshIO(filename, **kwargs)[source]
format = 'abaqus'
static guess(filename)[source]
read(mesh, **kwargs)[source]
read_dimension()[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.BDFMeshIO(filename, **kwargs)[source]
format = 'nastran'
static format_str(str, idx, n=8)[source]
read(mesh, **kwargs)[source]
read_dimension(ret_fd=False)[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.ComsolMeshIO(filename, **kwargs)[source]
format = 'comsol'
read(mesh, **kwargs)[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.HDF5MeshIO(filename, **kwargs)[source]
format = 'hdf5'
read(mesh=None, **kwargs)[source]
read_bounding_box(ret_fd=False, ret_dim=False)[source]
read_data(step, filename=None, cache=None)[source]
read_data_header(dname, step=None, filename=None)[source]
read_dimension(ret_fd=False)[source]
read_last_step(filename=None)[source]

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

static read_mesh_from_hdf5(filename, group=None, mesh=None)[source]

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)[source]
read_time_stepper(filename=None)[source]
read_times(filename=None)[source]

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)[source]
string = <module 'string' from '/usr/lib/python3.7/string.py'>
write(filename, mesh, out=None, ts=None, cache=None, **kwargs)[source]
static write_mesh_to_hdf5(filename, group, mesh)[source]

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.
class sfepy.discrete.fem.meshio.HypermeshAsciiMeshIO(filename, **kwargs)[source]
format = 'hmascii'
read(mesh, **kwargs)[source]
read_dimension()[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.MEDMeshIO(filename, **kwargs)[source]
format = 'med'
read(mesh, **kwargs)[source]
class sfepy.discrete.fem.meshio.MeditMeshIO(filename, **kwargs)[source]
format = 'medit'
read(mesh, omit_facets=False, **kwargs)[source]
read_bounding_box(ret_fd=False, ret_dim=False)[source]
read_dimension(ret_fd=False)[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.Mesh3DMeshIO(filename, **kwargs)[source]
format = 'mesh3d'
read(mesh, **kwargs)[source]
read_dimension()[source]
class sfepy.discrete.fem.meshio.MeshIO(filename, **kwargs)[source]

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.

The methods read_dimension(), read_bounding_box() should be implemented in subclasses, as it is often possible to get that kind of information without reading the whole mesh file.

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)

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!'
static for_format(filename, format=None, writable=False, prefix_dir=None)

Create a MeshIO instance for file filename with forced format.

Parameters:

filename : str

The name of the mesh file.

format : str

One of supported formats. If None, MeshIO.any_from_filename() is called instead.

writable : bool

If True, verify that the mesh format is writable.

prefix_dir : str

The directory name to prepend to filename.

Returns:

io : MeshIO subclass instance

The MeshIO subclass instance corresponding to the format.

format = None
get_filename_trunk()[source]
get_vector_format(dim)[source]
read(mesh, omit_facets=False, **kwargs)[source]
read_bounding_box(ret_fd=False, ret_dim=False)[source]
read_data(step, filename=None, cache=None)[source]
read_dimension(ret_fd=False)[source]
read_last_step()[source]

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

read_times(filename=None)[source]

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)[source]
write(filename, mesh, **kwargs)[source]
class sfepy.discrete.fem.meshio.Msh2MeshIO(filename, **kwargs)[source]

Used to read and write data from .msh format used by GMSH, format 2.0 is currently partially supported allowing: mesh and ElementNodeData with InterpolationScheme to be written and read.

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

Attributes

msh20header : Header containing version number.
msh_cells (dictionary) Mapping from msh to sfepy geometry.
geo2msh_type (dictionary) Mapping from sfepy to msh geometry.
format = 'msh_v2'
geo2msh_type = {'1_2': 1, '2_3': 2, '2_4': 3, '3_4': 4, '3_8': 5}
get_filename_format(filename)[source]
get_filename_wildcard(filename)[source]
load_slices = {'all': slice(0, None, None), 'first': slice(0, 1, None), 'last': slice(-1, None, None)}
msh20header = ['$MeshFormat\n', '2.0 0 8\n$EndMeshFormat\n']
msh_cells = {1: (2, 2), 2: (2, 3), 3: (2, 4), 4: (3, 4), 5: (3, 8), 6: (3, 6)}
prism2hexa = array([0, 1, 2, 2, 3, 4, 5, 5])
read(mesh, omit_facets=True, filename=None, drop_z=False, **kwargs)[source]

Reads mesh from msh v2.0 file returns it and also fills mesh parameter.

Parameters:

mesh : Mesh instance

Empty sfepy.discrete.fem.mesh.Mesh instance to fill.

omit_facets : bool

Not used.

filename : string, optional

Name of the file to use if None file from object is used.

drop_z : bool, optional, default False

Drop Z coordinate if zero and return 2D mesh, 2D meshes are stored as 3D by msh.

Returns:

mesh : Mesh instance

Computational mesh.

read_bounding_box(ret_fd=False, ret_dim=False)[source]
read_data(step=None, filename=None, cache=None, return_mesh=False, drop_z=True)[source]

Reads file or files with basename filename or self.filename, returns lists containing data. 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, if any. For stationary problems just reads one file with time 0.0 and time step 0.

Providing basename 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 varying step, if “last” read only last step of all files with the filename, if “first” reads step=0, if None reads file of filename provided or specified in object.

filename :string, optional

Basename of the files to use, if None file from object is used.

cache : object

Has no effect.

return_mesh : bool, optional, default True

Return mesh associated with data.

Returns:

mesh : sfepy.discrete.fem.mesh.Mesh

Computational mesh.

out : dictionary

The output dictionary. Its keys represent name of data, values are Struct instances with the following attributes:

  • data : array, contains ElementNodeData, shape is (len(time), n_cell, n_cell_dof).
  • time : array, contains times.
  • time_n : array, contains time step numbers.
  • scheme : Struct, interpolation scheme used in data, only one interpolation scheme is allowed. See Msh2MeshIO._write_interpolation_scheme().
read_dimension(ret_fd=True)[source]
write(filename, mesh, out=None, ts=None, **kwargs)[source]

Writes mesh and data into msh v2.0 file, handles dg_cell_dofs data from DGField if provided in out.

Parameters:

filename : string

Path to file.

mesh : sfepy.discrete.fem.mesh.Mesh

Computational mesh to write.

out : dictionary, optional

Dictionary containing data to write, expected to be in format generated by DGField.create_output(), key is name of data, value is Struct containing:

  • mode : string, so far only dg_cell_dofs, representing modal data in cells is supported.
  • data : array, DOFs as defined in DG Field.
  • interpolation_scheme : Struct, interpolation scheme used in data, only one interpolation scheme is allowed. See Msh2MeshIO._write_interpolation_scheme().

ts : sfepy.solvers.ts.TimeStepper instance, optional

Provides data to write time step.

class sfepy.discrete.fem.meshio.NEUMeshIO(filename, **kwargs)[source]
format = 'gambit'
read(mesh, **kwargs)[source]
read_dimension(ret_fd=False)[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.TetgenMeshIO(filename, **kwargs)[source]
format = 'tetgen'
static getele(fele)[source]

Reads t.1.ele, returns a list of elements.

Example:

>>> elements, regions = self.getele("t.1.ele")
>>> elements
[(20, 154, 122, 258), (86, 186, 134, 238), (15, 309, 170, 310), (146,
229, 145, 285), (206, 207, 125, 211), (99, 193, 39, 194), (185, 197,
158, 225), (53, 76, 74, 6), (19, 138, 129, 313), (23, 60, 47, 96),
(119, 321, 1, 329), (188, 296, 122, 322), (30, 255, 177, 256), ...]
>>> regions
{100: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, ...],
...}
static getnodes(fnods)[source]

Reads t.1.nodes, returns a list of nodes.

Example:

>>> self.getnodes("t.1.node")
[(0.0, 0.0, 0.0), (4.0, 0.0, 0.0), (0.0, 4.0, 0.0), (-4.0, 0.0, 0.0),
(0.0, 0.0, 4.0), (0.0, -4.0, 0.0), (0.0, -0.0, -4.0), (-2.0, 0.0,
-2.0), (-2.0, 2.0, 0.0), (0.0, 2.0, -2.0), (0.0, -2.0, -2.0), (2.0,
0.0, -2.0), (2.0, 2.0, 0.0), ... ]
read(mesh, **kwargs)[source]
read_bounding_box()[source]
read_dimension()[source]
write(filename, mesh, out=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.UserMeshIO(filename, **kwargs)[source]

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

format = 'function'
get_filename_trunk()[source]
read(mesh, *args, **kwargs)[source]
write(filename, mesh, *args, **kwargs)[source]
class sfepy.discrete.fem.meshio.VTKMeshIO(filename, **kwargs)[source]
format = 'vtk'
get_dimension(coors)[source]
read(mesh, **kwargs)[source]
read_bounding_box(ret_fd=False, ret_dim=False)[source]
read_coors(ret_fd=False)[source]
read_data(step, filename=None, cache=None)[source]
read_dimension(ret_fd=False)[source]
write(filename, mesh, out=None, ts=None, **kwargs)[source]
class sfepy.discrete.fem.meshio.XYZMeshIO(filename, **kwargs)[source]

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)[source]
read_bounding_box(ret_fd=False, ret_dim=False)[source]
read_dimension(ret_fd=False)[source]
write(filename, mesh, out=None, **kwargs)[source]
sfepy.discrete.fem.meshio.convert_complex_output(out_in)[source]

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

sfepy.discrete.fem.meshio.guess_format(filename, ext, formats, io_table)[source]

Guess the format of filename, candidates are in formats.

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)[source]
sfepy.discrete.fem.meshio.output_mesh_formats(mode='r')[source]
sfepy.discrete.fem.meshio.split_conns_mat_ids(conns_in)[source]

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

sfepy.discrete.fem.meshio.var(filename, ext, formats, io_table)

Guess the format of filename, candidates are in formats.