def jump_condition(x,y,u): u_desired = desired_func(x,y) u_n_desired = hf.norm_grad(u_desired,(x,y),lvl_func) #for Robin boundary condition only def sigma(x,y): return -0.25 * (hf.XYtoR(x-x0, y-y0)+10**-17) sigma_Robin = sigma(x, y) g_Robin = u_desired + sigma_Robin * u_n_desired ################################# if(bnd_type == "Dirichlet"): a_mesh = - u_desired b_mesh = - beta_m * hf.grad_frame(u,(x,y),lvl_func) elif(bnd_type == "Neumann"): a_mesh = - u b_mesh = - beta_m * u_n_desired elif(bnd_type == "Robin_u"): a_mesh = - u b_mesh = - beta_m * (g_Robin - u)/sigma_Robin elif(bnd_type == "Robin_u_n"): a_mesh = -(g_Robin - sigma_Robin*u_n_desired) b_mesh = - beta_m * hf.grad_frame(u,(x,y),lvl_func) elif(bnd_type == "exact"): a_mesh = - u_desired b_mesh = - beta_m * u_n_desired else: raise Exception("error: invalid boundary format") return (a_mesh, b_mesh)
global jmp_func jmp_func = jump_condition if (__name__ == "__main__"): ##generate poisson solver plt.close("all") initialize("u_n") u_cur_result = sol_func(xmesh, ymesh) for i in range(4): initialize("u_n") u_result = ps.poisson_jacobi_solver(u_cur_result, 200000, (xmesh, ymesh), (beta_p, beta_m), rhs_func, lvl_func, jmp_func) u_n_result = hf.grad_frame(u_result, (xmesh, ymesh), lvl_func) # plt.matshow(u_n_result) # plt.colorbar() fig_label = i hf.plot3d_all(u_result, (xmesh, ymesh), sol_func, fig_label, [True, True, True, True]) u_cur_result = u_result # initialize() # u_result2 = poisson_jacobi_solver(u_result1, 100000, (xmesh,ymesh), (beta_p, beta_m),rhs_func, lvl_func, jmp_func) # u_n_result2 = grad_frame(u_result2, (xmesh, ymesh), lvl_func) # plt.matshow(u_n_result2) # plt.colorbar() # plot3d_all(u_result2, (xmesh, ymesh), sol_func,[False, False,False,True]) # b_mesh = -beta_m * u_n[:,:] # a_mesh = -(get_u_from_un(u_n, xmesh, ymesh)) ## formulism 2
global jmp_func jmp_func = jump_condition ###################################################################### if (__name__ == "__main__"): ##generate poisson solver plt.close("all") setup_grid(101) u_cur_result = u_init for i in range(10): setup_equations("Dirichlet") u_result = ps.poisson_jacobi_solver(u_cur_result, 200000, (xmesh, ymesh), (beta_p, beta_m), rhs_func, lvl_func, jmp_func) u_n_result = hf.grad_frame(u_result, (xmesh, ymesh), lvl_func) # plt.matshow(u_n_result) # plt.colorbar() fig_label = i hf.plot3d_all(u_result, (xmesh, ymesh), sol_func, fig_label, [False, False, False, True]) hf.print_error(u_result, (xmesh, ymesh), sol_func) u_cur_result = u_result u_n_result = hf.grad_frame(u_result, (xmesh, ymesh), lvl_func) u_n_anal = hf.grad_frame(sol_func(xmesh, ymesh), (xmesh, ymesh), lvl_func) plt.matshow(u_n_result - u_n_anal) print(hf.L_n_norm(np.abs(u_n_result - u_n_anal), 2)) # initialize() # u_result2 = poisson_jacobi_solver(u_result1, 100000, (xmesh,ymesh), (beta_p, beta_m),rhs_func, lvl_func, jmp_func) # u_n_result2 = grad_frame(u_result2, (xmesh, ymesh), lvl_func)