def psi_dns_initial_no_ext(gradTx, gradTy, x, y, X, Y, max_len): yy, xx = np.meshgrid(y, x) # compute normal of s-l interface: X,Y nhat_x = np.zeros(X.size) nhat_y = np.zeros(Y.size) gx_interp = itp2d(x, y, gradTx.T, kind='linear') gy_interp = itp2d(x, y, gradTy.T, kind='linear') for j in range(X.size): vx = gx_interp(X[j], Y[j]) vy = gy_interp(X[j], Y[j]) vn = np.sqrt(vx**2 + vy**2) nhat_x[j] = vx / vn nhat_y[j] = vy / vn ds = np.sqrt((x[1] - x[0])**2 + (y[1] - y[0])**2) nstep = int(max_len / ds) X_char = np.zeros((X.size, 2 * nstep - 1)) Y_char = np.zeros((X.size, 2 * nstep - 1)) psi_char = np.zeros((X.size, 2 * nstep - 1)) for kk in range(nstep): if kk == 0: X_char[:, 0] = X Y_char[:, 0] = Y psi_char[:, 0] = 0 else: # follow characteristic in the dirction of the interior X_char[:, kk] = X_char[:, kk - 1] + nhat_x * ds Y_char[:, kk] = Y_char[:, kk - 1] + nhat_y * ds psi_char[:, kk] = psi_char[:, kk - 1] - ds # follow characteristic in the direction of the exterior X_char[:, -kk] = X_char[:, -kk + 1] - nhat_x * ds Y_char[:, -kk] = Y_char[:, -kk + 1] - nhat_y * ds psi_char[:, -kk] = psi_char[:, -kk + 1] + ds # pts= np.array( ( X_char.flatten(), Y_char.flatten() ) ).T # val= psi_char.flatten() # psi0 = griddata( pts, val, ( xx, yy ), method = 'cubic') # psi1 = griddata( pts, val, ( xx, yy ), method = 'nearest') # psi0[np.isnan(psi0)] = psi1[np.isnan(psi0)] # fig,ax=plt.subplots() # ax.pcolormesh( xx, yy , psi0) return X_char, Y_char, psi_char
def get_sl_interface(T2d, x, y, x_top, Tl): # T2d is 2d temperature # x : 1d array, e.g. x_dns # y : 1d array, e.g. y_dns # x_top: x-coordinate on the top boundary # Tl the temperature of your target interface # The solver loops over x_top, shoots a ray from x_top[j], and find the intersection with T=Tl # if no intersection is found, fill with nan. T_interp = itp2d(x, y, T2d.T) X = np.zeros(x_top.size) Y = np.zeros(x_top.size) for j in range(x_top.size): f = lambda s: T_interp(x_top[j], s) - Tl try: X[j] = x_top[j] Y[j] = brentq(f, y.min(), 0) except ValueError: X[j] = np.nan Y[j] = np.nan return X, Y
def trajectory(xj_arrn, yj_arrn, gTx_n, gTy_n, R, y_n, y_np): # calculate coordinates for time at n+1 and output interpered gradTx gradTy, R T_n = np.reshape(y_n, (ny, nx), order='F') T_np = np.reshape(y_np, (ny, nx), order='F') num_sam = len(xj_arrn) Tj_arrn = np.zeros(num_sam) gTxj_arrn = np.zeros(num_sam) gTyj_arrn = np.zeros(num_sam) Rj_arrn = np.zeros(num_sam) sj_arr = np.zeros(num_sam) T_itp = itp2d(x, ycoor, T_np, kind='linear') # get interp object for next time step t_n+1 gTxn_itp = itp2d(x, ycoor, gTx_n, kind='linear') gTyn_itp = itp2d(x, ycoor, gTy_n, kind='linear') R_itp = itp2d(x, ycoor, R, kind='linear') Tn_itp = itp2d(x, ycoor, T_n, kind='linear') for ii in range(num_sam): x_j = xj_arrn[ii] y_j = yj_arrn[ii] Tj_arrn[ii] = Tn_itp(x_j, y_j) gTxj_arrn[ii] = gTxn_itp(x_j, y_j) gTyj_arrn[ii] = gTyn_itp(x_j, y_j) Rj_arrn[ii] = R_itp(x_j, y_j) arg = (x_j, y_j, T_itp, gTxj_arrn[ii], gTyj_arrn[ii]) sj_arr[ii] = fsolve(stepj, [0.0], args=arg) Gj_arrn = np.sqrt(gTxj_arrn**2 + gTyj_arrn**2) betaj_arrn = np.arctan(gTyj_arrn / gTxj_arrn) * 180 / pi return xj_arrn + sj_arr*gTxj_arrn, yj_arrn + sj_arr*gTyj_arrn,\ xj_arrn, yj_arrn, Tj_arrn, Gj_arrn, betaj_arrn, Rj_arrn
def tem_dis(tp): time = int(t0 / dt) + t_st + tp + 1 #479, 349 G = np.reshape(G_arr[:, time], (ny, nx), order='F') T = np.reshape(temp[:, time], (ny, nx), order='F') Titp = itp2d(x, ycoor, T, kind='cubic') Gitp = itp2d(x, ycoor, G, kind='cubic') for i in range(T_len): Ttarg[i] = Titp(xtarg[i], ytarg[i]) G0 = Gitp(xtarg[tp], ytarg[tp]) print(tp, G0) for i in range(T_len): T_FR[i] = Ttarg[tp] + G0 * (zl[i] - zl[tp]) return Ttarg, T_FR
def psi_dns_initial(gradTx, gradTy, x, y, X, Y, max_len): yy, xx = np.meshgrid(y, x) # compute normal of s-l interface: X,Y nhat_x = np.zeros(X.size) nhat_y = np.zeros(Y.size) gx_interp = itp2d(x, y, gradTx.T, kind='linear') gy_interp = itp2d(x, y, gradTy.T, kind='linear') for j in range(X.size): vx = gx_interp(X[j], Y[j]) vy = gy_interp(X[j], Y[j]) vn = np.sqrt(vx**2 + vy**2) nhat_x[j] = vx / vn nhat_y[j] = vy / vn # LEFT EXTENSTION ds = np.sqrt((X[0] - X[1])**2 + (Y[0] - Y[1])**2) u = (X[0] - X[1]) / ds v = (Y[0] - Y[1]) / ds npts_ext = int((X[0] - x[0]) / ds) print('number of extension points = %d' % (npts_ext)) x_ext = np.zeros(npts_ext) y_ext = np.zeros(npts_ext) for k in range(npts_ext): x_ext[k] = X[0] + u * ds * k y_ext[k] = Y[0] + v * ds * k # compute normal of extended interface nhat_x_ext = y_ext[1:] - y_ext[:-1] nhat_y_ext = -x_ext[1:] + x_ext[:-1] n2_ext = np.sqrt(nhat_x_ext**2 + nhat_y_ext**2) nhat_x_ext = nhat_x_ext / n2_ext nhat_y_ext = nhat_y_ext / n2_ext # append extended interface with original X = np.append(x_ext[1:], X) Y = np.append(y_ext[1:], Y) nhat_x = np.append(nhat_x_ext, nhat_x) nhat_y = np.append(nhat_y_ext, nhat_y) ## RIGHT EXTENSION ds = np.sqrt((X[-1] - X[-2])**2 + (Y[-1] - Y[-2])**2) u = (X[-1] - X[-2]) / ds v = (Y[-1] - Y[-2]) / ds x_ext = np.zeros(npts_ext) y_ext = np.zeros(npts_ext) for k in range(npts_ext): x_ext[k] = X[-1] + u * ds * k y_ext[k] = Y[-1] + v * ds * k # compute normal of extended interface nhat_x_ext = -y_ext[1:] + y_ext[:-1] nhat_y_ext = x_ext[1:] - x_ext[:-1] n2_ext = np.sqrt(nhat_x_ext**2 + nhat_y_ext**2) nhat_x_ext = nhat_x_ext / n2_ext nhat_y_ext = nhat_y_ext / n2_ext # append extended interface with original X = np.append(X, x_ext[1:]) Y = np.append(Y, y_ext[1:]) nhat_x = np.append(nhat_x, nhat_x_ext) nhat_y = np.append(nhat_y, nhat_y_ext) # characteristics step size ds = np.sqrt((x[1] - x[0])**2 + (y[1] - y[0])**2) nstep = int(max_len / ds) X_char = np.zeros((X.size, 2 * nstep - 1)) Y_char = np.zeros((X.size, 2 * nstep - 1)) psi_char = np.zeros((X.size, 2 * nstep - 1)) for kk in range(nstep): if kk == 0: X_char[:, 0] = X Y_char[:, 0] = Y psi_char[:, 0] = 0 else: # follow characteristic in the dirction of the interior X_char[:, kk] = X_char[:, kk - 1] + nhat_x * ds Y_char[:, kk] = Y_char[:, kk - 1] + nhat_y * ds psi_char[:, kk] = psi_char[:, kk - 1] - ds # follow characteristic in the direction of the exterior X_char[:, -kk] = X_char[:, -kk + 1] - nhat_x * ds Y_char[:, -kk] = Y_char[:, -kk + 1] - nhat_y * ds psi_char[:, -kk] = psi_char[:, -kk + 1] + ds # pts= np.array( ( X_char.flatten(), Y_char.flatten() ) ).T # val= psi_char.flatten() # psi0 = griddata( pts, val, ( xx, yy ), method = 'cubic') # psi1 = griddata( pts, val, ( xx, yy ), method = 'nearest') # psi0[np.isnan(psi0)] = psi1[np.isnan(psi0)] # fig,ax=plt.subplots() # ax.pcolormesh( xx, yy , psi0) return X_char, Y_char, psi_char
# b = u + lat*A_l*u b = u + inv_Ste * A_l * u # u_top = u[0:-1:simu.ny] u_top = u[-simu.nx:] qs = heat_source(x, t * 0, simu.source_x[0]) set_top_bc(b, qs, u_top, t) unew, stat, num_iter = sparse_cg(A, Q @ b, u, simu.cg_tol, M, simu.maxit) dTdt_new = np.abs((unew - u) / simu.dt) u2d = np.reshape(unew, (simu.nx, simu.ny), order='F') u_interp = itp2d(x, y, u2d.T) try: pd = comp_pool_depth(u_interp, simu.source_x) print('cur depth', len_dim(pd)) except ValueError: print('Temperature is below T_liquid') u = unew dTdt = dTdt_new t += simu.dt iter_melt += 1
set_top_bc(b, qs_x, u_top, t) unew,stat,num_iter = sparse_cg(A, Q@b, u, TOL, M, maxit) dTdt = np.abs((unew - u)/dt) print('max cooling rate = ', dTdt.max()) # G,R, grad_x, grad_y = compute_GR(unew, u, dx) G,R, grad_x, grad_y = gradients(unew, u, dx) u2d = np.reshape(unew, (ny,nx), order='F') u_interp = itp2d(x,y,u2d) R_interp = itp2d(x_i, y_i, R) G_interp = itp2d(x_i, y_i, G) gx = itp2d(x_i, y_i, grad_x) gy = itp2d(x_i, y_i, grad_y) print('iter = %d'%(iter_melt)) if reach_bottom_check(unew, R) : print('reach the bottom at %d'%(iter_melt+1)) reach_bottom = True