コード例 #1
0
class CouplingDelegate(QItemDelegate):
    """
    Use of a combo box in the table.
    """
    def __init__(self, parent, mdl, dicoM2V, dicoV2M):
        super(CouplingDelegate, self).__init__(parent)
        self.parent = parent
        self.mdl = mdl
        self.dicoM2V = dicoM2V
        self.dicoV2M = dicoV2M

    def createEditor(self, parent, option, index):
        editor = QComboBox(parent)
        self.modelCombo = ComboModel(editor, 1, 1)
        fieldId = index.row() + 1

        if self.mdl.getCriterion(fieldId) == "continuous":
            self.modelCombo.addItem(self.tr(self.dicoM2V["none"]), "none")
            self.modelCombo.disableItem(str_model="none")
        else:
            self.modelCombo.addItem(self.tr(self.dicoM2V["none"]), "none")
            carrier = self.mdl.getCarrierField(fieldId)
            if self.mdl.getTurbulenceModel(carrier) == "k-epsilon" or \
               self.mdl.getTurbulenceModel(carrier) == "k-epsilon_linear_production" or \
               self.mdl.getTurbulenceModel(carrier) == "rij-epsilon_ssg" or \
               self.mdl.getTurbulenceModel(carrier) == "rij-epsilon_ebrsm":
                if self.mdl.getFieldNature(fieldId) == "gas":
                    # bulles
                    self.modelCombo.addItem(
                        self.tr(self.dicoM2V["large_inclusions"]),
                        "large_inclusions")
                else:
                    # gouttes et solide
                    self.modelCombo.addItem(
                        self.tr(self.dicoM2V["small_inclusions"]),
                        "small_inclusions")

        editor.setMinimumSize(editor.sizeHint())
        editor.installEventFilter(self)
        return editor

    def setEditorData(self, comboBox, index):
        row = index.row()
        col = index.column()
        string = index.model().getData(index)[col]
        self.modelCombo.setItem(str_view=string)

    def setModelData(self, comboBox, model, index):
        txt = str(comboBox.currentText())
        value = self.modelCombo.dicoV2M[txt]
        log.debug("CouplingDelegate value = %s" % value)

        selectionModel = self.parent.selectionModel()
        for idx in selectionModel.selectedIndexes():
            if idx.column() == index.column():
                model.setData(idx, self.dicoM2V[value], Qt.DisplayRole)
コード例 #2
0
class TurbFluxDelegate(QItemDelegate):
    """
    Use of a combobox in the table.
    """
    def __init__(self, parent, mdl, dicoM2V, dicoV2M):
        super(TurbFluxDelegate, self).__init__(parent)
        self.parent = parent
        self.mdl = mdl
        self.dicoM2V = dicoM2V
        self.dicoV2M = dicoV2M

    def createEditor(self, parent, option, index):
        editor = QComboBox(parent)
        self.modelCombo = ComboModel(editor, 1, 1)
        fieldId = index.row() + 1

        if self.mdl.getEnergyResolution(fieldId) == 'on':
            if self.mdl.useAdvancedThermalFluxes(fieldId) == True:
                for turbFlux in TurbulenceModelsDescription.ThermalTurbFluxModels:
                    self.modelCombo.addItem(self.tr(self.dicoM2V[turbFlux]),
                                            turbFlux)

            else:
                turb_flux = TurbulenceModelsDescription.ThermalTurbFluxModels[
                    0]
                self.modelCombo.addItem(self.tr(self.dicoM2V[turbFlux]),
                                        turbFlux)
                self.modelCombo.disableItem(index=0)
        else:
            self.modelCombo.addItem(self.tr(self.dicoM2V['none']), 'none')
            self.modelCombo.setItem(str_view='none')

        editor.setMinimumSize(editor.sizeHint())
        editor.installEventFilter(self)
        return editor

    def setEditorData(self, comboBox, index):
        row = index.row()
        col = index.column()
        string = index.model().getData(index)[col]
        self.modelCombo.setItem(str_view=string)

    def setModelData(self, comboBox, model, index):
        txt = str(comboBox.currentText())
        value = self.modelCombo.dicoV2M[txt]
        log.debug("TurbFluxDelegate value = %s" % value)

        selectionModel = self.parent.selectionModel()
        for idx in selectionModel.selectedIndexes():
            if idx.column() == index.column():
                model.setData(idx, self.dicoM2V[value], Qt.DisplayRole)
コード例 #3
0
class CriterionDelegate(QItemDelegate):
    """
    Use of a combo box in the table.
    """
    def __init__(self, parent):
        super(CriterionDelegate, self).__init__(parent)
        self.parent   = parent


    def createEditor(self, parent, option, index):
        editor = QComboBox(parent)
        self.modelCombo = ComboModel(editor, 3, 1)
        self.modelCombo.addItem(self.tr("continuous"), 'continuous')
        self.modelCombo.addItem(self.tr("dispersed"), 'dispersed')
        self.modelCombo.addItem(self.tr("auto"), 'auto')
        # TODO to delete if/when the auto option is implemented
        self.modelCombo.disableItem(2)
        # fixed to continuous for field 1
        if index.row() == 0 :
            editor.setEnabled(False)

        editor.installEventFilter(self)
        return editor


    def setEditorData(self, comboBox, index):
        row = index.row()
        col = index.column()
        string = index.model().getData(index)[col]
        self.modelCombo.setItem(str_model=string)


    def setModelData(self, comboBox, model, index):
        txt = str(comboBox.currentText())
        value = self.modelCombo.dicoV2M[txt]
        log.debug("CriterionDelegate value = %s"%value)

        selectionModel = self.parent.selectionModel()
        for idx in selectionModel.selectedIndexes():
            if idx.column() == index.column():
                model.setData(idx, value, Qt.DisplayRole)
