From 533cc181182938add16291f0d0bfb240dd1ab464 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 15 May 2020 11:57:31 +0100 Subject: [PATCH] fem: Reify known real expressions Will be used for type inference of return variable. --- tsfc/fem.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tsfc/fem.py b/tsfc/fem.py index 1726c468..b8d580b3 100644 --- a/tsfc/fem.py +++ b/tsfc/fem.py @@ -67,6 +67,14 @@ def __init__(self, interface, **kwargs): raise ValueError("unexpected keyword argument '{0}'".format(invalid_keywords.pop())) self.__dict__.update(kwargs) + def reify(self, expr): + if self.complex_mode: + indices = gem.indices(len(expr.shape)) + return gem.ComponentTensor(gem.MathFunction("real", gem.Indexed(expr, indices)), + indices) + else: + return expr + @cached_property def fiat_cell(self): return as_fiat_cell(self.ufl_cell) @@ -136,7 +144,7 @@ def config(self): return config def cell_size(self): - return self.interface.cell_size(self.mt.restriction) + return self.interface.reify(self.interface.cell_size(self.mt.restriction)) def jacobian_at(self, point): expr = Jacobian(self.mt.terminal.ufl_domain()) @@ -427,7 +435,7 @@ def translate_spatialcoordinate(terminal, mt, ctx): # Rebuild modified terminal expr = construct_modified_terminal(mt, terminal) # Translate replaced UFL snippet - return ctx.translator(expr) + return ctx.reify(ctx.translator(expr)) class CellVolumeKernelInterface(ProxyKernelInterface):