Esempio n. 1
0
def plot(self, fig=None):
    """Plot the Slot in a matplotlib fig

    Parameters
    ----------
    self : Slot
        A Slot object
    fig :
        if None, open a new fig and plot, else add to the current
        one (Default value = None)

    Returns
    -------
    None
    """
    surf = self.get_surface()

    # Display the result
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title("Slot")

    # Add the slot to the fig
    if self.get_is_stator:
        axes.add_patch(surf.get_patch(color=STATOR_COLOR))
    else:
        axes.add_patch(surf.get_patch(color=ROTOR_COLOR))

    # Axis Setup
    axis("equal")
    fig.show()
Esempio n. 2
0
def plot(self, fig=None):
    """Plot the Ventilation in a matplotlib fig

    Parameters
    ----------
    self : VentilationCirc
        A VentilationCirc object
    fig :
        if None, open a new fig and plot, else add to the current
        one (Default value = None)

    Returns
    -------
    None
    """
    self.check()

    patches = list()

    if fig is None:
        color = "k"  # Only the vents are plot
    else:
        color = "w"  # Vents are "air" on a Lamination

    for ii in range(self.Zh.size):  # For every ventilation group
        for jj in range(int(self.Zh[ii])):
            # For every ventilation in one group
            # Computation of center coordinates
            Zc = self.H0[ii] * exp(
                1j * (jj * 2 * pi / self.Zh[ii] + self.Alpha0[ii]))
            # Creation of the Circle
            patches.append(
                Circle((Zc.real, Zc.imag), self.D0[ii] / 2.0, color=color))

    # Display the result
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title("Axial Ventilation Ducts")

    # Add the magnet to the fig
    for patch in patches:
        axes.add_patch(patch)

    # Axis Setup
    axis("equal")
    Lim = self.comp_radius()[1] * 1.2
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    # Legend setup
    if color != "w":
        patch_leg.append(Patch(color="k"))
        label_leg.append("Ventilations")

        legend(patch_leg, label_leg)
    fig.show()
Esempio n. 3
0
def plot(self, fig=None, display_field=False):
    """Plot the Magnet in a matplotlib fig

    Parameters
    ----------
    self : Magnet
        A Magnet object
    fig :
        if None, open a new fig and plot, else add to the current
        one (Default value = None)
    display_field : bool
        if true, will display magnetization field arrow (Default value = False)

    Returns
    -------
    None
    """

    surf_list = self.build_geometry(Rbo)
    patches = list()
    for surf in surf_list:
        patches.append(surf.get_patch(color=MAGNET_COLOR))

    # Display the result
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title("Magnet")

    # Add the magnet to the fig
    for patch in patches:
        axes.add_patch(patch)

    # Add the field if needed
    if display_field:
        arrow_list = self.build_magnetization_field(Rbo)
        for arrow in arrow_list:
            axes.annotate(
                "",
                xy=(arrow[0].real, arrow[0].imag),
                xycoords="data",
                xytext=(arrow[1].real, arrow[1].imag),
                textcoords="data",
                arrowprops=dict(arrowstyle="->", connectionstyle="arc3"),
            )

    # Axis Setup
    axis("equal")

    # Legend setup
    if "Magnet" not in label_leg:
        patch_leg.append(Patch(color=MAGNET_COLOR))
        label_leg.append("Magnet")
        legend(patch_leg, label_leg)
    fig.show()
