diff --git a/examples/wave/wave-op-mpi.py b/examples/wave/wave-op-mpi.py index 11de2317e66c1992375c0337d05633f405597ee2..6b700e085db8d82c3fe1399d3d3a95db6f84ee21 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 0d50e9e6aef33158b6a1fcd0954e39a76da05a0f..53e66329590c16c780addfb62137009e047da43a 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 d8e81516fa1ac967c61751dd41a6a767ea9efdd8..3fa9e585cfc4be8f10afa660d820d8c7b4b0109f 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 cb570b77ce0aa664dd6fb0fad2e6057176df63d3..f96d195bf99e741b77a2f9fa47bf3bd3019d482e 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 67e7846ad2378c22e07b906e77b43f8038abe987..e7c66f0e355155663db5fff78ee40e1c892e4f43 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 24114f58723d5c2262361295639ca76bb908916c..ba5ec00d2d40172c45b3582da2281f213d2a664c 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 f6323c43bafd9498d1c779e1de99fb1af1a362c6..56d766247d2f82bbac9d97d284674a3634153fb9 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)