예제 #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
예제 #2
0
def test_difference(show=False):
    geo = dmsh.Difference(dmsh.Circle([-0.5, 0.0], 1.0),
                          dmsh.Circle([+0.5, 0.0], 1.0))
    X, cells = dmsh.generate(geo, 0.1, show=show)

    ref_norms = [
        2.9445552442961758e+02, 1.5856356670813716e+01, 1.4999999157880513e+00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-9)
    return X, cells
예제 #3
0
def test_difference(show=False):
    geo = dmsh.Difference(dmsh.Circle([-0.5, 0.0], 1.0),
                          dmsh.Circle([+0.5, 0.0], 1.0))
    X, cells = dmsh.generate(geo, 0.1, show=show)

    geo.plot()

    ref_norms = [2.9445555e02, 1.58563569e01, 1.499999914e00]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-7)
    return X, cells
예제 #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)
예제 #5
0
def test_intersection(show=False):
    geo = dmsh.Circle([0.0, -0.5], 1.0) & dmsh.Circle([0.0, +0.5], 1.0)
    X, cells = dmsh.generate(geo, 0.1, show=show, tol=1.0e-10, max_steps=100)

    geo.plot()

    ref_norms = [
        8.6491736892894920e01, 6.1568624411912278e00, 8.6602540378466342e-01
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
예제 #6
0
def test_boundary_step2():
    geo = dmsh.Circle([0.0, -0.5], 1.0) & dmsh.Circle([0.0, +0.5], 1.0)

    np.random.seed(0)
    pts = np.random.uniform(-1.0, 1.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-7)
예제 #7
0
def test_difference(show=False):
    geo = dmsh.Circle([-0.5, 0.0], 1.0) - dmsh.Circle([+0.5, 0.0], 1.0)
    X, cells = dmsh.generate(geo, 0.1, show=show, max_steps=100)

    geo.plot()

    ref_norms = [
        2.9409044729708609e02, 1.5855488859739937e01, 1.5000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-6)
    return X, cells
예제 #8
0
def test_boundary_step2():
    geo = dmsh.Difference(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)
예제 #9
0
파일: test_union.py 프로젝트: nschloe/dmsh
def test_union_circles(show=False):
    geo = 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
예제 #10
0
def test_intersection(show=False):
    geo = dmsh.Intersection(
        [dmsh.Circle([0.0, -0.5], 1.0),
         dmsh.Circle([0.0, +0.5], 1.0)])
    X, cells = dmsh.generate(geo, 0.1, show=show, tol=1.0e-10)

    ref_norms = [
        8.6619344595913475e+01, 6.1599895121114274e+00, 8.6602540378466342e-01
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-12)
    return X, cells
예제 #11
0
def test_boundary_step():
    geo = dmsh.Circle([0.0, -0.5], 1.0) & dmsh.Circle([0.0, +0.5], 1.0)

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

    pts = np.array([[0.0, -0.1], [0.0, 0.1]])
    pts = geo.boundary_step(pts.T).T
    ref = np.array([[0.0, -0.5], [0.0, 0.5]])
    assert np.all(np.abs(pts - ref) < 1.0e-10)
예제 #12
0
def test_boundary_step():
    geo = dmsh.Difference(dmsh.Circle([-0.5, 0.0], 1.0),
                          dmsh.Circle([+0.5, 0.0], 1.0))
    pts = np.array([
        [-2.1, 0.0],
        [0.1, 0.0],
        [-1.4, 0.0],
        [-0.6, 0.0],
    ])
    pts = geo.boundary_step(pts.T).T
    ref = np.array([[-1.5, 0.0], [-0.5, 0.0], [-1.5, 0.0], [-0.5, 0.0]])
    assert np.all(np.abs(pts - ref) < 1.0e-10)
예제 #13
0
파일: test_union.py 프로젝트: nschloe/dmsh
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
예제 #14
0
def test_intersection_circles(show=False):
    angles = np.pi * np.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])
    geo = dmsh.Intersection([
        dmsh.Circle([np.cos(angles[0]), np.sin(angles[0])], 1.5),
        dmsh.Circle([np.cos(angles[1]), np.sin(angles[1])], 1.5),
        dmsh.Circle([np.cos(angles[2]), np.sin(angles[2])], 1.5),
    ])
    X, cells = dmsh.generate(geo, 0.1, show=show, tol=1.0e-10, max_steps=100)

    ref_norms = [
        6.7661318585210836e01, 5.0568863746561723e00, 7.2474487138537913e-01
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
예제 #15
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
예제 #16
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.Intersection(
        [
            dmsh.Circle([numpy.cos(angles[0]), numpy.sin(angles[0])], 1.5),
            dmsh.Circle([numpy.cos(angles[1]), numpy.sin(angles[1])], 1.5),
            dmsh.Circle([numpy.cos(angles[2]), numpy.sin(angles[2])], 1.5),
        ]
    )
    X, cells = dmsh.generate(geo, 0.1, show=show, tol=1.0e-10)

    ref_norms = [6.8247386668599034e01, 5.1256971008793917e00, 7.2474487138537913e-01]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-12)
    return X, cells
