Esempio n. 1
0
def example1():
    """ unit circle mesh """
    def _fd(pts):
        """ shape function """
        return shape.circle(pts, pc=[0, 0], r=1.)

    def _fh(pts):
        """ distance function """
        r2 = np.sum(pts**2, axis=1)
        return 0.2 * (2.0 - r2)

    # build fix points, may be used as the position for electrodes
    num = 16
    p_fix = shape.fix_points_circle(ppl=num)

    # firs num nodes are the positions for electrodes
    el_pos = np.arange(num)

    # build triangle
    p, t = distmesh.build(_fd, _fh, pfix=p_fix, h0=0.05)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.plot(p[el_pos, 0], p[el_pos, 1], 'ro')
    ax.set_aspect('equal')
    ax.set_xlim([-1.5, 1.5])
    ax.set_ylim([-1.1, 1.1])
    plt.show()
Esempio n. 2
0
def example_intersect():
    """example on how to use dist_intersect and fix_points_fd"""
    def _fd(pts):
        """ _fd must centered at [0, 0] """
        ellipse = shape.ellipse(pts, pc=[0, -0.6], ab=[1, 1.5])
        circle = shape.circle(pts, pc=[0, 0], r=1)
        return shape.dist_intersect(ellipse, circle)

    # create equal-distributed electrodes
    p_fix = shape.fix_points_fd(_fd)

    # generate mesh
    bbox = [[-2, -2], [2, 2]]
    p, t = distmesh.build(_fd,
                          shape.area_uniform,
                          pfix=p_fix,
                          bbox=bbox,
                          h0=0.1)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.plot(p_fix[:, 0], p_fix[:, 1], 'ro')
    ax.set_aspect('equal')
    ax.set_xlim([-1.5, 1.5])
    ax.set_ylim([-1.2, 1.2])
    plt.show()
Esempio n. 3
0
def example5():
    """
    Notes
    -----
    L-shaped domain from
        'Finite Elements and Fast Iterative Solvers'
        by Elman, Silvester, and Wathen.
    """

    # set fixed points
    p_fix = [[1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1],
             [0, 0]]
    p_fix = np.array(p_fix)

    def _fd(pts):
        return shape.dist_diff(shape.rectangle(pts, p1=[-1, -1], p2=[1, 1]),
                               shape.rectangle(pts, p1=[0, 0], p2=[1, 1]))

    # build
    p, t = distmesh.build(_fd, shape.area_uniform, pfix=p_fix, h0=0.15)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.plot(p_fix[:, 0], p_fix[:, 1], 'ro')
    ax.set_aspect('equal')
    ax.set_xlim([-1.2, 1.2])
    ax.set_ylim([-1.2, 1.2])
    plt.show()
Esempio n. 4
0
def example1():
    """ unit circle mesh """

    def _fd(pts):
        """ shape function """
        return shape.circle(pts, pc=[0, 0], r=1.)

    def _fh(pts):
        """ distance function """
        r2 = np.sum(pts**2, axis=1)
        return 0.2*(2.0 - r2)

    # build fix points, may be used as the position for electrodes
    num = 16
    pfix = shape.pfix_circle(numEl=num)

    # firs num nodes are the positions for electrodes
    epos = np.arange(num)

    # build triangle
    p, t = distmesh.build(_fd, _fh, pfix=pfix, h0=0.05)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.plot(p[epos, 0], p[epos, 1], 'ro')
    plt.axis('equal')
    plt.axis([-1.5, 1.5, -1.1, 1.1])
    plt.show()
Esempio n. 5
0
def example_voronoi():
    """draw voronoi plots for triangle elements"""

    def _fd(pts):
        return shape.dist_diff(shape.circle(pts, r=0.7),
                               shape.circle(pts, r=0.3))

    # build triangle
    p, t = distmesh.build(_fd, shape.area_uniform, h0=0.1)

    # plot using customized voronoi function
    mplot.voronoi_plot(p, t)
Esempio n. 6
0
def example_voronoi():
    """draw voronoi plots for triangle elements"""

    def _fd(pts):
        # return d2d.dcircle(pts, pc=[0, 0], r=1.)
        return shape.ddiff(shape.circle(pts, r=0.7),
                           shape.circle(pts, r=0.3))

    # build triangle
    p, t = distmesh.build(_fd, shape.huniform, h0=0.1)

    # plot using customized voronoi function
    mplot.voronoi_plot(p, t)