コード例 #4
0
class NatureDelegate(QItemDelegate):
    """
    Use of a combo box in the table.
    """
    def __init__(self, parent):
        super(NatureDelegate, self).__init__(parent)
        self.parent   = parent


    def createEditor(self, parent, option, index):
        editor = QComboBox(parent)
        self.modelCombo = ComboModel(editor, 3, 1)
        self.modelCombo.addItem(self.tr("liquid"), 'liquid')
        self.modelCombo.addItem(self.tr("gas"), 'gas')
        self.modelCombo.addItem(self.tr("solid"), 'solid')

        row = index.row()
        if (row == 0) :
            self.modelCombo.disableItem(2)
        else :
            self.modelCombo.enableItem(2)

        editor.installEventFilter(self)
        return editor


    def setEditorData(self, comboBox, index):
        col = index.column()
        string = index.model().getData(index)[col]
        self.modelCombo.setItem(str_model=string)


    def setModelData(self, comboBox, model, index):
        txt = str(comboBox.currentText())
        value = self.modelCombo.dicoV2M[txt]
        log.debug("NatureDelegate value = %s"%value)

        selectionModel = self.parent.selectionModel()
        for idx in selectionModel.selectedIndexes():
            if idx.column() == index.column():
                model.setData(idx, value, Qt.DisplayRole)
