def vec_dt(A, E): #Constants de, ae, ke, ea = 1., 1., 1., 10. dx = 1. return ea * (1. - A) * E, de * discreteLaplacian.Lap2DMt( E, dx**2) - ke * E + ae * A * (1. - A)
def vec_dt(A, E, D, N): #Constants de, ae, ke, ea = 1., 1., 1., 10. kn, dn, dc, kd, ad = 1., 0.25, 0.25, 1., 1. #sum of D in neighboring cells D_upper = np.roll(D, 1, axis=0) D_upper[0, :] = 0 D_lower = np.roll(D, -1, axis=0) D_lower[-1, :] = 0 D_left = np.roll(D, 1, axis=1) D_left[0, :] = 0 D_right = np.roll(D, -1, axis=1) D_right[-1, :] = 0 D_nei = D_upper + D_lower + D_left + D_right #EGF mutant Emut = np.ones(E.shape) Emut[5:20, 5:20] = 0 dx = 1. #val of dx = dy for calculation of laplacian # Calc. max{E - N, 0} by clip(min, max) return ea * (1. - A) * (E - N).clip(0, None), \ de * discreteLaplacian.Lap2DMt(E, dx**2) - ke * E + ae * A * (1. - A) * Emut, \ -kd * D + ad * A * (1. - A),\ -kn * N + dn * D_nei - dc * D
def dvdt_dwdt(v, w, Ie): #Constants d, a, b, c = 1., 0.7, 0.8, 10. dx = 1. dx2 = dx * dx return c * (-v**3 / 3. + v - w + Ie) + d * discreteLaplacian.Lap2DMt( v, dx2), (v - b * w + a) / c
def heartbeat2D(matVW, t): # reshape V, W n = int(len(matVW) / 2) x_max = int(np.sqrt(n)) v1, w1 = matVW[:n].reshape(x_max, x_max), matVW[n:].reshape(x_max, x_max) #Initialize params i = np.zeros((x_max, x_max)) i[49:51, 49:51] = 1. d, a, b, c = 1., 0.7, 0.8, 10. dx = 1. dx2 = dx * dx #PDEs dvdt = c * (-v1**3 / 3. + v1 - w1 + i) + d * discreteLaplacian.Lap2DMt( v1, dx2) dwdt = (v1 - b * w1 + a) / c return np.hstack((dvdt.ravel(), dwdt.ravel()))
A = np.zeros((Xmax, Xmax, Tmax)) I = np.zeros((Xmax, Xmax, Tmax)) #Initial conc. distributions A[47:52, 47:52, 0] = 1. #Production rate of A c = np.zeros((Xmax, Xmax)) c[47:52, 47:52] = 1. starttime = time.time() #start timing #Solve PDEs for T in range(Tmax - 1): A[:, :, T + 1] = dt * (da * discreteLaplacian.Lap2DMt(A[:, :, T], dx2) + aa * A[:, :, T] + ia * I[:, :, T] + c) + A[:, :, T] I[:, :, T + 1] = dt * (di * discreteLaplacian.Lap2DMt(I[:, :, T], dx2) + ai * A[:, :, T] + ii * I[:, :, T]) + I[:, :, T] #Apply maximum and minimum values A[:, :, T + 1] = A[:, :, T + 1].clip(0., Amax) I[:, :, T + 1] = I[:, :, T + 1].clip(0., Imax) elapsedtime = time.time() - starttime print('Time elapsed (sec): {}'.format(elapsedtime)) #Plot results len_T = len(str(Tmax)) #the number of digits in Tmax for time in range(Tmax): fig, axs = plt.subplots(1, 2, figsize=(6.4, 2.4)) heatmapB = axs[0].pcolor(A[:, :, time], vmin=0.0, vmax=2.0, cmap='YlOrRd')
#Initialize params Tmax, dt = 5000, 0.02 Xmax, dx = 100, 1. dx2 = dx*dx V = np.zeros((Xmax, Xmax, Tmax)) W = np.zeros((Xmax, Xmax, Tmax)) I = np.zeros((Xmax, Xmax)) I[49:51, 49:51] = 1. a, b, c = 0.7, 0.8, 10. d = np.ones((100, 100)) d[40:50, 40:80] = 0. #Solve ODEs for T in range(Tmax-1): V[:, :, T + 1] = V[:, :, T] + dt * (c * (-V[:, :, T]**3 / 3. + V[:, :, T] - W[:, :, T] + I) + d * discreteLaplacian.Lap2DMt(V[:, :, T], dx2)) W[:, :, T + 1] = W[:, :, T] + dt * (V[:, :, T] - b * W[:, :, T] + a) / c #Reduce size of matrices by slicing STEP = 100 Vr = V[:, :, ::STEP] Wr = W[:, :, ::STEP] #Plot results len_T = len(str(Vr.shape[2])) #the number of digits for time in range(Vr.shape[2]): fig, axs = plt.subplots(1, 2, figsize=(6.4, 2.4)) heatmapV = axs[0].pcolor(Vr[:, :, time], vmin=0.0, vmax=np.ceil(V.max()), cmap='YlOrRd') fig.colorbar(heatmapV, ax=axs[0]) heatmapW = axs[1].pcolor(Wr[:, :, time], vmin=0.0, vmax=np.ceil(W.max()), cmap='YlOrRd') fig.colorbar(heatmapW, ax=axs[1])
Xmax, Tmax = 100, 500 dt, dx = 0.1, 1. d, k, a = 1., 0.1, 1. dx2 = dx * dx S = np.zeros((Xmax, Xmax, Tmax)) B = np.zeros((Xmax, Xmax, Tmax)) c = np.zeros((Xmax, Xmax)) #Initial conc. distribution of Dpp c[:, 47:53] = 0.5 starttime = time.time() #start timing #Solve. PDEs for T in range(Tmax - 1): B[:, :, T + 1] = dt * (d * discreteLaplacian.Lap2DMt(B[:, :, T], dx2) - k * B[:, :, T] + c) + B[:, :, T] S[:, :, T + 1] = dt * (a * B[:, :, T] - k * S[:, :, T]) + S[:, :, T] elapsedtime = time.time() - starttime print('Time elapsed (sec): {}'.format(elapsedtime)) #Plot results len_T = len(str(Tmax)) #the number of digits in Tmax for time in range(Tmax): fig, axs = plt.subplots(1, 2) heatmapB = axs[0].pcolor(B[:, :, time], vmin=0.0, vmax=1.0, cmap='YlOrRd') fig.colorbar(heatmapB, ax=axs[0]) heatmapS = axs[1].pcolor(S[:, :, time], vmin=0.0, vmax=1.0, cmap='YlOrRd') fig.colorbar(heatmapS, ax=axs[1]) s = str(time).zfill(len_T)
Tmax, dt = 5000, 0.02 Xmax, dx = 100, 1. dx2 = dx * dx V = np.zeros((Xmax, Xmax, Tmax)) W = np.zeros((Xmax, Xmax, Tmax)) I = np.zeros((Xmax, Xmax)) I[49:51, 49:51] = 1. d, a, b, c = 1., 0.7, 0.8, 10. #Solve ODEs for T in range(Tmax - 1): V[:, :, T + 1] = V[:, :, T] + dt * (c * (-V[:, :, T]**3 / 3. + V[:, :, T] - W[:, :, T] + I) + d * discreteLaplacian.Lap2DMt(V[:, :, T], dx2)) W[:, :, T + 1] = W[:, :, T] + dt * (V[:, :, T] - b * W[:, :, T] + a) / c #Reduce size of matrices by slicing STEP = 100 Vr = V[:, :, ::STEP] Wr = W[:, :, ::STEP] #Plot results len_T = len(str(Vr.shape[2])) #the number of digits for time in range(Vr.shape[2]): fig, axs = plt.subplots(1, 2, figsize=(6.4, 2.4)) heatmapV = axs[0].pcolor(Vr[:, :, time], vmin=0.0, vmax=np.ceil(V.max()), cmap='YlOrRd')
#init. Xmax, Tmax = 100, 100 dt, d, dx = 0.1, 1.0, 1.0 dx2 = dx * dx E = np.zeros((Xmax, Xmax, Tmax)) E[0:20, 40:60, 0] = np.random.randn(E[0:20, 40:60, 0].shape[0], E[0:20, 40:60, 0].shape[1]) #Initial conc. distribution starttime = time.time() #start timing #Solve PDE for T in range(Tmax - 1): E[:, :, T + 1] = dt * d * discreteLaplacian.Lap2DMt(E[:, :, T], dx2) + E[:, :, T] elapsedtime = time.time() - starttime print('Time elapsed (sec): {}'.format(elapsedtime)) #Plot results len_T = len(str(Tmax)) #the number of digits in Tmax for time in range(Tmax): fig, ax = plt.subplots() heatmap = ax.pcolor(E[:, :, time], vmin=0.0, vmax=1.0, cmap='YlOrRd') fig.colorbar(heatmap, ax=ax) s = str(time).zfill(len_T) fig.savefig("GIF\\{}.png".format(s)) #Save image for each loop plt.clf() plt.cla() plt.close()
A = np.zeros((Xmax, Xmax, Tmax)) I = np.zeros((Xmax, Xmax, Tmax)) #Initial conc. distributions A[47:52, 47:52, 0] = 1. #Production rate of A c = np.zeros((Xmax, Xmax)) c[47:52, 47:52] = 1. starttime = time.time() #start timing #Solve PDEs for T in range(Tmax - 1): A[:, :, T + 1] = dt * (da * discreteLaplacian.Lap2DMt(A[:, :, T], dx2) + aa * A[:, :, T] + ia * I[:, :, T] + c) + A[:, :, T] I[:, :, T + 1] = dt * (di * discreteLaplacian.Lap2DMt(I[:, :, T], dx2) + ai * A[:, :, T] + ii * I[:, :, T]) + I[:, :, T] #Apply maximum and minimum values A[:, :, T + 1] = A[:, :, T + 1] * ((A[:, :, T + 1] > 0.).astype(int) * (A[:, :, T + 1] < Amax).astype(int)) + Amax * (A[:, :, T + 1] >= Amax).astype(int) I[:, :, T + 1] = I[:, :, T + 1] * ((I[:, :, T + 1] > 0.).astype(int) * (I[:, :, T + 1] < Imax).astype(int)) + Imax * (I[:, :, T + 1] >= Imax).astype(int) elapsedtime = time.time() - starttime print('Time elapsed (sec): {}'.format(elapsedtime)) #Plot results len_T = len(str(Tmax)) #the number of digits in Tmax for time in range(Tmax): fig, axs = plt.subplots(1, 2, figsize=(6.4, 2.4)) heatmapB = axs[0].pcolor(A[:, :, time], vmin=0.0, vmax=2.0, cmap='YlOrRd') fig.colorbar(heatmapB, ax=axs[0]) heatmapW = axs[1].pcolor(I[:, :, time], vmin=0.0, vmax=2.0, cmap='YlOrRd')