Skip to content

Commit 235f642

Browse files
Fixed duplicate nodes on tet10 conversion and added associated test
1 parent 67ec599 commit 235f642

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

exodus_helper/reconfigure_mesh.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,75 @@
2525
# --------------------------------------------------------------------------- #
2626

2727
def convert_tet4_tet10(filename_from, filename_to=None, **kwargs):
28-
"""This converts a 4 node tetrahedral element to a 10 node tetrahedral
29-
element by placing additional nodes at the midpoint of every edge."""
28+
"""Convert a 4-node tetrahedral mesh into a 10-node tetrahedral mesh by
29+
adding mid-edge nodes to existing edges.
3030
31-
# Extract input mesh
31+
Args:
32+
filename_from (str): Name of a .g file created in association with a
33+
tet4 mesh.
34+
35+
filename_to (str): Name of the resultant .g file for the tet10 mesh.
36+
37+
Returns:
38+
mesh_to (): The converted mesh.
39+
"""
40+
41+
# Extract the tet4 mesh
3242
mesh_from = Exodus(filename_from)
3343

34-
# Get the old connectivity and use it to start the new connectivity
44+
# Initiate the tet10 connectivity from the tet4 connectivity.
45+
### NOTE: NODE NUMBERS IN SIERRA START AT 1 ###
3546
num_elements = mesh_from.get_num_elems()
3647
connectivity_to = np.zeros((num_elements, 10), dtype=int)
3748
connectivity_from = mesh_from.get_elem_connectivity_full()[:]
3849
connectivity_to[:, :4] = connectivity_from
39-
breakpoint()
4050

51+
# Get coordinates of vertex nodes
4152
coords_from = np.stack(mesh_from.get_coords()).T
4253
num_nodes_from = len(coords_from)
4354

55+
# Doing something, ns =14 and ss=6
4456
dims = mesh_from.dataset.dimensions
4557
num_ns = dims['num_ns_global'].size
4658
num_ss = dims['num_ss_global'].size
4759

60+
# Getting sides for the things above. it comes out to 242 for each instance
61+
# of ss
4862
num_side_sss = [dims[f'num_side_ss{n}'].size for n in range(1, num_ss + 1)]
4963

64+
# Initiate dictionary that gives the node number for the mid-node of an
65+
# edge
5066
pairs_elem_all = {}
67+
68+
# Initiate coordinates for tet10 mesh
5169
coords_to = coords_from.tolist()
70+
71+
# Loop over the elements in the tet4 mesh
5272
for idx_elem, ids_node in enumerate(connectivity_from):
53-
pairs_elem = [tuple(ids_node[i]) for i in IDXS_EDGES_4]
73+
74+
# Create the pairs of nodes which define an edge for this element. We
75+
# sort them in ascending order otherwise the logic-gate below results
76+
# in redundant nodes:
77+
pairs_elem = [tuple(sorted(sublist)) for sublist in
78+
[tuple(ids_node[i]) for i in IDXS_EDGES_4]]
79+
80+
# Loop over the edges of the element
5481
for idx_pair, pair in enumerate(pairs_elem):
82+
83+
# If the edge has already been considered, consult the dictionary
5584
if pair in pairs_elem_all:
5685
id_node_new = pairs_elem_all[pair]
5786
else:
87+
# Get the node number for the new node at the mid-point
5888
id_node_new = num_nodes_from + len(pairs_elem_all) + 1
5989
pairs_elem_all[pair] = id_node_new
90+
91+
# Get coordinates for new mid-edge node. Since sierra node
92+
# numbers start at one, subtract one for averaging
6093
idxs_old = [p - 1 for p in pair]
6194
coords_to.append(np.mean(coords_from[idxs_old, :], axis=0))
95+
96+
# Add this node to the connectivity of the tet10 mesh
6297
connectivity_to[idx_elem, 4 + idx_pair] = id_node_new
6398

6499
ids_node_set = mesh_from.get_node_set_ids()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = 'poetry.core.masonry.api'
44

55
[tool.poetry]
66
name = 'exodus_helper'
7-
version = '1.3.1'
7+
version = '1.3.2'
88
description = 'A package for manipulating ExodusII databases'
99
license = 'BSD-3-Clause'
1010
authors = ['Coleman Alleman <callema@sandia.gov>']

tests/test_exodus_helper.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,8 @@ def test_calculate_volumes_block(dir_test_file):
18211821

18221822
# Testing the reconfigure_mesh module --------------------------------------- #
18231823

1824-
def test_convert_tet4_tet10(dir_test_file):
1824+
def test_convert_tet4_tet10(dir_test_file, monkeypatch):
1825+
# monkeypatch.setattr('builtins.input', lambda _: 'y')
18251826
file_path = os.path.join(dir_test_file, 'test_convert_tet.g')
18261827
mesh_converted = exodus_helper.convert_tet4_tet10(file_path)
18271828
connectivity = mesh_converted.get_elem_connectivity_full()[:]
@@ -1832,6 +1833,15 @@ def test_convert_tet4_tet10(dir_test_file):
18321833
coords_1 = coords[ids_node[edge[1]] - 1]
18331834
coords_2 = coords[ids_node[idx + 4] - 1]
18341835
assert np.allclose(0.5 * (coords_0 + coords_1), coords_2)
1836+
mins = []
1837+
for idx_coords, coords_now in enumerate(coords[:-1]):
1838+
norms = np.linalg.norm(coords[idx_coords + 1:] - coords_now, axis=1)
1839+
mins.append(np.min(norms))
1840+
breakpoint()
1841+
assert not np.any(np.isclose(norms, 0))
1842+
1843+
print(np.min(mins))
1844+
18351845
os.remove(os.path.join(dir_test_file, 'test_convert_tet_tet10.g'))
18361846

18371847

0 commit comments

Comments
 (0)