def animate(i): global qtdemo, dt c = circle.center circle.center = (c[0] + 1 * dt, c[1]) circle.radius -= 0.1 * dt phi = lambda p: dcircle(p, circle.center, circle.radius) marker = AdaptiveMarker(phi) qtdemo.step(dt, marker) point = qtdemo.qtree.point cell = qtdemo.qtree.ds.cell polys.set_verts(point[cell, :]) return polys,
return self.dt def get_left_hand_matrix(self, t): dt = self.dt A = self.stiff_matrix M = self.mass_matrix def get_right_hand_vector(self, t): pass def accept_solution(self, current_solution): pass def solve(self, A, b): pass n = 10 box = [-1, 1, -1, 1] cxy = (0.0, 0.0) r = 0.5 phi = lambda p: dcircle(p, cxy, r) mesh = interfacemesh2d(box, phi, n) # plot fig = plt.figure() axes = fig.gca() mesh.add_plot(axes, pointcolor=mesh.pointMarker) circle = Circle(cxy, r, edgecolor='g', fill=False, linewidth=2) axes.add_patch(circle) plt.show()
def animate(i): global distmesh2d, dt distmesh2d.step(dt) point = distmesh2d.mesh.point edge = distmesh2d.mesh.ds.edge NE = edge.shape[0] xy = np.ones((3*NE, 2),dtype=np.float) xy[0::3,:] = point[edge[:,0],:] xy[1::3,:] = point[edge[:,1],:] xy[2::3,:] = np.nan lines.set_data(xy[:,0], xy[:,1]) points.set_data(point[:,0], point[:,1]) return lines, points fd = lambda p: ddiff(drectangle(p,[-1,1,-1,1]), dcircle(p, (0,0),0.5)) fh = lambda p: 0.05+0.3*dcircle(p,(0,0),0.5) bbox = [-1.2, 1.2, -1.2, 1.2] pfix = np.array([[-1,-1],[-1,1], [1,-1], [1,1]], dtype=np.float) h0 = 0.05 domain = DistDomain2d(fd, fh, bbox, pfix) distmesh2d = DistMesh2d(domain, h0) dt = 0.2 fig = plt.figure() axes = plt.axes(xlim=(-1.2,1.2),ylim=(-1.2,1.2)) lines, points = distmesh2d.mesh.add_plot(axes) interval = 1000 * dt ani = animation.FuncAnimation(fig, animate, frames=300, interval=interval, blit=True, init_func=init)
hg[phiSign>=0] = np.sqrt(np.maximum(np.minimum(a[phiSign>=0], 0)**2, np.maximum(b[phiSign>=0], 0)**2) + np.maximum(np.minimum(c[phiSign>=0], 0)**2, np.maximum(d[phiSign>=0], 0)**2)) hg[phiSign < 0] = np.sqrt(np.maximum(np.maximum(a[phiSign<0], 0)**2, np.minimum(b[phiSign<0], 0)**2) + np.maximum(np.maximum(c[phiSign<0], 0)**2, np.minimum(d[phiSign<0], 0)**2)) return hg n = int(sys.argv[1]) nx = n ny = n box = [-2, 2, -2, 2] cxy = (0.0, 0.0) r = 1 interface0 = lambda p: dcircle(p, cxy, r) interface = lambda p: circle(p, cxy, r) mesh = StructureQuadMesh(box, nx, ny) dx = mesh.dx dy = mesh.dy point = mesh.point N = point.shape[0] phi = interface(point) phiSign = sign(phi)