-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmesh.py
144 lines (116 loc) · 4.04 KB
/
smesh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from simphony.cuds import mesh as SMesh
from simphony.core import CUBA
from mupif import Mesh
from mupif import Vertex
from mupif import Cell
class SMesh (Mesh.Mesh):
"""
Mupif wrapper for Simphony Mesh class
"""
def __init__(self, smesh):
Mesh.__init__(self)
if isinstance(smesh, SMesh.Mesh):
self.smesh = smesh
else:
raise TypeError('smesh must be of type simphony mesh class')
# establish mappig between integer numbering and uuids
self._vertexUUIDMap = {}
self._cellUUIDMap = {}
i = 1
for point in self.smesh._iter_points():
self._vertexUUIDMap[i] = point.uid
i = i+1
# process cells (edges, faces, cells):
i = 1
for edge in self.smesh._iter_edges():
self._cellUUIDMap[i] = edge.uid
i = i+1
for face in self.smesh._iter_faces():
self._cellUUIDMap[i] = face.uid
i = i+1
for cell in self.smesh._iter_cells():
self._cellUUIDMap[i] = cell.uid
i = i+1
def getNumberOfVertices(self):
return self.smesh.count_of(CUBA.POINT)
def getNumberOfCells(self):
return (self.smesh.count_of(CUBA.EDGE)+
self.smesh.count_of(CUBA.FACE)+
self.smesh.count_of(CUBA.CELL))
def getVertex(self, i):
"""
The index here is uuid, not int -> check
Q: spoint.data -> metadata; how to map this to mupif?
Q: return copy or reference (wrapper class for Point)?
"""
spoint = self.smesh._get_point(self._vertexUUIDMap[i])
return Vertex.Vertex(i, i, coords=spoint.coordinates)
def getCell (self, i):
"""
The index here is uuid, not int -> check
"""
# need to deal with separate lists of edges, faces and cells on Simphony side
uuid = self._cellUUIDMap[i]
try:
edge = self.smesh._get_edge(uuid)
# no support for edges yet
cell = self._EdgeElement(len(edge.points)) (i, i, edge.points)
except KeyError:
cell = None
if (!cell):
try:
face = self.smesh._get_face(uuid)
cell = self._FaceElement(len(face.points)) (i, i, face.points)
except KeyError:
cell = None
if (!cell):
try:
scell = self.smesh._get_cell(uuid)
cell = self._CellElement(len(scell.points)) (i, i, scell.points)
except KeyError:
cell = None
if (cell):
return cell
else:
raise KeyError('cell id not found')
def giveVertexLocalizer(self):
return None
def giveCellLocalizer(self):
return None
def vertexLabel2Number(self, label):
pass
def cellLabel2Number(self, label):
pass
#
# protected methods
#
def _EdgeElement(self, nn):
"""
Return mupif cell class corresponding to edge with given number of nodes
:param:nvert number of nodes/vertices
"""
raise TypeError('unsupported number of vertices')
def _FaceElement(self, nn):
"""
Return mupif cell class corresponding to face with given number of nodes
:param:nvert number of nodes/vertices
"""
if (nn == 3):
return Cell.Triangle_2d_lin
else if (nn == 4):
return Cell.Quad_2d_lin
else if (nn == 6):
return Triangle_2d_quad
else:
raise TypeError('unsupported number of vertices')
def _CellElement(self, nn):
"""
Return mupif cell class corresponding to cell with given number of nodes
:param:nvert number of nodes/vertices
"""
if nn==4:
return Cell.Tetrahedron_3d_lin
else if nn==8:
return Cell.Brick_3d_lin
else:
raise TypeError('unsupported number of vertices')