@@ -2399,10 +2399,29 @@ def cell_sizes(self):
2399
2399
2400
2400
This is computed by the :math:`L^2` projection of the local mesh element size."""
2401
2401
from firedrake .ufl_expr import CellSize
2402
+ from firedrake .function import Function
2402
2403
from firedrake .functionspace import FunctionSpace
2403
2404
from firedrake .projection import project
2404
- P1 = FunctionSpace (self , "Lagrange" , 1 )
2405
- return project (CellSize (self ), P1 )
2405
+
2406
+ if self .topological_dimension () == 0 :
2407
+ # On vertex-only meshes we define the cell sizes as 1
2408
+ P0 = FunctionSpace (self , "DG" , 0 )
2409
+ return Function (P0 ).assign (1 )
2410
+
2411
+ if self .ufl_coordinate_element ().degree () > 1 :
2412
+ # We need a P1 mesh, as CellSize is not defined on high-order meshes
2413
+ VectorP1 = self .coordinates .function_space ().reconstruct (degree = 1 )
2414
+ mesh = Mesh (Function (VectorP1 ).interpolate (self .coordinates ))
2415
+ else :
2416
+ mesh = self
2417
+
2418
+ P1 = FunctionSpace (mesh , "Lagrange" , 1 )
2419
+ h = project (CellSize (mesh ), P1 )
2420
+
2421
+ if P1 .mesh () is not self :
2422
+ # Transfer the Function on the P1 mesh into the original mesh
2423
+ h = Function (P1 .reconstruct (mesh = self ), val = h .dat )
2424
+ return h
2406
2425
2407
2426
def clear_cell_sizes (self ):
2408
2427
"""Reset the :attr:`cell_sizes` field on this mesh geometry.
0 commit comments