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
|
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2014 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 contains the following classes:
- StandardItemModelBoundaries
- StandardItemModelScalars
- RadiativeBoundariesView
"""
#-------------------------------------------------------------------------------
# Standard modules
#-------------------------------------------------------------------------------
import logging
#-------------------------------------------------------------------------------
# Third-party modules
#-------------------------------------------------------------------------------
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from Pages.BoundaryConditionsWallRadiativeTransferForm import \
Ui_BoundaryConditionsWallRadiativeTransferForm
from Pages.ThermalRadiationModel import ThermalRadiationModel
from Base.Toolbox import GuiParam
from Base.QtPage import IntValidator, DoubleValidator, ComboModel, setGreenColor
from Base.QtPage import to_qvariant, from_qvariant
from Pages.LocalizationModel import LocalizationModel, Zone
from Pages.Boundary import Boundary
#-------------------------------------------------------------------------------
# log config
#-------------------------------------------------------------------------------
logging.basicConfig()
log = logging.getLogger("BoundaryConditionsWallRadiativeTransferView")
#-------------------------------------------------------------------------------
# StandarItemModel class to display scalars properties
#-------------------------------------------------------------------------------
class StandardItemModelScalars(QStandardItemModel):
def __init__(self, bdModel):
QStandardItemModel.__init__(self)
self.headers = [self.tr("Wall radiative\ncaracteristics"),
self.tr("Value"),
self.tr("Unit")]
self.setColumnCount(len(self.headers))
self.bdModel = bdModel
self.lst = self.getListVariablesForCondition()
self.setRowCount(len(self.lst))
log.debug("StandardItemModelScalars.__init__ lst = %s " % str(self.lst))
self.dataScalars = {}
self.dataScalars["EPSP"] = bdModel.getEmissivity()
self.dataScalars["XLAMP"] = bdModel.getThermalConductivity()
self.dataScalars["EPAP"] = bdModel.getThickness()
self.dataScalars["TEXTP"] = bdModel.getExternalTemperatureProfile()
self.dataScalars["TINTP"] = bdModel.getInternalTemperatureProfile()
self.dataScalars["FLUX"] = bdModel.getFlux()
def data(self, index, role):
if not index.isValid():
return to_qvariant()
if role == Qt.DisplayRole:
if index.column() == 0:
return to_qvariant(self.lst[index.row()][1])
elif index.column() == 1:
key = self.lst[index.row()][3]
return to_qvariant(self.dataScalars[key])
elif index.column() == 2:
return to_qvariant(self.lst[index.row()][2])
if role == Qt.ToolTipRole:
kword = self.lst[index.row()][3]
return to_qvariant(self.tr("Code_Saturne keyword: " + kword))
return to_qvariant()
def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled
elif index.column() == 1:
return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
else:
return Qt.ItemIsEnabled | Qt.ItemIsSelectable
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return to_qvariant(self.headers[section])
return to_qvariant()
def setData(self, index, value, role):
if index.column() == 1:
row = index.row()
key = self.lst[row][3]
tag = self.lst[row][4]
val = from_qvariant(value, float)
self.bdModel.setValRay(val, tag)
self.dataScalars[key] = val
self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), index, index)
return True
def deleteAll(self):
self.dataScalars = []
self.setRowCount(0)
def insertItem(self):
self.dataScalars.append()
row = self.rowCount()
self.setRowCount(row+1)
def getItem(self, row):
return self.dataScalars[row]
def getListVariablesForCondition(self):
"""
Get list of variables for condition choosed
"""
cond = self.bdModel.getRadiativeChoice()
if cond == 'itpimp':
lst = [(0, self.tr("Emissivite"), '', 'EPSP', 'emissivity'),
(1, self.tr("Initial temperature"), 'K', 'TINTP', 'internal_temperature_profile')]
if cond == 'ipgrno':
lst = [(0, self.tr("Emissivity"), '', 'EPSP', 'emissivity'),
(1, self.tr("Conductivity"), 'W/m/K', 'XLAMP', 'wall_thermal_conductivity'),
(2, self.tr("Thickness"), 'm', 'EPAP' , 'thickness'),
(3, self.tr("Profile of external temperature"), 'K', 'TEXTP', 'external_temperature_profile'),
(4, self.tr("Profile of internal temperature"), 'K', 'TINTP', 'internal_temperature_profile')]
if cond == 'ifgrno':
lst = [(0, self.tr("Emissivity"),'', 'EPSP', 'emissivity'),
(1, self.tr("Flux of conduction"), 'W/m2', 'FLUX', 'flux'),
(2, self.tr("Inital temperature"), 'K', 'TINTP', 'internal_temperature_profile')]
return lst
#-------------------------------------------------------------------------------
# Main class
#-------------------------------------------------------------------------------
class BoundaryConditionsWallRadiativeTransferView(QWidget,
Ui_BoundaryConditionsWallRadiativeTransferForm):
"""
"""
def __init__(self, parent):
"""
Constructor
"""
QWidget.__init__(self, parent)
Ui_BoundaryConditionsWallRadiativeTransferForm.__init__(self)
self.setupUi(self)
def setup(self, case):
"""
Setup the widget
"""
self.__case = case
self.__boundary = None
self.__case.undoStopGlobal()
# Create the Page layout.
# Combo
self.modelRadiative = ComboModel(self.comboBoxRadiative,3,1)
self.modelRadiative.addItem(self.tr("Gray or black wall\n"\
" and profile of fixed internal temperature"), 'itpimp')
self.modelRadiative.addItem(self.tr("Gray or black wall\n"\
" and profile of fixed external temperature"), 'ipgrno')
self.modelRadiative.addItem(self.tr("Gray or black wall\n"\
" and flux of fixed conduction"), 'ifgrno')
# Validator
validatorZone = IntValidator(self.lineEditZone, min=0)
validatorZone.setExclusiveMin(True)
self.lineEditZone.setValidator(validatorZone)
# Connections
self.connect(self.comboBoxRadiative,
SIGNAL("activated(const QString&)"),
self.slotRadiativeChoice)
self.connect(self.lineEditZone,
SIGNAL("textChanged(const QString &)"),
self.slotZone)
self.__case.undoStartGlobal()
def showWidget(self, b):
"""
Show the widget
"""
if ThermalRadiationModel(self.__case).getRadiativeModel() != "off":
label = b.getLabel()
self.__boundary = Boundary('radiative_wall', label, self.__case)
choice = self.__boundary.getRadiativeChoice()
self.modelRadiative.setItem(str_model=choice)
if hasattr(self, "modelScalars"):
del self.modelScalars
self.modelScalars = StandardItemModelScalars(self.__boundary)
self.tableViewScalars.setModel(self.modelScalars)
self.nb_zone = self.__boundary.getOutputRadiativeZone()
self.lineEditZone.setText(str(self.nb_zone))
self.show()
else:
self.hideWidget()
def hideWidget(self):
"""
Hide all the widget
"""
self.hide()
@pyqtSignature("const QString&")
def slotZone(self, text):
if self.sender().validator().state == QValidator.Acceptable:
nb_zone = from_qvariant(text, int)
self.__boundary.setOutputRadiativeZone(nb_zone)
return nb_zone
@pyqtSignature("const QString&")
def slotRadiativeChoice(self, text):
cond = self.modelRadiative.dicoV2M[str(text)]
log.debug("slotRadiativeChoice cond = %s "%cond)
self.__boundary.setRadiativeChoice(cond)
self.modelScalars.deleteAll()
self.modelScalars = StandardItemModelScalars(self.__boundary)
self.tableViewScalars.setModel(self.modelScalars)
def tr(self, text):
"""
Translation
"""
return text
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|