From 673a79659aefb7d8eaccb89c95947f193ca045e2 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 4 Nov 2024 16:00:03 -0600 Subject: [PATCH] Port towards actx --- test/test_recurrenceqbx.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/test/test_recurrenceqbx.py b/test/test_recurrenceqbx.py index 788f41494..c2f5eb565 100644 --- a/test/test_recurrenceqbx.py +++ b/test/test_recurrenceqbx.py @@ -6,8 +6,13 @@ import numpy as np import sympy as sp - from sympy import hankel1 + +from arraycontext import ( + ArrayContext, + pytest_generate_tests_for_array_contexts, +) + from sumpy.array_context import _acf from sumpy.expansion.diff_op import ( laplacian, @@ -19,10 +24,11 @@ from sumpy.recurrenceqbx import _make_sympy_vec, recurrence_qbx_lp -actx_factory = _acf +pytest_generate_tests = pytest_generate_tests_for_array_contexts([ + "pytato:pyopencl", + ]) ExpnClass = LineTaylorLocalExpansion -actx = actx_factory() lknl = LaplaceKernel(2) hlknl = HelmholtzKernel(2, "k") @@ -74,29 +80,32 @@ def _qbx_lp_laplace_general(sources, targets, centers, radius, strengths, order) return result_qbx -def _create_ellipse(n_p): +def _create_ellipse(actx: ArrayContext, n_p): h = 9.688 / n_p radius = 7*h - t = np.linspace(0, 2 * np.pi, n_p, endpoint=False) + t = actx.np.linspace(0, 2 * np.pi, n_p, endpoint=False) - unit_circle_param = np.exp(1j * t) - unit_circle = np.array([2 * unit_circle_param.real, unit_circle_param.imag]) + unit_circle_param = actx.np.exp(1j * t) + unit_circle = actx.np.stack([2 * unit_circle_param.real, unit_circle_param.imag], + axis=0) sources = unit_circle - normals = np.array([unit_circle_param.real, 2*unit_circle_param.imag]) - normals = normals / np.linalg.norm(normals, axis=0) + normals = actx.np.stack([unit_circle_param.real, 2*unit_circle_param.imag], axis=0) + # normals = normals / actx.np.linalg.norm(normals, axis=0) + normals = normals / np.sum(actx.np.sum(normals**2, axis=0)) centers = sources - normals * radius mode_nr = 25 - density = np.cos(mode_nr * t) + density = actx.np.cos(mode_nr * t) return sources, centers, normals, density, h, radius -def test_recurrence_laplace_2d_ellipse(): +def test_recurrence_laplace_2d_ellipse(actx_factory): r""" Tests recurrence + qbx code. """ + actx = actx_factory() # ------------- 1. Define PDE, Green's Function w = make_identity_diff_op(2) @@ -110,7 +119,7 @@ def test_recurrence_laplace_2d_ellipse(): p = 4 err = [] for n_p in range(200, 1001, 200): - sources, centers, normals, density, h, radius = _create_ellipse(n_p) + sources, centers, normals, density, h, radius = _create_ellipse(actx, n_p) strengths = h * density exp_res = recurrence_qbx_lp(sources, centers, normals, strengths, radius, laplace2d,