1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------------
4
5# This file is part of Code_Saturne, a general-purpose CFD tool.
6#
7# Copyright (C) 1998-2021 EDF S.A.
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; either version 2 of the License, or (at your option) any later
12# version.
13#
14# This program is distributed in the hope that it will be useful, but WITHOUT
15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17# details.
18#
19# You should have received a copy of the GNU General Public License along with
20# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
21# Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23# -------------------------------------------------------------------------------
24import logging
25import unittest
26
27from code_saturne.model.Common import GuiParam
28from code_saturne.model.MainFieldsModel import MainFieldsModel
29from code_saturne.model.NotebookModel import NotebookModel
30from code_saturne.model.OutputFieldsModel import OutputFieldsModel
31from code_saturne.model.SpeciesModel import SpeciesModel
32from code_saturne.model.XMLengine import *
33from code_saturne.model.XMLmodel import *
34from code_saturne.model.XMLvariables import Model
35
36# -------------------------------------------------------------------------------
37# log config
38# -------------------------------------------------------------------------------
39
40logging.basicConfig()
41log = logging.getLogger("ThermodynamicsModel")
42log.setLevel(GuiParam.DEBUG)
43
44# -------------------------------------------------------------------------------
45# EOS
46# -------------------------------------------------------------------------------
47
48EOS = 1
49try:
50   import eosAva
51except:
52   EOS = 0
53else :
54   import eosAva
55
56#-------------------------------------------------------------------------------
57# Constructor
58#-------------------------------------------------------------------------------
59
60
61class ThermodynamicsModel(MainFieldsModel, Variables, Model):
62    """
63    This class manages the Field objects in the XML file
64    """
65
66    def __init__(self, case):
67        """
68        Constuctor.
69        """
70        #
71        # XML file parameters
72        MainFieldsModel.__init__(self, case)
73        self.case            = case
74        self.XMLNodethermo   = self.case.xmlGetNode('thermophysical_models')
75        self.__XMLNodefields = self.XMLNodethermo.xmlInitNode('fields')
76        self.__XMLThermo     = self.XMLNodethermo.xmlInitNode('thermodynamics')
77        self.XMLNodeproperty = self.XMLNodethermo.xmlInitNode('properties')
78
79        self.m_spe = SpeciesModel(self.case)
80        self.notebook = NotebookModel(self.case)
81        self.list_scalars = []
82
83        self.m_out = OutputFieldsModel(self.case)
84        label = self.m_out.getVariableLabel("none", "pressure")
85        self.list_scalars.append(('pressure', label))
86
87
88    def defaultValues(self, field_id):
89        default = {}
90        default['density']              = 1.8
91        default['molecular_viscosity']  = 0.0000456
92        default['specific_heat']        = 4000
93        default['thermal_conductivity'] = 1.e-5
94        default['emissivity'] = 0.
95        default['elasticity'] = 0.9
96        default['radiative'] = "off"
97        default['material'] = "user_material"
98        default['method'] = "user_properties"
99        default['user_property'] = "constant"
100        default['thetisClipping'] = "on"
101        default['cathareClipping'] = "on"
102        default['propertyChoice'] = "constant"
103
104        if self.checkEOSRequirements(field_id):
105            default["material"] = "Water"
106            default["method"] = "Cathare2"
107
108        return default
109
110    def getDefaultFormula(self, field_id, property_name):
111        """
112        Return default formula for a given property.
113        """
114
115        label = self.m_out.getVariableLabel(field_id, property_name)
116        formula = ""
117        if "SaturationEnthalpy" in property_name:
118            formula = label + " = 0.;"
119
120        elif "d_Hsat_d_P_" in property_name:
121            formula = label + " = 0.;"
122
123        elif property_name == "SaturationTemperature":
124            formula = label + " = 273.15;"
125
126        elif property_name == "d_Tsat_d_P":
127            formula = label + " = 0.;"
128
129        elif property_name == "LatentHeat":
130            formula = label + " = 0.;"
131
132        return formula
133
134
135
136    def getExampleFormula(self, field_id, property_name):
137        """
138        Return an example formula for a given property.
139        """
140
141        label = self.m_out.getVariableLabel(field_id, property_name)
142        formula = ""
143        if "SaturationEnthalpy" in property_name:
144            formula = label + " = 0.;"
145
146        elif "d_Hsat_d_P_" in property_name:
147            formula = label + " = 0.;"
148
149        elif property_name == "SaturationTemperature":
150            formula = label + " = 273.15;"
151
152        elif property_name == "d_Tsat_d_P":
153            formula = label + " = 0.;"
154
155        elif property_name == "LatentHeat":
156            formula = label + " = 0.;"
157
158        return formula
159
160
161    def propertiesFormulaList(self):
162        lst = ('density', 'molecular_viscosity',
163               'specific_heat', 'thermal_conductivity',
164               'surface_tension',
165               'temperature', 'd_rho_d_P', 'd_rho_d_h',
166               'SaturationEnthalpyLiquid', 'SaturationEnthalpyGas',
167               'd_Hsat_d_P_Liquid', 'd_Hsat_d_P_Gas',
168               'SaturationTemperature', 'd_Tsat_d_P', 'LatentHeat')
169        return lst
170
171    def checkEOSRequirements(self, field_id):
172        """
173        Check if EOS material laws can be activated
174        :param field_id:
175        """
176        if self.getEnergyModel(field_id) == "off" or self.getEnergyResolution(field_id) == "off":
177            return False
178        return {1: True, 0: False}[EOS]
179
180    @Variables.undoLocal
181    def setMaterials(self, fieldId, material):
182        self.check_field_id(fieldId)
183        node = self.get_field_node(fieldId)
184        field_name = self.getFieldLabelsList()[int(fieldId) - 1]
185        childNode = node.xmlInitChildNode('material')
186        if not (self.checkEOSRequirements(fieldId)):
187            material = "user_material"
188            log.debug("Warning : EOS not available. Changing material to user...")
189        childNode.xmlSetAttribute(choice=material)
190
191        # if predefine flow and heat transfer activated : same material for 2 phases
192        if self.checkIdenticalMaterialsRequirements():
193            if str(fieldId) == '1' or str(fieldId) == '2':
194                if str(fieldId) == '1':
195                    field2 = '2'
196                else:
197                    field2 = '1'
198                node2 = self.get_field_node(field2)
199                childNode2 = node2.xmlInitChildNode('material')
200                m2 = childNode2.xmlGetNode('material')
201                oldMaterial2 = None
202                if m2 != None:
203                    oldMaterial2 = m2['choice']
204                childNode2.xmlSetAttribute(choice=material)
205                # update method
206                self.updateMethod(field2, oldMaterial2)
207
208        if material != "user_material":
209            for prop in self.propertiesFormulaList():
210                node = self.get_property_node(fieldId, prop)
211                if node:
212                    node.xmlRemoveChild('formula')
213            # add node enthalpy if needed
214            XMLNodeVariable = self.XMLNodethermo.xmlGetNode('variables')
215            node = XMLNodeVariable.xmlGetNode('variable', field_id=fieldId, name="enthalpy")
216            if not node:
217                Variables(self.case).setNewVariableProperty("variable", "", XMLNodeVariable, fieldId, "enthalpy", "enthalpy_"+field_name)
218
219    def checkIdenticalMaterialsRequirements(self):
220        force_identical_materials = (self.getPredefinedFlow() in ["free_surface", "boiling_flow", "droplet_flow",
221                                                                  "multiregime"]) \
222                                    and (self.getHeatMassTransferStatus() == "on")
223        return force_identical_materials
224
225    @Variables.noUndo
226    def getMaterials(self, fieldId):
227        """
228        get the nature of materials
229        """
230        self.check_field_id(fieldId)
231
232        node = self.get_field_node(fieldId)
233        nodem = node.xmlGetNode('material')
234        if nodem == None :
235            material = self.defaultValues(fieldId)['material']
236            self.setMaterials(fieldId, material)
237        material = node.xmlGetNode('material')['choice']
238        return material
239
240    @Variables.undoLocal
241    def setMethod(self, fieldId, method):
242        """
243        set the nature of materials
244        """
245        self.check_field_id(fieldId)
246        if not (self.checkEOSRequirements(fieldId)):
247            method = "user_properties"
248            log.debug("Warning : EOS not available. Changing method to user...")
249        node = self.get_field_node(fieldId)
250        childNode = node.xmlInitChildNode('method')
251        childNode.xmlSetAttribute(choice=method)
252        self.updateReference(fieldId)
253
254    @Variables.noUndo
255    def getMethod(self, fieldId):
256        """
257        get the nature of materials
258        """
259        self.check_field_id(fieldId)
260
261        node = self.get_field_node(fieldId)
262        nodem = node.xmlGetNode('method')
263        if nodem == None :
264            method = self.defaultValues(fieldId)['method']
265            self.setMethod(fieldId, method)
266        method = node.xmlGetNode('method')['choice']
267        return method
268
269    @Variables.undoGlobal
270    def updateMethod(self, fieldId, oldMaterial):
271        """
272        update reference value for EOS
273        """
274        self.check_field_id(fieldId)
275        material = self.getMaterials(fieldId)
276        if oldMaterial != material :
277            _default_method = self.defaultValues(fieldId)['method']
278            if material == self.defaultValues(fieldId)['material'] :
279               self.setMethod(fieldId, _default_method)
280            elif EOS == 1 and material != "user_material":
281                self.ava = eosAva.EosAvailable()
282                self.ava.setMethods(material)
283                fls = self.ava.whichMethods()
284                if _default_method in fls:
285                    self.setMethod(fieldId, _default_method)
286                elif "Cathare" in fls:
287                    self.setMethod(fieldId, "Cathare")
288                else:
289                    for fli in fls:
290                        if fli != "Ovap" and fli != "Flica4" and fli != "StiffenedGas":
291                            self.setMethod(fieldId, fli)
292                            break
293            else:
294                self.setMethod(fieldId, "user_properties")
295
296            if material == 'user_material' :
297                choice = 'constant'
298            else :
299                choice = 'user_law'
300            for tag in ['density', 'molecular_viscosity', 'specific_heat', 'thermal_conductivity'] :
301                self.setPropertyMode(fieldId, tag, choice)
302
303            if self.getFieldNature(fieldId) == "gas":
304                tag = 'surface_tension'
305                fieldId = "none"
306                self.setPropertyMode(fieldId, tag, choice)
307
308    @Variables.undoGlobal
309    def updateReference(self, fieldId):
310        """
311        return reference value for EOS
312        """
313        self.check_field_id(fieldId)
314
315        node = self.get_field_node(fieldId)
316        reference = ""
317        material = self.getMaterials(fieldId)
318        method = self.getMethod(fieldId)
319        if material == "user_material" :
320            reference = material
321        else :
322            phase = self.getFieldNature(fieldId)
323            if EOS == 1 :
324                self.ava = eosAva.EosAvailable()
325                self.ava.setMethods(material)
326                self.ava.setReferences(material, self.getMethod(fieldId))
327                ref = self.ava.whichReferences()
328
329                # Reference for methods
330                liqidx = 0
331                gasidx = 1
332                # if Refprop, the list has an additional element at position 0
333                if self.getMethod(fieldId) == "Refprop":
334                    liqidx += 1
335                    gasidx += 1
336
337                if len(ref) == 1 :
338                   # cas des gaz par exemple
339                   reference = ref[0]
340                else :
341                   if phase == "liquid" :
342                      reference = ref[liqidx]
343                   elif phase == "gas" :
344                      reference = ref[gasidx]
345            else :
346                reference = material + phase
347        # update XML
348        childNode = node.xmlInitChildNode('reference')
349        childNode.xmlSetAttribute(choice = reference)
350
351        return reference
352
353    @Variables.noUndo
354    def getInitialValue(self, fieldId, tag):
355        """
356        Return initial value of the markup tag : 'density', or
357        'molecular_viscosity', 'specific_heat', 'thermal_conductivity',
358        'surface_tension', 'emissivity' or 'elasticity'
359        """
360        fieldIdList = self.getFieldIdList()
361        fieldIdList.append('none')
362        self.isInList(str(fieldId),fieldIdList)
363
364        lst = ('density', 'molecular_viscosity',
365                'specific_heat', 'thermal_conductivity',
366                'surface_tension', 'emissivity','elasticity')
367        self.isInList(tag, lst)
368        node = self.get_property_node(fieldId, tag)
369        pp = node.xmlGetDouble('initial_value')
370        if pp == None:
371            pp = self.defaultValues(fieldId)[tag]
372            self.setInitialValue(fieldId, tag, pp)
373        return pp
374
375    @Variables.undoLocal
376    def setInitialValue(self, fieldId, tag, val):
377        """
378        Put initial value for the markup tag : 'density', or
379        'molecular_viscosity', 'specific_heat', 'thermal_conductivity',
380        'surface_tension', 'emissivity' or 'elasticity'
381        """
382        fieldIdList = self.getFieldIdList()
383        fieldIdList.append('none')
384        self.isInList(str(fieldId),fieldIdList)
385        lst = ('density', 'molecular_viscosity',
386                'specific_heat', 'thermal_conductivity',
387                'surface_tension', 'emissivity','elasticity')
388        self.isInList(tag, lst)
389        self.isFloat(val)
390        if tag != 'emissivity' and tag != 'elasticity':
391            self.isGreater(val, 0.)
392        node = self.get_property_node(fieldId, tag)
393        node.xmlSetData('initial_value', val)
394
395    @Variables.noUndo
396    def getInitialValueDensity(self, fieldId):
397        """Return initial value of density"""
398        return self.getInitialValue(fieldId, 'density')
399
400    @Variables.undoLocal
401    def setInitialValueDensity(self, fieldId, val):
402        """Put initial value for density"""
403        self.setInitialValue(fieldId, 'density', val)
404
405    @Variables.noUndo
406    def getInitialValueViscosity(self, fieldId):
407        """Return initial value of viscosity"""
408        return self.getInitialValue(fieldId, 'molecular_viscosity')
409
410    @Variables.undoLocal
411    def setInitialValueViscosity(self, fieldId, val):
412        """Put initial value for viscosity"""
413        self.setInitialValue(fieldId, 'molecular_viscosity', val)
414
415    @Variables.noUndo
416    def getInitialValueHeat(self, fieldId):
417        """Return initial value of specific heat"""
418        return self.getInitialValue(fieldId, 'specific_heat')
419
420    @Variables.undoLocal
421    def setInitialValueHeat(self, fieldId, val):
422        """Put initial value for specific heat"""
423        self.setInitialValue(fieldId, 'specific_heat', val)
424
425    @Variables.noUndo
426    def getInitialValueCond(self, fieldId):
427        """Return initial value of conductivity"""
428        return self.getInitialValue(fieldId, 'thermal_conductivity')
429
430    @Variables.undoLocal
431    def setInitialValueCond(self, fieldId, val):
432        """Put initial value for conductivity"""
433        self.setInitialValue(fieldId, 'thermal_conductivity', val)
434
435    @Variables.noUndo
436    def getInitialValueEmissivity(self, fieldId):
437        """Return initial value of emissivity"""
438        return self.getInitialValue(fieldId, 'emissivity')
439
440    @Variables.undoLocal
441    def setInitialValueEmissivity(self, fieldId, val):
442        """Put initial value for emissivity"""
443        self.setInitialValue(fieldId, 'emissivity', val)
444
445    @Variables.noUndo
446    def getInitialValueElastCoef(self, fieldId):
447        """Return initial value of elasticity coefficient"""
448        return self.getInitialValue(fieldId, 'elasticity')
449
450    @Variables.undoLocal
451    def setInitialValueElastCoef(self, fieldId, val):
452        """Put initial value for elasticity coefficient"""
453        self.setInitialValue(fieldId, 'elasticity', val)
454
455    @Variables.noUndo
456    def getFormula(self, fieldId, tag, zone="1"):
457        """
458        Return a formula for properties
459        """
460        fieldIdList = self.getFieldIdList()
461        fieldIdList.append('none')
462        self.isInList(str(fieldId), fieldIdList)
463        self.isInList(tag, self.propertiesFormulaList())
464        node = self.get_property_node(fieldId, tag)
465
466        if str(zone) != "1":
467            if node.xmlGetChildNode("zone", zone_id=zone):
468                node = node.xmlGetChildNode("zone", zone_id=zone)
469            else:
470                node = node.xmlInitChildNode("zone", zone_id=zone)
471
472        if node:
473            return node.xmlGetChildString('formula')
474        else:
475            return None
476
477    @Variables.undoLocal
478    def setFormula(self, fieldId, tag, strg, zone="1"):
479        """
480        Gives a formula for properties
481        """
482        fieldIdList = self.getFieldIdList()
483        fieldIdList.append('none')
484        self.isInList(str(fieldId), fieldIdList)
485        self.isInList(tag, self.propertiesFormulaList())
486        node = self.get_property_node(fieldId, tag)
487
488        if str(zone) != "1":
489            if node.xmlGetChildNode("zone", zone_id=zone):
490                node = node.xmlGetChildNode("zone", zone_id=zone)
491            else:
492                node = node.xmlInitChildNode("zone", zone_id=zone)
493
494        node.xmlSetData('formula', strg)
495
496    @Variables.undoLocal
497    def setRadiativeTransferStatus(self, fieldId, status):
498        """
499        set status for radiative resolution transfer
500        """
501        self.check_field_id(fieldId)
502        self.isOnOff(status)
503
504        node = self.get_field_node(fieldId)
505        childNode = node.xmlInitChildNode('particles_radiative_transfer')
506        childNode.xmlSetAttribute(status = status)
507
508    @Variables.noUndo
509    def getRadiativeTransferStatus(self, fieldId):
510        """
511        return status for radiative resolution transfer
512        """
513        self.check_field_id(fieldId)
514        node = self.get_field_node(fieldId)
515        nodeh = node.xmlGetNode('particles_radiative_transfer')
516        if nodeh == None:
517            rad = self.defaultValues(fieldId)['radiative']
518            self.setRadiativeTransferStatus(fieldId, rad)
519        rad = node.xmlGetNode('particles_radiative_transfer')['status']
520        return rad
521
522    @Variables.noUndo
523    def getPropertyMode(self, fieldId, tag):
524        """Return choice of node I{tag}. Choice is constant or variable"""
525        fieldIdList = self.getFieldIdList()
526        fieldIdList.append('none')
527        self.isInList(str(fieldId), fieldIdList)
528        self.isInList(tag, ('density', 'molecular_viscosity',
529                            'specific_heat', 'thermal_conductivity', 'surface_tension'))
530        node = self.get_property_node(fieldId, tag)
531
532        c = None
533        if node:
534            if node['choice'] != "" and node['choice'] != None:
535                c = node['choice']
536                self.isInList(c, ('constant', 'user_law', 'table_law'))
537
538        if c == None:
539            c = self.defaultValues(fieldId)['propertyChoice']
540            if node:
541                self.setPropertyMode(fieldId, tag, c)
542
543        return c
544
545    @Variables.undoLocal
546    def setPropertyMode(self, fieldId, tag, choice):
547        """Put choice in xml file's node I{tag}"""
548        fieldIdList = self.getFieldIdList()
549        fieldIdList.append('none')
550        self.isInList(str(fieldId), fieldIdList)
551        self.isInList(tag, ('density', 'molecular_viscosity',
552                            'specific_heat', 'thermal_conductivity', 'surface_tension'))
553        self.isInList(choice, ('constant', 'user_law', 'table_law'))
554
555        node = self.get_property_node(fieldId, tag)
556        node['choice'] = choice
557
558        if choice == 'constant':
559            node.xmlRemoveChild('formula')
560
561    def get_property_node(self, fieldId, prop):
562        node = self.XMLNodeproperty.xmlGetNode('property', field_id=fieldId, name=prop)
563        return node
564
565    def check_field_id(self, fieldId):
566        return self.isInList(str(fieldId), self.getFieldIdList())
567
568    def get_field_node(self, fieldId):
569        node = self.__XMLNodefields.xmlGetNode('field', field_id=fieldId)
570        return node
571
572    def getXMLNodefieldsNode(self):
573        return self.__XMLNodefields
574
575    def getXMLThermo(self):
576        return self.__XMLThermo
577
578    # MEG Generation related functions
579    def getFormulaComponents(self, fieldId, tag, zone="1"):
580        """
581        Get the formula components for a given tag
582        """
583
584        if tag == 'density':
585            return self.getFormulaRhoComponents(fieldId, zone)
586
587        elif tag == 'molecular_viscosity':
588            return self.getFormulaMuComponents(fieldId, zone)
589
590        elif tag == 'specific_heat':
591            return self.getFormulaCpComponents(fieldId, zone)
592
593        elif tag == 'thermal_conductivity':
594            return self.getFormulaAlComponents(fieldId, zone)
595
596        elif tag == 'd_rho_d_P':
597            return self.getFormuladrodpComponents(fieldId, zone)
598
599        elif tag == 'd_rho_d_h':
600            return self.getFormuladrodhComponents(fieldId, zone)
601
602        elif tag == 'temperature':
603            return self.getFormulaTemperatureComponents(fieldId, zone)
604
605        elif tag == 'd_Tsat_d_P':
606            return self.getFormuladTsatdpComponents(zone)
607
608        elif tag == 'LatentHeat':
609            return self.getFormulaHlatComponents(zone)
610
611        elif tag == 'SaturationTemperature':
612            return self.getFormulaTsatComponents(zone)
613
614        elif 'd_Hsat_d_P_' in tag:
615            return self.getFormuladHsatdpComponents(tag, zone)
616
617        elif 'SaturationEnthalpy' in tag:
618            return self.getFormulaHsatComponents(tag, zone)
619
620        else:
621            msg = 'Formula is not available for field %s_%s in MEG' % (tag,str(fieldId))
622            raise Exception(msg)
623
624    def getFormulaRhoComponents(self, fieldId, zone="1"):
625        """
626        User formula for density
627        """
628        exp = self.getFormula(fieldId, 'density', zone)
629        if not exp:
630            exp = "rho = 1.8;"
631        req = [('rho', 'Density')]
632
633        # Predefined Symbols
634        symbols = []
635
636        # Known fields (for equation->C translation) within the code
637        known_fields = []
638
639        for s in self.list_scalars:
640           symbols.append(s)
641           known_fields.append(s)
642
643        if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
644            label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
645            symbols.append((label, "enthalpy_"+str(fieldId)))
646            known_fields.append((label, "enthalpy_"+str(fieldId)))
647            # If working on total enthalpy, velocity is needed in order
648            # to compute specific_enthalpy
649            if MainFieldsModel(self.case).getEnergyModel(fieldId) == 'total_enthalpy':
650                ulabel = self.m_out.getVariableLabel(str(fieldId), "velocity")
651                symbols.append((ulabel, 'velocity_'+str(fieldId)))
652                known_fields.append((ulabel, 'velocity_'+str(fieldId),3))
653
654        rho0_value = self.getInitialValue(fieldId, 'density')
655        symbols.append(('rho0', 'Density (reference value) = '+str(rho0_value)))
656
657        symbols.append(('volume', 'Zone volume'))
658
659        for s in self.m_spe.getScalarByFieldId(fieldId):
660            symbols.append((s, s))
661            known_fields.append((s, s))
662
663        for (nme, val) in self.notebook.getNotebookList():
664            symbols.append((nme, 'value (notebook) = ' + str(val)))
665
666        return exp, req, known_fields, symbols
667
668
669    def getFormulaMuComponents(self, fieldId, zone="1"):
670        """
671        User formula for molecular viscosity
672        """
673        exp = self.getFormula(fieldId, 'molecular_viscosity', zone)
674        if not exp:
675            exp = "mu = 4.56e-05;"
676        req = [('mu', 'Molecular Viscosity')]
677
678        # Predefined Symbols
679        symbols = []
680
681        # Known fields (for equation->C translation) within the code
682        known_fields = []
683
684        for s in self.list_scalars:
685           symbols.append(s)
686           known_fields.append(s)
687
688        if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
689            label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
690            symbols.append((label, 'enthalpy_'+str(fieldId)))
691            known_fields.append((label, 'enthalpy_'+str(fieldId)))
692            # If working on total enthalpy, velocity is needed in order
693            # to compute specific_enthalpy
694            if MainFieldsModel(self.case).getEnergyModel(fieldId) == 'total_enthalpy':
695                ulabel = self.m_out.getVariableLabel(str(fieldId), "velocity")
696                symbols.append((ulabel, 'velocity_'+str(fieldId)))
697                known_fields.append((ulabel, 'velocity_'+str(fieldId),3))
698
699        mu0_val = self.getInitialValue(fieldId, 'molecular_viscosity')
700        symbols.append(('mu0', 'Viscosity (reference value) = '+str(mu0_val)))
701
702        symbols.append(('volume', 'Zone volume'))
703
704        for s in self.m_spe.getScalarByFieldId(fieldId):
705            symbols.append((s, s))
706            known_fields.append((s, s))
707
708        for (nme, val) in self.notebook.getNotebookList():
709            symbols.append((nme, 'value (notebook) = ' + str(val)))
710
711        return exp, req, known_fields, symbols
712
713
714    def getFormulaCpComponents(self, fieldId, zone="1"):
715        """
716        User formula for specific heat
717        """
718        exp = self.getFormula(fieldId, 'specific_heat', zone)
719
720        if not exp:
721            exp = "cp = 4000.;"
722        req = [('cp', 'Specific heat')]
723
724        # Predefined Symbols
725        symbols = []
726
727        # Known fields (for equation->C translation) within the code
728        known_fields = []
729
730        for s in self.list_scalars:
731           symbols.append(s)
732           known_fields.append(s)
733
734        if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
735            label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
736            symbols.append((label, "enthalpy_"+str(fieldId)))
737            known_fields.append((label, "enthalpy_"+str(fieldId)))
738            # If working on total enthalpy, velocity is needed in order
739            # to compute specific_enthalpy
740            if MainFieldsModel(self.case).getEnergyModel(fieldId) == 'total_enthalpy':
741                ulabel = self.m_out.getVariableLabel(str(fieldId), "velocity")
742                symbols.append((ulabel, 'velocity_'+str(fieldId)))
743                known_fields.append((ulabel, 'velocity_'+str(fieldId),3))
744
745        cp0_val = self.getInitialValue(fieldId, "specific_heat")
746        symbols.append(('cp0', 'Specific heat (reference value) = '+str(cp0_val)))
747
748        symbols.append(('volume', 'Zone volume'))
749
750        for s in self.m_spe.getScalarByFieldId(fieldId):
751            symbols.append((s, s))
752            known_fields.append((s, s))
753
754        for (nme, val) in self.notebook.getNotebookList():
755            symbols.append((nme, 'value (notebook) = ' + str(val)))
756
757        return exp, req, known_fields, symbols
758
759
760    def getFormulaAlComponents(self, fieldId, zone="1"):
761        """
762        User formula for thermal conductivity
763        """
764        exp = self.getFormula(fieldId, 'thermal_conductivity', zone)
765        if not exp:
766            exp = "lambda = 1.e-5;"
767        req = [('lambda', 'Thermal conductivity')]
768
769        # Predefined Symbols
770        symbols = []
771
772        # Known fields (for equation->C translation) within the code
773        known_fields = []
774
775        for s in self.list_scalars:
776           symbols.append(s)
777           known_fields.append(s)
778
779        if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
780            label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
781            symbols.append((label, 'enthalpy_'+str(fieldId)))
782            known_fields.append((label, 'enthalpy_'+str(fieldId)))
783            # If working on total enthalpy, velocity is needed in order
784            # to compute specific_enthalpy
785            if MainFieldsModel(self.case).getEnergyModel(fieldId) == 'total_enthalpy':
786                ulabel = self.m_out.getVariableLabel(str(fieldId), "velocity")
787                symbols.append((ulabel, 'velocity_'+str(fieldId)))
788                known_fields.append((ulabel, 'velocity_'+str(fieldId),3))
789
790        l0_val = self.getInitialValue(fieldId, 'thermal_conductivity')
791        symbols.append(('lambda0', 'Thermal conductivity (reference value) = '+str(l0_val)))
792
793        symbols.append(('volume', 'Zone volume'))
794
795        for s in self.m_spe.getScalarByFieldId(fieldId):
796            symbols.append((s, s))
797            known_fields.append((s, s))
798
799        for (nme, val) in self.notebook.getNotebookList():
800            symbols.append((nme, 'value (notebook) = ' + str(val)))
801
802        return exp, req, known_fields, symbols
803
804    def getFormulaTemperatureComponents(self, fieldId, zone="1"):
805        """
806        User formula for temperature as a function of enthalpy
807        """
808        label = self.m_out.getVariableLabel(str(fieldId), 'temperature')
809        exp = self.getFormula(fieldId, 'temperature', zone)
810        if not exp:
811            exp = "# If working with total enthalpy, you need to compute\n"
812            exp+= "# the specific enthalpy using:\n"
813            exp+= "# hspec = enthalpy - 0.5*square_norm(U)\n"
814            exp+= label + " = 273.15;"
815        req = [(label, 'temperature')]
816
817        # Predefined Symbols
818        symbols = []
819
820        # Known fields (for equation->C translation) within the code
821        known_fields = []
822
823        for s in self.list_scalars:
824           symbols.append(s)
825        if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
826            label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
827            symbols.append((label, 'enthalpy_'+str(fieldId)))
828            known_fields.append((label, 'enthalpy_'+str(fieldId)))
829
830            # If working on total enthalpy, velocity is needed in order
831            # to compute specific_enthalpy
832            if MainFieldsModel(self.case).getEnergyModel(fieldId) == 'total_enthalpy':
833                ulabel = self.m_out.getVariableLabel(str(fieldId), "velocity")
834                symbols.append((ulabel, 'velocity_'+str(fieldId)))
835                known_fields.append((ulabel, 'velocity_'+str(fieldId),3))
836
837        symbols.append(('volume', 'Zone volume'))
838
839        for s in self.m_spe.getScalarByFieldId(fieldId):
840            symbols.append((s, s))
841            known_fields.append((s, s))
842
843        for (nme, val) in self.notebook.getNotebookList():
844            symbols.append((nme, 'value (notebook) = ' + str(val)))
845
846        return exp, req, known_fields, symbols
847
848
849    def getFormuladrodpComponents(self, fieldId, zone="1"):
850        """
851        User formula for d(ro) / dp (compressible flow)
852        """
853        exp = self.getFormula(fieldId, 'd_rho_d_P', zone)
854        if not exp:
855            exp = "d_rho_d_P = 0.;"
856        req = [('d_rho_d_P', 'Partial derivative of density with respect to pressure')]
857
858        # Predefined Symbols
859        symbols = []
860
861        # Known fields (for equation->C translation) within the code
862        known_fields = []
863
864        for s in self.list_scalars:
865           symbols.append(s)
866           known_fields.append(s)
867
868        if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
869            label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
870            symbols.append((label, 'enthalpy_'+str(fieldId)))
871            known_fields.append((label, 'enthalpy_'+str(fieldId)))
872            # If working on total enthalpy, velocity is needed in order
873            # to compute specific_enthalpy
874            if MainFieldsModel(self.case).getEnergyModel(fieldId) == 'total_enthalpy':
875                ulabel = self.m_out.getVariableLabel(str(fieldId), "velocity")
876                symbols.append((ulabel, 'velocity_'+str(fieldId)))
877                known_fields.append((ulabel, 'velocity_'+str(fieldId),3))
878
879        symbols.append(('volume', 'Zone volume'))
880
881        for s in self.m_spe.getScalarByFieldId(fieldId):
882            symbols.append((s, s))
883            known_fields.append((s, s))
884
885        for (nme, val) in self.notebook.getNotebookList():
886            symbols.append((nme, 'value (notebook) = ' + str(val)))
887
888        return  exp, req, known_fields, symbols
889
890
891    def getFormuladrodhComponents(self, fieldId, zone="1"):
892        """
893        User formula for d(ro) / dh (compressible flow)
894        """
895        exp = self.getFormula(fieldId, 'd_rho_d_h', zone)
896        if not exp:
897            exp = "d_rho_d_h = 0.;"
898        req = [('d_rho_d_h', 'Partial derivative of density with respect to enthalpy')]
899
900        # Predefined Symbols
901        symbols = []
902
903        # Known fields (for equation->C translation) within the code
904        known_fields = []
905
906        for s in self.list_scalars:
907           symbols.append(s)
908           known_fields.append(s)
909
910        if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
911            label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
912            symbols.append((label, 'enthalpy_'+str(fieldId)))
913            known_fields.append((label, 'enthalpy_'+str(fieldId)))
914            # If working on total enthalpy, velocity is needed in order
915            # to compute specific_enthalpy
916            if MainFieldsModel(self.case).getEnergyModel(fieldId) == 'total_enthalpy':
917                ulabel = self.m_out.getVariableLabel(str(fieldId), "velocity")
918                symbols.append((ulabel, 'velocity_'+str(fieldId)))
919                known_fields.append((ulabel, 'velocity_'+str(fieldId),3))
920
921        symbols.append(('volume', 'Zone volume'))
922
923        for s in self.m_spe.getScalarByFieldId(fieldId):
924            symbols.append((s, s))
925            known_fields.append((s, s))
926
927        for (nme, val) in self.notebook.getNotebookList():
928            symbols.append((nme, 'value (notebook) = ' + str(val)))
929
930        return exp, req, known_fields, symbols
931
932
933    def getFormuladTsatdpComponents(self, zone="1"):
934
935        exp = self.getFormula('none', 'd_Tsat_d_P', zone)
936        label = self.m_out.getVariableLabel('none', 'd_Tsat_d_P')
937        req = [(label, 'Partial derivative of Saturation temperature with respect to pressure')]
938
939        # Predefined Symbols
940        symbols = []
941
942        # Known fields (for equation->C translation) within the code
943        known_fields = []
944
945        for s in self.list_scalars:
946            symbols.append(s)
947            known_fields.append(s)
948
949        symbols.append(('volume', 'Zone volume'))
950
951        for s in self.m_spe.getScalarNameList():
952            symbols.append((s, self.tr("Additional species")))
953            known_fields.append((s, self.tr("Additional species")))
954
955        return exp, req, known_fields, symbols
956
957
958    def getFormulaHlatComponents(self, zone="1"):
959
960        exp = self.getFormula('none', 'LatentHeat', zone)
961        label = self.m_out.getVariableLabel('none', 'LatentHeat')
962        req = [(label, 'latent heat')]
963
964        # Predefined Symbols
965        symbols = []
966
967        # Known fields (for equation->C translation) within the code
968        known_fields = []
969
970        for s in self.list_scalars:
971            symbols.append(s)
972            known_fields.append(s)
973
974        symbols.append(('volume', 'Zone volume'))
975
976        for s in self.m_spe.getScalarNameList():
977            symbols.append((s, self.tr('Additional species')))
978            known_fields.append((s, self.tr('Additional species')))
979
980        return exp, req, known_fields, symbols
981
982
983    def getFormulaTsatComponents(self, zone="1"):
984
985        exp = self.getFormula('none', 'SaturationTemperature', zone)
986        label = self.m_out.getVariableLabel('none', 'SaturationTemperature')
987        req = [(label, 'SaturationTemperature')]
988
989        # Predefined Symbols
990        symbols = []
991
992        # Known fields (for equation->C translation) within the code
993        known_fields = []
994
995        for s in self.list_scalars:
996            symbols.append(s)
997            known_fields.append(s)
998
999        symbols.append(('volume', 'Zone volume'))
1000
1001        for s in self.m_spe.getScalarNameList():
1002            symbols.append((s, self.tr('additional species')))
1003            known_fields.append((s, self.tr('additional species')))
1004
1005        return exp, req, known_fields, symbols
1006
1007    def getFormuladHsatdpComponents(self, tag, zone="1"):
1008
1009        exp = self.getFormula('none', tag, zone)
1010
1011        label = self.m_out.getVariableLabel('none', tag)
1012        req  = [(label, 'Partial derivative of enthalpy of saturation with respect to pressure')]
1013
1014        # Predefined Symbols
1015        symbols = []
1016
1017        # Known fields (for equation->C translation) within the code
1018        known_fields = []
1019
1020        for s in self.list_scalars:
1021            symbols.append(s)
1022            known_fields.append(s)
1023
1024        symbols.append(('volume', 'Zone volume'))
1025
1026        for s in self.m_spe.getScalarNameList():
1027            symbols.append((s, self.tr('Additional species')))
1028            known_fields.append((s, self.tr('Additional species')))
1029
1030        return exp, req, known_fields, symbols
1031
1032
1033    def getFormulaHsatComponents(self, tag, zone="1"):
1034
1035        label = self.m_out.getVariableLabel('none', tag)
1036        exp = self.getFormula('none', tag, zone)
1037
1038        req = [(label, 'enthalpy of saturation')]
1039
1040        # Predefined Symbols
1041        symbols = []
1042
1043        # Known fields (for equation->C translation) within the code
1044        known_fields = []
1045
1046        for s in self.list_scalars:
1047            symbols.append(s)
1048            known_fields.append(s)
1049
1050        symbols.append(('volume', 'Zone volume'))
1051
1052        for s in self.m_spe.getScalarNameList():
1053            symbols.append((s, self.tr('additional species')))
1054            known_fields.append((s, self.tr('additional species')))
1055
1056        return exp, req, known_fields, symbols
1057
1058    def tr(self, text):
1059        """
1060        translation
1061        """
1062        return text
1063
1064
1065# TODO change of architecture to avoid redundant get/set methods (instead of passing field_ids,
1066#  we should pass an common object, without the details of it being one field, two fields, a banana...)
1067class ThermodynamicsInteractionModel(ThermodynamicsModel):
1068
1069    def __init__(self, case):
1070        ThermodynamicsModel.__init__(self, case)
1071        self.available_modes = ["constant", "user_law", "eos"]
1072
1073    def defaultValues(self):
1074        reference_id = None
1075        for field_id in self.getFieldIdList():
1076            reference_id = field_id
1077            if not(super().checkEOSRequirements(field_id)):
1078                break
1079        default = super().defaultValues(reference_id)
1080        default["surface_tension"] = 0.075
1081        return default
1082
1083    def propertiesFormulaList(self):
1084        return ('surface_tension')
1085
1086    @Variables.noUndo
1087    def getPropertyMode(self, field_id_a, field_id_b, tag):
1088        """Return choice of node I{tag}. Choice is constant or variable"""
1089        fieldIdList = self.getFieldIdList()
1090        fieldIdList.append('none')
1091        self.isInList(str(field_id_a), fieldIdList)
1092        self.isInList(str(field_id_b), fieldIdList)
1093
1094        self.isInList(tag, self.propertiesFormulaList())
1095        node = self.XMLNodeproperty.xmlGetNode('property', field_id_a=field_id_a, field_id_b=field_id_b, name=tag)
1096
1097        c = None
1098        if node:
1099            if node['choice'] != "" and node['choice'] != None:
1100                c = node['choice']
1101                self.isInList(c, self.available_modes)
1102
1103        if c == None:
1104            c = self.defaultValues()['propertyChoice']
1105            if node:
1106                self.setPropertyMode(field_id_a, field_id_b, tag, c)
1107
1108        return c
1109
1110    @Variables.undoLocal
1111    def setPropertyMode(self, field_id_a, field_id_b, tag, choice):
1112        """Put choice in xml file's node I{tag}"""
1113        fieldIdList = self.getFieldIdList()
1114        fieldIdList.append('none')
1115        self.isInList(str(field_id_a), fieldIdList)
1116        self.isInList(str(field_id_b), fieldIdList)
1117
1118        self.isInList(tag, self.propertiesFormulaList())
1119        self.isInList(choice, self.available_modes)
1120
1121        node = self.XMLNodeproperty.xmlInitChildNode('property', field_id_a=field_id_a, field_id_b=field_id_b, name=tag)
1122        node['choice'] = choice
1123
1124        if choice == 'constant':
1125            node.xmlRemoveChild('formula')
1126
1127    @Variables.noUndo
1128    def getInitialValue(self, field_id_a, field_id_b, tag):
1129        """
1130        Return initial value of the markup tag : 'density', or
1131        'molecular_viscosity', 'specific_heat', 'thermal_conductivity',
1132        'surface_tension', 'emissivity' or 'elasticity'
1133        """
1134        fieldIdList = self.getFieldIdList()
1135        fieldIdList.append('none')
1136        self.isInList(str(field_id_a), fieldIdList)
1137        self.isInList(str(field_id_b), fieldIdList)
1138
1139        self.isInList(tag, self.propertiesFormulaList())
1140        node = self.XMLNodeproperty.xmlGetNode('property', field_id_a=field_id_a, field_id_b=field_id_b, name=tag)
1141        pp = node.xmlGetDouble('initial_value')
1142        if pp == None:
1143            pp = self.defaultValues()[tag]
1144            self.setInitialValue(field_id_a, field_id_b, tag, pp)
1145        return pp
1146
1147    @Variables.undoLocal
1148    def setInitialValue(self, field_id_a, field_id_b, tag, val):
1149        """
1150        Put initial value for the markup tag : 'density', or
1151        'molecular_viscosity', 'specific_heat', 'thermal_conductivity',
1152        'surface_tension', 'emissivity' or 'elasticity'
1153        """
1154        fieldIdList = self.getFieldIdList()
1155        fieldIdList.append('none')
1156        self.isInList(str(field_id_a), fieldIdList)
1157        self.isInList(str(field_id_b), fieldIdList)
1158
1159        self.isInList(tag, self.propertiesFormulaList())
1160        self.isFloat(val)
1161        if tag != 'emissivity' and tag != 'elasticity':
1162            self.isGreater(val, 0.)
1163        node = self.XMLNodeproperty.xmlInitChildNode('property', field_id_a=field_id_a, field_id_b=field_id_b, name=tag)
1164        node.xmlSetData('initial_value', val)
1165
1166    @Variables.noUndo
1167    def getFormula(self, field_id_a, field_id_b, tag, zone="1"):
1168        """
1169        Return a formula for properties
1170        """
1171        fieldIdList = self.getFieldIdList()
1172        fieldIdList.append('none')
1173        self.isInList(str(field_id_a), fieldIdList)
1174        self.isInList(str(field_id_b), fieldIdList)
1175        self.isInList(tag, self.propertiesFormulaList())
1176
1177        node = self.XMLNodeproperty.xmlGetNode('property', field_id_a=field_id_a, field_id_b=field_id_b, name=tag)
1178
1179        if str(zone) != "1":
1180            node = node.xmlGetChildNode("zone", zone_id=zone)
1181            if node == None:
1182                node = node.xmlInitChildNode("zone", zone_id=zone)
1183
1184        if node:
1185            return node.xmlGetChildString('formula')
1186        else:
1187            return None
1188
1189    @Variables.undoLocal
1190    def setFormula(self, field_id_a, field_id_b, tag, strg, zone="1"):
1191        """
1192        Gives a formula for properties
1193        """
1194        fieldIdList = self.getFieldIdList()
1195        fieldIdList.append('none')
1196        self.isInList(str(field_id_a), fieldIdList)
1197        self.isInList(str(field_id_b), fieldIdList)
1198        self.isInList(tag, self.propertiesFormulaList())
1199        node = self.XMLNodeproperty.xmlInitChildNode('property', field_id_a=field_id_a, field_id_b=field_id_b, name=tag)
1200
1201        if str(zone) != "1":
1202            node = node.xmlGetChildNode("zone", zone_id=zone)
1203            if node == None:
1204                node = node.xmlInitChildNode("zone", zone_id=zone)
1205
1206        node.xmlSetData('formula', strg)
1207
1208    @Variables.noUndo
1209    def getInitialValueTens(self, field_id_a, field_id_b):
1210        """Return initial value of surface tension"""
1211        return self.getInitialValue(field_id_a, field_id_b, 'surface_tension')
1212
1213    @Variables.undoLocal
1214    def setInitialValueTens(self, field_id_a, field_id_b, val):
1215        """Put initial value for surface tension"""
1216        self.setInitialValue(field_id_a, field_id_b, 'surface_tension', val)
1217
1218    def getFormulaComponents(self, field_id_a, field_id_b, tag, zone="1"):
1219        """
1220        Get the formula components for a given tag
1221        """
1222
1223        if tag == 'surface_tension':
1224            return self.getFormulaStComponents(field_id_a, field_id_b, zone)
1225        else:
1226            msg = 'Formula is not available for field %s_%s in MEG' % (tag, str(fieldId))
1227            raise Exception(msg)
1228
1229    def getFormulaStComponents(self, field_id_a, field_id_b, zone="1"):
1230        """
1231        User formula for surface tension
1232        """
1233        exp = self.getFormula(field_id_a, field_id_b, 'surface_tension', zone)
1234        if not exp:
1235            exp = "sigma = 0.075;"
1236        req = [('sigma', 'Surface Tension')]
1237
1238        # Predefined Symbols
1239        symbols = []
1240
1241        # Known fields (for equation->C translation) within the code
1242        known_fields = []
1243
1244        for s in self.list_scalars:
1245            symbols.append(s)
1246            known_fields.append(s)
1247
1248        for fieldId in self.getFieldIdList():
1249            if MainFieldsModel(self.case).getEnergyResolution(fieldId) == "on":
1250                label = self.m_out.getVariableLabel(str(fieldId), "enthalpy")
1251                symbols.append((label, 'enthalpy_' + str(fieldId)))
1252                known_fields.append((label, 'enthalpy_' + str(fieldId)))
1253
1254        s0_val = self.getInitialValue('none', 'surface_tension')
1255        symbols.append(('sigma0', 'Surface tension (reference value) = ' + str(s0_val)))
1256
1257        symbols.append(('volume', 'Zone volume'))
1258
1259        for s in self.m_spe.getScalarNameList():
1260            symbols.append((s, s))
1261            known_fields.append((s, s))
1262
1263        for (nme, val) in self.notebook.getNotebookList():
1264            symbols.append((nme, 'value (notebook) = ' + str(val)))
1265
1266        return exp, req, known_fields, symbols
1267
1268
1269# -------------------------------------------------------------------------------
1270# DefineUsersScalars test case
1271# -------------------------------------------------------------------------------
1272class ThermodynamicsTestCase(ModelTest):
1273    """
1274    """
1275
1276    def checkThermodynamicsInstantiation(self):
1277        """Check whether the ThermodynamicsModel class could be instantiated"""
1278        model = None
1279        model = ThermodynamicsModel(self.case)
1280        assert model != None, 'Could not instantiate ThermodynamicsModel'
1281
1282
1283    def checkGetandSetMaterials(self):
1284        """Check whether the ThermodynamicsModel class could set and get Materials"""
1285        MainFieldsModel(self.case).addField()
1286        mdl = ThermodynamicsModel(self.case)
1287        mdl.setMaterials('1','user_material')
1288        doc = '''<fields>
1289                         <field field_id="1" label="Field1">
1290                                 <type choice="continuous"/>
1291                                 <carrier_field field_id="off"/>
1292                                 <phase choice="liquid"/>
1293                                 <hresolution status="on"/>
1294                                 <compressible status="off"/>
1295                                 <material choice="user_material"/>
1296                         </field>
1297                 </fields>'''
1298        assert mdl.getXMLNodefieldsNode() == self.xmlNodeFromString(doc),\
1299            'Could not set Materials'
1300        assert mdl.getMaterials('1') == 'user_material',\
1301            'Could not get Materials'
1302
1303
1304    def checkGetandSetMethod(self):
1305        """Check whether the ThermodynamicsModel class could set and get Method"""
1306        MainFieldsModel(self.case).addField()
1307        mdl = ThermodynamicsModel(self.case)
1308        mdl.setMaterials('1','user_material')
1309        mdl.setMethod('1','user_properties')
1310        doc = '''<fields>
1311                         <field field_id="1" label="Field1">
1312                                 <type choice="continuous"/>
1313                                 <carrier_field field_id="off"/>
1314                                 <phase choice="liquid"/>
1315                                 <hresolution status="on"/>
1316                                 <compressible status="off"/>
1317                                 <method choice="user_properties"/>
1318                                 <material choice="user_material"/>
1319                                 <reference choice="user_material"/>
1320                         </field>
1321                 </fields>'''
1322        assert mdl.getXMLNodefieldsNode() == self.xmlNodeFromString(doc),\
1323            'Could not set Method'
1324        assert mdl.getMethod('1') == 'user_properties',\
1325            'Could not get Method'
1326
1327
1328    def checkGetandSetInitialValue(self):
1329        """Check whether the ThermodynamicsModel class could set and get InitialValue"""
1330        MainFieldsModel(self.case).addField()
1331        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
1332        MainFieldsModel(self.case).addDefinedField('3', 'field3', 'dispersed', 'gas', 'on', 'on', 'off', 3)
1333        mdl = ThermodynamicsModel(self.case)
1334        mdl.setInitialValue('2','density',1.24)
1335        mdl.setInitialValue('2','molecular_viscosity',4.21)
1336        mdl.setInitialValue('2','specific_heat',6.23)
1337        mdl.setInitialValue('2','thermal_conductivity',885.21)
1338        mdl.setInitialValue('none','surface_tension',0.075)
1339        mdl.setInitialValue('2','emissivity',15446.2)
1340        mdl.setInitialValue('2','elasticity',22.2)
1341        doc = '''<properties>
1342                         <property choice="" field_id="1" label="Temperature" name="temperature">
1343                                 <listing_printing status="on"/>
1344                                 <postprocessing_recording status="on"/>
1345                         </property>
1346                         <property choice="constant" field_id="1" label="density1" name="density">
1347                                 <listing_printing status="on"/>
1348                                 <postprocessing_recording status="on"/>
1349                         </property>
1350                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1351                                 <listing_printing status="on"/>
1352                                 <postprocessing_recording status="on"/>
1353                         </property>
1354                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1355                                 <listing_printing status="on"/>
1356                                 <postprocessing_recording status="on"/>
1357                         </property>
1358                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1359                                 <listing_printing status="on"/>
1360                                 <postprocessing_recording status="on"/>
1361                         </property>
1362                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1363                                 <listing_printing status="on"/>
1364                                 <postprocessing_recording status="on"/>
1365                         </property>
1366                         <property choice="" field_id="2" label="Diam2" name="Diameter">
1367                                 <listing_printing status="on"/>
1368                                 <postprocessing_recording status="on"/>
1369                         </property>
1370                         <property choice="" field_id="2" label="emissivity2" name="emissivity">
1371                                 <listing_printing status="on"/>
1372                                 <postprocessing_recording status="on"/>
1373                                 <initial_value>
1374                                         15446.2
1375                                 </initial_value>
1376                         </property>
1377                         <property choice="" field_id="2" label="elasticity2" name="elasticity">
1378                                 <listing_printing status="on"/>
1379                                 <postprocessing_recording status="on"/>
1380                                 <initial_value>
1381                                         22.2
1382                                 </initial_value>
1383                         </property>
1384                         <property choice="" field_id="2" label="temp2" name="temperature">
1385                                 <listing_printing status="on"/>
1386                                 <postprocessing_recording status="on"/>
1387                         </property>
1388                         <property choice="constant" field_id="2" label="density2" name="density">
1389                                 <listing_printing status="on"/>
1390                                 <postprocessing_recording status="on"/>
1391                                                  <initial_value>
1392                                         1.24
1393                                 </initial_value>
1394                         </property>
1395                         <property choice="constant" field_id="2" label="molecular_viscosity_2" name="molecular_viscosity">
1396                                 <listing_printing status="on"/>
1397                                 <postprocessing_recording status="on"/>
1398                                 <initial_value>
1399                                         4.21
1400                                 </initial_value>
1401                         </property>
1402                         <property choice="constant" field_id="2" label="specific_heat_2" name="specific_heat">
1403                                 <listing_printing status="on"/>
1404                                 <postprocessing_recording status="on"/>
1405                                 <initial_value>
1406                                         6.23
1407                                 </initial_value>
1408                         </property>
1409                         <property choice="constant" field_id="2" label="thermal_conductivity_2" name="thermal_conductivity">
1410                                 <listing_printing status="on"/>
1411                                 <postprocessing_recording status="on"/>
1412                                 <initial_value>
1413                                         885.21
1414                                 </initial_value>
1415                         </property>
1416                         <property choice="" field_id="2" label="mass_trans2" name="mass_trans">
1417                                 <listing_printing status="on"/>
1418                                 <postprocessing_recording status="on"/>
1419                         </property>
1420                         <property choice="constant" field_id="none" label="Surf_tens" name="surface_tension">
1421                                 <listing_printing status="on"/>
1422                                 <postprocessing_recording status="on"/>
1423                                 <initial_value>
1424                                         0.075
1425                                 </initial_value>
1426                         </property>
1427                 </properties>'''
1428        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1429            'Could not set InitialValue'
1430        assert mdl.getInitialValue('2','density') == 1.24,\
1431            'Could not get InitialValue density'
1432        assert mdl.getInitialValue('2','molecular_viscosity') == 4.21,\
1433            'Could not get InitialValue molecular_viscosity'
1434        assert mdl.getInitialValue('2','specific_heat') == 6.23,\
1435            'Could not get InitialValue specific_heat'
1436        assert mdl.getInitialValue('2','thermal_conductivity') == 885.21,\
1437            'Could not get InitialValue thermal_conductivity'
1438        assert mdl.getInitialValue('2','emissivity') == 15446.2,\
1439            'Could not get InitialValue emissivity'
1440        assert mdl.getInitialValue('2','elasticity') == 22.2,\
1441            'Could not get InitialValue elasticity'
1442        assert mdl.getInitialValue('none','surface_tension') == 0.075,\
1443            'Could not get InitialValue surface_tension'
1444
1445
1446    def checkGetandSetInitialValueDensity(self):
1447        """Check whether the ThermodynamicsModel class could set and get InitialValueDensity"""
1448        MainFieldsModel(self.case).addField()
1449        mdl = ThermodynamicsModel(self.case)
1450        mdl.setInitialValueDensity('1',8.8)
1451        doc = '''<properties>
1452                         <property choice="" field_id="1" label="Temperature" name="temperature">
1453                                 <listing_printing status="on"/>
1454                                 <postprocessing_recording status="on"/>
1455                         </property>
1456                         <property choice="constant" field_id="1" label="density1" name="density">
1457                                 <listing_printing status="on"/>
1458                                 <postprocessing_recording status="on"/>
1459                                 <initial_value>
1460                                         8.8
1461                                 </initial_value>
1462                         </property>
1463                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1464                                 <listing_printing status="on"/>
1465                                 <postprocessing_recording status="on"/>
1466                         </property>
1467                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1468                                 <listing_printing status="on"/>
1469                                 <postprocessing_recording status="on"/>
1470                         </property>
1471                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1472                                 <listing_printing status="on"/>
1473                                 <postprocessing_recording status="on"/>
1474                         </property>
1475                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1476                                 <listing_printing status="on"/>
1477                                 <postprocessing_recording status="on"/>
1478                         </property>
1479                 </properties>'''
1480        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1481            'Could not set InitialValueDensity'
1482        assert mdl.getInitialValueDensity('1') == 8.8,\
1483            'Could not get InitialValueDensity'
1484
1485
1486    def checkGetandSetInitialValueViscosity(self):
1487        """Check whether the ThermodynamicsModel class could set and get InitialValueViscosity"""
1488        MainFieldsModel(self.case).addField()
1489        mdl = ThermodynamicsModel(self.case)
1490        mdl.setInitialValueViscosity('1',7.7)
1491        doc = '''<properties>
1492                         <property choice="" field_id="1" label="Temperature" name="temperature">
1493                                 <listing_printing status="on"/>
1494                                 <postprocessing_recording status="on"/>
1495                         </property>
1496                         <property choice="constant" field_id="1" label="density1" name="density">
1497                                 <listing_printing status="on"/>
1498                                 <postprocessing_recording status="on"/>
1499                         </property>
1500                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1501                                 <listing_printing status="on"/>
1502                                 <postprocessing_recording status="on"/>
1503                                 <initial_value>
1504                                         7.7
1505                                 </initial_value>
1506                         </property>
1507                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1508                                 <listing_printing status="on"/>
1509                                 <postprocessing_recording status="on"/>
1510                         </property>
1511                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1512                                 <listing_printing status="on"/>
1513                                 <postprocessing_recording status="on"/>
1514                         </property>
1515                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1516                                 <listing_printing status="on"/>
1517                                 <postprocessing_recording status="on"/>
1518                         </property>
1519                 </properties>'''
1520        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1521            'Could not set InitialValueViscosity'
1522        assert mdl.getInitialValueViscosity('1') == 7.7,\
1523            'Could not get InitialValueViscosity'
1524
1525
1526    def checkGetandSetInitialValueHeat(self):
1527        """Check whether the ThermodynamicsModel class could set and get InitialValueHeat"""
1528        MainFieldsModel(self.case).addField()
1529        mdl = ThermodynamicsModel(self.case)
1530        mdl.setInitialValueHeat('1',118.712)
1531        doc = '''<properties>
1532                         <property choice="" field_id="1" label="Temperature" name="temperature">
1533                                 <listing_printing status="on"/>
1534                                 <postprocessing_recording status="on"/>
1535                         </property>
1536                         <property choice="constant" field_id="1" label="density1" name="density">
1537                                 <listing_printing status="on"/>
1538                                 <postprocessing_recording status="on"/>
1539                         </property>
1540                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1541                                 <listing_printing status="on"/>
1542                                 <postprocessing_recording status="on"/>
1543                         </property>
1544                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1545                                 <listing_printing status="on"/>
1546                                 <postprocessing_recording status="on"/>
1547                                 <initial_value>
1548                                         118.712
1549                                 </initial_value>
1550                         </property>
1551                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1552                                 <listing_printing status="on"/>
1553                                 <postprocessing_recording status="on"/>
1554                         </property>
1555                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1556                                 <listing_printing status="on"/>
1557                                 <postprocessing_recording status="on"/>
1558                         </property>
1559                 </properties>'''
1560        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1561            'Could not set InitialValueHeat'
1562        assert mdl.getInitialValueHeat('1') == 118.712,\
1563            'Could not get InitialValueHeat'
1564
1565
1566    def checkGetandSetInitialValueCond(self):
1567        """Check whether the ThermodynamicsModel class could set and get InitialValueCond"""
1568        MainFieldsModel(self.case).addField()
1569        mdl = ThermodynamicsModel(self.case)
1570        mdl.setInitialValueCond('1',456.1)
1571        doc = '''<properties>
1572                         <property choice="" field_id="1" label="Temperature" name="temperature">
1573                                 <listing_printing status="on"/>
1574                                 <postprocessing_recording status="on"/>
1575                         </property>
1576                         <property choice="constant" field_id="1" label="density1" name="density">
1577                                 <listing_printing status="on"/>
1578                                 <postprocessing_recording status="on"/>
1579                         </property>
1580                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1581                                 <listing_printing status="on"/>
1582                                 <postprocessing_recording status="on"/>
1583                         </property>
1584                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1585                                 <listing_printing status="on"/>
1586                                 <postprocessing_recording status="on"/>
1587                         </property>
1588                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1589                                 <listing_printing status="on"/>
1590                                 <postprocessing_recording status="on"/>
1591                                 <initial_value>
1592                                         456.1
1593                                 </initial_value>
1594                         </property>
1595                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1596                                 <listing_printing status="on"/>
1597                                 <postprocessing_recording status="on"/>
1598                         </property>
1599                 </properties>'''
1600        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1601            'Could not set InitialValueCond'
1602        assert mdl.getInitialValueCond('1') == 456.1,\
1603            'Could not get InitialValueCond'
1604
1605
1606    def checkGetandSetInitialValueTens(self):
1607        """Check whether the ThermodynamicsModel class could set and get InitialValueTens"""
1608        MainFieldsModel(self.case).addField()
1609        mdl = ThermodynamicsModel(self.case)
1610        mdl.setInitialValueTens('none',0.075)
1611        doc = '''<properties>
1612                         <property choice="" field_id="1" label="Temperature" name="temperature">
1613                                 <listing_printing status="on"/>
1614                                 <postprocessing_recording status="on"/>
1615                         </property>
1616                         <property choice="constant" field_id="1" label="density1" name="density">
1617                                 <listing_printing status="on"/>
1618                                 <postprocessing_recording status="on"/>
1619                         </property>
1620                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1621                                 <listing_printing status="on"/>
1622                                 <postprocessing_recording status="on"/>
1623                         </property>
1624                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1625                                 <listing_printing status="on"/>
1626                                 <postprocessing_recording status="on"/>
1627                         </property>
1628                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1629                                 <listing_printing status="on"/>
1630                                 <postprocessing_recording status="on"/>
1631                         </property>
1632                         <property choice="constant" field_id="none" label="Surf_tens1" name="surface_tension">
1633                                 <listing_printing status="on"/>
1634                                 <postprocessing_recording status="on"/>
1635                                 <initial_value>
1636                                         0.075
1637                                 </initial_value>
1638                         </property>
1639                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1640                                 <listing_printing status="on"/>
1641                                 <postprocessing_recording status="on"/>
1642                         </property>
1643                 </properties>'''
1644        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1645            'Could not set InitialValueTens'
1646        assert mdl.getInitialValueTens('none') == 0.075,\
1647            'Could not get InitialValueTens'
1648
1649
1650    def checkGetandSetInitialValueEmissivity(self):
1651        """Check whether the ThermodynamicsModel class could set and get InitialValueEmissivity"""
1652        MainFieldsModel(self.case).addField()
1653        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
1654        mdl = ThermodynamicsModel(self.case)
1655        mdl.setInitialValueEmissivity('2',0.008)
1656        doc = '''<properties>
1657                         <property choice="" field_id="1" label="Temperature" name="temperature">
1658                                 <listing_printing status="on"/>
1659                                 <postprocessing_recording status="on"/>
1660                         </property>
1661                         <property choice="constant" field_id="1" label="density1" name="density">
1662                                 <listing_printing status="on"/>
1663                                 <postprocessing_recording status="on"/>
1664                         </property>
1665                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1666                                 <listing_printing status="on"/>
1667                                 <postprocessing_recording status="on"/>
1668                         </property>
1669                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1670                                 <listing_printing status="on"/>
1671                                 <postprocessing_recording status="on"/>
1672                         </property>
1673                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1674                                 <listing_printing status="on"/>
1675                                 <postprocessing_recording status="on"/>
1676                         </property>
1677                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1678                                 <listing_printing status="on"/>
1679                                 <postprocessing_recording status="on"/>
1680                         </property>
1681                         <property choice="" field_id="2" label="Diam2" name="Diameter">
1682                                 <listing_printing status="on"/>
1683                                 <postprocessing_recording status="on"/>
1684                         </property>
1685                         <property choice="" field_id="2" label="emissivity2" name="emissivity">
1686                                 <listing_printing status="on"/>
1687                                 <postprocessing_recording status="on"/>
1688                                 <initial_value>
1689                                         0.008
1690                                 </initial_value>
1691                         </property>
1692                         <property choice="" field_id="2" label="elasticity2" name="elasticity">
1693                                 <listing_printing status="on"/>
1694                                 <postprocessing_recording status="on"/>
1695                         </property>
1696                         <property choice="" field_id="2" label="temp2" name="temperature">
1697                                 <listing_printing status="on"/>
1698                                 <postprocessing_recording status="on"/>
1699                         </property>
1700                         <property choice="constant" field_id="2" label="density2" name="density">
1701                                 <listing_printing status="on"/>
1702                                 <postprocessing_recording status="on"/>
1703                         </property>
1704                         <property choice="constant" field_id="2" label="molecular_viscosity_2" name="molecular_viscosity">
1705                                 <listing_printing status="on"/>
1706                                 <postprocessing_recording status="on"/>
1707                         </property>
1708                         <property choice="constant" field_id="2" label="specific_heat_2" name="specific_heat">
1709                                 <listing_printing status="on"/>
1710                                 <postprocessing_recording status="on"/>
1711                         </property>
1712                         <property choice="constant" field_id="2" label="thermal_conductivity_2" name="thermal_conductivity">
1713                                 <listing_printing status="on"/>
1714                                 <postprocessing_recording status="on"/>
1715                         </property>
1716                         <property choice="" field_id="2" label="mass_trans2" name="mass_trans">
1717                                 <listing_printing status="on"/>
1718                                 <postprocessing_recording status="on"/>
1719                         </property>
1720                 </properties>'''
1721        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1722            'Could not set InitialValueEmissivity'
1723        assert mdl.getInitialValueEmissivity('2') == 0.008,\
1724            'Could not get InitialValueEmissivity'
1725
1726
1727    def checkGetandSetInitialValueElastCoef(self):
1728        """Check whether the ThermodynamicsModel class could set and get InitialValueElastCoef"""
1729        MainFieldsModel(self.case).addField()
1730        MainFieldsModel(self.case).addDefinedField('2', 'field2', 'dispersed', 'solid', 'on', 'on', 'off', 2)
1731        mdl = ThermodynamicsModel(self.case)
1732        mdl.setInitialValueElastCoef('2',0.42)
1733        doc = '''<properties>
1734                         <property choice="" field_id="1" label="Temperature" name="temperature">
1735                                 <listing_printing status="on"/>
1736                                 <postprocessing_recording status="on"/>
1737                         </property>
1738                         <property choice="constant" field_id="1" label="density1" name="density">
1739                                 <listing_printing status="on"/>
1740                                 <postprocessing_recording status="on"/>
1741                         </property>
1742                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1743                                 <listing_printing status="on"/>
1744                                 <postprocessing_recording status="on"/>
1745                         </property>
1746                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1747                                 <listing_printing status="on"/>
1748                                 <postprocessing_recording status="on"/>
1749                         </property>
1750                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1751                                 <listing_printing status="on"/>
1752                                 <postprocessing_recording status="on"/>
1753                         </property>
1754                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1755                                 <listing_printing status="on"/>
1756                                 <postprocessing_recording status="on"/>
1757                         </property>
1758                         <property choice="" field_id="2" label="Diam2" name="Diameter">
1759                                 <listing_printing status="on"/>
1760                                 <postprocessing_recording status="on"/>
1761                         </property>
1762                         <property choice="" field_id="2" label="emissivity2" name="emissivity">
1763                                 <listing_printing status="on"/>
1764                                 <postprocessing_recording status="on"/>
1765                         </property>
1766                         <property choice="" field_id="2" label="elasticity2" name="elasticity">
1767                                 <listing_printing status="on"/>
1768                                 <postprocessing_recording status="on"/>
1769                                 <initial_value>
1770                                         0.42
1771                                 </initial_value>
1772                         </property>
1773                         <property choice="" field_id="2" label="temp2" name="temperature">
1774                                 <listing_printing status="on"/>
1775                                 <postprocessing_recording status="on"/>
1776                         </property>
1777                         <property choice="constant" field_id="2" label="density2" name="density">
1778                                 <listing_printing status="on"/>
1779                                 <postprocessing_recording status="on"/>
1780                         </property>
1781                         <property choice="constant" field_id="2" label="molecular_viscosity_2" name="molecular_viscosity">
1782                                 <listing_printing status="on"/>
1783                                 <postprocessing_recording status="on"/>
1784                         </property>
1785                         <property choice="constant" field_id="2" label="specific_heat_2" name="specific_heat">
1786                                 <listing_printing status="on"/>
1787                                 <postprocessing_recording status="on"/>
1788                         </property>
1789                         <property choice="constant" field_id="2" label="thermal_conductivity_2" name="thermal_conductivity">
1790                                 <listing_printing status="on"/>
1791                                 <postprocessing_recording status="on"/>
1792                         </property>
1793                         <property choice="" field_id="2" label="mass_trans2" name="mass_trans">
1794                                 <listing_printing status="on"/>
1795                                 <postprocessing_recording status="on"/>
1796                         </property>
1797                 </properties>'''
1798        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1799            'Could not set InitialValueElastCoef'
1800        assert mdl.getInitialValueElastCoef('2') == 0.42,\
1801            'Could not get InitialElastValueCoef'
1802
1803
1804    def checkGetandSetFormula(self):
1805        """Check whether the ThermodynamicsModel class could set and get Formula"""
1806        MainFieldsModel(self.case).addField()
1807        mdl = ThermodynamicsModel(self.case)
1808        mdl.setFormula('1','density','2.123')
1809        doc = '''<properties>
1810                         <property choice="" field_id="1" label="Temperature" name="temperature">
1811                                 <listing_printing status="on"/>
1812                                 <postprocessing_recording status="on"/>
1813                         </property>
1814                         <property choice="constant" field_id="1" label="density1" name="density">
1815                                 <listing_printing status="on"/>
1816                                 <postprocessing_recording status="on"/>
1817                                 <formula>
1818                                         2.123
1819                                 </formula>
1820                         </property>
1821                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1822                                 <listing_printing status="on"/>
1823                                 <postprocessing_recording status="on"/>
1824                         </property>
1825                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1826                                 <listing_printing status="on"/>
1827                                 <postprocessing_recording status="on"/>
1828                         </property>
1829                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1830                                 <listing_printing status="on"/>
1831                                 <postprocessing_recording status="on"/>
1832                         </property>
1833                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1834                                 <listing_printing status="on"/>
1835                                 <postprocessing_recording status="on"/>
1836                         </property>
1837                 </properties>'''
1838        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1839            'Could not set Formula'
1840        assert mdl.getFormula('1', 'density') == '2.123',\
1841            'Could not get Formula'
1842
1843
1844    def checkGetandSetRadiativeTransferStatus(self):
1845        """Check whether the ThermodynamicsModel class could set and get RadiativeTransferStatus"""
1846        MainFieldsModel(self.case).addField()
1847        mdl = ThermodynamicsModel(self.case)
1848        mdl.setRadiativeTransferStatus('1','on')
1849        doc = '''<fields>
1850                         <field field_id="1" label="Field1">
1851                                 <type choice="continuous"/>
1852                                 <carrier_field field_id="off"/>
1853                                 <phase choice="liquid"/>
1854                                 <hresolution status="on"/>
1855                                 <compressible status="off"/>
1856                                 <particles_radiative_transfer status="on"/>
1857                         </field>
1858                 </fields>'''
1859        assert mdl.getXMLNodefieldsNode() == self.xmlNodeFromString(doc),\
1860            'Could not set RadiativeTransferStatus'
1861        assert mdl.getRadiativeTransferStatus('1') == 'on',\
1862            'Could not get RadiativeTransferStatus'
1863
1864
1865    def checkGetandSetPropertyMode(self):
1866        """Check whether the ThermodynamicsModel class could set and get PropertyMode"""
1867        MainFieldsModel(self.case).addField()
1868        mdl = ThermodynamicsModel(self.case)
1869        mdl.setPropertyMode('1','density','user_law')
1870        doc = '''<properties>
1871                         <property choice="" field_id="1" label="Temperature" name="temperature">
1872                                 <listing_printing status="on"/>
1873                                 <postprocessing_recording status="on"/>
1874                         </property>
1875                         <property choice="user_law" field_id="1" label="density1" name="density">
1876                                 <listing_printing status="on"/>
1877                                 <postprocessing_recording status="on"/>
1878                         </property>
1879                         <property choice="constant" field_id="1" label="molecular_viscosity_1" name="molecular_viscosity">
1880                                 <listing_printing status="on"/>
1881                                 <postprocessing_recording status="on"/>
1882                         </property>
1883                         <property choice="constant" field_id="1" label="specific_heat_1" name="specific_heat">
1884                                 <listing_printing status="on"/>
1885                                 <postprocessing_recording status="on"/>
1886                         </property>
1887                         <property choice="constant" field_id="1" label="thermal_conductivity_1" name="thermal_conductivity">
1888                                 <listing_printing status="on"/>
1889                                 <postprocessing_recording status="on"/>
1890                         </property>
1891                         <property choice="" field_id="1" label="mass_trans1" name="mass_trans">
1892                                 <listing_printing status="on"/>
1893                                 <postprocessing_recording status="on"/>
1894                         </property>
1895                 </properties>'''
1896        assert mdl.XMLNodeproperty == self.xmlNodeFromString(doc),\
1897            'Could not set PropertyMode'
1898        assert mdl.getPropertyMode('1','density') == 'user_law',\
1899            'Could not get PropertyMode'
1900
1901
1902def suite():
1903    testSuite = unittest.makeSuite(ThermodynamicsTestCase, "check")
1904    return testSuite
1905
1906
1907def runTest():
1908    print("ThermodynamicsTestCase")
1909    runner = unittest.TextTestRunner()
1910    runner.run(suite())
1911
1912
1913