Skip to content

Commit d33efa9

Browse files
committed
cleanup
1 parent 635b95e commit d33efa9

File tree

2 files changed

+28
-46
lines changed

2 files changed

+28
-46
lines changed

firedrake/mesh.py

+2-21
Original file line numberDiff line numberDiff line change
@@ -2400,29 +2400,10 @@ 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.function import Function
24042403
from firedrake.functionspace import FunctionSpace
24052404
from firedrake.projection import project
2406-
2407-
if self.topological_dimension() == 0:
2408-
# On vertex-only meshes we define the cell sizes as 1
2409-
P0 = FunctionSpace(self, "DG", 0)
2410-
return Function(P0).assign(1)
2411-
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
2418-
2419-
P1 = FunctionSpace(mesh, "Lagrange", 1)
2420-
h = project(CellSize(mesh), P1)
2421-
2422-
if P1.mesh() is not self:
2423-
# Transfer the Function on the P1 mesh into the original mesh
2424-
h = Function(P1.reconstruct(mesh=self), val=h.dat)
2425-
return h
2405+
P1 = FunctionSpace(self, "Lagrange", 1)
2406+
return project(CellSize(self), P1)
24262407

24272408
def clear_cell_sizes(self):
24282409
"""Reset the :attr:`cell_sizes` field on this mesh geometry.

tests/firedrake/regression/test_interpolate_zany.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -78,39 +78,51 @@ def vom(mesh):
7878
return VertexOnlyMesh(mesh, [(0.5, 0.5), (0.31, 0.72)])
7979

8080

81-
def test_interpolate_zany_into_vom(V, mesh, which, vom):
81+
@pytest.fixture
82+
def expr_at_vom(V, which, vom):
83+
mesh = V.mesh()
8284
degree = V.ufl_element().degree()
8385
x, y = SpatialCoordinate(mesh)
8486
expr = (x + y)**degree
8587

86-
f = Function(V)
87-
f.project(expr, solver_parameters={"ksp_type": "preonly",
88-
"pc_type": "lu"})
89-
fexpr = f
90-
vexpr = TestFunction(V)
91-
P0 = FunctionSpace(vom, "DG", 0)
9288
if which == "coefficient":
9389
P0 = FunctionSpace(vom, "DG", 0)
9490
elif which == "grad":
95-
fexpr = grad(fexpr)
96-
vexpr = grad(vexpr)
9791
expr = ufl.algorithms.expand_derivatives(grad(expr))
9892
P0 = VectorFunctionSpace(vom, "DG", 0)
9993

100-
expected = Function(P0)
101-
point = Constant([0]*mesh.geometric_dimension())
94+
fvom = Function(P0)
95+
point = Constant([0] * mesh.geometric_dimension())
10296
expr_at_pt = ufl.replace(expr, {SpatialCoordinate(mesh): point})
10397
for i, pt in enumerate(vom.coordinates.dat.data_ro):
10498
point.assign(pt)
105-
expected.dat.data[i] = numpy.asarray(expr_at_pt, dtype=float)
99+
fvom.dat.data[i] = numpy.asarray(expr_at_pt, dtype=float)
100+
return fvom
101+
102+
103+
def test_interpolate_zany_into_vom(V, mesh, which, expr_at_vom):
104+
degree = V.ufl_element().degree()
105+
x, y = SpatialCoordinate(mesh)
106+
expr = (x + y)**degree
107+
108+
f = Function(V)
109+
f.project(expr, solver_parameters={"ksp_type": "preonly",
110+
"pc_type": "lu"})
111+
fexpr = f
112+
vexpr = TestFunction(V)
113+
if which == "grad":
114+
fexpr = grad(fexpr)
115+
vexpr = grad(vexpr)
116+
117+
P0 = expr_at_vom.function_space()
106118

107119
# Interpolate a Function into P0(vom)
108120
f_at_vom = assemble(Interpolate(fexpr, P0))
109-
assert numpy.allclose(f_at_vom.dat.data_ro, expected.dat.data_ro)
121+
assert numpy.allclose(f_at_vom.dat.data_ro, expr_at_vom.dat.data_ro)
110122

111123
# Construct a Cofunction on P0(vom)*
112124
Fvom = Cofunction(P0.dual()).assign(1)
113-
expected_action = assemble(action(Fvom, expected))
125+
expected_action = assemble(action(Fvom, expr_at_vom))
114126

115127
# Interpolate a Function into Fvom
116128
f_at_vom = assemble(Interpolate(fexpr, Fvom))
@@ -120,14 +132,3 @@ def test_interpolate_zany_into_vom(V, mesh, which, vom):
120132
expr_vom = assemble(Interpolate(vexpr, Fvom))
121133
f_at_vom = assemble(action(expr_vom, f))
122134
assert numpy.allclose(f_at_vom, expected_action)
123-
124-
125-
def test_high_order_mesh_cell_sizes():
126-
msh1 = UnitSquareMesh(2, 2)
127-
h1 = msh1.cell_sizes
128-
129-
P2 = msh1.coordinates.function_space().reconstruct(degree=2)
130-
msh2 = Mesh(Function(P2).interpolate(msh1.coordinates))
131-
h2 = msh2.cell_sizes
132-
133-
assert numpy.allclose(h1.dat.data, h2.dat.data)

0 commit comments

Comments
 (0)