def from_vertices_and_etov(vertices, etov, flip = False): vertex_objs = [] for v_idx in range(vertices.shape[0]): vertex_objs.append(Vertex((vertices[v_idx, 0], vertices[v_idx, 1]))) element_objs = [] for e_idx in range(etov.shape[0]): v0 = vertex_objs[etov[e_idx, 0]] v1 = vertex_objs[etov[e_idx, 1]] element_objs.append(Element(v0, v1)) if flip: element_objs = correct_misorientation(element_objs) m = Mesh(vertex_objs, element_objs) apply_mapping(m, PolynomialMapping) return m
def circular_mesh(n_elements, radius, mapping_gen = PolynomialMapping): n_vertices = n_elements t_list = np.linspace(0, 2 * np.pi, n_vertices + 1)[:-1] circle_func = lambda t: (radius * np.cos(t), radius * np.sin(t)) x_list, y_list = circle_func(t_list) vertices = [] for (x, y, t) in zip(x_list, y_list, t_list): vertices.append(Vertex(np.array((x, y)), t)) elements = [] for i in range(0, n_elements - 1): v0 = vertices[i] v1 = vertices[i + 1] elements.append(Element(v0, v1)) elements.append(Element(vertices[n_elements - 1], vertices[0])) m = Mesh(vertices, elements) apply_mapping(m, partial(mapping_gen, boundary_function = circle_func)) return m
def simple_line_mesh(n_elements, left_edge = (-1.0, 0.0), right_edge = (1.0, 0.0)): """ Create a mesh consisting of a line of elements starting at -1 and extending to +1 in x coordinate, y = 0. """ n_vertices = n_elements + 1 x_list = np.linspace(left_edge[0], right_edge[0], n_vertices) y_list = np.linspace(left_edge[1], right_edge[1], n_vertices) vertices = [] for (x, y) in zip(x_list, y_list): vertices.append(Vertex(np.array((x, y)), x)) elements = [] for i in range(0, n_elements): v0 = vertices[i] v1 = vertices[i + 1] elements.append(Element(v0, v1)) m = Mesh(vertices, elements) apply_mapping(m, PolynomialMapping) return m
def ray_mesh(start_point, direction, length, flip = False): """ Create a mesh starting at start_point and going in the direction specified with elements with a specified length. This is a obviously linear mesh, so there is no point in adding the necessary data to allow higher order mappings. This means that higher order mappings will fail. """ # Convert to numpy arrays so that users don't have to. start_point = np.array(start_point) direction = np.array(direction) # Normalize direction so the lengths stay true. direction /= np.linalg.norm(direction) vertices = [] vertices.append(Vertex(np.array(start_point))) sum_l = 0 for l in length: sum_l += l new_point = start_point + sum_l * direction vertices.append(Vertex(new_point)) if flip: vertices.reverse() elements = [] for i in range(0, len(length)): v0 = vertices[i] v1 = vertices[i + 1] # if flip: # v0, v1 = v1, v0 elements.append(Element(v0, v1)) # if flip: # elements.reverse() m = Mesh(vertices, elements) apply_mapping(m, PolynomialMapping) return m