Ejemplo n.º 1
0
    def _plate2(self, dlist):
        """Triangularize with MIT Per-Olof, Prof. Gilbert Strange's algorithm."""
        width = float(dlist[0])
        length = float(dlist[1])
        half_w = width / 2
        half_l = length / 2
        edge_size = dlist[2]
        self.x_extent = [-half_w, half_w]
        self.y_extent = [-half_l, half_l]
        self.maxdim = max([abs(each) for each in self.x_extent + self.y_extent])

        polygon = Poly([-half_w, -half_l])
        polygon.add_line2(width, 0, 1)
        polygon.add_line2(length, 90, 1)
        polygon.add_line2(width, 180, 1)
        polygon.add_line2(length, 270, 1)
        polygon.close()
        self.vertices = polygon.vertices
        pv = polygon.vertices
        f = lambda p: dm.dpoly(p,pv)
        pnt, tri = dm.distmesh2d(f, dm.huniform, edge_size, (-half_w, -half_l, half_w, half_l), pv)

        self.triangles = tri
        self.points = pnt
        self.triangles = [tuple(each) for each in self.triangles]
        self.triangles_total = len(self.triangles)
Ejemplo n.º 2
0
def square():
    """Square, with size function point and line sources"""
    fd = lambda p: dm.drectangle(p,0,1,0,1)
    fh = lambda p: np.minimum(np.minimum(
        0.01+0.3*abs(dm.dcircle(p,0,0,0)),
        0.025+0.3*abs(dm.dpoly(p,[(0.3,0.7),(0.7,0.5)]))), 0.15)
    return dm.distmesh2d(fd, fh, 0.01, (0,0,1,1), [(0,0), (1,0), (0,1), (1,1)])
Ejemplo n.º 3
0
def polygon():
    """Polygon"""
    pv = np.array([(-0.4,-0.5),(0.4,-0.2),(0.4,-0.7),(1.5,-0.4),(0.9,0.1),
                   (1.6,0.8),(0.5,0.5),(0.2,1.0),(0.1,0.4),(-0.7,0.7),
                   (-0.4,-0.5)])
    fd = lambda p: dm.dpoly(p, pv)
    return dm.distmesh2d(fd, dm.huniform, 0.1, (-1,-1, 2,1), pv)
Ejemplo n.º 4
0
def polygon():
    """Polygon"""
    pv = np.array([(-0.4, -0.5), (0.4, -0.2), (0.4, -0.7), (1.5, -0.4),
                   (0.9, 0.1), (1.6, 0.8), (0.5, 0.5), (0.2, 1.0), (0.1, 0.4),
                   (-0.7, 0.7), (-0.4, -0.5)])
    fd = lambda p: dm.dpoly(p, pv)
    return dm.distmesh2d(fd, dm.huniform, 0.1, (-1, -1, 2, 1), pv)
Ejemplo n.º 5
0
def square():
    """Square, with size function point and line sources"""
    fd = lambda p: dm.drectangle(p, 0, 1, 0, 1)
    fh = lambda p: np.minimum(
        np.minimum(0.01 + 0.3 * abs(dm.dcircle(p, 0, 0, 0)), 0.025 + 0.3 * abs(
            dm.dpoly(p, [(0.3, 0.7), (0.7, 0.5)]))), 0.15)
    return dm.distmesh2d(fd, fh, 0.01, (0, 0, 1, 1), [(0, 0), (1, 0), (0, 1),
                                                      (1, 1)])
Ejemplo n.º 6
0
def polygon(pv, d, minx, miny, maxx, maxy):  # GOES COUNTER_CLOCKWISE
    """Polygon"""
    # pv0 = np.array([(-0.4,-0.5),(0.4,-0.2),(0.4,-0.7),(1.5,-0.4),(0.9,0.1),
    #                (1.6,0.8),(0.5,0.5),(0.2,1.0),(0.1,0.4),(-0.7,0.7),
    #                (-0.4,-0.5)])
    # print type(pv0)
    # print type(pv0[0])
    fd = lambda p: dm.dpoly(p, pv)
    print 'bleh'
    return dm.distmesh2d(fd, dm.huniform, d / 5, (minx, miny, maxx, maxy), pv)
Ejemplo n.º 7
0
    def _poly(self, dlist):
        """Triangularize arbitrary shape of polygon with MIT Per-Olof, Prof. Gilbert Strange's algorithm."""
        vertices = dlist[0]
        x, y = [each[0] for each in vertices], [each[1] for each in vertices]
        self.x_extent = [min(x), max(x)]
        self.y_extent = [min(y), max(y)]
        self.maxdim = max([abs(each) for each in self.x_extent + self.y_extent])

        edge_size = dlist[1]
        bbox = dlist[2]
        self.vertices = vertices
        pv = vertices
        f = lambda p: dm.dpoly(p,pv)
        pnt, tri = dm.distmesh2d(f, dm.huniform, edge_size, bbox, pv)

        self.triangles = tri
        self.points = pnt
        self.triangles = [tuple(each) for each in self.triangles]
        self.triangles_total = len(self.triangles)
Ejemplo n.º 8
0
def process(inputs):
    csv_file = inputs[0]
    out_file = inputs[1]
    points = inputs[2]

    min_x = min([x[0] for x in points])
    min_y = min([x[1] for x in points])
    max_x = max([x[0] for x in points])
    max_y = max([x[1] for x in points])

    fd = lambda p: dm.dpoly(p, points)
    gen_points, gen_triangles = dm.distmesh2d(fd, dm.huniform, args['scale'], (min_x, min_y, max_x, max_y), points, None)

    with open(out_file, 'w') as of:
        for pt in gen_points:
            x = str(pt[0])
            y = str(pt[1])
            of.write(x+','+y+'\n')

    print 'File: %s, %d vertices, %d points generated.' % (csv_file, len(points), len(gen_points))
Ejemplo n.º 9
0
 def polygon(self, pv, h0, minx, miny, maxx,
             maxy):  # GOES COUNTER_CLOCKWISE
     """Polygon"""
     fd = lambda p: dm.dpoly(p, pv)
     print 'Working on generating the mesh!'
     return dm.distmesh2d(fd, dm.huniform, h0, (minx, miny, maxx, maxy), pv)
Ejemplo n.º 10
0
    posx.append(pv[i][0])
    posy.append(pv[i][1])

minx = min(posx)
miny = min(posy)
maxx = max(posx)
maxy = max(posy)
#print " * Min x and y            -> ", minx, ",  ", miny
#print " * Max x and y            -> ", maxx, ",  ", maxy

max = max([abs(minx), abs(miny), abs(maxx), abs(maxy)])

for i in range(len(pv)):
    pv[i] = (pv[i][0] / max, pv[i][1] / max)

fd = lambda p: distmesh.dpoly(p, pv)
p, t = distmesh.distmesh2d(fd, distmesh.huniform, float(sys.argv[2]),
                           (minx, miny, maxx, maxy), pv)

#for i in range(len(p)):
#	print p[i,0], p[i,1]

# Open file stream
fout = open(filename + '_distmesh.geo', 'w')
fout.write('%d\t' % len(p))
fout.write('0\t')
fout.write('%d\n' % len(t))

for i in range(len(p)):
    fout.write('%5d %14.5f %14.5f \n' % (i, p[i, 0], p[i, 1]))