Esempio n. 4
0
def plot(self, fig=None, sym=1, alpha=0, delta=0, is_edge_only=False):
    """Plot the Frame in a matplotlib fig

    Parameters
    ----------
    self : Frame
        A Frame object
    fig :
        if None, open a new fig and plot, else add to the gcf (Default value = None)
    sym : int
        Symmetry factor (1= plot full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation
    is_edge_only: bool
        To plot transparent Patches

    Returns
    -------
    None

    """

    # plot only if the frame has a height >0
    if self.comp_height_eq() != 0:
        (fig, axes, patch_leg, label_leg) = init_fig(fig)
        surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta)
        patches = list()
        for surf in surf_list:
            if surf.label is not None and surf.label == "Frame":
                patches.append(
                    surf.get_patch(color=FRAME_COLOR, is_edge_only=is_edge_only)
                )
            else:
                patches.append(surf.get_patch(is_edge_only=is_edge_only))

        axes.set_xlabel("(m)")
        axes.set_ylabel("(m)")
        axes.set_title("Frame")
        for patch in patches:
            axes.add_patch(patch)
        axis("equal")

        # The Lamination is centered in the figure
        Lim = self.Rext * 1.1
        axes.set_xlim(-Lim, Lim, auto=True)
        axes.set_ylim(-Lim, Lim, auto=True)

        if not is_edge_only:
            patch_leg.append(Patch(color=FRAME_COLOR))
            label_leg.append("Frame")
            axes.legend(patch_leg, label_leg)

        fig.show()
Esempio n. 5
0
def plot(self, fig=None, display_magnet=True):
    """Plot the Hole in a matplotlib fig

    Parameters
    ----------
    self : Hole
        A Hole object
    fig :
        if None, open a new fig and plot, else add to the current
        one (Default value = None)
    display_magnet : bool
        if True, plot the magnet inside the hole, if there is any (Default value = True)

    Returns
    -------
    None
    """
    display = fig is None
    if display:
        color = "k"
    else:
        color = "w"

    surf_hole = self.build_geometry()
    patches = list()
    for surf in surf_hole:
        if "Magnet" in surf.label and display_magnet:
            patches.append(surf.get_patch(color=MAGNET_COLOR))
        else:
            patches.append(surf.get_patch(color=color))

    # Display the result
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title("Hole")

    # Add all the hole (and magnet) to fig
    for patch in patches:
        axes.add_patch(patch)

    # Axis Setup
    axis("equal")
    Lim = self.get_Rbo() * 1.2
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    if display_magnet and "Magnet" in [surf.label for surf in surf_hole]:
        patch_leg.append(Patch(color=MAGNET_COLOR))
        label_leg.append("Magnet")
        legend(patch_leg, label_leg)
    fig.show()
Esempio n. 6
0
def plot(self, fig=None, sym=1, alpha=0, delta=0, is_edge_only=False):
    """Plot the Shaft in a matplotlib fig

    Parameters
    ----------
    self : Shaft
        A Shaft object
    fig :
        if none, open a new fig and plot, else add to the current
        one (Default value = None)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation
    is_edge_only: bool
        To plot transparent Patches

    Returns
    -------
    None
    """

    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    # Get the shaft surface(s)
    surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta)
    patches = list()
    for surf in surf_list:
        patches.append(
            surf.get_patch(color=SHAFT_COLOR, is_edge_only=is_edge_only))
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title("Shaft")
    for patch in patches:
        axes.add_patch(patch)
    axis("equal")

    # The Lamination is centered in the figure
    Lim = self.Drsh * 0.6
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    # Add legend
    if not is_edge_only:
        patch_leg.append(Patch(color=SHAFT_COLOR))
        label_leg.append("Shaft")

        legend(patch_leg, label_leg)
    fig.show()
Esempio n. 7
0
def plot(self,
         fig=None,
         color=PATCH_COLOR,
         edgecolor=PATCH_EDGE,
         is_edge_only=False):
    """Plot the Surface patch in a matplotlib fig

    Parameters
    ----------
    self : Surface
        A Surface object
    fig :
        if None, open a new fig and plot, else add to the
        current one (Default value = None)
    color :
        the color of the patch (Default value = PATCH_COLOR)
    edgecolor :
        the edge color of the patch (Default value = PATCH_EDGE)
    is_edge_only: bool
        To set the transparancy of the face color to 0 and 1 for the edge color

    Returns
    -------
    None
    """

    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")

    axes.add_patch(
        self.get_patch(color=color,
                       edgecolor=edgecolor,
                       is_edge_only=is_edge_only))

    # Axis Setup
    axis("equal")

    fig.show()
