1
1
"""calculation of mesh based features"""
2
+
2
3
from typing import Tuple , List , Any , Optional
3
4
4
5
import numpy as np
@@ -34,17 +35,21 @@ def _quad_to_tris(element_node_idxs: np.ndarray) -> Tuple[List[bool], np.ndarray
34
35
if len (element_node_idxs .shape ) == 3 : # points
35
36
is_quads = [any (element [3 ] != element [2 ]) for element in element_node_idxs ]
36
37
tri_faces_nested = [
37
- [element [:3 ].tolist (), element [[0 , 2 , 3 ]].tolist ()]
38
- if is_quad
39
- else [element [:3 ].tolist ()]
38
+ (
39
+ [element [:3 ].tolist (), element [[0 , 2 , 3 ]].tolist ()]
40
+ if is_quad
41
+ else [element [:3 ].tolist ()]
42
+ )
40
43
for is_quad , element in zip (is_quads , element_node_idxs )
41
44
]
42
45
else :
43
46
is_quads = [element [3 ] != element [2 ] for element in element_node_idxs ]
44
47
tri_faces_nested = [
45
- [element [:3 ].tolist (), element [[0 , 2 , 3 ]].tolist ()]
46
- if is_quad
47
- else [element [:3 ].tolist ()]
48
+ (
49
+ [element [:3 ].tolist (), element [[0 , 2 , 3 ]].tolist ()]
50
+ if is_quad
51
+ else [element [:3 ].tolist ()]
52
+ )
48
53
for is_quad , element in zip (is_quads , element_node_idxs )
49
54
]
50
55
tri_faces = np .array ([tri_face for tri_faces in tri_faces_nested for tri_face in tri_faces ])
@@ -125,10 +130,12 @@ def _make_ids_unique(
125
130
cumcounts = pd .DataFrame (array , columns = ["ids" ]).groupby ("ids" ).cumcount ().values
126
131
return np .array (
127
132
[
128
- old_id
129
- if postfix == 0
130
- else f"{ old_id } _{ point_uid [e [0 ]]} _{ point_uid [e [1 ]]} _"
131
- f"{ point_uid [e [2 ]]} _{ point_uid [e [3 ]]} "
133
+ (
134
+ old_id
135
+ if postfix == 0
136
+ else f"{ old_id } _{ point_uid [e [0 ]]} _{ point_uid [e [1 ]]} _"
137
+ f"{ point_uid [e [2 ]]} _{ point_uid [e [3 ]]} "
138
+ )
132
139
for old_id , e , postfix in zip (array , element_node_idxs , cumcounts )
133
140
]
134
141
)
@@ -252,6 +259,7 @@ def from_keyfile(keyfile: str, partid: str = "") -> "CaeShellMesh":
252
259
(6400, 3)
253
260
"""
254
261
262
+ # pylint: disable=too-many-branches, too-many-nested-blocks
255
263
def parse_contents (file_contents ):
256
264
lines = file_contents .split ("\n " )
257
265
current_section = ""
@@ -265,34 +273,46 @@ def parse_contents(file_contents):
265
273
for line in lines :
266
274
if line .startswith ("*" ):
267
275
current_section = line .split ()[0 ].upper ()
268
- current_section_options = set (current_section .split ('_' )[1 :])
276
+ current_section_options = set (current_section .split ("_" )[1 :])
269
277
current_section_lines_per_entry = 1
270
278
current_section_lineno = 0
271
279
continue
272
280
if line .startswith ("$" ): # comment
273
281
continue
274
282
if current_section == "*NODE" :
275
283
try :
276
- point_coordinates .append ([float (line [8 + i * 16 :8 + (i + 1 )* 16 ]) for i in range (3 )])
284
+ point_coordinates .append (
285
+ [float (line [8 + i * 16 : 8 + (i + 1 ) * 16 ]) for i in range (3 )]
286
+ )
277
287
pnt_ids .append (line [:8 ].strip ())
278
- except :
288
+ except [ ValueError , IndexError ] :
279
289
pass
280
290
elif current_section .startswith ("*ELEMENT_SHELL" ):
281
-
282
291
283
292
if current_section_lineno % current_section_lines_per_entry == 0 :
284
293
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" ]
294
+ node_ids = [
295
+ line [16 + i * 8 : 16 + (i + 1 ) * 8 ].strip () for i in range (8 )
296
+ ]
297
+ node_ids = [
298
+ node_id
299
+ for node_id in node_ids
300
+ if len (node_id ) > 0 and node_id != "0"
301
+ ]
302
+ # pylint: disable=fixme
287
303
# TODO: Check for unhandled options, e.g. COMPOSITE, DOF
288
304
if current_section_lineno == 0 :
289
305
if len (current_section_options & thickcard_options_set ) > 0 :
290
- current_section_lines_per_entry += 1 # skip thickness card
306
+ current_section_lines_per_entry += 1 # skip thickness card
291
307
if len (node_ids ) > 4 :
292
- current_section_lines_per_entry += 1 # skip additional thickness card for mid-side nodes
308
+ current_section_lines_per_entry += (
309
+ 1 # skip additional thickness card for mid-side nodes
310
+ )
293
311
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 ])
312
+ current_section_lines_per_entry += 1 # skip offset card
313
+ elem_node_ids .append (
314
+ [node_id for node_id in node_ids if len (node_id ) > 0 ]
315
+ )
296
316
if node_ids [0 ] == 1.0 :
297
317
print ("HERE" )
298
318
elem_ids .append (line [:8 ].strip ())
0 commit comments