def unify(self, other, expr=None): """Return a type that can represent both *self* and *other*. If impossible, raise :exc:`TypeError`. Subtypes should override :meth:`unify_inner`. """ # shortcut if self == other: return self u_s_o = self.unify_inner(other) u_o_s = other.unify_inner(self) if u_s_o is NotImplemented: if u_o_s is NotImplemented: if expr is not None: from hedge.optemplate.tools import pretty_print_optemplate raise TypeError( "types '%s' and '%s' for '%s' " "cannot be unified" % (self, other, pretty_print_optemplate(expr)) ) else: raise TypeError("types '%s' and '%s' cannot be unified" % (self, other)) else: return u_o_s elif u_o_s is NotImplemented: return u_s_o if u_s_o != u_o_s: raise RuntimeError("types '%s' and '%s' don't agree about their unifier" % (self, other)) return u_s_o
def map_operator_binding(self, expr): if isinstance(expr.op, hedge.optemplate.DiffOperatorBase): from hedge.optemplate import ( WeakFormDiffOperatorBase, StrongFormDiffOperatorBase, QuadratureGridUpsampler) if isinstance(expr.op, WeakFormDiffOperatorBase): factor = -1 elif isinstance(expr.op, StrongFormDiffOperatorBase): factor = 1 else: raise RuntimeError("unknown type of differentiation " "operator encountered by stab term generator") from hedge.optemplate import DifferentiationOperator return factor*DifferentiationOperator(expr.op.xyz_axis)(expr.field) elif isinstance(expr.op, hedge.optemplate.FluxOperatorBase): return 0 elif isinstance(expr.op, hedge.optemplate.InverseMassOperator): return self.rec(expr.field) elif isinstance(expr.op, hedge.optemplate.QuadratureInteriorFacesGridUpsampler): return hedge.optemplate.IdentityMapper.map_operator_binding( self, expr) else: from hedge.optemplate.tools import pretty_print_optemplate raise ValueError("IPDG derivative generator doesn't know " "what to do with '%s'" % pretty_print_optemplate(expr))
def map_operator_binding(self, expr, quad_above=[]): from hedge.optemplate.operators import ( DiffOperatorBase, FluxOperatorBase, InverseMassOperator, QuadratureInteriorFacesGridUpsampler) if isinstance(expr.op, DiffOperatorBase): flux_arg_idx = self.get_flux_arg_idx(expr.field, quad_above=quad_above) from hedge.optemplate import \ WeakFormDiffOperatorBase, \ StrongFormDiffOperatorBase if isinstance(expr.op, WeakFormDiffOperatorBase): factor = -1 elif isinstance(expr.op, StrongFormDiffOperatorBase): factor = 1 else: raise RuntimeError("unknown type of differentiation " "operator encountered by stab term generator") from hedge.flux import Normal, FluxScalarPlaceholder sph = FluxScalarPlaceholder(flux_arg_idx) return (factor * Normal(expr.op.xyz_axis) * (sph.int - sph.ext)) elif isinstance(expr.op, FluxOperatorBase): return 0 elif isinstance(expr.op, InverseMassOperator): return self.rec(expr.field, quad_above) elif isinstance(expr.op, QuadratureInteriorFacesGridUpsampler): if quad_above: raise RuntimeError("double quadrature upsampler found " "when generating stabilization term") return self.rec(expr.field, [expr.op]) else: from hedge.optemplate.tools import pretty_print_optemplate raise ValueError("stabilization term generator doesn't know " "what to do with '%s'" % pretty_print_optemplate(expr))