Esempio n. 8
0
def plot_lines(self, fig=None):
    """Plot the SurfLine-Contour in a matplotlib fig
    (For plotting unclosed contour, for Polygon use plot method from Surface object)

    Parameters
    ----------
    self : SurfLine
        A SurfLine object
    fig :
        if None, open a new fig and plot, else add to the
        current one (Default value = None)
   
    Returns
    -------
    None
    """

    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")

    points = self.discretize(10)

    for idx in range(len(points) - 1):
        z1 = points[idx]
        z2 = points[idx + 1]
        x1 = real(z1)
        y1 = imag(z1)
        x2 = real(z2)
        y2 = imag(z2)
        axes.plot([x1, x2], [y1, y2], "k")

    # Axis Setup
    axis("equal")

    fig.show()
Esempio n. 9
0
def plot_BH(self, fig=None, grid=True):
    """Plot the curve B(H) at the specified frequency

    Parameters
    ----------
    self : MatMagnetics
        a MatMagnetics object
    fig :
        if None, open a new fig and plot, else add to the gcf (Default value = None)

    Returns
    -------
    None
    """
    (fig, axes, patch_leg, label_leg) = init_fig(fig)

    if self.BH_curve is not None:
        BH = self.get_BH()
        axes.plot(BH[:, 0], BH[:, 1], color="r")
        axes.grid(b=True)
        axes.set_xlabel("H [A/m]")
        axes.set_ylabel("B [T]")
        axes.set_title("B(H) curve")
        fig.show()
Esempio n. 10
0
def plot(
    self,
    fig=None,
    is_lam_only=False,
    sym=1,
    alpha=0,
    delta=0,
    is_edge_only=False,
    is_display=True,
):
    """Plot the Lamination in a matplotlib fig

    Parameters
    ----------
    self : LamSlotWind
        A LamSlotWind object
    fig :
        if None, open a new fig and plot, else add to the current
        one (Default value = None)
    is_lam_only : bool
        True to plot only the lamination (remove the Winding)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation
    is_edge_only: bool
        To plot transparent Patches
    is_display : bool
        False to return the patches
    Returns
    -------
    patches : list
        List of Patches
    """
    if self.is_stator:
        color_lam = STATOR_COLOR
    else:
        color_lam = ROTOR_COLOR

    # Get the LamSlot surface(s)
    surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta)

    patches = list()
    # getting the matrix  wind_mat [Nrad,Ntan,Zs,qs] representing the winding
    if type(self.winding) is WindingSC:
        wind_mat = None
    else:
        try:
            Zs = self.get_Zs()
            wind_mat = self.winding.comp_connection_mat(Zs)
            (Nrad, Ntan, Zs, qs) = wind_mat.shape
        except Exception:
            wind_mat = None
    if wind_mat is None:
        qs = 1  # getting number of surface in winding Zone in the Slot
    for surf in surf_list:
        if surf.label is not None and "_Ext" in surf.label:
            patches.append(surf.get_patch(color_lam,
                                          is_edge_only=is_edge_only))
        elif surf.label is not None and "_In" in surf.label:
            patches.append(surf.get_patch(is_edge_only=is_edge_only))
        elif "Wind" in surf.label or "Bar" in surf.label:
            if not is_lam_only:
                color = find_wind_phase_color(wind_mat=wind_mat,
                                              label=surf.label)
                patches.append(
                    surf.get_patch(color=color, is_edge_only=is_edge_only))
        else:
            patches.append(surf.get_patch(is_edge_only=is_edge_only))

    if is_display:
        # Display the result
        (fig, axes, patch_leg, label_leg) = init_fig(fig)
        axes.set_xlabel("(m)")
        axes.set_ylabel("(m)")
        for patch in patches:
            axes.add_patch(patch)
        # Axis Setup
        axis("equal")

        # The Lamination is centered in the figure
        Lim = self.Rext * 1.5
        axes.set_xlim(-Lim, Lim)
        axes.set_ylim(-Lim, Lim)

        # Add the legend
        if not is_edge_only:
            if self.is_stator and "Stator" not in label_leg:
                patch_leg.append(Patch(color=STATOR_COLOR))
                label_leg.append("Stator")
                axes.set_title("Stator with Winding")
            elif not self.is_stator and "Rotor" not in label_leg:
                patch_leg.append(Patch(color=ROTOR_COLOR))
                label_leg.append("Rotor")
                axes.set_title("Rotor with Winding")
            # Add the winding legend only if needed
            if not is_lam_only:
                for ii in range(qs):
                    if not ("Phase " + PHASE_NAME[ii] in label_leg):
                        # Avoid adding twice the same label
                        index = ii % len(PHASE_COLOR)
                        patch_leg.append(Patch(color=PHASE_COLOR[index]))
                        label_leg.append("Phase " + PHASE_NAME[ii])
            legend(patch_leg, label_leg)
        fig.show()
    else:
        return patches
