Skip to content

Commit

Permalink
Merge pull request #2349 from firedrakeproject/connorjward/fast-path-…
Browse files Browse the repository at this point in the history
…real-assign

Avoid codegen when assigning scalars to Real space
  • Loading branch information
dham authored Feb 24, 2022
2 parents 2217841 + db3c8c6 commit c577798
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions firedrake/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c577798

Please sign in to comment.