From b060af817beff2620c78a0af1819a40007156316 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Jun 2017 12:14:56 -0400 Subject: [PATCH 1/9] Shrink 'tunnel of danger' to h/4 --- pytential/qbx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytential/qbx/__init__.py b/pytential/qbx/__init__.py index 5292f7bb..363a783f 100644 --- a/pytential/qbx/__init__.py +++ b/pytential/qbx/__init__.py @@ -300,7 +300,7 @@ class QBXLayerPotentialSource(LayerPotentialSource): @memoize_method def _close_target_tunnel_radius(self, last_dim_length): with cl.CommandQueue(self.cl_context) as queue: - return (self._panel_sizes(last_dim_length).with_queue(queue) * 0.5 + return (self._panel_sizes(last_dim_length).with_queue(queue) * 0.25 ).with_queue(None) @memoize_method -- GitLab From 6deb70776972185ef8b2a5c6a3e45fee6335e3f0 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Jun 2017 12:19:21 -0400 Subject: [PATCH 2/9] =?UTF-8?q?Only=20use=20QBX=C2=A0expansion=20for=20vol?= =?UTF-8?q?ume=20targets=20when=20required=20by=20'tunnel=20of=20danger'?= =?UTF-8?q?=20(#52=20on=20Gitlab)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytential/qbx/target_assoc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytential/qbx/target_assoc.py b/pytential/qbx/target_assoc.py index f30dda41..4d6664bd 100644 --- a/pytential/qbx/target_assoc.py +++ b/pytential/qbx/target_assoc.py @@ -223,7 +223,8 @@ QBX_CENTER_FINDER = AreaQueryElementwiseTemplate( if (my_dist_to_center <= expansion_radii_by_center_with_stick_out[center] - && my_dist_to_center < min_dist_to_center[i]) + && my_dist_to_center < min_dist_to_center[i] + && target_status[i] == MARKED_QBX_CENTER_PENDING) { target_status[i] = MARKED_QBX_CENTER_FOUND; min_dist_to_center[i] = my_dist_to_center; -- GitLab From 1336d8aceba192b9d29b262765c963151cfee4ea Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Jun 2017 12:31:51 -0400 Subject: [PATCH 3/9] Revert "Shrink 'tunnel of danger' to h/4" This reverts commit b060af817beff2620c78a0af1819a40007156316. --- pytential/qbx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytential/qbx/__init__.py b/pytential/qbx/__init__.py index 363a783f..5292f7bb 100644 --- a/pytential/qbx/__init__.py +++ b/pytential/qbx/__init__.py @@ -300,7 +300,7 @@ class QBXLayerPotentialSource(LayerPotentialSource): @memoize_method def _close_target_tunnel_radius(self, last_dim_length): with cl.CommandQueue(self.cl_context) as queue: - return (self._panel_sizes(last_dim_length).with_queue(queue) * 0.25 + return (self._panel_sizes(last_dim_length).with_queue(queue) * 0.5 ).with_queue(None) @memoize_method -- GitLab From 3f8335ddea1556bdbd8a989244976585828a3c61 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Jun 2017 21:19:42 -0400 Subject: [PATCH 4/9] Target assoc: Avoid whole center finding loop for centers not marked pending --- pytential/qbx/target_assoc.py | 54 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/pytential/qbx/target_assoc.py b/pytential/qbx/target_assoc.py index 4d6664bd..158b930c 100644 --- a/pytential/qbx/target_assoc.py +++ b/pytential/qbx/target_assoc.py @@ -194,7 +194,7 @@ QBX_CENTER_FINDER = AreaQueryElementwiseTemplate( coord_t *particles_${ax}, %endfor """, - ball_center_and_radius_expr=QBX_TREE_C_PREAMBLE + QBX_TREE_MAKO_DEFS + r""" + ball_center_and_radius_expr=QBX_TREE_C_PREAMBLE + QBX_TREE_MAKO_DEFS + r"""//CL// coord_vec_t tgt_coords; ${load_particle("INDEX_FOR_TARGET_PARTICLE(i)", "tgt_coords")} { @@ -203,32 +203,36 @@ QBX_CENTER_FINDER = AreaQueryElementwiseTemplate( ${ball_radius} = box_to_search_dist[my_box]; } """, - leaf_found_op=QBX_TREE_MAKO_DEFS + r""" - for (particle_id_t center_idx = box_to_center_starts[${leaf_box_id}]; - center_idx < box_to_center_starts[${leaf_box_id} + 1]; - ++center_idx) + leaf_found_op=QBX_TREE_MAKO_DEFS + r"""//CL// + if (target_status[i] == MARKED_QBX_CENTER_PENDING) { - particle_id_t center = box_to_center_lists[center_idx]; - int center_side = SIDE_FOR_CENTER_PARTICLE(center); - - // Sign of side should match requested target sign. - if (center_side * target_flags[i] < 0) - { - continue; - } - - coord_vec_t center_coords; - ${load_particle("INDEX_FOR_CENTER_PARTICLE(center)", "center_coords")} - coord_t my_dist_to_center = distance(tgt_coords, center_coords); - - if (my_dist_to_center - <= expansion_radii_by_center_with_stick_out[center] - && my_dist_to_center < min_dist_to_center[i] - && target_status[i] == MARKED_QBX_CENTER_PENDING) + for (particle_id_t center_idx = box_to_center_starts[${leaf_box_id}]; + center_idx < box_to_center_starts[${leaf_box_id} + 1]; + ++center_idx) { - target_status[i] = MARKED_QBX_CENTER_FOUND; - min_dist_to_center[i] = my_dist_to_center; - target_to_center[i] = center; + particle_id_t center = box_to_center_lists[center_idx]; + + int center_side = SIDE_FOR_CENTER_PARTICLE(center); + + // Sign of side should match requested target sign. + if (center_side * target_flags[i] < 0) + { + continue; + } + + coord_vec_t center_coords; + ${load_particle( + "INDEX_FOR_CENTER_PARTICLE(center)", "center_coords")} + coord_t my_dist_to_center = distance(tgt_coords, center_coords); + + if (my_dist_to_center + <= expansion_radii_by_center_with_stick_out[center] + && my_dist_to_center < min_dist_to_center[i]) + { + target_status[i] = MARKED_QBX_CENTER_FOUND; + min_dist_to_center[i] = my_dist_to_center; + target_to_center[i] = center; + } } } """, -- GitLab From 5067e795a3ed053617db95763c634dafbe7cbf67 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Jun 2017 21:22:05 -0400 Subject: [PATCH 5/9] Avoid complicated center number wrangling in target assoc test [ci skip] --- test/test_global_qbx.py | 77 ++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/test/test_global_qbx.py b/test/test_global_qbx.py index 7326efc1..0b964fbe 100644 --- a/test/test_global_qbx.py +++ b/test/test_global_qbx.py @@ -234,10 +234,8 @@ def test_target_association(ctx_getter, curve_name, curve_f, nelements): lpot_source, conn = QBXLayerPotentialSource(discr, order).with_refinement() del discr - from pytential.qbx.utils import get_centers_on_side - - int_centers = get_centers_on_side(lpot_source, -1) - ext_centers = get_centers_on_side(lpot_source, +1) + from pytential.qbx.utils import get_interleaved_centers + centers = get_interleaved_centers(queue, lpot_source) # }}} @@ -297,57 +295,82 @@ def test_target_association(ctx_getter, curve_name, curve_f, nelements): expansion_radii = lpot_source._expansion_radii("nsources").get(queue) - int_centers = np.array([axis.get(queue) for axis in int_centers]) - ext_centers = np.array([axis.get(queue) for axis in ext_centers]) int_targets = np.array([axis.get(queue) for axis in int_targets.nodes()]) ext_targets = np.array([axis.get(queue) for axis in ext_targets.nodes()]) # Checks that the sources match with their own centers. - def check_on_surface_targets(nsources, true_side, target_to_source_result, + def check_on_surface_targets(nsources, true_side, target_to_center, target_to_side_result): + assert (target_to_center >= 0).all() + sources = np.arange(0, nsources) - assert (target_to_source_result == sources).all() + + # Centers are on alternating sides of the geometry. Dividing by + # two yields the number of the source that spawned the center. + assert (target_to_center//2 == sources).all() + assert (target_to_side_result == true_side).all() # Checks that the targets match with centers on the appropriate side and # within the allowable distance. def check_close_targets(centers, targets, true_side, - target_to_source_result, target_to_side_result): - assert (target_to_side_result == true_side).all() - dists = la.norm((targets.T - centers.T[target_to_source_result]), axis=1) - assert (dists <= expansion_radii[target_to_source_result]).all() + target_to_center, target_to_side_result, + tgt_slice): + if 1: + # FIXME Remove + bad_index, = np.where(target_to_center < 0) + bad_index += tgt_slice.start + print(bad_index) + + assert (target_to_center >= 0).all() + + if 0: + # FIXME Remove + bad = target_to_side_result != true_side + bad_index, = np.where(bad) + print(bad_index+tgt_slice.start) + + # FIXME maybe preserve? + from meshmode.discretization.visualization import draw_curve + draw_curve(lpot_source.density_discr) + + import matplotlib.pyplot as plt + plt.plot(centers[0], centers[1], "gv") + plt.plot(targets[0][bad], targets[1][bad], "ro") + plt.plot(targets[0], targets[1], "x") + plt.show() - # Checks that far targets are not assigned a center. - def check_far_targets(target_to_source_result): - assert (target_to_source_result == -1).all() + assert (target_to_side_result == true_side).all() + dists = la.norm((targets.T - centers.T[target_to_center]), axis=1) + assert (dists <= expansion_radii[target_to_center]).all() - # Centers for source i are located at indices 2 * i, 2 * i + 1 - target_to_source = target_assoc.target_to_center // 2 # Center side order = -1, 1, -1, 1, ... target_to_center_side = 2 * (target_assoc.target_to_center % 2) - 1 check_on_surface_targets( nsources, -1, - target_to_source[surf_int_slice], + target_assoc.target_to_center[surf_int_slice], target_to_center_side[surf_int_slice]) check_on_surface_targets( nsources, +1, - target_to_source[surf_ext_slice], + target_assoc.target_to_center[surf_ext_slice], target_to_center_side[surf_ext_slice]) check_close_targets( - int_centers, int_targets, -1, - target_to_source[vol_int_slice], - target_to_center_side[vol_int_slice]) + centers, int_targets, -1, + target_assoc.target_to_center[vol_int_slice], + target_to_center_side[vol_int_slice], + vol_int_slice) check_close_targets( - ext_centers, ext_targets, +1, - target_to_source[vol_ext_slice], - target_to_center_side[vol_ext_slice]) + centers, ext_targets, +1, + target_assoc.target_to_center[vol_ext_slice], + target_to_center_side[vol_ext_slice], + vol_ext_slice) - check_far_targets( - target_to_source[far_slice]) + # Checks that far targets are not assigned a center. + assert (target_assoc.target_to_center[far_slice] == -1).all() # }}} -- GitLab From f32b1f096f206fea981b0c3cf330bf509d63e86a Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Jun 2017 21:29:19 -0400 Subject: [PATCH 6/9] Better explain max_levels rounding [ci skip] --- pytential/qbx/target_assoc.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pytential/qbx/target_assoc.py b/pytential/qbx/target_assoc.py index 158b930c..e3f8ae11 100644 --- a/pytential/qbx/target_assoc.py +++ b/pytential/qbx/target_assoc.py @@ -386,7 +386,8 @@ class QBXTargetAssociator(object): def mark_targets(self, queue, tree, peer_lists, lpot_source, target_status, debug, wait_for=None): - # Avoid generating too many kernels. + # Round up level count--this gets included in the kernel as + # a stack bound. Rounding avoids too many kernel versions. from pytools import div_ceil max_levels = 10 * div_ceil(tree.nlevels, 10) @@ -477,7 +478,8 @@ class QBXTargetAssociator(object): def try_find_centers(self, queue, tree, peer_lists, lpot_source, target_status, target_flags, target_assoc, stick_out_factor, debug, wait_for=None): - # Avoid generating too many kernels. + # Round up level count--this gets included in the kernel as + # a stack bound. Rounding avoids too many kernel versions. from pytools import div_ceil max_levels = 10 * div_ceil(tree.nlevels, 10) @@ -559,7 +561,8 @@ class QBXTargetAssociator(object): def mark_panels_for_refinement(self, queue, tree, peer_lists, lpot_source, target_status, refine_flags, debug, wait_for=None): - # Avoid generating too many kernels. + # Round up level count--this gets included in the kernel as + # a stack bound. Rounding avoids too many kernel versions. from pytools import div_ceil max_levels = 10 * div_ceil(tree.nlevels, 10) -- GitLab From cdabe13a26ebfcdb6bc8a2751f3503acdd199b8f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Jun 2017 21:48:14 -0400 Subject: [PATCH 7/9] Target assoc: Keep scanning for closer centers in other leaves [ci skip] --- pytential/qbx/target_assoc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pytential/qbx/target_assoc.py b/pytential/qbx/target_assoc.py index e3f8ae11..38d41c3e 100644 --- a/pytential/qbx/target_assoc.py +++ b/pytential/qbx/target_assoc.py @@ -204,7 +204,10 @@ QBX_CENTER_FINDER = AreaQueryElementwiseTemplate( } """, leaf_found_op=QBX_TREE_MAKO_DEFS + r"""//CL// - if (target_status[i] == MARKED_QBX_CENTER_PENDING) + if (target_status[i] == MARKED_QBX_CENTER_PENDING + // Found one in a prior leaf, but there may well be another + // that's closer. + || target_status[i] == MARKED_QBX_CENTER_FOUND) { for (particle_id_t center_idx = box_to_center_starts[${leaf_box_id}]; center_idx < box_to_center_starts[${leaf_box_id} + 1]; -- GitLab From de407bc6702c1b7831469c69e83c49709f2dbee2 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 8 Jun 2017 01:19:46 -0500 Subject: [PATCH 8/9] Fix finding source_slice. --- pytential/qbx/target_assoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytential/qbx/target_assoc.py b/pytential/qbx/target_assoc.py index 38d41c3e..cbf2a26c 100644 --- a/pytential/qbx/target_assoc.py +++ b/pytential/qbx/target_assoc.py @@ -405,7 +405,7 @@ class QBXTargetAssociator(object): found_target_close_to_panel.finish() # Perform a space invader query over the sources. - source_slice = tree.user_source_ids[tree.qbx_user_source_slice] + source_slice = tree.sorted_target_ids[tree.qbx_user_source_slice] sources = [axis.with_queue(queue)[source_slice] for axis in tree.sources] tunnel_radius_by_source = \ lpot_source._close_target_tunnel_radius("nsources").with_queue(queue) -- GitLab From 192f186e6240e5f90c45ff1f269bb8a1dd4d9a39 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 8 Jun 2017 01:21:58 -0500 Subject: [PATCH 9/9] Fix target association test. --- test/test_global_qbx.py | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/test/test_global_qbx.py b/test/test_global_qbx.py index 0b964fbe..c5f77476 100644 --- a/test/test_global_qbx.py +++ b/test/test_global_qbx.py @@ -235,7 +235,8 @@ def test_target_association(ctx_getter, curve_name, curve_f, nelements): del discr from pytential.qbx.utils import get_interleaved_centers - centers = get_interleaved_centers(queue, lpot_source) + centers = np.array([ax.get(queue) + for ax in get_interleaved_centers(queue, lpot_source)]) # }}} @@ -293,7 +294,7 @@ def test_target_association(ctx_getter, curve_name, curve_f, nelements): QBXTargetAssociator(cl_ctx)(lpot_source, target_discrs) .get(queue=queue)) - expansion_radii = lpot_source._expansion_radii("nsources").get(queue) + expansion_radii = lpot_source._expansion_radii("ncenters").get(queue) int_targets = np.array([axis.get(queue) for axis in int_targets.nodes()]) ext_targets = np.array([axis.get(queue) for axis in ext_targets.nodes()]) @@ -316,30 +317,7 @@ def test_target_association(ctx_getter, curve_name, curve_f, nelements): def check_close_targets(centers, targets, true_side, target_to_center, target_to_side_result, tgt_slice): - if 1: - # FIXME Remove - bad_index, = np.where(target_to_center < 0) - bad_index += tgt_slice.start - print(bad_index) - assert (target_to_center >= 0).all() - - if 0: - # FIXME Remove - bad = target_to_side_result != true_side - bad_index, = np.where(bad) - print(bad_index+tgt_slice.start) - - # FIXME maybe preserve? - from meshmode.discretization.visualization import draw_curve - draw_curve(lpot_source.density_discr) - - import matplotlib.pyplot as plt - plt.plot(centers[0], centers[1], "gv") - plt.plot(targets[0][bad], targets[1][bad], "ro") - plt.plot(targets[0], targets[1], "x") - plt.show() - assert (target_to_side_result == true_side).all() dists = la.norm((targets.T - centers.T[target_to_center]), axis=1) assert (dists <= expansion_radii[target_to_center]).all() -- GitLab