Exemplo n.º 1
0
def front_mesh_symmetric(res=0.025):
    """
    Creates a donut mesh with symmetry line through y = c_y
    """
    geometry = Geometry()
    mesh_r = width_scale*res
    c = geometry.add_point((c_x,c_y,0))
    
    # Elliptic obstacle
    p1 = geometry.add_point((c_x-r_x, c_y,0))
    p2 = geometry.add_point((c_x+r_x, c_y,0))
    # embed()
    arc_1 = geometry.add_circle_arc(p1, c, p2)
    arc_2 = geometry.add_circle_arc(p2, c, p1)

    # Surrounding mesh
    p3 = geometry.add_point((c_x-r_x-mesh_r, c_y,0))
    p4 = geometry.add_point((c_x+r_x+mesh_r, c_y,0))
    arc_5 = geometry.add_circle_arc(p3, c, p4)
    arc_6 = geometry.add_circle_arc(p4, c, p3)
    line_front = geometry.add_line(p3, p1)
    line_back = geometry.add_line(p2, p4)    
    surface_top = geometry.add_line_loop([line_front, arc_1, line_back, -arc_5])
    surface_bottom = geometry.add_line_loop([line_front, -arc_2, line_back,
                                             arc_6])

    obstacle_loop = geometry.add_line_loop([arc_1, arc_2])
    outer_loop = geometry.add_line_loop([arc_5,arc_6])
    
    top = geometry.add_plane_surface(surface_top)
    bottom = geometry.add_plane_surface(surface_bottom)
    geometry.add_physical_surface([top, bottom],label=12)
    geometry.add_physical_line(obstacle_loop.lines, label=inner_marker)
    geometry.add_physical_line(outer_loop.lines, label=outer_marker)

    # Create refined mesh around geometry
    field = geometry.add_boundary_layer(edges_list=obstacle_loop.lines,
                                        hfar=res, hwall_n=res/3,
                                        thickness=0.1*mesh_r)
    geometry.add_background_field([field])

    # Generate mesh
    (points, cells, point_data,
     cell_data, field_data) = generate_mesh(geometry, prune_z_0=True,
                                            geo_filename="meshes/test.geo")

    # Save mesh and mesh-function to file
    meshio.write("multimesh_1.xdmf", meshio.Mesh(
        points=points, cells={"triangle": cells["triangle"]}))
    
    meshio.write("mf_1.xdmf", meshio.Mesh(
        points=points, cells={"line": cells["line"]},
        cell_data={"line": {"name_to_read":
                            cell_data["line"]["gmsh:physical"]}}))
    import os
    os.system("mv multimesh_1.* meshes/")
    os.system("mv mf_1.* meshes/")
Exemplo n.º 2
0
def front_mesh_unsym(res=0.025):
    """
    Creates unsymmetric donut mesh
    """
    geometry = Geometry()
    mesh_r = width_scale*res
    c = geometry.add_point((c_x,c_y,0))
    
    # Elliptic obstacle
    p1 = geometry.add_point((c_x-r_x, c_y,0),lcar=res/2)
    p2 = geometry.add_point((c_x+r_x, c_y,0),lcar=res/2)

    arc_1 = geometry.add_circle_arc(p1, c, p2)
    arc_2 = geometry.add_circle_arc(p2, c, p1)

    # Surrounding mesh
    p3 = geometry.add_point((c_x-r_x-mesh_r, c_y,0),lcar=res)
    p4 = geometry.add_point((c_x+r_x+mesh_r, c_y,0),lcar=res)
    arc_5 = geometry.add_circle_arc(p3, c, p4)
    arc_6 = geometry.add_circle_arc(p4, c, p3)
    obstacle_loop = geometry.add_line_loop([arc_1, arc_2])
    outer_loop = geometry.add_line_loop([arc_5,arc_6])
    
    donut = geometry.add_plane_surface(obstacle_loop, holes=[outer_loop])
   
    geometry.add_physical_surface([donut],label=12)
    geometry.add_physical_line(obstacle_loop.lines, label=inner_marker)
    geometry.add_physical_line(outer_loop.lines, label=outer_marker)

    # Create refined mesh around geometry
    # field = geometry.add_boundary_layer(edges_list=obstacle_loop.lines,
    #                                     hfar=res, hwall_n=res/3,
    #                                     thickness=2*res)
    # geometry.add_background_field([field])

    # Generate mesh
    (points, cells, point_data,
     cell_data, field_data) = generate_mesh(geometry, prune_z_0=True,
                                            geo_filename="meshes/test.geo")

    # Save mesh and mesh-function to file
    meshio.write("meshes/multimesh_1.xdmf", meshio.Mesh(
        points=points, cells={"triangle": cells["triangle"]}))
    
    meshio.write("meshes/mf_1.xdmf", meshio.Mesh(
        points=points, cells={"line": cells["line"]},
        cell_data={"line": {"name_to_read":
                            cell_data["line"]["gmsh:physical"]}}))