k = 8 * np.pi / 3 solution_func = lambda x, y: -np.cos(x) * np.exp(np.sin(x)) * np.sin(y) force_func = lambda x, y: (2.0 * np.cos(x) + 3.0 * np.cos(x) * np.sin(x) - np. cos(x)**3) * np.exp(np.sin(x)) * np.sin(y) # solution_func = lambda x, y: np.exp(np.sin(k*x))*np.sin(k*y) # force_func = lambda x, y: k**2*np.exp(np.sin(k*x))*np.sin(k*y)*(np.cos(k*x)**2-np.sin(k*x)-1.0) f = force_func(ebdyc.grid.xg, ebdyc.grid.yg) * ebdyc.phys frs = [force_func(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdyc] ua = solution_func(ebdyc.grid.xg, ebdyc.grid.yg) * ebdyc.phys uars = [solution_func(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdyc] uar = uars[0] bcs2v = solution_func(ebdyc.all_bvx, ebdyc.all_bvy) bcs2l = ebdyc.v2l(bcs2v) ################################################################################ # Setup Poisson Solver solver = PoissonSolver(ebdyc, solver_type=solver_type) ue, uers = solver(f, frs, tol=1e-14, verbose=verbose) uer = uers[0] mue = np.ma.array(ue, mask=ebdyc.ext) if plot: fig, ax = plt.subplots() ax.pcolormesh(grid.xg, grid.yg, mue) ax.plot(ebdy.bdy.x, ebdy.bdy.y, color='black', linewidth=3) ax.plot(ebdy.interface.x, ebdy.interface.y, color='white', linewidth=3)
solution_func = lambda x, y: np.exp(np.sin(k * x)) * np.sin(k * y) solution_func_x = lambda x, y: k * np.cos(k * x) * np.exp(np.sin(k * x) ) * np.sin(k * y) solution_func_y = lambda x, y: k * np.exp(np.sin(k * x)) * np.cos(k * y) solution_func_n = lambda x, y, nx, ny: solution_func_x( x, y) * nx + solution_func_y(x, y) * ny force_func = lambda x, y: helmholtz_k**2 * solution_func(x, y) - k**2 * np.exp( np.sin(k * x)) * np.sin(k * y) * (np.cos(k * x)**2 - np.sin(k * x) - 1.0) f = force_func(grid.xg, grid.yg) frs = [force_func(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] ua = solution_func(grid.xg, grid.yg) uars = [solution_func(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] all_nx = np.concatenate([ebdy.bdy.normal_x for ebdy in ebdys]) all_ny = np.concatenate([ebdy.bdy.normal_y for ebdy in ebdys]) bcs2v = solution_func_n(ebdyc.all_bvx, ebdyc.all_bvy, all_nx, all_ny) bcs2l = ebdyc.v2l(bcs2v) ################################################################################ # Setup Poisson Solver print('Creating inhomogeneous solver') solver = ModifiedHelmholtzSolver(ebdyc, solver_type=solver_type, k=helmholtz_k) print('Solving inhomogeneous problem') ue, uers = solver(f, frs, tol=1e-12, verbose=verbose) print('Solving homogeneous problem') # this isn't correct yet because we haven't applied boundary conditions def two_d_split(MAT, hsplit, vsplit): vsplits = np.vsplit(MAT, vsplit)
# Interpolation of a globally smooth function on grid to radial f = test_func(grid.xg, grid.yg) frs = [test_func(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] fev = ebdyc.interpolate_grid_to_radial(f, order=5) fes = ebdyc.v2r(fev) errs = [np.abs(fe - fr).max() for fe, fr in zip(fes, frs)] err = max(errs) print('Error in grid --> radial interpolation: {:0.2e}'.format(err)) f *= ebdyc.phys # Interpolation of a function to the interface (3rd order) frs = [test_func(ebdy.interface.x, ebdy.interface.y) for ebdy in ebdys] fev = ebdyc.interpolate_grid_to_interface(f, order=3, cutoff=False) fes = ebdyc.v2l(fev) errs = [np.abs(fe - fr).max() for fe, fr in zip(fes, frs)] err = max(errs) print('Error in grid --> interface interpolation: {:0.2e}'.format(err)) # Interpolation of a function to the interface (NUFFT) frs = [test_func(ebdy.interface.x, ebdy.interface.y) for ebdy in ebdys] fev = ebdyc.interpolate_grid_to_interface(f, order=np.Inf, cutoff=True) fes = ebdyc.v2l(fev) errs = [np.abs(fe - fr).max() for fe, fr in zip(fes, frs)] err = max(errs) print('Error in grid --> interface interpolation: {:0.2e}'.format(err)) # Interpolation of a function from radial to grid frs = [test_func(ebdy.radial_x, ebdy.radial_y) for ebdy in ebdys] fts = ebdyc.interpolate_radial_to_grid(frs)
MATS[1][0][:] = d_only(bdy1, bdy2) + Stokes_Pressure_Fix(bdy1, bdy2) MATS[1][1][:] = cd_singular(bdy2) + half_eye(bdy2) + Stokes_Pressure_Fix( bdy2, bdy2) * 0.0 MATS[1][2][:] = c_and_d(bdy3, bdy2) + Stokes_Pressure_Fix(bdy3, bdy2) * 0.0 MATS[2][0][:] = d_only(bdy1, bdy3) + Stokes_Pressure_Fix(bdy1, bdy3) MATS[2][1][:] = c_and_d(bdy2, bdy3) + Stokes_Pressure_Fix(bdy2, bdy3) * 0.0 MATS[2][2][:] = cd_singular(bdy3) + half_eye(bdy3) + Stokes_Pressure_Fix( bdy3, bdy3) * 0.0 bu = solver.get_boundary_values(urs) bv = solver.get_boundary_values(vrs) bu_adj = upper_u - bu bv_adj = upper_v - bv bu_adj = ebdyc.v2l(bu_adj) bv_adj = ebdyc.v2l(bv_adj) bc_adj = np.concatenate( [np.concatenate([bu_a, bv_a]) for bu_a, bv_a in zip(bu_adj, bv_adj)]) tau = np.linalg.solve(MAT, bc_adj) taul = ebdyc.v2l2(tau) def v2f(x): return x.reshape(2, x.size // 2) # get effective sources qfs_list = [] Naive_SLP = lambda src, trg: Stokes_Layer_Form(src, trg, ifforce=True) Fixed_SLP = lambda src, trg: Naive_SLP(src, trg) + Stokes_Pressure_Fix(