Exemplo n.º 1
0
def polygonTriangulation(borderPoints, edge_size):
    """
    De una lista de puntos de borde crea una triangulacion de tamaño edge_size
    del poligono determinado por esos puntos
    """
    points, cells = dmsh.generate(dmsh.Polygon(borderPoints), edge_size)
    return Triangulation(points, cells)
Exemplo n.º 2
0
def get_mesh(area, contour):
    """
    get the points resulting from meshing
    
    Parameters:
    ----------
    area: int, area of small zones
    contour:list of tuples containing contour points coordinates
    
    Return:
    ------
    points: numpy.array, coordinates of the points forming the vertices of the mesh
    """
    contour = np.array(contour) / 100
    esize = area
    geo = dmsh.Polygon(contour)
    vertices, cells = dmsh.generate(geo, esize)
    vertices = (vertices * 100).astype(int)
    points = []
    for cell in cells:
        i, j, k = cell[0], cell[1], cell[2]
        point = (vertices[i] + vertices[j] + vertices[k]) / 3
        points.append(point.astype(int))
    points = np.vstack((points))

    return points, vertices, cells
Exemplo n.º 3
0
    def _set_TUB(self, mesh_size):
        geo = dmsh.Polygon([[1 / 3, 1 / 3], [1, 0], [0.5, 0.5]])
        points, triangles = dmsh.generate(geo, mesh_size)
        self._centroids = np.empty((len(triangles), 2))
        for i, triangle in enumerate(triangles):
            self._centroids[i] = np.mean(points[triangle], axis=0)

        tri = Triangulation(points[:, 0], points[:, 1], triangles)
        self._trifinder = tri.get_trifinder()
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def test_rectangle_hole2(show=False):
    geo = dmsh.Difference(
        dmsh.Rectangle(0.0, 5.0, 0.0, 5.0),
        dmsh.Polygon([[1, 1], [4, 1], [4, 4], [1, 4]]),
    )
    X, cells = dmsh.generate(geo, 1.0, show=show, tol=1.0e-3, max_steps=100)

    ref_norms = [
        1.3990406144096474e02, 2.2917592510234346e01, 5.0000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-2)
Exemplo n.º 6
0
def test(show=False):
    geo = dmsh.Difference(
        dmsh.Rectangle(0.0, 5.0, 0.0, 5.0),
        dmsh.Polygon([[1, 1], [4, 1], [4, 4], [1, 4]]),
    )
    X, cells = dmsh.generate(geo, 1.0, show=show, tol=1.0e-3)

    assert_norm_equality(X.flatten(),
                         [1.2599887992309357e02, 2.2109217065599051e01, 5.0],
                         1.0e-12)
    return
Exemplo n.º 7
0
def test(show=False):
    geo = dmsh.Difference(
        dmsh.Rectangle(0.0, 5.0, 0.0, 5.0),
        dmsh.Polygon([[1, 1], [4, 1], [4, 4], [1, 4]]),
    )
    X, cells = dmsh.generate(geo, 1.0, show=show, tol=1.0e-3)

    ref_norms = [
        1.4000000000000000e02, 2.3176757306973560e01, 5.0000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
Exemplo n.º 8
0
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-5, max_steps=100)

    ref_norms = [
        3.0173012692535394e02, 1.3565685453257570e01, 9.9999999999884770e-01
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-10)
    return X, cells
Exemplo n.º 9
0
def l_shape(h):
    return dmsh.generate(
        dmsh.Polygon([
            [-1.0, -1.0],
            [+1.0, -1.0],
            [+1.0, +0.0],
            [+0.0, +0.0],
            [+0.0, +1.0],
            [-1.0, +1.0],
        ]),
        edge_size=h,
        tol=1.0e-10,
    )
	def coreMesh(self,eleSize,outLineList,inLineList=None):
		"""
		核心混凝土的划分
		输入:
			eleSize:纤维单元的边长
			outLineList:外分界线节点列表[(x1,y1),(x2,y2),...,(xn,yn)]
			inLineList:内分界线节点列表[[(x1,y1),(x2,y2),...,(xn,yn)],[(x1,y1),(x2,y2),...,(xn,yn)]]
		返回:
			triEleInfoList:纤维单元信息列表[(xc1,yc1,area1),(xc2,yc2,area2)]
		"""
		triEleInfoList=None
		if inLineList==None:
			geo=dmsh.Polygon(outLineList)
			points, elements = dmsh.generate(geo, eleSize)
			triEleInfoList = self._triEleInfo(points, elements)
			self.ax.triplot(points[:, 0], points[:, 1], elements, c=self.coreColor, linewidth=self.lineWid, zorder=0)
		elif len(inLineList)==1:
			geo = dmsh.Difference(
				dmsh.Polygon(outLineList),
				dmsh.Polygon(inLineList[0]),
			)
			points, elements = dmsh.generate(geo, eleSize)
			triEleInfoList = self._triEleInfo(points, elements)
			self.ax.triplot(points[:,0],points[:,1],elements,c=self.coreColor,linewidth=self.lineWid, zorder=0)

		elif len(inLineList)==2:
			zhole,yhole=self._twoHoleDirect(self.inNode)
			list1,list2=self._twoHolePolygonDivide(outLineList, inLineList,zhole,yhole)
			geo1= dmsh.Polygon(list1)
			geo2 = dmsh.Polygon(list2)
			points1, elements1 = dmsh.generate(geo1, eleSize)
			points2, elements2 = dmsh.generate(geo2, eleSize)
			triEleInfoList1=self._triEleInfo(points1,elements1)
			triEleInfoList2 = self._triEleInfo(points2, elements2)
			triEleInfoList=triEleInfoList1+triEleInfoList2
			self.ax.triplot(points1[:, 0], points1[:, 1], elements1,c=self.coreColor,linewidth=self.lineWid,zorder = 0)
			self.ax.triplot(points2[:, 0], points2[:, 1], elements2, c=self.coreColor,linewidth=self.lineWid,zorder=0)
		return triEleInfoList
