Back to index

salome-med  6.5.0
MESHconnectivities.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 from libMEDMEM_Swig import *
00025 
00026 MedFile = "pointe.med"
00027 #MedFile = "carre_quad4_3.med"
00028 #MedFile = "polyedres.med"
00029 #MedFile = "polygones.med"
00030 meshName = "maa1"
00031 #meshName = "CARRE_EN_QUAD4"
00032 #meshName = "Erreur orientation"
00033 #meshName = "Bord"
00034 
00035 myMesh = MESH(MED_DRIVER,MedFile,meshName)
00036 myMesh.read()
00037 
00038 nameMesh = myMesh.getName()
00039 
00040 print "Mesh name : ",nameMesh
00041 
00042 numberOfTypes = myMesh.getNumberOfTypes(MED_CELL)
00043 print "Show Connectivity (Nodal) : "
00044 
00045 # This example use access with a specified medGeometryElement through
00046 # CELLMODEL class
00047 
00048 for i in range(numberOfTypes):
00049     cellType = myMesh.getCellType(MED_CELL,i)
00050     nameType = cellType.getName()
00051     type = cellType.getType()
00052     numberOfElements = myMesh.getNumberOfElements(MED_CELL,type)
00053     numberOfNodesPerCell = cellType.getNumberOfNodes()
00054     connectivity = myMesh.getConnectivity(MED_NODAL,MED_CELL,type)
00055     print "For Type ",nameType," : "
00056     for j in range(numberOfElements):
00057         print "Element ",(j+1)," : ",connectivity[j*numberOfNodesPerCell:
00058                                                   (j+1)*numberOfNodesPerCell]
00059 
00060 print "Show Reverse Nodal Connectivity :"
00061 
00062 # This example use global access with index array
00063 
00064 numberOfNodes = myMesh.getNumberOfNodes()
00065 
00066 reverseNodalConnectivity = myMesh.getReverseConnectivity(MED_NODAL)
00067 reverseNodalConnectivityIndex = myMesh.getReverseConnectivityIndex(MED_NODAL)
00068 
00069 for i in range(numberOfNodes):
00070     indexBegin = reverseNodalConnectivityIndex[i]
00071     indexEnd = reverseNodalConnectivityIndex[i+1]
00072 
00073     # Index value begin at 1 so (index-1) is in fact used here
00074 
00075     print "Node ",(i+1)," : ",reverseNodalConnectivity[(indexBegin-1):
00076                                                        (indexEnd-1)]
00077 
00078 print "Show Connectivity (Descending) :"
00079 
00080 # This example use global access with index array
00081 
00082 numberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00083 descendingConnectivity = myMesh.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS)
00084 descendingConnectivityIndex = myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL)
00085 
00086 for i in range(numberOfElements):
00087     indexBegin = descendingConnectivityIndex[i]
00088     indexEnd = descendingConnectivityIndex[i+1]
00089 
00090     # Index value begin at 1 so (index-1) is in fact used here
00091 
00092     print "Element ",(i+1)," : ",descendingConnectivity[(indexBegin-1):
00093                                                         (indexEnd-1)]
00094 
00095 print "Show Reverse Descending Connectivity :"
00096 
00097 # This example use global access with index array
00098 
00099 meshDimension = myMesh.getMeshDimension()
00100 
00101 if (meshDimension == 1):
00102     print "ERROR : Mesh Dimension = 1"
00103     print "Then the Reverse Descending Connectivity could not be seen"
00104 else:
00105     if (meshDimension == 2):
00106         constituent = "Edge"
00107         constituentEntity = MED_EDGE
00108 
00109     if (meshDimension == 3):
00110         constituent = "Face"
00111         constituentEntity = MED_FACE
00112 
00113     numberOfConstituents = myMesh.getNumberOfElements(constituentEntity,
00114                                                       MED_ALL_ELEMENTS)
00115     reverseDescendingConnectivity = myMesh.getReverseConnectivity(
00116         MED_DESCENDING)
00117     reverseDescendingConnectivityIndex = myMesh.getReverseConnectivityIndex(
00118         MED_DESCENDING)
00119 
00120     for i in range(numberOfConstituents):
00121         indexBegin = reverseDescendingConnectivityIndex[i]
00122         indexEnd = reverseDescendingConnectivityIndex[i+1]
00123 
00124         # Index value begin at 1 so (index-1) is in fact used here
00125 
00126         print constituent," : ",(i+1)," : ",reverseDescendingConnectivity[
00127             (indexBegin-1):(indexEnd-1)]
00128 
00129     print "Show ",constituent," Connectivity (Nodal) :"
00130 
00131     constituentConnectivity = myMesh.getConnectivity(MED_NODAL,constituentEntity,MED_ALL_ELEMENTS)
00132     constituentConnectivityIndex = myMesh.getConnectivityIndex(MED_NODAL,constituentEntity)
00133 
00134     for i in range(numberOfConstituents):
00135         indexBegin = constituentConnectivityIndex[i]
00136         indexEnd = constituentConnectivityIndex[i+1]
00137 
00138         # Index value begin at 1 so (index-1) is in fact used here
00139 
00140         print constituent," : ",(i+1)," : ",constituentConnectivity[
00141             (indexBegin-1):(indexEnd-1)]
00142         pass
00143     pass
00144