コード例 #5
0
class OpenTurnsDialogView(QDialog, Ui_OpenTurnsDialogForm):
    """
    OpenTurns Page viewer class
    """
    def __init__(self, parent, case):
        """
        Constructor
        """
        QDialog.__init__(self, parent)

        Ui_OpenTurnsDialogForm.__init__(self)
        self.setupUi(self)

        self.case = case
        self.parent = parent

        title = self.tr("OpenTURNS parameters")
        self.setWindowTitle(title)

        self.case.undoStopGlobal()

        case_is_saved = not self.case.isModified()

        self.mdl = OpenTurnsModel(case)
        if not self.mdl.getHostName():
            self.mdl.setDefaultOptions()

        # Combo model
        config = configparser.ConfigParser()
        config.read(self.case['package'].get_configfiles())
        self.nmodes = 1

        dist_hosts = None
        if config.has_section('distant_hosts'):
            if len(config.options('distant_hosts')) != 0:
                dist_hosts = config.options('distant_hosts')
                self.nmodes += len(dist_hosts)

        self.modelOtStudyHosts = ComboModel(self.comboBoxStudyMode,
                                            self.nmodes, 1)
        self.modelOtStudyHosts.addItem(self.tr("Localhost"), 'localhost')

        self.hosts_bmgr = {}
        if config.has_option('install', 'batch'):
            self.hosts_bmgr['localhost'] = (config.get('install',
                                                       'batch')).lower()
        else:
            self.hosts_bmgr['localhost'] = 'none'

        # Check for distant builds:
        # Hosts are stored in the form <batch_rm>_<host_name> hence the split
        # used hereafter to determine the "real" host name
        self.hosts_binpath = {}
        self.hosts_binpath['localhost'] = 'default'

        self.distant_host_builds = None
        if dist_hosts != None:
            self.distant_host_builds = {}
            for key in dist_hosts:
                host_name = key.split('_')[1]
                self.hosts_bmgr[host_name] = key.split('_')[0]

                self.hosts_binpath[host_name] = config.get(
                    'distant_hosts', key)

                self.addDistantBuilds(host_name)

                dh_not_found = False
                if self.distant_host_builds[host_name] is None:
                    self.distant_host_builds[host_name] = ['none found']
                    dh_not_found = True

                host_tag = 'distant : ' + host_name
                self.modelOtStudyHosts.addItem(self.tr(host_tag),
                                               host_name,
                                               warn=dh_not_found)
                if dh_not_found:
                    self.modelOtStudyHosts.disableItem(str_model=host_name)

        # ---------------------------------------
        # Connections:
        self.comboBoxStudyMode.activated[str].connect(self.slotOtStudyMode)
        self.comboBoxDistantBuilds.activated[str].connect(self.slotBuildChoice)

        self.lineEditDistWorkDir.textChanged[str].connect(self.slotOtDistWdir)

        self.spinBoxNumberNodes.valueChanged[int].connect(
            self.slotUpdateNodesNumber)
        self.spinBoxNumberTasks.valueChanged[int].connect(
            self.slotUpdateTasksNumber)
        self.spinBoxNumberThreads.valueChanged[int].connect(
            self.slotUpdateThreadsNumber)

        self.spinBoxNumberDays.valueChanged[int].connect(self.slotUpdateWCDays)
        self.spinBoxNumberHours.valueChanged[int].connect(
            self.slotUpdateWCHours)
        self.spinBoxNumberMinutes.valueChanged[int].connect(
            self.slotUpdateWCMinutes)
        self.spinBoxNumberSeconds.valueChanged[int].connect(
            self.slotUpdateWCSeconds)
        self.lineEditWCKEY.textChanged[str].connect(self.slotUpdateWckey)

        self.pushButtonLaunchOT.clicked.connect(self.slotLaunchCsOt)

        self.pushButtonCancel.clicked.connect(self.slotCancel)

        # ---------------------------------------
        # Hide/Show initial elements
        if self.nmodes == 1:
            self.groupBoxLocalLaunch.show()
            self.groupBoxDistantLaunch.hide()
            self.setAvailableBuildsList('localhost')
        else:
            self.setAvailableBuildsList(self.mdl.getHostName())
            if self.mdl.getHostName() == "localhost":
                self.groupBoxLocalLaunch.show()
                self.groupBoxDistantLaunch.hide()
            else:
                self.groupBoxLocalLaunch.hide()
                self.groupBoxDistantLaunch.show()

        # ---------------------------------------
        # Initial values
        if dist_hosts != None:
            self.modelOtStudyHosts.setItem(str_model=self.mdl.host_name)
        else:
            self.modelOtStudyHosts.setItem(str_model='localhost')

        self.spinBoxLocalProcs.setValue(int(self.mdl.nprocs))
        self.spinBoxLocalThreads.setValue(1)

        self.spinBoxNumberNodes.setValue(int(self.mdl.nnodes))
        self.spinBoxNumberTasks.setValue(int(self.mdl.ntasks))
        self.spinBoxNumberThreads.setValue(int(self.mdl.nthreads))

        wct = self.mdl.getWallClockTime()
        self.spinBoxNumberDays.setValue(int(wct[0]))
        self.spinBoxNumberHours.setValue(int(wct[1]))
        self.spinBoxNumberMinutes.setValue(int(wct[2]))
        self.spinBoxNumberSeconds.setValue(int(wct[3]))

        self.lineEditWCKEY.setText(self.mdl.getWCKEY())

        self.case.undoStartGlobal()

    @pyqtSlot(str)
    def slotOtStudyMode(self, text):
        """
        Host type: localhost or a distant one (defined in code_saturne.cfg).
        """
        host_name = self.modelOtStudyHosts.dicoV2M[str(text)]

        self.mdl.setHostName(host_name)
        self.mdl.setBatchManager(self.hosts_bmgr[host_name])

        if host_name != 'localhost':
            self.groupBoxDistantLaunch.show()
        else:
            self.groupBoxDistantLaunch.hide()

        self.setAvailableBuildsList(host_name)

        self.mdl.arch_path = self.hosts_binpath[host_name]

    @pyqtSlot(str)
    def slotBuildChoice(self, text):
        """
        Sets the hostname
        """
        self.mdl.setBuildName(text)

    @pyqtSlot(str)
    def slotOtDistWdir(self, text):
        """
        Set the distant workdir path
        """
        self.mdl.setDistWorkdir(text)

    @pyqtSlot(int)
    def slotUpdateNodesNumber(self, v):
        """
        Update the number of required computation nodes
        """

        n = int(self.spinBoxNumberNodes.text())
        self.mdl.setClusterParams(nnodes=n)

    @pyqtSlot(int)
    def slotUpdateNprocs(self, v):
        """
        Update the number of required processes
        """

        n = int(self.spinBoxLocalProcs.text())
        self.mdl.setNprocs(n)

    @pyqtSlot(int)
    def slotUpdateTasksNumber(self, v):
        """
        Update the number of required mpi tasks per node
        """

        n = int(self.spinBoxNumberTasks.text())
        self.mdl.setClusterParams(ntasks=n)

    @pyqtSlot(int)
    def slotUpdateThreadsNumber(self, v):
        """
        Update the number of required threads per processor
        """

        n = int(self.spinBoxNumberThreads.text())
        self.mdl.setClusterParams(nthreads=n)

    @pyqtSlot(int)
    def slotUpdateWCDays(self, v):
        """
        Update the wall clock days value
        """

        d, h, m, s = self.mdl.getWallClockTime()
        d = str(int(self.spinBoxNumberDays.text()))

        self.mdl.setWallClockTime(d, h, m, s)

    @pyqtSlot(int)
    def slotUpdateWCHours(self, v):
        """
        Update the wall clock hours value
        """

        d, h, m, s = self.mdl.getWallClockTime()
        h = str(int(self.spinBoxNumberHours.text()))

        self.mdl.setWallClockTime(d, h, m, s)

    @pyqtSlot(int)
    def slotUpdateWCMinutes(self, v):
        """
        Update the wall clock minutes value
        """

        d, h, m, s = self.mdl.getWallClockTime()
        m = str(int(self.spinBoxNumberMinutes.text()))

        self.mdl.setWallClockTime(d, h, m, s)

    @pyqtSlot(int)
    def slotUpdateWCSeconds(self, v):
        """
        Update the wall clock seconds value
        """

        d, h, m, s = self.mdl.getWallClockTime()
        s = str(int(self.spinBoxNumberSeconds.text()))

        self.mdl.setWallClockTime(d, h, m, s)

    @pyqtSlot(str)
    def slotUpdateWckey(self, text):
        """
        Update the WCKEY variable
        """

        self.mdl.setWCKEY(text)

    @pyqtSlot()
    def slotLaunchCsOt(self):
        """
        Translate the Code_Sature reference case and study into an OpenTurs
        physical model and study
        """
        QDialog.accept(self)

        if self.case['salome']:
            import salome_ot

            # Update the study cfg file
            self.mdl.update_cfg_file()

            # Generating OpenTurns _exec function
            self.create_cs_exec_function()

            # Load the code_saturne case as Physical model and launch
            # OpenTurns GUI
            cs_exec_script_name = os.path.join(self.mdl.otstudy_path,
                                               'cs_execute_job.py')
            salome_ot.loadYacsPyStudy(cs_exec_script_name)

        else:
            print(
                "This option is only available within the SALOME_CFD platform")

    @pyqtSlot()
    def slotCancel(self):
        """
        Close dialog with no modifications
        """

        QDialog.accept(self)

    def addDistantBuilds(self, host_name):
        """
        Search for the distant builds of code_saturne for the given distant
        host.
        """

        host_path = self.hosts_binpath[host_name]

        builds_list = __getListOfDistantBuilds__(host_name, host_path)

        self.distant_host_builds[host_name] = builds_list

    def setAvailableBuildsList(self, host_name):
        """
        Set the list of available builds per host
        """

        if host_name == 'localhost':

            self.groupBoxDistantLaunch.hide()
            self.groupBoxLocalLaunch.show()

            self.comboBoxDistantBuilds.hide()
            self.labelDistantBuilds.hide()
            return

        else:
            self.groupBoxDistantLaunch.show()
            self.groupBoxLocalLaunch.hide()

            self.comboBoxDistantBuilds.show()
            self.labelDistantBuilds.show()

            dist_builds_list = self.distant_host_builds[host_name]
            self.modelOtDistantBuilds = ComboModel(self.comboBoxDistantBuilds,
                                                   len(dist_builds_list), 1)
            for db in dist_builds_list:
                self.modelOtDistantBuilds.addItem(self.tr(db), db)

    def create_cs_exec_function(self):
        """
        This function generates the _exec function needed by OpenTurns for a study
        using distant launching on clusters.
        Takes as input:
            - code_saturne study path
            - OT_params.cfg name
            - list of OTurns input variables
            - list of OTurns output variables
            - the requested cluster name
            - the result file name which contains the output values
        """

        cluster = self.mdl.host_name

        exec_file_name = os.path.join(self.mdl.otstudy_path,
                                      'cs_execute_job.py')

        f = open(exec_file_name, 'w')

        script_cmd = "\n"
        script_cmd += "# ============================================================================== \n"
        script_cmd += "# OPENTURNS EXEC FUNCTION WHICH LAUNCHES CODE_SATURNE ON A DISTANT CLUSTER \n"
        script_cmd += "# ============================================================================== \n"

        script_cmd += "\n\n"

        nvars = len(self.mdl.input_variables)

        script_cmd = 'def _exec('
        vars_dict = '{'

        toffset = '    '
        cmd1 = 'cfd_eval = cfd_openturns_study('
        loffset1 = toffset
        for i in range(len(cmd1)):
            loffset1 += ' '

        loffset2 = '           '

        iv = -1
        for i in range(nvars):
            if i == 0:
                script_cmd += self.mdl.input_variables[i]
                vars_dict += '"' + self.mdl.input_variables[i] + '":'
                vars_dict += self.mdl.input_variables[i]
            else:
                script_cmd += ", " + self.mdl.input_variables[i]
                vars_dict += ', \n'
                vars_dict += loffset1 + loffset2 + '   '
                vars_dict += '"' + self.mdl.input_variables[i] + '":'
                vars_dict += self.mdl.input_variables[i]

        script_cmd += '):\n\n'
        vars_dict += '}'

        script_cmd += toffset + "import sys\n"

        salome_pydir = os.path.join(self.case['package'].dirs['pythondir'],
                                    'salome')
        script_cmd += toffset
        script_cmd += "sys.path.insert(-1, '%s')\n\n" % salome_pydir
        script_cmd += toffset + "from CFDSTUDYOTURNS_StudyInterface import cfd_openturns_study"
        script_cmd += "\n\n"

        script_cmd += toffset + cmd1 + 'study_path = "' + self.mdl.otstudy_path + '",\n'
        script_cmd += loffset1 + 'study_cfg  = "openturns_study.cfg",\n'
        script_cmd += loffset1 + 'vars_dico  = ' + vars_dict + ')\n\n'

        script_cmd += toffset + 'cfd_eval.study2code() \n\n'
        script_cmd += toffset + 'cfd_eval.run() \n\n'

        n_vals = len(self.mdl.output_variables)
        vals_list = ""
        for i in range(n_vals):
            if i != 0:
                vals_list += ', '
            vals_list += self.mdl.output_variables[i]

        cmd_m1 = '(%s,) = cfd_eval.code2study(n_values=%d)\n' % (vals_list,
                                                                 n_vals)
        script_cmd += toffset + cmd_m1

        script_cmd += '\n'

        script_cmd += toffset + 'return '
        script_cmd += vals_list + '\n'

        f.write(script_cmd)
        f.close()
