def createUniqueList(P1, P2, P3, tol=1e-5): ''' Create unique list of nodes Input: P1: Node 1 of triangle P2: Node 2 of triangle P3: Node 3 of triangle Output: unique_nodes: Unique list of nodes in structure conn: Elemental connectivity node_conn: Adjacency matrix ''' # Tolerance for uniqueness Xpts = np.vstack((P1, P2, P3)) loc = TMR.PointLocator(Xpts) node_nums = -np.ones(Xpts.shape[0], dtype='intc') # Locate the closest K points K = 20 index = np.zeros(K, dtype='intc') dist = np.zeros(K) unique_node = 0 for row in range(Xpts.shape[0]): if node_nums[row] < 0: # Locate the closest points and label them with # the same index loc.locateClosest(Xpts[row, :], index, dist) for k in range(K): if np.sqrt(dist[k]) < tol: node_nums[index[k]] = unique_node else: break # If we ordered one node, increment the counter if dist[0] < tol: unique_node += 1 # Create the unique list of nodes unique_nodes = np.zeros((unique_node, 3)) for row in range(Xpts.shape[0]): unique_nodes[node_nums[row], :] = Xpts[row, :] # Create the connectivity conn = np.zeros((P1.shape[0], 3), dtype='intc') for row in range(P1.shape[0]): conn[row, 0] = node_nums[row] conn[row, 1] = node_nums[row + P1.shape[0]] conn[row, 2] = node_nums[row + 2 * P1.shape[0]] # Return node connectivity (adjacency matrix) node_conn = [[] for x in range(unique_node)] # Loop over each triangle and add the connectivity for k in range(conn.shape[0]): u = conn[k, 0] v = conn[k, 1] w = conn[k, 2] if u < v: node_conn[u].append(v) if v < w: node_conn[v].append(w) if u < w: node_conn[u].append(w) return unique_nodes, conn, node_conn
# Compute the (approximate) area Area = 0.64 * xlen**2 # Set the bounds on the variables a = 0.4 * xlen + 1e-6 # Set the x/y locations of the density "nodes" n = 100 x = np.linspace(0, xlen, n) pts = [] for j in range(n): for i in range(n): if x[i] <= a or x[j] <= a: pts.append([x[i], x[j], 0.0]) locator = TMR.PointLocator(np.array(pts)) # Set the number of design variables num_design_vars = len(pts) # Load in the L-bracket model geo = TMR.LoadModel('2d-bracket-fillet.stp') verts = geo.getVertices() edges = geo.getEdges() faces = geo.getFaces() geo = TMR.Model(verts, edges, faces) # Set the edges edges[5].setName('clamped') edges[1].setName('traction')