Esempio n. 11
0
def plot(self, fig=None, is_magnet=True, sym=1, alpha=0, delta=0):
    """Plot a Lamination with Magnets in a matplotlib fig

    Parameters
    ----------
    self : LamSlotMag
        A LamSlotMag object
    fig :
        if None, open a new fig and plot, else add to the
        current one (Default value = None)
    is_magnet :
        If True plot the magnets (Default value = True)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation

    Returns
    -------
    None
    """

    if self.is_stator:
        lam_color = STATOR_COLOR
    else:
        lam_color = ROTOR_COLOR

    (fig, axes, patch_leg, label_leg) = init_fig(fig)

    # Get the lamination surfaces
    surf_list = self.build_geometry(is_magnet=is_magnet,
                                    sym=sym,
                                    alpha=alpha,
                                    delta=delta)
    patches = list()
    for surf in surf_list:
        if "Ext" in surf.label:
            patches.append(surf.get_patch(color=lam_color))
        elif "Magnet" in surf.label:
            patches.append(surf.get_patch(color=MAGNET_COLOR))
        else:
            patches.append(surf.get_patch())
    # Display the result
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    for patch in patches:
        axes.add_patch(patch)

    # Axis Setup
    axis("equal")

    # The Lamination is centered in the figure
    Lim = self.Rext * 1.5
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    # Add the legend
    if self.is_stator:
        patch_leg.append(Patch(color=STATOR_COLOR))
        label_leg.append("Stator")
        axes.set_title("Stator with Magnet")
    else:
        patch_leg.append(Patch(color=ROTOR_COLOR))
        label_leg.append("Rotor")
        axes.set_title("Rotor with Magnet")

    legend(patch_leg, label_leg)
    fig.show()
Esempio n. 12
0
def plot(self, fig=None, sym=1, alpha=0, delta=0):
    """Plot the Lamination in a matplotlib fig

    Parameters
    ----------
    self : Lamination
        A Lamination object
    fig :
        if None, open a new fig and plot, else add to the current one (Default value = None)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation

    Returns
    -------

    """
    if self.is_stator:
        lam_color = STATOR_COLOR
    else:
        lam_color = ROTOR_COLOR
    (fig, axes, patch_leg, label_leg) = init_fig(fig)

    surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta)
    patches = list()

    # Color Selection for Lamination
    for surf in surf_list:
        if surf.label is not None and "_Ext" in surf.label:
            patches.append(surf.get_patch(color=lam_color))
        elif surf.label is not None and "Ventilation_" in surf.label:
            patches.append(
                surf.get_patch(color=VENT_COLOR, edgecolor=VENT_EDGE))
        else:
            patches.append(surf.get_patch())

    # Display the result
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    for patch in patches:
        axes.add_patch(patch)

    # Axis Setup
    axis("equal")

    # The Lamination is centered in the figure
    Lim = self.Rext * 1.5
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    if self.is_stator:
        patch_leg.append(Patch(color=STATOR_COLOR))
        label_leg.append("Stator")
        axes.set_title("Stator without slot")
    else:
        patch_leg.append(Patch(color=ROTOR_COLOR))
        label_leg.append("Rotor")
        axes.set_title("Rotor without slot")

    legend(patch_leg, label_leg)
    fig.show()
