Salome HOME
MEDMEM suppression
[modules/med.git] / src / MED / testMedAlliances1.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 import salome
25 import SALOME
26 import os
27
28 filePath=os.environ["MED_ROOT_DIR"]
29 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
30
31 import string
32
33 import SALOME_MED
34
35 from libSALOME_Swig import *
36 sg = SALOMEGUI_Swig()
37
38 def print_ord(i):
39     if i == 0:
40         return 'first'
41     elif i == 1:
42         return 'second'
43     elif i == 2:
44         return 'third'
45     else:
46         return `(i+1)`+'th'
47
48 def changeBlankToUnderScore(stringWithBlank):
49     blank = ' '
50     underscore = '_'
51     decompString = string.split(stringWithBlank,blank)
52     length = len(decompString)
53     stringWithUnderScore = decompString[0]
54     for i in range(1,length):
55         stringWithUnderScore += underscore
56         stringWithUnderScore += decompString[i]
57     return stringWithUnderScore
58
59 def getMedObjectFromStudy(file):
60     objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
61     compNameInStudy= "MED"
62     listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
63     listLength = len(listOfSO)
64     if (listLength == 0) :
65         print objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
66         return None
67     elif (listLength > 1) :
68         print "there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
69         return None
70     mySO = listOfSO[0]
71     if (mySO == None) :
72         print objNameInStudy," cannot be found in the Study"
73         return mySO
74     else:
75         anAttr = mySO.FindAttribute("AttributeIOR")[1]
76         obj = salome.orb.string_to_object(anAttr.Value())
77         myObj = obj._narrow(SALOME_MED.MED)
78         if (myObj == None) :
79             print objNameInStudy," has been found in the Study but with the wrong type"
80         return myObj
81
82 def getMeshObjectFromStudy(meshName):
83     objNameInStudy = "/Med/MEDMESH/"+meshName
84     mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
85     if (mySO == None) :
86         print objNameInStudy," cannot be found in the Study"
87         return mySO
88     else:
89         anAttr = mySO.FindAttribute("AttributeIOR")[1]
90         obj = salome.orb.string_to_object(anAttr.Value())
91         myObj = obj._narrow(SALOME_MED.MESH)
92         if (myObj == None) :
93             print objNameInStudy," has been found in the Study but with the wrong type"
94         return myObj
95
96 def getSupportObjectFromStudy(meshName,supportName):
97     meshNameStudy = changeBlankToUnderScore(meshName)
98     objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy+"/"+supportName
99     mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
100     if (mySO == None) :
101         print objNameInStudy," cannot be found in the Study"
102         return mySO
103     else:
104         anAttr = mySO.FindAttribute("AttributeIOR")[1]
105         obj = salome.orb.string_to_object(anAttr.Value())
106         myObj = obj._narrow(SALOME_MED.SUPPORT)
107         if (myObj == None) :
108             print objNameInStudy," has been found in the Study but with the wrong type"
109         return myObj
110
111 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
112     meshNameStudy = changeBlankToUnderScore(meshName)
113     objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy
114     mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
115     if (mySO == None) :
116         print objNameInStudy," cannot be found in the Study"
117         return mySO
118     else:
119         anAttr = mySO.FindAttribute("AttributeIOR")[1]
120         obj = salome.orb.string_to_object(anAttr.Value())
121         myObj = obj._narrow(SALOME_MED.FIELDINT)
122         if (myObj == None):
123             myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
124             if (myObj == None) :
125                 print objNameInStudy," has been found in the Study but with the wrong type"
126         return myObj
127
128 medFiles = []
129 medFiles.append("ChampsDarcy.med")
130 medFiles.append("darcy_1.1_res.med")
131 medFiles.append("darcy_1.3_resCASTEM.med")
132 medFiles.append("darcy_1.3_resPORFLOW.med")
133 medFiles.append("darcy_1.3_resTRACES.med")
134 medFiles.append("darcy2_Castem_EFMH.med")
135 medFiles.append("darcy2_Castem_qua_EFMH.med")
136 medFiles.append("darcy2_Castem_qua_VF.med")
137 medFiles.append("Deff_fdt_5.8_castem_efmh_diff_conc_dom.med")
138 medFiles.append("Deff_fdt_5.8_castem_vf_diff_conc_dom.med")
139 medFiles.append("extendedtransport53_triangles.med")
140 medFiles.append("H_CastCast_EFMH_I129_COUPLEX1.med")
141 medFiles.append("H_CastCast_VF_I129_COUPLEX1.med")
142 medFiles.append("H_CastCast_VF_Se79_COUPLEX1.med")
143 medFiles.append("H_CastPorf_I129_COUPLEX1.med")
144 medFiles.append("H_CastPorf_Se79_COUPLEX1.med")
145 medFiles.append("H_PorfCast_EFMH_I129_COUPLEX1.med")
146 medFiles.append("H_PorfCast_EFMH_Se79_COUPLEX1.med")
147 medFiles.append("H_PorfPorf_I129_COUPLEX1.med")
148 medFiles.append("H_Traces_I129_COUPLEX1.med")
149 medFiles.append("H_Traces_Se79_COUPLEX1.med")
150 medFiles.append("maillage_5_5_5.med")
151 medFiles.append("maillage_chemvalIV_cas1_40elts.med")
152 medFiles.append("Old_ChampsDarcy.med")
153 medFiles.append("Old_darcy_1.1_res.med")
154 medFiles.append("Old_darcy_1.3_resCASTEM.med")
155 medFiles.append("Old_darcy_1.3_resPORFLOW.med")
156 medFiles.append("Old_darcy_1.3_resTRACES.med")
157 medFiles.append("Old_darcy2_Castem_EFMH.med")
158 medFiles.append("Old_darcy2_Castem_qua_EFMH.med")
159 medFiles.append("Old_darcy2_Castem_qua_VF.med")
160 medFiles.append("Old_Deff_fdt_5.8_castem_efmh_diff_conc_dom.med")
161 medFiles.append("Old_Deff_fdt_5.8_castem_vf_diff_conc_dom.med")
162 medFiles.append("Old_H_CastCast_EFMH_I129_COUPLEX1.med")
163 medFiles.append("Old_H_CastCast_VF_I129_COUPLEX1.med")
164 medFiles.append("Old_H_CastCast_VF_Se79_COUPLEX1.med")
165 medFiles.append("Old_H_CastPorf_I129_COUPLEX1.med")
166 medFiles.append("Old_H_CastPorf_Se79_COUPLEX1.med")
167 medFiles.append("Old_H_PorfCast_EFMH_I129_COUPLEX1.med")
168 medFiles.append("Old_H_PorfCast_EFMH_Se79_COUPLEX1.med")
169 medFiles.append("Old_H_PorfPorf_I129_COUPLEX1.med")
170 medFiles.append("Old_H_PorfPorf_Se79_COUPLEX1.med")
171 medFiles.append("Old_H_Traces_I129_COUPLEX1.med")
172 medFiles.append("Old_H_Traces_Se79_COUPLEX1.med")
173 medFiles.append("Old_maillage_chemvalIV_cas1_40elts.med")
174
175 nbOfFiles = len(medFiles)
176
177 med=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
178
179 for i in range(nbOfFiles):
180     medFile = medFiles[i]
181     print "Testing with the file ",medFile
182     medFile = os.path.join(filePath, medFile)
183     med.readStructFileWithFieldType(medFile,salome.myStudyName)
184
185 print "END of the Pyhton script ..... Ctrl D to exit"