gmshType.py 5.2 KB
Newer Older
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
1
# Marblesbag - Copyright (C) <2010-2018>
2
3
# <Universite catholique de Louvain (UCL), Belgium
#  Universite de Montpellier, France>
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
4
# 	
5
# List of the contributors to the development of Marblesbag: see AUTHORS file.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
6
7
8
# Description and complete License: see LICENSE file.
# 	
# This program (Marblesbag) is free software: 
9
# you can redistribute it and/or modify it under the terms of the GNU Lesser General 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
10
11
12
13
14
15
# Public License as published by the Free Software Foundation, either version
# 3 of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU Lesser General Public License for more details.
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
17
# 
18
19
# You should have received a copy of the GNU Lesser General Public License
# along with this program (see COPYING and COPYING.LESSER files).  If not, 
Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
20
21
# see <http://www.gnu.org/licenses/>.

Jonathan Lambrechts's avatar
Jonathan Lambrechts committed
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
class MshBaseElementType :
  def __init__(self, name, tag, dimension) :
    self.name = name
    self.tag = tag
    self.dimension = dimension
    self.mshType = [None] * 11
    self.mshTypeSerendip = [None] * 11

BaseType = [None]
Type = [None]

for t in [
  ('TYPE_PNT', 1, 0),
  ('TYPE_LIN', 2, 1),
  ('TYPE_TRI', 3, 2),
  ('TYPE_QUA', 4, 2),
  ('TYPE_TET', 5, 3),
  ('TYPE_PYR', 6, 3),
  ('TYPE_PRI', 7, 3),
  ('TYPE_HEX', 8, 3),
  ('TYPE_POLYG', 9, 2),
  ('TYPE_POLYH', 10, 3)
] :
  BaseType.append(MshBaseElementType(*t))
  globals()[t[0]] = BaseType[-1]

class MshElementType :
  def __init__(self, name, tag, numVertices, baseType, order, serendip) :
    self.name = name
    self.tag = tag
    self.numVertices = numVertices
    self.baseType = baseType
    self.order = order
    self.serendip = serendip