Exemplo n.º 11
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
Exemplo n.º 12
0
def test(show=False):
    geo = dmsh.Polygon([
        [0.0, 0.0],
        [1.1, 0.0],
        [1.2, 0.5],
        [0.7, 0.6],
        [2.0, 1.0],
        [1.0, 2.0],
        [0.5, 1.5],
    ])
    X, cells = dmsh.generate(geo, 0.1, show=show)

    ref_norms = [4.1468030858462305e+02, 2.1861920662017866e+01, 2.0]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-5)
    return X, cells
Exemplo n.º 13
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
Exemplo n.º 14
0
def test(show=False):
    geo = dmsh.Polygon([
        [0.0, 0.0],
        [1.1, 0.0],
        [1.2, 0.5],
        [0.7, 0.6],
        [2.0, 1.0],
        [1.0, 2.0],
        [0.5, 1.5],
    ])
    # geo.show()
    X, cells = dmsh.generate(geo, 0.1, show=show, max_steps=100)

    ref_norms = [
        4.1426056822140765e02, 2.1830112296142847e01, 2.0000000000000000e00
    ]
    assert_norm_equality(X.flatten(), ref_norms, 1.0e-5)
    return X, cells
Exemplo n.º 15
0
def test_boundary_step2():
    geo = dmsh.Polygon([
        [0.0, 0.0],
        [1.1, 0.0],
        [1.2, 0.5],
        [0.7, 0.6],
        [2.0, 1.0],
        [1.0, 2.0],
        [0.5, 1.5],
    ])
    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()
    # print(geo.dist(pts).shape)
    dist = geo.dist(pts)
    assert np.all(np.abs(dist) < 1.0e-12)
Exemplo n.º 16
0
def test_boundary_step_pacman():
    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]]),
    )
    # np.random.seed(0)
    # pts = np.random.uniform(-2.0, 2.0, (2, 100))
    # pts = np.array([[-2.0, 0.0]])
    # pts = np.array([[-0.1, 0.0]])
    # pts = np.array([[0.0, 2.0]])
    # pts = np.array([[0.0, 0.9]])
    # pts = np.array([[2.0, 0.1]])
    # pts = np.array([[0.1, 0.1]])
    # pts = np.array([[0.7, 0.1]])
    pts = np.array([[0.5, 0.1]])
    pts = pts.T
    print(pts.T.shape)
    pts = geo.boundary_step(pts)
    geo.plot()
    import matplotlib.pyplot as plt

    plt.plot(pts[0], pts[1], "xk")
    plt.show()
#-*-coding: UTF-8-*-
import subprocess
import dmsh
import optimesh
import meshio
import matplotlib.pyplot as pt
import numpy as np

# p = subprocess.Popen("OpenSees.exe", stdin=subprocess.PIPE,
#                      stdout=subprocess.PIPE,
#                      stderr=subprocess.PIPE)
# p.stdin.write("source AnJiuCableStayedBridge.tcl\n".encode())
######################################################################################
geo = dmsh.Difference(
    dmsh.Polygon([[10, 10], [10, -10], [-10, -10], [-10, 10]]),
    dmsh.Polygon([[4, 4], [4, -4], [-4, -4], [-4, 4]]),
)
points, elements = dmsh.generate(geo, 0.4)
pt.triplot(points[:, 0], points[:, 1], elements)
pt.show()

################################################################
Exemplo n.º 18
0
X, cells = dmsh.generate(geo, 0.1)
# optionally optimize the mesh
X, cells = optimesh.optimize_points_cells(X, cells, "CVT (full)", 1.0e-10, 100)
save(X, cells, "circle.svg")


geo = dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0)
X, cells = dmsh.generate(geo, 0.1)
save(X, cells, "rectangle.svg")

geo = dmsh.Polygon(
    [
        [0.0, 0.0],
        [1.1, 0.0],
        [1.2, 0.5],
        [0.7, 0.6],
        [2.0, 1.0],
        [1.0, 2.0],
        [0.5, 1.5],
    ]
)
X, cells = dmsh.generate(geo, 0.1)
save(X, cells, "polygon.svg")

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)
save(X, cells, "moon.svg")


geo = dmsh.Difference(
    dmsh.Circle([0.0, 0.0], 1.0),