~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to gui/Pages/LocalizationModel.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: iso-8859-1 -*-
2
 
#
 
1
# -*- coding: utf-8 -*-
 
2
 
3
3
#-------------------------------------------------------------------------------
4
 
#
5
 
#     This file is part of the Code_Saturne User Interface, element of the
6
 
#     Code_Saturne CFD tool.
7
 
#
8
 
#     Copyright (C) 1998-2007 EDF S.A., France
9
 
#
10
 
#     contact: saturne-support@edf.fr
11
 
#
12
 
#     The Code_Saturne User Interface is free software; you can redistribute it
13
 
#     and/or modify it under the terms of the GNU General Public License
14
 
#     as published by the Free Software Foundation; either version 2 of
15
 
#     the License, or (at your option) any later version.
16
 
#
17
 
#     The Code_Saturne User Interface is distributed in the hope that it will be
18
 
#     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19
 
#     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
#     GNU General Public License for more details.
21
 
#
22
 
#     You should have received a copy of the GNU General Public License
23
 
#     along with the Code_Saturne Kernel; if not, write to the
24
 
#     Free Software Foundation, Inc.,
25
 
#     51 Franklin St, Fifth Floor,
26
 
#     Boston, MA  02110-1301  USA
27
 
#
 
4
 
 
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
 
6
#
 
7
# Copyright (C) 1998-2011 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
 
28
23
#-------------------------------------------------------------------------------
29
24
 
30
25
"""
71
66
        elif typeZone == 'VolumicZone':
72
67
            return VolumicZone.__new__(VolumicZone, label, codeNumber, localization)
73
68
        else:
74
 
            raise ValueError, "Unknown type zone"
 
69
            raise ValueError("Unknown type zone")
75
70
 
76
71
 
77
72
    def __init__(self, typeZone , label = None, codeNumber = None, localization = None, nature = None):
258
253
        elif typeZone == 'VolumicZone':
259
254
            return VolumicZone.__new__(VolumicLocalizationModel, case)
260
255
        else:
261
 
            raise ValueError, "Unknown type zone"
 
256
            raise ValueError("Unknown type zone")
262
257
 
263
258
 
264
259
    def __init__(self, typeZone, case):
494
489
        XMLSolutionDomainNode = self._case.xmlInitNode('solution_domain')
495
490
        self.__XMLVolumicConditionsNode = XMLSolutionDomainNode.xmlInitNode('volumic_conditions')
496
491
        self.__natureOptions = Zone('VolumicZone').getNatureList()
497
 
        self._tagList = ['initial_value']
498
 
 
 
492
        self._tagList = ['initial_value', 'head_loss']
 
493
        self.node_models = self._case.xmlGetNode('thermophysical_models')
 
494
        self.node_veloce = self.node_models.xmlGetNode('velocity_pressure')
 
495
        self.scalar_node = self._case.xmlGetNode('additional_scalars')
 
496
        self.losses_node = self._case.xmlGetNode('heads_losses')
499
497
 
500
498
    def getZones(self):
501
499
        """
502
500
        Get zones in the XML file
503
501
        """
504
 
        XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'name')
 
502
        XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'id')
505
503
 
506
504
        # XML file reading
507
505
        zones = []
508
506
        for node in XMLZonesNodes:
509
507
            label = str(node['label'])
510
 
            codeNumber = int(node['name'])
 
508
            codeNumber = int(node['id'])
511
509
            localization = str(node.xmlGetTextNode())
512
510
            nature = self.getNature(label)
513
511
            zone = Zone('VolumicZone',
523
521
        """
524
522
        Get zones in the XML file
525
523
        """
526
 
        XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'name')
 
524
        XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'id')
527
525
 
528
526
        # XML file reading
529
527
        for node in XMLZonesNodes:
530
528
            if node['label'] == label:
531
 
                codeNumber = node['name']
 
529
                codeNumber = node['id']
532
530
 
533
531
        return codeNumber
534
532
 
538
536
        Define a new localization for the current zone (zone.getLabel == label)
539
537
        Update XML file
540
538
        """
541
 
        node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'name', label = label)
 
539
        node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'id', label = label)
542
540
        node.xmlSetTextNode(localization)
543
541
 
544
542
 
547
545
        Define a new code number for the current zone (zone.getLabel == label)
548
546
        Update XML file
549
547
        """
550
 
        XMLZonesNodesList = self._case.xmlGetNodeList('zone', 'label', 'name')
 
548
        XMLZonesNodesList = self._case.xmlGetNodeList('zone', 'label', 'id')
551
549
        codeList = []
552
550
        for node in XMLZonesNodesList:
553
 
            codeList.append(node['name'])
 
551
            codeList.append(node['id'])
554
552
        return codeList
555
553
 
556
554
 
559
557
        Define a new Nature for the current zone (zone.getLabel == label)
560
558
        Update XML file
561
559
        """
