if (use_source):
sigma = np.zeros((N_x, N_y))
sigma = 0.0001*np.exp(-((X-L_x/2)**2/(2*(1E+5)**2) + (Y-L_y/2)**2/(2*(1E+5)**2)))
if (use_sink is True):
w = np.ones((N_x, N_y))*sigma.sum()/(N_x*N_y)
with open("param_output.txt", "w") as output_file:
output_file.write(param_string)
print(param_string)
u_n = np.zeros((N_x, N_y))
u_np1 = np.zeros((N_x, N_y))
v_n = np.zeros((N_x, N_y))
v_np1 = np.zeros((N_x, N_y))
eta_n = np.zeros((N_x, N_y))
eta_np1 = np.zeros((N_x, N_y))
h_e = np.zeros((N_x, N_y))
h_w = np.zeros((N_x, N_y))
h_n = np.zeros((N_x, N_y))
h_s = np.zeros((N_x, N_y))
uhwe = np.zeros((N_x, N_y))
vhns = np.zeros((N_x, N_y))
u_n[:, :] = 0.0
v_n[:, :] = 0.0
u_n[-1, :] = 0.0
v_n[:, -1] = 0.0
eta_n = np.exp(-((X-L_x/2.7)**2/(2*(0.05E+6)**2) + (Y-L_y/4)**2/(2*(0.05E+6)**2)))
eta_list = list(); u_list = list(); v_list = list()
hm_sample = list(); ts_sample = list(); t_sample = list()
hm_sample.append(eta_n[:, int(N_y/2)])
ts_sample.append(eta_n[int(N_x/2), int(N_y/2)])
t_sample.append(0.0)
anim_interval = 20
sample_interval = 1000
t_0 = time.perf_counter()
while (time_step < max_time_step):
u_np1[:-1, :] = u_n[:-1, :] - g*dt/dx*(eta_n[1:, :] - eta_n[:-1, :])
v_np1[:, :-1] = v_n[:, :-1] - g*dt/dy*(eta_n[:, 1:] - eta_n[:, :-1])
if (use_friction is True):
u_np1[:-1, :] -= dt*kappa[:-1, :]*u_n[:-1, :]
v_np1[:-1, :] -= dt*kappa[:-1, :]*v_n[:-1, :]
if (use_wind is True):
u_np1[:-1, :] += dt*tau_x[:]/(rho_0*H)
v_np1[:-1, :] += dt*tau_y[:]/(rho_0*H)
if (use_coriolis is True):
u_np1[:, :] = (u_np1[:, :] - beta_c*u_n[:, :] + alpha*v_n[:, :])/(1 + beta_c)
v_np1[:, :] = (v_np1[:, :] - beta_c*v_n[:, :] - alpha*u_n[:, :])/(1 + beta_c)
v_np1[:, -1] = 0.0
u_np1[-1, :] = 0.0
h_e[:-1, :] = np.where(u_np1[:-1, :] > 0, eta_n[:-1, :] + H, eta_n[1:, :] + H)
h_e[-1, :] = eta_n[-1, :] + H
h_w[0, :] = eta_n[0, :] + H
h_w[1:, :] = np.where(u_np1[:-1, :] > 0, eta_n[:-1, :] + H, eta_n[1:, :] + H)
h_n[:, :-1] = np.where(v_np1[:, :-1] > 0, eta_n[:, :-1] + H, eta_n[:, 1:] + H)
h_n[:, -1] = eta_n[:, -1] + H
h_s[:, 0] = eta_n[:, 0] + H
h_s[:, 1:] = np.where(v_np1[:, :-1] > 0, eta_n[:, :-1] + H, eta_n[:, 1:] + H)
uhwe[0, :] = u_np1[0, :]*h_e[0, :]
uhwe[1:, :] = u_np1[1:, :]*h_e[1:, :] - u_np1[:-1, :]*h_w[1:, :]
vhns[:, 0] = v_np1[:, 0]*h_n[:, 0]
vhns[:, 1:] = v_np1[:, 1:]*h_n[:, 1:] - v_np1[:, :-1]*h_s[:, 1:]
eta_np1[:, :] = eta_n[:, :] - dt*(uhwe[:, :]/dx + vhns[:, :]/dy)
if (use_source is True):
eta_np1[:, :] += dt*sigma
if (use_sink is True):
eta_np1[:, :] -= dt*w
u_n = np.copy(u_np1)
v_n = np.copy(v_np1)
eta_n = np.copy(eta_np1)
time_step += 1
if (time_step % sample_interval == 0):
hm_sample.append(eta_n[:, int(N_y/2)])
ts_sample.append(eta_n[int(N_x/2), int(N_y/2)])
t_sample.append(time_step*dt)
if (time_step % anim_interval == 0):
print("Time: \t{:.2f} hours".format(time_step*dt/3600))
print("Step: \t{} / {}".format(time_step, max_time_step))
print("Mass: \t{}\n".format(np.sum(eta_n)))
u_list.append(u_n)
v_list.append(v_n)
eta_list.append(eta_n)