def ext_helmholtz_convg(qbx_order, k): """ Tests external Helmholtz solution by placing monopoles inside domain """ alpha = k # CFIE parameter sp, dp, qbx_exp_slp, qbx_exp_dlp, _, _, _, _ = eval_sp_dp_QBX(qbx_order, k) xs = 0.75 ys = 1.75 test_targets = np.array([[-1, 0], [4, 0], [0, -1], [0, 4]]).T # test_targets = np.array([[-5, 0], [5, 0], [0, -5], [0, 5]]).T exact_test = sp(test_targets[0], test_targets[1], xs, ys) plotset() n_panels = np.arange(10, 60, 5) convg_err = [] for n in n_panels: domain = QuadratureInfo(n, show_bound=0) rhs = sp(domain.curve_nodes[0], domain.curve_nodes[1], xs, ys) soln = bvp(n, k, domain, alpha, qbx_exp_slp, qbx_exp_dlp, rhs) num_test = eval_target( test_targets, domain.curve_nodes, domain.curve_weights, domain.normals, soln, sp, dp, alpha, ) er = la.norm( np.abs(num_test - exact_test) / la.norm(np.abs(exact_test))) convg_err.append(er) plt.figure(1) plt.loglog(n_panels, np.array(convg_err), "-o", label="QBX" + str(qbx_order)) plt.loglog( n_panels, 5e4 * np.power(n_panels.astype(float), -qbx_order - 1), label="$N^{-5}$", ) plt.loglog(n_panels, 2e3 * np.power(n_panels.astype(float), -qbx_order), label="$N^{-4}$") title = "Helmholtz exterior problem: target evaluation convergence" plt.xlabel("Number of panels", size=25) plt.ylabel("$|u - u_e| / |u_e|$", size=25) plt.title(title, size=25) plt.legend(loc="upper right", ncol=1, frameon=True) plt.show() slope, _, _, _, _ = stats.linregress(np.log(n_panels), np.log(np.array(convg_err))) print(slope)
def main(): k = 10 alpha = k # CFIE parameter sp, dp, qbx_exp_slp, qbx_exp_dlp, _, _, _, _ = eval_sp_dp_QBX(4, k) npanels = 30 domain = QuadratureInfo(npanels, show_bound=1) xs = 0.75 ys = 1.75 tg_size = 101 x = np.linspace(-2, 5, tg_size) y = np.linspace(-2, 5, tg_size) X, Y = np.meshgrid(x, y) test_targets = np.array((X.reshape(-1), Y.reshape(-1))) rhs = sp(domain.curve_nodes[0], domain.curve_nodes[1], xs, ys) soln1 = bvp(npanels, k, domain, alpha, qbx_exp_slp, qbx_exp_dlp, rhs) num_test = eval_target( test_targets, domain.curve_nodes, domain.curve_weights, domain.normals, soln1, sp, dp, alpha, ).reshape(tg_size, -1) exact_test = sp(test_targets[0], test_targets[1], xs, ys).reshape(tg_size, -1) err = np.abs(num_test - exact_test) / np.abs(exact_test) # plt.contourf(X, Y, np.real(exact_test), cmap='magma', levels=100) v = np.linspace(-0.15, 0.15, 100, endpoint=True) plt.figure(1) plt.contourf(X, Y, np.real(num_test), v, cmap="twilight") plt.plot(xs, ys, "ro") plt.fill(domain.curve_nodes[0], domain.curve_nodes[1], "w") show_targets = np.array([[-1, 0], [4, 0], [0, -1], [0, 4]]).T plt.plot(show_targets[0], show_targets[1], "go") plt.xlabel("X", size=10) plt.ylabel("Y", size=10) plt.colorbar() plt.figure(2) plt.contourf(X, Y, np.log10(err), cmap="magma", levels=200) plt.fill(domain.curve_nodes[0], domain.curve_nodes[1], "w") plt.plot(xs, ys, "ro") plt.plot(show_targets[0], show_targets[1], "go") plt.xlabel("X", size=10) plt.ylabel("Y", size=10) plt.colorbar() plt.show()
import matplotlib.pyplot as plt import numpy as np # import numpy.linalg as la from kernels import eval_sp_dp_QBX, sommerfeld, Images_Integral plt.gca().set_aspect("equal") k = 10.2 alpha = k # CFIE parameter beta = 2.04 interval = 20 xs = 0 ys = 5 m = int(np.ceil(np.log(k / ys) / np.log(2))) (sp, dp, qbx_exp_slp, qbx_exp_dlp, img_sp, img_dp, _, _) = eval_sp_dp_QBX(4, k) som_sp, som_dp = sommerfeld(k, beta, interval, "far") imgs = Images_Integral(m, beta, img_sp, img_dp) tg_size = 101 x = np.linspace(-5, 5, tg_size) y = np.linspace(0, 10, tg_size) X, Y = np.meshgrid(x, y) test_targets = np.array((X.reshape(-1), Y.reshape(-1))) exact_test = sp(test_targets[0], test_targets[1], xs, ys).reshape(tg_size, -1) som_test = som_sp(test_targets[0], test_targets[1], xs, ys).reshape(tg_size, -1) imag_sp, imag_dp = imgs.eval_integral(test_targets, (xs, ys), 0.0, 0.0) imag_sp = imag_sp.reshape(tg_size, -1) v = np.linspace(-0.15, 0.15, 100, endpoint=True) plt.figure(1)
import matplotlib.pyplot as plt import numpy as np from plotset import plotset import numpy.linalg as la from kernels import eval_sp_dp_QBX from kernels import Images_Integral plotset() xs = -2 ys = 0.1 k = 10 alpha = k # CFIE parameter beta = 2 (_, _, _, _, img_sp, img_dp, _, _) = eval_sp_dp_QBX(4, k) convg_err = [] test_targets = np.array([[-2, 0.01], [0, 5], [-2, 4]]).T C = 1 m = int(np.floor(np.log(k / ys * C) / np.log(2))) for x in range(1, m + 1): imgs = Images_Integral(x, beta, img_sp, img_dp) num_test, _ = imgs.eval_integral(test_targets, (xs, ys), 0.0, 0.0) convg_err.append(num_test) print(x) print(la.norm(num_test)) convg = np.array((convg_err)) num_fine = convg[-1] convg = convg[:-1] - num_fine convg_norm = [] for x in convg:
import matplotlib.pyplot as plt import numpy as np # import numpy.linalg as la from kernels import eval_sp_dp_QBX, sommerfeld plt.gca().set_aspect("equal") k = 10 alpha = k # CFIE parameter beta = 0 interval = 10 xs = 0 ys = 5 sp, dp, _, _, _, _, _, _ = eval_sp_dp_QBX(4, k) som_sp, _ = sommerfeld(k, beta, interval, "full") tg_size = 101 x = np.linspace(-5, 5, tg_size) y = np.linspace(0, 10, tg_size) X, Y = np.meshgrid(x, y) test_targets = np.array((X.reshape(-1), Y.reshape(-1))) exact_test = sp(test_targets[0], test_targets[1], xs, ys).reshape(tg_size, -1) som_test = som_sp(test_targets[0], test_targets[1], xs, ys).reshape(tg_size, -1) v = np.linspace(-0.15, 0.15, 100, endpoint=True) # plt.contourf(X, Y, np.real(exact_test), v, # cmap='magma', extend='both') plt.figure(1) plt.contourf(X, Y, np.real(exact_test), v, cmap="twilight") plt.colorbar()