From f9d9bab9b12e3a7363067f50dde2d1307b2dabb3 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 18 May 2017 10:20:09 -0500 Subject: [PATCH 1/2] Implement more special functions in the symbolic language --- pytential/symbolic/execution.py | 16 ++++++------- pytential/symbolic/primitives.py | 41 +++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/pytential/symbolic/execution.py b/pytential/symbolic/execution.py index a229b48e..5f67e808 100644 --- a/pytential/symbolic/execution.py +++ b/pytential/symbolic/execution.py @@ -127,24 +127,24 @@ class EvaluationMapper(EvaluationMapperBase): assert not is_obj_array(result) # numpy bug with obj_array.imag return result.imag - def apply_sqrt(self, args): + def apply_conj(self, args): arg, = args - return cl.clmath.sqrt(self.rec(arg)) + return self.rec(arg).conj() def apply_abs(self, args): arg, = args return abs(self.rec(arg)) - def apply_conj(self, args): - arg, = args - return self.rec(arg).conj() - # }}} def map_call(self, expr): - from pytential.symbolic.primitives import Function - if isinstance(expr.function, Function): + from pytential.symbolic.primitives import EvalMapperFunction, CLMathFunction + + if isinstance(expr.function, EvalMapperFunction): return getattr(self, "apply_"+expr.function.name)(expr.parameters) + elif isinstance(expr.function, CLMathFunction): + return getattr(cl.clmath, expr.function.name)( + *(self.rec(arg) for arg in expr.parameters), queue=self.queue) else: return EvaluationMapperBase.map_call(self, expr) diff --git a/pytential/symbolic/primitives.py b/pytential/symbolic/primitives.py index 27c2e24c..2769cfed 100644 --- a/pytential/symbolic/primitives.py +++ b/pytential/symbolic/primitives.py @@ -153,14 +153,43 @@ class Function(var): return with_object_array_or_scalar(make_op, operand) else: - return var.__call__(self, operand) + return var.__call__(self, operand, *args, **kwargs) -real = Function("real") -imag = Function("imag") -conj = Function("conj") -sqrt = Function("sqrt") -abs = Function("abs") +class EvalMapperFunction(Function): + pass + + +class CLMathFunction(Function): + pass + + +real = EvalMapperFunction("real") +imag = EvalMapperFunction("imag") +conj = EvalMapperFunction("conj") +abs = EvalMapperFunction("abs") + +sqrt = CLMathFunction("sqrt") + +sin = CLMathFunction("sin") +cos = CLMathFunction("cos") +tan = CLMathFunction("tan") + +asin = CLMathFunction("asin") +acos = CLMathFunction("acos") +atan = CLMathFunction("atan") +atan2 = CLMathFunction("atan2") + +sinh = CLMathFunction("sinh") +cosh = CLMathFunction("cosh") +tanh = CLMathFunction("tanh") + +asinh = CLMathFunction("asinh") +acosh = CLMathFunction("acosh") +atanh = CLMathFunction("atanh") + +exp = CLMathFunction("exp") +log = CLMathFunction("log") class DiscretizationProperty(Expression): -- GitLab From 2b952592e7160e4d70e04fab664b87f1fdafca2c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 18 May 2017 10:20:59 -0500 Subject: [PATCH 2/2] Fix the GA normal formula --- pytential/symbolic/primitives.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pytential/symbolic/primitives.py b/pytential/symbolic/primitives.py index 2769cfed..57b3ff97 100644 --- a/pytential/symbolic/primitives.py +++ b/pytential/symbolic/primitives.py @@ -296,6 +296,9 @@ def parametrization_derivative(ambient_dim, dim, where=None): def pseudoscalar(ambient_dim, dim=None, where=None): + """ + Same as the outer product of all parametrization derivative columns. + """ if dim is None: dim = ambient_dim - 1 @@ -328,7 +331,9 @@ def normal(ambient_dim, dim=None, where=None): pder = ( pseudoscalar(ambient_dim, dim, where) / area_element(ambient_dim, dim, where)) - return cse(pder.I | pder, "normal", + return cse( + # Dorst Section 3.7.2 + pder << pder.I.inv(), cse_scope.DISCRETIZATION) -- GitLab