Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrichardson committed Aug 11, 2022
2 parents 8c10b78 + 07b61c3 commit b3c61d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ufl/constant.py
Expand Up @@ -66,6 +66,12 @@ def __eq__(self, other):
self._ufl_domain == other._ufl_domain and
self._ufl_shape == self._ufl_shape)

def _ufl_signature_data_(self, renumbering):
"Signature data for constant depends on renumbering"
return "Constant({}, {}, {})".format(
self._ufl_domain._ufl_signature_data_(renumbering), repr(self._ufl_shape),
repr(renumbering[self]))


def VectorConstant(domain, count=None):
domain = as_domain(domain)
Expand Down
19 changes: 19 additions & 0 deletions ufl/form.py
Expand Up @@ -81,6 +81,7 @@ class Form(object):
"_arguments",
"_coefficients",
"_coefficient_numbering",
"_constant_numbering",
"_constants",
"_hash",
"_signature",
Expand Down Expand Up @@ -111,9 +112,12 @@ def __init__(self, integrals):
self._arguments = None
self._coefficients = None
self._coefficient_numbering = None
self._constant_numbering = None

from ufl.algorithms.analysis import extract_constants
self._constants = extract_constants(self)
self._constant_numbering = dict(
(c, i) for i, c in enumerate(self._constants))

# Internal variables for caching of hash and signature after
# first request
Expand Down Expand Up @@ -237,6 +241,11 @@ def coefficient_numbering(self):
def constants(self):
return self._constants

def constant_numbering(self):
"""Return a contiguous numbering of constants in a mapping
``{constant:number}``."""
return self._constant_numbering

def signature(self):
"Signature for use with jit cache (independent of incidental numbering of indices etc.)"
if self._signature is None:
Expand Down Expand Up @@ -458,9 +467,11 @@ def _compute_renumbering(self):
# Include integration domains and coefficients in renumbering
dn = self.domain_numbering()
cn = self.coefficient_numbering()
cnstn = self.constant_numbering()
renumbering = {}
renumbering.update(dn)
renumbering.update(cn)
renumbering.update(cnstn)

# Add domains of coefficients, these may include domains not
# among integration domains
Expand All @@ -479,6 +490,14 @@ def _compute_renumbering(self):
renumbering[d] = k
k += 1

# Add domains of constants, these may include domains not
# among integration domains
for c in self._constants:
d = c.ufl_domain()
if d is not None and d not in renumbering:
renumbering[d] = k
k += 1

return renumbering

def _compute_signature(self):
Expand Down

0 comments on commit b3c61d6

Please sign in to comment.