# -*- 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 XML data model in which the user defines the physical
options of the treated case.
This module contains the following classe:
- XMLinit
- XMLinitTestCase
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import sys, unittest
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from XMLvariables import Variables
import Toolbox
from Pages.InitZone import InitZoneModel
from Pages.Turbulence import TurbulenceModel
from Pages.Initialization import InitializationModel
from Pages.TimeStep import TimeStepModel
from Pages.FluidCharacteristics import FluidCharacteristicsModel
from Pages.CoalCombustion import CoalCombustionModel
from Pages.ThermalScalar import ThermalScalarModel
from Pages.ElectricalModels import ElectricalModel
from Pages.GasCombustion import GasCombustionModel
from Pages.ThermalRadiation import ThermalRadiationModel
from Pages.Lagrangian import LagrangianModel
from Pages.DefineBoundaryRegions import DefBCModel
#-------------------------------------------------------------------------------
# class XMLinit
#-------------------------------------------------------------------------------
class XMLinit(Variables):
"""
This class initialize the XML contents of the case.
"""
def __init__(self, case):
"""
"""
self.case = case
self.root = self.case.root()
# Verify that all Heading exist only once in the XMLDocument.
# Create the missing heading.
#
self.initHeading()
# Initialization (order is important, see turbulenceModelsList method)
#
self.node_models = self.case.xmlInitNode('thermophysical_models')
node = self.node_models.xmlInitNode('velocity_pressure')
for tag in ('pressure', 'velocity_U', 'velocity_V', 'velocity_W'):
self.setNewVariable(node, tag)
self.setNewProperty(node, 'total_pressure')
TurbulenceModel(self.case).getTurbulenceModel()
#self.node_models.xmlInitChildNode('initialization').xmlInitNode('zone', name="1").xmlSetTextNode("0")
InitZoneModel(self.case).NewZone("1", "0")
InitializationModel(self.case).getInitialTurbulenceChoice()
InitializationModel(self.case).getReferenceVelocity()
TimeStepModel(self.case).getTimeStep()
TimeStepModel(self.case).getIterationsNumber()
TimeStepModel(self.case).getTimePassing()
for tag in ('density', 'molecular_viscosity', 'specific_heat', 'thermal_conductivity'):
FluidCharacteristicsModel(self.case).getInitialValue(tag)
self.boundcond = DefBCModel(self.case)
ThermalScalarModel(self.case).getThermalScalar()
CoalCombustionModel(self.case).getCoalCombustionModel()
GasCombustionModel(self.case).getGasCombustionModel()
ElectricalModel(self.case).getElectricalModel()
ThermalRadiationModel(self.case).mGetModel()
LagrangianModel(self.case).getLagrangianModel()
def _errorExit(self, msg):
"""
"""
print 'XML ERROR'
raise ValueError, msg
def initHeading(self):
"""
Create if necessary headings from the root element of the case.
"""
tagList = ('solution_domain',
'thermophysical_models',
'numerical_parameters',
'physical_properties',
'additional_scalars',
'lagrangian',
'boundary_conditions',
'analysis_control',
'calcul_management')
for tag in tagList:
nodeList = self.root.xmlInitChildNodeList(tag)
if len(nodeList) > 1:
msg = "There is an error in with the use of the initHeading method. "\
"There is more than one occurence of the tag: \n\n" + tag + \
"\n\nThe application will finish. Sorry."
self._errorExit(msg)
for tag in tagList:
nodeList = self.case.xmlInitNodeList(tag)
if len(nodeList) > 1:
msg = "There is an error in with the use of the initHeading method. "\
"There is more than one occurence of the tag: \n\n" + tag + \
"\n\nThe application will finish. Sorry."
self._errorExit(msg)
#-------------------------------------------------------------------------------
# XMLinit test case
#-------------------------------------------------------------------------------
class XMLinitTestCase(unittest.TestCase):
"""
"""
def setUp(self):
"""
This method is executed before all "check" methods.
"""
import XMLengine
Toolbox.GuiParam.lang = 'en'
self.doc = XMLengine.XMLDocument("")
self.case = XMLengine.Case(None)
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 checkXMLinitInstantiation(self):
"""
Check whether the Case class could be instantiated
"""
xmldoc = None
xmldoc = XMLinit(self.case)
assert xmldoc != None, 'Could not instantiate XMLinit'
def checkInitHeading(self):
"""
Check whether the headings markups could be initialized
"""
doc = \
'<Code_Saturne_GUI case="" study="" version="0.0">'\
'<solution_domain/>'\
'<thermophysical_models>'\
'<velocity_pressure>'\
'<variable label="Pressure" name="pressure"/>'\
'<variable label="VelocitU" name="velocity_U"/>'\
'<variable label="VelocitV" name="velocity_V"/>'\
'<variable label="VelocitW" name="velocity_W"/>'\
'<property label="total_pressure" name="total_pressure"/>'\
'</velocity_pressure>'\
'<turbulence model="k-epsilon">'\
'<variable label="TurbEner" name="turb_k"/>'\
'<variable label="Dissip" name="turb_eps"/>'\
'<property label="turb. vi" name="turb_viscosity"/>'\
'<initialization choice="reference_velocity">'\
'<reference_velocity>1.0</reference_velocity>'\
'</initialization>'\
'</turbulence>'\
'<initialization>'\
'<zone name="1">0</zone>'\
'</initialization>'\
'<thermal_scalar model="off"/>'\
'<gas_combustion model="off"/>'\
'<pulverized_coal model="off"/>'\
'<joule_effect model="off"/>'\
'<radiative_transfer model="off">'\
'<absorption_coeff type=""/>'\
'<restart status=""/>'\
'</radiative_transfer>'\
'</thermophysical_models>'\
'<numerical_parameters/>'\
'<physical_properties>'\
'<fluid_properties>'\
'<property choice="constant" label="Density" name="density">'\
'<listing_printing status="off"/>'\
'<postprocessing_recording status="off"/>'\
'<initial_value>1.17862</initial_value>'\
'</property>'\
'<property choice="constant" label="Lam. vis" name="molecular_viscosity">'\
'<listing_printing status="off"/>'\
'<postprocessing_recording status="off"/>'\
'<initial_value>1.83e-05</initial_value>'\
'</property>'\
'<property choice="constant" label="Sp. heat" name="specific_heat">'\
'<listing_printing status="off"/>'\
'<postprocessing_recording status="off"/>'\
'<initial_value>1017.24</initial_value>'\
'</property>'\
'<property choice="constant" label="Th. cond" name="thermal_conductivity">'\
'<listing_printing status="off"/>'\
'<postprocessing_recording status="off"/>'\
'<initial_value>0.02495</initial_value>'\
'</property>'\
'</fluid_properties>'\
'</physical_properties>'\
'<additional_scalars/>'\
'<lagrangian model="off"/>'\
'<boundary_conditions>'\
'<boundary_definition/>'\
'</boundary_conditions>'\
'<analysis_control>'\
'<output/>'\
'<time_parameters>'\
'<time_step_ref>0.1</time_step_ref>'\
'<property label="Nb Courant" name="courant_number">'\
'<property label="Nb Fourier" name="fourier_number">'\
'</time_parameters>'\
'</analysis_control>'\
'<calcul_management/>'\
'</Code_Saturne_GUI>'
XMLinit(self.case)
## print self.case.root()
assert self.case.root() == self.xmlNodeFromString(doc), \
'Could not use the constructor of the XMLinit class'
def suite():
testSuite = unittest.makeSuite(XMLinitTestCase, "check")
return testSuite
def runTest():
print "XMLinitTestCase to be completed..."
runner = unittest.TextTestRunner()
runner.run(suite())
#-------------------------------------------------------------------------------
# End of XMLinit
#-------------------------------------------------------------------------------
syntax highlighted by Code2HTML, v. 0.9.1