Skip to content

Commit 7a07dff

Browse files
committed
cleanup
1 parent 3c63f6c commit 7a07dff

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

firedrake/functionspaceimpl.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def collapse(self):
357357
return type(self).create(self.topological.collapse(), self.mesh())
358358

359359
@classmethod
360-
def make_function_space(cls, mesh, element, name=None, boundary_set=None):
360+
def make_function_space(cls, mesh, element, name=None):
361361
r"""Factory method for :class:`.WithGeometryBase`."""
362362
mesh.init()
363363
topology = mesh.topology
@@ -376,25 +376,25 @@ def make_function_space(cls, mesh, element, name=None, boundary_set=None):
376376
if mesh is not topology:
377377
# Create a concrete WithGeometry or FiredrakeDualSpace on this mesh
378378
new = cls.create(new, mesh)
379-
380-
if boundary_set:
381-
new = RestrictedFunctionSpace(new, boundary_set=boundary_set)
382-
if mesh is not topology:
383-
new = cls.create(new, mesh)
384379
return new
385380

386-
def reconstruct(self, mesh=None, element=None, name=None, **kwargs):
381+
def reconstruct(self, mesh=None, element=None, boundary_set=None, name=None, **kwargs):
387382
r"""Reconstruct this :class:`.WithGeometryBase` .
388383
389384
:kwarg mesh: the new :func:`~.Mesh` (defaults to same mesh)
390385
:kwarg element: the new :class:`finat.ufl.FiniteElement` (defaults to same element)
386+
:kwarg boundary_set: boundary subdomain labels defining a new
387+
:func:`~.RestrictedFunctionSpace` (defaults to same boundary_set)
391388
:kwarg name: the new name (defaults to None)
392389
:returns: the new function space of the same class as ``self``.
393390
394391
Any extra kwargs are used to reconstruct the finite element.
395392
For details see :meth:`finat.ufl.finiteelement.FiniteElement.reconstruct`.
396393
"""
397394
V_parent = self
395+
if boundary_set is None:
396+
boundary_set = V_parent.boundary_set
397+
398398
# Deal with ProxyFunctionSpace
399399
indices = []
400400
while True:
@@ -409,17 +409,19 @@ def reconstruct(self, mesh=None, element=None, name=None, **kwargs):
409409

410410
if mesh is None:
411411
mesh = V_parent.mesh()
412-
413412
if element is None:
414413
element = V_parent.ufl_element()
414+
415415
cell = mesh.topology.ufl_cell()
416416
if len(kwargs) > 0 or element.cell != cell:
417417
element = element.reconstruct(cell=cell, **kwargs)
418418

419-
V = type(self).make_function_space(mesh, element, name=name,
420-
boundary_set=V_parent.boundary_set)
419+
V = type(self).make_function_space(mesh, element, name=name)
421420
for i in reversed(indices):
422421
V = V.sub(i)
422+
423+
if boundary_set:
424+
V = RestrictedFunctionSpace(V, boundary_set=boundary_set, name=V.name)
423425
return V
424426

425427

@@ -884,6 +886,15 @@ class RestrictedFunctionSpace(FunctionSpace):
884886
If using this class to solve or similar, a list of DirichletBCs will still
885887
need to be specified on this space and passed into the function.
886888
"""
889+
def __new__(cls, function_space, boundary_set=frozenset(), name=None):
890+
mesh = function_space.mesh()
891+
if mesh is not mesh.topology:
892+
# Restrict WithGeometry and return a WithGeometry
893+
V = RestrictedFunctionSpace(function_space.topological,
894+
boundary_set=boundary_set, name=name)
895+
return type(function_space).create(V, mesh)
896+
return FunctionSpace.__new__(cls)
897+
887898
def __init__(self, function_space, boundary_set=frozenset(), name=None):
888899
label = ""
889900
boundary_set_ = []
@@ -1207,7 +1218,7 @@ class ProxyFunctionSpace(FunctionSpace):
12071218
"""
12081219
def __new__(cls, mesh, element, name=None):
12091220
topology = mesh.topology
1210-
self = super(ProxyFunctionSpace, cls).__new__(cls)
1221+
self = FunctionSpace.__new__(cls)
12111222
if mesh is not topology:
12121223
return WithGeometry.create(self, mesh)
12131224
else:
@@ -1262,7 +1273,7 @@ class ProxyRestrictedFunctionSpace(RestrictedFunctionSpace):
12621273
"""
12631274
def __new__(cls, function_space, boundary_set=frozenset(), name=None):
12641275
topology = function_space._mesh.topology
1265-
self = super(ProxyRestrictedFunctionSpace, cls).__new__(cls)
1276+
self = FunctionSpace.__new__(cls)
12661277
if function_space._mesh is not topology:
12671278
return WithGeometry.create(self, function_space._mesh)
12681279
else:

firedrake/mg/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def physical_node_locations(V):
140140
try:
141141
return cache[key]
142142
except KeyError:
143-
Vc = V.reconstruct(element=finat.ufl.VectorElement(element, dim=mesh.geometric_dimension()))
143+
Vc = V.collapse().reconstruct(element=finat.ufl.VectorElement(element, dim=mesh.geometric_dimension()))
144144

145145
# FIXME: This is unsafe for DG coordinates and CG target spaces.
146146
locations = firedrake.assemble(firedrake.Interpolate(firedrake.SpatialCoordinate(mesh), Vc))

0 commit comments

Comments
 (0)