Utilities#

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

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/).

Numba

Numba functions to speed up calculations.

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).

Utilities API#

class EasyFEA.Utilities.Observable[source]#

Bases: object

The observable interface

_Add_observer(observer)[source]#

Add observer.

Return type:

None

_Notify(event)[source]#

Notifies the observers.

Return type:

None

_Remove_observer(observer)[source]#

Remove the observer.

Return type:

None

property observers[source]#

Oberservers looking for the observable obect

class EasyFEA.Utilities.Tic[source]#

Bases: object

static Clear()[source]#

Deletes history.

Return type:

None

static Get_Remaining_Time(i, N, time)[source]#

Returns remaining time asssuming that time is in s.

Return type:

str

static Get_time_unity(time)[source]#

Returns time with unity

Return type:

tuple[float, str]

static Plot_History(folder='', details=False)[source]#

Plots history.

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

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

Return type:

None

static Resume(verbosity=True)[source]#

Returns the TicTac summary

Return type:

str

static nTic()[source]#
Return type:

int

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

Returns the time elapsed since the last Tic or Tac.

Return type:

float

class EasyFEA.Utilities._IObserver[source]#

Bases: ABC

The observer interface

abstractmethod _Update(observable, event)[source]#

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

Return type:

None

EasyFEA.Utilities._CheckIsInIntervalcc(value, inf, sup)[source]#

