# -*- 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 values of reference. This module contains the following classes and function: - ReferenceValuesModel - ReferenceValuesView - PageText - ReferenceValuesTestCase """ #------------------------------------------------------------------------------- # Library modules import #------------------------------------------------------------------------------- import Tix from Tkconstants import * import sys, unittest #------------------------------------------------------------------------------- # Application modules import #------------------------------------------------------------------------------- from Base.Common import * import Base.Toolbox as Tool import Base.Dialog as Dialog import Base.TkPage as TkPage from Base.XMLvariables import Variables #------------------------------------------------------------------------------- # Reference values model class #------------------------------------------------------------------------------- class ReferenceValuesModel: """ Manage the input/output markups in the xml doc about Pressure """ def __init__(self, case): """ Constructor. """ self.case = case self.node_models = self.case.xmlGetNode('thermophysical_models') self.node_veloce = self.node_models.xmlGetNode('velocity_pressure') self.node_coal = self.node_models.xmlGetNode('pulverized_coal', 'model') def defaultValues(self): """ Return reference values by default """ default = {} default['reference_pressure'] = 1.013e+5 default['reference_temperature'] = 1273.15 return default def setPressure(self, value): """ Set value of reference pressure into xml file. """ node = self.node_veloce.xmlGetNode('variable',name ='pressure') node.xmlSetData('reference_pressure', value) def getPressure(self): """ Return the value of reference pressure. """ node = self.node_veloce.xmlGetNode('variable',name ='pressure') value = node.xmlGetDouble('reference_pressure') if value == None: value = self.defaultValues()['reference_pressure'] self.setPressure(value) return value def setTemperature(self, value): """ Set reference temperature. """ self.node_coal.xmlSetData('temperature', value) def getTemperature(self): """ Get reference temperature. """ value = self.node_coal.xmlGetDouble('temperature') if not value : value = self.defaultValues()['reference_temperature'] self.setTemperature(value) return value #------------------------------------------------------------------------------- # Main View class #------------------------------------------------------------------------------- class ReferenceValuesView(TkPage.Page): """ Class to open Reference Pressure Page. """ def _dependsPages(self, name): """ Construction of the list of dependencies Pages. """ self.case[name]['depends'] = ['models/initia', 'bounda/thermo'] def _tkControlVariables(self): """ Tkinter variables declaration. """ self.pressure = Tix.DoubleVar() self.temperature = Tix.DoubleVar() def _pageControl(self): """ Instantiate the turbulence modelling class. """ self.mdl = ReferenceValuesModel(self.case) import Pages.CoalCombustion as CoalCombustion self.coalModel = CoalCombustion.CoalCombustionModel(self.case).getCoalCombustionModel() def getPressure(self, event=None): """ Input PRESS. """ self.stbar.busy() if self.check2.isPositive(self.p, self.pressure): self.stbar.clear() pressure = self.pressure.get() self.mdl.setPressure(pressure) self.stbar.idle() def getTemperature(self, event=None): """ Input TEMPERATURE. """ self.stbar.busy() temperature = self.temperature.get() self.mdl.setTemperature(temperature) self.stbar.idle() def _createWidgets(self): """ Create the Page layout. """ t = PageText() ## lf = Tix.LabelFrame(self.myPage, bd=2, ## label=t.VALUES_TITLE, relief=FLAT) ## lf.label.config(font=fT) ## lf.pack(side=TOP, fill=X, padx=10, pady=10) lf1 = Tix.LabelFrame(self.myPage, bd=2, label=t.PRESSURE_TITLE, relief=FLAT) lf1.label.config(font=fT) lf1.pack(side=TOP, fill=X, padx=10, pady=10) lp = Tix.Label(lf1.frame, text=t.REF_PRESS) lp.grid(row=0, column=0, padx=5, pady=10, sticky=W) self.p = Tix.Entry(lf1.frame, bd=2, width=10, textvariable=self.pressure) self.p.grid(row=0, column=1, padx=5, pady=10) self.p.event_add("<>", "", "", "") self.p.bind("<>",self.getPressure) labp = Tix.Label(lf1.frame, text="Pa") labp.grid(row=0, column=2, padx=5, pady=10, sticky=E) self.balloon.bind_widget(self.p,balloonmsg=t.KEYWORD+'P0') if self.coalModel != "off": lf2 = Tix.LabelFrame(self.myPage, bd=2, label=t.TEMPERATURE_TITLE, relief=FLAT) lf2.label.config(font=fT) lf2.pack(side=TOP, fill=X, padx=10, pady=10) ## lt = Tix.LabelFrame(lf2.frame, label=t.REF_TEMP, relief=FLAT) ## fcoal.pack(side=TOP, fill=X) ## fcoal.label.config(font=fT) lt = Tix.Label(lf2.frame, text=t.REF_TEMP) lt.grid(row=0, column=0, padx=5, pady=10, sticky=W) self.t = Tix.Entry(lf2.frame, bd=2, width=10, textvariable=self.temperature) self.t.grid(row=0, column=1, padx=5, pady=10) self.t.event_add("<>", "", "", "") self.t.bind("<>",self.getTemperature) labt = Tix.Label(lf2.frame, text="K") labt.grid(row=0, column=2, padx=5, pady=10, sticky=E) 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. """ self.pressure.set(self.mdl.getPressure()) if self.coalModel != "off": self.temperature.set(self.mdl.getTemperature()) #------------------------------------------------------------------------------- # Text and messages for this page #------------------------------------------------------------------------------- class PageText: """ Storage of all texts and messages for this page. """ def __init__(self): # 1) Texts # if Tool.GuiParam.lang == 'fr': self.PRESSURE_TITLE = "Pression de référence" self.TEMPERATURE_TITLE = "Température de référence" self.VALUES_TITLE = "Valeurs de référence" self.REF_PRESS = "Pression de référence pour la pression totale" self.REF_TEMP = "Température de référence" self.KEYWORD = "Mot clé Code_Saturne : " else: self.PRESSURE_TITLE = "Reference pressure" self.TEMPERATURE_TITLE = "Reference temperature" self.VALUES_TITLE = "Reference values" self.REF_PRESS = "Reference pressure for total pressure" self.REF_TEMP = "Reference temperature" self.KEYWORD = "Code_Saturne key word: " # 2) Messages # ## if Tool.GuiParam.lang == 'fr': ## self.MSG_GRAVITY = "Utile si la gravité est non nulle." ## self.MSG_ITURB = "Pour le modèle 'longueur de mélange' contacter "\ ## "l'équipe de développement." ## self.MSG_LENGTH_SCALE = "L'echelle de longueur est un réel > 0." ## self.MSG_LES = "Consultez les informations dans le "\ ## "sous-programme utilisateur : 'ussmag'" ## else: ## self.MSG_GRAVITY = "Usefull if gravity is not set to zero." ## self.MSG_ITURB = "For mixing length contact the "\ ## "development team." ## self.MSG_LENGTH_SCALE = "The mixing length is a > 0 real." ## self.MSG_LES = "Please report to the informations "\ ## "contain in the user subroutine: 'ussmag'" #------------------------------------------------------------------------------- # TurbulenceModel test case #------------------------------------------------------------------------------- class ReferencePressureTestCase(unittest.TestCase): """ """ def setUp(self): """This method is executed before all "check" methods.""" from Base.XMLengine import Case, XMLDocument from Base.XMLinitialize import XMLinit Tool.GuiParam.lang = 'en' self.case = Case(None) XMLinit(self.case) self.doc = XMLDocument() def tearDown(self): """This method is executed after all "check" methods.""" del self.case del self.doc def xmlNodeFromString(self, string): """Private method to return a xml node from string""" return self.doc.parseString(string).root() def checkTurbulenceInstantiation(self): """Check whether the TurbulenceModel class could be instantiated""" model = None model = TurbulenceModel(self.case) assert model != None, 'Could not instantiate TurbulenceModel' def suite(): testSuite = unittest.makeSuite(TurbulenceTestCase, "check") return testSuite def runTest(): print "TurbulenceTestCase" runner = unittest.TextTestRunner() runner.run(suite()) #------------------------------------------------------------------------------- # End #-------------------------------------------------------------------------------