Esempio n. 13
0
def plot(self,
         fig=None,
         sym=1,
         alpha=0,
         delta=0,
         is_edge_only=False,
         comp_machine=None):
    """Plot the Machine in a matplotlib fig

    Parameters
    ----------
    self : Machine
        A Machine object
    fig :
        if None, open a new fig and plot, else add to the gcf (Default value = None)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation
    is_edge_only: bool
        To plot transparent Patches
    comp_machine : Machine
        A machine to plot in transparency on top of the self machine

    Returns
    -------
    None

    """
    # Display
    # fig, axes = subplots()
    (fig, axes, patch_leg, label_leg) = init_fig(fig)

    # Get the patches to display from corresponding plot
    # The order in the list matters (largest to smallest)
    if self.frame is not None:
        plot_frame = self.frame.plot
        Wfra = self.frame.comp_height_eq()
    else:
        plot_frame = None
        Wfra = 0

    # Determin order of plotting parts
    plot_int, plot_ext, plot_shaft = None, None, None
    Rext = 0

    if self.rotor is not None:
        if self.rotor.is_internal:
            plot_int = self.rotor.plot
            if self.rotor.Rint > 0 and self.shaft is not None:
                plot_shaft = self.shaft.plot
        else:
            plot_ext = self.rotor.plot
        Rext = self.rotor.Rext  # will be reset by stator in case

    if self.stator is not None:
        if self.stator.is_internal:
            plot_int = self.stator.plot
        else:
            plot_ext = self.stator.plot
        if self.stator.Rext > Rext:
            Rext = self.stator.Rext

    Lim = (Rext + Wfra) * 1.5  # Axes limit for plot

    # Plot
    plot_args = {
        "sym": sym,
        "alpha": alpha,
        "delta": delta,
        "is_edge_only": is_edge_only,
    }

    _plot(plot_frame, fig, plot_args)
    _plot(plot_ext, fig, plot_args)
    _plot(plot_int, fig, plot_args)
    _plot(plot_shaft, fig, plot_args)

    if comp_machine is not None:
        comp_machine.rotor.plot(fig,
                                sym=sym,
                                alpha=alpha,
                                delta=delta,
                                is_edge_only=True)
        comp_machine.stator.plot(fig,
                                 sym=sym,
                                 alpha=alpha,
                                 delta=delta,
                                 is_edge_only=True)

    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title(self.name)

    # Axis Setup
    axis("equal")

    # The Lamination is centered in the figure
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)
    fig.show()