for i, t in enumerate([
  'MSH_LIN_2', 'MSH_TRI_3', 'MSH_QUA_4', 'MSH_TET_4', 'MSH_HEX_8',
  'MSH_PRI_6', 'MSH_PYR_5', 'MSH_LIN_3', 'MSH_TRI_6', 'MSH_QUA_9',
  'MSH_TET_10', 'MSH_HEX_27', 'MSH_PRI_18', 'MSH_PYR_14', 'MSH_PNT',
  'MSH_QUA_8', 'MSH_HEX_20', 'MSH_PRI_15', 'MSH_PYR_13', 'MSH_TRI_9',
  'MSH_TRI_10', 'MSH_TRI_12', 'MSH_TRI_15', 'MSH_TRI_15I', 'MSH_TRI_21',
  'MSH_LIN_4', 'MSH_LIN_5', 'MSH_LIN_6', 'MSH_TET_20', 'MSH_TET_35',
  'MSH_TET_56', 'MSH_TET_22', 'MSH_TET_28', 'MSH_POLYG_', 'MSH_POLYH_',
  'MSH_QUA_16', 'MSH_QUA_25', 'MSH_QUA_36', 'MSH_QUA_12', 'MSH_QUA_16I',
  'MSH_QUA_20', 'MSH_TRI_28', 'MSH_TRI_36', 'MSH_TRI_45', 'MSH_TRI_55',
  'MSH_TRI_66', 'MSH_QUA_49', 'MSH_QUA_64', 'MSH_QUA_81', 'MSH_QUA_100',
  'MSH_QUA_121', 'MSH_TRI_18', 'MSH_TRI_21I', 'MSH_TRI_24', 'MSH_TRI_27',
  'MSH_TRI_30', 'MSH_QUA_24', 'MSH_QUA_28', 'MSH_QUA_32', 'MSH_QUA_36I',
  'MSH_QUA_40', 'MSH_LIN_7', 'MSH_LIN_8', 'MSH_LIN_9', 'MSH_LIN_10',
  'MSH_LIN_11', 'MSH_LIN_B', 'MSH_TRI_B', 'MSH_POLYG_B', 'MSH_LIN_C',
  'MSH_TET_84', 'MSH_TET_120', 'MSH_TET_165', 'MSH_TET_220', 'MSH_TET_286',
  None, None, None, 'MSH_TET_34', 'MSH_TET_40',
  'MSH_TET_46', 'MSH_TET_52', 'MSH_TET_58', 'MSH_LIN_1', 'MSH_TRI_1',
  'MSH_QUA_1', 'MSH_TET_1', 'MSH_HEX_1', 'MSH_PRI_1', 'MSH_PRI_40',
  'MSH_PRI_75', 'MSH_HEX_64', 'MSH_HEX_125', 'MSH_HEX_216', 'MSH_HEX_343',
  'MSH_HEX_512', 'MSH_HEX_729', 'MSH_HEX_1000', 'MSH_HEX_32', 'MSH_HEX_44',
  'MSH_HEX_56', 'MSH_HEX_68', 'MSH_HEX_80', 'MSH_HEX_92', 'MSH_HEX_104',
  'MSH_PRI_126', 'MSH_PRI_196', 'MSH_PRI_288', 'MSH_PRI_405', 'MSH_PRI_550',
  'MSH_PRI_24', 'MSH_PRI_33', 'MSH_PRI_42', 'MSH_PRI_51', 'MSH_PRI_60',
  'MSH_PRI_69', 'MSH_PRI_78', 'MSH_PYR_30', 'MSH_PYR_55', 'MSH_PYR_91',
  'MSH_PYR_140', 'MSH_PYR_204', 'MSH_PYR_285', 'MSH_PYR_385', 'MSH_PYR_21',
  'MSH_PYR_29', 'MSH_PYR_37', 'MSH_PYR_45', 'MSH_PYR_53', 'MSH_PYR_61',
  'MSH_PYR_69', 'MSH_PYR_1', 'MSH_PNT_SUB', 'MSH_LIN_SUB', 'MSH_TRI_SUB',
  'MSH_TET_SUB', 'MSH_TET_16'
]) :
  if not t :
    Type.append(None)
    continue
  w = t.split("_")
  baseType = globals()["TYPE_"+w[1]]
  nnodes2order = {
    TYPE_LIN:(dict((o+1,o) for o in range(11)), {}),
    TYPE_TRI:(dict(((o+1) * (o+2) / 2,o) for o in range(11)), dict((3 * o,o) for o in range(11))),
    TYPE_QUA:(dict(((o+1) * (o+1),o) for o in range(11)), dict((4 * o,o) for o in range(11))),
    TYPE_TET:(dict(((o+1) * (o+2) * (o+3) / 6,o) for o in range(11)), dict((4 + 6 *  (o - 1), o) for o in range(11))),
    TYPE_HEX:(dict(((o+1) * (o+1) * (o+1),o) for o in range(11)), dict((8 + 12 * (o - 1), o) for o in range(11))),
    TYPE_PRI:(dict(((o+1) * (o+2) * (o+1)/2,o) for o in range(11)), dict((6 + 9 * (o - 1), o) for o in range(11))),
    TYPE_PYR:(dict(((o+1) * (o+2) * (2*o +3)/6, o) for o in range(11)), dict((5 + 8 * (o - 1),o) for o in range(11)))
  }
  try :
    numnodes = int(w[2].strip("I"))
  except:
    numnodes = 1 if baseType == TYPE_PNT else -1
  try :
    serendip = (w[2][-1] == 'I')
  except :
    serendip = False
  if numnodes == -1 :
    order = -1
  elif baseType == TYPE_PNT :
    order = 0
    serendip = False
  else:
    if (not serendip) and numnodes in nnodes2order[baseType][0] :
      order = nnodes2order[baseType][0][numnodes]
    else :
      order = nnodes2order[baseType][1][numnodes]
      serendip = True
  Type.append(MshElementType(t, i + 1, numnodes, baseType, order, serendip))
  if serendip :
    baseType.mshTypeSerendip[order] = Type[-1]
  else :
    baseType.mshType[order] = Type[-1]
  globals()[t] = Type[-1]