def method(res=50, diameter=1., length=5., **kwargs):
    '''
    Function That Generates a mesh for a barbell capilar,
    Meshing method is mshr.

    Note: The generarted mesh is stored in "BERNAISE/meshes/".
    '''
    info("Generating mesh using the mshr tool.")

    inletdiameter = diameter * 5.
    inletlength = diameter * 4.

    # Define coners of "capilar"
    a = df.Point(-diameter / 2., -length / 2 - inletlength / 2.)
    b = df.Point(diameter / 2., length / 2 + inletlength / 2.)
    capilar = mshr.Rectangle(a, b)
    # Define coners of "leftbell
    c = df.Point(-inletdiameter / 2., -length / 2 - inletlength)
    d = df.Point(inletdiameter / 2., -length / 2)
    leftbell = mshr.Rectangle(c, d)
    # Define coners of "rightbell"
    e = df.Point(-inletdiameter / 2., length / 2)
    f = df.Point(inletdiameter / 2., length / 2 + inletlength)
    rightbell = mshr.Rectangle(e, f)

    domain = capilar + leftbell + rightbell
    mesh = mshr.generate_mesh(domain, res)
    meshpath = os.path.join(
        MESHES_DIR, "BarbellCapilarDolfin_d" + str(diameter) + "_l" +
        str(length) + "_res" + str(res))
    store_mesh_HDF5(mesh, meshpath)
示例#2
0
def method(Lx=1.,
           Ly=1.,
           scale=0.75,
           dx=0.02,
           show=False,
           polygon="flipper",
           center=(0.5, 0.5),
           **kwargs):
    edges = np.loadtxt(os.path.join(MESHES_DIR, polygon + ".edges"),
                       dtype=int).tolist()
    nodes = np.loadtxt(os.path.join(MESHES_DIR, polygon + ".nodes"))

    nodes[:, 0] -= 0.5 * np.max(nodes[:, 0])
    nodes[:, 1] -= 0.5 * np.max(nodes[:, 1])
    nodes[:, :] *= scale
    nodes[:, 0] += center[0] * Lx
    nodes[:, 1] += center[1] * Ly

    nodes = nodes.tolist()

    x_min, x_max = 0., Lx
    y_min, y_max = 0., Ly

    corner_pts = [(x_min, y_min), (x_max, y_min), (x_max, y_max),
                  (x_min, y_max)]

    outer_nodes, outer_edges = make_polygon(corner_pts, dx, len(nodes))
    nodes.extend(outer_nodes)
    edges.extend(outer_edges)

    if show:
        plot_edges(nodes, edges)

    mi = tri.MeshInfo()
    mi.set_points(nodes)
    mi.set_facets(edges)
    mi.set_holes([(center[0] * Lx, center[1] * Ly)])

    max_area = 0.5 * dx**2

    mesh = tri.build(mi,
                     max_volume=max_area,
                     min_angle=25,
                     allow_boundary_steiner=False)

    coords = np.array(mesh.points)
    faces = np.array(mesh.elements)

    if show:
        plot_faces(coords, faces)

    mesh = numpy_to_dolfin(coords, faces)

    if show:
        df.plot(mesh)
        plt.show()

    mesh_path = os.path.join(MESHES_DIR,
                             "{}_dx{}_Lx{}_Ly{}".format(polygon, dx, Lx, Ly))
    store_mesh_HDF5(mesh, mesh_path)
示例#3
0
def method(Lx=4.,
           Ly=4.,
           rad=0.2,
           R=0.3,
           N=24,
           n_segments=40,
           res=80,
           do_plot=False,
           **kwargs):
    """ Porous mesh. Not really done or useful. """
    info("Generating porous mesh")

    # x = np.random.rand(N, 2)

    diam2 = 4 * R**2

    pts = np.zeros((N, 2))
    for i in range(N):
        while True:
            pt = (np.random.rand(2) - 0.5) * np.array([Lx - 2 * R, Ly - 2 * R])
            if i == 0:
                break
            dist = pts[:i, :] - np.outer(np.ones(i), pt)
            dist2 = dist[:, 0]**2 + dist[:, 1]**2
            if all(dist2 > diam2):
                break
        pts[i, :] = pt

    rect = mshr.Rectangle(df.Point(-Lx / 2, -Ly / 2), df.Point(Lx / 2, Ly / 2))
    domain = rect
    for i in range(N):
        domain -= mshr.Circle(df.Point(pts[i, 0], pts[i, 1]),
                              rad,
                              segments=n_segments)

    mesh = mshr.generate_mesh(domain, res)

    store_mesh_HDF5(
        mesh,
        os.path.join(
            MESHES_DIR,
            "porous_Lx{Lx}_Ly{Ly}_rad{rad}_R{R}_N{N}_res{res}.h5".format(
                Lx=Lx, Ly=Ly, rad=rad, R=R, N=N, res=res)))

    if do_plot:
        df.plot(mesh)
        df.interactive()
