From fcc98682fe5e2650c4ff17254cdd1d11da935bb9 Mon Sep 17 00:00:00 2001 From: Alex Fikl Date: Sun, 10 Jun 2018 15:18:23 -0500 Subject: [PATCH 1/3] matrix: flatten resampler and test on refined geometry --- pytential/symbolic/matrix.py | 6 ++++-- test/test_matrix.py | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pytential/symbolic/matrix.py b/pytential/symbolic/matrix.py index 84cd46ce..1b1ca5d6 100644 --- a/pytential/symbolic/matrix.py +++ b/pytential/symbolic/matrix.py @@ -198,8 +198,10 @@ class MatrixBuilder(EvaluationMapperBase): waa = source.weights_and_area_elements().get(queue=self.queue) mat[:, :] *= waa - resample_mat = ( - source.resampler.full_resample_matrix(self.queue).get(self.queue)) + from meshmode.discretization.connection import flatten_chained_connection + resampler = flatten_chained_connection(self.queue, source.resampler) + resample_mat = resampler.full_resample_matrix(self.queue).get(self.queue) + mat = mat.dot(resample_mat) mat = mat.dot(rec_density) diff --git a/test/test_matrix.py b/test/test_matrix.py index 1d04789d..9f0ff0b4 100644 --- a/test/test_matrix.py +++ b/test/test_matrix.py @@ -26,9 +26,8 @@ import numpy as np import numpy.linalg as la import pyopencl as cl import pytest -from meshmode.mesh.generation import ( # noqa - ellipse, cloverleaf, starfish, drop, n_gon, qbx_peanut, - make_curve_mesh) +from meshmode.mesh.generation import \ + ellipse, NArmedStarfish, make_curve_mesh from pytential import bind, sym from functools import partial from sumpy.symbolic import USE_SYMENGINE @@ -40,10 +39,12 @@ from pyopencl.tools import ( # noqa @pytest.mark.skipif(USE_SYMENGINE, reason="https://gitlab.tiker.net/inducer/sumpy/issues/25") -@pytest.mark.parametrize(("k", "layer_pot_id"), - [(0, 1), (0, 2), - (42, 1), (42, 2)]) -def test_matrix_build(ctx_factory, k, layer_pot_id, visualize=False): +@pytest.mark.parametrize("k", [0, 42]) +@pytest.mark.parametrize("curve_f", [ + partial(ellipse, 3), + NArmedStarfish(5, 0.25)]) +@pytest.mark.parametrize("layer_pot_id", [1, 2]) +def test_matrix_build(ctx_factory, k, curve_f, layer_pot_id, visualize=False): cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) @@ -54,7 +55,6 @@ def test_matrix_build(ctx_factory, k, layer_pot_id, visualize=False): target_order = 7 qbx_order = 4 nelements = 30 - curve_f = partial(ellipse, 3) from sumpy.kernel import LaplaceKernel, HelmholtzKernel if k: @@ -106,7 +106,8 @@ def test_matrix_build(ctx_factory, k, layer_pot_id, visualize=False): if visualize: from sumpy.tools import build_matrix as build_matrix_via_matvec - mat2 = build_matrix_via_matvec(bound_op.scipy_op(queue, "u")) + mat2 = bound_op.scipy_op(queue, "u", dtype=mat.dtype, **knl_kwargs) + mat2 = build_matrix_via_matvec(mat2) print(la.norm((mat - mat2).real, "fro") / la.norm(mat2.real, "fro"), la.norm((mat - mat2).imag, "fro") / la.norm(mat2.imag, "fro")) @@ -135,7 +136,7 @@ def test_matrix_build(ctx_factory, k, layer_pot_id, visualize=False): if is_obj_array(u_sym): u = make_obj_array([ np.random.randn(density_discr.nnodes) - for i in range(len(u_sym)) + for _ in range(len(u_sym)) ]) else: u = np.random.randn(density_discr.nnodes) -- GitLab From 41a3ad84d683c6c53d5a883306b2c3e83042331e Mon Sep 17 00:00:00 2001 From: Alex Fikl Date: Wed, 13 Jun 2018 16:43:19 -0500 Subject: [PATCH 2/3] matrix: move flattening the resampler to QBXLayerPotentialSource --- pytential/qbx/__init__.py | 23 +++++++++++++++++++++++ pytential/symbolic/matrix.py | 3 +-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pytential/qbx/__init__.py b/pytential/qbx/__init__.py index ff4c1ade..c86d78fa 100644 --- a/pytential/qbx/__init__.py +++ b/pytential/qbx/__init__.py @@ -375,6 +375,29 @@ class QBXLayerPotentialSource(LayerPotentialSourceBase): return conn + @property + @memoize_method + def direct_resampler(self): + """ + .. warning:: + + This always returns a + :class:`~meshmode.discretization.connection.DirectDiscretizationConnect`. + In case the geometry has been refined multiple times, a direct + connection can have a large number of groups and/or + interpolation batches, making the single connection scale + significantly worse than the one returned by :attr:`resampler`. + + """ + from meshmode.discretization.connection import \ + flatten_chained_connection + + conn = self.resampler + with cl.CommandQueue(self.cl_context) as queue: + conn = flatten_chained_connection(queue, conn) + + return conn + @property @memoize_method def tree_code_container(self): diff --git a/pytential/symbolic/matrix.py b/pytential/symbolic/matrix.py index 1b1ca5d6..f0b1d82f 100644 --- a/pytential/symbolic/matrix.py +++ b/pytential/symbolic/matrix.py @@ -198,8 +198,7 @@ class MatrixBuilder(EvaluationMapperBase): waa = source.weights_and_area_elements().get(queue=self.queue) mat[:, :] *= waa - from meshmode.discretization.connection import flatten_chained_connection - resampler = flatten_chained_connection(self.queue, source.resampler) + resampler = source.direct_resampler resample_mat = resampler.full_resample_matrix(self.queue).get(self.queue) mat = mat.dot(resample_mat) -- GitLab From 4537381ac4e324fa7a146a5066a9c8e423b07bea Mon Sep 17 00:00:00 2001 From: Alex Fikl Date: Wed, 13 Jun 2018 16:49:02 -0500 Subject: [PATCH 3/3] qbx: better phrasing --- pytential/qbx/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pytential/qbx/__init__.py b/pytential/qbx/__init__.py index c86d78fa..d3cd843a 100644 --- a/pytential/qbx/__init__.py +++ b/pytential/qbx/__init__.py @@ -385,9 +385,8 @@ class QBXLayerPotentialSource(LayerPotentialSourceBase): :class:`~meshmode.discretization.connection.DirectDiscretizationConnect`. In case the geometry has been refined multiple times, a direct connection can have a large number of groups and/or - interpolation batches, making the single connection scale - significantly worse than the one returned by :attr:`resampler`. - + interpolation batches, making it scale significantly worse than + the one returned by :attr:`resampler`. """ from meshmode.discretization.connection import \ flatten_chained_connection -- GitLab