Example #1
0
def test_union(show=False):
    geo = dmsh.Union(
        [dmsh.Circle([-0.5, 0.0], 1.0),
         dmsh.Circle([+0.5, 0.0], 1.0)])
    X, cells = dmsh.generate(geo, 0.15, show=show, tol=1.0e-10)

    ref_norms = [3.0088043884612756e+02, 1.5785099320497183e+01, 1.5]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-12)
    return X, cells
Example #2
0
def test_union(show=False):
    geo = dmsh.Union([
        dmsh.Rectangle(-1.0, +0.5, -1.0, +0.5),
        dmsh.Rectangle(-0.5, +1.0, -0.5, +1.0)
    ])
    X, cells = dmsh.generate(geo, 0.15, show=show, tol=1.0e-10)

    ref_norms = [1.7868961429998612e+02, 1.1117047580567053e+01, 1.0]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-12)
    return X, cells
Example #3
0
def sartenTriangulation(size, edge_size):
    """
    Triangulación de silueta de una sartén de cocina
    """
    c = dmsh.Circle([0, 0], size)
    r = dmsh.Rectangle(-2.5*size, -size*0.9, -size/8, size/8)

    geo = dmsh.Union([c, r])
    points, cells = dmsh.generate(geo, edge_size)
    return Triangulation(points, cells)
Example #4
0
def test_boundary_step():
    geo = dmsh.Union([dmsh.Circle([-0.5, 0.0], 1.0), dmsh.Circle([+0.5, 0.0], 1.0)])
    geo.show()
    a = geo.boundary_step([-0.5, 0.9])
    assert numpy.array_equal(a, [-0.5, 1.0])

    a = geo.boundary_step([-0.5, 0.6])
    assert numpy.array_equal(a, [-0.5, 1.0])

    a = geo.boundary_step([0.05, 0.05])
    assert_equality(a, [-4.4469961425821203e-01, 9.9846976285554556e-01], 1.0e-10)
