From d88d7f53b79c3c7d587bd8704342ab0c9945ad12 Mon Sep 17 00:00:00 2001 From: Thomas Gibson Date: Thu, 3 Jun 2021 19:37:12 -0500 Subject: [PATCH] Remove scaling arg from non geometric factor; allow apps to specify --- examples/advection/surface.py | 2 +- examples/wave/var-propagation-speed.py | 3 ++- examples/wave/wave-min-mpi.py | 3 ++- examples/wave/wave-min.py | 3 ++- examples/wave/wave-op-mpi.py | 7 ++++--- examples/wave/wave-op-var-velocity.py | 7 ++++--- examples/wave/wave-op.py | 7 ++++--- grudge/dt_utils.py | 29 ++++++++++++-------------- 8 files changed, 32 insertions(+), 29 deletions(-) diff --git a/examples/advection/surface.py b/examples/advection/surface.py index 56bdfa3d..9dcdc93e 100644 --- a/examples/advection/surface.py +++ b/examples/advection/surface.py @@ -203,7 +203,7 @@ def main(ctx_factory, dim=2, order=4, use_quad=False, visualize=False): # {{{ time stepping - dt = adv_operator.estimate_rk4_timestep(dcoll, fields=u0, dt_scaling=8/9) + dt = adv_operator.estimate_rk4_timestep(dcoll, fields=u0) nsteps = int(final_time // dt) + 1 logger.info("dt: %.5e", dt) diff --git a/examples/wave/var-propagation-speed.py b/examples/wave/var-propagation-speed.py index a0237d7b..0b8d51b9 100644 --- a/examples/wave/var-propagation-speed.py +++ b/examples/wave/var-propagation-speed.py @@ -102,7 +102,8 @@ def main(ctx_factory, dim=2, order=4, visualize=False): def rhs(t, w): return wave_op.operator(t, w) - dt = wave_op.estimate_rk4_timestep(dcoll, fields=fields) + dt_scaling_const = 2/3 + dt = dt_scaling_const * wave_op.estimate_rk4_timestep(dcoll, fields=fields) dt_stepper = set_up_rk4("w", dt, fields, rhs) diff --git a/examples/wave/wave-min-mpi.py b/examples/wave/wave-min-mpi.py index 25f0174d..a3e75c7b 100644 --- a/examples/wave/wave-min-mpi.py +++ b/examples/wave/wave-min-mpi.py @@ -114,7 +114,8 @@ def main(ctx_factory, dim=2, order=4, visualize=False): [dcoll.zeros(actx) for i in range(dcoll.dim)] ) - dt = wave_op.estimate_rk4_timestep(dcoll, fields=fields) + dt_scaling_const = 2/3 + dt = dt_scaling_const * wave_op.estimate_rk4_timestep(dcoll, fields=fields) wave_op.check_bc_coverage(local_mesh) diff --git a/examples/wave/wave-min.py b/examples/wave/wave-min.py index 7f19a228..7b18d3df 100644 --- a/examples/wave/wave-min.py +++ b/examples/wave/wave-min.py @@ -95,7 +95,8 @@ def main(ctx_factory, dim=2, order=4, visualize=False): [dcoll.zeros(actx) for i in range(dcoll.dim)] ) - dt = wave_op.estimate_rk4_timestep(dcoll, fields=fields) + dt_scaling_const = 2/3 + dt = dt_scaling_const * wave_op.estimate_rk4_timestep(dcoll, fields=fields) wave_op.check_bc_coverage(mesh) diff --git a/examples/wave/wave-op-mpi.py b/examples/wave/wave-op-mpi.py index 4c0d01bc..3fb49d7d 100644 --- a/examples/wave/wave-op-mpi.py +++ b/examples/wave/wave-op-mpi.py @@ -114,14 +114,14 @@ def rk4_step(y, t, h, f): return y + h/6*(k1 + 2*k2 + 2*k3 + k4) -def estimate_rk4_timestep(dcoll, c, scaling=None): +def estimate_rk4_timestep(dcoll, c): from grudge.dt_utils import (dt_non_geometric_factor, dt_geometric_factors) # FIXME: We should make the nodal reductions respect MPI. # See: https://github.com/inducer/grudge/issues/112 and # https://github.com/inducer/grudge/issues/113 - dt_factor = (dt_non_geometric_factor(dcoll, scaling=scaling) + dt_factor = (dt_non_geometric_factor(dcoll) * op.nodal_min(dcoll, "vol", dt_geometric_factors(dcoll))) mpi_comm = dcoll.mpi_communicator @@ -192,7 +192,8 @@ def main(ctx_factory, dim=2, order=3, visualize=False): ) c = 1 - dt = estimate_rk4_timestep(dcoll, c, scaling=0.45) + dt_scaling_const = 0.45 + dt = dt_scaling_const * estimate_rk4_timestep(dcoll, c) vis = make_visualizer(dcoll) diff --git a/examples/wave/wave-op-var-velocity.py b/examples/wave/wave-op-var-velocity.py index 1f5c35b3..e48c8d71 100644 --- a/examples/wave/wave-op-var-velocity.py +++ b/examples/wave/wave-op-var-velocity.py @@ -129,11 +129,11 @@ def rk4_step(y, t, h, f): return y + h/6*(k1 + 2*k2 + 2*k3 + k4) -def estimate_rk4_timestep(dcoll, c, scaling=None): +def estimate_rk4_timestep(dcoll, c): from grudge.dt_utils import (dt_non_geometric_factor, dt_geometric_factors) - dt_factor = (dt_non_geometric_factor(dcoll, scaling=scaling) + dt_factor = (dt_non_geometric_factor(dcoll) * op.nodal_min(dcoll, "vol", dt_geometric_factors(dcoll))) return dt_factor * (1 / c) @@ -189,7 +189,8 @@ def main(ctx_factory, dim=2, order=3, visualize=False): # bounded above by 1 c = 0.2 + 0.8*bump(actx, dcoll, center=np.zeros(3), width=0.5) - dt = estimate_rk4_timestep(dcoll, c=1, scaling=0.5) + dt_scaling_const = 0.5 + dt = dt_scaling_const * estimate_rk4_timestep(dcoll, c=1) fields = flat_obj_array( bump(actx, dcoll, ), diff --git a/examples/wave/wave-op.py b/examples/wave/wave-op.py index 9c39f289..c0494d9f 100644 --- a/examples/wave/wave-op.py +++ b/examples/wave/wave-op.py @@ -112,11 +112,11 @@ def rk4_step(y, t, h, f): return y + h/6*(k1 + 2*k2 + 2*k3 + k4) -def estimate_rk4_timestep(dcoll, c, scaling=None): +def estimate_rk4_timestep(dcoll, c): from grudge.dt_utils import (dt_non_geometric_factor, dt_geometric_factors) - dt_factor = (dt_non_geometric_factor(dcoll, scaling=scaling) + dt_factor = (dt_non_geometric_factor(dcoll) * op.nodal_min(dcoll, "vol", dt_geometric_factors(dcoll))) return dt_factor * (1 / c) @@ -165,7 +165,8 @@ def main(ctx_factory, dim=2, order=3, visualize=False): ) c = 1 - dt = estimate_rk4_timestep(dcoll, c, scaling=0.45) + dt_scaling_const = 0.45 + dt = dt_scaling_const * estimate_rk4_timestep(dcoll, c) vis = make_visualizer(dcoll) diff --git a/grudge/dt_utils.py b/grudge/dt_utils.py index 4fdba9e7..14c95559 100644 --- a/grudge/dt_utils.py +++ b/grudge/dt_utils.py @@ -1,7 +1,7 @@ """Helper functions for estimating stable time steps for RKDG methods. .. autofunction:: dt_non_geometric_factor -.. autofunction:: dt_geometric_factor +.. autofunction:: dt_geometric_factors """ __copyright__ = """ @@ -44,8 +44,7 @@ from pytools import memoize_on_first_arg @memoize_on_first_arg -def dt_non_geometric_factor( - dcoll: DiscretizationCollection, scaling=None, dd=None) -> float: +def dt_non_geometric_factor(dcoll: DiscretizationCollection, dd=None) -> float: r"""Computes the non-geometric scale factor following [Hesthaven_2008]_, section 6.4: @@ -56,8 +55,6 @@ def dt_non_geometric_factor( where :math:`\Delta r_i` denotes the distance between two distinct nodes on the reference element. - :arg scaling: a :class:`float` denoting the scaling factor. By default, - the constant is set to 2/3. :arg dd: a :class:`~grudge.dof_desc.DOFDesc`, or a value convertible to one. Defaults to the base volume discretization if not provided. :returns: a :class:`float` denoting the minimum node distance on the @@ -66,9 +63,6 @@ def dt_non_geometric_factor( if dd is None: dd = DD_VOLUME - if scaling is None: - scaling = 2/3 - discr = dcoll.discr_from_dd(dd) min_delta_rs = [] for grp in discr.groups: @@ -93,7 +87,7 @@ def dt_non_geometric_factor( ) # Return minimum over all element groups in the discretization - return scaling * min(min_delta_rs) + return min(min_delta_rs) @memoize_on_first_arg @@ -132,12 +126,14 @@ def dt_geometric_factors( "Geometric factors are only implemented for simplex element groups" ) - cell_vols = op.elementwise_integral( - dcoll, dd, volm_discr.zeros(actx) + 1.0 + cell_vols = abs( + op.elementwise_integral( + dcoll, dd, volm_discr.zeros(actx) + 1.0 + ) ) if dcoll.dim == 1: - return op.nodal_min(dcoll, dd, cell_vols) + return cell_vols dd_face = DOFDesc("all_faces", dd.discretization_tag) face_discr = dcoll.discr_from_dd(dd_face) @@ -146,8 +142,10 @@ def dt_geometric_factors( # take the sum over the averaged face areas on each face. # NOTE: The face areas are the *same* at each face nodal location. # This assumes there are the *same* number of face nodes on each face. - surface_areas = op.elementwise_integral( - dcoll, dd_face, face_discr.zeros(actx) + 1.0 + surface_areas = abs( + op.elementwise_integral( + dcoll, dd_face, face_discr.zeros(actx) + 1.0 + ) ) surface_areas = DOFArray( actx, @@ -162,7 +160,7 @@ def dt_geometric_factors( for vgrp, afgrp, face_ae_i in zip(volm_discr.groups, face_discr.groups, - actx.np.fabs(surface_areas)) + surface_areas) ) ) @@ -177,4 +175,3 @@ def dt_geometric_factors( for cv_i, sae_i in zip(cell_vols, surface_areas) ) ) - -- GitLab