porepy.viz.exporter module

Module for exporting to vtu for (e.g. ParaView) visualization using the vtk module.

The Exporter class contains methods for exporting a single grid or mixed-dimensional with associated data to the vtu format. For mixed-dimensional grids, one vtu file is printed for each grid. For transient simulations with multiple time steps, a single pvd file takes care of the ordering of all printed vtu files.

class Exporter(grid, file_name, folder_name=None, **kwargs)[source]

Bases: object

Class for exporting data to vtu files.

The Exporter allows for various way to express which state variables, on which grids, and which extra data should be exported. A thorough demonstration is available as a dedicated tutorial. Check out tutorials/exporter.ipynb.

In general, pvd files gather data exported in separate files, including data on differently dimensioned grids, constant data, and finally time steps.

In the case of different keywords, change the file name with “change_name”.

NOTE: the following names are reserved for constant data exporting and should not be used otherwise (otherwise data is overwritten): grid_dim, is_mortar, mortar_side, cell_id, subdomain_id, interface_id.

Examples

# Here, merely a brief demonstration of the use of Exporter is presented.

# If you need to export the state with key “pressure” on a single grid: save = Exporter(g, “solution”, folder_name=”results”) save.write_vtu([“pressure”])

# In a time loop, if you need to export states with keys “pressure” and # “displacement” stored in a mixed-dimensional grid, do:

save = Exporter(mdg, “solution”, folder_name=”results”) while time:

save.write_vtu([“pressure”, “displacement”], time_step=i)

save.write_pvd(times)

# where times is a list of actual times (not time steps), associated # to the previously exported time steps. If times is not provided # the time steps will be used instead.

Parameters
  • grid (Union[pp.Grid, pp.MixedDimensionalGrid]) –

  • file_name (str) –

  • folder_name (Optional[str]) –

add_constant_data(data=None)[source]

Collect user-defined constant-in-time data, associated with grids, and to be exported to separate files instead of the main files.

In principle, constant data is not different from standard output data. It is merely printed to another file and just when any constant data is updated (via updates of the grid, or the use of this routine). Hence, the same input formats are allowed as for the usual field data, which is varying in time. As part of the routine, the data is converted to the same unified format.

Parameters

data (Union[DataInput, list[DataInput]], optional) –

subdomain and interface data, prescribed through strings, or tuples of subdomains/interfaces, keys and values. If not provided, only geometrical information is exported.

NOTE: The user has to make sure that each unique key has associated data values for all or no grids of each specific dimension.

Return type

None

write_pvd(times=None, file_extension=None)[source]

Interface function to export in PVD file the time loop information. The user should open only this file in ParaView.

We assume that the VTU associated files have the same name, and that. the VTU associated files are in the working directory.

Parameters
  • times (np.ndarray, optional) – array of actual times to be exported. These will be the times associated with individual time steps in, say, ParaView. By default, the times will be associated with the order in which the time steps were exported. This can be overridden by the file_extension argument. If no times are provided, the exported time steps are used.

  • file_extension (np.array-like, optional) – End of file names used in the export of individual time steps, see self.write_vtu(). If provided, it should have the same length as time. If not provided, the file names will be picked from those used when writing individual time steps.

Return type

None

write_vtu(data=None, time_dependent=False, time_step=None, grid=None)[source]

Interface function to export the grid and additional data with meshio.

In 1d the cells are represented as lines, 2d the cells as polygon or triangle/quad, while in 3d as polyhedra/tetrahedra/hexahedra. In all the dimensions the geometry of the mesh needs to be computed.

Parameters
  • data (Union[DataInput, list[DataInput]], optional) –

    subdomain and interface data, prescribed through strings, or tuples of subdomains/interfaces, keys and values. If not provided only geometrical infos are exported.

    NOTE: The user has to make sure that each unique key has associated data values for all or no grids of each specific dimension.

  • time_dependent (boolean) – If False (default), file names will not be appended with an index that marks the time step. Can be overwritten by giving a value to time_step; if not, the file names will subsequently be ending with 1, 2, etc.

  • time_step (int, optional) – will be used as appendix to define the file corresponding to this specific time step.

  • grid (Union[pp.Grid, pp.MixedDimensionalGrid], optional) – subdomain or mixed-dimensional grid if it is not fixed and should be updated.

Raises

ValueError if a grid is provided as argument although the exporter – has been instructed that the grid is fixed

Return type

None

class Field(name, values)

Bases: tuple

name

Alias for field number 0

values

Alias for field number 1

class Meshio_Geom(pts, connectivity, cell_ids)

Bases: tuple

cell_ids

Alias for field number 2

connectivity

Alias for field number 1

pts

Alias for field number 0