Example #5
0
def test_union(show=False):
    geo = dmsh.Union([
        dmsh.Rectangle(-1.0, +0.5, -1.0, +0.5),
        dmsh.Rectangle(-0.5, +1.0, -0.5, +1.0)
    ])
    X, cells = dmsh.generate(geo, 0.15, show=show, tol=1.0e-5)

    ref_norms = [
        1.8432376349018622e02, 1.1278734993846784e01, 1.0000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
Example #6
0
def test_boundary_step2():
    geo = dmsh.Union(
        [dmsh.Circle([-0.5, 0.0], 1.0),
         dmsh.Circle([+0.5, 0.0], 1.0)])
    np.random.seed(0)
    pts = np.random.uniform(-2.0, 2.0, (2, 100))
    pts = geo.boundary_step(pts)
    # geo.plot()
    # import matplotlib.pyplot as plt
    # plt.plot(pts[0], pts[1], "xk")
    # plt.show()
    assert np.all(np.abs(geo.dist(pts)) < 1.0e-12)
Example #7
0
def test_union_rectangles(show=False):
    geo = dmsh.Union([
        dmsh.Rectangle(-1.0, +0.5, -1.0, +0.5),
        dmsh.Rectangle(-0.5, +1.0, -0.5, +1.0)
    ])
    X, cells = dmsh.generate(geo, 0.15, show=show, tol=1.0e-5, max_steps=100)

    ref_norms = [
        1.8417796811774514e02, 1.1277323166424049e01, 1.0000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
Example #8
0
def test_union_circles(show=False):
    geo = dmsh.Union(
        [dmsh.Circle([-0.5, 0.0], 1.0),
         dmsh.Circle([+0.5, 0.0], 1.0)])
    X, cells = dmsh.generate(geo, 0.15, show=show, tol=1.0e-5, max_steps=100)

    geo.plot()

    ref_norms = [
        3.0080546580519666e02, 1.5775854476745508e01, 1.5000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
Example #9
0
def test_union(show=False):
    angles = numpy.pi * numpy.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
    geo = dmsh.Union(
        [
            dmsh.Circle([numpy.cos(angles[0]), numpy.sin(angles[0])], 1.0),
            dmsh.Circle([numpy.cos(angles[1]), numpy.sin(angles[1])], 1.0),
            dmsh.Circle([numpy.cos(angles[2]), numpy.sin(angles[2])], 1.0),
        ]
    )
    X, cells = dmsh.generate(geo, 0.2, show=show, tol=1.0e-10)

    ref_norms = [4.0372522103229670e02, 2.1155465970807523e01, 1.9999337650692937e00]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
Example #10
0
def main():
    fig = plt.figure()
    position = 231 
    
    geo = dmsh.Union( 
        [dmsh.Rectangle(-1.0, +0.5, -1.0, +0.5), dmsh.Rectangle(-0.5, +1.0, -0.5, +1.0)] 
    )
        
    for it in [1, 3, 5, 10, 30, 50]: 
        ax = fig.add_subplot(position) 
        drawPlot(it, ax, geo)
        position += 1
    
    plt.show() 
Example #11
0
def test_union_three_circles(show=False):
    angles = np.pi * np.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
    geo = dmsh.Union([
        dmsh.Circle([np.cos(angles[0]), np.sin(angles[0])], 1.0),
        dmsh.Circle([np.cos(angles[1]), np.sin(angles[1])], 1.0),
        dmsh.Circle([np.cos(angles[2]), np.sin(angles[2])], 1.0),
    ])
    X, cells = dmsh.generate(geo, 0.2, show=show, tol=1.0e-5, max_steps=100)

    ref_norms = [
        4.0359760255235619e02, 2.1162741423521961e01, 2.0000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
Example #12
0
def test_union(show=False):
    angles = numpy.pi * numpy.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
    geo = dmsh.Union([
        dmsh.Circle(
            [numpy.cos(angles[0]), numpy.sin(angles[0])], 1.0),
        dmsh.Circle(
            [numpy.cos(angles[1]), numpy.sin(angles[1])], 1.0),
        dmsh.Circle(
            [numpy.cos(angles[2]), numpy.sin(angles[2])], 1.0),
    ])
    X, cells = dmsh.generate(geo, 0.2, show=show, tol=1.0e-10)

    ref_norms = [
        4.1390554922002769e+02, 2.1440246410944471e+01, 1.9947113226010518e+00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-12)
    return X, cells
def _create_mesh(filename):
    poly = dmsh.Polygon(
        [
            [-295.0, 0.0],
            [-160.0, 0.0],
            [-50.0, 110.0],
            [-50.0, 190.0],
            [+50.0, 190.0],
            [+50.0, 110.0],
            [+160.0, 0.0],
            [+295.0, 0.0],
            [+405.0, 110.0],
            [+405.0, 235.0],
            [+200.0, 430.0],
            [+170.0, 400.0],
            [+355.0, 235.0],
            [-355.0, 235.0],
            [-170.0, 400.0],
            [-200.0, 430.0],
            [-405.0, 235.0],
            [-405.0, 110.0],
        ]
    )

    geo = dmsh.Union(
        [
            poly,
            dmsh.Circle([-295.0, 110.0], 110.0),
            dmsh.Circle([+295.0, 110.0], 110.0),
            dmsh.Circle([-160.0, 110.0], 110.0),
            dmsh.Circle([+160.0, 110.0], 110.0),
        ]
    )

    X, cells = dmsh.generate(
        geo,
        35.0,
        # show=True
    )

    X, cells = optimesh.lloyd(X, cells, 1.0e-3, 100)

    X = numpy.column_stack([X[:, 0], X[:, 1], numpy.zeros(X.shape[0])])

    meshio.write_points_cells(filename, X, {"triangle": cells})
    return
Example #14
0
def polygon2geo(polygon):
    # exterior boundary (dmsh does not include the last point twice to close the polygon such as shapely)
    e = list(polygon.exterior.coords.xy)
    boundary_e = [[e[0][i], e[1][i]] for i in range(len(e[0]) - 1)]
    outer = dmsh.Polygon(boundary_e)
    print(boundary_e)
    # interior boundary
    inner = []
    for int in polygon.interiors:
        h = list(int.coords.xy)
        boundary_h = [[h[0][i], h[1][i]] for i in range(len(h[0]) - 1)]
        hole = dmsh.Polygon(boundary_h)
        inner.append(hole)

    if len(inner) > 1:
        inner = dmsh.Union(inner)
        geo = dmsh.Difference(outer, inner)
    elif len(inner) == 1:
        inner = inner[0]
        geo = dmsh.Difference(outer, inner)
    else:
        geo = outer
    return geo
Example #15
0
def test_boundary_step():
    geo = dmsh.Union(
        [dmsh.Circle([-0.5, 0.0], 1.0),
         dmsh.Circle([+0.5, 0.0], 1.0)])
    a = geo.boundary_step([-0.5, 0.9])
    assert np.array_equal(a, [-0.5, 1.0])

    a = geo.boundary_step([-0.5, 0.6])
    assert np.array_equal(a, [-0.5, 1.0])

    a = geo.boundary_step([0.05, 0.05])
    assert_equality(a, [-4.4469961425821203e-01, 9.9846976285554556e-01],
                    1.0e-10)

    pts = np.array([[-5.0, 0.0], [4.1, 0.0]])
    pts = geo.boundary_step(pts.T).T
    ref = np.array([[-1.5, 0.0], [1.5, 0.0]])
    assert np.all(np.abs(pts - ref) < 1.0e-10)

    pts = np.array([[-0.9, 0.0], [1.1, 0.0]])
    pts = geo.boundary_step(pts.T).T
    ref = np.array([[-1.5, 0.0], [1.5, 0.0]])
    assert np.all(np.abs(pts - ref) < 1.0e-10)
Example #16
0
geo = dmsh.Difference(
    dmsh.Circle([0.0, 0.0], 1.0),
    dmsh.Polygon([[0.0, 0.0], [1.5, 0.4], [1.5, -0.4]]),
)
X, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)
save(X, cells, "pacman.svg")


r = dmsh.Rectangle(-1.0, +1.0, -1.0, +1.0)
c = dmsh.Circle([0.0, 0.0], 0.3)
geo = dmsh.Difference(r, c)
X, cells = dmsh.generate(geo, lambda pts: np.abs(c.dist(pts)) / 5 + 0.05, tol=1.0e-10)
save(X, cells, "rectangle-hole-refinement.svg")


geo = dmsh.Union([dmsh.Circle([-0.5, 0.0], 1.0), dmsh.Circle([+0.5, 0.0], 1.0)])
X, cells = dmsh.generate(geo, 0.15)
save(X, cells, "union-circles.svg")


geo = dmsh.Union(
    [dmsh.Rectangle(-1.0, +0.5, -1.0, +0.5), dmsh.Rectangle(-0.5, +1.0, -0.5, +1.0)]
)
X, cells = dmsh.generate(geo, 0.15)
save(X, cells, "union-rectangles.svg")


angles = np.pi * np.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
geo = dmsh.Union(
    [
        dmsh.Circle([np.cos(angles[0]), np.sin(angles[0])], 1.0),
Example #17
0
    else:
        raise ValueError("Quadrature precision too high on triangle")

    assert abs(np.sum(qwgts) -
               1) < 1e-12  #Ensures that the weights do indeed sum to 1.
    return rspts, qwgts


def Isopmap(x, y, r, s, shapefcn):
    S, dSdr, dSds = shapefcn(r, s)
    j11, j12 = dSdr[:, 0].dot(x), dSdr[:, 0].dot(y)
    j21, j22 = dSds[:, 0].dot(x), dSds[:, 0].dot(y)
    detJ = j11 * j22 - j12 * j21
    dSdx = (j22 * dSdr - j12 * dSds) / detJ
    dSdy = (-j21 * dSdr + j11 * dSds) / detJ

    return S, dSdx, dSdy, detJ


if __name__ == '__main__':
    import dmsh

    geo1 = dmsh.Circle((0, 0), 1)
    geo2 = dmsh.Rectangle(0.5, 1.5, 0, 1)
    geo = dmsh.Union((geo1, geo2))
    P, T, E, B = dmsh.generate(geo, .5)
    fem = FEM_P2CG(P, T, E, B)
    fem.show_mesh2D()

    A = fem.IsoStiffnessAssembler(lambda x, y: 1)