fluidfoam.meshvisu

Visualisation of 2D OpenFoam Mesh with Python

This module provides functions to read 2D OpenFoam Mesh:

class fluidfoam.meshvisu.MeshVisu(path, box=None, plane='xy', time_name=None, verbose=True)[source]

Read OpenFoam mesh of 2D planar simulation and list all the edges contained in a box.

Args:

path: str

box: tuple of box’s dimension: ((xmin, ymin, zmin), (xmax, ymax, zmax))

(if None, includes the whole mesh)

plane: str plane in which the mesh is contained, either:

‘xy’: the xy-plane of outgoing normal z (default value)

‘xz’: the xz-plane of outgoing normal -y

‘yz’: the yz-plane of outgoing normal x

time_name: str (‘latestTime’ is supported)

verbose : True or False (default: True)

A way you might use me is:

MyMesh = fluidfoam.MeshVisu(path = ‘path_of_OpenFoam_case’)

Then a minimal example to generate and save vectorial mesh figure could be:

import matplotlib.pyplot as plt

from matplotlib.collections import LineCollection

fig, ax = plt.subplots()

ln_coll = LineCollection(MyMesh.get_all_edgesInBox())

ax.add_collection(ln_coll, autolim=True)

plt.savefig(‘./myMesh.svg’, dpi=fig.dpi, transparent = True, bbox_inches = ‘tight’)

MeshVisu.get_xlim()[source]

returns the x limits of the mesh visualization box.

Returns:

tuple of floats: (xmin, xmax)

MeshVisu.get_ylim()[source]

returns the y limits of the mesh visualization box.

Returns:

tuple of floats: (ymin, ymax)

MeshVisu.get_zlim()[source]

returns the z limits of the mesh visualization box.

Returns:

tuple of floats: (zmin, zmax)

MeshVisu.get_all_edgesInBox()[source]

return the list of all edges in box.

Eatch edge is describe by a tuple of tuples of float: ((x0, y0), (x1, y1)).

(x0, y0) being the coordonates of the fisrt point, (x1, y1), the coordinates of the second point.

This list can be given as an argument to the matplotlib LineCollection function, which allows to display a large number of segments on an image.

Returns:

list of tuples

MeshVisu.update_box(box, verbose=True)[source]

updates the mesh visualization box

Args:

box: tuple ((xmin, ymin, zmin), (xmax, ymax, zmax))

A way you might use me is:

MyMesh.update(box = ((0, 0, -1), (0.05, 0.05, 1)))

MeshVisu.get_box()[source]

return the mesh visualization box

Returns:

tuple: ((xmin, ymin, zmin), (xmax, ymax, zmax))

MeshVisu.set_box_to_mesh_size(verbose=False)[source]

Set the mesh visualization box to mesh size.

Classes

MeshVisu(path[, box, plane, time_name, verbose])

Read OpenFoam mesh of 2D planar simulation and list all the edges contained in a box.