# -*- coding: iso-8859-1 -*- # #------------------------------------------------------------------------------- # Code_Saturne version 1.3 # ------------------------ # # # This file is part of the Code_Saturne User Interface, element of the # Code_Saturne CFD tool. # # Copyright (C) 1998-2007 EDF S.A., France # # contact: saturne-support@edf.fr # # The Code_Saturne User Interface 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. # # The Code_Saturne User Interface 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 the Code_Saturne Kernel; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301 USA # #------------------------------------------------------------------------------- """ This module defines the storage system type. This module contains the following classes and function: - MatisseGeomModel - MatisseGeomView - PageText """ #------------------------------------------------------------------------------- # Library modules import #------------------------------------------------------------------------------- import Tix from Tkconstants import * import shutil, sys, unittest #------------------------------------------------------------------------------- # Application modules import #------------------------------------------------------------------------------- from Base.Common import * import Base.Toolbox as Tool import Base.TkPage as TkPage import Pages.MatisseType as MatisseType #------------------------------------------------------------------------------- # Turbulence model class #------------------------------------------------------------------------------- class MatisseGeomModel: """ Manage the input/output markups in the xml doc about Turbulence """ def __init__(self, case): """ Constructor. """ self.case = case self.node_matisse = self.case.root().xmlInitChildNode('matisse') self.node_mesh = self.node_matisse.xmlInitChildNode('mesh') self.node_compute = self.node_matisse.xmlInitChildNode('compute') self.node_geom_mesh = self.node_mesh.xmlInitChildNode('geometry') self.node_geom_compute = self.node_compute.xmlInitChildNode('geometry') self.mesh_geom_vars = ['nechrg','nergrs','neclrg','neciel','nergch', 'jeuchr','jeurcl','jeuclr','jeurch', 'hbdtoi'] self.compute_geom_vars = ['epchem','nptran','nplgrs','nelgrs', 'nchest','netran','epregi','hconve', 'rconve','hchali','hcheva','hfttoi', 'ptrres','frdtra','plgres','epchel', 'dmcont'] typeModel = MatisseType.MatisseTypeModel(self.case) self.matisseType = typeModel.getMatisseType() def defaultMatisseGeomValues(self): """ Return in a dictionnary which contains default values """ default = {} # # node geom_mesh default['nechrg'] = 1 default['nergrs'] = 5 default['neclrg'] = 5 default['nergch'] = 1 default['neciel'] = 20 default['jeuchr'] = 0.2 default['jeurcl'] = 2. default['jeuclr'] = 2. default['jeurch'] = 0.2 default['hbdtoi'] = 15. # # node geom_compute default['epchem'] = 2. default['nptran'] = 1 default['nplgrs'] = 24 default['nelgrs'] = 1 default['nchest'] = 24 default['netran'] = 1 default['epregi'] = 1. default['hconve'] = 15. default['rconve'] = 4.93 default['hchali'] = 24. default['hcheva'] = 24. default['hfttoi'] = 20. default['ptrres'] = 0.8 default['frdtra'] = 1. default['plgres'] = 0.7 default['epchel'] = 0.333 default['dmcont'] = 0.347 return default def setMatisseGeomVar(self, tag, val): """ """ if tag in self.mesh_geom_vars : self.node_geom_mesh.xmlSetData(tag, val) elif tag in self.compute_geom_vars : self.node_geom_compute.xmlSetData(tag, val) else : print tag + ": unknown parameter" sys.exit(1) self.updateMeshAndProbes() def getMatisseGeomIntVar(self,tag): """ """ if tag in self.mesh_geom_vars : val = self.node_geom_mesh.xmlGetInt(tag) elif tag in self.compute_geom_vars : val = self.node_geom_compute.xmlGetInt(tag) else : print tag+" : Paramètre non classé" sys.exit(1) if val == "" or val == None: if tag in self.mesh_geom_vars : self.node_geom_mesh.xmlInitChildNode(tag) elif tag in self.compute_geom_vars : self.node_geom_compute.xmlInitChildNode(tag) val = self.defaultMatisseGeomValues()[tag] self.setMatisseGeomVar(tag, val) return val def getMatisseGeomDoubleVar(self,tag): """ """ if tag in self.mesh_geom_vars : val = self.node_geom_mesh.xmlGetDouble(tag) elif tag in self.compute_geom_vars : val = self.node_geom_compute.xmlGetDouble(tag) else : print tag+" : Paramètre non classé" sys.exit(1) if val == "" or val == None: if tag in self.mesh_geom_vars : self.node_geom_mesh.xmlInitChildNode(tag) elif tag in self.compute_geom_vars : self.node_geom_compute.xmlInitChildNode(tag) val = self.defaultMatisseGeomValues()[tag] self.setMatisseGeomVar(tag, val) return val def updateMeshAndProbes(self): """ """ self.replaceText={} self.replaceText['PTTUB'] = str(self.getMatisseGeomDoubleVar('ptrres')) self.replaceText['NLIGN'] = str(self.getMatisseGeomIntVar('nptran')) self.replaceText['PLTUB'] = str(self.getMatisseGeomDoubleVar('plgres')) self.replaceText['NRANG'] = str(self.getMatisseGeomIntVar('nplgrs')) self.replaceText['PVTUB'] = str(self.getMatisseGeomDoubleVar('epchel')) self.replaceText['NZTUB'] = str(self.getMatisseGeomIntVar('nchest')) self.replaceText['ABAMON'] = str(self.getMatisseGeomDoubleVar('epregi')) self.replaceText['EPSCHEM'] = str(self.getMatisseGeomDoubleVar('epchem')) self.replaceText['HCHALIM'] = str(self.getMatisseGeomDoubleVar('hchali')) self.replaceText['HCHEVAC'] = str(self.getMatisseGeomDoubleVar('hcheva')) self.replaceText['NCELT'] = str(self.getMatisseGeomIntVar('netran')) self.replaceText['NCELL'] = str(self.getMatisseGeomIntVar('nelgrs')) self.replaceText['GAPGECH'] = str(self.getMatisseGeomDoubleVar('jeurch')) self.replaceText['NELGECH'] = str(self.getMatisseGeomIntVar('nergch')) self.replaceText['GAPREG'] = str(self.getMatisseGeomDoubleVar('jeuclr')) self.replaceText['NELREG'] = str(self.getMatisseGeomIntVar('neclrg')) self.replaceText['GAPGRE'] = str(self.getMatisseGeomDoubleVar('jeurcl')) self.replaceText['NELGRE'] = str(self.getMatisseGeomIntVar('nergrs')) self.replaceText['GAPCHEG'] = str(self.getMatisseGeomDoubleVar('jeuchr')) self.replaceText['NELCHEG'] = str(self.getMatisseGeomIntVar('nechrg')) self.replaceText['HCONVER'] = str(self.getMatisseGeomDoubleVar('hconve')) self.replaceText['RCONVER'] = str(self.getMatisseGeomDoubleVar('rconve')) self.replaceText['NCELCIEL']= str(self.getMatisseGeomIntVar('neciel')) self.replaceText['HTOITBAS']= str(self.getMatisseGeomDoubleVar('hbdtoi')) self.replaceText['HTOITHAU']= str(self.getMatisseGeomDoubleVar('hfttoi')) self.meshUpdate() self.probesUpdate() def meshUpdate(self): """ Update mesh file """ # # copy of default mesh cs_home = os.popen('echo $CS_HOME').read() if cs_home == '\n': print "CS_HOME is not set" sys.exit(1) defaultMeshDir = cs_home[:-1] + '/data/mati' if (self.matisseType == 'vault') or (self.matisseType == 'djw'): meshFile = 'vault.dat' geomFile = 'vault.geom' desFile = 'vault.des' elif self.matisseType == 'emm': meshFile = 'emm.dat' geomFile = 'emm.geom' desFile = 'emm.des' else: print self.matisseType + ": matisseType unknown" sys.exit(1) geomFileInitName = defaultMeshDir + '/' + geomFile geomFileName = self.case['mesh_path'] + '/' + geomFile meshFileName = self.case['mesh_path'] + '/' + meshFile shutil.copyfile(defaultMeshDir + '/' + meshFile, meshFileName) geomFileInit = open(geomFileInitName, 'r') geomFile = open(geomFileName, 'w') # # update mesh while 1: line = geomFileInit.readline() if line != '': for param in self.replaceText: newLine = line.replace(param,self.replaceText[param]) line = newLine geomFile.write(newLine) else: break # # update node in XML file node_enveloppe = self.case.root().xmlGetNode('solution_domain') node_meshes_list= node_enveloppe.xmlInitChildNode('meshes_list') mesh_nodes = node_meshes_list.xmlGetNodeList('mesh', 'name') if mesh_nodes != []: for i in range(len(mesh_nodes)): if i == 0: mesh_nodes[i]['format'] = 'des' mesh_nodes[i]['name'] = desFile else: mesh_nodes[i].xmlRemoveNode() else : node_meshes_list.xmlInitChildNode('mesh', format='des',name=desFile) def probesUpdate(self): """ Update probes """ # # update probes cy = float(self.replaceText['PLTUB']) nr = int(self.replaceText['NRANG']) cz = float(self.replaceText['PVTUB']) nz = int(self.replaceText['NZTUB']) probes=[] probes.append(["1",[0.02, 0.25*cy*nr/11., 1*0.95*cz*nz/7.]]) probes.append(["2",[0.02, 0.25*cy*nr/11., 2*0.95*cz*nz/7.]]) probes.append(["3",[0.02, 0.25*cy*nr/11., 3*0.95*cz*nz/7.]]) probes.append(["4",[0.02, 0.25*cy*nr/11., 4*0.95*cz*nz/7.]]) probes.append(["5",[0.02, 0.25*cy*nr/11., 5*0.95*cz*nz/7.]]) probes.append(["6",[0.02, 0.25*cy*nr/11., 6*0.95*cz*nz/7.]]) probes.append(["7",[0.02, 0.25*cy*nr/11., 7*0.95*cz*nz/7.]]) probes.append(["8",[0.02, 4.*cy*nr/11., 1*0.95*cz*nz/7.]]) probes.append(["9",[0.02, 4.*cy*nr/11., 2*0.95*cz*nz/7.]]) probes.append(["10",[0.02, 4.*cy*nr/11., 3*0.95*cz*nz/7.]]) probes.append(["11",[0.02, 4.*cy*nr/11., 4*0.95*cz*nz/7.]]) probes.append(["12",[0.02, 4.*cy*nr/11., 5*0.95*cz*nz/7.]]) probes.append(["13",[0.02, 4.*cy*nr/11., 6*0.95*cz*nz/7.]]) probes.append(["14",[0.02, 4.*cy*nr/11., 7*0.95*cz*nz/7.]]) probes.append(["15",[0.02, 7.*cy*nr/11., 1*0.95*cz*nz/7.]]) probes.append(["16",[0.02, 7.*cy*nr/11., 2*0.95*cz*nz/7.]]) probes.append(["17",[0.02, 7.*cy*nr/11., 3*0.95*cz*nz/7.]]) probes.append(["18",[0.02, 7.*cy*nr/11., 4*0.95*cz*nz/7.]]) probes.append(["19",[0.02, 7.*cy*nr/11., 5*0.95*cz*nz/7.]]) probes.append(["20",[0.02, 7.*cy*nr/11., 6*0.95*cz*nz/7.]]) probes.append(["21",[0.02, 7.*cy*nr/11., 7*0.95*cz*nz/7.]]) probes.append(["22",[0.02, 10.*cy*nr/11., 1*0.95*cz*nz/7.]]) probes.append(["23",[0.02, 10.*cy*nr/11., 2*0.95*cz*nz/7.]]) probes.append(["24",[0.02, 10.*cy*nr/11., 3*0.95*cz*nz/7.]]) probes.append(["25",[0.02, 10.*cy*nr/11., 4*0.95*cz*nz/7.]]) probes.append(["26",[0.02, 10.*cy*nr/11., 5*0.95*cz*nz/7.]]) probes.append(["27",[0.02, 10.*cy*nr/11., 6*0.95*cz*nz/7.]]) probes.append(["28",[0.02, 10.*cy*nr/11., 7*0.95*cz*nz/7.]]) # # update XML node_control = self.case.root().xmlGetChildNode('analysis_control') node_output = node_control.xmlGetChildNode('output') node_probes = node_output.xmlGetNodeList('probe','name') import Pages.OutputControl as OutputControl output = OutputControl.OutputControlModel(self.case) for probe in probes : try: output.replaceMonitoringPointCoordinates(x = probe[1][0], y = probe[1][1], z = probe[1][2], name = probe[0]) except: output.addMonitoringPoint(x = probe[1][0], y = probe[1][1], z = probe[1][2]) #------------------------------------------------------------------------------- # Main view class #------------------------------------------------------------------------------- class MatisseGeomView(TkPage.Page): """ Class to open Matisse Page. """ def _tkControlVariables(self): """ Tkinter variables declaration. """ # # Var Int self.nechrg = Tix.IntVar() self.nergrs = Tix.IntVar() self.neclrg = Tix.IntVar() self.nergch = Tix.IntVar() self.neciel = Tix.IntVar() self.nptran = Tix.IntVar() self.nplgrs = Tix.IntVar() self.nelgrs = Tix.IntVar() self.nchest = Tix.IntVar() self.netran = Tix.IntVar() self.jeuchr = Tix.DoubleVar() self.jeurcl = Tix.DoubleVar() self.jeuclr = Tix.DoubleVar() self.jeurch = Tix.DoubleVar() self.hbdtoi = Tix.DoubleVar() self.epchem = Tix.DoubleVar() self.epregi = Tix.DoubleVar() self.hconve = Tix.DoubleVar() self.rconve = Tix.DoubleVar() self.hchali = Tix.DoubleVar() self.hcheva = Tix.DoubleVar() self.hfttoi = Tix.DoubleVar() self.ptrres = Tix.DoubleVar() self.frdtra = Tix.DoubleVar() self.plgres = Tix.DoubleVar() self.epchel = Tix.DoubleVar() self.dmcont = Tix.DoubleVar() # # association between tix variable and tag self.variables=[('epregi', self.epregi,'double'), ('epchem', self.epchem,'double'), ('jeuchr', self.jeuchr,'double'), ('nechrg', self.nechrg,'int'), ('jeurcl', self.jeurcl,'double'), ('nergrs', self.nergrs,'int'), ('jeuclr', self.jeuclr,'double'), ('neclrg', self.neclrg,'int'), ('jeurch', self.jeurch,'double'), ('nergch', self.nergch,'int'), ('hconve', self.hconve,'double'), ('rconve', self.rconve,'double'), ('hchali', self.hchali,'double'), ('hcheva', self.hcheva,'double'), ('hbdtoi', self.hbdtoi,'double'), ('hfttoi', self.hfttoi,'double'), ('neciel', self.neciel,'int'), ('ptrres', self.ptrres,'double'), ('nptran', self.nptran,'int'), ('netran', self.netran,'int'), ('frdtra', self.frdtra,'double'), ('plgres', self.plgres,'double'), ('nplgrs', self.nplgrs,'int'), ('nelgrs', self.nelgrs,'int'), ('epchel', self.epchel,'double'), ('nchest', self.nchest,'int'), ('dmcont', self.dmcont,'double')] def _pageControl(self): """ Instantiate the matisse type modelling class. """ self.model = MatisseGeomModel(self.case) self.model_mat_type = MatisseType.MatisseTypeModel(self.case) def ActiveWidget(self, i , stat) : if stat == 'off': self.e[i].config(state=DISABLED, fg='grey') self.e[i].unbind("<>") self.l1[i].config(fg='grey') self.l2[i].config(fg='grey') try: self.l3[i].config(fg='grey') except: pass else : self.e[i].config(state=NORMAL, fg='black') self.e[i].event_add("<>", "", "", "") self.e[i].bind("<>",TkPage.Callback(self.getMatisseGeomVar, i, self.variables[i])) self.l1[i].config(fg='black') self.l2[i].config(fg='black') try: self.l3[i].config(fg='black') except: pass def getMatisseGeomVar(self, i, variable, event=None): """ Input Storage matisse type. """ self.stbar.busy() tag = variable[0] var = variable[1] if self.check2.hasType(self.e[i], var): self.model.setMatisseGeomVar(tag, var.get()) self.stbar.idle() def _createWidgets(self): """ Create the Page layout. """ t = PageText() lf1 = Tix.LabelFrame(self.myPage, bd=2, label=t.MATISSE_GEOM_TITLE, relief=FLAT) lf1.label.config(font=fT) lf1.pack(side=TOP, fill=X, padx=10, pady=10) self.e= [0]*len(self.variables) self.l1 = [0]*len(self.variables) self.l2 = [0]*len(self.variables) self.l3 = [0]*len(self.variables) for i in range(len(self.variables)): variable=self.variables[i] self.l1[i] = Tix.Label(lf1.frame, text=t.texts[variable[0]][0]) self.l1[i].grid(row=i, column=0, padx=2, pady=2, sticky=W) self.l2[i] = Tix.Label(lf1.frame, text=t.texts[variable[0]][1]) self.l2[i].grid(row=i, column=1, padx=2, pady=2, sticky=W) self.e[i] = Tix.Entry(lf1.frame, width=10, textvariable=variable[1]) self.e[i].grid(row=i, column=2, padx=3, pady=2) self.e[i].event_add("<>", "", "", "") self.e[i].bind("<>",TkPage.Callback(self.getMatisseGeomVar, i, variable)) try: self.l3[i] = Tix.Label(lf1.frame, text=t.texts[variable[0]][2]) self.l3[i].grid(row=i, column=3, pady=2, sticky=E) except : pass def _initializeWidgets(self): """ Extract resquested informations from XML document. This informations are used to initialize the widgets. For this page default values of all widgets are necessary included in the XML file. """ i = 0 for variable in self.variables: if variable[2] == 'double': val = self.model.getMatisseGeomDoubleVar(variable[0]) elif variable[2] == 'int': val = self.model.getMatisseGeomIntVar(variable[0]) else : print variable[2]+": unknown type" sys.exit(1) variable[1].set(val) t = self.model_mat_type.getMatisseType() if variable[0] in ('hfttoi', 'hbdtoi', 'neciel') : if (t == 'vault') or (t == 'djw'): self.ActiveWidget(i, 'off') elif variable[0] in ('jeuclr', 'neclrg', 'jeurch', 'nergch' ) : if t == 'emm' : self.ActiveWidget(i, 'off') else : pass i += 1 #------------------------------------------------------------------------------- # Text and messages for this page #------------------------------------------------------------------------------- class PageText: """ Storage of all texts and messages for this page. """ def __init__(self): if Tool.GuiParam.lang == 'fr': self.MATISSE_GEOM_TITLE="Géométrie de l'entrepôt" self.texts={} self.texts['jeuchr']=(6 ,"Jeu amont entre cheminée/registre","m") self.texts['nechrg']=(7 ,"Nombre d'éléments entre cheminée/registre amont") self.texts['jeurcl']=(8 ,"Jeu entre registre amont/conteneurs","m") self.texts['nergrs']=(9 ,"Nombre d'éléments entre registre amont/conteneurs") self.texts['jeuclr']=(10,"Jeu entre conteneurs/registre aval","m") self.texts['neclrg']=(11,"Nombre d'éléments entre conteneurs/registre aval") self.texts['jeurch']=(12,"Jeu aval entre registre/cheminée","m") self.texts['nergch']=(13,"Nombre d'éléments entre registre aval/cheminée") self.texts['hbdtoi']=(18,"Hauteur au bord du toit","m") self.texts['neciel']=(20,"Nombre de couches d'éléments du ciel d'entrepôt") self.texts['epregi']=(4 ,"Epaisseur des registres/cloisons amont et aval","m") self.texts['epchem']=(5 ,"Epaisseur des cheminées","m") self.texts['hconve']=(14,"Hauteur du convergent","m") self.texts['rconve']=(15,"Rapport du convergent","m") self.texts['hchali']=(16,"Hauteur de la cheminée d'alimentation","m") self.texts['hcheva']=(17,"Hauteur de la cheminée d'évacuation","m") self.texts['hfttoi']=(19,"Hauteur du faite du toit","m") self.texts['ptrres']=(21,"Pas transversal du réseau de conteneurs","m") self.texts['nptran']=(22,"Nombre de pas d'espace transversal") self.texts['netran']=(23,"Nombre d'éléments par pas transversal") self.texts['frdtra']=(24,"Facteur de réduction transversal du modèle/réel") self.texts['plgres']=(25,"Pas longitudinal du réseau de conteneurs","m") self.texts['nplgrs']=(26,"Nombre de pas d'espace longitudinal") self.texts['nelgrs']=(27,"Nombre d'éléments par pas longitudinal") self.texts['epchel']=(28,"Epaisseur d'une couche d'éléments (zone stockage)","m") self.texts['nchest']=(29,"Nombre de couches d'éléments dans la zone stockage") self.texts['dmcont']=(30,"Diamètre des conteneurs","m") else: self.MATISSE_GEOM_TITLE="Storage concept geometry" self.texts={} self.texts['jeuchr']=(6 ,"Upstream space between chimney/register","m") self.texts['nechrg']=(7 ,"Number of cells between chimney/upstream register") self.texts['jeurcl']=(8 ,"Space between upstream register/canisters","m") self.texts['nergrs']=(9 ,"Number of cells between upstream register/canisters") self.texts['jeuclr']=(10,"Space between canisters/downstream register","m") self.texts['neclrg']=(11,"Number of cells between canisters/downstream register") self.texts['jeurch']=(12,"Downstrean space between register/chimney","m") self.texts['nergch']=(13,"Number of cells between downstream register/chimney") self.texts['hbdtoi']=(18,"Height of roof edge","m") self.texts['neciel']=(20,"Number of cells layers above canisters") self.texts['epregi']=(4 ,"Upstream and downstream registers/doors thickness","m") self.texts['epchem']=(5 ,"chimneys' thickness","m") self.texts['hconve']=(14,"Convergent height","m") self.texts['rconve']=(15,"Convergent ratio","m") self.texts['hchali']=(16,"Inlet chimney height","m") self.texts['hcheva']=(17,"Outlet chimney height","m") self.texts['hfttoi']=(19,"Roof ridge height","m") self.texts['ptrres']=(21,"Transverse step of canisters network","m") self.texts['nptran']=(22,"Number of tranverse steps") self.texts['netran']=(23,"Number of cells by tranverse step") self.texts['frdtra']=(24,"Transverse reduction factor model/real","m") self.texts['plgres']=(25,"Longitudinal step of canisters network","m") self.texts['nplgrs']=(26,"Number of longitudinal steps") self.texts['nelgrs']=(27,"Number of cells by longitudinal step") self.texts['epchel']=(28,"Cells height (storage area)","m") self.texts['nchest']=(29,"Number of cells layers in the storage area") self.texts['dmcont']=(30,"Canister diameter","m") #------------------------------------------------------------------------------- # TurbulenceModel test case #------------------------------------------------------------------------------- class MatisseGeomTestCase(unittest.TestCase): """ """ def setUp(self): """ This method is executed before all "check" methods. """ from Base.XMLengine import Case self.case = Case() def tearDown(self): """ This method is executed after all "check" methods. """ del self.case def checkMatisseTypeInstantiation(self): """ Check whether the TurbulenceModel class could be instantiated """ model = None model = MatisseGeomModel(self.case) assert model != None, 'Could not instantiate MatisseGeomModel' def suite(): testSuite = unittest.makeSuite(TurbulenceTestCase, "check") return testSuite def runTest(): print "MatisseGeomTestCase" runner = unittest.TextTestRunner() runner.run(suite()) #------------------------------------------------------------------------------- # End #-------------------------------------------------------------------------------