示例#4
0
def method(L=3., H=1., R=0.3, n_segments=40, res=60, show=False, **kwargs):
    """
    Generates mesh of Snausen/Snoevsen.
    """
    info("Generating mesh of Snoevsen.")

    # Define points:
    pt_A = df.Point(0., 0.)
    pt_B = df.Point(L, H)
    pt_C = df.Point(L / 2 - 2 * R, 0.)
    pt_D = df.Point(L / 2 + 2 * R, 0.)
    pt_E = df.Point(L / 2 - 2 * R, -R)
    pt_F = df.Point(L / 2 + 2 * R, -R)
    pt_G = df.Point(L / 2, -R)

    tube = mshr.Rectangle(pt_A, pt_B)
    add_rect = mshr.Rectangle(pt_E, pt_D)
    neg_circ_L = mshr.Circle(pt_E, R, segments=n_segments)
    neg_circ_R = mshr.Circle(pt_F, R, segments=n_segments)
    pos_circ = mshr.Circle(pt_G, R, segments=n_segments)

    domain = tube + add_rect - neg_circ_L - neg_circ_R + pos_circ

    mesh = mshr.generate_mesh(domain, res)

    # check that mesh is periodic along x
    boun = df.BoundaryMesh(mesh, "exterior")
    y = boun.coordinates()[:, 1]
    y = y[y < 1.]
    y = y[y > 0.]
    n_y = len(y)
    n_y_unique = len(np.unique(y))

    assert (n_y == 2 * n_y_unique)

    mesh_path = os.path.join(MESHES_DIR, "snoevsen_res" + str(res))
    store_mesh_HDF5(mesh, mesh_path)

    if show:
        df.plot(mesh, "Mesh")
        plt.show()
示例#5
0
def method(res=10, height=1, length=5, use_mshr=False, show=False, **kwargs):
    '''
    Function that generates a mesh for a straight capillary, default
    meshing method is Dolfin's RectangleMesh, but there is an option for
    mshr.

    Note: The generated mesh is stored in "BERNAISE/meshes/".

    '''
    if use_mshr:  # use mshr for the generation
        info("Generating mesh using the mshr tool")
        # Define coners of Rectangle
        a = df.Point(0, 0)
        b = df.Point(height, length)
        domain = mshr.Rectangle(a, b)
        mesh = mshr.generate_mesh(domain, res)
        meshpath = os.path.join(
            MESHES_DIR, "straight_capillary_mshr_h{}_l{}_res{}".format(
                height, length, res))
        info("Done.")
    else:  # use the Dolfin built-in function
        info("Generating mesh using the Dolfin built-in function.")
        # Define coners of rectangle/capilar
        a = df.Point(0, 0)
        b = df.Point(height, length)
        # Setting the reselution
        if height <= length:
            num_points_height = res
            num_points_length = res * int(length / height)
        else:
            num_points_height = res * int(height / length)
            num_points_length = res
        mesh = df.RectangleMesh(a, b, num_points_height, num_points_length)
        meshpath = os.path.join(
            MESHES_DIR, "straight_capillary_dolfin_h{}_l{}_res{}".format(
                height, length, res))
    store_mesh_HDF5(mesh, meshpath)

    if show:
        df.plot(mesh)
        plt.show()