コード例 #6
0
class NeptuneWallTransferView(QWidget, Ui_NeptuneWallTransferForm):
    def __init__(self, parent, case):
        QWidget.__init__(self, parent)
        Ui_NeptuneWallTransferForm.__init__(self)
        self.setupUi(self)

        self.case = case
        self.case.undoStopGlobal()
        self.xml_model = NeptuneWallTransferModel(self.case)

        self.set_connections()
        # Connections must be set before ComboModel is declared.
        self.combomodel_wallmodel = ComboModel(self.comboBoxWallTransferType)
        self.fill_widgets()
        self.initialize_widgets()
        self.update_view()

    def initialize_widgets(self):
        predefined_flow = MainFieldsModel(self.case).getPredefinedFlow()
        if predefined_flow in ["free_surface", "boiling_flow"]:
            self.combomodel_wallmodel.setItem(str_model="nucleate_boiling")
            self.setEnabled(False)
        elif predefined_flow == "droplet_flow":
            self.combomodel_wallmodel.setItem(
                str_model="droplet_evaporation_condensation")
            self.setEnabled(False)
        elif predefined_flow == "multiregime":
            self.combomodel_wallmodel.disableItem(str_model="none")
            self.combomodel_wallmodel.setItem(
                str_model=self.xml_model.wall_transfer_type)
            self.boilingWidget.setEnabled(False)
            self.dropletWidget.setEnabled(False)
        else:
            self.combomodel_wallmodel.setItem(
                str_model=self.xml_model.wall_transfer_type)

    def update_view(self):
        model = self.xml_model.wall_transfer_type
        self.boilingWidget.hide()
        self.dropletWidget.hide()
        if model == "nucleate_boiling":
            self.boilingWidget.setup(self.case)
            self.boilingWidget.show()
        elif model == "droplet_evaporation_condensation":
            self.dropletWidget.setup(self.case)
            self.dropletWidget.show()
        elif model == "none":
            pass
        else:
            raise ValueError("Unknown model {0}".format(model))
        return

    def fill_widgets(self):
        self.combomodel_wallmodel.addItem(self.tr("None"), "none")
        self.combomodel_wallmodel.addItem(self.tr("Nucleate boiling"),
                                          "nucleate_boiling")
        self.combomodel_wallmodel.addItem(
            self.tr("Droplet evaporation/condensation"),
            "droplet_evaporation_condensation")
        return

    def set_connections(self):
        self.comboBoxWallTransferType.currentTextChanged[str].connect(
            self.slot_set_wall_model)

    @pyqtSlot(str)
    def slot_set_wall_model(self, text):
        model = self.combomodel_wallmodel.dicoV2M[text]
        self.xml_model.wall_transfer_type = model
        self.update_view()
        return
