|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""wedge.py <out.su2> <angle deg> <ncirc> <nsect> <nr> <nz> [r0] |
| 3 | +3D pipe (radius 1, length 2, axis = z) made of nsect sectors of <angle> degrees with ncirc cells each in the |
| 4 | +circumferential direction. If nsect * angle = 360 the mesh is the full pipe (no periodic markers), otherwise the |
| 5 | +markers per1 (theta = 0) and per2 (theta = nsect * angle) are written. |
| 6 | +r0 = 0 (default): the mesh contains the axis (prisms at the axis, the axis nodes lie on both periodic markers); |
| 7 | +r0 > 0: annular mesh without axis nodes (marker hub at r = r0). |
| 8 | +Markers: per1, per2, inlet (z = 0), outlet (z = 2), wall (r = 1) [, hub]. |
| 9 | +Also writes <out.su2>.map with one line per node: node, j (circumferential index), i (radial index), k (axial |
| 10 | +index); axis nodes have j = 0, i = 0. Nodes with the same (j, i, k) are the same node in a sector and in the full pipe.""" |
| 11 | + |
| 12 | +import math |
| 13 | +import sys |
| 14 | + |
| 15 | +output = sys.argv[1] |
| 16 | +sector_angle = float(sys.argv[2]) |
| 17 | +circumferential_cells_per_sector = int(sys.argv[3]) |
| 18 | +sectors = int(sys.argv[4]) |
| 19 | +radial_cells = int(sys.argv[5]) |
| 20 | +axial_cells = int(sys.argv[6]) |
| 21 | +inner_radius = float(sys.argv[7]) if len(sys.argv) > 7 else 0.0 |
| 22 | +radius, length = 1.0, 2.0 |
| 23 | +circumferential_cells = circumferential_cells_per_sector * sectors |
| 24 | +full_pipe = abs(sectors * sector_angle - 360.0) < 1e-9 |
| 25 | +includes_axis = inner_radius == 0.0 |
| 26 | +points, node_indices = [], [] |
| 27 | + |
| 28 | + |
| 29 | +def add_point(x, y, z, j, i, k): |
| 30 | + points.append((x, y, z)) |
| 31 | + node_indices.append((j, i, k)) |
| 32 | + return len(points) - 1 |
| 33 | + |
| 34 | + |
| 35 | +# All circumferential node lines share a single axial line at r = 0. |
| 36 | +axis_nodes = [] |
| 37 | +if includes_axis: |
| 38 | + axis_nodes = [add_point(0.0, 0.0, length * k / axial_cells, 0, 0, k) |
| 39 | + for k in range(axial_cells + 1)] |
| 40 | +first_radial_index = 1 if includes_axis else 0 |
| 41 | +circumferential_node_lines = circumferential_cells if full_pipe else circumferential_cells + 1 |
| 42 | +node_ids = [[[None] * (axial_cells + 1) for _ in range(radial_cells + 1)] |
| 43 | + for _ in range(circumferential_node_lines)] |
| 44 | +for j in range(circumferential_node_lines): |
| 45 | + theta = math.radians(sector_angle) * j / circumferential_cells_per_sector |
| 46 | + for i in range(first_radial_index, radial_cells + 1): |
| 47 | + r = inner_radius + (radius - inner_radius) * i / radial_cells |
| 48 | + for k in range(axial_cells + 1): |
| 49 | + node_ids[j][i][k] = add_point(r * math.cos(theta), r * math.sin(theta), |
| 50 | + length * k / axial_cells, j, i, k) |
| 51 | + |
| 52 | +elements = [] |
| 53 | +markers = {"per1": [], "per2": [], "inlet": [], "outlet": [], "wall": []} |
| 54 | +if full_pipe: |
| 55 | + del markers["per1"], markers["per2"] |
| 56 | +if not includes_axis: |
| 57 | + markers["hub"] = [] |
| 58 | + |
| 59 | +# SU2 element types: triangle = 5, quadrilateral = 9, hexahedron = 12, prism = 13. |
| 60 | +for k in range(axial_cells): |
| 61 | + for j in range(circumferential_cells): |
| 62 | + # Wrap the last node line onto the first one only for the full pipe. |
| 63 | + left = node_ids[j] |
| 64 | + right = node_ids[(j + 1) % circumferential_node_lines] |
| 65 | + if includes_axis: |
| 66 | + elements.append((13, axis_nodes[k], left[1][k], right[1][k], |
| 67 | + axis_nodes[k + 1], left[1][k + 1], right[1][k + 1])) |
| 68 | + else: |
| 69 | + markers["hub"].append((9, left[0][k], right[0][k], right[0][k + 1], left[0][k + 1])) |
| 70 | + for i in range(first_radial_index, radial_cells): |
| 71 | + elements.append((12, left[i][k], left[i + 1][k], right[i + 1][k], right[i][k], |
| 72 | + left[i][k + 1], left[i + 1][k + 1], right[i + 1][k + 1], right[i][k + 1])) |
| 73 | + markers["wall"].append((9, left[radial_cells][k], right[radial_cells][k], |
| 74 | + right[radial_cells][k + 1], left[radial_cells][k + 1])) |
| 75 | + if not full_pipe: |
| 76 | + for j, marker in ((0, "per1"), (circumferential_cells, "per2")): |
| 77 | + nodes = node_ids[j] |
| 78 | + if includes_axis: |
| 79 | + markers[marker].append((9, axis_nodes[k], nodes[1][k], nodes[1][k + 1], axis_nodes[k + 1])) |
| 80 | + for i in range(first_radial_index, radial_cells): |
| 81 | + markers[marker].append((9, nodes[i][k], nodes[i + 1][k], nodes[i + 1][k + 1], nodes[i][k + 1])) |
| 82 | + |
| 83 | +for k, marker in ((0, "inlet"), (axial_cells, "outlet")): |
| 84 | + for j in range(circumferential_cells): |
| 85 | + left = node_ids[j] |
| 86 | + right = node_ids[(j + 1) % circumferential_node_lines] |
| 87 | + if includes_axis: |
| 88 | + markers[marker].append((5, axis_nodes[k], left[1][k], right[1][k])) |
| 89 | + for i in range(first_radial_index, radial_cells): |
| 90 | + markers[marker].append((9, left[i][k], left[i + 1][k], right[i + 1][k], right[i][k])) |
| 91 | + |
| 92 | +with open(output, "w") as mesh_file: |
| 93 | + mesh_file.write("NDIME= 3\nNELEM= %d\n" % len(elements)) |
| 94 | + for element_id, element in enumerate(elements): |
| 95 | + mesh_file.write(" ".join(map(str, element)) + " %d\n" % element_id) |
| 96 | + mesh_file.write("NPOIN= %d\n" % len(points)) |
| 97 | + for node_id, (x, y, z) in enumerate(points): |
| 98 | + mesh_file.write("%.17g %.17g %.17g %d\n" % (x, y, z, node_id)) |
| 99 | + mesh_file.write("NMARK= %d\n" % len(markers)) |
| 100 | + for marker, faces in markers.items(): |
| 101 | + mesh_file.write("MARKER_TAG= %s\nMARKER_ELEMS= %d\n" % (marker, len(faces))) |
| 102 | + for face in faces: |
| 103 | + mesh_file.write(" ".join(map(str, face)) + "\n") |
| 104 | + |
| 105 | +with open(output + ".map", "w") as map_file: |
| 106 | + for node_id, indices in enumerate(node_indices): |
| 107 | + map_file.write("%d %d %d %d\n" % ((node_id,) + indices)) |
| 108 | + |
| 109 | +print(output, "points", len(points), "elements", len(elements), "axis nodes", len(axis_nodes), |
| 110 | + "full" if full_pipe else "sector") |
0 commit comments