Example #1
0
    def set_avd(self):
        """Open the GUI to allow the edition of the axial ventilation duct

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        self.avd_win = DAVDuct(self.obj)
        return_code = self.avd_win.exec_()
        if return_code == QDialog.Accepted:
            # self.obj.axial_vent = self.avd_win.vent
            self.update_avd_text()
            # Notify the machine GUI that the machine has changed
            self.saveNeeded.emit()
Example #2
0
    def test_init_trap(self):
        """Check that the Widget initialise for polar ventilations"""
        # Init the widget with Polar vent
        self.test_obj.axial_vent = [
            VentilationTrap(Zh=4,
                            H0=24e-3,
                            D0=34e-3,
                            W1=44e-3,
                            W2=54e-3,
                            Alpha0=0)
        ]
        self.widget = DAVDuct(self.test_obj)

        self.assertEqual(self.widget.tab_vent.count(), 1)
        self.assertEqual(self.widget.tab_vent.currentIndex(), 0)

        # First set
        self.assertEqual(type(self.widget.tab_vent.widget(0).w_vent),
                         PVentTrap)
        self.assertEqual(
            self.widget.tab_vent.widget(0).c_vent_type.currentIndex(), 1)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.si_Zh.value(), 4)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_H0.value(), 24e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_D0.value(), 34e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_W1.value(), 44e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_W2.value(), 54e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_Alpha0.value(), 0)
Example #3
0
    def setUp(self):
        """Run at the begining of every test to setup the gui"""

        self.test_obj = Lamination(Rint=0.1,
                                   Rext=1,
                                   is_stator=True,
                                   is_internal=True)
        self.test_obj.axial_vent.append(
            VentilationCirc(Zh=8, H0=10e-3, D0=40e-3, Alpha0=0))
        self.test_obj.axial_vent.append(
            VentilationCirc(Zh=9, H0=20e-3, D0=50e-3, Alpha0=0))

        self.widget = DAVDuct(self.test_obj)
Example #4
0
    def test_init_all_type(self):
        """Check that you can combine several kind of ventilations
        """
        self.test_obj = Lamination(Rint=0.1,
                                   Rext=1,
                                   is_stator=True,
                                   is_internal=True)
        self.test_obj.axial_vent.append(
            VentilationCirc(Zh=8, H0=10e-3, D0=40e-3, Alpha0=0))
        self.test_obj.axial_vent.append(
            VentilationTrap(Zh=4,
                            H0=24e-3,
                            D0=34e-3,
                            W1=44e-3,
                            W2=54e-3,
                            Alpha0=0))
        self.test_obj.axial_vent.append(
            VentilationPolar(Zh=3, H0=23e-3, D0=33e-3, W1=43e-3, Alpha0=0))
        self.widget = DAVDuct(self.test_obj)

        self.assertEqual(self.widget.tab_vent.count(), 3)
        self.assertEqual(self.widget.tab_vent.currentIndex(), 0)

        # First set
        self.assertEqual(type(self.widget.tab_vent.widget(0).w_vent),
                         PVentCirc)
        self.assertEqual(
            self.widget.tab_vent.widget(0).c_vent_type.currentIndex(), 0)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.si_Zh.value(), 8)

        # 2nd set
        self.assertEqual(type(self.widget.tab_vent.widget(1).w_vent),
                         PVentTrap)
        self.assertEqual(
            self.widget.tab_vent.widget(1).c_vent_type.currentIndex(), 1)
        self.assertEqual(
            self.widget.tab_vent.widget(1).w_vent.si_Zh.value(), 4)

        # 3rd set
        self.assertEqual(type(self.widget.tab_vent.widget(2).w_vent),
                         PVentPolar)
        self.assertEqual(
            self.widget.tab_vent.widget(2).c_vent_type.currentIndex(), 2)
        self.assertEqual(
            self.widget.tab_vent.widget(2).w_vent.si_Zh.value(), 3)
Example #5
0
class SLamParam(Gen_SLamParam, QWidget):
    """Step to setup the main lamination parameters
    """

    # Signal to DMachineSetup to know that the save popup is needed
    saveNeeded = pyqtSignal()
    # Information for the DMachineSetup nav
    step_name = "Lamination"

    def __init__(self, machine, matlib=[], is_stator=False):
        """Initialize the widget according to machine

        Parameters
        ----------
        self : SLamParam
            A SLamParam widget
        machine : Machine
            current machine to edit
        matlib : list
            List of available Material
        is_stator : bool
            To adapt the GUI to set either the stator or the rotor
        """

        # Build the interface according to the .ui file
        QWidget.__init__(self)
        self.setupUi(self)

        # Saving arguments
        self.machine = machine
        self.matlib = matlib
        self.is_stator = is_stator

        # Set FloatEdit unit
        self.lf_L1.unit = "m"
        self.lf_Wrvd.unit = "m"
        self.u = gui_option.unit
        self.unit_L1.setText(self.u.get_m_name())
        self.unit_Wrvd.setText(self.u.get_m_name())

        # Get the correct object to set
        if self.is_stator:
            self.obj = machine.stator
            if self.obj.Kf1 is None:
                self.obj.Kf1 = 0.95  # Defaut value
        else:
            self.obj = machine.rotor
            if self.obj.L1 is None:
                # Default value for rotor is the stator one
                self.obj.L1 = self.machine.stator.L1
            if self.obj.Kf1 is None:
                # Default value for rotor is the stator one
                self.obj.Kf1 = self.machine.stator.Kf1

        self.w_mat.update(self.obj.mat_type, matlib)

        self.lf_L1.setValue(self.obj.L1)
        self.lf_Kf1.setValue(self.obj.Kf1)

        # Ventilation setup
        self.update_avd_text()
        if len(self.obj.axial_vent) > 0 and self.obj.axial_vent[0].Zh > 0:
            self.g_ax_vent.setChecked(True)

        if self.obj.Nrvd is None or self.obj.Nrvd == 0:
            self.si_Nrvd.setValue(0)
        else:
            self.si_Nrvd.setValue(self.obj.Nrvd)
            self.g_rad_vent.setChecked(True)

        if self.obj.Wrvd is None or self.obj.Wrvd == 0:
            self.lf_Wrvd.setValue(0)
        else:
            self.lf_Wrvd.setValue(self.obj.Wrvd)
            self.g_rad_vent.setChecked(True)

        self.update_lenght()  # Update out_length if possible

        # Connecting the signal
        self.lf_L1.editingFinished.connect(self.set_L1)
        self.lf_Kf1.editingFinished.connect(self.set_Kf1)
        self.g_rad_vent.toggled.connect(self.enable_rad_vent)
        self.g_ax_vent.toggled.connect(self.enable_ax_vent)
        self.b_axial_duct.clicked.connect(self.set_avd)
        self.si_Nrvd.editingFinished.connect(self.set_Nrvd)
        self.lf_Wrvd.editingFinished.connect(self.set_Wrvd)
        self.b_plot.clicked.connect(self.s_plot)
        self.w_mat.saveNeeded.connect(self.emit_save)

    def emit_save(self):
        self.saveNeeded.emit()

    def set_L1(self):
        """Signal to update the value of L1 according to the line edit

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        if self.lf_L1.value() != self.obj.L1:
            self.obj.L1 = self.lf_L1.value()
            self.update_lenght()
            # Notify the machine GUI that the machine has changed
            self.saveNeeded.emit()

    def set_Kf1(self):
        """Signal to update the value of Kf1 according to the line edit

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        self.obj.Kf1 = self.lf_Kf1.value()
        # Notify the machine GUI that the machine has changed
        self.saveNeeded.emit()

    def enable_rad_vent(self, is_checked):
        """Clear radial vent value if g_rad_vent is unselected

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        is_checked : bool
            State of the g_rad_vent checkbox
        """
        if not is_checked:
            self.lf_Wrvd.setValue(0)
            self.si_Nrvd.setValue(0)
            self.set_Nrvd()
            self.set_Wrvd()
            self.update_lenght()
        # Notify the machine GUI that the machine has changed
        self.saveNeeded.emit()

    def enable_ax_vent(self, is_checked):
        """Clear axial vent value if g_ax_vent is unselected

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        is_checked : bool
            State of the g_ax_vent checkbox
        """
        if not is_checked:
            self.obj.axial_vent = list()  # Default empty
            self.update_avd_text()
        # Notify the machine GUI that the machine has changed
        self.saveNeeded.emit()

    def set_avd(self):
        """Open the GUI to allow the edition of the axial ventilation duct

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        self.avd_win = DAVDuct(self.obj)
        return_code = self.avd_win.exec_()
        if return_code == QDialog.Accepted:
            # self.obj.axial_vent = self.avd_win.vent
            self.update_avd_text()
            # Notify the machine GUI that the machine has changed
            self.saveNeeded.emit()

    def update_avd_text(self):
        """Update the text with the current number of axial vent

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        Nset = 0
        Nduct = 0
        for vent in self.obj.axial_vent:
            Nset += 1
            Nduct += vent.Zh
        self.out_axial_duct.setText(
            self.tr("Axial: ", "Part of Axial: X set (Y ducts)") + str(Nset) +
            self.tr(" set (", "Part of Axial: X set (Y ducts)") + str(Nduct) +
            self.tr(" ducts)", "Part of Axial: X set (Y ducts)"))

    def set_Nrvd(self):
        """Signal to update the value of Nrvd according to the spinbox

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        self.obj.Nrvd = self.si_Nrvd.value()
        self.update_lenght()
        # Notify the machine GUI that the machine has changed
        self.saveNeeded.emit()

    def set_Wrvd(self):
        """Signal to update the value of Wrvd according to the line edit

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        self.obj.Wrvd = self.lf_Wrvd.value()
        self.update_lenght()
        # Notify the machine GUI that the machine has changed
        self.saveNeeded.emit()

    def update_lenght(self):
        """Update the text of out_length

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        if self.obj.is_stator:  # Adapt the text to the current lamination
            lam_txt = self.tr("Stator total length = L1 + Nrvd * Wrvd = ")
        else:
            lam_txt = self.tr("Rotor total length = L1 + Nrvd * Wrvd = ")

        if self.obj.L1 is None or self.obj.Nrvd is None or self.obj.Wrvd is None:
            self.out_length.setText(lam_txt + "?")
        else:
            length = format(
                self.u.get_m(self.obj.L1 + self.obj.Nrvd * self.obj.Wrvd),
                ".4g")
            self.out_length.setText(lam_txt + length + " " +
                                    self.u.get_m_name())

    @staticmethod
    def check(lamination):
        """Check that the current machine have all the needed field set

        Parameters
        ----------
        lamination : Lamination
            Lamination to check

        Returns
        -------
        error : str
            Error message (return None if no error)
        """

        # Check that everything is set
        if lamination.L1 is None:
            return "You must set L1 !"
        elif lamination.Kf1 is None:
            return "You must set Kf1 !"

    def check_gui(self):
        """Check that the widget are set right according to the current machine

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """
        if self.g_rad_vent.isChecked() and self.obj.Nrvd is None:
            return self.tr("You must set Nrvd or unchecked "
                           "radial Ventilation !")
        if self.g_rad_vent.isChecked() and self.obj.Wrvd is None:
            return self.tr("You must set Wrvd or unchecked "
                           "radial Ventilation !")
        if self.g_ax_vent.isChecked() and len(self.obj.axial_vent) == 0:
            return self.tr("You must add some Axial Ventilation Ducts or "
                           "unchecked Axial Ventilation !")

        if not self.g_rad_vent.isChecked():
            self.obj.Nrvd = 0
            self.obj.Wrvd = 0
        if not self.g_ax_vent.isChecked():
            self.obj.axial_vent = list()  # Default empty

    def s_plot(self):
        """Plot the lamination (radial and axial) if possible

        Parameters
        ----------
        self : SLamParam
            A SLamParam object
        """

        # We use an empty lamination for the plot to avoid problem with magnet
        # or winding which are not setup yet
        if self.obj.Rint is None:
            QMessageBox().critical(
                self,
                self.tr("Error"),
                self.tr("Unable to plot the lamination "
                        "(Rint missing)"),
            )
        elif self.obj.Rext is None:
            QMessageBox().critical(
                self,
                self.tr("Error"),
                self.tr("Unable to plot the lamination "
                        "(Rext missing)"),
            )
        else:
            plot_obj = Lamination(Rint=self.obj.Rint,
                                  Rext=self.obj.Rext,
                                  axial_vent=self.obj.axial_vent)
            if self.obj.is_stator is not None:
                plot_obj.is_stator = self.obj.is_stator
            plot_obj.plot()
            gcf().canvas.set_window_title(
                self.tr("Lamination (without slots) Front view"))
Example #6
0
    def test_init_polar(self):
        """Check that the Widget initialise for polar ventilations
        """
        # Init the widget with Polar vent
        vent = list()
        vent.append(
            VentilationPolar(Zh=1, H0=21e-3, D0=31e-3, W1=41e-3, Alpha0=0))
        vent.append(
            VentilationPolar(Zh=2, H0=22e-3, D0=32e-3, W1=42e-3, Alpha0=0))
        vent.append(
            VentilationPolar(Zh=3, H0=23e-3, D0=33e-3, W1=43e-3, Alpha0=0))

        self.test_obj.axial_vent = vent
        self.widget = DAVDuct(self.test_obj)

        self.assertEqual(self.widget.tab_vent.count(), 3)
        self.assertEqual(self.widget.tab_vent.currentIndex(), 0)

        # First set
        self.assertEqual(type(self.widget.tab_vent.widget(0).w_vent),
                         PVentPolar)
        self.assertEqual(
            self.widget.tab_vent.widget(0).c_vent_type.currentIndex(), 2)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.si_Zh.value(), 1)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_H0.value(), 21e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_D0.value(), 31e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_W1.value(), 41e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(0).w_vent.lf_Alpha0.value(), 0)

        # 2nd set
        self.assertEqual(type(self.widget.tab_vent.widget(1).w_vent),
                         PVentPolar)
        self.assertEqual(
            self.widget.tab_vent.widget(1).c_vent_type.currentIndex(), 2)
        self.assertEqual(
            self.widget.tab_vent.widget(1).w_vent.si_Zh.value(), 2)
        self.assertEqual(
            self.widget.tab_vent.widget(1).w_vent.lf_H0.value(), 22e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(1).w_vent.lf_D0.value(), 32e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(1).w_vent.lf_W1.value(), 42e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(1).w_vent.lf_Alpha0.value(), 0)

        # 3rd set
        self.assertEqual(type(self.widget.tab_vent.widget(2).w_vent),
                         PVentPolar)
        self.assertEqual(
            self.widget.tab_vent.widget(2).c_vent_type.currentIndex(), 2)
        self.assertEqual(
            self.widget.tab_vent.widget(2).w_vent.si_Zh.value(), 3)
        self.assertEqual(
            self.widget.tab_vent.widget(2).w_vent.lf_H0.value(), 23e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(2).w_vent.lf_D0.value(), 33e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(2).w_vent.lf_W1.value(), 43e-3)
        self.assertEqual(
            self.widget.tab_vent.widget(2).w_vent.lf_Alpha0.value(), 0)