Esempio n. 14
0
def plot(self,
         fig=None,
         is_lam_only=False,
         sym=1,
         alpha=0,
         delta=0,
         is_edge_only=False):
    """Plot a Lamination with Buried Magnets in a matplotlib fig

    Parameters
    ----------
    self : LamHole
        A LamHole object
    fig :
        if None, open a new fig and plot, else add to the
        current one (Default value = None)
    is_lam_only: bool
        True to plot only the lamination (remove the magnets)
    sym : int
        Symmetry factor (1= plot full machine, 2= half of the machine...)
    alpha : float
        angle for rotation (Default value = 0) [rad]
    delta : complex
        complex for translation (Default value = 0)
    is_edge_only: bool
        To plot transparent Patches

    Returns
    -------
    None
    """

    # Lamination bore
    if self.is_stator:
        lam_color = STATOR_COLOR
    else:
        lam_color = ROTOR_COLOR

    # List of surface to plot the lamination
    surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta)
    patches = list()
    for surf in surf_list:
        if (surf.label is not None and "Lamination" in surf.label
                and "Ext" in surf.label):
            patches.append(
                surf.get_patch(color=lam_color, is_edge_only=is_edge_only))
        elif surf.label is not None and "Magnet" in surf.label:
            if is_lam_only:
                patches.append(surf.get_patch(color="w", edgecolor="w"))
            else:
                patches.append(
                    surf.get_patch(color=MAGNET_COLOR,
                                   is_edge_only=is_edge_only))
        else:
            patches.append(surf.get_patch(is_edge_only=is_edge_only))

    # Display the result
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")

    for patch in patches:
        axes.add_patch(patch)
    # Axis Setup
    axis("equal")

    # The Lamination is centered in the figure
    Lim = self.Rext * 1.5
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    # Set legend
    if not is_edge_only:
        if self.is_stator:
            patch_leg.append(Patch(color=STATOR_COLOR))
            label_leg.append("Stator")
            axes.set_title("Stator with Interior Magnet")
        else:
            patch_leg.append(Patch(color=ROTOR_COLOR))
            label_leg.append("Rotor")
            axes.set_title("Rotor with Interior Magnet")
        if not is_lam_only:
            patch_leg.append(Patch(color=MAGNET_COLOR))
            label_leg.append("Magnet")
        legend(patch_leg, label_leg)
    fig.show()