예제 #17
0
def quarter_annulus(h):
    disk0 = dmsh.Circle([0.0, 0.0], 0.25)
    disk1 = dmsh.Circle([0.0, 0.0], 1.0)
    diff0 = dmsh.Difference(disk1, disk0)

    rect = dmsh.Rectangle(0.0, 1.0, 0.0, 1.0)
    quarter = dmsh.Intersection([diff0, rect])

    points, cells = dmsh.generate(
        quarter,
        edge_size=lambda x: h + 0.1 * numpy.abs(disk0.dist(x)),
        tol=1.0e-10,
        max_steps=max_steps,
    )
    return points, cells
예제 #18
0
def test_boundary_step():
    geo = dmsh.Circle([0.1, 0.2], 1.0)
    np.random.seed(0)
    pts = np.random.uniform(-1.0, 1.0, (2, 100))
    pts = geo.boundary_step(pts)
    tol = 1.0e-12
    assert np.all(np.abs(geo.dist(pts)) < tol)
예제 #19
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
예제 #20
0
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
예제 #21
0
파일: test_circle.py 프로젝트: 1027kg/dmsh
def test_circle(show=True):
    geo = dmsh.Circle([0.0, 0.0], 1.0)
    X, cells = dmsh.generate(geo, 0.1, show=show)

    ref_norms = [
        3.2795193920779542e02, 1.4263721858241993e01, 1.0000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-12)
    return X, cells
예제 #22
0
def test_circle(radius, ref_norms, show=False):
    geo = dmsh.Circle([0.0, 0.0], 1.0)
    X, cells = dmsh.generate(geo, radius, show=show)

    # make sure the origin is part of the mesh
    assert numpy.sum(numpy.einsum("ij,ij->i", X, X) < 1.0e-10) == 1

    assert_norm_equality(X.flatten(), ref_norms, 1.0e-5)
    return X, cells
예제 #23
0
def test_circle(radius, ref_norms, show=False):
    geo = dmsh.Circle([0.0, 0.0], 1.0)
    X, cells = dmsh.generate(geo, radius, show=show, max_steps=100)
    meshplex.MeshTri(X, cells).show()

    # make sure the origin is part of the mesh
    assert np.sum(np.einsum("ij,ij->i", X, X) < 1.0e-6) == 1

    assert_norm_equality(X.flatten(), ref_norms, 1.0e-5)
    return X, cells
예제 #24
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)
예제 #25
0
파일: test_pacman.py 프로젝트: jchkoch/dmsh
def test_pacman(show=False):
    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, show=show, tol=1.0e-10)

    ref_norms = [3.0385105041432689e02, 1.3644964912810719e01, 1.0]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
예제 #26
0
def test_degenerate_circle(target_edge_length):
    geo = dmsh.Circle([0.0, 0.0], 1.0)
    X, cells = dmsh.generate(geo,
                             target_edge_length,
                             show=False,
                             max_steps=200,
                             verbose=True)

    mesh = meshplex.MeshTri(X, cells)
    min_q = np.min(mesh.q_radius_ratio)
    assert min_q > 0.5, f"min cell quality: {min_q:.3f}"
예제 #27
0
def test_halfspace(show=False):
    geo = dmsh.Intersection([
        dmsh.HalfSpace(numpy.sqrt(0.5) * numpy.array([1.0, 1.0]), 0.0),
        dmsh.Circle([0.0, 0.0], 1.0),
    ])
    X, cells = dmsh.generate(geo, 0.1, show=show)

    ref_norms = [
        1.6445971629723411e02, 1.0032823867864321e01, 9.9962000746451751e-01
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-12)
    return X, cells
예제 #28
0
def test_halfspace(show=False):
    geo = dmsh.Intersection([
        dmsh.HalfSpace(np.sqrt(0.5) * np.array([1.0, 1.0])),
        dmsh.Circle([0.0, 0.0], 1.0),
    ])
    X, cells = dmsh.generate(geo, 0.1, show=show, max_steps=100)

    ref_norms = [
        1.6399670188761661e02, 1.0011048291798387e01, 9.9959986881486440e-01
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-6)
    return X, cells
예제 #29
0
def test(show=False):
    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: numpy.abs(c.dist(pts)) / 5 + 0.05, show=show, tol=1.0e-10
    )

    ref_norms = [2.48e02, 1.200e01, 1.0]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-3)
    return X, cells
	def coreMesh(self,eleSize):
		"""
		核心混凝土的划分
		输入:
			eleSize:核心区纤维单元大小
		返回:
			coreFiberInfo:核心混凝土纤维单元列表[(xc1,yc1,area1),(xc2,yc2,area2)]
		"""
		outDNew=self.outD-self.d0*2.0
		if self.inD!=None:
			inDNew=self.inD+self.d0*2.0
			geo = dmsh.Difference(dmsh.Circle([0, 0], outDNew/2.0), dmsh.Circle([0, 0.0],inDNew/2.0))
			points, elements= dmsh.generate(geo, eleSize)
			coreFiberInfo=self._triEleInfo(points,elements)
			self.ax.triplot(points[:, 0], points[:, 1], elements)
		else:
			geo = dmsh.Circle([0.0, 0.0],outDNew/2.0)
			points, elements = dmsh.generate(geo,eleSize)
			coreFiberInfo = self._triEleInfo(points, elements)
			self.ax.triplot(points[:, 0], points[:, 1], elements)
		return coreFiberInfo