Esempio n. 7
0
def example2():
    """unit circle with a whole at the center"""
    def _fd(pts):
        return shape.dist_diff(shape.circle(pts, r=0.7),
                               shape.circle(pts, r=0.3))

    # build triangle
    p, t = distmesh.build(_fd, shape.area_uniform, h0=0.1)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.set_aspect('equal')
    plt.show()
Esempio n. 8
0
def example2():
    """unit circle with a whole at the center"""

    def _fd(pts):
        return shape.ddiff(shape.circle(pts, r=0.7),
                           shape.circle(pts, r=0.3))

    # build triangle
    p, t = distmesh.build(_fd, shape.huniform, h0=0.1)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    plt.axis('equal')
    plt.show()
Esempio n. 9
0
def example_voronoi():
    """draw voronoi plots for triangle elements"""
    def _fd(pts):
        return shape.dist_diff(shape.circle(pts, r=0.9),
                               shape.circle(pts, r=0.4))

    # build triangle
    p, t = distmesh.build(_fd, shape.area_uniform, h0=0.1)

    # plot using customized voronoi function
    _, ax = voronoi_plot(p, t, figsize=(9, 6))
    ax.triplot(p[:, 0], p[:, 1], t, color='k', alpha=0.35)
    ax.set_aspect('equal')
    ax.set_xlim([-1.0, 1.0])
    ax.set_ylim([-1.0, 1.0])
    plt.show()
Esempio n. 10
0
def example4():
    """ellipse"""

    def _fd(pts):
        if pts.ndim == 1:
            pts = pts[np.newaxis]
        a, b = 2.0, 1.0
        return np.sum((pts/[a, b])**2, axis=1) - 1.0

    # build triangle
    p, t = distmesh.build(_fd, shape.huniform,
                          bbox=[[-2, -1], [2, 1]], h0=0.15)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    plt.axis('equal')
    plt.show()
Esempio n. 11
0
def example4():
    """ellipse"""

    def _fd(pts):
        if pts.ndim == 1:
            pts = pts[np.newaxis]
        a, b = 2.0, 1.0
        return np.sum((pts/[a, b])**2, axis=1) - 1.0

    # build triangle
    p, t = distmesh.build(_fd, shape.area_uniform,
                          bbox=[[-2, -1], [2, 1]], h0=0.15)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    plt.axis('equal')
    plt.show()
Esempio n. 12
0
def example_dintersect():
    """example on how to use dintersect and pfix_fd"""

    def _fd(pts):
        """ _fd must centered at [0, 0] """
        return shape.dintersect(shape.ellipse(pts, pc=[0, -0.6], ab=[1, 1.5]),
                                shape.circle(pts, pc=[0, 0], r=1))

    # create equal-distributed electrodes
    pfix = shape.pfix_fd(_fd)

    # generate mesh
    bbox = [[-2, -2], [2, 2]]
    p, t = distmesh.build(_fd, shape.huniform, pfix=pfix, bbox=bbox, h0=0.1)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.plot(pfix[:, 0], pfix[:, 1], 'ro')
    ax.axis('equal')
Esempio n. 13
0
def example3():
    """rectangle with a whole at the center"""

    # interior
    def _fd(pts):
        return shape.ddiff(shape.rectangle(pts, p1=[-1, -0.6], p2=[1, 0.6]),
                           shape.circle(pts, r=0.3))

    # constraints
    def _fh(pts):
        return 0.05 + 0.05 * shape.circle(pts, r=0.3)

    # build triangle
    p, t = distmesh.build(_fd, _fh, h0=0.05)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.set_xlim([-1.2, 1.2])
    ax.set_ylim([-1, 1])
    plt.show()
