File: XMLmodel.py

package info (click to toggle)
code-saturne 3.3.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 203,032 kB
  • ctags: 65,237
  • sloc: ansic: 202,560; f90: 140,879; python: 50,858; sh: 12,257; cpp: 3,671; makefile: 3,318; xml: 3,214; lex: 176; yacc: 101; sed: 16
file content (244 lines) | stat: -rw-r--r-- 8,150 bytes parent folder | download
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
# -*- 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 defines the XML data model in which the user defines the physical
options of the treated case. This module defines also a very usefull
function for the NavigatorTree display updating, taking into account
the current options selected by the user.

This module contains the following classes and function:
- XMLmodel
- XMLmodelTestCase
"""

#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------


import sys, unittest


#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------


from Base.XMLvariables import Variables
from Base import Toolbox


#-------------------------------------------------------------------------------
# class XMLmodel
#-------------------------------------------------------------------------------


class XMLmodel(Variables):
    """
    This class initialize the XML contents of the case.
    """
    def __init__(self, case):
        """
        """
        self.case = case
        self.root = self.case.root()
        self.node_models = self.case.xmlGetNode('thermophysical_models')

#FIXME: voir getTurbulenceModel de Turbulence.py (le noeud etant a declarer des le deaprt /...
    def getTurbModel(self):
        """
        This method return the turbilence model, but does not manage
        default values. Therefore...
        """
        nodeTurb = self.node_models.xmlGetNode('turbulence', 'model')
        return nodeTurb, nodeTurb['model']


    def getTurbVariable(self):
        """
        """
        nodeTurb, model = self.getTurbModel()
        nodeList = []

        if model in ('k-epsilon', 'k-epsilon-PL'):
            nodeList.append(nodeTurb.xmlGetNode('variable', name='k'))
            nodeList.append(nodeTurb.xmlGetNode('variable', name='epsilon'))

        elif model in ('Rij-epsilon', 'Rij-SSG', 'Rij-EBRSM'):
            for var in ('r11', 'r22', 'r33',
                        'r12', 'r13', 'r23',
                        'epsilon'):
                nodeList.append(nodeTurb.xmlGetNode('variable', name=var))
            if model in ('Rij-EBRSM'):
                nodeList.append(nodeTurb.xmlGetNode('variable', name='alpha'))

        elif model in ('v2f-BL-v2/k'):
            for var in ('k', 'epsilon', 'phi', 'alpha'):
                nodeList.append(nodeTurb.xmlGetNode('variable', name=var))

        elif model in ('k-omega-SST'):
            nodeList.append(nodeTurb.xmlGetNode('variable', name='k'))
            nodeList.append(nodeTurb.xmlGetNode('variable', name='omega'))

        elif model in ('Spalart-Allmaras'):
            nodeList.append(nodeTurb.xmlGetNode('variable', name='nu_tilda'))

        return nodeList


    def getTurbProperty(self):
        """
        """
        nodeTurb, model = self.getTurbModel()
        nodeList = []

        if model in ('mixing_length',
                     'k-epsilon',
                     'k-epsilon-PL',
                     'k-omega-SST',
                     'v2f-BL-v2/k',
                     'Rij-epsilon',
                     'Rij-SSG',
                     'Rij-EBRSM',
                     'Spalart-Allmaras'):
            nodeList.append(nodeTurb.xmlGetNode('property', name='turbulent_viscosity'))

        elif model in ('LES_Smagorinsky', 'LES_dynamique'):
            nodeList.append(nodeTurb.xmlGetNode('property', name='smagorinsky_constant^2'))

        return nodeList

#FIXME: A METTRE en commentaire  mais aussi getTurbVariable et getTurbProperty
    def getTurbNodeList(self):
        """
        """
        nodeList = []
        for node in self.getTurbVariable(): nodeList.append(node)
        for node in self.getTurbProperty(): nodeList.append(node)

        return nodeList



#-------------------------------------------------------------------------------
# XMLmodel test case
#-------------------------------------------------------------------------------

class ModelTest(unittest.TestCase):
    """
    Class beginning class test case of all pages
    """
    def setUp(self):
        """This method is executed before all "check" methods."""
        from Base.XMLengine import Case, XMLDocument
        from Base.XMLinitialize import XMLinit
        Toolbox.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"""
        n = self.doc.parseString(string)
        self.doc.xmlCleanAllBlank(n)
        return self.doc.root()


#-------------------------------------------------------------------------------
# XMLmodel test case
#-------------------------------------------------------------------------------


class XMLmodelTestCase(unittest.TestCase):
    """
    """
    def setUp(self):
        """
        This method is executed before all "check" methods.
        """
        from Base.XMLengine import Case
        from Base.XMLinitialize import XMLinit
        Toolbox.GuiParam.lang = 'en'
        self.case = Case(None)
        XMLinit(self.case)

    def tearDown(self):
        """
        This method is executed after all "check" methods.
        """
        del self.case

    def checkXMLmodelInstantiation(self):
        """
        Check whether the Case class could be instantiated
        """
        xmldoc = None
        xmldoc = XMLmodel(self.case)
        assert xmldoc != None, 'Could not instantiate XMLmodel'

##    def checkGetThermalModel(self):
##        """
##        Check whether the thermal model could be get.
##        """
##        doc = XMLmodel(self.case)
##        node_coal = self.case.xmlGetNode('solid_fuels', 'model')
##        node_coal['model'] = "toto"
##        nodeThermal, model = doc.getThermalModel()
##
##        assert nodeThermal == node_coal, \
##               'Could not use the getThermalModel method'
##        assert model == "toto", \
##               'Could not use the getThermalModel method'

##    def checkGetThermoPhysicalModel(self):
##        """
##        Check whether the specific thermophysical model could be get.
##        """
##        doc = XMLmodel(self.case)
##        node_coal = self.case.xmlGetNode('solid_fuels', 'model')
##        node_coal['model'] = "toto"
##        model = doc.getThermoPhysicalModel()
##
##        assert model == node_coal.el.tagName, \
##               'Could not use the getTermoPhysicalModel method'

def suite():
    testSuite = unittest.makeSuite(XMLmodelTestCase, "check")
    return testSuite

def runTest():
    print("XMLmodelTestCase to be completed...")
    runner = unittest.TextTestRunner()
    runner.run(suite())


#-------------------------------------------------------------------------------
# End of XMLmodel
#-------------------------------------------------------------------------------