Skip to content

Commit c577798

Browse files
authored
Merge pull request #2349 from firedrakeproject/connorjward/fast-path-real-assign
Avoid codegen when assigning scalars to Real space
2 parents 2217841 + db3c8c6 commit c577798

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

firedrake/function.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ctypes
55
from collections import OrderedDict
66
from ctypes import POINTER, c_int, c_double, c_void_p
7+
import numbers
78

89
from pyop2 import op2
910

@@ -386,6 +387,12 @@ def assign(self, expr, subset=None):
386387
:class:`Function`'s ``node_set``. The expression will then
387388
only be assigned to the nodes on that subset.
388389
"""
390+
# Avoid generating code when assigning scalar values to the Real space
391+
if (isinstance(expr, numbers.Number)
392+
and self.function_space().ufl_element().family() == "Real"):
393+
self.dat.data[...] = expr
394+
return self
395+
389396
expr = ufl.as_ufl(expr)
390397
if isinstance(expr, ufl.classes.Zero):
391398
self.dat.zero(subset=subset)

0 commit comments

Comments
 (0)