Skip to content

Commit

Permalink
Enable to set the measure options.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ig-dolci committed Dec 8, 2024
1 parent 6a20368 commit ff16183
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions firedrake/adjoint_utils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def _ad_convert_riesz(self, value, options=None):
options = {} if options is None else options
riesz_representation = options.get("riesz_representation", "L2")
solver_options = options.get("solver_options", {})
mensure_options = options.get("mensure_options", {})
V = options.get("function_space", self.function_space())
if value == 0.:
# In adjoint-based differentiation, value == 0. arises only when
Expand All @@ -243,7 +244,8 @@ def _ad_convert_riesz(self, value, options=None):
raise TypeError("Expected a Cofunction")

ret = Function(V)
a = self._define_riesz_map_form(riesz_representation, V)
a = self._define_riesz_map_form(
riesz_representation, V, mensure_options)
firedrake.solve(a == value, ret, **solver_options)
return ret

Expand All @@ -254,17 +256,18 @@ def _ad_convert_riesz(self, value, options=None):
raise ValueError(
"Unknown Riesz representation %s" % riesz_representation)

def _define_riesz_map_form(self, riesz_representation, V):
def _define_riesz_map_form(self, riesz_representation, V, mensure_options):
from firedrake import TrialFunction, TestFunction

u = TrialFunction(V)
v = TestFunction(V)
if riesz_representation == "L2":
a = firedrake.inner(u, v)*firedrake.dx
a = firedrake.inner(u, v)*firedrake.dx(**mensure_options)

elif riesz_representation == "H1":
a = firedrake.inner(u, v)*firedrake.dx \
+ firedrake.inner(firedrake.grad(u), firedrake.grad(v))*firedrake.dx
a = firedrake.inner(u, v)*firedrake.dx(**mensure_options) \
+ firedrake.inner(firedrake.grad(u), firedrake.grad(v)
) * firedrake.dx(**mensure_options)

else:
raise NotImplementedError(
Expand Down

0 comments on commit ff16183

Please sign in to comment.