1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2019 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
#-------------------------------------------------------------------------------
"""
This module defines the turbulence model data management.
This module contains the following classes:
- TurbulenceAdvancedOptionsDialogView
- TurbulenceView
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import sys, logging
#-------------------------------------------------------------------------------
# Third-party modules
#-------------------------------------------------------------------------------
from code_saturne.Base.QtCore import *
from code_saturne.Base.QtGui import *
from code_saturne.Base.QtWidgets import *
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from code_saturne.model.Common import GuiParam
from code_saturne.Base.QtPage import ComboModel, DoubleValidator, from_qvariant
from code_saturne.Pages.TurbulenceForm import Ui_TurbulenceForm
from code_saturne.Pages.TurbulenceAdvancedOptionsDialogForm import Ui_TurbulenceAdvancedOptionsDialogForm
from code_saturne.model.TurbulenceModel import TurbulenceModel
#-------------------------------------------------------------------------------
# log config
#-------------------------------------------------------------------------------
logging.basicConfig()
log = logging.getLogger("TurbulenceView")
log.setLevel(GuiParam.DEBUG)
#-------------------------------------------------------------------------------
# Advanced dialog
#-------------------------------------------------------------------------------
class TurbulenceAdvancedOptionsDialogView(QDialog, Ui_TurbulenceAdvancedOptionsDialogForm):
"""
Advanced dialog
"""
def __init__(self, parent, case, default):
"""
Constructor
"""
QDialog.__init__(self, parent)
Ui_TurbulenceAdvancedOptionsDialogForm.__init__(self)
self.setupUi(self)
self.case = case
self.case.undoStopGlobal()
if default['model'] in ('k-epsilon', 'k-epsilon-PL'):
title = self.tr("Options for k-epsilon model")
elif default['model'] in ('Rij-epsilon', 'Rij-SSG', 'Rij-EBRSM'):
title = self.tr("Options for Rij-epsilon model")
elif default['model'] == 'k-omega-SST':
title = self.tr("Options for k-omega-SST model")
elif default['model'] == 'v2f-BL-v2/k':
title = self.tr("Options for v2f-BL-v2/k model")
elif default['model'] == 'Spalart-Allmaras':
title = self.tr("Options for Spalart-Allmaras model")
self.setWindowTitle(title)
self.default = default
self.result = self.default.copy()
self.checkBoxGravity.setEnabled(True)
self.comboBoxWallFunctions.setEnabled(True)
if default['model'] == 'Rij-EBRSM':
# Combo - piecewise laws (iwallf=2,3) unavailable through the GUI
self.wallFunctions = ComboModel(self.comboBoxWallFunctions, 2, 1)
self.wallFunctions.addItem(self.tr("No wall function"), '0')
self.wallFunctions.addItem(self.tr("2-scale model (all y+)"), '7')
# Initialization of wall function model
self.wallFunctions.setItem(str_model=str(self.result['wall_function']))
elif default['model'] == 'v2f-BL-v2/k':
self.wallFunctions = ComboModel(self.comboBoxWallFunctions, 1, 1)
self.wallFunctions.addItem(self.tr("No wall function"), '0')
self.comboBoxWallFunctions.setEnabled(False)
elif default['model'] == 'Spalart-Allmaras':
self.wallFunctions = ComboModel(self.comboBoxWallFunctions, 1, 1)
self.wallFunctions.addItem(self.tr("One scale model (log law)"), '2')
self.comboBoxWallFunctions.setEnabled(False)
elif default['model'] == 'k-omega-SST':
# Combo - power law (iwallf=1) unavailable through the GUI
self.wallFunctions = ComboModel(self.comboBoxWallFunctions, 5, 1)
self.wallFunctions.addItem(self.tr("No wall function"), '0')
self.wallFunctions.addItem(self.tr("1-scale model (log law)"), '2')
self.wallFunctions.addItem(self.tr("2-scale model (log law)"), '3')
self.wallFunctions.addItem(self.tr("2-scale model (all y+)"), '7')
self.wallFunctions.addItem(self.tr("Scalable 2-scale model (log law)"), '4')
# Initialization of wall function model
self.wallFunctions.setItem(str_model=str(self.result['wall_function']))
else:
# Combo - power law (iwallf=1) unavailable through the GUI
self.wallFunctions = ComboModel(self.comboBoxWallFunctions, 4, 1)
self.wallFunctions.addItem(self.tr("No wall function"), '0')
self.wallFunctions.addItem(self.tr("1-scale model (log law)"), '2')
self.wallFunctions.addItem(self.tr("2-scale model (log law)"), '3')
self.wallFunctions.addItem(self.tr("Scalable 2-scale model (log law)"), '4')
# Initialization of wall function model
self.wallFunctions.setItem(str_model=str(self.result['wall_function']))
# Initialization gravity terms
if self.result['gravity_terms'] == 'on':
self.checkBoxGravity.setChecked(True)
else:
self.checkBoxGravity.setChecked(False)
self.case.undoStartGlobal()
def get_result(self):
"""
Method to get the result
"""
return self.result
def accept(self):
"""
Method called when user clicks 'OK'
"""
if self.checkBoxGravity.isChecked():
self.result['gravity_terms'] = "on"
else:
self.result['gravity_terms'] = "off"
self.result['wall_function'] = \
int(self.wallFunctions.dicoV2M[str(self.comboBoxWallFunctions.currentText())])
QDialog.accept(self)
def reject(self):
"""
Method called when user clicks 'Cancel'
"""
QDialog.reject(self)
def tr(self, text):
"""
Translation
"""
return text
#-------------------------------------------------------------------------------
# Main view class
#-------------------------------------------------------------------------------
class TurbulenceView(QWidget, Ui_TurbulenceForm):
"""
Class to open Turbulence Page.
"""
def __init__(self, parent=None, case=None):
"""
Constructor
"""
QWidget.__init__(self, parent)
Ui_TurbulenceForm.__init__(self)
self.setupUi(self)
self.case = case
self.case.undoStopGlobal()
self.model = TurbulenceModel(self.case)
# Combo model
self.modelTurbModel = ComboModel(self.comboBoxTurbModel,10,1)
self.modelTurbModel.addItem(self.tr("No model (i.e. laminar flow)"), "off")
self.modelTurbModel.addItem(self.tr("Mixing length"), "mixing_length")
self.modelTurbModel.addItem(self.tr("k-epsilon"), "k-epsilon")
self.modelTurbModel.addItem(self.tr("k-epsilon Linear Production"), "k-epsilon-PL")
self.modelTurbModel.addItem(self.tr("Rij-epsilon LRR"), "Rij-epsilon")
self.modelTurbModel.addItem(self.tr("Rij-epsilon SSG"), "Rij-SSG")
self.modelTurbModel.addItem(self.tr("Rij-epsilon EBRSM"), "Rij-EBRSM")
self.modelTurbModel.addItem(self.tr("v2f BL-v2/k"), "v2f-BL-v2/k")
self.modelTurbModel.addItem(self.tr("k-omega SST"), "k-omega-SST")
self.modelTurbModel.addItem(self.tr("Spalart-Allmaras"), "Spalart-Allmaras")
self.modelTurbModel.addItem(self.tr("LES (Smagorinsky)"), "LES_Smagorinsky")
self.modelTurbModel.addItem(self.tr("LES (classical dynamic model)"), "LES_dynamique")
self.modelTurbModel.addItem(self.tr("LES (WALE)"), "LES_WALE")
self.modelLength = ComboModel(self.comboBoxLength,2,1)
self.modelLength.addItem(self.tr("Automatic"), 'automatic')
self.modelLength.addItem(self.tr("Prescribed"), 'prescribed')
self.comboBoxLength.setSizeAdjustPolicy(QComboBox.AdjustToContents)
# Connections
self.comboBoxTurbModel.activated[str].connect(self.slotTurbulenceModel)
self.pushButtonAdvanced.clicked.connect(self.slotAdvancedOptions)
self.lineEditLength.textChanged[str].connect(self.slotLengthScale)
self.lineEditV0.textChanged[str].connect(self.slotVelocity)
self.comboBoxLength.activated[str].connect(self.slotLengthChoice)
self.lineEditL0.textChanged[str].connect(self.slotLength)
# Frames display
self.frameAdvanced.hide()
self.frameLength.hide()
# Validators
validator = DoubleValidator(self.lineEditLength, min=0.0)
validator.setExclusiveMin(True)
self.lineEditLength.setValidator(validator)
validatorV0 = DoubleValidator(self.lineEditV0, min=0.0)
self.lineEditV0.setValidator(validatorV0)
validatorL0 = DoubleValidator(self.lineEditL0, min=0.0)
self.lineEditL0.setValidator(validatorL0)
# Update the turbulence models list with the calculation features
for turb in self.model.turbulenceModels():
if turb not in self.model.turbulenceModelsList():
self.modelTurbModel.disableItem(str_model=turb)
# Select the turbulence model
model = self.model.getTurbulenceModel()
self.modelTurbModel.setItem(str_model=model)
self.__initializeView()
# Length scale
l_scale = self.model.getLengthScale()
self.lineEditLength.setText(str(l_scale))
# Initialization
v = self.model.getVelocity()
self.lineEditV0.setText(str(v))
init_length_choice = self.model.getLengthChoice()
self.modelLength.setItem(str_model=init_length_choice)
if init_length_choice == 'automatic':
self.lineEditL0.setText(str())
self.lineEditL0.hide()
self.labelUnitL0.hide()
else:
self.lineEditL0.show()
self.labelUnitL0.show()
l = self.model.getLength()
self.lineEditL0.setText(str(l))
self.case.undoStartGlobal()
def __initializeView(self):
"""
Private Method.
initalize view for a turbulence model
"""
model = self.model.getTurbulenceModel()
self.frameAdvanced.hide()
self.frameLength.hide()
self.groupBoxReferenceValues.hide()
if model not in ('off', 'mixing_length', 'LES_Smagorinsky', 'LES_dynamique', 'LES_WALE'):
self.groupBoxReferenceValues.show()
if model == 'mixing_length':
self.frameLength.show()
self.frameAdvanced.hide()
self.model.getLengthScale()
elif model not in ('off', 'LES_Smagorinsky', 'LES_dynamique', 'LES_WALE', 'Spalart-Allmaras'):
self.frameLength.hide()
self.frameAdvanced.show()
if model in ('off', 'LES_Smagorinsky', 'LES_dynamique', 'LES_WALE', 'Spalart-Allmaras'):
self.line.hide()
else:
self.line.show()
@pyqtSlot(str)
def slotLengthScale(self, text):
"""
Private slot.
Input XLOMLG.
"""
if self.lineEditLength.validator().state == QValidator.Acceptable:
l_scale = from_qvariant(text, float)
self.model.setLengthScale(l_scale)
@pyqtSlot(str)
def slotTurbulenceModel(self, text):
"""
Private slot.
Input ITURB.
"""
model = self.modelTurbModel.dicoV2M[str(text)]
self.model.setTurbulenceModel(model)
self.__initializeView()
@pyqtSlot(str)
def slotVelocity(self, text):
"""
Private slot.
Input reference velocity.
"""
if self.lineEditV0.validator().state == QValidator.Acceptable:
v = from_qvariant(text, float)
self.model.setVelocity(v)
@pyqtSlot(str)
def slotLengthChoice(self,text):
"""
Private slot.
Input mode for reference length.
"""
choice = self.modelLength.dicoV2M[str(text)]
self.model.setLengthChoice(choice)
if choice == 'automatic':
self.lineEditL0.setText(str())
self.lineEditL0.hide()
self.labelUnitL0.hide()
else:
self.lineEditL0.show()
self.labelUnitL0.show()
value = self.model.getLength()
self.lineEditL0.setText(str(value))
log.debug("slotlengthchoice-> %s" % choice)
@pyqtSlot(str)
def slotLength(self, text):
"""
Private slot.
Input reference length.
"""
if self.lineEditL0.validator().state == QValidator.Acceptable:
l = from_qvariant(text, float)
self.model.setLength(l)
@pyqtSlot()
def slotAdvancedOptions(self):
"""
Private slot.
Ask one popup for advanced specifications
"""
default = {}
default['model'] = self.model.getTurbulenceModel()
default['wall_function'] = self.model.getWallFunction()
default['gravity_terms'] = self.model.getGravity()
log.debug("slotAdvancedOptions -> %s" % str(default))
dialog = TurbulenceAdvancedOptionsDialogView(self, self.case, default)
if dialog.exec_():
result = dialog.get_result()
log.debug("slotAdvancedOptions -> %s" % str(result))
self.model.setTurbulenceModel(result['model'])
self.model.setWallFunction(result['wall_function'])
self.model.setGravity(result['gravity_terms'])
def tr(self, text):
"""
Translation
"""
return text
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|