domain.vertices # You could thus get a vertex by accessing the right position of the list, # like this (in order to get the first vertex that was added to the domain): v0 = domain.vertices[0] # However, using 'domain.vertices' requires that the list be fully created # every time the 'vertices' property of 'domain' is accessed. If the domain # contains a lot of vertices, this will be highly inefficient. # # Getting the list will be good if you want to iterate over all vertices, but # if you want to access only one vertex, use the 'get_vertex' method instead: v0 = domain.get_vertex(0) # Vertices are of type 'TriangularCartesian2D_Vertex' in this case, which # can be converted to the corresponding point type (in this case: # 'PointCartesian2D'). Once we have the point, we can get its coordinates: p = v0.to_point() p.coords # Create a segmentation of the domain segmentation = Segmentation(domain) # Create 2 segments in the segmentation of the domain seg0 = segmentation.make_segment()
domain.make_vertex(Point(1, 0)) # Vertex with ID #1 domain.make_vertex(Point(2, 0)) # Vertex with ID #2 domain.make_vertex(Point(2, 1)) # Vertex with ID #3 domain.make_vertex(Point(1, 1)) # Vertex with ID #4 domain.make_vertex(Point(0, 1)) # Vertex with ID #5 # Create a segmentation of the domain segmentation = Segmentation(domain) # Create 2 segments in the segmentation of the domain seg0 = segmentation.make_segment() seg1 = segmentation.make_segment() # Create 2 cells in the first segment. Since the domain is a triangular domain, # cells are triangles and three vertices must be specified to create a cell. seg0.make_cell(domain.get_vertex(0), domain.get_vertex(1), domain.get_vertex(5)) seg0.make_cell(domain.get_vertex(1), domain.get_vertex(4), domain.get_vertex(5)) # Create 2 cells in the second segment. This time, we will use variable to # make the code shorter. seg1.make_cell(domain.get_vertex(1), domain.get_vertex(2), domain.get_vertex(4)) seg1.make_cell(domain.get_vertex(3), domain.get_vertex(2), domain.get_vertex(4)) # Create a new accessor for the cells of the domain and save for each cell # its surface. cell_surface_accessor = CellAccessor() # For each cell of the domain, we calculate its surface and store the surface # of the cell using the accessor. To do that, we call the 'set_value' method # of the accessor specifying the cell and the value that we want to assign to # the cell.
p4 = Point(1, 1) p5 = Point(0, 1) domain.make_vertex(p0) # Vertex with ID #0 domain.make_vertex(p1) # Vertex with ID #1 domain.make_vertex(p2) # Vertex with ID #2 domain.make_vertex(p3) # Vertex with ID #3 domain.make_vertex(p4) # Vertex with ID #4 domain.make_vertex(p5) # Vertex with ID #5 segmentation = Segmentation(domain) seg0 = segmentation.make_segment() seg1 = segmentation.make_segment() cell_00 = seg0.make_cell(domain.get_vertex(0), domain.get_vertex(1), domain.get_vertex(5)) cell_01 = seg0.make_cell(domain.get_vertex(1), domain.get_vertex(4), domain.get_vertex(5)) cell_10 = seg1.make_cell(domain.get_vertex(1), domain.get_vertex(2), domain.get_vertex(4)) cell_11 = seg1.make_cell(domain.get_vertex(3), domain.get_vertex(2), domain.get_vertex(4)) #################################### # apply_voronoi #################################### apply_voronoi(domain) #################################### # cell_refine ####################################