|
25 | 25 | # --------------------------------------------------------------------------- #
|
26 | 26 |
|
27 | 27 | 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. |
30 | 30 |
|
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 |
32 | 42 | mesh_from = Exodus(filename_from)
|
33 | 43 |
|
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 ### |
35 | 46 | num_elements = mesh_from.get_num_elems()
|
36 | 47 | connectivity_to = np.zeros((num_elements, 10), dtype=int)
|
37 | 48 | connectivity_from = mesh_from.get_elem_connectivity_full()[:]
|
38 | 49 | connectivity_to[:, :4] = connectivity_from
|
39 |
| - breakpoint() |
40 | 50 |
|
| 51 | + # Get coordinates of vertex nodes |
41 | 52 | coords_from = np.stack(mesh_from.get_coords()).T
|
42 | 53 | num_nodes_from = len(coords_from)
|
43 | 54 |
|
| 55 | + # Doing something, ns =14 and ss=6 |
44 | 56 | dims = mesh_from.dataset.dimensions
|
45 | 57 | num_ns = dims['num_ns_global'].size
|
46 | 58 | num_ss = dims['num_ss_global'].size
|
47 | 59 |
|
| 60 | + # Getting sides for the things above. it comes out to 242 for each instance |
| 61 | + # of ss |
48 | 62 | num_side_sss = [dims[f'num_side_ss{n}'].size for n in range(1, num_ss + 1)]
|
49 | 63 |
|
| 64 | + # Initiate dictionary that gives the node number for the mid-node of an |
| 65 | + # edge |
50 | 66 | pairs_elem_all = {}
|
| 67 | + |
| 68 | + # Initiate coordinates for tet10 mesh |
51 | 69 | coords_to = coords_from.tolist()
|
| 70 | + |
| 71 | + # Loop over the elements in the tet4 mesh |
52 | 72 | 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 |
54 | 81 | for idx_pair, pair in enumerate(pairs_elem):
|
| 82 | + |
| 83 | + # If the edge has already been considered, consult the dictionary |
55 | 84 | if pair in pairs_elem_all:
|
56 | 85 | id_node_new = pairs_elem_all[pair]
|
57 | 86 | else:
|
| 87 | + # Get the node number for the new node at the mid-point |
58 | 88 | id_node_new = num_nodes_from + len(pairs_elem_all) + 1
|
59 | 89 | 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 |
60 | 93 | idxs_old = [p - 1 for p in pair]
|
61 | 94 | coords_to.append(np.mean(coords_from[idxs_old, :], axis=0))
|
| 95 | + |
| 96 | + # Add this node to the connectivity of the tet10 mesh |
62 | 97 | connectivity_to[idx_elem, 4 + idx_pair] = id_node_new
|
63 | 98 |
|
64 | 99 | ids_node_set = mesh_from.get_node_set_ids()
|
|
0 commit comments