File: SolidModel.py

package info (click to toggle)
code-saturne 6.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 63,340 kB
  • sloc: ansic: 354,724; f90: 119,812; python: 87,716; makefile: 4,653; cpp: 4,272; xml: 2,839; sh: 1,228; lex: 170; yacc: 100
file content (333 lines) | stat: -rw-r--r-- 12,071 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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# -*- coding: utf-8 -*-

#-------------------------------------------------------------------------------

# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2019 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.

#-------------------------------------------------------------------------------

import sys, unittest
from code_saturne.model.XMLvariables import Model
from code_saturne.model.XMLengine import *
from code_saturne.model.XMLmodel import *
from code_saturne.model.MainFieldsModel import *
from code_saturne.model.TurbulenceNeptuneModel import TurbulenceModel


class SolidModel(TurbulenceModel):

    """
    This class manages the turbulence objects in the XML file
    """

    def __init__(self, case):
        """
        Constuctor.
        """
        #
        # XML file parameters
        MainFieldsModel.__init__(self, case)
        TurbulenceModel.__init__(self, case)
        self.case = case
        self.XMLThermo = self.case.xmlGetNode('thermophysical_models')
        self.__XMLNodefields = self.XMLNodethermo.xmlInitNode('fields')


    def defaultValues(self):
        default = TurbulenceModel.defaultValues(self)

        default['compaction']    = 0.64
        default['friction']      = "none"
        default['granular']      = "none"
        default['kinetic']       = "none"
        default['polydispersed'] = "off"
        return default


    @Variables.undoLocal
    def setFrictionModel(self, fieldId, model) :
        """
        Public method.
        Put model for friction.
        """
        self.isInList(str(fieldId),self.getFieldIdList())
        self.isInList(model, ('none', 'pressure', 'fluxes'))

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)
        childNode = node.xmlInitChildNode('friction')
        childNode.xmlSetAttribute(model = model)


    @Variables.noUndo
    def getFrictionModel(self, fieldId) :
        """
        Public method.
        Return model for friction.
        """
        self.isInList(str(fieldId),self.getFieldIdList())

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)
        noden = node.xmlGetNode('friction')
        if noden == None :
            model = self.defaultValues()['friction']
            self.setFrictionModel(fieldId, model)
        model = node.xmlGetNode('friction')['model']

        return model


    @Variables.undoLocal
    def setGranularModel(self, fieldId, model) :
        """
        Public method.
        Put model for granular.
        """
        self.isInList(str(fieldId),self.getFieldIdList())
        self.isInList(model, ('none', 'pressure', 'fluxes'))

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)
        childNode = node.xmlInitChildNode('granular')
        childNode.xmlSetAttribute(model = model)


    @Variables.noUndo
    def getGranularModel(self, fieldId) :
        """
        Public method.
        Return model for granular.
        """
        self.isInList(str(fieldId),self.getFieldIdList())

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)
        noden = node.xmlGetNode('granular')
        if noden == None :
            model = self.defaultValues()['granular']
            self.setGranularModel(fieldId, model)
        model = node.xmlGetNode('granular')['model']

        return model


    @Variables.undoLocal
    def setKineticModel(self, fieldId, model) :
        """
        Public method.
        Put model for kinetic.
        """
        self.isInList(str(fieldId),self.getFieldIdList())
        self.isInList(model, ('none', 'uncorrelate_collision', 'correlate_collision'))

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)
        childNode = node.xmlInitChildNode('kinetic')
        childNode.xmlSetAttribute(model = model)


    @Variables.noUndo
    def getKineticModel(self, fieldId) :
        """
        Public method.
        Return model for kinetic.
        """
        self.isInList(str(fieldId),self.getFieldIdList())

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)
        noden = node.xmlGetNode('kinetic')
        if noden == None :
            model = self.defaultValues()['kinetic']
            self.setKineticModel(fieldId, model)
        model = node.xmlGetNode('kinetic')['model']

        return model


    @Variables.undoLocal
    def setCompaction(self, value) :
        """
        Public method.
        Return values for compaction.
        """
        self.isPositiveFloat(value)

        self.XMLThermo.xmlSetData('solid_compaction', value)


    @Variables.noUndo
    def getCompaction(self) :
        """
        Public method.
        put values for compaction.
        """
        value = self.XMLThermo.xmlGetDouble('solid_compaction')
        if value == None :
           value = self.defaultValues()['compaction']
           self.setCompaction(value)
        return value


    @Variables.undoLocal
    def setCouplingStatus(self, fieldId, status):
        """
        put polydispersed coupling status
        """
        self.isInList(str(fieldId),self.getFieldIdList())
        self.isOnOff(status)

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)
        node.xmlSetData('polydispersed', status)


    @Variables.noUndo
    def getCouplingStatus(self, fieldId):
        """
        get polydispersed coupling status
        """
        self.isInList(str(fieldId),self.getFieldIdList())

        node = self.__XMLNodefields.xmlGetNode('field', field_id = fieldId)

        ChildNode = node.xmlGetChildNode('polydispersed')
        if ChildNode == None:
           status = self.defaultValues()['polydispersed']
           self.setCouplingStatus(fieldId, status)
        status = node.xmlGetString('polydispersed')
        return status


    def getXMLNodefields(self):
        return self.__XMLNodefields

