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)
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')
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: