From 3cf654129cc580b4dc8200a5c7042a4e080c2770 Mon Sep 17 00:00:00 2001 From: Thomas Gibson Date: Sat, 22 May 2021 18:32:21 -0500 Subject: [PATCH] Pass dcoll to nodal reductions --- examples/wave/wave-op-mpi.py | 4 ++-- examples/wave/wave-op-var-velocity.py | 4 ++-- examples/wave/wave-op.py | 4 ++-- grudge/models/em.py | 3 ++- grudge/models/wave.py | 2 +- grudge/op.py | 25 +++++++++++++++++-------- test/test_grudge.py | 2 +- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/examples/wave/wave-op-mpi.py b/examples/wave/wave-op-mpi.py index 11de2317..6b700e08 100644 --- a/examples/wave/wave-op-mpi.py +++ b/examples/wave/wave-op-mpi.py @@ -200,8 +200,8 @@ def main(write_output=False): print(f"step: {istep} t: {t} " f"L2: {op.norm(dcoll, fields[0], 2)} " f"Linf: {op.norm(dcoll, fields[0], np.inf)} " - f"sol max: {op.nodal_maximum(fields[0])} " - f"sol min: {op.nodal_minimum(fields[0])}") + f"sol max: {op.nodal_maximum(dcoll, fields[0])} " + f"sol min: {op.nodal_minimum(dcoll, fields[0])}") if write_output: vis.write_parallel_vtk_file( comm, diff --git a/examples/wave/wave-op-var-velocity.py b/examples/wave/wave-op-var-velocity.py index 0d50e9e6..53e66329 100644 --- a/examples/wave/wave-op-var-velocity.py +++ b/examples/wave/wave-op-var-velocity.py @@ -210,8 +210,8 @@ def main(write_output=False): print(f"step: {istep} t: {t} " f"L2: {op.norm(dcoll, fields[0], 2)} " f"Linf: {op.norm(dcoll, fields[0], np.inf)} " - f"sol max: {op.nodal_maximum(fields[0])} " - f"sol min: {op.nodal_minimum(fields[0])}") + f"sol max: {op.nodal_maximum(dcoll, fields[0])} " + f"sol min: {op.nodal_minimum(dcoll, fields[0])}") if write_output: vis.write_vtk_file( "fld-wave-eager-var-velocity-%04d.vtu" % istep, diff --git a/examples/wave/wave-op.py b/examples/wave/wave-op.py index d8e81516..3fa9e585 100644 --- a/examples/wave/wave-op.py +++ b/examples/wave/wave-op.py @@ -179,8 +179,8 @@ def main(write_output=False): print(f"step: {istep} t: {t} " f"L2: {op.norm(dcoll, fields[0], 2)} " f"Linf: {op.norm(dcoll, fields[0], np.inf)} " - f"sol max: {op.nodal_maximum(fields[0])} " - f"sol min: {op.nodal_minimum(fields[0])}") + f"sol max: {op.nodal_maximum(dcoll, fields[0])} " + f"sol min: {op.nodal_minimum(dcoll, fields[0])}") if write_output: vis.write_vtk_file( "fld-wave-eager-%04d.vtu" % istep, diff --git a/grudge/models/em.py b/grudge/models/em.py index cb570b77..f96d195b 100644 --- a/grudge/models/em.py +++ b/grudge/models/em.py @@ -341,7 +341,8 @@ class MaxwellOperator(HyperbolicOperator): return 1/sqrt(self.epsilon*self.mu) # a number else: actx = self.dcoll._setup_actx - return op.nodal_maximum(1 / actx.np.sqrt(self.epsilon * self.mu)) + return op.nodal_maximum(self.dcoll, + 1 / actx.np.sqrt(self.epsilon * self.mu)) def max_eigenvalue(self, t, fields=None, discr=None, context=None): if context is None: diff --git a/grudge/models/wave.py b/grudge/models/wave.py index 67e7846a..e7c66f0e 100644 --- a/grudge/models/wave.py +++ b/grudge/models/wave.py @@ -333,7 +333,7 @@ class VariableCoefficientWeakWaveOperator(HyperbolicOperator): def max_eigenvalue(self, t, fields=None, discr=None): actx = self.dcoll._setup_actx - return op.nodal_maximum(actx.np.fabs(self.c)) + return op.nodal_maximum(self.dcoll, actx.np.fabs(self.c)) # }}} diff --git a/grudge/op.py b/grudge/op.py index 24114f58..ba5ec00d 100644 --- a/grudge/op.py +++ b/grudge/op.py @@ -226,6 +226,7 @@ def h_max_from_volume(dcoll, dim=None, dd=None): ones = dcoll.discr_from_dd(dd).zeros(dcoll._setup_actx) + 1.0 return nodal_maximum( + dcoll, elementwise_sum(dcoll, mass(dcoll, dd, ones)) ) ** (1.0 / dim) @@ -253,6 +254,7 @@ def h_min_from_volume(dcoll, dim=None, dd=None): ones = dcoll.discr_from_dd(dd).zeros(dcoll._setup_actx) + 1.0 return nodal_minimum( + dcoll, elementwise_sum(dcoll, mass(dcoll, dd, ones)) ) ** (1.0 / dim) @@ -958,11 +960,12 @@ def _norm(dcoll, vec, p, dd): if p == 2: return np.sqrt( nodal_summation( + dcoll, vec * _apply_mass_operator(dcoll, dd, dd, vec) ) ) elif p == np.inf: - return nodal_maximum(dcoll._setup_actx.np.fabs(vec)) + return nodal_maximum(dcoll, dcoll._setup_actx.np.fabs(vec)) else: raise NotImplementedError("Unsupported value of p") @@ -1006,15 +1009,17 @@ def nodal_sum(dcoll, dd, vec): from warnings import warn warn("Using 'nodal_sum' is deprecated, use 'nodal_summation' instead.", DeprecationWarning, stacklevel=2) - return nodal_summation(vec) + return nodal_summation(dcoll, vec) -def nodal_summation(vec): +def nodal_summation(dcoll, vec): r"""Return the nodal sum of a vector of degrees of freedom *vec*. + :arg dcoll: a :class:`grudge.discretization.DiscretizationCollection`. :arg vec: a :class:`~meshmode.dof_array.DOFArray`. :returns: an integer denoting the nodal sum. """ + # FIXME: Make MPI-aware actx = vec.array_context return sum([actx.np.sum(grp_ary) for grp_ary in vec]) @@ -1023,15 +1028,17 @@ def nodal_min(dcoll, dd, vec): from warnings import warn warn("Using 'nodal_min' is deprecated, use 'nodal_minimum' instead.", DeprecationWarning, stacklevel=2) - return nodal_minimum(vec) + return nodal_minimum(dcoll, vec) -def nodal_minimum(vec): +def nodal_minimum(dcoll, vec): r"""Return the nodal minimum of a vector of degrees of freedom *vec*. + :arg dcoll: a :class:`grudge.discretization.DiscretizationCollection`. :arg vec: a :class:`~meshmode.dof_array.DOFArray`. :returns: an integer denoting the nodal minimum. """ + # FIXME: Make MPI-aware actx = vec.array_context return reduce(lambda acc, grp_ary: actx.np.minimum(acc, actx.np.min(grp_ary)), vec, -np.inf) @@ -1041,15 +1048,17 @@ def nodal_max(dcoll, dd, vec): from warnings import warn warn("Using 'nodal_max' is deprecated, use 'nodal_maximum' instead.", DeprecationWarning, stacklevel=2) - return nodal_maximum(vec) + return nodal_maximum(dcoll, vec) -def nodal_maximum(vec): +def nodal_maximum(dcoll, vec): r"""Return the nodal maximum of a vector of degrees of freedom *vec*. + :arg dcoll: a :class:`grudge.discretization.DiscretizationCollection`. :arg vec: a :class:`~meshmode.dof_array.DOFArray`. :returns: an integer denoting the nodal maximum. """ + # FIXME: Make MPI-aware actx = vec.array_context return reduce(lambda acc, grp_ary: actx.np.maximum(acc, actx.np.max(grp_ary)), vec, -np.inf) @@ -1073,7 +1082,7 @@ def integral(dcoll, vec, dd=None): ones = dcoll.discr_from_dd(dd).zeros(vec.array_context) + 1.0 return nodal_summation( - vec * _apply_mass_operator(dcoll, dd, dd, ones) + dcoll, vec * _apply_mass_operator(dcoll, dd, dd, ones) ) # }}} diff --git a/test/test_grudge.py b/test/test_grudge.py index f6323c43..56d76624 100644 --- a/test/test_grudge.py +++ b/test/test_grudge.py @@ -618,7 +618,7 @@ def test_surface_divergence_theorem(actx_factory, mesh_name, visualize=False): flux = op.face_mass(dcoll, face_f.dot(face_normal)) # sum everything up - op_global = op.nodal_summation(stiff - (stiff_t + kterm)) + op_global = op.nodal_summation(dcoll, stiff - (stiff_t + kterm)) op_local = op.elementwise_sum(dcoll, dd, stiff - (stiff_t + kterm + flux)) err_global = abs(op_global) -- GitLab