Esempio n. 15
0
def plot_wind(self, wind_mat=None, fig=None, is_bar=False):
    """Plot the winding area of the lamination according to the wind_mat

    Parameters
    ----------
    self : SlotWind
        A SlotWind object
    wind_mat : numpy.ndarray
        A matrix [Nrad,Ntan,Zs,qs] representing the winding (Default value = None)
    fig :
        if None, open a new fig and plot, else add to the current
        one (Default value = None)
    is_bar : bool
        To adapt the legend text for squirrel cage bar (Default value = False)

    Returns
    -------
    None
    """

    if wind_mat is None:  # Default : Only one zone monocolor
        Nrad, Ntan, qs = 1, 1, 1
        Zs = self.Zs
    else:
        (Nrad, Ntan, Zs, qs) = wind_mat.shape

    surf_list = self.build_geometry_wind(Nrad, Ntan)

    patches = list()
    for ii in range(len(surf_list)):
        # Compute the coordinate for one zone
        point_list = list()
        for curve in surf_list[ii].get_lines():
            point_list.extend(curve.discretize().tolist())
        point_list = array(point_list)

        for jj in range(Zs):
            if wind_mat is None or len(surf_list) != Ntan * Nrad:
                x, y = point_list.real, point_list.imag
                patches.append(Polygon(list(zip(x, y)), color=PHASE_COLOR[0]))
            else:
                # print "Nrad, Ntan, Zs : "+str((ii%Nrad,ii/Nrad,jj))
                color = get_color(wind_mat, ii % Nrad, ii // Nrad, jj)
                x, y = point_list.real, point_list.imag
                patches.append(Polygon(list(zip(x, y)), color=color))
            point_list = point_list * exp(1j * (2 * pi) / self.Zs)

    # Display the result
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title("Winding Pattern")

    # Add the magnet to the fig
    for patch in patches:
        axes.add_patch(patch)

    # Axis Setup
    axis("equal")
    Rbo = self.get_Rbo()

    Lim = Rbo * 1.2
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    # Legend setup
    if wind_mat is None or len(surf_list) != Ntan * Nrad:
        # No winding matrix => Only one zone
        if not is_bar and not ("Winding" in label_leg):
            # Avoid adding twice the same label
            patch_leg.append(Patch(color=PHASE_COLOR[0]))
            label_leg.append("Winding")
        elif is_bar and not ("Rotor bar" in label_leg):
            # Avoid adding twice the same label
            patch_leg.append(Patch(color=PHASE_COLOR[0]))
            label_leg.append("Rotor bar")
    else:  # Add every phase to the legend
        for ii in range(qs):
            if not ("Phase " + PHASE_NAME[ii] in label_leg):
                # Avoid adding twice the same label
                index = ii % len(PHASE_COLOR)
                patch_leg.append(Patch(color=PHASE_COLOR[index]))
                label_leg.append("Phase " + PHASE_NAME[ii])

    legend(patch_leg, label_leg)
    fig.show()
Esempio n. 16
0
def plot(
    self,
    fig=None,
    is_lam_only=False,
    sym=1,
    alpha=0,
    delta=0,
    is_edge_only=False,
    is_display=True,
):
    """Plot the Lamination with empty Slots in a matplotlib fig

    Parameters
    ----------
    self : LamSlot
        A LamSlot object
    fig :
        if None, open a new fig and plot, else add to the
        current one (Default value = None)
    is_lam_only: bool
        True to plot only the lamination (No effect for LamSlot)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation
    is_edge_only: bool
        To plot transparent Patches
    is_display : bool
        False to return the patches
    Returns
    -------
    patches : list
        List of Patches
    """

    if self.is_stator:
        lam_color = STATOR_COLOR
    else:
        lam_color = ROTOR_COLOR

    (fig, axes, patch_leg, label_leg) = init_fig(fig)

    surf_list = self.build_geometry(sym=sym, alpha=alpha, delta=delta)
    patches = list()
    for surf in surf_list:
        if "Ext" in surf.label:
            patches.append(
                surf.get_patch(color=lam_color, is_edge_only=is_edge_only))
        else:
            patches.append(surf.get_patch(is_edge_only=is_edge_only))
    # Display the result
    if is_display:
        (fig, axes, patch_leg, label_leg) = init_fig(fig)
        axes.set_xlabel("(m)")
        axes.set_ylabel("(m)")
        for patch in patches:
            axes.add_patch(patch)

        # Axis Setup
        axis("equal")

        # The Lamination is centered in the figure
        Lim = self.Rext * 1.5
        axes.set_xlim(-Lim, Lim)
        axes.set_ylim(-Lim, Lim)

        # Add the legend
        if not is_edge_only:
            if self.is_stator and "Stator" not in label_leg:
                patch_leg.append(Patch(color=STATOR_COLOR))
                label_leg.append("Stator")
                axes.set_title("Stator with empty slot")
            elif not self.is_stator and "Rotor" not in label_leg:
                patch_leg.append(Patch(color=ROTOR_COLOR))
                label_leg.append("Rotor")
                axes.set_title("Rotor with empty slot")

            legend(patch_leg, label_leg)
        fig.show()
    else:
        return patches
Esempio n. 17
0
def plot(self, fig=None, plot_winding=False, sym=1, alpha=0, delta=0):
    """Plot the Lamination in a matplotlib fig

    Parameters
    ----------
    self : LamSquirrelCage
        A LamSquirrelCage object
    fig :
        if None, open a new fig and plot, else add to the current
        one (Default value = None)
    plot_winding : bool
        If true, plot the bar and short circuit ring (Default value = False)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation

    Returns
    -------
    None
    """

    # Lamination and ventilation ducts patches
    (fig, axes, patch_leg, label_leg) = init_fig(fig)
    # Plot the lamination
    super(type(self), self).plot(fig,
                                 plot_winding=False,
                                 sym=sym,
                                 alpha=alpha,
                                 delta=delta)

    # Plot the winding if needed
    if plot_winding:
        # point needed to plot the bar of a slot
        Hbar = self.winding.conductor.Hbar
        Wbar = self.winding.conductor.Wbar
        if self.is_internal:
            HS = self.Rext - self.slot.comp_height(self.Rext)
            Bar_points = [
                HS + 1j * Wbar / 2,
                HS - 1j * Wbar / 2,
                HS + Hbar - 1j * Wbar / 2,
                HS + Hbar + 1j * Wbar / 2,
            ]
        else:
            HS = self.Rint + self.slot.comp_height(self.Rint)
            Bar_points = [
                HS + 1j * Wbar / 2,
                HS - 1j * Wbar / 2,
                HS - Hbar - 1j * Wbar / 2,
                HS - Hbar + 1j * Wbar / 2,
            ]
        Bar_array = array(Bar_points)
        # Computation of the coordinate of every bar by complex rotation
        bar_list = []
        for i in range(self.slot.Zs):
            bar_list.append(Bar_array * exp(-1j * i * (2 * pi) / self.slot.Zs))

        patches = list()
        # Creation of the bar patches
        for wind in bar_list:
            patches.append(Polygon(zip(wind.real, wind.imag), color=BAR_COLOR))

        # Add the Short Circuit Ring
        if self.is_internal:
            Rmw = self.slot.comp_radius_mid_wind(self.Rext)
        else:
            Rmw = self.slot.comp_radius_mid_wind(self.Rint)
        patches.append(
            Wedge((0, 0),
                  Rmw + self.Hscr / 2.0,
                  0,
                  360,
                  width=self.Hscr,
                  color=SCR_COLOR))  # Full ring

    # Display the result
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    axes.set_title("Squirrel Cage Rotor")

    # Axis Setup
    axis("equal")
    Lim = self.Rext * 1.5
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)

    if plot_winding:
        # Add the magnet to the fig
        for patch in patches:
            axes.add_patch(patch)
        # Legend setup (Rotor already setup by LamSlotWind.plot)
        patch_leg.append(Patch(color=BAR_COLOR))
        label_leg.append("Rotor Bar")
        patch_leg.append(Patch(color=SCR_COLOR))
        label_leg.append("Short Circuit Ring")

        legend(patch_leg, label_leg)
    fig.show()