def method(res=10, height=1, length=5, use_mshr=False, **kwargs):
    '''
    Function that generates a mesh for a straight capilar, default
    meshing method is dolfin's "RectangleMesh" but has an option for
    mshr.

    Note: The generated mesh is stored in "BERNAISE/meshes/".

    '''
    if use_mshr:  # use mshr for the generation
        info("Generating mesh using the mshr tool")
        # Define coners of Rectangle
        a = df.Point(0, 0)
        b = df.Point(height, length)
        domain = mshr.Rectangle(a, b)
        mesh = mshr.generate_mesh(domain, res)
        meshpath = os.path.join(
            MESHES_DIR, "StraightCapilarMshr_h" + str(height) + "_l" +
            str(length) + "_res" + str(res))
        info("Done.")
    else:  # use the Dolfin built-in function
        info("Generating mesh using the Dolfin built-in function.")
        # Define coners of rectangle/capilar
        a = df.Point(0, 0)
        b = df.Point(height, length)
        # Setting the reselution
        if height <= length:
            num_points_height = res
            num_points_length = res * int(length / height)
        else:
            num_points_height = res * int(height / length)
            num_points_length = res
        mesh = df.RectangleMesh(a, b, num_points_height, num_points_length)
        meshpath = os.path.join(
            MESHES_DIR, "StraightCapilarDolfin_h" + str(height) + "_l" +
            str(length) + "_res" + str(res))
    store_mesh_HDF5(mesh, meshpath)
def method(res=96, H=0.41, L=2.2, x=0.2, y=0.2, r=0.05,
           segments=100, show=False, **kwargs):
    '''
    Generates mesh for the 'Flow around cylinder' benchmark:

    http://www.featflow.de/en/benchmarks/cfdbenchmarking/flow.html

    Note: The generated mesh is stored in "BERNAISE/meshes/".
    '''
    info("Generating mesh using the mshr tool.")

    rect = mshr.Rectangle(df.Point(0, 0), df.Point(L, H))
    cyl = mshr.Circle(df.Point(x, y), r, segments=segments)
    domain = rect - cyl
    mesh = mshr.generate_mesh(domain, res)
    meshpath = os.path.join(
        MESHES_DIR,
        "cylinderinchannel_H{}_L{}_x{}_y{}_r{}_res{}".format(
            H, L, x, y, r, res))
    store_mesh_HDF5(mesh, meshpath)

    if show:
        df.plot(mesh)
        plt.show()
