Back to index

salome-med  6.5.0
testWriteAndFam.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 ###################################################################################
00025 # This Python script is testing the writing in Med format V2.1 V2.2
00026 # You can check if the analysis of the families is OK.
00027 ###################################################################################
00028 #
00029 from libMEDMEM_Swig import *
00030 import string
00031 import os
00032 #
00033 #befor running this script, please be sure about the path the files
00034 #
00035 filePath=os.environ["MED_ROOT_DIR"]
00036 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
00037 
00038 medFiles = []
00039 #medFiles.append("geomMesh21.med")
00040 medFiles.append("geomMesh22.med")
00041 nbOfFiles = len(medFiles)
00042 
00043 for i in range(nbOfFiles):
00044     medFile = medFiles[i]
00045     medFile = os.path.join( filePath, medFile )
00046     medFiles[i] = medFile
00047     pass
00048 
00049 meshName = "GeomMesh"
00050 
00051 for i in range(nbOfFiles):
00052     medFile = medFiles[i]
00053 
00054     rootFile = string.split(medFile,".")[0]
00055     medFileOut21 = rootFile + "Out21.med"
00056     medFileOut22 = rootFile + "Out22.med"
00057 
00058     print "Mounting in memory of the mesh ",meshName," from the file ",medFile
00059     mesh = MESH(MED_DRIVER,medFile,meshName)
00060     
00061     print ""
00062     print "Families analysis of the mesh ",meshName," from the file ",medFile
00063     print ""
00064 
00065     for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
00066         nbFam = mesh.getNumberOfFamilies(entity)
00067         if (entity == MED_NODE) & (nbFam > 0):
00068             print "This mesh has",nbFam,"Node Family(ies)"
00069             pass
00070         elif (entity == MED_CELL) & (nbFam > 0):
00071             print "This mesh has",nbFam,"Cell Family(ies)"
00072             pass
00073         elif (entity == MED_FACE) & (nbFam > 0):
00074             print "This mesh has",nbFam,"Face Family(ies)"
00075             pass
00076         elif (entity == MED_EDGE) & (nbFam > 0):
00077             print "This mesh has",nbFam,"Edge Family(ies)"
00078             pass
00079 
00080         if nbFam > 0:
00081             for j in range(nbFam):
00082                 print ""
00083                 family = mesh.getFamily(entity,j+1)
00084                 familyName = family.getName()
00085                 familyBool = family.isOnAllElements()
00086                 if (familyBool):
00087                     print "  -this famyly named ",familyName," is on all entities"
00088                     pass
00089                 else:
00090                     familyNumber = family.getNumber(MED_ALL_ELEMENTS)
00091                     print "  -this famyly named ",familyName," has ",len(familyNumber)," entities"
00092                     pass
00093                 pass
00094             pass
00095         pass
00096     
00097     print ""
00098     print "  adding a Med file V2.2 format driver to the mesh with the file ",medFileOut22
00099     idMedV22 = mesh.addDriver(MED_DRIVER,medFileOut22,mesh.getName())
00100 
00101     print ""
00102     print "  writing the mesh in Med file V2.2 format"
00103     mesh.write(idMedV22)
00104     print ""
00105     pass
00106 
00107 medFiles2 = []
00108 
00109 for i in range(nbOfFiles):
00110     medFile = medFiles[i]
00111     rootFile = string.split(medFile,".")[0]
00112     medFileOut22 = rootFile + "Out22.med"
00113 
00114     medFiles2.append(medFileOut22)
00115     pass
00116 
00117 nbOfFiles = len(medFiles2)
00118 
00119 for i in range(nbOfFiles):
00120     medFile = medFiles2[i]
00121     mesh = MESH(MED_DRIVER,medFile,meshName)
00122 
00123     print "Families analysis of the mesh ",meshName," from the file ",medFile
00124     print ""
00125     for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
00126         nbFam = mesh.getNumberOfFamilies(entity)
00127         if (entity == MED_NODE) & (nbFam > 0):
00128             print "This mesh has",nbFam,"Node Family(ies)"
00129             pass
00130         elif (entity == MED_CELL) & (nbFam > 0):
00131             print "This mesh has",nbFam,"Cell Family(ies)"
00132             pass
00133         elif (entity == MED_FACE) & (nbFam > 0):
00134             print "This mesh has",nbFam,"Face Family(ies)"
00135             pass
00136         elif (entity == MED_EDGE) & (nbFam > 0):
00137             print "This mesh has",nbFam,"Edge Family(ies)"
00138             pass
00139 
00140         if nbFam > 0:
00141             for j in range(nbFam):
00142                 print ""
00143                 family = mesh.getFamily(entity,j+1)
00144                 familyName = family.getName()
00145                 familyBool = family.isOnAllElements()
00146                 if (familyBool):
00147                     print "  -this famyly named ",familyName," is on all entities"
00148                     pass
00149                 else:
00150                     familyNumber = family.getNumber(MED_ALL_ELEMENTS)
00151                     print "  -this famyly named ",familyName," has ",len(familyNumber)," entities"
00152                     pass
00153                 pass
00154             pass
00155         pass
00156     pass
00157 
00158 print ""
00159 print "END of the Pyhton script ..... Ctrl D to exit"