Salome HOME
b11f0e9a1b6188f9467d802d3e395f660e75f393
[modules/med.git] / src / MEDMEM_SWIG / testWriteAndFam.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 ###################################################################################
25 # This Python script is testing the writing in Med format V2.1 V2.2
26 # You can check if the analysis of the families is OK.
27 ###################################################################################
28 #
29 from libMEDMEM_Swig import *
30 import string
31 import os
32 #
33 #befor running this script, please be sure about the path the files
34 #
35 filePath=os.environ["MED_ROOT_DIR"]
36 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
37
38 medFiles = []
39 #medFiles.append("geomMesh21.med")
40 medFiles.append("geomMesh22.med")
41 nbOfFiles = len(medFiles)
42
43 for i in range(nbOfFiles):
44     medFile = medFiles[i]
45     medFile = os.path.join( filePath, medFile )
46     medFiles[i] = medFile
47     pass
48
49 meshName = "GeomMesh"
50
51 for i in range(nbOfFiles):
52     medFile = medFiles[i]
53
54     rootFile = string.split(medFile,".")[0]
55     medFileOut21 = rootFile + "Out21.med"
56     medFileOut22 = rootFile + "Out22.med"
57
58     print "Mounting in memory of the mesh ",meshName," from the file ",medFile
59     mesh = MESH(MED_DRIVER,medFile,meshName)
60     
61     print ""
62     print "Families analysis of the mesh ",meshName," from the file ",medFile
63     print ""
64
65     for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
66         nbFam = mesh.getNumberOfFamilies(entity)
67         if (entity == MED_NODE) & (nbFam > 0):
68             print "This mesh has",nbFam,"Node Family(ies)"
69             pass
70         elif (entity == MED_CELL) & (nbFam > 0):
71             print "This mesh has",nbFam,"Cell Family(ies)"
72             pass
73         elif (entity == MED_FACE) & (nbFam > 0):
74             print "This mesh has",nbFam,"Face Family(ies)"
75             pass
76         elif (entity == MED_EDGE) & (nbFam > 0):
77             print "This mesh has",nbFam,"Edge Family(ies)"
78             pass
79
80         if nbFam > 0:
81             for j in range(nbFam):
82                 print ""
83                 family = mesh.getFamily(entity,j+1)
84                 familyName = family.getName()
85                 familyBool = family.isOnAllElements()
86                 if (familyBool):
87                     print "  -this famyly named ",familyName," is on all entities"
88                     pass
89                 else:
90                     familyNumber = family.getNumber(MED_ALL_ELEMENTS)
91                     print "  -this famyly named ",familyName," has ",len(familyNumber)," entities"
92                     pass
93                 pass
94             pass
95         pass
96     
97     print ""
98     print "  adding a Med file V2.2 format driver to the mesh with the file ",medFileOut22
99     idMedV22 = mesh.addDriver(MED_DRIVER,medFileOut22,mesh.getName())
100
101     print ""
102     print "  writing the mesh in Med file V2.2 format"
103     mesh.write(idMedV22)
104     print ""
105     pass
106
107 medFiles2 = []
108
109 for i in range(nbOfFiles):
110     medFile = medFiles[i]
111     rootFile = string.split(medFile,".")[0]
112     medFileOut22 = rootFile + "Out22.med"
113
114     medFiles2.append(medFileOut22)
115     pass
116
117 nbOfFiles = len(medFiles2)
118
119 for i in range(nbOfFiles):
120     medFile = medFiles2[i]
121     mesh = MESH(MED_DRIVER,medFile,meshName)
122
123     print "Families analysis of the mesh ",meshName," from the file ",medFile
124     print ""
125     for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
126         nbFam = mesh.getNumberOfFamilies(entity)
127         if (entity == MED_NODE) & (nbFam > 0):
128             print "This mesh has",nbFam,"Node Family(ies)"
129             pass
130         elif (entity == MED_CELL) & (nbFam > 0):
131             print "This mesh has",nbFam,"Cell Family(ies)"
132             pass
133         elif (entity == MED_FACE) & (nbFam > 0):
134             print "This mesh has",nbFam,"Face Family(ies)"
135             pass
136         elif (entity == MED_EDGE) & (nbFam > 0):
137             print "This mesh has",nbFam,"Edge Family(ies)"
138             pass
139
140         if nbFam > 0:
141             for j in range(nbFam):
142                 print ""
143                 family = mesh.getFamily(entity,j+1)
144                 familyName = family.getName()
145                 familyBool = family.isOnAllElements()
146                 if (familyBool):
147                     print "  -this famyly named ",familyName," is on all entities"
148                     pass
149                 else:
150                     familyNumber = family.getNumber(MED_ALL_ELEMENTS)
151                     print "  -this famyly named ",familyName," has ",len(familyNumber)," entities"
152                     pass
153                 pass
154             pass
155         pass
156     pass
157
158 print ""
159 print "END of the Pyhton script ..... Ctrl D to exit"