def method(Lx=6.,
           Ly=4.,
           Lx_inner=4.,
           num_obstacles=32,
           rad=0.2,
           R=0.3,
           dx=0.05,
           seed=121,
           do_plot=True,
           **kwargs):
    N = int(np.ceil(Lx / dx))

    x_min, x_max = -Lx / 2, Lx / 2
    y_min, y_max = -Ly / 2, Ly / 2

    y = np.linspace(y_min, y_max, N).flatten()

    pts = np.zeros((num_obstacles, 2))
    diam2 = 4 * R**2

    np.random.seed(seed)

    for i in range(num_obstacles):
        while True:
            pt = (np.random.rand(2) - 0.5) * np.array([Lx_inner, Ly])
            if i == 0:
                break
            dist = pts[:i, :] - np.outer(np.ones(i), pt)
            for j in range(len(dist)):
                if abs(dist[j, 1]) > Ly / 2:
                    dist[j, 1] = abs(dist[j, 1]) - Ly
            dist2 = dist[:, 0]**2 + dist[:, 1]**2
            if all(dist2 > diam2):
                break
        pts[i, :] = pt

    pts = pts[pts[:, 0].argsort(), :]

    obstacles = [tuple(row) for row in pts]

    line_segments_top = []
    line_segments_btm = []

    x_prev = x_min

    curve_segments_top = []
    curve_segments_btm = []

    interior_obstacles = []
    exterior_obstacles = []

    for x_c in obstacles:
        # Close to the top of the domain
        if x_c[1] > y_max - rad:
            # identify intersection
            theta = np.arcsin((y_max - x_c[1]) / rad)
            rx = rad * np.cos(theta)
            x_left = x_c[0] - rx
            x_right = x_c[0] + rx

            line_segments_top.append(
                line_points((x_prev, y_max), (x_left, y_max), dx))
            line_segments_btm.append(
                line_points((x_prev, y_min), (x_left, y_min), dx))
            curve_btm = rad_points((x_c[0], x_c[1] - Ly),
                                   rad,
                                   dx,
                                   theta_start=np.pi - theta,
                                   theta_stop=theta)[1:-1]
            curve_top = rad_points(x_c,
                                   rad,
                                   dx,
                                   theta_start=np.pi - theta,
                                   theta_stop=2 * np.pi + theta)[1:-1]
            curve_segments_btm.append(curve_btm)
            curve_segments_top.append(curve_top)

            x_prev = x_right

            exterior_obstacles.append(x_c)
            exterior_obstacles.append((x_c[0], x_c[1] - Ly))
        # Close to the bottom of the domain
        elif x_c[1] < y_min + rad:
            # identify intersection
            theta = np.arcsin((-y_min + x_c[1]) / rad)
            rx = rad * np.cos(theta)
            x_left = x_c[0] - rx
            x_right = x_c[0] + rx

            line_segments_top.append(
                line_points((x_prev, y_max), (x_left, y_max), dx))
            line_segments_btm.append(
                line_points((x_prev, y_min), (x_left, y_min), dx))
            curve_btm = rad_points(x_c,
                                   rad,
                                   dx,
                                   theta_start=np.pi + theta,
                                   theta_stop=-theta)[1:-1]
            curve_top = rad_points((x_c[0], x_c[1] + Ly),
                                   rad,
                                   dx,
                                   theta_start=np.pi + theta,
                                   theta_stop=2 * np.pi - theta)[1:-1]
            curve_segments_btm.append(curve_btm)
            curve_segments_top.append(curve_top)

            x_prev = x_right

            exterior_obstacles.append(x_c)
            exterior_obstacles.append((x_c[0], x_c[1] + Ly))
        else:
            interior_obstacles.append(x_c)

    line_segments_top.append(line_points((x_prev, y_max), (x_max, y_max), dx))
    line_segments_btm.append(line_points((x_prev, y_min), (x_max, y_min), dx))

    assert (len(line_segments_top) == len(curve_segments_top) + 1)
    assert (len(line_segments_btm) == len(curve_segments_btm) + 1)

    pts_top = line_segments_top[0]
    for i in range(len(curve_segments_top)):
        pts_top.extend(curve_segments_top[i])
        pts_top.extend(line_segments_top[i + 1])
    pts_top = pts_top[::-1]

    pts_btm = line_segments_btm[0]
    for i in range(len(curve_segments_btm)):
        pts_btm.extend(curve_segments_btm[i])
        pts_btm.extend(line_segments_btm[i + 1])

    y_side = y[1:-1]
    pts_right = zip(x_max * np.ones(N - 2), y_side)
    pts_left = zip(x_min * np.ones(N - 2), y_side[::-1])

    pts = pts_btm + pts_right + pts_top + pts_left
    edges = round_trip_connect(0, len(pts) - 1)

    for interior_obstacle in interior_obstacles:
        pts_obstacle = rad_points(interior_obstacle, rad, dx)[1:]
        edges_obstacle = round_trip_connect(len(pts),
                                            len(pts) + len(pts_obstacle) - 1)

        pts.extend(pts_obstacle)
        edges.extend(edges_obstacle)

    if do_plot:
        plot_edges(pts, edges)

    mi = tri.MeshInfo()
    mi.set_points(pts)
    mi.set_facets(edges)
    mi.set_holes(interior_obstacles)

    max_area = 0.5 * dx**2

    mesh = tri.build(mi,
                     max_volume=max_area,
                     min_angle=25,
                     allow_boundary_steiner=False)

    coords = np.array(mesh.points)
    faces = np.array(mesh.elements)

    # pp = [tuple(point) for point in mesh.points]
    # print "Number of points:", len(pp)
    # print "Number unique points:", len(set(pp))

    if do_plot:
        plot_faces(coords, faces)

    msh = numpy_to_dolfin(coords, faces)

    mesh_path = os.path.join(
        MESHES_DIR, "periodic_porous_Lx{}_Ly{}_rad{}_N{}_dx{}".format(
            Lx, Ly, rad, num_obstacles, dx))
    store_mesh_HDF5(msh, mesh_path)

    obstacles_path = os.path.join(
        MESHES_DIR, "periodic_porous_Lx{}_Ly{}_rad{}_N{}_dx{}.dat".format(
            Lx, Ly, rad, num_obstacles, dx))

    all_obstacles = np.vstack(
        (np.array(exterior_obstacles), np.array(interior_obstacles)))
    np.savetxt(
        obstacles_path,
        np.hstack((all_obstacles, np.ones((len(all_obstacles), 1)) * rad)))

    if do_plot:
        df.plot(msh)
        df.interactive()