コード例 #7
0
class GlobalNumericalParametersView(QWidget, Ui_GlobalNumericalParameters):
    """
    Global numerical parameters layout.
    """
    def __init__(self, parent, case):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_GlobalNumericalParameters.__init__(self)
        self.setupUi(self)

        self.case = case
        self.case.undoStopGlobal()
        self.mdl = GlobalNumericalParametersModel(self.case)

        # Combo model
        self.modelVelocityAlgorithm = ComboModel(
            self.comboBoxVelocityAlgorithm, 3, 1)
        self.modelVelocityAlgorithm.addItem(self.tr("Standard"),
                                            "standard_difvit")
        self.modelVelocityAlgorithm.addItem(self.tr("Coupled"),
                                            "coupled_difvitc")
        self.modelVelocityAlgorithm.addItem(
            self.tr("Mean velocity - relative velocity"),
            "mean_velocity_relative_velocity")

        mfm = MainFieldsModel(self.case)
        if len(mfm.getFieldIdList()) < 2:
            self.modelVelocityAlgorithm.disableItem(2)
        else:
            self.modelVelocityAlgorithm.enableItem(2)

        # Validator
        validatorMaxRestart = IntValidator(self.lineEditMaxRestart, min=0)
        validatorSplitting = DoubleValidator(self.lineEditTimeSplitting,
                                             min=0.)
        validatorPRelax = DoubleValidator(self.lineEditPressureRelaxation,
                                          min=0.)
        validatorMinP = DoubleValidator(self.lineEditMinimumPressure)
        validatorMaxP = DoubleValidator(self.lineEditMaximumPressure)

        validatorMaxRestart.setExclusiveMin(False)
        validatorSplitting.setExclusiveMin(True)
        validatorPRelax.setExclusiveMin(True)

        self.lineEditMaxRestart.setValidator(validatorMaxRestart)
        self.lineEditTimeSplitting.setValidator(validatorSplitting)
        self.lineEditPressureRelaxation.setValidator(validatorPRelax)
        self.lineEditMinimumPressure.setValidator(validatorMinP)
        self.lineEditMaximumPressure.setValidator(validatorMaxP)

        # Connections
        self.checkBoxRestart.clicked.connect(self.slotRestart)
        self.checkBoxPotentialState.clicked.connect(self.slotPotentialState)
        self.checkBoxFacesReconstruction.clicked.connect(
            self.slotFacesReconstruction)
        self.checkBoxMultigrid.clicked.connect(self.slotMultigrid)
        self.lineEditMinimumPressure.textChanged[str].connect(
            self.slotMinimumPressure)
        self.lineEditMaximumPressure.textChanged[str].connect(
            self.slotMaximumPressure)
        self.pushButtonAdvanced.clicked.connect(self.slotAdvancedOptions)
        self.lineEditMaxRestart.textChanged[str].connect(self.slotMaxRestart)
        self.lineEditTimeSplitting.textChanged[str].connect(
            self.slotTimeSplitting)
        self.lineEditPressureRelaxation.textChanged[str].connect(
            self.slotPressureRelaxation)
        self.checkBoxUpwindAlphaEnergy.clicked.connect(
            self.slotUpwindAlphaEnergy)
        self.checkBoxStopRestart.clicked.connect(self.slotStopRestart)
        self.comboBoxVelocityAlgorithm.activated[str].connect(
            self.slotVelocityAlgorithm)

        self.checkBoxRegulBadCells.clicked.connect(self.slotRegulateBadCells)

        # Initialize widget
        status = self.mdl.getRestartTimeStep()
        if status == 'on':
            self.checkBoxRestart.setChecked(1)
            self.groupBoxRestartOption.show()

            value = self.mdl.getMaxNumberOfRestart()
            self.lineEditMaxRestart.setText(str(value))
            value = self.mdl.getTimeSplit()
            self.lineEditTimeSplitting.setText(str(value))
            value = self.mdl.getPressureRelaxation()
            self.lineEditPressureRelaxation.setText(str(value))
            status = self.mdl.getUpwindScheme()
            if status == 'on':
                self.checkBoxUpwindAlphaEnergy.setChecked(True)
            else:
                self.checkBoxUpwindAlphaEnergy.setChecked(False)
            status = self.mdl.getStopNoConvergence()
            if status == 'on':
                self.checkBoxStopRestart.setChecked(True)
            else:
                self.checkBoxStopRestart.setChecked(False)
        else:
            self.checkBoxRestart.setChecked(0)
            self.groupBoxRestartOption.hide()

        is_compressible = False
        for fid in mfm.getFieldIdList():
            if mfm.getCompressibleStatus(int(fid)) == 'on':
                is_compressible = True
                break

        if is_compressible:
            self.mdl.setPotentielState('off')
            self.checkBoxPotentialState.setChecked(0)
            self.checkBoxPotentialState.setEnabled(False)
        else:
            status = self.mdl.getPotentielState()
            if status == 'on':
                self.checkBoxPotentialState.setChecked(1)
            else:
                self.checkBoxPotentialState.setChecked(0)

        status = self.mdl.getFacesReconstruction()
        if status == 'on':
            self.checkBoxFacesReconstruction.setChecked(1)
        else:
            self.checkBoxFacesReconstruction.setChecked(0)

        status = self.mdl.getRegulateBadCElls()
        self.checkBoxRegulBadCells.setChecked(status == 'on')

        status = self.mdl.getMultigridStatus()
        if status == 'on':
            self.checkBoxMultigrid.setChecked(1)
        else:
            self.checkBoxMultigrid.setChecked(0)

        value = self.mdl.getMinPressure()
        self.lineEditMinimumPressure.setText(str(value))
        value = self.mdl.getMaxPressure()
        self.lineEditMaximumPressure.setText(str(value))

        model = self.mdl.getVelocityPredictorAlgo()
        self.modelVelocityAlgorithm.setItem(str_model=model)

        self.case.undoStartGlobal()

        predefined_flow = MainFieldsModel(self.case).getPredefinedFlow()
        if predefined_flow in ["free_surface", "droplet_flow", "multiregime"]:
            self.modelVelocityAlgorithm.setItem(str_model="coupled_difvitc")
            self.comboBoxVelocityAlgorithm.setEnabled(False)
        elif predefined_flow == "boiling_flow":
            self.modelVelocityAlgorithm.setItem(
                str_model="mean_velocity_relative_velocity")
            self.comboBoxVelocityAlgorithm.setEnabled(False)

    @pyqtSlot()
    def slotRestart(self):
        """
        Input if restart time step if not converged
        """
        if self.checkBoxRestart.isChecked():
            self.mdl.setRestartTimeStep('on')
            self.groupBoxRestartOption.show()

            value = self.mdl.getMaxNumberOfRestart()
            self.lineEditMaxRestart.setText(str(value))
            value = self.mdl.getTimeSplit()
            self.lineEditTimeSplitting.setText(str(value))
            value = self.mdl.getPressureRelaxation()
            self.lineEditPressureRelaxation.setText(str(value))
            status = self.mdl.getUpwindScheme()
            if status == 'on':
                self.checkBoxUpwindAlphaEnergy.setChecked(True)
            else:
                self.checkBoxUpwindAlphaEnergy.setChecked(False)
            status = self.mdl.getStopNoConvergence()
            if status == 'on':
                self.checkBoxStopRestart.setChecked(True)
            else:
                self.checkBoxStopRestart.setChecked(False)
        else:
            self.mdl.setRestartTimeStep('off')
            self.groupBoxRestartOption.hide()

    @pyqtSlot()
    def slotPotentialState(self):
        """
        Input if restart time step if not converged
        """
        if self.checkBoxPotentialState.isChecked():
            self.mdl.setPotentielState('on')
        else:
            self.mdl.setPotentielState('off')

    @pyqtSlot()
    def slotFacesReconstruction(self):
        """
        Input if faces reconstruction
        """
        if self.checkBoxFacesReconstruction.isChecked():
            self.mdl.setFacesReconstruction('on')
            self.checkBoxFacesReconstruction.setChecked(1)
        else:
            self.mdl.setFacesReconstruction('off')

    @pyqtSlot()
    def slotMultigrid(self):
        """
        Input if multigrid for pressure
        """
        if self.checkBoxMultigrid.isChecked():
            self.mdl.setMultigridStatus('on')
        else:
            self.mdl.setMultigridStatus('off')

    @pyqtSlot(str)
    def slotMinimumPressure(self, text):
        """
        Input value of minimum pressure
        """
        if self.lineEditMinimumPressure.validator(
        ).state == QValidator.Acceptable:
            value = from_qvariant(text, float)
            self.mdl.setMinPressure(value)

    @pyqtSlot(str)
    def slotMaximumPressure(self, text):
        """
        Input value of maximum pressure
        """
        if self.lineEditMaximumPressure.validator(
        ).state == QValidator.Acceptable:
            value = from_qvariant(text, float)
            self.mdl.setMaxPressure(value)

    @pyqtSlot()
    def slotAdvancedOptions(self):
        """
        Ask one popup for advanced specifications
        """
        default = {}
        default['velocity_update'] = self.mdl.getVelocityUpdate()
        default['pressure_symetrisation'] = self.mdl.getPressureSymetrisation()
        default['pressure_gradient'] = self.mdl.getPressureGradient()
        default['max_sum_alpha'] = self.mdl.getSumAlpha()
        default['alpha_p_cycle'] = self.mdl.getAlphaPressureCycles()
        log.debug("slotAdvancedOptions -> %s" % str(default))

        dialog = GlobalNumericalParametersAdvancedOptionsDialogView(
            self, self.case, default)
        if dialog.exec_():
            result = dialog.get_result()
            log.debug("slotAdvancedOptions -> %s" % str(result))
            self.mdl.setVelocityUpdate(result['velocity_update'])
            self.mdl.setPressureSymetrisation(result['pressure_symetrisation'])
            self.mdl.setPressureGradient(result['pressure_gradient'])
            self.mdl.setSumAlpha(result['max_sum_alpha'])
            self.mdl.setAlphaPressureCycles(result['alpha_p_cycle'])

    @pyqtSlot(str)
    def slotMaxRestart(self, text):
        """
        Input value of Maximum number of restart
        """
        if self.lineEditMaxRestart.validator().state == QValidator.Acceptable:
            value = from_qvariant(text, int)
            self.mdl.setMaxNumberOfRestart(value)

    @pyqtSlot(str)
    def slotTimeSplitting(self, text):
        """
        Input value of time-step splitting
        """
        if self.lineEditTimeSplitting.validator(
        ).state == QValidator.Acceptable:
            value = from_qvariant(text, float)
            self.mdl.setTimeSplit(value)

    @pyqtSlot(str)
    def slotPressureRelaxation(self, text):
        """
        Input value of pressure increment relaxation
        """
        if self.lineEditPressureRelaxation.validator(
        ).state == QValidator.Acceptable:
            value = from_qvariant(text, float)
            self.mdl.setPressureRelaxation(value)

    @pyqtSlot()
    def slotUpwindAlphaEnergy(self):
        """
        Input if upwind scheme for mass and energy
        """
        if self.checkBoxUpwindAlphaEnergy.isChecked():
            self.mdl.setUpwindScheme('on')
        else:
            self.mdl.setUpwindScheme('off')

    @pyqtSlot()
    def slotStopRestart(self):
        """
        Input if stop if no convergence
        """
        if self.checkBoxStopRestart.isChecked():
            self.mdl.setStopNoConvergence('on')
        else:
            self.mdl.setStopNoConvergence('off')

    @pyqtSlot(str)
    def slotVelocityAlgorithm(self, text):
        """
        Input velocity algorithm model
        """
        model = self.modelVelocityAlgorithm.dicoV2M[str(text)]
        self.mdl.setVelocityPredictorAlgo(model)

    @pyqtSlot()
    def slotRegulateBadCells(self):
        """
        Activate bad cells regulations.
        """
        if self.checkBoxRegulBadCells.isChecked():
            self.mdl.setRegulateBadCells('on')
        else:
            self.mdl.setRegulateBadCells('off')
