def generate_disk_mesh(radius=1.0, theta_max=np.pi, nr=2, ntheta=4, center=(0, 0, 0), normal=(1, 0, 0), name=None) -> Mesh: theta_range = np.linspace(0, 2 * theta_max, ntheta + 1) r_range = np.linspace(0.0, radius, nr + 1) nodes = np.zeros(((ntheta + 1) * (nr + 1), 3), dtype=float) for i, (r, t) in enumerate(product(r_range, theta_range)): y = +r * np.sin(t) z = -r * np.cos(t) nodes[i, :] = (0, y, z) panels = np.zeros((ntheta * nr, 4), dtype=int) for k, (i, j) in enumerate(product(range(0, nr), range(0, ntheta))): panels[k, :] = (j + i * (ntheta + 1), j + 1 + i * (ntheta + 1), j + 1 + (i + 1) * (ntheta + 1), j + (i + 1) * (ntheta + 1)) mesh = Mesh(nodes, panels, name=name) mesh.merge_duplicates() mesh.heal_triangles() mesh.rotate_around_center_to_align_vectors( (0, 0, 0), mesh.faces_normals[0], normal) mesh.translate(center) return mesh
def generate_rectangle_mesh(width=1.0, height=1.0, nw=1, nh=1, center=(0, 0, 0), normal=(1, 0, 0), name=None): Y = np.linspace(-width / 2, width / 2, nw + 1) Z = np.linspace(-height / 2, height / 2, nh + 1) nodes = np.zeros(((nw + 1) * (nh + 1), 3), dtype=np.float) panels = np.zeros((nw * nh, 4), dtype=np.int) for i, (x, y, z) in enumerate(product([0.0], Y, Z)): nodes[i, :] = x, y, z for k, (i, j) in enumerate(product(range(0, nw), range(0, nh))): panels[k, :] = (j + i * (nh + 1), j + 1 + i * (nh + 1), j + 1 + (i + 1) * (nh + 1), j + (i + 1) * (nh + 1)) if name is None: name = f"rectangle_{next(Mesh._ids)}" mesh = Mesh(nodes, panels, name=f"{name}_mesh") mesh.rotate_around_center_to_align_vectors( (0, 0, 0), mesh.faces_normals[0], normal) mesh.translate(center) return mesh