@@ -237,10 +237,15 @@ def from_ansa_json(elements: List[Any], nodes: List[Any]) -> "CaeShellMesh":
237
237
return CaeShellMesh (point_coordinates , pnt_ids , elem_ids , elem_node_idxs )
238
238
239
239
@staticmethod
240
- def from_keyfile (keyfile : str ) -> "CaeShellMesh" :
240
+ def from_keyfile (keyfile : str , partid : str = "" ) -> "CaeShellMesh" :
241
241
"""
242
242
create CaeShellMesh from keyfile
243
- Example:
243
+
244
+ Args:
245
+ keyfile: path to LSDYNA keyfile in fixed column format
246
+ partid: part id to use for hypergraph generation
247
+
248
+ Example:
244
249
>>> from mesh2vec.mesh_features import CaeShellMesh
245
250
>>> mesh = CaeShellMesh.from_keyfile("data/hat/Hatprofile.k")
246
251
>>> print(mesh.point_coordinates.shape)
@@ -256,33 +261,43 @@ def parse_contents(file_contents):
256
261
257
262
elem_ids = []
258
263
elem_node_ids = []
259
-
264
+ thickcard_options_set = set ([ "THICKNESS" , "BETA" , "MCID" ])
260
265
for line in lines :
261
266
if line .startswith ("*" ):
262
267
current_section = line .split ()[0 ].upper ()
268
+ current_section_options = set (current_section .split ('_' )[1 :])
269
+ current_section_lines_per_entry = 1
270
+ current_section_lineno = 0
263
271
continue
264
- if line .startswith ("$# " ): # comment
272
+ if line .startswith ("$" ): # comment
265
273
continue
266
-
267
274
if current_section == "*NODE" :
268
- data = line .split ()
269
- if data :
270
- point_coordinates .append ([float (data [1 ]), float (data [2 ]), float (data [3 ])])
271
- pnt_ids .append (data [0 ])
272
-
273
- elif "*ELEMENT_SHELL" in current_section :
274
- data = line .split ()
275
- if data :
276
- # check for floats - floats are a hint of options like THICKNESS
277
- if (
278
- not data [2 ].isdigit ()
279
- or not data [3 ].isdigit ()
280
- or not data [4 ].isdigit ()
281
- or not data [5 ].isdigit ()
282
- ):
283
- continue
284
- elem_node_ids .append ([data [2 ], data [3 ], data [4 ], data [5 ]])
285
- elem_ids .append (data [0 ])
275
+ try :
276
+ point_coordinates .append ([float (line [8 + i * 16 :8 + (i + 1 )* 16 ]) for i in range (3 )])
277
+ pnt_ids .append (line [:8 ].strip ())
278
+ except :
279
+ pass
280
+ elif current_section .startswith ("*ELEMENT_SHELL" ):
281
+
282
+
283
+ if current_section_lineno % current_section_lines_per_entry == 0 :
284
+ if partid == "" or partid == line [8 :16 ].strip ():
285
+ node_ids = [line [16 + i * 8 :16 + (i + 1 )* 8 ].strip () for i in range (8 )]
286
+ node_ids = [node_id for node_id in node_ids if len (node_id ) > 0 and node_id != "0" ]
287
+ # TODO: Check for unhandled options, e.g. COMPOSITE, DOF
288
+ if current_section_lineno == 0 :
289
+ if len (current_section_options & thickcard_options_set ) > 0 :
290
+ current_section_lines_per_entry += 1 # skip thickness card
291
+ if len (node_ids ) > 4 :
292
+ current_section_lines_per_entry += 1 # skip additional thickness card for mid-side nodes
293
+ if "OFFSET" in current_section_options :
294
+ current_section_lines_per_entry += 1 # skip offset card
295
+ elem_node_ids .append ([node_id for node_id in node_ids if len (node_id ) > 0 ])
296
+ if node_ids [0 ] == 1.0 :
297
+ print ("HERE" )
298
+ elem_ids .append (line [:8 ].strip ())
299
+ current_section_lineno += 1
300
+
286
301
pnt_idx = {pnt_id : i for i , pnt_id in enumerate (pnt_ids )}
287
302
288
303
elem_node_idx = np .array (
0 commit comments