コード例 #8
0
class NucleateBoilingView(QWidget, Ui_NucleateBoiling):
    """
    Nucleate boiling model layout.
    """
    def __init__(self, parent):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_NucleateBoiling.__init__(self)
        self.setupUi(self)

    def setup(self, case):

        self.case = case
        self.case.undoStopGlobal()
        self.mdl = NucleateBoilingModel(self.case)

        self.modelHeatTransferModel = ComboModel(
            self.comboBoxHeatTransferModel, 2, 1)
        self.modelHeatTransferModel.addItem(
            self.tr("Extended Kurul-Podowski model"),
            "extended_kurul-podowski")
        self.modelHeatTransferModel.addItem(
            self.tr("Standard Kurul-Podowski model"),
            "standard_kurul-podowski")

        self.modelWallFunctionModel = ComboModel(
            self.comboBoxWallFunctionModel, 3, 1)
        self.modelWallFunctionModel.addItem(
            self.tr("standard (single phase wall function)"), "standard")
        self.modelWallFunctionModel.addItem(self.tr("Koncar Tiselj-NED 2008"),
                                            "koncar")
        self.modelWallFunctionModel.addItem(self.tr("Mimouni et al-NED 2008"),
                                            "mimouni")
        if InterfacialEnthalpyModel(self.case).getPoolBoiling() == "on":
            self.modelWallFunctionModel.disableItem(str_model="koncar")
            self.modelWallFunctionModel.disableItem(str_model="mimouni")

        self.modelYPlus = ComboModel(self.comboBoxYPlus, 3, 1)
        self.modelYPlus.addItem(self.tr("Boundary cell center"), "center")
        self.modelYPlus.addItem(self.tr("Y+ = "), "Yplus_value")
        self.modelYPlus.addItem(self.tr("Nucleate bubble diameter"),
                                "diameter")

        # Validators

        validatorYplus = DoubleValidator(self.lineEditYPlus, min=0.0)
        validatorRad = DoubleValidator(self.lineEditMaxRadius, min=0.0)
        validatorDiam = DoubleValidator(self.lineEditMaxDiam, min=0.0)
        validatorSat = DoubleValidator(self.lineEditMaxOverSaturation, min=0.0)
        validatorLam = DoubleValidator(self.lineEditThermalConductivity,
                                       min=0.0)
        validatorRho = DoubleValidator(self.lineEditDensity, min=0.0)
        validatorCp = DoubleValidator(self.lineEditSpecificHeat, min=0.0)
        validatorTh = DoubleValidator(self.lineEditThickness, min=0.0)

        validatorYplus.setExclusiveMin(True)
        validatorRad.setExclusiveMin(True)
        validatorDiam.setExclusiveMin(True)
        validatorSat.setExclusiveMin(True)
        validatorLam.setExclusiveMin(True)
        validatorRho.setExclusiveMin(True)
        validatorCp.setExclusiveMin(True)
        validatorTh.setExclusiveMin(True)

        self.lineEditYPlus.setValidator(validatorYplus)
        self.lineEditMaxRadius.setValidator(validatorRad)
        self.lineEditMaxDiam.setValidator(validatorDiam)
        self.lineEditMaxOverSaturation.setValidator(validatorSat)
        self.lineEditThermalConductivity.setValidator(validatorLam)
        self.lineEditDensity.setValidator(validatorRho)
        self.lineEditSpecificHeat.setValidator(validatorCp)
        self.lineEditThickness.setValidator(validatorTh)

        # Connect signals to slots
        self.comboBoxHeatTransferModel.activated[str].connect(
            self.slotHeatTransferModel)
        self.comboBoxWallFunctionModel.activated[str].connect(
            self.slotWallFunctionModel)
        self.comboBoxYPlus.activated[str].connect(self.slotYPlus)
        self.checkBoxThickness.clicked.connect(self.slotThickness)
        self.lineEditYPlus.textChanged[str].connect(self.slotYPlusValue)
        self.lineEditMaxRadius.textChanged[str].connect(self.slotMaxRadius)
        self.lineEditMaxDiam.textChanged[str].connect(self.slotMaxDiam)
        self.lineEditMaxOverSaturation.textChanged[str].connect(
            self.slotMaxOverSaturation)
        self.lineEditThermalConductivity.textChanged[str].connect(
            self.slotThermalConductivity)
        self.lineEditDensity.textChanged[str].connect(self.slotDensity)
        self.lineEditSpecificHeat.textChanged[str].connect(
            self.slotSpecificHeat)
        self.lineEditThickness.textChanged[str].connect(
            self.slotThicknessValue)

        # load values
        isYPlus = self.mdl.getYPlusModel()
        self.modelYPlus.setItem(str_model=isYPlus)

        if isYPlus == "Yplus_value":
            self.lineEditYPlus.show()
            self.lineEditYPlus.setText(str(self.mdl.getYPlusValue()))
        else:
            self.lineEditYPlus.hide()

        self.lineEditMaxRadius.setText(str(self.mdl.getMaxRadius()))
        self.lineEditMaxDiam.setText(str(self.mdl.getMaxDiameter()))
        self.lineEditMaxOverSaturation.setText(
            str(self.mdl.getMaxOverSaturation()))
        self.lineEditThermalConductivity.setText(
            str(self.mdl.getThermalConductivity()))
        self.lineEditDensity.setText(str(self.mdl.getDensity()))
        self.lineEditSpecificHeat.setText(str(self.mdl.getSpecificHeat()))

        model = self.mdl.getHeatTransferModel()
        self.modelHeatTransferModel.setItem(str_model=model)
        if model == "standard_kurul-podowski":
            self.labelMaxRadius.setEnabled(0)
            self.lineEditMaxRadius.setEnabled(0)
            self.labelMaxRadiusUnit.setEnabled(0)
            self.labelMaxDiam.setEnabled(0)
            self.lineEditMaxDiam.setEnabled(0)
            self.labelMaxDiamUnit.setEnabled(0)
        else:
            self.labelMaxRadius.setEnabled(1)
            self.lineEditMaxRadius.setEnabled(1)
            self.labelMaxRadiusUnit.setEnabled(1)
            self.labelMaxDiam.setEnabled(1)
            self.lineEditMaxDiam.setEnabled(1)
            self.labelMaxDiamUnit.setEnabled(1)

        isThickness = self.mdl.getThicknessStatus() == "on"
        self.checkBoxThickness.setChecked(isThickness)

        if isThickness:
            self.lineEditThickness.show()
            self.labelThickness1.show()
            self.labelThickness2.show()
            self.lineEditThickness.setText(str(self.mdl.getThicknessValue()))
        else:
            self.lineEditThickness.hide()
            self.labelThickness1.hide()
            self.labelThickness2.hide()

        model = self.mdl.getWallFunctionModel()
        self.modelWallFunctionModel.setItem(str_model=model)

        self.case.undoStartGlobal()
