pyleecan.Classes.MeshSolution module

Method code available at https://github.com/Eomys/pyleecan/tree/master/pyleecan/Methods/Mesh/MeshSolution

class MeshSolution(label='', mesh=- 1, is_same_mesh=True, solution=- 1, group=None, dimension=2, path=None, init_dict=None, init_str=None)[source]

Bases: FrozenClass

Abstract class to associate a mesh with one or several solutions

VERSION = 1
get_mesh(label=None, index=None)

Return the mesh corresponding to label or an index.

Parameters:
  • self (MeshSolution) – an MeshSolution object

  • label (str) – a label

  • index (int) – an index

Returns:

mesh – a Mesh object

Return type:

Mesh

get_solution(label=None, index=None)

Return the solution corresponding to label or an index.

Parameters:
  • self (MeshSolution) – an MeshSolution object

  • label (str) – a label

  • index (int) – an index

Returns:

solution – a Solution object

Return type:

Solution

get_field(*args_list, label=None, index=None, indices=None, is_rthetaz=False, is_pol2cart=False, is_radial=False, is_normal=False, is_rms=False, is_center=False, is_surf=False, is_squeeze=True)

Return the solution corresponding to label or an index.

Parameters:
  • self (MeshSolution) – an MeshSolution object

  • *args_list (list of strings) – List of axes requested by the user, their units and values (optional)

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of indices to extract from mesh and field

  • is_rthetaz (bool) – cylindrical coordinates

  • is_radial (bool) – radial component only

  • is_normal (bool) – normal component only (on nodes or centers)

  • is_rms (bool) – rms over surface sum((F.n)**2 dS)/S

  • is_center (bool) – field at cell centers

  • is_surf (bool) – field over outer surface

  • is_squeeze (bool) – squeeze the output result

Returns:

result – field

Return type:

ndarray

get_group(group_names)

Return all attributes of a MeshSolution object with only the cells, nodes and corresponding solutions of the group.

Parameters:
  • self (MeshSolution) – an MeshSolution object

  • group_name ([str]) – list of the name of the group(s) (e.g. [“stator”])

Returns:

meshsol_grp – a new MeshSolution object which is subpart of self

Return type:

MeshSolution

get_mesh_field_pv(*args, label=None, index=None, indices=None, is_surf=False, is_radial=False, is_center=False, is_normal=False, field_name=None, itimefreq=0)

Return the mesh and field adapted to pyvista plots.

Parameters:
  • self (MeshSolution) – an MeshSolution object

  • *args (list of strings) – List of axes requested by the user, their units and values (optional)

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of indices

  • is_radial (bool) – radial component only

  • is_center (bool) – field at cell centers

  • field_name (str) – label of the field to return

  • itimefreq (int) – if the field depends has a time/freqs axis, return the timefreq-th slice.

Returns:

  • mesh_pv (vtk.vtkPointSet) – a pyvista mesh object

  • field (ndarray) – an extracted field

  • field_name (str) – name of the extracted field (useful if not specified as input)

plot_mesh(p=None, label=None, index=None, indices=None, save_path=None, group_names=None, node_label=None, is_show_axes=False, is_show_fig=True, is_show_grid=False, win_title=None)

Plot the mesh using pyvista plotter.

Parameters:
  • self (MeshSolution) – a MeshSolution object

  • p (a pyvista(qt) object, optional) – a pyvista object which will be used for the plot

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of the points to extract (optional)

  • is_show_axes (bool) – True to show axes

  • is_show_fig (bool) – To call show at the end of the method

  • is_show_grid (bool) – True to show grid

plot_contour(*args, label=None, index=None, indices=None, is_surf=False, is_radial=False, is_center=False, clim=None, field_name=None, group_names=None, save_path=None, itimefreq=0, is_show_fig=True, win_title=None, factor=None, is_animated=False, title='', p=None, colormap='RdBu_r')

Plot the contour of a field on a mesh using pyvista plotter.

Parameters:
  • self (MeshSolution) – a MeshSolution object

  • *args (list of strings) – List of axes requested by the user, their units and values (optional)

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of the points to extract (optional)

  • is_surf (bool) – field over outer surface

  • is_radial (bool) – radial component only

  • is_center (bool) – field at cell-centers

  • clim (list) – a list of 2 elements for the limits of the colorbar

  • field_name (str) – title of the field to display on plot

  • group_names (list) – a list of str corresponding to group name(s)

  • save_path (str) – path to save the figure

  • itimefreq (int) – if the field depends has a time/freqs axis, return the timefreq-th slice.

  • is_show_fig (bool) – To call show at the end of the method

  • win_title (str) – Name of the window

  • factor (float) – Normalization factor

  • is_animated (bool) – True to animate magnetic flux density

  • title (str) – Name of the figure

  • p – Pyvista plotter

  • colormap (str) – Name of the colormap to use (default is from config_dict)

