def background_mesh(res=0.025):
    """
    Create rectangular background mesh for the Poisson problem
    """
    geometry = Geometry()
    rectangle = geometry.add_rectangle(0, L, 0, H, 0, res)

    geometry.add_physical_surface(rectangle.surface, label=12)
    geometry.add_physical_line(rectangle.line_loop.lines, label=outer_marker)

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

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

    meshio.write(
        "meshes/mf_0.xdmf",
        meshio.Mesh(points=points,
                    cells={"line": cells["line"]},
                    cell_data={
                        "line": {
                            "name_to_read": cell_data["line"]["gmsh:physical"]
                        }
                    }))
Esempio n. 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"]
                        }
                    }))
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"]
                        }
                    }))
Esempio n. 4
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"]
                        }
                    }))
Esempio n. 5
0
def background_mesh(res=0.025):
    """
    Create rectangular background mesh for the Poisson problem
    """
    geometry = Geometry()
    # r_bottom = geometry.add_rectangle(0,L,0,H/2,0, res)
    # r_top = geometry.add_rectangle(0,L,H/2,H,0, res)
    square = geometry.add_rectangle(0, L, 0, H, 0, res)
    geometry.add_physical_surface([square.surface], label=12)
    geometry.add_physical_line([square.line_loop.lines[3]], label=inflow)
    geometry.add_physical_line([square.line_loop.lines[1]], label=outflow)
    geometry.add_physical_line(
        [square.line_loop.lines[0], square.line_loop.lines[2]], label=walls)

    # geometry.add_physical_surface([r_bottom.surface,
    #                                r_top.surface],label=12)
    # in_lines = [r_bottom.line_loop.lines[3],r_top.line_loop.lines[3]]
    # geometry.add_physical_line(in_lines, label=inflow)
    # out_lines = [r_bottom.line_loop.lines[1],r_top.line_loop.lines[1]]
    # geometry.add_physical_line(out_lines, label=outflow)
    # wall_lines = [r_bottom.line_loop.lines[0],r_top.line_loop.lines[2]]
    # geometry.add_physical_line(wall_lines, label=walls)

    (points, cells, point_data, cell_data,
     field_data) = generate_mesh(geometry,
                                 prune_z_0=True,
                                 geo_filename="meshes/tmp.geo")
    meshio.write(
        "meshes/multimesh_0.xdmf",
        meshio.Mesh(points=points, cells={"triangle": cells["triangle"]}))

    meshio.write(
        "meshes/mf_0.xdmf",
        meshio.Mesh(points=points,
                    cells={"line": cells["line"]},
                    cell_data={
                        "line": {
                            "name_to_read": cell_data["line"]["gmsh:physical"]
                        }
                    }))
Esempio n. 6
0
def background_mesh(res=0.025):
    """
    Create rectangular background mesh for the Poisson problem
    """
    geometry = Geometry()
    square = geometry.add_rectangle(0,L,0,H,0, 5*res)
    geometry.add_physical_surface([square.surface],label=12)
    geometry.add_physical_line([square.line_loop.lines[3]], label=inflow)
    geometry.add_physical_line([square.line_loop.lines[1]], label=outflow)
    geometry.add_physical_line([square.line_loop.lines[0],
                                square.line_loop.lines[2]], label=walls)
    p_c = geometry.add_point((c_x,c_y,0),lcar=0.1*res)
    geometry.add_raw_code(["Field[1]=Attractor;",
                           "Field[1].NodesList={{ {} }};".format(p_c.id),
                           "Field[2]=Threshold;",
                           "Field[2].IField=1;",
                           "Field[2].LcMin={};".format(res),
                           "Field[2].LcMax={};".format(5*res),
                           "Field[2].DistMin={};".format(2*r_x),
                           "Field[2].DistMax={};".format(4*r_x),
                           "Field[3]=Min;",
                           "Field[3].FieldsList = {2};",
                           "Background Field = 3;"])
    (points, cells, point_data,
     cell_data, field_data) = generate_mesh(geometry, prune_z_0=True,dim=2,
                                            geo_filename="meshes/tmp.geo")
    meshio.write("multimesh_0.xdmf", meshio.Mesh(
        points=points, cells={"triangle": cells["triangle"]}))
    
    meshio.write("mf_0.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_0.* meshes/")
    os.system("mv mf_0.* meshes/")