コード例 #9
0
class InterfacialAreaView(QWidget, Ui_InterfacialArea):
    """
    InterfacialAreaView layout.
    """
    def __init__(self, parent, case):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_InterfacialArea.__init__(self)
        self.setupUi(self)

        self.case = case
        self.case.undoStopGlobal()
        self.mdl = InterfacialAreaModel(self.case)

        dispersed_fields = self.mdl.getDispersedFieldList(
        ) + InterfacialForcesModel(self.case).getGLIMfields()

        if dispersed_fields == []:
            self.groupBoxField.hide()
            self.groupBoxMinMaxDiameter.hide()
            self.groupBoxModel.hide()
            self.labelNoDispersedPhase.show()
            self.mdl.remove()
            return

        # Combo box models
        id_to_set = -1
        self.modelField = ComboModel(self.comboBoxField, 1, 1)

        # For consistency with the previous pages, the second phase of the
        # Large Interface Model is set before the dispersed fields

        for fieldId in dispersed_fields:
            label = self.mdl.getLabel(fieldId)
            name = str(fieldId)
            self.modelField.addItem(self.tr(label), name)

        if len(dispersed_fields) > 0 and id_to_set == -1:
            id_to_set = dispersed_fields[0]
            self.modelField.setItem(str_model=id_to_set)

        # case no field
        self.currentid = id_to_set

        self.modelModel = ComboModel(self.comboBoxModel, 2, 1)
        self.modelModel.addItem(self.tr("constant"), "constant")
        self.modelModel.addItem(self.tr("interfacial area transport"),
                                "interfacial_area_transport")

        self.modelSourceTerm = ComboModel(self.comboBoxSourceTerm, 4, 1)

        self.modelSourceTerm.addItem(
            self.tr("No coalescence, no fragmentation"),
            "no_coalescence_no_fragmentation")
        self.modelSourceTerm.addItem(self.tr("Yao & Morel"), "wei_yao")
        self.modelSourceTerm.addItem(self.tr("Kamp & Colin"), "kamp_colin")
        self.modelSourceTerm.addItem(self.tr("Ruyer & Seiler"), "ruyer_seiler")
        self.modelSourceTerm.disableItem(2)  # Why ?

        # Validators
        validatorDefDiam = DoubleValidator(self.lineEditDefaultDiameter,
                                           min=0.0)
        validatorMinDiam = DoubleValidator(self.lineEditMinDiameter, min=0.0)
        validatorMaxDiam = DoubleValidator(self.lineEditMaxDiameter, min=0.0)

        validatorDefDiam.setExclusiveMin(True)
        validatorMinDiam.setExclusiveMin(True)
        validatorMaxDiam.setExclusiveMin(True)

        self.lineEditDefaultDiameter.setValidator(validatorDefDiam)
        self.lineEditMinDiameter.setValidator(validatorMinDiam)
        self.lineEditMaxDiameter.setValidator(validatorMaxDiam)

        # Connect signals to slots
        self.comboBoxField.activated[str].connect(self.slotField)
        self.comboBoxModel.activated[str].connect(self.slotModel)
        self.comboBoxSourceTerm.activated[str].connect(self.slotSourceTerm)
        self.lineEditDefaultDiameter.textChanged[str].connect(
            self.slotDefaultDiameter)
        self.lineEditMinDiameter.textChanged[str].connect(self.slotMinDiameter)
        self.lineEditMaxDiameter.textChanged[str].connect(self.slotMaxDiameter)

        # Initialize widget
        self.initializeVariables(self.currentid)

        self.case.undoStartGlobal()

    @pyqtSlot(str)
    def slotField(self, text):
        """
        INPUT label for choice of field
        """
        self.currentid = self.modelField.dicoV2M[text]
        self.initializeVariables(self.currentid)

        if self.mdl.getFieldNature(self.currentid) == "gas":
            self.modelSourceTerm.enableItem(0)
        else:
            self.modelSourceTerm.disableItem(0)

    @pyqtSlot(str)
    def slotModel(self, text):
        """
        INPUT type for choice of model
        """
        model = self.modelModel.dicoV2M[text]
        self.mdl.setAreaModel(self.currentid, model)
        self.initializeVariables(self.currentid)

    @pyqtSlot(str)
    def slotSourceTerm(self, text):
        """
        INPUT type for choice of model source term
        """
        model = self.modelSourceTerm.dicoV2M[text]
        self.mdl.setSourceTerm(self.currentid, model)

    @pyqtSlot(str)
    def slotDefaultDiameter(self, var):
        """
        """
        if self.lineEditDefaultDiameter.validator(
        ).state == QValidator.Acceptable:
            value = from_qvariant(var, float)
            self.mdl.setInitialDiameter(self.currentid, value)

    @pyqtSlot(str)
    def slotMinDiameter(self, var):
        """
        """
        if self.lineEditMinDiameter.validator().state == QValidator.Acceptable:
            value = from_qvariant(var, float)
            self.mdl.setMinDiameter(self.currentid, value)

    @pyqtSlot(str)
    def slotMaxDiameter(self, var):
        """
        """
        if self.lineEditMaxDiameter.validator().state == QValidator.Acceptable:
            value = from_qvariant(var, float)
            self.mdl.setMaxDiameter(self.currentid, value)

    def initializeVariables(self, fieldId):
        """
        Initialize variables when a new fieldId is choosen
        """
        self.labelNoDispersedPhase.hide()
        model = self.mdl.getAreaModel(fieldId)
        self.modelModel.setItem(str_model=model)

        value = self.mdl.getInitialDiameter(self.currentid)
        self.lineEditDefaultDiameter.setText(str(value))

        if self.mdl.getAreaModel(fieldId) == "constant":
            self.groupBoxAreaTransport.hide()
            self.groupBoxMinMaxDiameter.hide()
        else:
            self.groupBoxAreaTransport.show()
            model = self.mdl.getSourceTerm(fieldId)
            self.modelSourceTerm.setItem(str_model=model)

            self.groupBoxMinMaxDiameter.show()

            value = self.mdl.getMinDiameter(self.currentid)
            self.lineEditMinDiameter.setText(str(value))

            value = self.mdl.getMaxDiameter(self.currentid)
            self.lineEditMaxDiameter.setText(str(value))

            if MainFieldsModel(self.case).getFieldNature(fieldId) != 'gas':
                self.modelSourceTerm.disableItem(1)
                self.modelSourceTerm.disableItem(2)
                self.modelSourceTerm.disableItem(3)
            else: