Exemplo n.º 1
0
def plate_with_hole(size=.05):
    fd = lambda p: dm.ddiff(dm.drectangle(p, -1, 1, -1, 1),
                            dm.dcircle(p, 0, 0, 0.5))
    fh = lambda p: 0.05 + 0.3 * dm.dcircle(p, 0, 0, 0.5)
    p, t = dm.distmesh2d(fd, fh, size, (-1, -1, 1, 1), [(-1, -1), (-1, 1),
                                                        (1, -1), (1, 1)])
    return p, t
Exemplo n.º 2
0
def plate_with_hole(size=.05):
    fd = lambda p: dm.ddiff(dm.drectangle(p,-1,1,-1,1),
                            dm.dcircle(p,0,0,0.5))
    fh = lambda p: 0.05+0.3*dm.dcircle(p,0,0,0.5)
    p, t = dm.distmesh2d(fd, fh, size, (-1,-1,1,1),
                         [(-1,-1),(-1,1),(1,-1),(1,1)])
    return p, t
Exemplo n.º 3
0
def naca0012_airfoil():
    """NACA0012 airfoil"""
    hlead = 0.01
    htrail = 0.04
    hmax = 2
    circx = 2
    circr = 4
    a = .12 / .2 * np.array([0.2969, -0.1260, -0.3516, 0.2843, -0.1036])
    a0 = a[0]
    a1 = np.hstack((a[5:0:-1], 0.0))

    fd = lambda p: dm.ddiff(dm.dcircle(p, circx, 0, circr), (abs(
        p[:, 1]) - np.polyval(a1, p[:, 0]))**2 - a0**2 * p[:, 0])
    fh = lambda p: np.minimum(
        np.minimum(hlead + 0.3 * dm.dcircle(p, 0, 0, 0), htrail + 0.3 * dm.
                   dcircle(p, 1, 0, 0)), hmax)

    fixx = 1.0 - htrail * np.cumsum(1.3**np.arange(5))
    fixy = a0 * np.sqrt(fixx) + np.polyval(a1, fixx)
    fix = np.vstack(
        (np.array([(circx - circr, 0), (circx + circr, 0), (circx, -circr),
                   (circx, circr), (0, 0), (1, 0)]), np.vstack(
                       (fixx, fixy)).T, np.vstack((fixx, -fixy)).T))
    box = (circx - circr, -circr, circx + circr, circr)
    h0 = min(hlead, htrail, hmax)
    return dm.distmesh2d(fd, fh, h0, box, fix)
Exemplo n.º 4
0
def rectangle_with_circular_hole():
    """Rectangle with circular hole, refined at circle boundary"""
    fd = lambda p: dm.ddiff(dm.drectangle(p, -1, 1, -1, 1),
                            dm.dcircle(p, 0, 0, 0.5))
    fh = lambda p: 0.05 + 0.3 * dm.dcircle(p, 0, 0, 0.5)
    return dm.distmesh2d(fd, fh, 0.05, (-1, -1, 1, 1), [(-1, -1), (-1, 1),
                                                        (1, -1), (1, 1)])
Exemplo 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)])
Exemplo n.º 6
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)])
Exemplo n.º 7
0
def naca0012_airfoil():
    """NACA0012 airfoil"""
    hlead=0.01; htrail=0.04; hmax=2; circx=2; circr=4
    a=.12/.2*np.array([0.2969,-0.1260,-0.3516,0.2843,-0.1036])
    a0=a[0]; a1=np.hstack((a[5:0:-1], 0.0))

    fd = lambda p: dm.ddiff(
        dm.dcircle(p,circx,0,circr),
        (abs(p[:,1])-np.polyval(a1, p[:,0]))**2-a0**2*p[:,0])
    fh = lambda p: np.minimum(np.minimum(
        hlead+0.3*dm.dcircle(p,0,0,0),
        htrail+0.3*dm.dcircle(p,1,0,0)),hmax)

    fixx = 1.0-htrail*np.cumsum(1.3**np.arange(5))
    fixy = a0*np.sqrt(fixx)+np.polyval(a1, fixx)
    fix = np.vstack((
        np.array([(circx-circr,0),(circx+circr,0),
                  (circx,-circr),(circx,circr),
                  (0,0),(1,0)]),
        np.vstack((fixx, fixy)).T,
        np.vstack((fixx, -fixy)).T))
    box = (circx-circr,-circr, circx+circr,circr)
    h0 = min(hlead, htrail, hmax)
    return dm.distmesh2d(fd, fh, h0, box, fix)
Exemplo n.º 8
0
	def __init__(self, lx, ly, cx, cy, r):
		fd = lambda p: dm.ddiff(dm.drectangle(p,-lx,lx,-ly,ly), dm.dcircle(p,cx,cx,r))
		fh = lambda p: 0.05+0.03*dm.dcircle(p,cx,cy,r)	
		p, t = dm.distmeshnd(fd, fh, 0.5, (-lx,-ly,lx,ly),[(-lx,-ly),(-lx,ly),(lx,-ly),(lx,ly)])
		self.nodes = p
		self.conn = t
Exemplo n.º 9
0
# Problem 2 Mesh Generation
h0_rect = 0.05
h0_cell = h0_rect * (7 / 8)
h0_elec = h0_cell
xi = -5
xf = 5
yi = 0
yf = 6
x_elec1 = [-3, -1]
x_elec2 = [1, 3]
x_range = [xi, xf]
y_range = [yi, yf]
bbox = [xi - 0.1, yi - 0.1, xf + 0.1, yf + 0.1]

# Mesh inside the cell
fd_rod1 = lambda p: dm.dcircle(p, 0, 2, 1)
p_r1, t_r1 = dm.distmesh2d(fd_rod1, dm.huniform, h0_cell, bbox)

plt.scatter(p_r1[:, 0], p_r1[:, 1], s=1, marker=".")
plt.title("Cell mesh - Problem #2")
plt.show()

# Rectangle mesh
fd_rect = lambda p: dm.drectangle0(p, xi, xf, yi, yf)

# Add denser mesh around the electrodes
N_elec = int((max(x_elec1) - min(x_elec1)) / h0_elec)
p_e1 = np.zeros((N_elec, 2))
p_e1[:, 0] = np.linspace(min(x_elec1), max(x_elec1), N_elec)

p_e2 = p_e1.copy()
Exemplo n.º 10
0
def rectangle_with_circle_at_corner():
    # Does not terminate!
    fd = lambda p: dm.ddiff(dm.drectangle(p, 0, 10, 0, 6),
                            dm.dcircle(p, 10, 0, 4))
    return dm.distmesh2d(fd, dm.huniform, 0.9, (0, 0, 10, 6))
Exemplo n.º 11
0
def fh(p):
    return dm.dunion(dm.dunion(0.0004-0.3*fdout(p), 0.0004+0.3*dm.dcircle(p,0,0,vfr)), 0.0004+0.3*dm.dcircle(p,2*rad,0,vfr))
Exemplo n.º 12
0
import distmesh as dm
fd = lambda p: dm.ddiff(dm.drectangle(p,-1,1,-1,1), dm.dcircle(p,0,0,0.5))
fh = lambda p: 0.05+0.3*dm.dcircle(p,0,0,0.5)
p, t = dm.distmesh2d(fd, fh, 0.05, (-1,-1,1,1), [(-1,-1),(-1,1),(1,-1),(1,1)])
Exemplo n.º 13
0
def rectangle_with_circle_at_corner():
    # Does not terminate!
    fd = lambda p: dm.ddiff(dm.drectangle(p,0,10,0,6), dm.dcircle(p,10,0,4))
    return dm.distmesh2d(fd, dm.huniform, 0.9, (0, 0, 10, 6))
Exemplo n.º 14
0
def rectangle_with_circle_at_centre():
    # Does not terminate!
    fd = lambda p: dm.ddiff(dm.drectangle(p,0,20,0,12), dm.dcircle(p,10,6,4))
    return dm.distmesh2d(fd, dm.huniform, 0.5, (0, 0, 20, 12), max_iter=100)
Exemplo n.º 15
0
def fdout(p):
    return dm.dunion(dm.dunion(dm.dcircle(p,0,0,rad), dm.drectangle(p,0.0,2*rad, -rad,rad)), dm.dcircle(p,2*rad,0,rad))
Exemplo n.º 16
0
def fd(p):
    return dm.ddiff(dm.ddiff(fdout(p), dm.dcircle(p,0,0,vfr)), dm.dcircle(p,2*rad,0,vfr))
Exemplo n.º 17
0
def rectangle_with_circular_hole():
    """Rectangle with circular hole, refined at circle boundary"""
    fd = lambda p: dm.ddiff(dm.drectangle(p,-1,1,-1,1), dm.dcircle(p,0,0,0.5))
    fh = lambda p: 0.05+0.3*dm.dcircle(p,0,0,0.5)
    return dm.distmesh2d(fd, fh, 0.05, (-1,-1,1,1),
                         [(-1,-1),(-1,1),(1,-1),(1,1)])
Exemplo n.º 18
0
# Problem 1 Mesh Generation
h0_rect = 0.015
h0_rod1 = 0.8*h0_rect
h0_rod2 = 0.8*h0_rect
xi = -1.5; xf = 1.5
yi = -1.0; yf = 1.0
x_range = [xi, xf]
y_range = [yi, yf]
bbox = [xi-0.1, yi-0.1, xf+0.1, yf+0.1]

# Mesh inside the first circle

fig = plt.figure(dpi=400)
rod_dist = 0.35
fd_rod1 = lambda p: dm.dcircle(p, -rod_dist/2, 0, 0.1)
p_r1, t_r1 = dm.distmesh2d(fd_rod1, dm.huniform, h0_rod1, bbox, pfix=None)

#plt.scatter(p_r1[:, 0], p_r1[:, 1], s=5, color="black", marker=".")
plt.title("Rod1 mesh - Problem #1")
plt.show()


fig = plt.figure(dpi=400)
fd_rod2 = lambda p: dm.dcircle(p, rod_dist/2, 0, 0.05)
p_r2, t_r2 = dm.distmesh2d(fd_rod2, dm.huniform, h0_rod2, bbox, pfix=None)

#plt.scatter(p_r2[:, 0], p_r2[:, 1], s=5, color="black", marker=".")
plt.title("Rod2 mesh - Problem #1")
plt.show()
Exemplo n.º 19
0
def rectangle_with_circle_at_centre():
    # Does not terminate!
    fd = lambda p: dm.ddiff(dm.drectangle(p, 0, 20, 0, 12),
                            dm.dcircle(p, 10, 6, 4))
    return dm.distmesh2d(fd, dm.huniform, 0.5, (0, 0, 20, 12), max_iter=100)