#-------------------------------------------------------------------------------
# DefineUsersScalars test case
#-------------------------------------------------------------------------------
class SolidTestCase(ModelTest):
    """
    """
    def checkSolidInstantiation(self):
        """Check whether the SolidModel class could be instantiated"""
        model = None
        model = SolidModel(self.case)
        assert model != None, 'Could not instantiate SolidModel'


    def checkGetandSetFrictionModel(self):
        """Check whether the SolidModel class could set and get FrictionModel"""
        MainFieldsModel(self.case).addField()
        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
        mdl = SolidModel(self.case)
        mdl.setFrictionModel('2','pressure')
        doc = '''<field field_id="2" label="field2">
                         <type choice="dispersed"/>
                         <carrier_field field_id="on"/>
                         <phase choice="solid"/>
                         <hresolution status="on"/>
                         <compressible status="off"/>
                         <friction model="pressure"/>
                 </field>'''
        assert mdl.getXMLNodefields().xmlGetNode('field', field_id = '2') == self.xmlNodeFromString(doc),\
            'Could not set FrictionModel'
        assert mdl.getFrictionModel('2') == 'pressure',\
            'Could not get FrictionModel'


    def checkGetandSetGranularModel(self):
        """Check whether the SolidModel class could set and get GranularModel"""
        MainFieldsModel(self.case).addField()
        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
        mdl = SolidModel(self.case)
        mdl.setGranularModel('2','pressure')
        doc = '''<field field_id="2" label="field2">
                         <type choice="dispersed"/>
                         <carrier_field field_id="on"/>
                         <phase choice="solid"/>
                         <hresolution status="on"/>
                         <compressible status="off"/>
                         <granular model="pressure"/>
                 </field>'''
        assert mdl.getXMLNodefields().xmlGetNode('field', field_id = '2') == self.xmlNodeFromString(doc),\
            'Could not set GranularModel'
        assert mdl.getGranularModel('2') == 'pressure',\
            'Could not get GranularModel'


    def checkGetandSetKineticModel(self):
        """Check whether the SolidModel class could set and get KineticModel"""
        MainFieldsModel(self.case).addField()
        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
        mdl = SolidModel(self.case)
        mdl.setKineticModel('2','correlate_collision')
        doc = '''<field field_id="2" label="field2">
                         <type choice="dispersed"/>
                         <carrier_field field_id="on"/>
                         <phase choice="solid"/>
                         <hresolution status="on"/>
                         <compressible status="off"/>
                         <kinetic model="correlate_collision"/>
                 </field>'''
        assert mdl.getXMLNodefields().xmlGetNode('field', field_id = '2') == self.xmlNodeFromString(doc),\
            'Could not set KineticModel'
        assert mdl.getKineticModel('2') == 'correlate_collision',\
            'Could not get KineticModel'


    def checkGetandSetCompaction(self):
        """Check whether the SolidModel class could set and get Compaction"""
        MainFieldsModel(self.case).addField()
        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
        mdl = SolidModel(self.case)
        mdl.setCompaction(0.6)
        doc = '''<solid_compaction>
                         0.6
                 </solid_compaction>'''
        assert mdl.XMLThermo.xmlGetNode('solid_compaction') == self.xmlNodeFromString(doc),\
            'Could not set Compaction'
        assert mdl.getCompaction() == 0.6,\
            'Could not get Compaction'


    def checkGetandSetCouplingStatus(self):
        """Check whether the SolidModel class could set and get CouplingStatus"""
        MainFieldsModel(self.case).addField()
        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
        mdl = SolidModel(self.case)
        mdl.setCouplingStatus('2','on')
        doc = '''<field field_id="2" label="field2">
                         <type choice="dispersed"/>
                         <carrier_field field_id="on"/>
                         <phase choice="solid"/>
                         <hresolution status="on"/>
                         <compressible status="off"/>
                         <polydispersed>
                                 on
                         </polydispersed>
                 </field>'''
        assert mdl.getXMLNodefields().xmlGetNode('field', field_id = '2') == self.xmlNodeFromString(doc),\
            'Could not set CouplingStatus'
        assert mdl.getCouplingStatus('2') == 'on',\
            'Could not get CouplingStatus'


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


def runTest():
    print("SolidTestCase")
    runner = unittest.TextTestRunner()
    runner.run(suite())