Esempio n. 18
0
def plot(self,
         fig=None,
         sym=1,
         alpha=0,
         delta=0,
         is_edge_only=False,
         comp_machine=None):
    """Plot the Machine in a matplotlib fig

    Parameters
    ----------
    self : MachineUD
        A MachineUD object
    fig :
        if None, open a new fig and plot, else add to the gcf (Default value = None)
    sym : int
        Symmetry factor (1= full machine, 2= half of the machine...)
    alpha : float
        Angle for rotation [rad]
    delta : complex
        Complex value for translation
    is_edge_only: bool
        To plot transparent Patches
    comp_machine : Machine
        A machine to plot in transparency on top of the self machine

    Returns
    -------
    None

    """
    # Display
    # fig, axes = subplots()
    (fig, axes, patch_leg, label_leg) = init_fig(fig)

    plot_list = list()
    # Get the patches to display from corresponding plot
    # The order in the list matters (largest to smallest)
    if self.frame is not None:
        plot_list.append(self.frame.plot)
        Wfra = self.frame.comp_height_eq()
    else:
        Wfra = 0

    Rext = 0
    for lam in self.lam_list:
        plot_list.append(lam.plot)
        Rext = max(Rext, lam.Rext)

    Lim = (Rext + Wfra) * 1.5  # Axes limit for plot

    # Plot
    plot_args = {
        "sym": sym,
        "alpha": alpha,
        "delta": delta,
        "is_edge_only": is_edge_only,
    }

    for plot_fct in plot_list:
        _plot(plot_fct, fig, plot_args)

    if comp_machine is not None:
        raise ValueError("Comp_machine is not available for MachineUD")
    axes.set_xlabel("(m)")
    axes.set_ylabel("(m)")
    if self.name in [None, ""]:
        axes.set_title("Machine")
    else:
        axes.set_title(self.name)

    # Axis Setup
    axis("equal")

    # The Lamination is centered in the figure
    axes.set_xlim(-Lim, Lim)
    axes.set_ylim(-Lim, Lim)
    fig.show()