|
1 | 1 | import numpy as np
|
2 | 2 | import sympy as sp
|
| 3 | +from sympy import hankel1 |
3 | 4 |
|
4 | 5 | from sumpy.expansion.diff_op import (
|
5 | 6 | laplacian,
|
|
8 | 9 | from sumpy.recurrenceqbx import recurrence_qbx_lp, _make_sympy_vec
|
9 | 10 | from sumpy.array_context import PytestPyOpenCLArrayContextFactory, _acf # noqa: F401
|
10 | 11 | from sumpy.expansion.local import LineTaylorLocalExpansion, VolumeTaylorLocalExpansion
|
11 |
| -from sumpy.kernel import LaplaceKernel |
| 12 | +from sumpy.kernel import LaplaceKernel, HelmholtzKernel |
12 | 13 | from sumpy.qbx import LayerPotential
|
13 | 14 |
|
14 | 15 | actx_factory = _acf
|
15 | 16 | expn_class = LineTaylorLocalExpansion
|
16 | 17 |
|
17 | 18 | actx = actx_factory()
|
18 | 19 | lknl = LaplaceKernel(2)
|
| 20 | +hlknl = HelmholtzKernel(2, "k") |
| 21 | + |
| 22 | +def _qbx_lp_helmholtz_general(sources,targets,centers,radius,strengths,order): |
| 23 | + lpot = LayerPotential(actx.context, |
| 24 | + expansion=expn_class(hlknl, order), |
| 25 | + target_kernels=(hlknl,), |
| 26 | + source_kernels=(hlknl,)) |
| 27 | + |
| 28 | + #print(lpot.get_kernel()) |
| 29 | + expansion_radii = actx.from_numpy(radius * np.ones(sources.shape[1])) |
| 30 | + sources = actx.from_numpy(sources) |
| 31 | + targets = actx.from_numpy(targets) |
| 32 | + centers = actx.from_numpy(centers) |
| 33 | + |
| 34 | + strengths = (strengths,) |
| 35 | + extra_kernel_kwargs={"k": 1} |
| 36 | + _evt, (result_qbx,) = lpot( |
| 37 | + actx.queue, |
| 38 | + targets, sources, centers, strengths, |
| 39 | + expansion_radii=expansion_radii, |
| 40 | + kwargs=extra_kernel_kwargs) |
| 41 | + result_qbx = actx.to_numpy(result_qbx) |
| 42 | + |
| 43 | + return result_qbx |
| 44 | + |
19 | 45 |
|
20 | 46 | def _qbx_lp_laplace_general(sources,targets,centers,radius,strengths,order):
|
21 | 47 | lpot = LayerPotential(actx.context,
|
@@ -78,4 +104,28 @@ def test_recurrence_laplace_2d_ellipse():
|
78 | 104 | err.append(np.max(np.abs(exp_res - qbx_res)))
|
79 | 105 | assert np.max(err) <= 1e-13
|
80 | 106 |
|
81 |
| -test_recurrence_laplace_2d_ellipse() |
| 107 | + |
| 108 | +def test_recurrence_helmholtz_2d_ellipse(): |
| 109 | + |
| 110 | + #------------- 1. Define PDE, Green's Function |
| 111 | + w = make_identity_diff_op(2) |
| 112 | + helmholtz2d = laplacian(w) + w |
| 113 | + |
| 114 | + var = _make_sympy_vec("x", 2) |
| 115 | + var_t = _make_sympy_vec("t", 2) |
| 116 | + k = 1 |
| 117 | + abs_dist = sp.sqrt((var[0]-var_t[0])**2 + (var[1]-var_t[1])**2) |
| 118 | + g_x_y = (1j/4) * hankel1(0, k * abs_dist) |
| 119 | + |
| 120 | + p = 4 |
| 121 | + err = [] |
| 122 | + for n_p in range(200, 1001, 200): |
| 123 | + sources, centers, normals, density, h, radius = _create_ellipse(n_p) |
| 124 | + strengths = h * density |
| 125 | + exp_res = recurrence_qbx_lp(sources, centers, normals, strengths, radius, helmholtz2d, g_x_y, 2, p) |
| 126 | + #qbx_res = _qbx_lp_helmholtz_general(sources, sources, centers, radius, strengths, p) |
| 127 | + #qbx_res,_ = lpot_eval_circle(sources.shape[1], p) |
| 128 | + #err.append(np.max(np.abs(exp_res - qbx_res))) |
| 129 | + #assert np.max(err) <= 1e-13 |
| 130 | + |
| 131 | +test_recurrence_helmholtz_2d_ellipse() |
0 commit comments