@@ -2400,22 +2400,28 @@ def cell_sizes(self):
2400
2400
2401
2401
This is computed by the :math:`L^2` projection of the local mesh element size."""
2402
2402
from firedrake .ufl_expr import CellSize
2403
- from firedrake .functionspace import FunctionSpace
2404
2403
from firedrake .function import Function
2404
+ from firedrake .functionspace import FunctionSpace
2405
2405
from firedrake .projection import project
2406
2406
2407
- mesh = self
2408
2407
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 )
2410
2410
return Function (P0 ).assign (1 )
2411
2411
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
2415
2418
2419
+ # Project the CellSize into P1
2416
2420
P1 = FunctionSpace (mesh , "Lagrange" , 1 )
2417
2421
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
2419
2425
h = Function (P1 .reconstruct (mesh = self ), val = h .dat )
2420
2426
return h
2421
2427
0 commit comments