def front_mesh(res=0.025):
    geometry = Geometry()
    c = geometry.add_point((c_x, c_y, 0))
    mesh_r = 5 * res  # Width of mesh

    # Elliptic obstacle
    p1 = geometry.add_point((c_x - r_x, c_y, 0))
    p2 = geometry.add_point((c_x, c_y + r_y, 0))
    p3 = geometry.add_point((c_x + r_x, c_y, 0))
    p4 = geometry.add_point((c_x, c_y - r_y, 0))
    arc_1 = geometry.add_ellipse_arc(p1, c, p2, p2)
    arc_2 = geometry.add_ellipse_arc(p2, c, p3, p3)
    arc_3 = geometry.add_ellipse_arc(p3, c, p4, p4)
    arc_4 = geometry.add_ellipse_arc(p4, c, p1, p1)
    obstacle_loop = geometry.add_line_loop([arc_1, arc_2, arc_3, arc_4])

    # Surrounding mesh
    p1 = geometry.add_point((c_x - r_x - mesh_r, c_y, 0))
    p2 = geometry.add_point((c_x, c_y + r_y + mesh_r, 0))
    p3 = geometry.add_point((c_x + r_x + mesh_r, c_y, 0))
    p4 = geometry.add_point((c_x, c_y - r_y - mesh_r, 0))
    arc_5 = geometry.add_ellipse_arc(p1, c, p2, p2)
    arc_6 = geometry.add_ellipse_arc(p2, c, p3, p3)
    arc_7 = geometry.add_ellipse_arc(p3, c, p4, p4)
    arc_8 = geometry.add_ellipse_arc(p4, c, p1, p1)
    loop = geometry.add_line_loop([arc_5, arc_6, arc_7, arc_8])
    mesh = geometry.add_plane_surface(loop, holes=[obstacle_loop])
    geometry.add_physical_surface(mesh, label=12)
    geometry.add_physical_line(loop.lines, label=outer_marker)
    geometry.add_physical_line(obstacle_loop.lines, label=inner_marker)

    # Create refined mesh around geometry
    field = geometry.add_boundary_layer(edges_list=obstacle_loop.lines,
                                        hfar=res,
                                        hwall_n=res / 2,
                                        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"]
                        }
                    }))
示例#2
0
def single_mesh(res=0.025):
    """ 
    Creates a single mesh containing a circular obstacle
    """

    geometry = Geometry()
    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, c_y + r_x, 0))
    p3 = geometry.add_point((c_x + r_x, c_y, 0))
    p4 = geometry.add_point((c_x, c_y - r_x, 0))
    arc_1 = geometry.add_ellipse_arc(p1, c, p2, p2)
    arc_2 = geometry.add_ellipse_arc(p2, c, p3, p3)
    arc_3 = geometry.add_ellipse_arc(p3, c, p4, p4)
    arc_4 = geometry.add_ellipse_arc(p4, c, p1, p1)
    obstacle_loop = geometry.add_line_loop([arc_1, arc_2, arc_3, arc_4])

    rectangle = geometry.add_rectangle(0,
                                       L,
                                       0,
                                       H,
                                       0,
                                       res,
                                       holes=[obstacle_loop])
    flow_list = [rectangle.line_loop.lines[3]]
    obstacle_list = obstacle_loop.lines
    walls_list = [rectangle.line_loop.lines[0], rectangle.line_loop.lines[2]]
    geometry.add_physical_surface(rectangle.surface, label=12)
    geometry.add_physical_line(flow_list, label=inflow)
    geometry.add_physical_line(walls_list, label=walls)
    geometry.add_physical_line([rectangle.line_loop.lines[1]], label=outflow)
    geometry.add_physical_line(obstacle_list, label=obstacle)
    field = geometry.add_boundary_layer(edges_list=obstacle_loop.lines,
                                        hfar=res,
                                        hwall_n=res / 8,
                                        thickness=res / 2)
    geometry.add_background_field([field])

    (points, cells, point_data, cell_data,
     field_data) = generate_mesh(geometry,
                                 prune_z_0=True,
                                 geo_filename="test.geo")

    meshio.write(
        "mesh.xdmf",
        meshio.Mesh(points=points, cells={"triangle": cells["triangle"]}))

    meshio.write(
        "mf.xdmf",
        meshio.Mesh(points=points,
                    cells={"line": cells["line"]},
                    cell_data={
                        "line": {
                            "name_to_read": cell_data["line"]["gmsh:physical"]
                        }
                    }))
