Skip to content

Commit cefb398

Browse files
committed
Address review comments
1 parent de5f5ee commit cefb398

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

firedrake/interpolation.py

+3
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,9 @@ def callable():
10131013
# Make sure we have an expression of the right length i.e. a value for
10141014
# each component in the value shape of each function space
10151015
loops = []
1016+
if numpy.prod(expr.ufl_shape, dtype=int) != V.value_size:
1017+
raise RuntimeError('Expression of length %d required, got length %d'
1018+
% (V.value_size, numpy.prod(expr.ufl_shape, dtype=int)))
10161019

10171020
if len(V) == 1:
10181021
loops.extend(_interpolator(V, tensor, expr, subset, arguments, access, bcs=bcs))

firedrake/mesh.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -2400,22 +2400,28 @@ def cell_sizes(self):
24002400
24012401
This is computed by the :math:`L^2` projection of the local mesh element size."""
24022402
from firedrake.ufl_expr import CellSize
2403-
from firedrake.functionspace import FunctionSpace
24042403
from firedrake.function import Function
2404+
from firedrake.functionspace import FunctionSpace
24052405
from firedrake.projection import project
24062406

2407-
mesh = self
24082407
if self.topological_dimension() == 0:
2409-
P0 = FunctionSpace(mesh, "DG", 0)
2408+
# On vertex-only meshes we define the cell sizes as 1
2409+
P0 = FunctionSpace(self, "DG", 0)
24102410
return Function(P0).assign(1)
24112411

2412-
elif self.ufl_coordinate_element().degree() > 1:
2413-
V = self.coordinates.function_space().reconstruct(degree=1)
2414-
mesh = Mesh(Function(V).interpolate(self.coordinates))
2412+
if self.ufl_coordinate_element().degree() > 1:
2413+
# We need a P1 mesh, as CellSize is not defined on high-order meshes
2414+
VectorP1 = self.coordinates.function_space().reconstruct(degree=1)
2415+
mesh = Mesh(Function(VectorP1).interpolate(self.coordinates))
2416+
else:
2417+
mesh = self
24152418

2419+
# Project the CellSize into P1
24162420
P1 = FunctionSpace(mesh, "Lagrange", 1)
24172421
h = project(CellSize(mesh), P1)
2418-
if self is not mesh:
2422+
2423+
if P1.mesh() is not self:
2424+
# Transfer the Function on the P1 mesh into the original mesh
24192425
h = Function(P1.reconstruct(mesh=self), val=h.dat)
24202426
return h
24212427

0 commit comments

Comments
 (0)