Skip to content

Commit 91d9ec9

Browse files
authored
Merge pull request #10 from git47/master
modified: mesh2vec/mesh2vec_cae.py
2 parents 432f988 + 14c05f4 commit 91d9ec9

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

mesh2vec/mesh2vec_cae.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,15 @@ def from_d3plot_shell(
254254
return Mesh2VecCae(distance, mesh, element_info, calc_strategy=calc_strategy)
255255

256256
@staticmethod
257-
def from_keyfile_shell(distance: int, keyfile: Path, calc_strategy="bfs") -> "Mesh2VecCae":
257+
def from_keyfile_shell(distance: int, keyfile: Path, partid="", calc_strategy="bfs") -> "Mesh2VecCae":
258258
"""
259259
Read the given keyfile and use the shell elements to generate a hypergraph, using mesh
260260
nodes as hyperedges, and adjacent elements as hypervertices.
261261
262262
Args:
263263
distance: the maximum distance for neighborhood generation and feature aggregation
264264
keyfile: path to keyfile
265+
partid: part id to use for hypergraph generation (default empty string, use all shell parts)
265266
calc_strategy: choose the algorithm to calculate adjacencies
266267
267268
* "dfs": depth first search (defaultl fast)
@@ -275,7 +276,7 @@ def from_keyfile_shell(distance: int, keyfile: Path, calc_strategy="bfs") -> "Me
275276
>>> len(m2v._hyper_edges)
276277
6666
277278
"""
278-
mesh = CaeShellMesh.from_keyfile(keyfile)
279+
mesh = CaeShellMesh.from_keyfile(keyfile, partid)
279280
element_info = pd.DataFrame({"element_id": mesh.element_ids})
280281
element_info["file_path"] = str(keyfile)
281282
return Mesh2VecCae(distance, mesh, element_info, calc_strategy=calc_strategy)
@@ -347,7 +348,7 @@ def add_features_from_ansa(
347348

348349
for feature in features:
349350
if not feature in okay_ansa + okay_inplace:
350-
if not allow_additional_ansa_features:
351+
if allow_additional_ansa_features:
351352
okay_ansa.append(feature)
352353
else:
353354
raise ValueError(

mesh2vec/mesh_features.py

+38-23
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,15 @@ def from_ansa_json(elements: List[Any], nodes: List[Any]) -> "CaeShellMesh":
237237
return CaeShellMesh(point_coordinates, pnt_ids, elem_ids, elem_node_idxs)
238238

239239
@staticmethod
240-
def from_keyfile(keyfile: str) -> "CaeShellMesh":
240+
def from_keyfile(keyfile: str, partid: str = "") -> "CaeShellMesh":
241241
"""
242242
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:
244249
>>> from mesh2vec.mesh_features import CaeShellMesh
245250
>>> mesh = CaeShellMesh.from_keyfile("data/hat/Hatprofile.k")
246251
>>> print(mesh.point_coordinates.shape)
@@ -256,33 +261,43 @@ def parse_contents(file_contents):
256261

257262
elem_ids = []
258263
elem_node_ids = []
259-
264+
thickcard_options_set = set(["THICKNESS", "BETA", "MCID"])
260265
for line in lines:
261266
if line.startswith("*"):
262267
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
263271
continue
264-
if line.startswith("$#"): # comment
272+
if line.startswith("$"): # comment
265273
continue
266-
267274
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+
286301
pnt_idx = {pnt_id: i for i, pnt_id in enumerate(pnt_ids)}
287302

288303
elem_node_idx = np.array(

0 commit comments

Comments
 (0)