1
# -*- coding: iso-8859-1 -*-
1
# -*- coding: utf-8 -*-
3
3
#-------------------------------------------------------------------------------
5
# This file is part of the Code_Saturne User Interface, element of the
6
# Code_Saturne CFD tool.
8
# Copyright (C) 1998-2007 EDF S.A., France
10
# contact: saturne-support@edf.fr
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.
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.
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
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
7
# Copyright (C) 1998-2011 EDF S.A.
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
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
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.
28
23
#-------------------------------------------------------------------------------
71
66
elif typeZone == 'VolumicZone':
72
67
return VolumicZone.__new__(VolumicZone, label, codeNumber, localization)
74
raise ValueError, "Unknown type zone"
69
raise ValueError("Unknown type zone")
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)
261
raise ValueError, "Unknown type zone"
256
raise ValueError("Unknown type zone")
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']
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')
500
498
def getZones(self):
502
500
Get zones in the XML file
504
XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'name')
502
XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'id')
506
504
# XML file reading
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',
524
522
Get zones in the XML file
526
XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'name')
524
XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'id')
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']
533
531
return codeNumber
538
536
Define a new localization for the current zone (zone.getLabel == label)
541
node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'name', label = label)
539
node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'id', label = label)
542
540
node.xmlSetTextNode(localization)
547
545
Define a new code number for the current zone (zone.getLabel == label)
550
XMLZonesNodesList = self._case.xmlGetNodeList('zone', 'label', 'name')
548
XMLZonesNodesList = self._case.xmlGetNodeList('zone', 'label', 'id')
552
550
for node in XMLZonesNodesList:
553
codeList.append(node['name'])
551
codeList.append(node['id'])
559
557
Define a new Nature for the current zone (zone.getLabel == label)
562
node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'name', label = label)
560
node = self.__XMLVolumicConditionsNode.xmlGetChildNode('zone', 'id', label = label)
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)
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())
598
596
for k, v in newZone.getNature().items():
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
619
617
node['label'] = newLabel
620
618
node.xmlSetTextNode(newLocal)
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
644
642
node = self._case.xmlGetNode('zone', label=label)
647
645
node.xmlRemoveNode()
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
XMLZonesNodes = self.__XMLVolumicConditionsNode.xmlGetChildNodeList('zone', 'label', 'id')
656
for node in XMLZonesNodes:
657
nodeid = int(node['id'])
658
if nodeid > int(name):
659
node['id'] = str(nodeid-1)
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)
667
for tag in self._tagList:
668
for n in self.node_veloce.xmlGetNodeList('variable'):
669
node = n.xmlGetNode('initial_value')
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)
655
680
#-------------------------------------------------------------------------------
657
682
#-------------------------------------------------------------------------------