From 2e6b66c81884dc0ef8f5167da5ab86966c1a6391 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Wed, 20 Oct 2021 10:43:28 -0500 Subject: [PATCH] return device scalar from h_min/max_from_volume --- grudge/dt_utils.py | 13 +++++++------ test/test_grudge.py | 14 +++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/grudge/dt_utils.py b/grudge/dt_utils.py index 57801476..42537d9a 100644 --- a/grudge/dt_utils.py +++ b/grudge/dt_utils.py @@ -44,6 +44,7 @@ THE SOFTWARE. import numpy as np +from typing import Any from arraycontext import ArrayContext, thaw, freeze from meshmode.transform_metadata import FirstAxisIsElementsTag @@ -158,7 +159,7 @@ def dt_non_geometric_factors( @memoize_on_first_arg def h_max_from_volume( - dcoll: DiscretizationCollection, dim=None, dd=None) -> float: + dcoll: DiscretizationCollection, dim=None, dd=None) -> Any: """Returns a (maximum) characteristic length based on the volume of the elements. This length may not be representative if the elements have very high aspect ratios. @@ -182,16 +183,16 @@ def h_max_from_volume( actx = dcoll._setup_actx ones = dcoll.discr_from_dd(dd).zeros(actx) + 1.0 - return actx.to_numpy(nodal_max( + return nodal_max( dcoll, dd, elementwise_sum(dcoll, op.mass(dcoll, dd, ones)) - ) ** (1.0 / dim)) + ) ** (1.0 / dim) @memoize_on_first_arg def h_min_from_volume( - dcoll: DiscretizationCollection, dim=None, dd=None) -> float: + dcoll: DiscretizationCollection, dim=None, dd=None) -> Any: """Returns a (minimum) characteristic length based on the volume of the elements. This length may not be representative if the elements have very high aspect ratios. @@ -215,11 +216,11 @@ def h_min_from_volume( actx = dcoll._setup_actx ones = dcoll.discr_from_dd(dd).zeros(actx) + 1.0 - return actx.to_numpy(nodal_min( + return nodal_min( dcoll, dd, elementwise_sum(dcoll, op.mass(dcoll, dd, ones)) - ) ** (1.0 / dim)) + ) ** (1.0 / dim) def dt_geometric_factors( diff --git a/test/test_grudge.py b/test/test_grudge.py index 43c3535d..c8778eb3 100644 --- a/test/test_grudge.py +++ b/test/test_grudge.py @@ -254,7 +254,7 @@ def test_mass_surface_area(actx_factory, name): h_max = h_max_from_volume(dcoll) - eoc.add_data_point(h_max, area_error) + eoc.add_data_point(actx.to_numpy(h_max), area_error) # }}} @@ -328,7 +328,7 @@ def test_mass_operator_inverse(actx_factory, name): h_max = h_max_from_volume(dcoll) - eoc.add_data_point(h_max, inv_error) + eoc.add_data_point(actx.to_numpy(h_max), inv_error) logger.info("inverse mass error\n%s", str(eoc)) @@ -636,8 +636,8 @@ def test_surface_divergence_theorem(actx_factory, mesh_name, visualize=False): h_max = h_max_from_volume(dcoll) - eoc_global.add_data_point(h_max, actx.to_numpy(err_global)) - eoc_local.add_data_point(h_max, actx.to_numpy(err_local)) + eoc_global.add_data_point(actx.to_numpy(h_max), actx.to_numpy(err_global)) + eoc_local.add_data_point(actx.to_numpy(h_max), actx.to_numpy(err_local)) if visualize: from grudge.shortcuts import make_visualizer @@ -773,7 +773,7 @@ def test_convergence_advec(actx_factory, mesh_name, mesh_pars, op_type, flux_typ from grudge.dt_utils import h_max_from_volume h_max = h_max_from_volume(dcoll, dim=dcoll.ambient_dim) - dt = dt_factor * h_max/order**2 + dt = actx.to_numpy(dt_factor * h_max/order**2) nsteps = (final_time // dt) + 1 dt = final_time/nsteps + 1e-15 @@ -806,8 +806,8 @@ def test_convergence_advec(actx_factory, mesh_name, mesh_pars, op_type, flux_typ last_u - u_analytic(nodes, t=last_t), 2 ) - logger.info("h_max %.5e error %.5e", h_max, error_l2) - eoc_rec.add_data_point(h_max, actx.to_numpy(error_l2)) + logger.info("h_max %.5e error %.5e", actx.to_numpy(h_max), error_l2) + eoc_rec.add_data_point(actx.to_numpy(h_max), actx.to_numpy(error_l2)) logger.info("\n%s", eoc_rec.pretty_print( abscissa_label="h", -- GitLab