1515from ufl .core .expr import Expr
1616from ufl .core .multiindex import indices
1717from ufl .domain import AbstractDomain , MeshSequence , extract_unique_domain
18- from ufl .functionspace import FunctionSpace
1918from ufl .tensors import as_tensor
2019
2120if TYPE_CHECKING :
@@ -428,15 +427,14 @@ def apply(self, expr, domain=None):
428427 subdomain = domain [i ] if isinstance (domain , MeshSequence ) else None
429428 rmapped = subelem .pullback .apply (rsub , domain = subdomain )
430429 # Flatten into the pulled back expression for the whole thing
431- g_components .extend ([ rmapped [idx ] for idx in np .ndindex (rmapped .ufl_shape )] )
430+ g_components .extend (rmapped [idx ] for idx in np .ndindex (rmapped .ufl_shape ))
432431 offset += subelem .reference_value_size
433432 # And reshape appropriately
434- space = FunctionSpace ( domain , self ._element )
435- f = as_tensor (np .asarray (g_components ).reshape (space . value_shape ))
436- if f .ufl_shape != space . value_shape :
433+ value_shape = self . physical_value_shape ( self ._element , domain )
434+ f = as_tensor (np .asarray (g_components ).reshape (value_shape ))
435+ if f .ufl_shape != value_shape :
437436 raise ValueError (
438- "Expecting pulled back expression with shape "
439- f"'{ space .value_shape } ', got '{ f .ufl_shape } '"
437+ f"Expecting pulled back expression with shape '{ value_shape } ', got '{ f .ufl_shape } '"
440438 )
441439 return f
442440
@@ -453,7 +451,8 @@ def physical_value_shape(self, element, domain) -> tuple[int, ...]:
453451 assert element == self ._element
454452 domains = domain .iterable_like (element )
455453 dim = sum (
456- FunctionSpace (d , e ).value_size for d , e in zip (domains , self ._element .sub_elements )
454+ int (np .prod (e .pullback .physical_value_shape (e , d ), dtype = int ))
455+ for d , e in zip (domains , self ._element .sub_elements )
457456 )
458457 return (dim ,)
459458
@@ -496,8 +495,6 @@ def apply(self, expr, domain=None):
496495
497496 Returns: The function pulled back to the reference cell
498497 """
499- domain = extract_unique_domain (expr )
500- space = FunctionSpace (domain , self ._element )
501498 rflat = [expr [idx ] for idx in np .ndindex (expr .ufl_shape )]
502499 g_components = []
503500 offsets = [0 ]
@@ -520,13 +517,13 @@ def apply(self, expr, domain=None):
520517 subdomain = domain [i ] if isinstance (domain , MeshSequence ) else None
521518 rmapped = subelem .pullback .apply (rsub , domain = subdomain )
522519 # Flatten into the pulled back expression for the whole thing
523- g_components .extend ([ rmapped [idx ] for idx in np .ndindex (rmapped .ufl_shape )] )
520+ g_components .extend (rmapped [idx ] for idx in np .ndindex (rmapped .ufl_shape ))
524521 # And reshape appropriately
525- f = as_tensor (np .asarray (g_components ).reshape (space .value_shape ))
526- if f .ufl_shape != space .value_shape :
522+ value_shape = self .physical_value_shape (self ._element , domain )
523+ f = as_tensor (np .asarray (g_components ).reshape (value_shape ))
524+ if f .ufl_shape != value_shape :
527525 raise ValueError (
528- f"Expecting pulled back expression with shape "
529- f"'{ space .value_shape } ', got '{ f .ufl_shape } '"
526+ f"Expecting pulled back expression with shape '{ value_shape } ', got '{ f .ufl_shape } '"
530527 )
531528 return f
532529
@@ -543,7 +540,7 @@ def physical_value_shape(self, element, domain) -> tuple[int, ...]:
543540 assert isinstance (element , type (self ._element ))
544541 subelem = element .sub_elements [0 ]
545542 pvs = subelem .pullback .physical_value_shape (subelem , domain )
546- return tuple (i + 1 for i in max (self ._symmetry .keys ())) + pvs
543+ return tuple (int ( i ) + 1 for i in max (self ._symmetry .keys ())) + pvs
547544
548545
549546class PhysicalPullback (AbstractPullback ):
0 commit comments