示例#3
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/")
def single_mesh(res=0.025):
    """
    Create rectangular background mesh for the Poisson problem
    """
    geometry = Geometry()
    c = geometry.add_point((c_x, c_y, 0))
    mesh_r = 5 * res  # Width of mesh

    # Elliptic obstacle
    p1 = geometry.add_point((c_x - r_x, c_y, 0))
    p2 = geometry.add_point((c_x, c_y + r_y, 0))
    p3 = geometry.add_point((c_x + r_x, c_y, 0))
    p4 = geometry.add_point((c_x, c_y - r_y, 0))
    arc_1 = geometry.add_ellipse_arc(p1, c, p2, p2)
    arc_2 = geometry.add_ellipse_arc(p2, c, p3, p3)
    arc_3 = geometry.add_ellipse_arc(p3, c, p4, p4)
    arc_4 = geometry.add_ellipse_arc(p4, c, p1, p1)
    obstacle_loop = geometry.add_line_loop([arc_1, arc_2, arc_3, arc_4])

    # Surrounding mesh
    rectangle = geometry.add_rectangle(0,
                                       L,
                                       0,
                                       H,
                                       0,
                                       res,
                                       holes=[obstacle_loop])
    geometry.add_physical_surface(rectangle.surface, label=12)
    geometry.add_physical_line(obstacle_loop.lines, label=inner_marker)
    geometry.add_physical_line(rectangle.line_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 / 2,
                                        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_single.geo")

    # Save mesh and mesh-function to file
    meshio.write(
        "meshes/singlemesh.xdmf",
        meshio.Mesh(points=points, cells={"triangle": cells["triangle"]}))

    meshio.write(
        "meshes/mf.xdmf",
        meshio.Mesh(points=points,
                    cells={"line": cells["line"]},
                    cell_data={
                        "line": {
                            "name_to_read": cell_data["line"]["gmsh:physical"]
                        }
                    }))
示例#5
0
def single_mesh(res=0.025):
    geometry = Geometry()
    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, c_y + r_y, 0))
    p3 = geometry.add_point((c_x + r_x, c_y, 0))
    p4 = geometry.add_point((c_x, c_y - r_y, 0))
    arc_1 = geometry.add_ellipse_arc(p1, c, p2, p2)
    arc_2 = geometry.add_ellipse_arc(p2, c, p3, p3)
    arc_3 = geometry.add_ellipse_arc(p3, c, p4, p4)
    arc_4 = geometry.add_ellipse_arc(p4, c, p1, p1)
    obstacle_loop = geometry.add_line_loop([arc_1, arc_2, arc_3, arc_4])

    rectangle = geometry.add_rectangle(0,
                                       L,
                                       0,
                                       H,
                                       0,
                                       res,
                                       holes=[obstacle_loop])

    geometry.add_physical_surface(rectangle.surface, label=12)
    geometry.add_physical_line(obstacle_loop.lines, label=inner_marker)
    geometry.add_physical_line(rectangle.line_loop.lines, label=outer_marker)
    field = geometry.add_boundary_layer(edges_list=obstacle_loop.lines,
                                        hfar=res,
                                        hwall_n=res / 2,
                                        thickness=2 * res)
    geometry.add_background_field([field])

    (points, cells, point_data, cell_data,
     field_data) = generate_mesh(geometry, prune_z_0=True)

    meshio.write(
        "meshes/singlemesh.xdmf",
        meshio.Mesh(points=points, cells={"triangle": cells["triangle"]}))

    meshio.write(
        "meshes/mf.xdmf",
        meshio.Mesh(points=points,
                    cells={"line": cells["line"]},
                    cell_data={
                        "line": {
                            "name_to_read": cell_data["line"]["gmsh:physical"]
                        }
                    }))
示例#6
0
def front_mesh(res=0.025):
    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))
    p12 = geometry.add_point((c_x, c_y + 1.4 * r_x, 0))
    p21 = geometry.add_point((c_x, c_y - 1.4 * r_x, 0))

    arc_1 = geometry.add_spline([p1, p12, p2])
    arc_2 = geometry.add_spline([p2, p21, p1])
    # 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))
    p34 = geometry.add_point((c_x, c_y + 1.4 * r_x + mesh_r, 0))
    p43 = geometry.add_point((c_x, c_y - 1.4 * r_x - mesh_r, 0))
    arc_5 = geometry.add_spline([p3, p34, p4])
    arc_6 = geometry.add_spline([p4, p43, p3])

    # 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])

    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)

    # 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"]
                        }
                    }))