Checks whether the value is in ]inf, sup[

Return type:

None

EasyFEA.Utilities._CheckIsInIntervaloo(value, inf, sup)[source]#

Checks whether the value is in [inf, sup]

Return type:

None

EasyFEA.Utilities._CheckIsNegative(value)[source]#

Checks whether the value is negative

Return type:

None

EasyFEA.Utilities._CheckIsPositive(value)[source]#

Checks whether the value is positive

Return type:

None

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

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

Clears the terminal.

Return type:

None

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

Initialize 2d or 3d axes.

Return type:

Union[Axes, Axes3D]

EasyFEA.Utilities.Display.Movie_Simu(
simu,
result,
folder,
filename='video.gif',
N=200,
deformFactor=0.0,
coef=1.0,
nodeValues=True,
plotMesh=False,
edgecolor='black',
fps=30,
**kwargs,
)[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

Return type:

None

EasyFEA.Utilities.Display.Movie_func(func, fig, N, folder, 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, color='cyan', bold=False, italic=False, underLine=False, end='')[source]#
Return type:

str

EasyFEA.Utilities.Display.MyPrintError(text)[source]#
Return type:

str

EasyFEA.Utilities.Display.Plot_BoundaryConditions(simu, ax=None)[source]#

Plots simulation’s boundary conditions.

Parameters:
  • simu (_Simu) – simulation

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

Return type:

_types.Axes

EasyFEA.Utilities.Display.Plot_Elements(
obj,
nodes=[],
dimElem=None,
showId=False,
alpha=1.0,
color='red',
edgecolor='black',
ax=None,
)[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 (_types.Axes, optional) – Axis to use, default None

Return type:

_types.Axes

EasyFEA.Utilities.Display.Plot_Energy(
simu,
load=array([], dtype=float64),
displacement=array([], dtype=float64),
plotSolMax=True,
N=200,
folder='',
)[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 “”

Return type:

None

EasyFEA.Utilities.Display.Plot_Force_Displacement(force, displacement, xlabel='u', ylabel='f', folder='', ax=None)[source]#

Plots the force displacement curve.

Parameters:
  • force (_types.FloatArray) – array of values for force

  • displacement (_types.FloatArray) – array of values for displacements

  • xlabel (str, optional) – x-axis title, by default ‘u’.

  • ylabel (str, optional) – y-axis title, by default ‘f’ folder : str, optional

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

  • ax (_types.Axes, optional) – ax in which to plot the figure, by default None

Returns:

returns figure and ax

Return type:

tuple[plt.Figure, _types.Axes]

EasyFEA.Utilities.Display.Plot_Iter_Summary(simu, folder='', iterMin=None, iterMax=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

Return type:

None

EasyFEA.Utilities.Display.Plot_Mesh(
obj,
deformFactor=0.0,
alpha=1.0,
facecolors='c',
edgecolor='black',
lw=0.5,
ax=None,
folder='',
title='',
)[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 (_types.Axes, optional) – Axis to use, default None

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

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

Return type:

_types.Axes

EasyFEA.Utilities.Display.Plot_Nodes(obj, nodes=None, showId=False, marker='.', color='red', ax=None)[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 (_types.Axes, optional) – Axis to use, default None, default None

Return type:

_types.Axes

EasyFEA.Utilities.Display.Plot_Result(
obj,
result,
deformFactor=0.0,
coef=1.0,
nodeValues=True,
plotMesh=False,
edgecolor='black',
title='',
cmap='jet',
ncolors=256,
clim=(None, None),
colorbarIsClose=False,
colorbarLabel='',
ax=None,
folder='',
filename='',
)[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

EasyFEA.Utilities.Display.Plot_Tags(obj, showId=True, folder='', alpha=1.0, useColorCycler=False, ax=None)[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 (_types.Axes, optional) – Axis to use, default None

Return type:

_types.Axes

EasyFEA.Utilities.Display.Save_fig(folder, filename, transparent=False, extension='pdf', dpi='figure')[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’

Return type:

None

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

Creates a new section in the terminal.

Return type:

str

EasyFEA.Utilities.Display._Axis_equal_3D(ax, coord)[source]#

Changes axis size for 3D display.

Center the part and make the axes the right size.

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

  • coord (_types.FloatArray) – mesh coordinates

Return type:

None

EasyFEA.Utilities.Display._Get_list_surfaces(mesh, dimElem)[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

Return type:

list[list[int]]

EasyFEA.Utilities.Display._Get_values(simu, mesh, result, nodeValues=True)[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, deformFactor=0.0)[source]#

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, alpha=1.0, color='gray', ax=None)[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 (_types.Axes, optional) – Axis to use, default None

Return type:

_types.Axes

EasyFEA.Utilities.Display._Remove_colorbar(ax)[source]#

Removes the current colorbar from the axis.

Return type:

None

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

EasyFEA.Utilities.Folder.Dir(path, depth=1)[source]#

Returns the directory of the specified path.

Return type:

str

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

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

Return type:

bool

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

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

Return type:

str

EasyFEA.Utilities.Folder.Results_Dir()[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!

Return type:

str

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

EasyFEA.Utilities.MeshIO.EasyFEA_to_Ensight(mesh, folder, name)[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, folder, name, useBinary=False)[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

EasyFEA.Utilities.MeshIO.EasyFEA_to_Medit(mesh, folder, name, dict_tags_converter={}, useBinary=False)[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

EasyFEA.Utilities.MeshIO.EasyFEA_to_PyVista(mesh, coord=None, useAllElements=True)[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

EasyFEA.Utilities.MeshIO.Ensight_to_EasyFEA(geoFile)[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)[source]#

Converts Gmsh mesh to EasyFEA format.

Parameters:

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

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

EasyFEA.Utilities.MeshIO.Medit_to_EasyFEA(meditMesh)[source]#

Converts Medit mesh to EasyFEA format.

Parameters:

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

Returns:

Converted EasyFEA mesh object.

Return type:

Mesh

EasyFEA.Utilities.MeshIO.PyVista_to_EasyFEA(pyVistaMesh)[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)[source]#

Reconstructs the missing surfaces in a mesh.

Return type:

Mesh

EasyFEA.Utilities.MeshIO._EasyFEA_to_Meshio(mesh, dict_tags_converter={}, cellType='tags')[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)[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)[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)[source]#
Return type:

tuple[CellType, ndarray[tuple[Any, ...], dtype[int64]]]

EasyFEA.Utilities.MeshIO._GroupElem_to_PyVista(groupElem, elements=None)[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)[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, dict_tags)[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.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, CellType] = {ElemType.HEXA20: CellType.QUADRATIC_HEXAHEDRON, ElemType.HEXA27: CellType.TRIQUADRATIC_HEXAHEDRON, ElemType.HEXA8: CellType.HEXAHEDRON, ElemType.POINT: CellType.VERTEX, ElemType.PRISM15: CellType.QUADRATIC_WEDGE, ElemType.PRISM18: CellType.BIQUADRATIC_QUADRATIC_WEDGE, ElemType.PRISM6: CellType.WEDGE, ElemType.QUAD4: CellType.QUAD, ElemType.QUAD8: CellType.QUADRATIC_QUAD, ElemType.QUAD9: CellType.BIQUADRATIC_QUAD, ElemType.SEG2: CellType.LINE, ElemType.SEG3: CellType.QUADRATIC_EDGE, ElemType.SEG4: CellType.CUBIC_LINE, ElemType.SEG5: CellType.HIGHER_ORDER_EDGE, ElemType.TETRA10: CellType.QUADRATIC_TETRA, ElemType.TETRA4: CellType.TETRA, ElemType.TRI10: CellType.LAGRANGE_TRIANGLE, ElemType.TRI15: CellType.LAGRANGE_TRIANGLE, ElemType.TRI3: CellType.TRIANGLE, ElemType.TRI6: CellType.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_PYVISTA_TO_ELEMTYPE: dict[CellType, ElemType] = {CellType.VERTEX: ElemType.POINT, CellType.LINE: ElemType.SEG2, CellType.TRIANGLE: ElemType.TRI3, CellType.QUAD: ElemType.QUAD4, CellType.TETRA: ElemType.TETRA4, CellType.HEXAHEDRON: ElemType.HEXA8, CellType.WEDGE: ElemType.PRISM6, CellType.QUADRATIC_EDGE: ElemType.SEG3, CellType.QUADRATIC_TRIANGLE: ElemType.TRI6, CellType.QUADRATIC_QUAD: ElemType.QUAD8, CellType.QUADRATIC_TETRA: ElemType.TETRA10, CellType.QUADRATIC_HEXAHEDRON: ElemType.HEXA20, CellType.QUADRATIC_WEDGE: ElemType.PRISM15, CellType.BIQUADRATIC_QUAD: ElemType.QUAD9, CellType.TRIQUADRATIC_HEXAHEDRON: ElemType.HEXA27, CellType.BIQUADRATIC_QUADRATIC_WEDGE: ElemType.PRISM18, CellType.CUBIC_LINE: ElemType.SEG4, CellType.HIGHER_ORDER_EDGE: ElemType.SEG5, CellType.LAGRANGE_TRIANGLE: ElemType.TRI15}#

ElemType

Type:

CellType

EasyFEA.Utilities.MeshIO.DICT_VTK_TO_GMSH_INDEXES: dict[CellType, list[int]] = {CellType.QUADRATIC_TETRA: [0, 1, 2, 3, 4, 5, 6, 7, 9, 8], CellType.QUADRATIC_HEXAHEDRON: [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 16, 9, 17, 10, 18, 19, 12, 15, 13, 14], CellType.QUADRATIC_WEDGE: [0, 1, 2, 3, 4, 5, 6, 8, 12, 7, 13, 14, 9, 11, 10], CellType.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], CellType.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

Numba functions to speed up calculations.

EasyFEA.Utilities.Numba.numba_decorator(func)[source]#

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

EasyFEA.Utilities.Paraview.Save_simu(simu, folder, N=200, details=False, nodeFields=[], elementFields=[])[source]#

Generates the paraview (.pvd and .pvu files) with a simu.

Parameters:
  • simulation (_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

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

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

EasyFEA.Utilities.Paraview._Save_mesh(mesh, folder, N, nodeFields={}, elementFields={})[source]#

Generates the paraview (.pvd and .pvu 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.Movie_func(func, N, folder, 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,
result,
folder,
filename='video.gif',
N=200,
deformFactor=0.0,
coef=1.0,
nodeValues=True,
**kwargs,
)[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

Return type:

None

EasyFEA.Utilities.PyVista.MyPrint(text, color='cyan', bold=False, italic=False, underLine=False, end='')[source]#
Return type:

str

EasyFEA.Utilities.PyVista.MyPrintError(text)[source]#
Return type:

str

EasyFEA.Utilities.PyVista.Plot(
obj,
result=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=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

EasyFEA.Utilities.PyVista.Plot_BoundaryConditions(simu, deformFactor=0.0, plotter=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,
nodes=None,
dimElem=None,
showId=False,
deformFactor=0.0,
alpha=1.0,
color='red',
edgecolor='black',
linewidth=None,
label=None,
plotter=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, line_width=2, plotLegend=True, plotter=None, **kwargs)[source]#

Plots _Geom objects

Parameters:
Returns:

The pyvista plotter

Return type:

pv.Plotter

EasyFEA.Utilities.PyVista.Plot_Mesh(
obj,
deformFactor=0.0,
alpha=1.0,
color='cyan',
edgecolor='black',
linewidth=0.5,
plotter=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

EasyFEA.Utilities.PyVista.Plot_Nodes(
obj,
nodes=None,
showId=False,
deformFactor=0,
color='red',
folder='',
label=None,
plotter=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, useColorCycler=False, plotter=None)[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

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

  • 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._(geom)[source]#
EasyFEA.Utilities.PyVista._Get_values(simu, mesh, result, nodeValues=True)[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, deformFactor=0.0)[source]#

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)[source]#
Return type:

Union[DataSet, list[DataSet]]

EasyFEA.Utilities.PyVista._pvMesh(
obj,
result=None,
deformFactor=0.0,
nodeValues=True,
clipAxis=None,
clipCenter=None,
)[source]#

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

Return type:

UnstructuredGrid

EasyFEA.Utilities.PyVista._setCameraPosition(
plotter,
inDim,
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

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

EasyFEA.Utilities.Vizir.Save_simu(simu, results, types, folder, N=None)[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)[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, coords)[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, coords)[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, coords)[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, order)[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,
dofsValues,
assembly_e,
type,
order,
folder,
filename,
warpVector_n=None,
deformFactor=1.0,
)[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