plot_deflection(*args, label=None, index=None, indices=None, clim=None, factor=None, field_name=None, group_names=None, save_path=None, title='', win_title='', is_surf=True, is_show_fig=True, p=None, sargs=None, is_animated=False, phase=1, is_return_plot_args=False)

Plot the operational deflection shape using pyvista plotter.

Parameters:
  • self (MeshSolution) – a MeshSolution object

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of the points to extract (optional)

  • clim (list) – a list of 2 elements for the limits of the colorbar

  • factor (float) – factor to multiply vector field

  • field_name (str) – title of the field to display on plot

  • is_show_fig (bool) – To call show at the end of the method

  • p=None

:param : :param meshsol_list=[]: :param : :param plot_list=[]: :param :

plot_glyph(*args, label=None, index=None, indices=None, clim=None, factor=None, field_name=None, save_path=None, is_point_arrow=False, group_names=None, is_show_fig=True, p=None, enforced_mesh=None, win_title='', title='', is_animated=False, phase=1, is_return_plot_args=False)

Plot the vector field as a glyph (or quiver) over the mesh.

Parameters:
  • self (MeshSolution) – a MeshSolution object

  • *args (list of strings) – List of axes requested by the user, their units and values (optional)

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of the points to extract (optional)

  • clim (list) – a list of 2 elements for the limits of the colorbar

  • factor (float) – factor to multiply vector field

  • field_name (str) – title of the field to display on plot

  • save_path (str) – path to save the plot into an image

  • is_point_arrow (bool) – to plot a nodal field (point-wise solution required)

  • group_names ([str]) – plot is restricted to the group(s) corresponding to this list of group names.

  • p (pyvista) – a pyvista object

  • enforced_mesh (Mesh) – enforced Mesh object

perm_coord(perm_coord_list=[0, 1, 2])

Permute coordinates of Mesh Solution in place

Parameters:
  • self (MeshSolution) – a MeshSolution object

  • perm_coord_list (list) – list of the coordinates to be permuted

get_deflection(*args, label, index, indices, field_name)

Get the vector field, the field name and the corresponding pyvista mesh in format adapted to a glyph plot.

Parameters:
  • self (MeshSolution) – a MeshSolution object

  • *args (list of strings) – List of axes requested by the user, their units and values (optional)

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of the points to extract (optional)

  • field_name (str) – title of the field to display on plot

Returns:

  • vect_field (ndaray) – vector field to plot

  • field_normal_amp (ndarray) – scalar field which is the normal/radial component of vect_field (to adjust the colormap)

  • field_name (str) – name of the field

  • mesh_pv (UnstructuredGrid) – pyvista mesh to plot

get_glyph(*args, label, index, indices, field_name)

Get the vector field, the field name and the corresponding pyvista mesh in format adapted to a glyph plot.

Parameters:
  • self (MeshSolution) – a MeshSolution object

  • *args (list of strings) – List of axes requested by the user, their units and values (optional)

  • label (str) – a label

  • index (int) – an index

  • indices (list) – list of the points to extract (optional)

  • field_name (str) – title of the field to display on plot

Returns:

  • vect_field (ndaray) – field to plot

  • field_name (str) – name of the field

  • mesh_pv (UnstructuredGrid) – pyvista mesh to plot

save(save_path='', is_folder=False, type_handle_old=2, type_compression=0)

Save the object to the save_path

Parameters:
  • self – A pyleecan object

  • save_path (str) – path to the folder to save the object

  • is_folder (bool) – to split the object in different files: separate simulation machine and materials (json only)

  • type_handle_old (int) – How to handle old file in folder mode (0:Nothing, 1:Delete, 2:Move to “Backup” folder)

  • type_compression (int) – Available only for json, 0: no compression, 1: gzip

get_logger()

Get the object logger or its parent’s one

Parameters:

obj – A pyleecan object

Returns:

logger – Pyleecan object dedicated logger

Return type:

logging.Logger

compare(other, name='self', ignore_list=None, is_add_value=False)[source]

Compare two objects and return list of differences

as_dict(type_handle_ndarray=0, keep_function=False, **kwargs)[source]

Convert this object in a json serializable dict (can be use in __init__). type_handle_ndarray: int

How to handle ndarray (0: tolist, 1: copy, 2: nothing)

keep_functionbool

True to keep the function object, else return str

Optional keyword input parameter is for internal use only and may prevent json serializability.

copy()[source]

Creates a deepcopy of the object

property label

(Optional) Descriptive name of the mesh

Type:

str

property mesh

A list of Mesh objects.

Type:

[Mesh]

property is_same_mesh

1 if the mesh is the same at each step (time, mode etc.)

Type:

bool

property solution

A list of Solution objects

Type:

[Solution]

property group

Dict sorted by groups name with list of cells indices.

Type:

dict

property dimension

Dimension of the physical problem

Type:

int

Min:

1

Max:

3

property path

Path where the MeshSolution is stored as a file

Type:

str