From db3c8c69aab53a5b89add7a76d242dab54859d75 Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Wed, 16 Feb 2022 13:58:42 +0000 Subject: [PATCH] Avoid codegen when assigning scalars to Real space --- firedrake/function.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/firedrake/function.py b/firedrake/function.py index 1d36b06bbf..c0dd1d1673 100644 --- a/firedrake/function.py +++ b/firedrake/function.py @@ -4,6 +4,7 @@ import ctypes from collections import OrderedDict from ctypes import POINTER, c_int, c_double, c_void_p +import numbers from pyop2 import op2 @@ -386,6 +387,12 @@ def assign(self, expr, subset=None): :class:`Function`'s ``node_set``. The expression will then only be assigned to the nodes on that subset. """ + # Avoid generating code when assigning scalar values to the Real space + if (isinstance(expr, numbers.Number) + and self.function_space().ufl_element().family() == "Real"): + self.dat.data[...] = expr + return self + expr = ufl.as_ufl(expr) if isinstance(expr, ufl.classes.Zero): self.dat.zero(subset=subset)