@@ -116,9 +116,6 @@ def add_cell(nastran_type, cell, cell_ref):
116
116
else :
117
117
break
118
118
119
- print ()
120
- print ()
121
- print (repr (next_line ))
122
119
while True :
123
120
# End loop when ENDDATA detected
124
121
if next_line .startswith ("ENDDATA" ):
@@ -131,7 +128,6 @@ def add_cell(nastran_type, cell, cell_ref):
131
128
chunks .append (c )
132
129
while True :
133
130
next_line = f .readline ()
134
- print (repr (next_line ))
135
131
136
132
if not next_line :
137
133
raise ReadError ("Premature EOF" )
@@ -147,56 +143,85 @@ def add_cell(nastran_type, cell, cell_ref):
147
143
# continuation identifier. A continuation identifier is a
148
144
# special character (+ or *) that indicates that the data
149
145
# continues on another line.
146
+ assert len (chunks [- 1 ]) <= 10
147
+ if len (chunks [- 1 ]) == 10 :
148
+ # This is a continuation line, so the 10th chunk of the
149
+ # previous line must also be a continuation indicator.
150
+ # Sometimes its first character is a `+`, but it's not
151
+ # always present. Anyway, cut it off.
152
+ chunks [- 1 ][- 1 ] = None
150
153
c , _ = _chunk_line (next_line )
151
- chunks .append (c [1 :])
154
+ c [0 ] = None
155
+ chunks .append (c )
152
156
153
157
elif len (chunks [- 1 ]) == 10 and chunks [- 1 ][- 1 ] == " " :
154
158
# automatic continuation: last chunk of previous line and first
155
159
# chunk of current line are spaces
156
160
c , _ = _chunk_line (next_line )
157
161
if c [0 ] == " " :
158
- chunks [- 1 ] = chunks [- 1 ][:9 ]
159
- chunks .append (c [1 :])
162
+ chunks [- 1 ][9 ] = None
163
+ c [0 ] = None
164
+ chunks .append (c )
160
165
else :
161
166
# not a continuation
162
167
break
163
168
else :
164
169
break
165
170
171
+ # merge chunks according to large field format
172
+ # large field format: 8 + 16 + 16 + 16 + 16 + 8
173
+ if chunks [0 ][0 ].startswith ("GRID*" ):
174
+ new_chunks = []
175
+ for c in chunks :
176
+ d = [c [0 ]]
177
+
178
+ if len (c ) > 1 :
179
+ d .append (c [1 ])
180
+ if len (c ) > 2 :
181
+ d [- 1 ] += c [2 ]
182
+
183
+ if len (c ) > 3 :
184
+ d .append (c [3 ])
185
+ if len (c ) > 4 :
186
+ d [- 1 ] += c [4 ]
187
+
188
+ if len (c ) > 5 :
189
+ d .append (c [5 ])
190
+ if len (c ) > 6 :
191
+ d [- 1 ] += c [6 ]
192
+
193
+ if len (c ) > 7 :
194
+ d .append (c [7 ])
195
+ if len (c ) > 8 :
196
+ d [- 1 ] += c [8 ]
197
+
198
+ if len (c ) > 9 :
199
+ d .append (c [9 ])
200
+
201
+ new_chunks .append (d )
202
+
203
+ chunks = new_chunks
204
+
166
205
# flatten
167
206
chunks = [item for sublist in chunks for item in sublist ]
168
207
208
+ # remove None (continuation blocks)
209
+ chunks = [chunk for chunk in chunks if chunk is not None ]
210
+
169
211
# strip chunks
170
212
chunks = [chunk .strip () for chunk in chunks ]
171
213
172
214
keyword = chunks [0 ]
173
215
174
- print (chunks )
175
-
176
216
# Points
177
- if keyword == "GRID" :
178
- # remove empty chunks
179
- chunks = [c for c in chunks if c != "" ]
217
+ if keyword in ["GRID" , "GRID*" ]:
180
218
point_id = int (chunks [1 ])
181
219
pref = chunks [2 ].strip ()
182
220
if len (pref ) > 0 :
183
221
point_refs .append (int (pref ))
184
222
points_id .append (point_id )
185
223
points .append ([_nastran_string_to_float (i ) for i in chunks [3 :6 ]])
186
224
187
- elif keyword == "GRID*" : # large field format: 8 + 16*4 + 8
188
- point_id = int (chunks [1 ] + chunks [2 ])
189
- pref = (chunks [3 ] + chunks [4 ]).strip ()
190
- if len (pref ) > 0 :
191
- point_refs .append (int (pref ))
192
- points_id .append (point_id )
193
- points .append (
194
- [
195
- _nastran_string_to_float (i + j )
196
- for i , j in [chunks [5 :7 ], chunks [7 :9 ], chunks [9 :11 ]]
197
- ]
198
- )
199
-
200
225
# CellBlock
201
226
elif keyword in nastran_to_meshio_type :
202
227
cell_id = int (chunks [1 ])
@@ -313,8 +338,6 @@ def write(filename, mesh, point_format="fixed-large", cell_format="fixed-small")
313
338
fx = [float_fmt (k ) for k in x ]
314
339
pref = str (point_refs [point_id ]) if point_refs is not None else ""
315
340
string = grid_fmt .format (point_id + 1 , pref , fx [0 ], fx [1 ], fx [2 ])
316
- print (point_id + 1 , repr (pref ), x , fx )
317
- print ("s" , repr (string ))
318
341
f .write (string )
319
342
320
343
# CellBlock
@@ -338,6 +361,7 @@ def write(filename, mesh, point_format="fixed-large", cell_format="fixed-small")
338
361
cell1 = cell + 1
339
362
cell1 = _convert_to_nastran_ordering (cell1 , nastran_type )
340
363
conn = sjoin .join (int_fmt .format (nid ) for nid in cell1 [:nipl1 ])
364
+
341
365
if len (cell1 ) > nipl1 :
342
366
if cell_format == "free" :
343
367
cflag1 = cflag3 = ""
0 commit comments