Skip to content

Commit c55b648

Browse files
committed
dmhooks: support RestrictedFunctionSpace
1 parent c1d8a15 commit c55b648

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

firedrake/bcs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ def reconstruct(self, field=None, V=None, g=None, sub_domain=None, use_split=Fal
319319
V = V.sub(index)
320320
if g is None:
321321
g = self._original_arg
322+
if isinstance(g, firedrake.Function) and g.function_space() != V:
323+
g = firedrake.Function(V).interpolate(g)
322324
if sub_domain is None:
323325
sub_domain = self.sub_domain
324326
if field is not None:
@@ -739,11 +741,11 @@ def restricted_function_space(V, ids):
739741
return V
740742

741743
assert len(ids) == len(V)
742-
spaces = [Vsub if len(boundary_set) == 0 else
743-
firedrake.RestrictedFunctionSpace(Vsub, boundary_set=boundary_set)
744-
for Vsub, boundary_set in zip(V, ids)]
744+
spaces = [V_ if len(boundary_set) == 0 else
745+
firedrake.RestrictedFunctionSpace(V_, boundary_set=boundary_set, name=V_.name)
746+
for V_, boundary_set in zip(V, ids)]
745747

746748
if len(spaces) == 1:
747749
return spaces[0]
748750
else:
749-
return firedrake.MixedFunctionSpace(spaces)
751+
return firedrake.MixedFunctionSpace(spaces, name=V.name)

firedrake/dmhooks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ def get_function_space(dm):
5353
:raises RuntimeError: if no function space was found.
5454
"""
5555
info = dm.getAttr("__fs_info__")
56-
meshref, element, indices, (name, names) = info
56+
meshref, element, indices, (name, names), boundary_sets = info
5757
mesh = meshref()
5858
if mesh is None:
5959
raise RuntimeError("Somehow your mesh was collected, this should never happen")
6060
V = firedrake.FunctionSpace(mesh, element, name=name)
61+
if any(boundary_sets):
62+
V = firedrake.bcs.restricted_function_space(V, boundary_sets)
6163
if len(V) > 1:
6264
for V_, name in zip(V, names):
6365
V_.topological.name = name
@@ -93,8 +95,8 @@ def set_function_space(dm, V):
9395
if len(V) > 1:
9496
names = tuple(V_.name for V_ in V)
9597
element = V.ufl_element()
96-
97-
info = (weakref.ref(mesh), element, tuple(reversed(indices)), (V.name, names))
98+
boundary_sets = tuple(V_.boundary_set for V_ in V)
99+
info = (weakref.ref(mesh), element, tuple(reversed(indices)), (V.name, names), boundary_sets)
98100
dm.setAttr("__fs_info__", info)
99101

100102

firedrake/functionspaceimpl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,7 @@ def __init__(self, function_space, boundary_set=frozenset(), name=None):
901901
function_space.ufl_element(),
902902
label=self._label)
903903
self.function_space = function_space
904-
self.name = name or (function_space.name or "Restricted" + "_"
905-
+ "_".join(sorted(map(str, self.boundary_set))))
904+
self.name = name or function_space.name
906905

907906
def set_shared_data(self):
908907
sdata = get_shared_data(self._mesh, self.ufl_element(), self.boundary_set)

0 commit comments

Comments
 (0)