File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,6 +188,22 @@ def test_zero_base_form_list_arguments():
188188 assert hash (f ) == hash (ZeroBaseForm ((v ,)))
189189
190190
191+ def test_zero_base_form_signature ():
192+ domain_2d = Mesh (LagrangeElement (triangle , 1 , (2 ,)))
193+ f_2d = LagrangeElement (triangle , 1 )
194+ V = FunctionSpace (domain_2d , f_2d )
195+
196+ v = TestFunction (V )
197+ f = ZeroBaseForm ((v ,))
198+
199+ assert f .signature () == ZeroBaseForm ((v ,)).signature ()
200+ assert isinstance (f .signature (), str )
201+
202+ W = FunctionSpace (domain_2d , LagrangeElement (triangle , 2 ))
203+ w = TestFunction (W )
204+ assert f .signature () != ZeroBaseForm ((w ,)).signature ()
205+
206+
191207def test_zero_base_form_reconstruct ():
192208 # ZeroBaseForm._ufl_expr_reconstruct_ inherited BaseForm's default,
193209 # `type(self)(*operands)`, which unpacks `ufl_operands` into positional
Original file line number Diff line number Diff line change 1111# Modified by Nacime Bouziani, 2020.
1212# Modified by Jørgen S. Dokken 2023.
1313
14+ import hashlib
1415import numbers
1516import typing
1617import warnings
@@ -884,6 +885,7 @@ class ZeroBaseForm(BaseForm):
884885 "_coefficients" ,
885886 "_domains" ,
886887 "_hash" ,
888+ "_signature" ,
887889 # Pyadjoint compatibility
888890 "form" ,
889891 "ufl_operands" ,
@@ -896,6 +898,7 @@ def __init__(self, arguments):
896898 self ._arguments = arguments
897899 self .ufl_operands = arguments
898900 self ._hash = None
901+ self ._signature = None
899902 self ._domains = None
900903 self .form = None
901904
@@ -927,6 +930,19 @@ def empty(self):
927930 """Returns whether the ZeroBaseForm has no components, which is always true."""
928931 return True
929932
933+ def signature (self ):
934+ """Return a signature for use with JIT caches."""
935+ if self ._signature is None :
936+ renumbering = {
937+ domain : i for i , domain in enumerate (self .ufl_domains ())
938+ }
939+ data = tuple (
940+ argument ._ufl_signature_data_ (renumbering )
941+ for argument in self .arguments ()
942+ )
943+ self ._signature = hashlib .sha512 (str (data ).encode ("utf-8" )).hexdigest ()
944+ return self ._signature
945+
930946 def __ne__ (self , other ):
931947 """Overwrite BaseForm.__neq__ which relies on `equals`."""
932948 return not self == other
You can’t perform that action at this time.
0 commit comments