diff --git a/doc/conf.py b/doc/conf.py index 560efec5951aa5de9a4b732e304a121c0c0c8baa..6bb9487380141270dcbfcf88c7e5036935be7e91 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -319,12 +319,12 @@ texinfo_documents = [ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - 'http://docs.python.org/': None, - 'http://docs.scipy.org/doc/numpy/': None, - 'http://documen.tician.de/pyopencl/': None, - 'http://documen.tician.de/modepy/': None, - 'http://documen.tician.de/pymbolic/': None, - 'http://documen.tician.de/meshmode/': None, + 'https://docs.python.org/': None, + 'https://docs.scipy.org/doc/numpy/': None, + 'https://documen.tician.de/pyopencl/': None, + 'https://documen.tician.de/modepy/': None, + 'https://documen.tician.de/pymbolic/': None, + 'https://documen.tician.de/meshmode/': None, #'http://documen.tician.de/loopy/': None, } autoclass_content = "both" diff --git a/grudge/execution.py b/grudge/execution.py index 761b14729c330e5d1ebcdaf203dea1c437259a4f..a95b15e75e43917688f2c3766651e3018ff9d526 100644 --- a/grudge/execution.py +++ b/grudge/execution.py @@ -54,7 +54,7 @@ class ExecutionMapper(mappers.Evaluator, self.function_registry = bound_op.function_registry self.queue = queue - # {{{ expression mappings ------------------------------------------------- + # {{{ expression mappings def map_ones(self, expr): if expr.dd.is_scalar(): @@ -100,6 +100,49 @@ class ExecutionMapper(mappers.Evaluator, args = [self.rec(p) for p in expr.parameters] return self.function_registry[expr.function.name](self.queue, *args) + # }}} + + # {{{ elementwise reductions + + def _map_elementwise_reduction(self, op_name, field_expr, dd): + @memoize_in(self, "elementwise_%s_knl" % op_name) + def knl(): + knl = lp.make_kernel( + "{[el, idof, jdof]: 0<=el%s" % (self._format_dd(op.dd_in), self._format_dd(op.dd_out)) + # {{{ elementwise ops + + def map_elementwise_sum(self, expr, enclosing_prec): + return "ElementwiseSum" + self._format_op_dd(expr) + + def map_elementwise_max(self, expr, enclosing_prec): + return "ElementwiseMax" + self._format_op_dd(expr) + + def map_elementwise_min(self, expr, enclosing_prec): + return "ElementwiseMin" + self._format_op_dd(expr) + + # }}} + # {{{ nodal ops def map_nodal_sum(self, expr, enclosing_prec): diff --git a/grudge/symbolic/operators.py b/grudge/symbolic/operators.py index 56a26feef896bc9599f8358a8a5dc0d792456825..2722e161baa49e5761c116ca2b8f4910be201f8e 100644 --- a/grudge/symbolic/operators.py +++ b/grudge/symbolic/operators.py @@ -43,6 +43,8 @@ Basic Operators Reductions ^^^^^^^^^^ +.. autoclass:: ElementwiseSumOperator +.. autoclass:: ElementwiseMinOperator .. autoclass:: ElementwiseMaxOperator .. autoclass:: NodalReductionOperator @@ -170,9 +172,38 @@ class InterpolationOperator(Operator): interp = InterpolationOperator -class ElementwiseMaxOperator(Operator): +# {{{ element reduction: sum, min, max + +class ElementwiseReductionOperator(Operator): + def __init__(self, dd): + super(ElementwiseReductionOperator, self).__init__(dd_in=dd, dd_out=dd) + + +class ElementwiseSumOperator(ElementwiseReductionOperator): + """Returns a vector of DOFs with all entries on each element set + to the sum of DOFs on that element. + """ + + mapper_method = intern("map_elementwise_sum") + + +class ElementwiseMinOperator(ElementwiseReductionOperator): + """Returns a vector of DOFs with all entries on each element set + to the minimum of DOFs on that element. + """ + + mapper_method = intern("map_elementwise_min") + + +class ElementwiseMaxOperator(ElementwiseReductionOperator): + """Returns a vector of DOFs with all entries on each element set + to the maximum of DOFs on that element. + """ + mapper_method = intern("map_elementwise_max") +# }}} + # {{{ nodal reduction: sum, integral, max @@ -684,6 +715,27 @@ def norm(p, arg, dd=None): else: raise ValueError("unsupported value of p") + +def h_max_from_volume(ambient_dim, dim=None, dd=None): + """Defines a characteristic length based on the volume of the elements. + This length may not be representative if the elements have very high + aspect ratios. + """ + + import grudge.symbolic.primitives as prim + if dd is None: + dd = prim.DD_VOLUME + dd = prim.as_dofdesc(dd) + + if dim is None: + dim = ambient_dim + + return NodalMax(dd_in=dd)( + ElementwiseSumOperator(dd)( + MassOperator(dd_in=dd)(prim.Ones(dd)) + ) + )**(1.0/dim) + # }}} # vim: foldmethod=marker diff --git a/test/test_grudge.py b/test/test_grudge.py index a55f92baffb7d7f5bfa293bb105579dfeeba08a5..53bd4975176e7f4a263fecfa2985997f26be90f4 100644 --- a/test/test_grudge.py +++ b/test/test_grudge.py @@ -263,7 +263,6 @@ def test_convergence_advec(ctx_factory, mesh_name, mesh_pars, op_type, flux_type [np.linspace(-1.0, 1.0, mesh_par)], order=order) - h = 2.0 / mesh_par dim = 1 dt_factor = 1.0 elif mesh_name == "disk": @@ -281,7 +280,6 @@ def test_convergence_advec(ctx_factory, mesh_name, mesh_pars, op_type, flux_type from meshmode.mesh.io import from_meshpy mesh = from_meshpy(mesh_info, order=1) - h = np.sqrt(mesh_par) dim = 2 dt_factor = 4 elif mesh_name.startswith("rect"): @@ -290,7 +288,6 @@ def test_convergence_advec(ctx_factory, mesh_name, mesh_pars, op_type, flux_type mesh = generate_regular_rect_mesh(a=(-0.5,)*dim, b=(0.5,)*dim, n=(mesh_par,)*dim, order=4) - h = 1/mesh_par if dim == 2: dt_factor = 4 elif dim == 3: @@ -337,7 +334,8 @@ def test_convergence_advec(ctx_factory, mesh_name, mesh_pars, op_type, flux_type else: final_time = 0.2 - dt = dt_factor * h/order**2 + h_max = bind(discr, sym.h_max_from_volume(discr.ambient_dim))(queue) + dt = dt_factor * h_max/order**2 nsteps = (final_time // dt) + 1 dt = final_time/nsteps + 1e-15 @@ -366,11 +364,12 @@ def test_convergence_advec(ctx_factory, mesh_name, mesh_pars, op_type, flux_type error_l2 = bind(discr, sym.norm(2, sym.var("u")-u_analytic(sym.nodes(dim))))( queue, t=last_t, u=last_u) - print(h, error_l2) - eoc_rec.add_data_point(h, error_l2) + print(h_max, error_l2) + eoc_rec.add_data_point(h_max, error_l2) - print(eoc_rec.pretty_print(abscissa_label="h", - error_label="L2 Error")) + print(eoc_rec.pretty_print( + abscissa_label="h", + error_label="L2 Error")) assert eoc_rec.order_estimate() > order