Esempio n. 14
0
def example3():
    """rectangle with a whole at the center"""

    # interior
    def _fd(pts):
        rect = shape.rectangle(pts, p1=[-1, -0.6], p2=[1, 0.6])
        circle = shape.circle(pts, r=0.3)
        return shape.dist_diff(rect, circle)

    # constraints
    def _fh(pts):
        return 0.05 + 0.05 * shape.circle(pts, r=0.3)

    # build triangle
    p, t = distmesh.build(_fd, _fh, h0=0.05)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.set_xlim([-1.2, 1.2])
    ax.set_ylim([-1, 1])
    plt.show()
Esempio n. 15
0
def example5():
    """ L-shaped domain from 'Finite Elements and Fast Iterative Solvers'
    by Elman, Silvester, and Wathen. """

    # set fixed points
    pfix = [[1, 0],  [1, -1], [0, -1], [-1, -1],
            [-1, 0], [-1, 1], [0, 1],  [0, 0]]
    pfix = np.array(pfix)

    def _fd(pts):
        return shape.ddiff(shape.rectangle(pts, p1=[-1, -1], p2=[1, 1]),
                           shape.rectangle(pts, p1=[0, 0], p2=[1, 1]))

    # build
    p, t = distmesh.build(_fd, shape.huniform, pfix=pfix, h0=0.15)

    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    ax.plot(pfix[:, 0], pfix[:, 1], 'ro')
    ax.set_xlim([-1.2, 1.2])
    ax.set_ylim([-1.2, 1.2])
    plt.show()
Esempio n. 16
0
def mesh_gen(n_el=20, num_per_el=3):
    ''' 

    function that generates the mesh to be used in solving the FEM and inverse problem

    takes:

    n_el - number of electrodes - int (=20 by default)

    returns:

    mesh_dict - dictionary of mesh characteristics:
        p - array of mesh node coordinates - array shape (number of nodes, 2)
        t - indices of triangle vertices in p array (counter-clockwise) - array shape (number of triangles, 3)
        el_pos - positions of electrodes on plate (clockwise) - array shape (n_el, 2)
        p_fix - coords of fixed points - array shape (number of fixed points, 2)

    '''

    # defining the shape of the plate (a rectangle of sides a and b)
    def _fd(pts):
        return shape.rectangle(pts, p1=[-1., -1.], p2=[1., 1.])

    # (optional) variable meshing with smaller triangles close to the electrodes - taken by the DISTMESH class (pyEIT)
    def _fh(pts):
        p_fix, el_pos = fix_electrodes_multiple(edgeX=0.1,
                                                edgeY=0.1,
                                                a=2,
                                                b=2,
                                                ppl=n_el,
                                                el_width=0.2,
                                                num_per_el=num_per_el)
        #p_fix, el_pos = fix_points_rectangle(edgeX=0.2, edgeY=0.2, a=2, b=2)
        minDist = min_dist_to_el(pts, el_pos)
        return 0.45 + 0.3 * np.power(minDist / np.amax(minDist), 2)

    # setting the electrodes and fixed points positions in p_fix array
    p_fix1, el_pos = fix_electrodes_multiple(edgeX=0.1,
                                             edgeY=0.1,
                                             a=2,
                                             b=2,
                                             ppl=n_el,
                                             el_width=0.2,
                                             num_per_el=num_per_el)
    p_fix = np.empty((len(el_pos) + len(p_fix1), 2), dtype='f4')
    p_fix[0:len(el_pos)] = el_pos
    p_fix[len(el_pos):len(el_pos) + len(p_fix1)] = p_fix1
    # building the DISTMESH class object (from pyEIT)
    p, t = distmesh.build(_fd, _fh, pfix=p_fix, h0=0.12, maxiter=1000)
    # creating the dictionary with the specifics of the meshing
    mesh_dict = {'p': p, 't': t, 'el_pos': el_pos, 'p_fix': p_fix}
    '''
    # plot
    fig, ax = plt.subplots()
    ax.triplot(p[:, 0], p[:, 1], t)
    #ax.plot(p_fix[:, 0], p_fix[:, 1], 'ro')
    ax.set_aspect('equal')
    #ax.set_xlabel(c0)
    #ax.set_ylabel(c1)
    ax.set_xlim([-1.2, 1.2])
    ax.set_ylim([-1.2, 1.2])
    
    ax.plot(el_pos[:, 0], el_pos[:, 1], 'ro')
    plt.show()
    '''
    # return dictionary
    return mesh_dict