示例#9
0
def method(Lx=4.,
           Ly=4.,
           num_obstacles=25,
           rad=0.25,
           R=0.3,
           dx=0.05,
           seed=123,
           show=False,
           **kwargs):
    x_min, x_max = -Lx / 2, Lx / 2
    y_min, y_max = -Ly / 2, Ly / 2

    np.random.seed(seed)
    obstacles = place_obstacles(num_obstacles, Lx, Ly, R)
    obstacles = correct_obstacles(obstacles, rad, x_min, x_max, y_min, y_max)

    interior_obstacles, exterior_obstacles, obst = classify_obstacles(
        obstacles, rad, x_min, x_max, y_min, y_max)

    theta_low, theta_high = compute_intersections(obst, rad, x_min, x_max,
                                                  y_min, y_max)

    curves = draw_curves(obst, theta_low, theta_high, rad, dx)
    if len(curves) > 0:
        curve_start, curve_stop = get_curve_intersection_points(
            curves, x_min, x_max, y_min, y_max)

        segments = construct_segments(curve_start, curve_stop, x_min, x_max,
                                      y_min, y_max)
        pt_start = curves[0][0]
    else:
        curve_start = []
        curve_stop = []
        segments = [((x_min, y_min), (x_max, y_min)),
                    ((x_max, y_min), (x_max, y_max)),
                    ((x_max, y_max), (x_min, y_max)),
                    ((x_min, y_max), (x_min, y_min))]
        segments = dict(segments)
        pt_start = (x_min, y_min)

    if show:
        for x_a, x_b in segments.items():
            x = np.array([x_a[0], x_b[0]])
            y = np.array([x_a[1], x_b[1]])
            plt.quiver(x[:-1],
                       y[:-1],
                       x[1:] - x[:-1],
                       y[1:] - y[:-1],
                       scale_units='xy',
                       angles='xy',
                       scale=1)
        for curve in curves:
            x = np.array(curve)
            plt.quiver(x[:-1, 0],
                       x[:-1, 1],
                       x[1:, 0] - x[:-1, 0],
                       x[1:, 1] - x[:-1, 1],
                       scale_units='xy',
                       angles='xy',
                       scale=1)

    pts = discretize_loop(pt_start, curve_start, curves, segments, dx)[::-1]

    plt.show()

    edges = round_trip_connect(0, len(pts) - 1)

    for interior_obstacle in interior_obstacles:
        pts_obstacle = rad_points(interior_obstacle, rad, dx)[1:]
        edges_obstacle = round_trip_connect(len(pts),
                                            len(pts) + len(pts_obstacle) - 1)

        pts.extend(pts_obstacle)
        edges.extend(edges_obstacle)

    if show:
        plot_edges(pts, edges)

    mi = tri.MeshInfo()
    mi.set_points(pts)
    mi.set_facets(edges)
    mi.set_holes(interior_obstacles)

    max_area = 0.5 * dx**2

    mesh = tri.build(mi,
                     max_volume=max_area,
                     min_angle=25,
                     allow_boundary_steiner=False)

    coords = np.array(mesh.points)
    faces = np.array(mesh.elements)

    pp = [tuple(point) for point in mesh.points]
    info("Number of points:     {}".format(len(pp)))
    info("Number unique points: {}".format(len(set(pp))))

    if show:
        plot_faces(coords, faces)

    msh = numpy_to_dolfin(coords, faces)

    mesh_path = os.path.join(
        MESHES_DIR, "periodic_porous_Lx{}_Ly{}_rad{}_N{}_dx{}".format(
            Lx, Ly, rad, num_obstacles, dx))
    store_mesh_HDF5(msh, mesh_path)

    obstacles_path = os.path.join(
        MESHES_DIR, "periodic_porous_Lx{}_Ly{}_rad{}_N{}_dx{}.dat".format(
            Lx, Ly, rad, num_obstacles, dx))

    if len(obst) and len(interior_obstacles):
        all_obstacles = np.vstack(
            (np.array(obst), np.array(interior_obstacles)))
    elif len(interior_obstacles):
        all_obstacles = interior_obstacles
    else:
        all_obstacles = []

    if len(all_obstacles):
        np.savetxt(
            obstacles_path,
            np.hstack((all_obstacles, np.ones((len(all_obstacles), 1)) * rad)))
