Utilities#

The EasyFEA.Utilities module provides essential tools for post-processing.

In the simulation workflow, Utilities is the final step: once simu.Solve() has run, these tools visualize results, export to external formats, and manage files. Display and PyVista cover interactive visualization; Paraview, GLTF, and USD handle external export.

Display

Module containing functions used to display simulations and meshes with matplotlib (https://matplotlib.org/).

Folder

Module containing functions used to facilitate folder and file creation using (os).

MeshIO

Module providing an interface with meshio (https://pypi.org/project/meshio/).

Paraview

This module allows you to save a simulation's results on Paraview (https://www.paraview.org/).

PyVista

Module providing an interface with PyVista (https://docs.pyvista.org/version/stable/).

Vizir

Module providing functions used to save FEM-solutions for vizir (https://pyamg.saclay.inria.fr/vizir4.html).

USD

Module providing an interface with Universal Scene Description Format (USD) using usd-core (https://pypi.org/project/usd-core/).

GLTF

Module providing an interface with Graphics Library Transmission Format (GLTF) using pygltflib (https://pypi.org/project/pygltflib/).

Utilities API#

class EasyFEA.Utilities.Observable[source]#

Bases: object

The observable interface

_Add_observer(observer) None[source]#

Add observer.

_Notify(event: str) None[source]#

Notifies the observers.

_Remove_observer(observer) None[source]#

Remove the observer.

property observers[source]#

Oberservers looking for the observable obect

class EasyFEA.Utilities.Tic[source]#

Bases: object

static Clear() None[source]#

Deletes history.

static Get_Remaining_Time(i: int, N: int, time: float) str[source]#

Returns remaining time asssuming that time is in s.

static Get_time_unity(time: float) tuple[float, str][source]#

Returns time with unity

static Resume(verbosity=True) str[source]#

Returns the TicTac summary

static nTic() int[source]#
Plot_History(details=False) None[source]#

Plots history.

Parameters:
  • folder (str, optional) – save folder, by default “”

  • details (bool, optional) – History details, by default True

Tac(category='', text='', verbosity=False) float[source]#

Returns the time elapsed since the last Tic or Tac.

class EasyFEA.Utilities._IObserver[source]#

Bases: ABC

The observer interface

abstractmethod _Update(
observable: Observable,
event: str,
) None[source]#

Receive an update/event from an observable object (observer pattern).

EasyFEA.Utilities._CheckIsInIntervalcc(value: int | float | Iterable, inf, sup) None[source]#

Checks whether the value is in ]inf, sup[

EasyFEA.Utilities._CheckIsInIntervaloo(value: int | float | Iterable, inf, sup) None[source]#

Checks whether the value is in [inf, sup]

EasyFEA.Utilities._CheckIsNegative(value: int | float | Iterable) None[source]#

Checks whether the value is negative

EasyFEA.Utilities._CheckIsPositive(value: int | float | Collection[int | float]) None[source]#

Checks whether the value is positive

Module containing functions used to display simulations and meshes with matplotlib (https://matplotlib.org/).

EasyFEA.Utilities.Display.Clear() None[source]#

Clears the terminal.

EasyFEA.Utilities.Display.Create_requires_decorator(*modules: str, libraries: list[str] = None)[source]#

Creates a decorator that checks if modules are available before executing a function.

Returns:

A decorator that raises an ImportError if the modules are not available.

Return type:

function

EasyFEA.Utilities.Display.Init_Axes(
dim: int = 2,
elev=105,
azim=-90,
) Axes | Axes3D[source]#

Initialize 2d or 3d axes.

EasyFEA.Utilities.Display.Movie_Simu(
simu,
result: str,
folder: str,
filename='video.gif',
N: int = 200,
deformFactor=0.0,
coef=1.0,
nodeValues=True,
plotMesh=False,
edgecolor='black',
fps=30,
**kwargs,
) None[source]#

Generates a movie from a simulation’s result.

Parameters:
  • simu (_Simu) – simulation

  • result (str) – result that you want to plot

  • folder (str) – folder where you want to save the video

  • filename (str, optional) – filename of the video with the extension (gif, mp4), by default ‘video.gif’

  • N (int, optional) – Maximal number of iterations displayed, by default 200

  • deformFactor (int, optional) – deformation factor, by default 0.0

  • coef (float, optional) – Coef to apply to the solution, by default 1.0

  • nodeValues (bool, optional) – Displays result to nodes otherwise displays it to elements, by default True

  • plotMesh (bool, optional) – Plot the mesh, by default False

  • edgecolor (str, optional) – Color used to plot the mesh, by default ‘black’

  • fps (int, optional) – frames per second, by default 30

EasyFEA.Utilities.Display.Movie_func(
func: Callable[[Figure, int], None],
fig: Figure | Any,
N: int,
folder: str,
filename='video.gif',
fps=30,
dpi=200,
show=True,
)[source]#

Generates the movie for the specified function.

This function will peform a loop in range(N).

Parameters:
  • func (Callable[[plt.Figure, int], None]) –

    The function that will use in first argument the plotter and in second argument the iter step such that.

    def func(fig, i) -> None

  • fig (Figure) – Figure used to make the video

  • N (int) – number of iteration

  • folder (str) – folder where you want to save the video

  • filename (str, optional) – filename of the video with the extension (eg. .gif, .mp4), by default ‘video.gif’

  • fps (int, optional) – frames per second, by default 30

  • dpi (int, optional) – Dots per Inch, by default 200

  • show (bool, optional) – shows the movie, by default True

EasyFEA.Utilities.Display.MyPrint(
text: str,
color='cyan',
bold=False,
italic=False,
underLine=False,
end: str = '',
) str[source]#
EasyFEA.Utilities.Display.MyPrintError(text: str) str[source]#
EasyFEA.Utilities.Display.Plot_BoundaryConditions(
simu,
ax: Axes | Axes3D | None = None,
) Axes | Axes3D[source]#

Plots simulation’s boundary conditions.

Parameters:
  • simu (_Simu) – simulation

  • ax (Axes, optional) – Axis to use, default None

Return type:

Axes

Examples

>>> import matplotlib.pyplot as plt
>>> Display.Plot_BoundaryConditions(simu)
>>> plt.show()

Combined with mesh overlay:

>>> ax = Display.Plot_Mesh(simu)
>>> Display.Plot_BoundaryConditions(simu, ax=ax)
>>> plt.show()
EasyFEA.Utilities.Display.Plot_Elements(
obj,
nodes=[],
dimElem: int | None = None,
showId=False,
alpha=1.0,
color='red',
edgecolor='black',
ax: Axes | Axes3D | None = None,
) Axes | Axes3D[source]#

Plots the mesh’s elements corresponding to the given nodes.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – object containing the mesh

  • nodes (list, optional) – node numbers, by default []

  • dimElem (int, optional) – dimension of elements, by default None

  • showId (bool, optional) – display numbers, by default False

  • alpha (float, optional) – transparency of faces, by default 1.0

  • color (str, optional) – color used to display faces, by default ‘red

  • edgecolor (str, optional) – color used to display segments, by default ‘black’

  • ax (Axes, optional) – Axis to use, default None

Return type:

Axes

EasyFEA.Utilities.Display.Plot_Energy(
simu: _Simu,
load: _types.FloatArray = array([], dtype=float64),
displacement: _types.FloatArray = array([], dtype=float64),
plotSolMax: bool = True,
N: int = 200,
folder: str = '',
) None[source]#

Plots the energy for each iteration.

Parameters:
  • simu (_Simu) – simulation

  • load (_types.FloatArray, optional) – array of values, by default np.array([])

  • displacement (_types.FloatArray, optional) – array of values, by default np.array([])

  • plotSolMax (bool, optional) – displays the evolution of the maximul solution over iterations. (max damage for damage simulation), by default True

  • N (int, optional) – number of iterations for which energy will be calculated, by default 200

  • folder (str, optional) – save folder, by default “”

EasyFEA.Utilities.Display.Plot_Iter_Summary(simu, folder='', iterMin=None, iterMax=None) None[source]#

Plots a summary of iterations between iterMin and iterMax.

Parameters:
  • simu (_Simu) – Simulation

  • folder (str, optional) – backup folder, by default “”

  • iterMin (int, optional) – lower bound, by default None

  • iterMax (int, optional) – upper bound, by default None

EasyFEA.Utilities.Display.Plot_Mesh(
obj: '_Simu' | 'Mesh',
deformFactor: float = 0.0,
alpha: float = 1.0,
facecolors: str = 'c',
edgecolor: str = 'black',
lw: float = 0.5,
ax: Axes | None = None,
folder: str = '',
title: str = '',
) Axes[source]#

Plots the mesh.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – object containing the mesh

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • alpha (float, optional) – face transparency, default 1.0

  • facecolors (str, optional) – facecolors, default ‘c’ (cyan)

  • edgecolor (str, optional) – edgecolor, default ‘black’

  • lw (float, optional) – line width, default 0.5

  • ax (Axes, optional) – Axis to use, default None

  • folder (str, optional) – save folder, default “”.

  • title (str, optional) – figure title, by default “”

Return type:

Axes

Examples

Undeformed mesh:

>>> import matplotlib.pyplot as plt
>>> Display.Plot_Mesh(simu)
>>> plt.show()

Deformed mesh, semi-transparent faces:

>>> Display.Plot_Mesh(simu, deformFactor=50, facecolors="white", alpha=0.5)
>>> plt.show()
EasyFEA.Utilities.Display.Plot_Nodes(
obj,
nodes: ndarray[tuple[Any, ...], dtype[int64]] | None = None,
showId=False,
marker='.',
color='red',
ax: Axes | Axes3D | None = None,
) Axes | Axes3D[source]#

Plots the mesh’s nodes.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – object containing the mesh

  • nodes (_types.IntArray, optional) – nodes to display, default []

  • showId (bool, optional) – display numbers, default False

  • marker (str, optional) – marker type (matplotlib.markers), default ‘.’

  • color (str, optional) – color, default ‘red’

  • ax (Axes, optional) – Axis to use, default None, default None

Return type:

Axes

EasyFEA.Utilities.Display.Plot_Result(
obj: '_Simu' | 'Mesh',
result: str | _types.FloatArray,
deformFactor: _types.Number = 0.0,
coef: _types.Number = 1.0,
nodeValues: bool = True,
plotMesh: bool = False,
edgecolor: str = 'black',
title: str = '',
cmap: str = 'jet',
ncolors=256,
clim=(None, None),
colorbarIsClose=False,
colorbarLabel='',
ax: Axes | None = None,
folder: str = '',
filename: str = '',
) Axes[source]#

Plots a simulation’s result.

Parameters:
  • obj (_Simu | Mesh) – simulation

  • result (str | _types.FloatArray) – Result you want to display. Must be included in simu.Get_Results() or be a numpy array of size (Nn, Ne).

  • deformFactor (float, optional) – factor used to display the deformed solution (0 means no deformations), default 0.0

  • coef (float, optional) – coef to apply to the solution, by default 1.0

  • nodeValues (bool, optional) – displays result to nodes otherwise displays it to elements, by default True

  • plotMesh (bool, optional) – displays mesh, by default False

  • edgecolor (str, optional) – Color used to plot the mesh, by default ‘black’

  • title (str, optional) – figure title, by default “”

  • cmap (str, optional) –

    the color map used near the figure, by default “jet”

    [“jet”, “seismic”, “binary”, “viridis”] -> https://matplotlib.org/stable/tutorials/colors/colormaps.html

  • ncolors (int, optional) – number of colors for colorbar, by default 21

  • clim (sequence[float], optional) – Two item color bar range for scalars. Defaults to minimum and maximum of scalars array. Example: (-1, 2), by default (None, None)

  • colorbarIsClose (bool, optional) – color bar is displayed close to the figure, by default False

  • colorbarLabel (str, optional) – colorbar label, by default “”

  • ax (axis, optional) – Axis to use, default None, by default None

  • folder (str, optional) – save folder, by default “”.

  • filename (str, optional) – filename, by default “”

Return type:

_types.Axis

Examples

Von Mises stress in MPa (elastic simulation):

>>> import matplotlib.pyplot as plt
>>> Display.Plot_Result(simu, "Svm", coef=1e-6, colorbarLabel="σ_vm [MPa]")
>>> plt.show()

With deformed mesh:

>>> Display.Plot_Result(simu, "displacement_norm", deformFactor=100, cmap="viridis")
>>> plt.show()

Temperature field at a specific iteration (thermal simulation):

>>> Display.Plot_Result(simu, "thermal", iter=5, colorbarLabel="T [°C]")
>>> plt.show()
EasyFEA.Utilities.Display.Plot_Tags(
obj,
showId=True,
folder='',
alpha=1.0,
useColorCycler=False,
ax: Axes | Axes3D | None = None,
) Axes | Axes3D[source]#

Plots the mesh’s elements tags (from 2d elements to points) but do not plot the 3d elements tags.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – object containing the mesh

  • showId (bool, optional) – shows tags, by default True

  • folder (str, optional) – saves folder, by default “”

  • alpha (float, optional) – transparency, by default 1.0

  • useColorCycler (bool, optional) – whether to use color cycler, by default False

  • ax (Axes, optional) – Axis to use, default None

Return type:

Axes

EasyFEA.Utilities.Display.Save_fig(
folder: str,
filename: str,
transparent=False,
extension='pdf',
dpi='figure',
) None[source]#

Saves the current figure.

Parameters:
  • folder (str) – save folder

  • filename (str) – filename

  • transparent (bool, optional) – transparent background, by default False

  • extension (str, optional) – extension, by default ‘pdf’, [pdf, png]

  • dpi (str, optional) – dpi, by default ‘figure’

EasyFEA.Utilities.Display.Section(text: str, verbosity=True) str[source]#

Creates a new section in the terminal.

EasyFEA.Utilities.Display._Axis_equal_3D(
ax: Axes3D,
coord: ndarray[tuple[Any, ...], dtype[floating]],
) None[source]#

Changes axis size for 3D display.

Center the part and make the axes the right size.

Parameters:
  • ax (Axes) – Axes in which figure will be created

  • coord (_types.FloatArray) – mesh coordinates

EasyFEA.Utilities.Display._Get_colors_for_values(
values: ndarray,
vMin: float = None,
vMax: float = None,
cmap: str = 'jet',
) ndarray[source]#

Generates RGB colors for scalar values using a matplotlib colormap.

Parameters:
  • values (np.ndarray) – 1D array of scalar values to be mapped to colors

  • vMin (float, optional) – Minimum value for normalization. If None, uses the minimum of values.

  • vMax (float, optional) – Maximum value for normalization. If None, uses the maximum of values.

  • cmap (str, optional) –

    the color map used near the figure, by default “jet”

    [“jet”, “seismic”, “binary”, “viridis”] -> https://matplotlib.org/stable/tutorials/colors/colormaps.html

Returns:

Array of RGB colors with shape (N, 3) and values in range [0, 1]

Return type:

np.ndarray

Notes

The function normalizes input values to [0, 1] and maps them through the specified colormap. The alpha channel is discarded, returning only RGB components.

EasyFEA.Utilities.Display._Get_list_surfaces(mesh, dimElem: int) list[list[int]][source]#

Returns a list of surfaces for each element group of dimension dimElem.

Surfaces are a list of index used to construct/plot a surface.

You can go check their values for each groupElem in EasyFEA/fem/elems/ folder

EasyFEA.Utilities.Display._Get_values(
simu: _Simu | None,
mesh: Mesh,
result: str | ndarray[tuple[Any, ...], dtype[Any]],
nodeValues=True,
) ndarray[tuple[Any, ...], dtype[Any]][source]#

Retrieves values and ensures compatibility with the mesh.

Parameters:
  • simu (Union[_Simu, None]) – Simulation (can be set to None).

  • mesh (Mesh) – Mesh used to display the result.

  • result (Union[str, _types.AnyArray]) – Result you want to display. Must be included in simu.Get_Results() or be a numpy array of size (Nn, Ne).

  • nodeValues (bool, optional) – Displays result on nodes; otherwise, displays it on elements. Default is True.

Returns:

values

Return type:

_types.AnyArray

EasyFEA.Utilities.Display._Init_obj(
obj: _Simu | Mesh | _GroupElem,
deformFactor: float = 0.0,
) tuple[_Simu | None, Mesh, ndarray[tuple[Any, ...], dtype[floating]], int][source]#
EasyFEA.Utilities.Display._Init_obj(obj: _Simu, deformFactor: float = 0.0)
EasyFEA.Utilities.Display._Init_obj(obj: Mesh, deformFactor: float = 0.0)
EasyFEA.Utilities.Display._Init_obj(obj: _GroupElem, deformFactor: float = 0.0)

Returns (simu, mesh, coord, inDim) from an ojbect that could be either a _Simu, a Mesh or a _GroupElem object.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – An object that contain the mesh

  • deformFactor (float, optional) – the factor used to deform the mesh, by default 0.0

Returns:

(simu, mesh, coord, inDim)

Return type:

tuple[_Simu|None, Mesh, ndarray, int]

EasyFEA.Utilities.Display._Plot_obj(
obj: '_Simu' | 'Mesh' | '_GroupElem',
alpha: float = 1.0,
color: str = 'gray',
ax: Axes | None = None,
) Axes[source]#

Plots the mesh.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – object containing the mesh

  • alpha (float, optional) – face transparency, default 1.0

  • color (str, optional) – color, default ‘gray’

  • ax (Axes, optional) – Axis to use, default None

Return type:

Axes

EasyFEA.Utilities.Display._Remove_colorbar(
ax: Axes | Axes3D,
) None[source]#

Removes the current colorbar from the axis.

EasyFEA.Utilities.Display._Save_colorbar(
vMin: float,
vMax: float,
folder: str,
filename='colorbar',
cmap='jet',
orientation='vertical',
label='',
)[source]#

Generates and save colorbar.

Parameters:
  • vMin (float, optional) – Minimum value for normalization. If None, uses the minimum of values.

  • vMax (float, optional) – Maximum value for normalization. If None, uses the maximum of values.

  • folder (str, optional) – save folder, by default “”.

  • filename (str, optional) – filename, by default “colorbar”

  • cmap (str, optional) –

    the color map used near the figure, by default “jet”

    [“jet”, “seismic”, “binary”, “viridis”] -> https://matplotlib.org/stable/tutorials/colors/colormaps.html

  • orientation (str, optional) – orientation, by default “vertical”

  • label (str, optional) – label, by default “”

EasyFEA.Utilities.Display.rank0_only(func)[source]#

Decorator: only rank 0 executes the function. Non-root ranks return None.

Use on file-output and visualization functions (Display, GLTF, USD, Vizir) to prevent non-root MPI ranks from writing files or rendering plots.

EasyFEA.Utilities.Display.requires_matplotlib(func)[source]#

Module containing functions used to facilitate folder and file creation using (os).

EasyFEA.Utilities.Folder.Dir(path: str = None, n: int = 1) str[source]#

Returns the directory located n parent levels above the given path.

EasyFEA.Utilities.Folder.Exists(path: str) bool[source]#

Test whether a path exists. Returns False for broken symbolic links

EasyFEA.Utilities.Folder.Join(*args: str, mkdir=False) str[source]#

Joins two or more pathname components and create (or not) the path.

EasyFEA.Utilities.Folder.Rank_Dir(path: str) str[source]#
EasyFEA.Utilities.Folder.Results_Dir() str[source]#

Provides the directory path where results should be stored, relative to the calling Python script: <script_directory>/results/<script_name>.

Warning

This function does not work in a Jupyter notebook!

Module providing an interface with meshio (https://pypi.org/project/meshio/).

class EasyFEA.Utilities.MeshIO.VTKCellType(value)[source]#

Bases: int, Enum

BEZIER_CURVE = 75#
BEZIER_HEXAHEDRON = 79#
BEZIER_PYRAMID = 81#
BEZIER_QUADRILATERAL = 77#
BEZIER_TETRAHEDRON = 78#
BEZIER_TRIANGLE = 76#
BEZIER_WEDGE = 80#
BIQUADRATIC_QUAD = 28#
BIQUADRATIC_QUADRATIC_HEXAHEDRON = 33#
BIQUADRATIC_QUADRATIC_WEDGE = 32#
BIQUADRATIC_TRIANGLE = 34#
CONVEX_POINT_SET = 41#
CUBIC_LINE = 35#
EMPTY_CELL = 0#
HEXAGONAL_PRISM = 16#
HEXAHEDRON = 12#
HIGHER_ORDER_EDGE = 60#
HIGHER_ORDER_HEXAHEDRON = 67#
HIGHER_ORDER_POLYGON = 63#
HIGHER_ORDER_PYRAMID = 66#
HIGHER_ORDER_QUAD = 62#
HIGHER_ORDER_TETRAHEDRON = 64#
HIGHER_ORDER_TRIANGLE = 61#
HIGHER_ORDER_WEDGE = 65#
LAGRANGE_CURVE = 68#
LAGRANGE_HEXAHEDRON = 72#
LAGRANGE_PYRAMID = 74#
LAGRANGE_QUADRILATERAL = 70#
LAGRANGE_TETRAHEDRON = 71#
LAGRANGE_TRIANGLE = 69#
LAGRANGE_WEDGE = 73#
LINE = 3#
NUMBER_OF_CELL_TYPES = 82#
PARAMETRIC_CURVE = 51#
PARAMETRIC_HEX_REGION = 56#
PARAMETRIC_QUAD_SURFACE = 54#
PARAMETRIC_SURFACE = 52#
PARAMETRIC_TETRA_REGION = 55#
PARAMETRIC_TRI_SURFACE = 53#
PENTAGONAL_PRISM = 15#
PIXEL = 8#
POLYGON = 7#
POLYHEDRON = 42#
POLY_LINE = 4#
POLY_VERTEX = 2#
PYRAMID = 14#
QUAD = 9#
QUADRATIC_EDGE = 21#
QUADRATIC_HEXAHEDRON = 25#
QUADRATIC_LINEAR_QUAD = 30#
QUADRATIC_LINEAR_WEDGE = 31#
QUADRATIC_POLYGON = 36#
QUADRATIC_PYRAMID = 27#
QUADRATIC_QUAD = 23#
QUADRATIC_TETRA = 24#
QUADRATIC_TRIANGLE = 22#
QUADRATIC_WEDGE = 26#
TETRA = 10#
TRIANGLE = 5#
TRIANGLE_STRIP = 6#
TRIQUADRATIC_HEXAHEDRON = 29#
TRIQUADRATIC_PYRAMID = 37#
VERTEX = 1#
VOXEL = 11#
WEDGE = 13#
EasyFEA.Utilities.MeshIO.Create_requires_decorator(*modules: str, libraries: list[str] = None)[source]#

Creates a decorator that checks if modules are available before executing a function.

Returns:

A decorator that raises an ImportError if the modules are not available.

Return type:

function

EasyFEA.Utilities.MeshIO.EasyFEA_to_Ensight(mesh: Mesh, folder: str, name: str) str[source]#

Converts EasyFEA mesh to Gmsh format.

Parameters:
  • mesh (Mesh) – EasyFEA mesh object.

  • folder (str) – Directory to save the Ensight .geo file.

  • name (str) – The name of the Ensight .geo file, without the extension.

Returns:

Path to the saved Ensight .geo file.

Return type:

str

EasyFEA.Utilities.MeshIO.EasyFEA_to_Gmsh(
mesh: Mesh,
folder: str,
name: str,
useBinary=False,
) str[source]#

Converts EasyFEA mesh to Gmsh format.

Parameters:
  • mesh (Mesh) – EasyFEA mesh object.

  • folder (str) – Directory to save the Gmsh file.

  • name (str) – The name of the Gmsh file, without the extension.

  • useBinary (bool, optional) – Whether to save as binary (default is False).

Returns:

Path to the saved Gmsh file.

Return type:

str

Examples

>>> from EasyFEA.Utilities import MeshIO
>>> MeshIO.EasyFEA_to_Gmsh(mesh, folder="results", name="my_mesh")
EasyFEA.Utilities.MeshIO.EasyFEA_to_Medit(
mesh: Mesh,
folder: str,
name: str,
dict_tags_converter: dict[str, int] = {},
useBinary=False,
) str[source]#

Converts EasyFEA mesh to Medit format.

Parameters:
  • mesh (Mesh) – EasyFEA mesh object.

  • folder (str) – Directory to save the Medit file.

  • name (str) – The name of the Medit file, without the extension.

  • dict_tags_converter (dict[str, int], optional) – Dictionary converting string tags to integers (default is {}).

  • useBinary (bool, optional) – Whether to save as binary (default is False).

Returns:

Path to the saved Medit file.

Return type:

str

Examples

>>> from EasyFEA.Utilities import MeshIO
>>> MeshIO.EasyFEA_to_Medit(mesh, folder="results", name="my_mesh")
EasyFEA.Utilities.MeshIO.EasyFEA_to_PyVista(
mesh: Mesh,
coord: ndarray[tuple[Any, ...], dtype[floating]] | None = None,
useAllElements=True,
) UnstructuredGrid[source]#

Converts EasyFEA mesh to PyVista Multiblock format.

Parameters:
  • mesh (Mesh) – EasyFEA mesh object.

  • coord (_types.FloatArray, optional) – mesh coordinates, by default None

  • useAllElements (bool, optional) – Use all group of elements, by default True Uses only the main group of elements if set to False.

Returns:

pyvista mesh

Return type:

pv.UnstructuredGrid

Examples

Convert and inspect the PyVista mesh:

>>> from EasyFEA.Utilities import MeshIO
>>> pvMesh = MeshIO.EasyFEA_to_PyVista(mesh)
>>> print(pvMesh)
EasyFEA.Utilities.MeshIO.Ensight_to_EasyFEA(geoFile: str) Mesh[source]#

Converts Ensight mesh to EasyFEA format.

Parameters:

geoFile (str) – Path to the Ensight geo file.

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

EasyFEA.Utilities.MeshIO.Gmsh_to_EasyFEA(gmshMesh: str) Mesh[source]#

Converts Gmsh mesh to EasyFEA format.

Parameters:

gmshMesh (str) – Path to the Gmsh mesh file.

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

Examples

>>> from EasyFEA.Utilities import MeshIO
>>> mesh = MeshIO.Gmsh_to_EasyFEA("mesh.msh")
EasyFEA.Utilities.MeshIO.Medit_to_EasyFEA(meditMesh: str) Mesh[source]#

Converts Medit mesh to EasyFEA format.

Parameters:

meditMesh (str) – Path to the Medit mesh file.

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

Examples

>>> from EasyFEA.Utilities import MeshIO
>>> mesh = MeshIO.Medit_to_EasyFEA("mesh.mesh")
EasyFEA.Utilities.MeshIO.PyVista_to_EasyFEA(
pyVistaMesh: UnstructuredGrid | MultiBlock,
) Mesh[source]#

Converts PyVista mesh to EasyFEA format.

Parameters:

pyVistaMesh (pv.UnstructuredGrid | pv.MultiBlock) – PyVista mesh object.

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

EasyFEA.Utilities.MeshIO.Surface_reconstruction(mesh: Mesh) Mesh[source]#

Reconstructs the missing surfaces in a mesh.

EasyFEA.Utilities.MeshIO._EasyFEA_to_Meshio(
mesh: Mesh,
dict_tags_converter: dict[Any, int] = {},
cellType: str = 'tags',
) Mesh[source]#

Converts EasyFEA mesh to meshio format.

Parameters:
  • mesh (Mesh) – EasyFEA mesh object.

  • dict_tags_converter (dict[Any, int], optional) – Dictionary converting tags to integers, by default {}

  • cellType (str, optional) – cell type to acces tags, by default “tags”

Returns:

Converted meshio mesh object.

Return type:

meshio.Mesh

EasyFEA.Utilities.MeshIO._Ensight_to_Meshio(geoFile: str) Mesh[source]#

Converts Ensight mesh to Meshio format.

Parameters:

geoFile (str) – Path to the Ensight geo file.

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

EasyFEA.Utilities.MeshIO._Ensight_to_PyVista(geoFile: str) MultiBlock[source]#

Converts Ensight mesh to PyVista format.

Parameters:

geoFile (str) – Path to the Ensight geo file.

Returns:

Converted PyVista mesh object.

Return type:

Mesh

EasyFEA.Utilities.MeshIO._Get_pyvista_cell(
groupElem: _GroupElem,
) tuple[VTKCellType, ndarray[tuple[Any, ...], dtype[int64]]][source]#
EasyFEA.Utilities.MeshIO._GroupElem_to_PyVista(
groupElem: _GroupElem,
elements: ndarray[tuple[Any, ...], dtype[int64]] | None = None,
) UnstructuredGrid[source]#

Converts EasyFEA mesh to PyVista Multiblock format.

Parameters:
  • mesh (Mesh) – EasyFEA mesh object.

  • elements (_types.IntArray, optional) – mesh coordinates, by default None

Returns:

pyvista mesh

Return type:

pv.UnstructuredGrid

EasyFEA.Utilities.MeshIO._Meshio_to_EasyFEA(meshioMesh: Mesh) Mesh[source]#

Converts meshio mesh to EasyFEA format.

Parameters:

meshioMesh (meshio.Mesh) – Meshio mesh object.

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

EasyFEA.Utilities.MeshIO._Set_Tags(
mesh: Mesh,
dict_tags: dict[str, ndarray[tuple[Any, ...], dtype[int64]]],
)[source]#

Set tags for nodes and elements in the EasyFEA mesh.

Parameters:
  • mesh (Mesh) – EasyFEA mesh object.

  • dict_tags (dict[str, _types.IntArray]) – Dictionary of tags for elements.

EasyFEA.Utilities.MeshIO.requires_meshio(func)[source]#
EasyFEA.Utilities.MeshIO.requires_pyvista(func)[source]#
EasyFEA.Utilities.MeshIO.DICT_ELEMTYPE_TO_ENSIGHT: dict[ElemType, str] = {ElemType.HEXA20: 'hexa20', ElemType.HEXA8: 'hexa8', ElemType.POINT: 'point', ElemType.PRISM15: 'wedge15', ElemType.PRISM6: 'wedge6', ElemType.QUAD4: 'quad4', ElemType.QUAD8: 'quad8', ElemType.SEG2: 'bar2', ElemType.SEG3: 'bar3', ElemType.TETRA10: 'tetra10', ElemType.TETRA4: 'tetra4', ElemType.TRI3: 'tria3', ElemType.TRI6: 'tria6'}#

Ensight

Type:

ElemType

EasyFEA.Utilities.MeshIO.DICT_ELEMTYPE_TO_MESHIO = {ElemType.HEXA20: 'hexahedron20', ElemType.HEXA27: 'hexahedron27', ElemType.HEXA8: 'hexahedron', ElemType.POINT: 'vertex', ElemType.PRISM15: 'wedge15', ElemType.PRISM18: 'wedge18', ElemType.PRISM6: 'wedge', ElemType.QUAD4: 'quad', ElemType.QUAD8: 'quad8', ElemType.QUAD9: 'quad9', ElemType.SEG2: 'line', ElemType.SEG3: 'line3', ElemType.SEG4: 'line4', ElemType.SEG5: 'line5', ElemType.TETRA10: 'tetra10', ElemType.TETRA4: 'tetra', ElemType.TRI10: 'triangle10', ElemType.TRI15: 'triangle15', ElemType.TRI3: 'triangle', ElemType.TRI6: 'triangle6'}#

meshioType

Type:

ElemType

EasyFEA.Utilities.MeshIO.DICT_ELEMTYPE_TO_VTK: dict[ElemType, VTKCellType] = {ElemType.HEXA20: VTKCellType.QUADRATIC_HEXAHEDRON, ElemType.HEXA27: VTKCellType.TRIQUADRATIC_HEXAHEDRON, ElemType.HEXA8: VTKCellType.HEXAHEDRON, ElemType.POINT: VTKCellType.VERTEX, ElemType.PRISM15: VTKCellType.QUADRATIC_WEDGE, ElemType.PRISM18: VTKCellType.BIQUADRATIC_QUADRATIC_WEDGE, ElemType.PRISM6: VTKCellType.WEDGE, ElemType.QUAD4: VTKCellType.QUAD, ElemType.QUAD8: VTKCellType.QUADRATIC_QUAD, ElemType.QUAD9: VTKCellType.BIQUADRATIC_QUAD, ElemType.SEG2: VTKCellType.LINE, ElemType.SEG3: VTKCellType.QUADRATIC_EDGE, ElemType.SEG4: VTKCellType.CUBIC_LINE, ElemType.SEG5: VTKCellType.HIGHER_ORDER_EDGE, ElemType.TETRA10: VTKCellType.QUADRATIC_TETRA, ElemType.TETRA4: VTKCellType.TETRA, ElemType.TRI10: VTKCellType.LAGRANGE_TRIANGLE, ElemType.TRI15: VTKCellType.LAGRANGE_TRIANGLE, ElemType.TRI3: VTKCellType.TRIANGLE, ElemType.TRI6: VTKCellType.QUADRATIC_TRIANGLE}#

CellType

Type:

ElemType

EasyFEA.Utilities.MeshIO.DICT_ENSIGHT_TO_ELEMTYPE: dict[str, ElemType] = {'bar2': ElemType.SEG2, 'bar3': ElemType.SEG3, 'hexa20': ElemType.HEXA20, 'hexa8': ElemType.HEXA8, 'point': ElemType.POINT, 'quad4': ElemType.QUAD4, 'quad8': ElemType.QUAD8, 'tetra10': ElemType.TETRA10, 'tetra4': ElemType.TETRA4, 'tria3': ElemType.TRI3, 'tria6': ElemType.TRI6, 'wedge15': ElemType.PRISM15, 'wedge6': ElemType.PRISM6}#

ElemType

Type:

Ensight

EasyFEA.Utilities.MeshIO.DICT_ENSIGHT_TO_GMSH_INDEXES: dict[str, list[int]] = {'bar3': [0, 2, 1], 'hexa20': [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 9, 16, 18, 19, 17, 10, 12, 14, 15], 'tetra10': [0, 1, 2, 3, 4, 5, 6, 7, 9, 8], 'wedge15': [0, 1, 2, 3, 4, 5, 6, 9, 7, 12, 14, 13, 8, 10, 11]}#

list[int]

Type:

Ensight

EasyFEA.Utilities.MeshIO.DICT_GMSH_TO_ENSIGHT_INDEXES: dict[ElemType, list[int]] = {ElemType.HEXA20: [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 16, 9, 17, 10, 18, 19, 12, 15, 13, 14], ElemType.PRISM15: [0, 1, 2, 3, 4, 5, 6, 8, 12, 7, 13, 14, 9, 11, 10], ElemType.SEG3: [0, 2, 1], ElemType.TETRA10: [0, 1, 2, 3, 4, 5, 6, 7, 9, 8]}#

list[int]

Type:

ElemType

EasyFEA.Utilities.MeshIO.DICT_GMSH_TO_VTK_INDEXES: dict[ElemType, list[int]] = {ElemType.HEXA20: [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 9, 16, 18, 19, 17, 10, 12, 14, 15], ElemType.HEXA27: [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 9, 16, 18, 19, 17, 10, 12, 14, 15, 22, 23, 21, 24, 20, 25, 26], ElemType.PRISM15: [0, 1, 2, 3, 4, 5, 6, 9, 7, 12, 14, 13, 8, 10, 11], ElemType.PRISM18: [0, 1, 2, 3, 4, 5, 6, 9, 7, 12, 14, 13, 8, 10, 11, 15, 17, 16], ElemType.TETRA10: [0, 1, 2, 3, 4, 5, 6, 7, 9, 8]}#

list[int]

Type:

ElemType

EasyFEA.Utilities.MeshIO.DICT_MESHIO_TO_ELEMTYPE: dict[str, ElemType] = {'hexahedron': ElemType.HEXA8, 'hexahedron20': ElemType.HEXA20, 'hexahedron27': ElemType.HEXA27, 'line': ElemType.SEG2, 'line3': ElemType.SEG3, 'line4': ElemType.SEG4, 'line5': ElemType.SEG5, 'quad': ElemType.QUAD4, 'quad8': ElemType.QUAD8, 'quad9': ElemType.QUAD9, 'tetra': ElemType.TETRA4, 'tetra10': ElemType.TETRA10, 'triangle': ElemType.TRI3, 'triangle10': ElemType.TRI10, 'triangle15': ElemType.TRI15, 'triangle6': ElemType.TRI6, 'vertex': ElemType.POINT, 'wedge': ElemType.PRISM6, 'wedge15': ElemType.PRISM15, 'wedge18': ElemType.PRISM18}#

ElemType

Type:

CellType

EasyFEA.Utilities.MeshIO.DICT_VTK_TO_ELEMTYPE: dict[VTKCellType, ElemType] = {VTKCellType.VERTEX: ElemType.POINT, VTKCellType.LINE: ElemType.SEG2, VTKCellType.TRIANGLE: ElemType.TRI3, VTKCellType.QUAD: ElemType.QUAD4, VTKCellType.TETRA: ElemType.TETRA4, VTKCellType.HEXAHEDRON: ElemType.HEXA8, VTKCellType.WEDGE: ElemType.PRISM6, VTKCellType.QUADRATIC_EDGE: ElemType.SEG3, VTKCellType.QUADRATIC_TRIANGLE: ElemType.TRI6, VTKCellType.QUADRATIC_QUAD: ElemType.QUAD8, VTKCellType.QUADRATIC_TETRA: ElemType.TETRA10, VTKCellType.QUADRATIC_HEXAHEDRON: ElemType.HEXA20, VTKCellType.QUADRATIC_WEDGE: ElemType.PRISM15, VTKCellType.BIQUADRATIC_QUAD: ElemType.QUAD9, VTKCellType.TRIQUADRATIC_HEXAHEDRON: ElemType.HEXA27, VTKCellType.BIQUADRATIC_QUADRATIC_WEDGE: ElemType.PRISM18, VTKCellType.CUBIC_LINE: ElemType.SEG4, VTKCellType.HIGHER_ORDER_EDGE: ElemType.SEG5, VTKCellType.LAGRANGE_TRIANGLE: ElemType.TRI15}#

ElemType

Type:

CellType

EasyFEA.Utilities.MeshIO.DICT_VTK_TO_GMSH_INDEXES: dict[VTKCellType, list[int]] = {VTKCellType.QUADRATIC_TETRA: [0, 1, 2, 3, 4, 5, 6, 7, 9, 8], VTKCellType.QUADRATIC_HEXAHEDRON: [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 16, 9, 17, 10, 18, 19, 12, 15, 13, 14], VTKCellType.QUADRATIC_WEDGE: [0, 1, 2, 3, 4, 5, 6, 8, 12, 7, 13, 14, 9, 11, 10], VTKCellType.TRIQUADRATIC_HEXAHEDRON: [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 16, 9, 17, 10, 18, 19, 12, 15, 13, 14, 24, 22, 20, 21, 23, 25, 26], VTKCellType.BIQUADRATIC_QUADRATIC_WEDGE: [0, 1, 2, 3, 4, 5, 6, 8, 12, 7, 13, 14, 9, 11, 10, 15, 17, 16]}#

list[int]

Type:

CellType

This module allows you to save a simulation’s results on Paraview (https://www.paraview.org/).

EasyFEA.Utilities.Paraview.CalcOffset(offset, count, biteSize=4)[source]#
EasyFEA.Utilities.Paraview.Save_simu(
simu: _Simu,
folder: str,
N: int = 200,
details: bool = False,
nodeFields: list[str] = [],
elementFields: list[str] = [],
)[source]#

Generates the paraview (.pvd and .vtu/.pvtu files) with a simu.

Parameters:
  • simu (_Simu) – Simulation

  • folder (str) – folder in which we will create the Paraview folder

  • N (int, optional) – Maximal number of iterations displayed, by default 200

  • details (bool, optional) – details of nodesField and elementsField used in the .vtu

  • nodeFields (list, optional) – Additional nodeFields, by default []

  • elementFields (list, optional) – Additional elementFields, by default []

EasyFEA.Utilities.Paraview._Save_mesh(
mesh: Mesh,
folder: str,
N: int,
nodeFields: dict[str, list[ndarray[tuple[Any, ...], dtype[Any]]]] = {},
elementFields: dict[str, list[ndarray[tuple[Any, ...], dtype[Any]]]] = {},
)[source]#

Generates the paraview (.pvd and .vtu/.pvtu files) with a mesh.

Parameters:
  • mesh (Mesh) – mesh

  • folder (str) – folder in which we will create the Paraview folder

  • N (int) – number of iterations

  • nodeFields (dict[str, list[_types.AnyArray]], optional) – Additional nodeFields, by default {}

  • elementFields (dict[str, list[_types.AnyArray]], optional) – Additional elementFields, by default {}

Module providing an interface with PyVista (https://docs.pyvista.org/version/stable/).

https://docs.pyvista.org/api/plotting/plotting.html

EasyFEA.Utilities.PyVista.Create_requires_decorator(*modules: str, libraries: list[str] = None)[source]#

Creates a decorator that checks if modules are available before executing a function.

Returns:

A decorator that raises an ImportError if the modules are not available.

Return type:

function

EasyFEA.Utilities.PyVista.Movie_func(
func: Callable[[Plotter, int], None],
N: int,
folder: str,
filename='video.gif',
)[source]#

Generates the movie for the specified function.

This function will peform a loop in range(N).

Parameters:
  • func (Callable[[pv.Plotter, int], None]) –

    The function that will use in first argument the plotter and in second argument the iter step such that.

    def func(plotter, i) -> None

  • N (int) – number of iteration

  • folder (str) – folder where you want to save the video

  • filename (str, optional) – filename of the video with the extension (gif, mp4), by default ‘video.gif’

EasyFEA.Utilities.PyVista.Movie_simu(
simu: _Simu,
result: str,
folder: str,
filename='video.gif',
N: int = 200,
deformFactor=0.0,
coef=1.0,
nodeValues=True,
**kwargs,
) None[source]#

Generates a movie from a simulation’s result.

Parameters:
  • simu (_Simu) – simulation

  • result (str) – result that you want to plot

  • folder (str) – folder where you want to save the video

  • filename (str, optional) – filename of the video with the extension (gif, mp4), by default ‘video.gif’

  • N (int, optional) – Maximal number of iterations displayed, by default 200

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • coef (float, optional) – Coef to apply to the solution, by default 1.0

  • nodeValues (bool, optional) – Displays result to nodes otherwise displays it to elements, by default True

EasyFEA.Utilities.PyVista.Plot(
obj: '_Simu' | 'Mesh' | '_GroupElem' | Any,
result: str | _types.FloatArray | None = None,
deformFactor=0.0,
coef=1.0,
nodeValues=True,
color=None,
plotMesh=False,
edgecolor='k',
linewidth=None,
plotNodes=False,
point_size=None,
alpha=1.0,
style='surface',
cmap='jet',
nColors=256,
clim=None,
plotter: pv.Plotter | None = None,
show_grid=False,
colorbarTitle=None,
verticalColobar=True,
**kwargs,
)[source]#

Plots the object obj that can be either a simu, mesh, MultiBlock, PolyData.

If you want to plot the solution use plotter.show().

Parameters:
  • obj (_Simu | Mesh | _GroupElem | MultiBlock | PolyData | UnstructuredGrid) – The object to plot and will be transformed to a mesh

  • result (Union[str,_types.FloatArray], optional) – Scalars used to “color” the mesh, by default None

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • coef (float, optional) – Coef to apply to the solution, by default 1.0

  • nodeValues (bool, optional) – Displays result to nodes otherwise displays it to elements, by default True

  • color (str, optional) – Use to make the entire mesh have a single solid color, by default None

  • plotMesh (bool, optional) – Shows the edges of a mesh. Does not apply to a wireframe representation, by default False

  • edgecolor (str, optional) – The solid color to give the edges when show_edges=True, by default ‘k’

  • linewidth (float, optional) – Thickness of lines. Only valid for wireframe and surface representations, by default None

  • plotNodes (bool, optional) – Shows the nodes, by default False

  • point_size (float, optional) – Point size of any nodes in the dataset plotted when plotNodes=True, by default None

  • alpha (float | str | ndarray, optional) – Opacity of the mesh, by default 1.0

  • style (str, optional) – Visualization style of the mesh. One of the following: [‘surface’, ‘wireframe’, ‘points’, ‘points_gaussian’], by default ‘surface’

  • cmap (str, optional) –

    If a string, this is the name of the matplotlib colormap to use when mapping the scalars, by default “jet”

    [“jet”, “seismic”, “binary”] -> https://matplotlib.org/stable/tutorials/colors/colormaps.html

  • nColors (int, optional) – Number of colors to use when displaying scalars, by default 256

  • clim (sequence[float], optional) – Two item color bar range for scalars. Defaults to minimum and maximum of scalars array. Example: [-1, 2], by default None

  • plotter (pv.Plotter, optional) – The pyvista plotter, by default None and create a new Plotter instance

  • show_grid (bool, optionnal) – Show the grid, by default False

  • colorbarTitle (str, optionnal) – colorbar title, by default None

  • verticalColobar (bool, optionnal) – color bar is vertical, by default True

  • **kwargs – Everything that can goes in add_mesh function https://docs.pyvista.org/version/stable/api/plotting/_autosummary/pyvista.Plotter.add_mesh.html#pyvista.Plotter.add_mesh

Returns:

The pyvista plotter

Return type:

pv.Plotter

Examples

Von Mises stress in MPa (elastic simulation):

>>> from EasyFEA.Utilities import PyVista
>>> plotter = PyVista.Plot(simu, result="Svm", coef=1e-6, colorbarTitle="σ_vm [MPa]")
>>> plotter.show()

With deformed mesh:

>>> plotter = PyVista.Plot(simu, result="displacement_norm", deformFactor=100)
>>> plotter.show()

Mesh only (no scalar field):

>>> plotter = PyVista.Plot(mesh)
>>> plotter.show()
EasyFEA.Utilities.PyVista.Plot_Arrows(
obj: '_Simu' | 'Mesh',
nodes: _types.IntArray,
vectors: _types.FloatArray,
deformFactor: float = 0.0,
magnitudeCoef: float = 0.1,
alpha: float = 1.0,
color: str = 'red',
linewidth: float | None = None,
label: str | None = None,
plotter: pv.Plotter | None = None,
)[source]#

Plots the mesh elements corresponding to the given nodes.

Parameters:
  • obj (_Simu | Mesh) – object containing the mesh

  • nodes (_types.IntArray) – mesh nodes

  • vectors (_types.FloatArray) – vectors on nodes

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • magnitudeCoef (float, optional) – coef used to scale the average distance between the coordinates and the center, by default 0.1

  • alpha (float, optional) – transparency of faces, by default 1.0

  • color (str, optional) – color used to display faces, by default ‘red

  • linewidth (float, optional) – Thickness of lines, by default None

  • label (str, optional) – label, by default None

  • plotter (pv.Plotter, optional) – The pyvista plotter, by default None and create a new Plotter instance

Returns:

The pyvista plotter

Return type:

pv.Plotter

EasyFEA.Utilities.PyVista.Plot_BoundaryConditions(
simu: _Simu,
deformFactor=0.0,
plotter: pv.Plotter | None = None,
)[source]#

Plots simulation’s boundary conditions.

Parameters:
  • simu (Simu) – simulation

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • plotter (pv.Plotter, optional) – The pyvista plotter, by default None and create a new Plotter instance, default None

Returns:

The pyvista plotter

Return type:

pv.Plotter

EasyFEA.Utilities.PyVista.Plot_Elements(
obj: '_Simu' | 'Mesh',
nodes: _types.IntArray = [],
dimElem: int | None = None,
showId=False,
deformFactor=0.0,
alpha=1.0,
color='red',
edgecolor='black',
linewidth: float | None = None,
label: str | None = None,
plotter: pv.Plotter | None = None,
)[source]#

Plots the mesh elements corresponding to the given nodes.

Parameters:
  • obj (_Simu | Mesh) – object containing the mesh

  • nodes (_types.IntArray, optional) – nodes used by elements, default None

  • dimElem (int, optional) – dimension of elements, by default None (mesh.dim)

  • showId (bool, optional) – display numbers, by default False

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • alpha (float, optional) – transparency of faces, by default 1.0

  • color (str, optional) – color used to display faces, by default ‘red

  • edgecolor (str, optional) – color used to display segments, by default ‘black’

  • linewidth (float, optional) – Thickness of lines, by default None

  • label (str, optional) – label, by default None

  • plotter (pv.Plotter, optional) – The pyvista plotter, by default None and create a new Plotter instance

Returns:

The pyvista plotter

Return type:

pv.Plotter

EasyFEA.Utilities.PyVista.Plot_Geoms(
geoms: list,
line_width=2,
plotLegend=True,
plotter: Plotter | None = None,
**kwargs,
) Plotter[source]#

Plots _Geom objects

Parameters:
Returns:

The pyvista plotter

Return type:

pv.Plotter

EasyFEA.Utilities.PyVista.Plot_Mesh(
obj: '_Simu' | 'Mesh' | Any,
deformFactor=0.0,
alpha=1.0,
color='cyan',
edgecolor='black',
linewidth=0.5,
plotter: pv.Plotter | None = None,
)[source]#

Plots the mesh.

Parameters:
  • obj (_Simu | Mesh | MultiBlock | PolyData | UnstructuredGrid) – object containing the mesh

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • alpha (float, optional) – face opacity, default 1.0

  • color (str, optional) – face colors, default ‘cyan’

  • edgecolor (str, optional) – edge color, default ‘black’

  • line_width (float, optional) – line width, default 0.5

  • plotter (pv.Plotter, optional) – The pyvista plotter, by default None and create a new Plotter instance

Returns:

The pyvista plotter

Return type:

pv.Plotter

Examples

Undeformed mesh:

>>> from EasyFEA.Utilities import PyVista
>>> plotter = PyVista.Plot_Mesh(mesh)
>>> plotter.show()

Deformed mesh with transparency:

>>> plotter = PyVista.Plot_Mesh(simu, deformFactor=50, alpha=0.5)
>>> plotter.show()
EasyFEA.Utilities.PyVista.Plot_Nodes(
obj: '_Simu' | 'Mesh',
nodes: _types.IntArray | None = None,
showId=False,
deformFactor=0,
color='red',
folder='',
label=None,
plotter: pv.Plotter | None = None,
)[source]#

Plots mesh’s nodes.

Parameters:
  • obj (_Simu | Mesh) – object containing the mesh

  • nodes (_types.IntArray, optional) – nodes to display, default None

  • showId (bool, optional) – display node numbers, default False

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • color (str, optional) – color, default ‘red’

  • label (str, optional) – label, by default None

  • plotter (pv.Plotter, optional) – The pyvista plotter, by default None and create a new Plotter instance

Returns:

The pyvista plotter

Return type:

pv.Plotter

EasyFEA.Utilities.PyVista.Plot_Tags(
obj,
alpha: float = 1.0,
useColorCycler=False,
useLegend: bool = False,
plotter: Plotter | None = None,
) Plotter[source]#

Plots the mesh’s elements tags (from 2d elements to points) but do not plot the 3d elements tags.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – object containing the mesh

  • alpha (float | str | ndarray, optional) – Opacity of the mesh, by default 1.0

  • useColorCycler (bool, optional) – whether to use color cycler, by default False

  • useLegend (bool, optional) – Use legen, by default False.

  • plotter (pv.Plotter, optional) – The pyvista plotter, by default None and create a new Plotter instance.

Returns:

The pyvista plotter

Return type:

pv.Plotter

EasyFEA.Utilities.PyVista._(geom: Contour)[source]#
EasyFEA.Utilities.PyVista._Get_values(
simu: _Simu | None,
mesh: Mesh,
result: str | ndarray[tuple[Any, ...], dtype[Any]],
nodeValues=True,
) ndarray[tuple[Any, ...], dtype[Any]][source]#

Retrieves values and ensures compatibility with the mesh.

Parameters:
  • simu (Union[_Simu, None]) – Simulation (can be set to None).

  • mesh (Mesh) – Mesh used to display the result.

  • result (Union[str, _types.AnyArray]) – Result you want to display. Must be included in simu.Get_Results() or be a numpy array of size (Nn, Ne).

  • nodeValues (bool, optional) – Displays result on nodes; otherwise, displays it on elements. Default is True.

Returns:

values

Return type:

_types.AnyArray

EasyFEA.Utilities.PyVista._Init_obj(
obj: _Simu | Mesh | _GroupElem,
deformFactor: float = 0.0,
) tuple[_Simu | None, Mesh, ndarray[tuple[Any, ...], dtype[floating]], int][source]#
EasyFEA.Utilities.PyVista._Init_obj(obj: _Simu, deformFactor: float = 0.0)
EasyFEA.Utilities.PyVista._Init_obj(obj: Mesh, deformFactor: float = 0.0)
EasyFEA.Utilities.PyVista._Init_obj(obj: _GroupElem, deformFactor: float = 0.0)

Returns (simu, mesh, coord, inDim) from an ojbect that could be either a _Simu, a Mesh or a _GroupElem object.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – An object that contain the mesh

  • deformFactor (float, optional) – the factor used to deform the mesh, by default 0.0

Returns:

(simu, mesh, coord, inDim)

Return type:

tuple[_Simu|None, Mesh, ndarray, int]

EasyFEA.Utilities.PyVista._Plotter(off_screen=False, add_axes=True, shape=(1, 1), linkViews=True)[source]#
EasyFEA.Utilities.PyVista._pvGeom(geom) DataSet | list[DataSet][source]#
EasyFEA.Utilities.PyVista._pvGeom(line: Line)
EasyFEA.Utilities.PyVista._pvGeom(circleArc: CircleArc)
EasyFEA.Utilities.PyVista._pvGeom(geom: Point)
EasyFEA.Utilities.PyVista._pvGeom(geom: Domain)
EasyFEA.Utilities.PyVista._pvGeom(geom: Circle)
EasyFEA.Utilities.PyVista._pvGeom(geom: Points)
EasyFEA.Utilities.PyVista._pvGeom(geom: Contour)
EasyFEA.Utilities.PyVista._pvMesh(
obj: '_Simu' | 'Mesh' | '_GroupElem',
result: str | _types.AnyArray | None = None,
deformFactor=0.0,
nodeValues=True,
clipAxis=None,
clipCenter=None,
) pv.UnstructuredGrid[source]#

Creates the pyvista mesh from obj (_Simu, Mesh and _GroupElem objects)

EasyFEA.Utilities.PyVista._setCameraPosition(
plotter: Plotter,
inDim: int,
camera_position='xy',
roll=0,
elevation=25,
azimuth=10,
)[source]#

Sets the camera position, then controls the camera and resets the clipping range if inDim == 3.

https://docs.pyvista.org/api/core/camera.html#controlling-camera-rotation

Parameters:
  • plotter (pv.Plotter) – pyvista plotter

  • inDim (int) – dimension in which the objects lies.

  • camera_position (str, optional) – camera position of the active render window., by default “xy”

  • roll (int, optional) – this will spin the camera about its axis., by default 0

  • elevation (int, optional) – the vertical rotation of the scene, by default 25

  • azimuth (int, optional) – the azimuth of the camera, by default 10

EasyFEA.Utilities.PyVista.rank0_only(func)[source]#

Decorator: only rank 0 executes the function. Non-root ranks return None.

Use on file-output and visualization functions (Display, GLTF, USD, Vizir) to prevent non-root MPI ranks from writing files or rendering plots.

EasyFEA.Utilities.PyVista.requires_pyvista(func)[source]#

Module providing functions used to save FEM-solutions for vizir (https://pyamg.saclay.inria.fr/vizir4.html).

EasyFEA.Utilities.Vizir.Save_simu(
simu: _Simu,
results: list[str],
types: list[int],
folder: str,
N: int | None = None,
) str[source]#

Saves simulation results to files and prepares a command for visualization.

Parameters:
  • simu (_Simu) – The simulation object containing the results to be saved.

  • results (list[str]) – A list of result names to be saved.

  • types (list[int]) – A list of types corresponding to each result.

  • folder (str) – The directory where the results will be saved.

  • N (Optional[int], optional) – The number of iterations to sample from the simulation. If None, all iterations are used.

Returns:

A command string for visualizing the saved results using vizir.

Return type:

str

EasyFEA.Utilities.Vizir._Get_BaryCentric_Coordinates(
groupElem: _GroupElem,
) ndarray[tuple[Any, ...], dtype[floating]][source]#

Computes the barycentric coordinates for a given group element based on its type.

Parameters:

groupElem (_GroupElem) – An object representing a group element.

Returns:

The barycentric coordinates corresponding to the specified element type.

Return type:

_types.FloatArray

EasyFEA.Utilities.Vizir._Get_BaryCentric_Coordinates_In_Segment(
vertices: ndarray[tuple[Any, ...], dtype[Any]],
coords: ndarray[tuple[Any, ...], dtype[Any]],
) ndarray[tuple[Any, ...], dtype[floating]][source]#

Computes barycentrice coordinates within a segment

Parameters:
  • vertices (_types.AnyArray) – vertices used to construct de segment

  • coords (_types.AnyArray) – coordinates within the segment

Returns:

barycentric_coords

Return type:

_types.FloatArray

EasyFEA.Utilities.Vizir._Get_BaryCentric_Coordinates_In_Tetrahedron(
vertices: ndarray[tuple[Any, ...], dtype[Any]],
coords: ndarray[tuple[Any, ...], dtype[Any]],
) ndarray[tuple[Any, ...], dtype[floating]][source]#

Computes barycentrice coordinates within a tetrahedron

Parameters:
  • vertices (_types.AnyArray) – vertices used to construct de tetrahedron

  • coords (_types.AnyArray) – coordinates within the tetrahedron

Returns:

barycentric_coords

Return type:

_types.FloatArray

EasyFEA.Utilities.Vizir._Get_BaryCentric_Coordinates_In_Triangle(
vertices: ndarray[tuple[Any, ...], dtype[Any]],
coords: ndarray[tuple[Any, ...], dtype[Any]],
) ndarray[tuple[Any, ...], dtype[floating]][source]#

Computes barycentrice coordinates within a triangle

Parameters:
  • vertices (_types.AnyArray) – vertices used to construct de triangle

  • coords (_types.AnyArray) – coordinates within the triangle

Returns:

barycentric_coords

Return type:

_types.FloatArray

EasyFEA.Utilities.Vizir._Get_empty_groupElem(groupElem: _GroupElem, order: int)[source]#

Generates an empty group element based on the specified order.

Parameters:
  • groupElem (_GroupElem) – An object representing a group element.

  • order (int) – The desired order for the new group element.

Returns:

An empty group element of the specified order.

Return type:

_GroupElem

EasyFEA.Utilities.Vizir._Write_solution_file(
mesh: Mesh,
dofsValues: ndarray[tuple[Any, ...], dtype[floating]],
assembly_e: ndarray[tuple[Any, ...], dtype[int64]],
type: int,
order: int,
folder: str,
filename: str,
warpVector_n: ndarray[tuple[Any, ...], dtype[floating]] | None = None,
deformFactor: float = 1.0,
) str[source]#

Writes a solution file for a given mesh and solution data.

Parameters:
  • mesh (Mesh) – The mesh object for which the solution is being written.

  • dofsValues (_types.FloatArray) – Array of degree of freedom values.

  • assembly_e (_types.IntArray) – Assembly information array.

  • type (int) – The type of solution being written.

  • order (int) – The order of the elements for which data is being written.

  • folder (str) – The directory where the solution file will be saved.

  • filename (str) – The name of the solution file.

  • warpVector_n (Optional[_types.FloatArray], optional) – Warp vector values for mesh deformation.

  • deformFactor (float, optional) – Deformation factor for the warp vector, default is 1.0.

Returns:

The path to the created solution file.

Return type:

str

EasyFEA.Utilities.Vizir.rank0_only(func)[source]#

Decorator: only rank 0 executes the function. Non-root ranks return None.

Use on file-output and visualization functions (Display, GLTF, USD, Vizir) to prevent non-root MPI ranks from writing files or rendering plots.

Module providing an interface with Universal Scene Description Format (USD) using usd-core (https://pypi.org/project/usd-core/).

EasyFEA.Utilities.USD.Create_requires_decorator(*modules: str, libraries: list[str] = None)[source]#

Creates a decorator that checks if modules are available before executing a function.

Returns:

A decorator that raises an ImportError if the modules are not available.

Return type:

function

EasyFEA.Utilities.USD.Save_mesh(
mesh: Mesh,
folder: str,
filename: str = 'mesh',
list_displacementMatrix: list[np.ndarray] = [],
list_nodesValues_n: list[np.ndarray] = [],
plotMesh=False,
cmap: str = 'jet',
fps: int = 30,
unit: float = 1.0,
smoothAnimation: bool = True,
) str[source]#

Saves the mesh as usdz file.

Parameters:
  • mesh (Mesh) – The mesh

  • folder (str) – The directory where the results will be saved.

  • filename (str, optional) – The name of the solution file, by default “mesh”

  • list_displacementMatrix (list[np.ndarray], optional) – List of displacement matrix, by default []

  • list_nodesValues_n (list[np.ndarray], optional) – List of node values for colors, by default []

  • plotMesh (bool, optional) – If True, wrong camera zoom in Keynote. If False, good camera zoom in Keynote. Default False

  • cmap (str, optional) –

    the color map used near the figure, by default “jet”

    [“jet”, “seismic”, “binary”, “viridis”] -> https://matplotlib.org/stable/tutorials/colors/colormaps.htmlcmap: str, optional

  • fps (int, optional) – Frames per second, by default 30

  • unit (float, optional) – Meters per unit, by default 1.0

  • smoothAnimation (bool, optional) – If True, smooth interpolation in Preview but no animation in Keynote. If False, frame-by-frame animation in Preview and Keynote. Default True.

Returns:

The path to the created usdz file.

Return type:

str

EasyFEA.Utilities.USD.Save_simu(
simu: _Simu,
results: list[str],
folder: str,
N: int = 50,
deformFactor=1.0,
plotMesh=False,
cmap: str = 'jet',
fps: int = 30,
unit: float = 1.0,
smoothAnimation: bool = True,
) None[source]#

Saves the simulation’s results as usdz files.

Parameters:
  • simu (_Simu) – simulation

  • results (list[str]) – results that you want to plot

  • folder (str) – folder where you want to save the video

  • N (int, optional) – Maximal number of iterations displayed, by default 200

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 0.0

  • plotMesh (bool, optional) – If True, wrong camera zoom in Keynote. If False, good camera zoom in Keynote. Default False

  • cmap (str, optional) –

    the color map used near the figure, by default “jet”

    [“jet”, “seismic”, “binary”, “viridis”] -> https://matplotlib.org/stable/tutorials/colors/colormaps.html

  • fps (int, optional) – Frames per second, by default 30

  • unit (float, optional) – Meters per unit, by default 1.0

  • smoothAnimation (bool, optional) – If True, smooth interpolation on Preview but no animation on Keynote. If False, frame-by-frame animation on Previewer and Keynote. Default True.

EasyFEA.Utilities.USD.Surface_reconstruction(mesh: Mesh) Mesh[source]#

Reconstructs the missing surfaces in a mesh.

EasyFEA.Utilities.USD._Init_obj(
obj: _Simu | Mesh | _GroupElem,
deformFactor: float = 0.0,
) tuple[_Simu | None, Mesh, ndarray[tuple[Any, ...], dtype[floating]], int][source]#
EasyFEA.Utilities.USD._Init_obj(obj: _Simu, deformFactor: float = 0.0)
EasyFEA.Utilities.USD._Init_obj(obj: Mesh, deformFactor: float = 0.0)
EasyFEA.Utilities.USD._Init_obj(obj: _GroupElem, deformFactor: float = 0.0)

Returns (simu, mesh, coord, inDim) from an ojbect that could be either a _Simu, a Mesh or a _GroupElem object.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – An object that contain the mesh

  • deformFactor (float, optional) – the factor used to deform the mesh, by default 0.0

Returns:

(simu, mesh, coord, inDim)

Return type:

tuple[_Simu|None, Mesh, ndarray, int]

EasyFEA.Utilities.USD._get_lines(mesh: Mesh) np.ndarray[source]#
EasyFEA.Utilities.USD._get_list_nodesValues(list_nodesValues_n: list[ndarray])[source]#
EasyFEA.Utilities.USD._get_triangles(mesh: Mesh) np.ndarray[source]#
EasyFEA.Utilities.USD.rank0_only(func)[source]#

Decorator: only rank 0 executes the function. Non-root ranks return None.

Use on file-output and visualization functions (Display, GLTF, USD, Vizir) to prevent non-root MPI ranks from writing files or rendering plots.

EasyFEA.Utilities.USD.requires_pxr(func)[source]#

Module providing an interface with Graphics Library Transmission Format (GLTF) using pygltflib (https://pypi.org/project/pygltflib/).

class EasyFEA.Utilities.GLTF.Component(value)[source]#

Bases: int, Enum

FLOAT = 5126#
SIGNED_BYTE = 5120#
SIGNED_SHORT = 5122#
UNSIGNED_BYTE = 5121#
UNSIGNED_INT = 5125#
UNSIGNED_SHORT = 5123#
class EasyFEA.Utilities.GLTF.Data(
data: ndarray | list[ndarray],
count: int,
type: Type,
component: Component,
target: Target = None,
)[source]#

Bases: object

Data class used to generate gltf data and save offset, bufferViews and accesors.

classmethod _Clear_All() None[source]#

Resets all class data.

classmethod _Get_list_data() list[Data][source]#

Returns list of Data.

class EasyFEA.Utilities.GLTF.StructFormat(value)[source]#

Bases: str, Enum

FLOAT = 'f'#
SIGNED_SHORT = 'h'#
UNSIGNED_INT = 'I'#
UNSIGNED_SHORT = 'H'#
class EasyFEA.Utilities.GLTF.Target(value)[source]#

Bases: int, Enum

ARRAY_BUFFER = 34962#
ELEMENT_ARRAY_BUFFER = 34963#
class EasyFEA.Utilities.GLTF.Type(value)[source]#

Bases: str, Enum

MAT2 = 'MAT2'#
MAT3 = 'MAT3'#
MAT4 = 'MAT4'#
SCALAR = 'SCALAR'#
VEC2 = 'VEC2'#
VEC3 = 'VEC3'#
VEC4 = 'VEC4'#
EasyFEA.Utilities.GLTF.Create_html(
path: str,
modelViewerDir: str = None,
defaultResult: str = None,
allowModelSelectorButton=True,
allowAninationButton=True,
allowColorbar=True,
)[source]#
EasyFEA.Utilities.GLTF.Create_requires_decorator(*modules: str, libraries: list[str] = None)[source]#

Creates a decorator that checks if modules are available before executing a function.

Returns:

A decorator that raises an ImportError if the modules are not available.

Return type:

function

EasyFEA.Utilities.GLTF.Open(path: str)[source]#

Opens the specified file or directory in the default web browser.

Parameters:

path (str) – Path to a glb/gltf file or a directory containing glb/gltf files.

EasyFEA.Utilities.GLTF.Save_mesh(
mesh: Mesh,
folder: str,
filename: str = 'mesh',
list_displacementMatrix: list[np.ndarray] = [],
list_nodesValues_n: list[np.ndarray] = [],
plotMesh=False,
cmap='jet',
fps: int = 30,
) str[source]#

Saves the mesh as glb file.

Parameters:
  • mesh (Mesh) – The mesh

  • folder (str) – The directory where the results will be saved.

  • filename (str, optional) – The name of the solution file, by default “mesh”

  • list_displacementMatrix (list[np.ndarray], optional) – List of displacement matrix, by default []

  • plotMesh (bool, optional) – displays mesh, by default False

  • cmap (str, optional) –

    the color map used near the figure, by default “jet”

    [“jet”, “seismic”, “binary”, “viridis”] -> https://matplotlib.org/stable/tutorials/colors/colormaps.html

  • fps (int, optional) – Frames per second, by default 30

Returns:

The path to the created glb file.

Return type:

str

EasyFEA.Utilities.GLTF.Save_simu(
simu: _Simu,
results: list[str],
folder: str,
N: int = 200,
deformFactor=1.0,
plotMesh=False,
fps: int = 30,
openWebBrowser=False,
) None[source]#

Saves the simulation as glb file.

Parameters:
  • simu (_Simu) – simulation

  • results (list[str]) – results that you want to plot

  • folder (str) – folder where you want to save the video

  • N (int, optional) – Maximal number of iterations displayed, by default 200

  • deformFactor (float, optional) – Factor used to display the deformed solution (0 means no deformations), default 1.0

  • plotMesh (bool, optional) – displays mesh, by default False

  • fps (int, optional) – Frames per second, by default 30

  • openWebBrowser (bool, optional) – open in the generated files in your web browser, by default False

Returns:

The path to the created glb file.

Return type:

str

EasyFEA.Utilities.GLTF.Surface_reconstruction(mesh: Mesh) Mesh[source]#

Reconstructs the missing surfaces in a mesh.

EasyFEA.Utilities.GLTF._Create_modelViewer_folder(
folder: str,
useAnimation: bool = False,
useColorbar: bool = False,
useModelSelector: bool = False,
)[source]#
EasyFEA.Utilities.GLTF._Init_obj(
obj: _Simu | Mesh | _GroupElem,
deformFactor: float = 0.0,
) tuple[_Simu | None, Mesh, ndarray[tuple[Any, ...], dtype[floating]], int][source]#
EasyFEA.Utilities.GLTF._Init_obj(obj: _Simu, deformFactor: float = 0.0)
EasyFEA.Utilities.GLTF._Init_obj(obj: Mesh, deformFactor: float = 0.0)
EasyFEA.Utilities.GLTF._Init_obj(obj: _GroupElem, deformFactor: float = 0.0)

Returns (simu, mesh, coord, inDim) from an ojbect that could be either a _Simu, a Mesh or a _GroupElem object.

Parameters:
  • obj (_Simu | Mesh | _GroupElem) – An object that contain the mesh

  • deformFactor (float, optional) – the factor used to deform the mesh, by default 0.0

Returns:

(simu, mesh, coord, inDim)

Return type:

tuple[_Simu|None, Mesh, ndarray, int]

EasyFEA.Utilities.GLTF._get_list_nodesValues(list_nodesValues_n: list[ndarray])[source]#
EasyFEA.Utilities.GLTF._write_file(file: str, content: str) str[source]#
EasyFEA.Utilities.GLTF.rank0_only(func)[source]#

Decorator: only rank 0 executes the function. Non-root ranks return None.

Use on file-output and visualization functions (Display, GLTF, USD, Vizir) to prevent non-root MPI ranks from writing files or rendering plots.

EasyFEA.Utilities.GLTF.requires_pygltflib(func)[source]#