1# -*- coding: utf-8 -*- 2 3#------------------------------------------------------------------------------- 4 5# This file is part of Code_Saturne, a general-purpose CFD tool. 6# 7# Copyright (C) 1998-2021 EDF S.A. 8# 9# This program is free software; you can redistribute it and/or modify it under 10# the terms of the GNU General Public License as published by the Free Software 11# Foundation; either version 2 of the License, or (at your option) any later 12# version. 13# 14# This program is distributed in the hope that it will be useful, but WITHOUT 15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17# details. 18# 19# You should have received a copy of the GNU General Public License along with 20# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 21# Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 23#------------------------------------------------------------------------------- 24 25""" 26This module contains the following classes: 27- ScalarsBoundariesView 28""" 29 30#------------------------------------------------------------------------------- 31# Standard modules 32#------------------------------------------------------------------------------- 33 34import logging 35 36#------------------------------------------------------------------------------- 37# Third-party modules 38#------------------------------------------------------------------------------- 39 40from code_saturne.Base.QtCore import * 41from code_saturne.Base.QtGui import * 42from code_saturne.Base.QtWidgets import * 43 44#------------------------------------------------------------------------------- 45# Application modules import 46#------------------------------------------------------------------------------- 47 48from code_saturne.model.Common import GuiParam 49from code_saturne.Base.QtPage import DoubleValidator, IntValidator, ComboModel, from_qvariant 50 51from code_saturne.Pages.BoundaryConditionsScalarsForm import Ui_BoundaryConditionsScalarsForm 52from code_saturne.model.LocalizationModel import LocalizationModel, Zone 53from code_saturne.model.DefineUserScalarsModel import DefineUserScalarsModel 54from code_saturne.model.ThermalScalarModel import ThermalScalarModel 55from code_saturne.Pages.QMegEditorView import QMegEditorView 56from code_saturne.model.Boundary import Boundary 57from code_saturne.model.CompressibleModel import CompressibleModel 58from code_saturne.model.AtmosphericFlowsModel import AtmosphericFlowsModel 59from code_saturne.model.NotebookModel import NotebookModel 60from code_saturne.model.ConjugateHeatTransferModel import ConjugateHeatTransferModel 61 62# ------------------------------------------------------------------------------- 63# log config 64# ------------------------------------------------------------------------------- 65 66logging.basicConfig() 67log = logging.getLogger("BoundaryConditionsScalarsView") 68log.setLevel(GuiParam.DEBUG) 69 70#------------------------------------------------------------------------------- 71# Main class 72#------------------------------------------------------------------------------- 73 74class BoundaryConditionsScalarsView(QWidget, Ui_BoundaryConditionsScalarsForm): 75 """ 76 """ 77 def __init__(self, parent): 78 """ 79 Constructor 80 """ 81 QWidget.__init__(self, parent) 82 83 Ui_BoundaryConditionsScalarsForm.__init__(self) 84 self.setupUi(self) 85 86 87 def __get_thermal_type__(self): 88 """ 89 Return thermal type and conversion option 90 """ 91 thermal_type_s = self.thermal_type.split(':') 92 thermal_type = thermal_type_s[0] 93 convert = None 94 if len(thermal_type_s) > 1: 95 convert = thermal_type_s[1] 96 return thermal_type, convert 97 98 99 def setup(self, case): 100 """ 101 Setup the widget 102 """ 103 self.case = case 104 self.__boundary = None 105 106 self.case.undoStopGlobal() 107 self.notebook = NotebookModel(self.case) 108 self.cht_model = ConjugateHeatTransferModel(self.case) 109 110 self.lineEditValueThermal.textChanged[str].connect(self.slotValueThermal) 111 self.lineEditValueSpecies.textChanged[str].connect(self.slotValueSpecies) 112 self.lineEditValueMeteo.textChanged[str].connect(self.slotValueMeteo) 113 self.lineEditExThermal.textChanged[str].connect(self.slotExThermal) 114 self.lineEditExSpecies.textChanged[str].connect(self.slotExSpecies) 115 self.lineEditExMeteo.textChanged[str].connect(self.slotExMeteo) 116 117 self.pushButtonThermal.clicked.connect(self.slotThermalFormula) 118 self.pushButtonSpecies.clicked.connect(self.slotSpeciesFormula) 119 self.pushButtonMeteo.clicked.connect(self.slotMeteoFormula) 120 self.comboBoxThermal.activated[str].connect(self.slotThermalChoice) 121 self.comboBoxTypeThermal.activated[str].connect(self.slotThermalTypeChoice) 122 self.comboBoxSpecies.activated[str].connect(self.slotSpeciesChoice) 123 self.comboBoxTypeSpecies.activated[str].connect(self.slotSpeciesTypeChoice) 124 self.comboBoxMeteo.activated[str].connect(self.slotMeteoChoice) 125 self.comboBoxTypeMeteo.activated[str].connect(self.slotMeteoTypeChoice) 126 127 # Syrthes coupling 128 self.lineEditSyrthesInstance.editingFinished.connect(self.slotChooseSyrthesInstance) 129 130 ## Validators 131 validatorValueThermal = DoubleValidator(self.lineEditValueThermal) 132 validatorValueSpecies = DoubleValidator(self.lineEditValueSpecies) 133 validatorValueMeteo = DoubleValidator(self.lineEditValueMeteo) 134 validatorExThermal = DoubleValidator(self.lineEditExThermal) 135 validatorExSpecies = DoubleValidator(self.lineEditExSpecies) 136 validatorExMeteo = DoubleValidator(self.lineEditExMeteo) 137 138 self.lineEditValueThermal.setValidator(validatorValueThermal) 139 self.lineEditValueSpecies.setValidator(validatorValueSpecies) 140 self.lineEditValueMeteo.setValidator(validatorValueMeteo) 141 self.lineEditExThermal.setValidator(validatorExThermal) 142 self.lineEditExSpecies.setValidator(validatorExSpecies) 143 self.lineEditExMeteo.setValidator(validatorExMeteo) 144 145 self.case.undoStartGlobal() 146 147 148 def __setBoundary(self, boundary): 149 """ 150 Set the current boundary 151 """ 152 self.__boundary = boundary 153 154 self.nature = boundary.getNature() 155 self.therm = ThermalScalarModel(self.case) 156 self.sca_mo = DefineUserScalarsModel(self.case) 157 self.comp = CompressibleModel(self.case) 158 self.atm = AtmosphericFlowsModel(self.case) 159 160 self.model_th = self.therm.getThermalScalarModel() 161 162 self.modelTypeThermal = ComboModel(self.comboBoxTypeThermal, 1, 1) 163 self.modelTypeSpecies = ComboModel(self.comboBoxTypeSpecies, 1, 1) 164 self.modelTypeMeteo = ComboModel(self.comboBoxTypeMeteo, 1, 1) 165 166 self.modelTypeThermal.addItem(self.tr("Prescribed value"), 'dirichlet') 167 if self.model_th == "enthalpy": 168 self.modelTypeThermal.addItem(self.tr("Prescribed temperature value"), 169 'dirichlet:temperature') 170 171 self.modelTypeSpecies.addItem(self.tr("Prescribed value"), 'dirichlet') 172 self.modelTypeMeteo.addItem(self.tr("Prescribed value"), 'dirichlet') 173 174 self.modelTypeThermal.addItem(self.tr("Prescribed value (user law)"), 175 'dirichlet_formula') 176 if self.model_th == "enthalpy": 177 self.modelTypeThermal.addItem(self.tr("Prescribed temperature value (user law)"), 178 'dirichlet_formula:temperature') 179 self.modelTypeSpecies.addItem(self.tr("Prescribed value (user law)"), 180 'dirichlet_formula') 181 self.modelTypeMeteo.addItem(self.tr("Prescribed value (user law)"), 182 'dirichlet_formula') 183 184 if self.nature == 'outlet': 185 self.modelTypeThermal.addItem(self.tr("Prescribed (outgoing) flux"), 'neumann') 186 self.modelTypeSpecies.addItem(self.tr("Prescribed (outgoing) flux"), 'neumann') 187 self.modelTypeMeteo.addItem( self.tr("Prescribed (outgoing) flux"), 'neumann') 188 elif self.nature == 'wall': 189 self.initSyrthesInstanceList() 190 191 self.modelTypeThermal.addItem(self.tr("Prescribed (outgoing) flux"), 'neumann') 192 self.modelTypeSpecies.addItem(self.tr("Prescribed (outgoing) flux"), 'neumann') 193 self.modelTypeMeteo.addItem(self.tr("Prescribed (outgoing) flux"), 'neumann') 194 self.modelTypeThermal.addItem(self.tr("Prescribed (outgoing) flux (user law)"), 195 'neumann_formula') 196 self.modelTypeSpecies.addItem(self.tr("Prescribed (outgoing) flux (user law)"), 197 'neumann_formula') 198 self.modelTypeMeteo.addItem(self.tr("Prescribed (outgoing) flux (user law)"), 199 'neumann_formula') 200 self.modelTypeThermal.addItem(self.tr("Exchange coefficient"), 201 'exchange_coefficient') 202 self.modelTypeSpecies.addItem(self.tr("Exchange coefficient"), 203 'exchange_coefficient') 204 self.modelTypeMeteo.addItem(self.tr("Exchange coefficient"), 205 'exchange_coefficient') 206 self.modelTypeThermal.addItem(self.tr("Exchange coefficient (user law)"), 207 'exchange_coefficient_formula') 208 self.modelTypeSpecies.addItem(self.tr("Exchange coefficient (user law)"), 209 'exchange_coefficient_formula') 210 self.modelTypeMeteo.addItem(self.tr("Exchange coefficient (user law)"), 211 'exchange_coefficient_formula') 212 self.modelTypeThermal.addItem(self.tr("SYRTHES coupling"), "syrthes_coupling") 213 214 elif self.nature == 'groundwater': 215 self.modelTypeSpecies.addItem(self.tr("Prescribed (outgoing) flux"), 'neumann') 216 217 self.species = "" 218 self.species_list = self.sca_mo.getUserScalarNameList() 219 for s in self.sca_mo.getScalarsVarianceList(): 220 if s in self.species_list: 221 self.species_list.remove(s) 222 223 self.species = "" 224 if self.species_list != []: 225 self.groupBoxSpecies.show() 226 self.modelSpecies = ComboModel(self.comboBoxSpecies, 1, 1) 227 for species in self.species_list: 228 self.modelSpecies.addItem(self.tr(species), species) 229 self.species = self.species_list[0] 230 self.modelSpecies.setItem(str_model = self.species) 231 else: 232 self.groupBoxSpecies.hide() 233 234 if self.model_th != 'off' and self.comp.getCompressibleModel() == 'off': 235 self.groupBoxThermal.show() 236 self.modelThermal = ComboModel(self.comboBoxThermal,1,1) 237 self.thermal = self.therm.getThermalScalarName() 238 self.thermal_type = self.__boundary.getScalarChoice(self.thermal) 239 cnv = self.__boundary.getScalarConvert(self.thermal) 240 if cnv: 241 self.thermal_type += ':' + cnv 242 self.modelThermal.addItem(self.tr(self.thermal), self.thermal) 243 self.modelThermal.setItem(str_model = self.thermal) 244 else: 245 self.groupBoxThermal.hide() 246 247 self.meteo_list = self.sca_mo.getMeteoScalarsNameList() 248 249 self.groupBoxMeteo.hide() 250 251 if (self.atm.getAtmosphericFlowsModel() != "off" and self.nature == 'wall'): 252 self.modelMeteo = ComboModel(self.comboBoxMeteo, 1, 1) 253 if len(self.meteo_list) > 0: 254 self.groupBoxMeteo.show() 255 for m in self.meteo_list: 256 self.modelMeteo.addItem(self.tr(m), m) 257 self.meteo = self.meteo_list[0] 258 self.modelMeteo.setItem(str_model = self.meteo) 259 260 if (self.atm.getAtmosphericFlowsModel() != "off" and \ 261 (self.nature == 'inlet' or self.nature == 'outlet')): 262 label = self.__boundary.getLabel() 263 nature = "meteo_" + self.nature 264 bb = Boundary(nature, label, self.case) 265 266 if bb.getMeteoDataStatus() == 'off': 267 self.groupBoxMeteo.hide() 268 if self.model_th != 'off': 269 self.groupBoxThermal.show() 270 self.modelMeteo = ComboModel(self.comboBoxMeteo, 1, 1) 271 if len(self.meteo_list) > 0: 272 self.groupBoxMeteo.show() 273 for m in self.meteo_list: 274 self.modelMeteo.addItem(self.tr(m), m) 275 self.meteo = self.meteo_list[0] 276 self.modelMeteo.setItem(str_model=self.meteo) 277 else: 278 self.groupBoxMeteo.hide() 279 self.groupBoxThermal.hide() 280 281 self.initializeVariables() 282 283 def initSyrthesInstanceList(self): 284 syrthes_instances = self.cht_model.getSyrthesInstancesList() 285 current_instance = self.__boundary.getConjugateHeatTransferCoupling() 286 if current_instance: 287 self.lineEditSyrthesInstance.setText(str(current_instance)) 288 289 def initializeVariables(self): 290 """ 291 Initialize widget 292 """ 293 # Initalize exchange coef 294 self.lineEditExThermal.hide() 295 self.labelExThermal.hide() 296 self.lineEditExSpecies.hide() 297 self.labelExSpecies.hide() 298 self.lineEditExMeteo.hide() 299 self.labelExMeteo.hide() 300 301 # Initalize thermal 302 self.lineEditValueThermal.hide() 303 self.labelValueThermal.hide() 304 self.pushButtonThermal.setEnabled(False) 305 self.pushButtonThermal.setStyleSheet("background-color: None") 306# self.groupBoxSyrthes.hide() 307 self.labelSyrthesInstance.hide() 308 self.lineEditSyrthesInstance.hide() 309 310 if self.model_th != 'off' and self.comp.getCompressibleModel() == 'off': 311 self.modelTypeThermal.setItem(str_model=self.thermal_type) 312 self.labelValueThermal.setText('Value') 313 self.groupBoxThermal.setTitle('Thermal') 314 315 thermal_type, convert = self.__get_thermal_type__() 316 if thermal_type in ('dirichlet', 'exchange_coefficient', 'neumann'): 317 self.labelValueThermal.show() 318 self.lineEditValueThermal.show() 319 320 if thermal_type == 'exchange_coefficient': 321 self.lineEditExThermal.show() 322 self.labelExThermal.show() 323 v = self.__boundary.getScalarValue(self.thermal, 'dirichlet') 324 w = self.__boundary.getScalarValue(self.thermal, 'exchange_coefficient') 325 self.lineEditValueThermal.setText(str(v)) 326 self.lineEditExThermal.setText(str(w)) 327 else: 328 v = self.__boundary.getScalarValue(self.thermal, thermal_type) 329 self.lineEditValueThermal.setText(str(v)) 330 331 if thermal_type == 'neumann': 332 self.labelValueThermal.setText('Flux') 333 if self.nature == 'outlet': 334 self.groupBoxThermal.setTitle('Thermal for backflow') 335 336 elif thermal_type in ('exchange_coefficient_formula', 'dirichlet_formula', 337 'neumann_formula'): 338 self.pushButtonThermal.setEnabled(True) 339 exp = self.__boundary.getScalarFormula(self.thermal, thermal_type) 340 if exp: 341 self.pushButtonThermal.setStyleSheet("background-color: green") 342 self.pushButtonThermal.setToolTip(exp) 343 else: 344 self.pushButtonThermal.setStyleSheet("background-color: red") 345 346 elif self.thermal_type == "syrthes_coupling": 347 self.labelSyrthesInstance.show() 348 self.lineEditSyrthesInstance.show() 349 syrCompleter = QCompleter(self.cht_model.getSyrthesInstancesList()) 350 self.lineEditSyrthesInstance.setCompleter(syrCompleter) 351 352 # Initalize species 353 self.labelValueSpecies.hide() 354 self.lineEditValueSpecies.hide() 355 self.pushButtonSpecies.setEnabled(False) 356 self.pushButtonSpecies.setStyleSheet("background-color: None") 357 358 if self.species_list != None and self.species_list != []: 359 self.species_type = self.__boundary.getScalarChoice(self.species) 360 self.modelTypeSpecies.setItem(str_model=self.species_type) 361 self.labelValueSpecies.setText('Value') 362 self.groupBoxSpecies.setTitle('Species') 363 364 if self.species_type in ('dirichlet', 'exchange_coefficient', 'neumann'): 365 self.labelValueSpecies.show() 366 self.lineEditValueSpecies.show() 367 368 if self.species_type == 'exchange_coefficient': 369 self.lineEditExSpecies.show() 370 self.labelExSpecies.show() 371 v = self.__boundary.getScalarValue(self.species, 'dirichlet') 372 w = self.__boundary.getScalarValue(self.species, 'exchange_coefficient') 373 if self.nature == 'groundwater': 374 self.labelValueSpecies.setText('Velocity') 375 self.labelExSpecies.setText('Concentration') 376 self.lineEditValueSpecies.setText(str(v)) 377 self.lineEditExSpecies.setText(str(w)) 378 else: 379 v = self.__boundary.getScalarValue(self.species, self.species_type) 380 self.lineEditValueSpecies.setText(str(v)) 381 382 if self.species_type == 'neumann': 383 self.labelValueSpecies.setText('Flux') 384 if self.nature == 'outlet': 385 self.groupBoxSpecies.setTitle('Species for backflow') 386 387 elif self.species_type in ('exchange_coefficient_formula', 388 'dirichlet_formula', 'neumann_formula'): 389 self.pushButtonSpecies.setEnabled(True) 390 exp = self.__boundary.getScalarFormula(self.species, self.species_type) 391 if exp: 392 self.pushButtonSpecies.setStyleSheet("background-color: green") 393 self.pushButtonSpecies.setToolTip(exp) 394 else: 395 self.pushButtonSpecies.setStyleSheet("background-color: red") 396 397 if self.nature == 'groundwater': 398 self.groupBoxSpecies.setTitle('Transport equation') 399 400 # Initalize meteo 401 self.labelValueMeteo.hide() 402 self.lineEditValueMeteo.hide() 403 self.pushButtonMeteo.setEnabled(False) 404 self.pushButtonMeteo.setStyleSheet("background-color: None") 405 406 if (self.meteo_list): 407 label = self.__boundary.getLabel() 408 if self.nature != 'wall': 409 nature = "meteo_" + self.nature 410 else: 411 nature = self.nature 412 bb = Boundary(nature, label, self.case) 413 414 if self.nature == 'wall' or bb.getMeteoDataStatus() == 'off': 415 self.meteo_type = self.__boundary.getScalarChoice(self.meteo) 416 self.modelTypeMeteo.setItem(str_model = self.meteo_type) 417 self.labelValueMeteo.setText('Value') 418 self.groupBoxMeteo.setTitle('Meteo') 419 420 if self.meteo_type in ('dirichlet', 'exchange_coefficient', 'neumann'): 421 self.labelValueMeteo.show() 422 self.lineEditValueMeteo.show() 423 424 if self.meteo_type == 'exchange_coefficient': 425 self.lineEditExMeteo.show() 426 self.labelExMeteo.show() 427 v = self.__boundary.getScalarValue(self.meteo, 'dirichlet') 428 w = self.__boundary.getScalarValue(self.meteo, 'exchange_coefficient') 429 self.lineEditValueMeteo.setText(str(v)) 430 self.lineEditExMeteo.setText(str(w)) 431 else: 432 v = self.__boundary.getScalarValue(self.meteo, self.meteo_type) 433 self.lineEditValueMeteo.setText(str(v)) 434 435 if self.meteo_type == 'neumann': 436 self.labelValueMeteo.setText('Flux') 437 if self.nature == 'outlet': 438 self.groupBoxMeteo.setTitle('Meteo for backflow') 439 440 if self.meteo_type in ('exchange_coefficient_formula', 441 'dirichlet_formula', 'neumann_formula'): 442 self.pushButtonMeteo.setEnabled(True) 443 exp = self.__boundary.getScalarFormula(self.meteo, self.meteo_type) 444 if exp: 445 self.pushButtonMeteo.setStyleSheet("background-color: green") 446 self.pushButtonMeteo.setToolTip(exp) 447 else: 448 self.pushButtonMeteo.setStyleSheet("background-color: red") 449 450 451 def showWidget(self, boundary): 452 """ 453 Show the widget 454 """ 455 if DefineUserScalarsModel(self.case).getScalarNameList() or\ 456 DefineUserScalarsModel(self.case).getMeteoScalarsNameList() or\ 457 DefineUserScalarsModel(self.case).getThermalScalarName(): 458 self.__setBoundary(boundary) 459 self.show() 460 else: 461 self.hideWidget() 462 463 464 def hideWidget(self): 465 """ 466 Hide all 467 """ 468 self.hide() 469 470 471 @pyqtSlot(str) 472 def slotThermalChoice(self, text): 473 """ 474 INPUT label for choice of zone 475 """ 476 self.thermal = self.modelThermal.dicoV2M[str(text)] 477 self.initializeVariables() 478 479 480 @pyqtSlot(str) 481 def slotThermalTypeChoice(self, text): 482 """ 483 INPUT label for choice of zone 484 """ 485 self.thermal_type = self.modelTypeThermal.dicoV2M[str(text)] 486 thermal_type, convert = self.__get_thermal_type__() 487 self.__boundary.setScalarChoice(self.thermal, thermal_type) 488 if not convert: 489 convert = None 490 self.__boundary.setScalarConvert(self.thermal, convert=convert) 491 492 self.initializeVariables() 493 494 495 @pyqtSlot(str) 496 def slotSpeciesChoice(self, text): 497 """ 498 INPUT label for choice of zone 499 """ 500 self.species = self.modelSpecies.dicoV2M[str(text)] 501 self.initializeVariables() 502 503 504 @pyqtSlot(str) 505 def slotSpeciesTypeChoice(self, text): 506 """ 507 INPUT label for choice of zone 508 """ 509 self.species_type = self.modelTypeSpecies.dicoV2M[str(text)] 510 self.__boundary.setScalarChoice(self.species, self.species_type) 511 self.initializeVariables() 512 513 514 @pyqtSlot(str) 515 def slotMeteoChoice(self, text): 516 """ 517 INPUT label for choice of zone 518 """ 519 self.meteo = self.modelMeteo.dicoV2M[str(text)] 520 self.initializeVariables() 521 522 523 @pyqtSlot(str) 524 def slotMeteoTypeChoice(self, text): 525 """ 526 INPUT label for choice of zone 527 """ 528 self.meteo_type= self.modelTypeMeteo.dicoV2M[str(text)] 529 self.__boundary.setScalarChoice(self.meteo, self.meteo_type) 530 self.initializeVariables() 531 532 533 @pyqtSlot() 534 def slotThermalFormula(self): 535 """ 536 """ 537 name = self.thermal 538 variable_name = name 539 thermal_type, convert = self.__get_thermal_type__() 540 if convert: 541 name = convert 542 543 exp = self.__boundary.getScalarFormula(self.thermal, thermal_type) 544 exa = """#example: """ 545 if thermal_type == 'dirichlet_formula': 546 req = [(name, str(name))] 547 elif thermal_type == 'neumann_formula': 548 req = [("flux", "flux")] 549 elif thermal_type == 'exchange_coefficient_formula': 550 req = [(name, str(name)),("hc", "heat coefficient")] 551 552 sym = [('x', "X face's gravity center"), 553 ('y', "Y face's gravity center"), 554 ('z', "Z face's gravity center"), 555 ('dt', 'time step'), 556 ('t', 'current time'), 557 ('iter', 'number of iteration'), 558 ('surface', 'Boundary zone surface')] 559 560 for (nme, val) in self.notebook.getNotebookList(): 561 sym.append((nme, 'value (notebook) = ' + str(val))) 562 563 c = self.__boundary.getScalarChoice(variable_name) 564 565 dialog = QMegEditorView(parent = self, 566 function_type = 'bnd', 567 zone_name = self.__boundary._label, 568 variable_name = name, 569 expression = exp, 570 required = req, 571 symbols = sym, 572 condition = c, 573 examples = exa) 574 575 if dialog.exec_(): 576 result = dialog.get_result() 577 log.debug("slotThermalFormula -> %s" % str(result)) 578 self.__boundary.setScalarFormula(self.thermal, thermal_type, str(result)) 579 self.pushButtonThermal.setStyleSheet("background-color: green") 580 self.pushButtonThermal.setToolTip(exp) 581 582 583 @pyqtSlot() 584 def slotSpeciesFormula(self): 585 """ 586 """ 587 exp = self.__boundary.getScalarFormula(self.species, self.species_type) 588 exa = """#example: """ 589 if self.species_type == 'dirichlet_formula': 590 req = [(self.species, str(self.species))] 591 elif self.species_type == 'neumann_formula': 592 req = [("flux", "flux")] 593 elif self.species_type == 'exchange_coefficient_formula': 594 req = [(self.species, str(self.species)),("hc", "heat coefficient")] 595 596 sym = [('x', "X face's gravity center"), 597 ('y', "Y face's gravity center"), 598 ('z', "Z face's gravity center"), 599 ('dt', 'time step'), 600 ('t', 'current time'), 601 ('iter', 'number of iteration'), 602 ('surface', 'Boundary zone surface')] 603 604 for (nme, val) in self.notebook.getNotebookList(): 605 sym.append((nme, 'value (notebook) = ' + str(val))) 606 607 c = self.__boundary.getScalarChoice(self.species) 608 dialog = QMegEditorView(parent = self, 609 function_type = 'bnd', 610 zone_name = self.__boundary._label, 611 variable_name = self.species, 612 expression = exp, 613 required = req, 614 symbols = sym, 615 condition = c, 616 examples = exa) 617 618 if dialog.exec_(): 619 result = dialog.get_result() 620 log.debug("slotSpeciesFormula -> %s" % str(result)) 621 self.__boundary.setScalarFormula(self.species, self.species_type, str(result)) 622 self.pushButtonSpecies.setStyleSheet("background-color: green") 623 self.pushButtonSpecies.setToolTip(exp) 624 625 626 @pyqtSlot() 627 def slotMeteoFormula(self): 628 """ 629 """ 630 exp = self.__boundary.getScalarFormula(self.meteo, self.meteo_type) 631 exa = """#example: """ 632 if self.meteo_type == 'dirichlet_formula': 633 req = [(self.meteo, str(self.meteo))] 634 elif self.meteo_type == 'neumann_formula': 635 req = [("flux", "flux")] 636 elif self.meteo_type == 'exchange_coefficient_formula': 637 req = [(self.meteo, str(self.meteo)), 638 ("hc", "heat coefficient")] 639 640 sym = [('x', "X face's gravity center"), 641 ('y', "Y face's gravity center"), 642 ('z', "Z face's gravity center"), 643 ('dt', 'time step'), 644 ('t', 'current time'), 645 ('iter', 'number of iteration'), 646 ('surface', 'Boundary zone surface')] 647 648 for (nme, val) in self.notebook.getNotebookList(): 649 sym.append((nme, 'value (notebook) = ' + str(val))) 650 651 dialog = QMegEditorView(parent = self, 652 function_type = 'bnd', 653 zone_name = self.__boundary._label, 654 variable_name = self.meteo, 655 expression = exp, 656 required = req, 657 symbols = sym, 658 condition = self.meteo_type, 659 examples = exa) 660 661 if dialog.exec_(): 662 result = dialog.get_result() 663 log.debug("slotMeteoFormula -> %s" % str(result)) 664 self.__boundary.setScalarFormula(self.meteo, self.meteo_type, str(result)) 665 self.pushButtonMeteo.setStyleSheet("background-color: green") 666 self.pushButtonMeteo.setToolTip(exp) 667 668 669 @pyqtSlot(str) 670 def slotValueThermal(self, var): 671 """ 672 """ 673 if self.lineEditValueThermal.validator().state == QValidator.Acceptable: 674 value = from_qvariant(var, float) 675 thermal_type = self.thermal_type.split(':')[0] 676 if thermal_type in ('dirichlet', 'neumann'): 677 self.__boundary.setScalarValue(self.thermal, thermal_type, value) 678 elif thermal_type == 'exchange_coefficient': 679 self.__boundary.setScalarValue(self.thermal, 'dirichlet', value) 680 681 682 @pyqtSlot(str) 683 def slotValueSpecies(self, var): 684 """ 685 """ 686 if self.lineEditValueSpecies.validator().state == QValidator.Acceptable: 687 value = from_qvariant(var, float) 688 if self.species_type in ('dirichlet', 'neumann'): 689 self.__boundary.setScalarValue(self.species, self.species_type, value) 690 elif self.species_type == 'exchange_coefficient' : 691 self.__boundary.setScalarValue(self.species, 'dirichlet', value) 692 693 694 @pyqtSlot(str) 695 def slotValueMeteo(self, var): 696 """ 697 """ 698 if self.lineEditValueMeteo.validator().state == QValidator.Acceptable: 699 value = from_qvariant(var, float) 700 if self.meteo_type in ('dirichlet', 'neumann'): 701 self.__boundary.setScalarValue(self.meteo, self.meteo_type, value) 702 elif self.meteo_type == 'exchange_coefficient': 703 self.__boundary.setScalarValue(self.meteo, 'dirichlet', value) 704 705 706 @pyqtSlot(str) 707 def slotExThermal(self, var): 708 """ 709 """ 710 if self.lineEditExThermal.validator().state == QValidator.Acceptable: 711 value = from_qvariant(var, float) 712 self.__boundary.setScalarValue(self.thermal, 'exchange_coefficient', value) 713 714 715 @pyqtSlot(str) 716 def slotExSpecies(self, var): 717 """ 718 """ 719 if self.lineEditExSpecies.validator().state == QValidator.Acceptable: 720 value = from_qvariant(var, float) 721 self.__boundary.setScalarValue(self.species, 'exchange_coefficient', value) 722 723 @pyqtSlot(str) 724 def slotExMeteo(self, var): 725 """ 726 """ 727 if self.lineEditExMeteo.validator().state == QValidator.Acceptable: 728 value = from_qvariant(var, float) 729 self.__boundary.setScalarValue(self.meteo, 'exchange_coefficient', value) 730 731 @pyqtSlot() 732 def slotChooseSyrthesInstance(self): 733 734 value = str(self.lineEditSyrthesInstance.text()) 735 if value: 736 bnd_label = self.__boundary.getLabel() 737 value_p = self.__boundary.getConjugateHeatTransferCoupling() 738 bnd_label = self.__boundary.getLabel() 739 if value != value_p: 740 self.cht_model.deleteSyrthesCoupling(value_p, bnd_label) 741 742 self.__boundary.setConjugateHeatTransferCoupling(value) 743 744 if value not in self.cht_model.getSyrthesInstancesList(): 745 self.cht_model.addSyrthesCoupling(value) 746 self.cht_model.addBoundaryLabel(value, bnd_label) 747 748 return 749 750#------------------------------------------------------------------------------- 751# End 752#------------------------------------------------------------------------------- 753