Back to index

salome-med  6.5.0
testMedAlliances1.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 import salome
00025 import SALOME
00026 import os
00027 
00028 filePath=os.environ["MED_ROOT_DIR"]
00029 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
00030 
00031 import string
00032 
00033 import SALOME_MED
00034 
00035 from libSALOME_Swig import *
00036 sg = SALOMEGUI_Swig()
00037 
00038 def print_ord(i):
00039     if i == 0:
00040         return 'first'
00041     elif i == 1:
00042         return 'second'
00043     elif i == 2:
00044         return 'third'
00045     else:
00046         return `(i+1)`+'th'
00047 
00048 def changeBlankToUnderScore(stringWithBlank):
00049     blank = ' '
00050     underscore = '_'
00051     decompString = string.split(stringWithBlank,blank)
00052     length = len(decompString)
00053     stringWithUnderScore = decompString[0]
00054     for i in range(1,length):
00055         stringWithUnderScore += underscore
00056         stringWithUnderScore += decompString[i]
00057     return stringWithUnderScore
00058 
00059 def getMedObjectFromStudy(file):
00060     objNameInStudy = "MED_OBJECT_FROM_FILE_"+file
00061     compNameInStudy= "MED"
00062     listOfSO = salome.myStudy.FindObjectByName(objNameInStudy,compNameInStudy)
00063     listLength = len(listOfSO)
00064     if (listLength == 0) :
00065         print objNameInStudy," cannot be found in the Study under the component ",compNameInStudy
00066         return None
00067     elif (listLength > 1) :
00068         print "there are more than one instance of ",objNameInStudy," in the Study under the component ",compNameInStudy
00069         return None
00070     mySO = listOfSO[0]
00071     if (mySO == None) :
00072         print objNameInStudy," cannot be found in the Study"
00073         return mySO
00074     else:
00075         anAttr = mySO.FindAttribute("AttributeIOR")[1]
00076         obj = salome.orb.string_to_object(anAttr.Value())
00077         myObj = obj._narrow(SALOME_MED.MED)
00078         if (myObj == None) :
00079             print objNameInStudy," has been found in the Study but with the wrong type"
00080         return myObj
00081 
00082 def getMeshObjectFromStudy(meshName):
00083     objNameInStudy = "/Med/MEDMESH/"+meshName
00084     mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
00085     if (mySO == None) :
00086         print objNameInStudy," cannot be found in the Study"
00087         return mySO
00088     else:
00089         anAttr = mySO.FindAttribute("AttributeIOR")[1]
00090         obj = salome.orb.string_to_object(anAttr.Value())
00091         myObj = obj._narrow(SALOME_MED.MESH)
00092         if (myObj == None) :
00093             print objNameInStudy," has been found in the Study but with the wrong type"
00094         return myObj
00095 
00096 def getSupportObjectFromStudy(meshName,supportName):
00097     meshNameStudy = changeBlankToUnderScore(meshName)
00098     objNameInStudy = "/Med/MEDMESH/MEDSUPPORTS_OF_"+meshNameStudy+"/"+supportName
00099     mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
00100     if (mySO == None) :
00101         print objNameInStudy," cannot be found in the Study"
00102         return mySO
00103     else:
00104         anAttr = mySO.FindAttribute("AttributeIOR")[1]
00105         obj = salome.orb.string_to_object(anAttr.Value())
00106         myObj = obj._narrow(SALOME_MED.SUPPORT)
00107         if (myObj == None) :
00108             print objNameInStudy," has been found in the Study but with the wrong type"
00109         return myObj
00110 
00111 def getFieldObjectFromStudy(dt,it,fieldName,supportName,meshName):
00112     meshNameStudy = changeBlankToUnderScore(meshName)
00113     objNameInStudy = "/Med/MEDFIELD/"+fieldName+"/("+str(dt)+","+str(it)+")_ON_"+supportName+"_OF_"+meshNameStudy
00114     mySO = salome.myStudy.FindObjectByPath(objNameInStudy)
00115     if (mySO == None) :
00116         print objNameInStudy," cannot be found in the Study"
00117         return mySO
00118     else:
00119         anAttr = mySO.FindAttribute("AttributeIOR")[1]
00120         obj = salome.orb.string_to_object(anAttr.Value())
00121         myObj = obj._narrow(SALOME_MED.FIELDINT)
00122         if (myObj == None):
00123             myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
00124             if (myObj == None) :
00125                 print objNameInStudy," has been found in the Study but with the wrong type"
00126         return myObj
00127 
00128 medFiles = []
00129 medFiles.append("ChampsDarcy.med")
00130 medFiles.append("darcy_1.1_res.med")
00131 medFiles.append("darcy_1.3_resCASTEM.med")
00132 medFiles.append("darcy_1.3_resPORFLOW.med")
00133 medFiles.append("darcy_1.3_resTRACES.med")
00134 medFiles.append("darcy2_Castem_EFMH.med")
00135 medFiles.append("darcy2_Castem_qua_EFMH.med")
00136 medFiles.append("darcy2_Castem_qua_VF.med")
00137 medFiles.append("Deff_fdt_5.8_castem_efmh_diff_conc_dom.med")
00138 medFiles.append("Deff_fdt_5.8_castem_vf_diff_conc_dom.med")
00139 medFiles.append("extendedtransport53_triangles.med")
00140 medFiles.append("H_CastCast_EFMH_I129_COUPLEX1.med")
00141 medFiles.append("H_CastCast_VF_I129_COUPLEX1.med")
00142 medFiles.append("H_CastCast_VF_Se79_COUPLEX1.med")
00143 medFiles.append("H_CastPorf_I129_COUPLEX1.med")
00144 medFiles.append("H_CastPorf_Se79_COUPLEX1.med")
00145 medFiles.append("H_PorfCast_EFMH_I129_COUPLEX1.med")
00146 medFiles.append("H_PorfCast_EFMH_Se79_COUPLEX1.med")
00147 medFiles.append("H_PorfPorf_I129_COUPLEX1.med")
00148 medFiles.append("H_Traces_I129_COUPLEX1.med")
00149 medFiles.append("H_Traces_Se79_COUPLEX1.med")
00150 medFiles.append("maillage_5_5_5.med")
00151 medFiles.append("maillage_chemvalIV_cas1_40elts.med")
00152 medFiles.append("Old_ChampsDarcy.med")
00153 medFiles.append("Old_darcy_1.1_res.med")
00154 medFiles.append("Old_darcy_1.3_resCASTEM.med")
00155 medFiles.append("Old_darcy_1.3_resPORFLOW.med")
00156 medFiles.append("Old_darcy_1.3_resTRACES.med")
00157 medFiles.append("Old_darcy2_Castem_EFMH.med")
00158 medFiles.append("Old_darcy2_Castem_qua_EFMH.med")
00159 medFiles.append("Old_darcy2_Castem_qua_VF.med")
00160 medFiles.append("Old_Deff_fdt_5.8_castem_efmh_diff_conc_dom.med")
00161 medFiles.append("Old_Deff_fdt_5.8_castem_vf_diff_conc_dom.med")
00162 medFiles.append("Old_H_CastCast_EFMH_I129_COUPLEX1.med")
00163 medFiles.append("Old_H_CastCast_VF_I129_COUPLEX1.med")
00164 medFiles.append("Old_H_CastCast_VF_Se79_COUPLEX1.med")
00165 medFiles.append("Old_H_CastPorf_I129_COUPLEX1.med")
00166 medFiles.append("Old_H_CastPorf_Se79_COUPLEX1.med")
00167 medFiles.append("Old_H_PorfCast_EFMH_I129_COUPLEX1.med")
00168 medFiles.append("Old_H_PorfCast_EFMH_Se79_COUPLEX1.med")
00169 medFiles.append("Old_H_PorfPorf_I129_COUPLEX1.med")
00170 medFiles.append("Old_H_PorfPorf_Se79_COUPLEX1.med")
00171 medFiles.append("Old_H_Traces_I129_COUPLEX1.med")
00172 medFiles.append("Old_H_Traces_Se79_COUPLEX1.med")
00173 medFiles.append("Old_maillage_chemvalIV_cas1_40elts.med")
00174 
00175 nbOfFiles = len(medFiles)
00176 
00177 med=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
00178 
00179 for i in range(nbOfFiles):
00180     medFile = medFiles[i]
00181     print "Testing with the file ",medFile
00182     medFile = os.path.join(filePath, medFile)
00183     med.readStructFileWithFieldType(medFile,salome.myStudyName)
00184 
00185 print "END of the Pyhton script ..... Ctrl D to exit"