562
 
        node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'name', label = label)
 
560
        node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'id', label = label)
563
561
        nature = {}
564
562
        for option in self.__natureOptions:
565
563
            if node[option] == 'on':
574
572
        Define a new Nature for the current zone (zone.getLabel == label)
575
573
        Update XML file
576
574
        """
577
 
        node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'name', label = label)
 
575
        node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'id', label = label)
578
576
        oldNature = self.getNature(label)
579
577
        if oldNature != nature:
580
578
            for option in self.__natureOptions:
593
591
        # XML file updating
594
592
        node = self.__XMLVolumicConditionsNode.xmlInitNode('zone',
595
593
                                                           label = newZone.getLabel(),
596
 
                                                           name = newZone.getCodeNumber())
 
594
                                                           id = newZone.getCodeNumber())
597
595
 
598
596
        for k, v in newZone.getNature().items():
599
597
            node[k] = v
614
612
 
615
613
        # if codeNumber is modified, we must modify zone in initialization of variables
616
614
        if old_zone.getCodeNumber() != newCodeNumber:
617
 
            node['name'] = newCodeNumber
 
615
            node['id'] = newCodeNumber
618
616
 
619
617
        node['label'] = newLabel
620
618
        node.xmlSetTextNode(newLocal)
628
626
        for tag in list:
629
627
            for n in self._case.xmlGetNodeList(tag, zone=old_zone.getCodeNumber()):
630
628
                n['zone'] = newCodeNumber
631
 
            for n in self._case.xmlGetNodeList(tag, name=old_zone.getCodeNumber()):
632
 
                n['name'] = newCodeNumber
 
629
            for n in self._case.xmlGetNodeList(tag, id=old_zone.getCodeNumber()):
 
630
                n['zone_id'] = newCodeNumber
633
631
            for n in self._case.xmlGetNodeList(tag, label=old_zone.getLabel()):
634
632
                n['label'] = newLabel
635
633
 
643
641
        # Delete node
644
642
        node = self._case.xmlGetNode('zone', label=label)
645
643
        if node:
646
 
            name = node['name']
 
644
            name = node['id']
647
645
            node.xmlRemoveNode()
648
646
 
649
647
        # Delete the other nodes for zone initializations
650
648
        for tag in self._tagList:
651
 
            nodeList = self._case.xmlGetNodeList(tag, zone=name)
 
649
            nodeList = self._case.xmlGetNodeList(tag, zone_id=name)
652
650
            for node in nodeList:
653
651
                node.xmlRemoveNode()
654
652
 
 
653
        # Update Id's
 
654
        XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'id')
 
655
 
 
656
        for node in XMLZonesNodes:
 
657
            nodeid = int(node['id'])
 
658
            if nodeid > int(name):
 
659
                node['id'] = str(nodeid-1)
 
660
 
 
661
        if self.losses_node is not None:
 
662
            for node in self.losses_node.xmlGetNodeList('head_loss'):
 
663
                nodeid = int(node['zone_id'])
 
664
                if nodeid > int(name):
 
665
                    node['zone_id'] = str(nodeid-1)
 
666
 
 
667
        for tag in self._tagList:
 
668
            for n in self.node_veloce.xmlGetNodeList('variable'):
 
669
                node = n.xmlGetNode('initial_value')
 
670
                if node:
 
671
                    nodeid = int(node['zone_id'])
 
672
                    if nodeid > int(name):
 
673
                        node['zone_id'] = str(nodeid-1)
 
674
            for n in self.scalar_node.xmlGetNodeList('scalar'):
 
675
                for node in n.xmlGetNodeList('initial_value', 'zone_id'):
 
676
                    nodeid = int(node['zone_id'])
 
677
                    if nodeid > int(name):
 
678
                        node['zone_id'] = str(nodeid-1)
 
679
 
655
680
#-------------------------------------------------------------------------------
656
681
#
657
682
#-------------------------------------------------------------------------------
1013
1038
 
1014
1039
 
1015
1040
def runTest1():
1016
 
    print __file__
 
1041
    print(__file__)
1017
1042
    runner = unittest.TextTestRunner()
1018
1043
    runner.run(suite1())
1019
1044
 
1150
1175
 
1151
1176
 
1152
1177
def runTest2():
1153
 
    print __file__
 
1178
    print(__file__)
1154
1179
    runner = unittest.TextTestRunner()
1155
1180
    runner.run(suite2())
1156
1181