Skip to content

Commit

Permalink
split logic via isinstance not TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
JHopeCollins committed Dec 19, 2024
1 parent e4f1a4d commit e9e6d68
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions firedrake/formmanipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ def argument(self, o):
V_is = V.subfunctions
indices = self.blocks[o.number()]

try:
indices = tuple(indices)
nidx = len(indices)
except TypeError:
# Only one index provided.
# Only one index provided.
if isinstance(indices, int):
indices = (indices, )
nidx = 1

if nidx == 1:
if len(indices) == 1:
W = V_is[indices[0]]
W = FunctionSpace(W.mesh(), W.ufl_element())
a = (Argument(W, o.number(), part=o.part()), )
Expand Down Expand Up @@ -141,12 +137,9 @@ def cofunction(self, o):
indices = self.blocks[0]
V_is = V.subfunctions

try:
indices = tuple(indices)
nidx = len(indices)
except TypeError: # Only one index
# Only one index provided.
if isinstance(indices, int):
indices = (indices, )
nidx = 1

# for two-forms, the cofunction should only
# be returned for the diagonal blocks, so
Expand All @@ -164,7 +157,7 @@ def cofunction(self, o):
# the full space. This means that the right hand side
# of the fieldsplit problem will be correct.
if on_diag:
if nidx == 1:
if len(indices) == 1:
i = indices[0]
W = V_is[i]
W = DualSpace(W.mesh(), W.ufl_element())
Expand Down

0 comments on commit e9e6d68

Please sign in to comment.