Skip to content

Commit 6e5c84a

Browse files
committed
suggestions from review
1 parent 1abec01 commit 6e5c84a

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

firedrake/assemble.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,14 +835,10 @@ def restructure_base_form(expr, visited=None):
835835
def preprocess_base_form(expr, mat_type=None, form_compiler_parameters=None):
836836
"""Preprocess ufl.BaseForm objects"""
837837
original_expr = expr
838-
if mat_type != "matfree":
838+
if len(expr.arguments()) == 2 and mat_type != "matfree":
839839
# Don't expand derivatives if `mat_type` is 'matfree'
840840
# For "matfree", Form evaluation is delayed
841-
try:
842-
expr = BaseFormAssembler.expand_derivatives_form(expr, form_compiler_parameters)
843-
except ValueError:
844-
# BaseForms with SLATE tensors are not fully supported in UFL.
845-
pass
841+
expr = BaseFormAssembler.expand_derivatives_form(expr, form_compiler_parameters)
846842
if not isinstance(expr, (ufl.form.Form, slate.TensorBase)):
847843
# => No restructuring needed for Form and slate.TensorBase
848844
expr = BaseFormAssembler.restructure_base_form_preorder(expr)

firedrake/variational_solver.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,22 @@ def dm(self):
133133

134134
@staticmethod
135135
def compute_bc_lifting(J, u, L=0):
136-
"""Return the action of the bilinear form J (without bcs) on a Function u."""
136+
"""Compute the residual after lifting DirichletBCs.
137+
138+
Parameters
139+
----------
140+
J : ufl.BaseForm or slate.TensorBase
141+
The Jacobian bilinear form.
142+
u : firedrake.Function
143+
The Function on which DirichletBCs are applied.
144+
L : ufl.BaseForm or slate.TensorBase
145+
The unlifted residual linear form.
146+
147+
Return
148+
------
149+
F : ufl.BaseForm or slate.TensorBase
150+
The residual J*u-L after lifting DirichletBCs.
151+
"""
137152
if isinstance(J, MatrixBase) and J.has_bcs:
138153
# Extract the full form without bcs
139154
if not isinstance(J.a, (ufl.BaseForm, slate.slate.TensorBase)):
@@ -399,14 +414,12 @@ def __init__(self, a, L, u, bcs=None, aP=None,
399414
"""
400415
# In the linear case, the Jacobian is the equation LHS (J=a).
401416
# Jacobian is checked in superclass, but let's check L here.
402-
if not isinstance(L, (ufl.BaseForm, slate.slate.TensorBase)) and L == 0:
403-
F = self.compute_bc_lifting(a, u)
404-
else:
405-
if not isinstance(L, (ufl.BaseForm, slate.slate.TensorBase)):
406-
raise TypeError("Provided RHS is a '%s', not a Form or Slate Tensor" % type(L).__name__)
417+
if isinstance(L, (ufl.BaseForm, slate.slate.TensorBase)):
407418
if len(L.arguments()) != 1 and not L.empty():
408419
raise ValueError("Provided RHS is not a linear form")
409-
F = self.compute_bc_lifting(a, u, L=L)
420+
elif L != 0:
421+
raise TypeError(f"Provided RHS is a '{type(L).__name__}', not a Form or Slate Tensor")
422+
F = self.compute_bc_lifting(a, u, L=L)
410423

411424
super(LinearVariationalProblem, self).__init__(F, u, bcs=bcs, J=a, Jp=aP,
412425
form_compiler_parameters=form_compiler_parameters,

0 commit comments

Comments
 (0)