示例#10
0
def method(L=6., H=2., R=0.3, n_segments=40, res=180, show=False, **kwargs):
    """
    Generates hourglass.
    """
    info("Generating mesh of an hourglass")

    pt_1 = df.Point(0., 0.)
    pt_1star = df.Point(2., 0.)
    pt_1starstar = df.Point(L/(2*res), 0.)
    pt_2 = df.Point(L, H)
    pt_2star = df.Point(L-2., H)
    pt_2starstar = df.Point(L-L/(2*res), H)
    pt_3 = df.Point(2., H)
    pt_3star = df.Point(0, H)
    pt_3starstar = df.Point(L/(2*res), H)
    pt_4 = df.Point(L-2., 0)
    pt_4star = df.Point(L, 0)
    pt_4starstar = df.Point(L-L/(2*res), 0)
    pt_5 = df.Point(2., R)
    pt_6 = df.Point(2., H-R)
    pt_7 = df.Point(L-2., R)
    pt_8 = df.Point(L-2., H-R)
    pt_9 = df.Point(2.+2*R, R)
    pt_10 = df.Point(2.+2*R, H-R)
    pt_11 = df.Point(L-2*R-2, R)
    pt_12 = df.Point(L-2*R-2, H-R)
    pt_13 = df.Point(2.+2*R, H-2*R)
    pt_14 = df.Point(L-2*R-2, 2*R)

    inlet_polygon = [pt_1]
    inlet_polygon.append(pt_1starstar)
    add_vertical_boundary_vertices(inlet_polygon, L/res, H, res, 1)
    inlet_polygon.append(pt_3starstar)
    inlet_polygon.append(pt_3star)
    add_vertical_boundary_vertices(inlet_polygon, 0.0, H, res, -1)
    inlet_polygon.append(pt_1)

    outlet_polygon = [pt_4starstar]
    outlet_polygon.append(pt_4star)
    add_vertical_boundary_vertices(outlet_polygon, L, H, res, 1)
    outlet_polygon.append(pt_2)
    outlet_polygon.append(pt_2starstar)
    add_vertical_boundary_vertices(outlet_polygon, L-L/res, H, res, -1)
    outlet_polygon.append(pt_4starstar)

    inlet1 = mshr.Polygon(inlet_polygon)
    inlet2 = mshr.Rectangle(pt_1starstar, pt_3)
    outlet1 = mshr.Polygon(outlet_polygon)
    outlet2 = mshr.Rectangle(pt_4, pt_2starstar)
    channel = mshr.Rectangle(pt_5, pt_8)
    pos_cir_1 = mshr.Circle(pt_5, R, segments=n_segments)
    pos_cir_2 = mshr.Circle(pt_6, R, segments=n_segments)
    pos_cir_3 = mshr.Circle(pt_7, R, segments=n_segments)
    pos_cir_4 = mshr.Circle(pt_8, R, segments=n_segments)
    neg_cir_1 = mshr.Circle(pt_9, R, segments=n_segments)
    neg_cir_2 = mshr.Circle(pt_10, R, segments=n_segments)
    neg_cir_3 = mshr.Circle(pt_11, R, segments=n_segments)
    neg_cir_4 = mshr.Circle(pt_12, R, segments=n_segments)
    neg_reg_1 = mshr.Rectangle(pt_13, pt_12)
    neg_reg_2 = mshr.Rectangle(pt_9, pt_14)

    domain = inlet1 + inlet2 + outlet1 + outlet2 + channel + \
        pos_cir_1 + pos_cir_2 + pos_cir_3 + pos_cir_4 - neg_cir_1 - \
        neg_cir_2 - neg_cir_3 - neg_cir_4 - neg_reg_1 - neg_reg_2

    mesh = mshr.generate_mesh(domain, res)

    mesh_path = os.path.join(MESHES_DIR,
                             "hourglass_res" + str(res))
    store_mesh_HDF5(mesh, mesh_path)
    if show:
        df.plot(mesh)
        plt.show()
示例#11
0
def method(L=6., H=2., R=0.3, n_segments=40, res=120, **kwargs):
    """
    Generates barbell capilar with rounded edges.
    """
    info("Generating mesh of rounded barbell capilar")
    
    pt_1 = df.Point(0., 0.)
    pt_1star = df.Point(1., 0.)
    pt_1starstar = df.Point(L/(2*res), 0.)
    pt_2 = df.Point(L, H)
    pt_2star = df.Point(L-1., H)
    pt_2starstar = df.Point(L-L/(2*res), H)
    pt_3 = df.Point(1., H)
    pt_3star = df.Point(0, H)
    pt_3starstar = df.Point(L/(2*res), H)
    pt_4 = df.Point(L-1., 0)
    pt_4star = df.Point(L, 0)
    pt_4starstar = df.Point(L-L/(2*res), 0)
    pt_5 = df.Point(1., R)
    pt_6 = df.Point(1., H-R)
    pt_7 = df.Point(L-1., R)
    pt_8 = df.Point(L-1., H-R)
    pt_9 = df.Point(1.+2*R, R)
    pt_10 = df.Point(1.+2*R, H-R)
    pt_11 = df.Point(L-2*R-1, R)
    pt_12 = df.Point(L-2*R-1, H-R)
    pt_13 = df.Point(1.+2*R, H-2*R)
    pt_14 = df.Point(L-2*R-1, 2*R)

    inlet_polygon = [pt_1]
    inlet_polygon.append(pt_1starstar)
    add_vertical_boundary_vertices(inlet_polygon, L/res, H, res, 1)
    inlet_polygon.append(pt_3starstar)
    inlet_polygon.append(pt_3star)
    add_vertical_boundary_vertices(inlet_polygon, 0.0, H, res, -1)
    inlet_polygon.append(pt_1)

    outlet_polygon = [pt_4starstar]
    outlet_polygon.append(pt_4star)
    add_vertical_boundary_vertices(outlet_polygon, L, H, res, 1)
    outlet_polygon.append(pt_2)
    outlet_polygon.append(pt_2starstar)
    add_vertical_boundary_vertices(outlet_polygon, L-L/res, H, res, -1)
    outlet_polygon.append(pt_4starstar)

    inlet1 = mshr.Polygon(inlet_polygon)
    inlet2 = mshr.Rectangle(pt_1starstar, pt_3)
    outlet1 = mshr.Polygon(outlet_polygon)
    outlet2 = mshr.Rectangle(pt_4, pt_2starstar)
    channel = mshr.Rectangle(pt_5, pt_8)
    pos_cir_1 = mshr.Circle(pt_5, R, segments=n_segments)
    pos_cir_2 = mshr.Circle(pt_6, R, segments=n_segments)
    pos_cir_3 = mshr.Circle(pt_7, R, segments=n_segments)
    pos_cir_4 = mshr.Circle(pt_8, R, segments=n_segments)
    neg_cir_1 = mshr.Circle(pt_9, R, segments=n_segments)
    neg_cir_2 = mshr.Circle(pt_10, R, segments=n_segments)
    neg_cir_3 = mshr.Circle(pt_11, R, segments=n_segments)
    neg_cir_4 = mshr.Circle(pt_12, R, segments=n_segments)
    neg_reg_1 = mshr.Rectangle(pt_13, pt_12)
    neg_reg_2 = mshr.Rectangle(pt_9, pt_14)

    domain = inlet1 + inlet2 + outlet1 + outlet2 + \
        channel + pos_cir_1 + pos_cir_2 + pos_cir_3 + \
        pos_cir_4 - neg_cir_1 - neg_cir_2 - neg_cir_3 - \
        neg_cir_4 - neg_reg_1 - neg_reg_2

    mesh = mshr.generate_mesh(domain, res)

    mesh_path = os.path.join(MESHES_DIR,
                             "roundet_barbell_res" + str(res))
    store_mesh_HDF5(mesh, mesh_path)
    df.plot(mesh)
    df.interactive()