Skip to content

Commit 81e8d34

Browse files
committed
Cleanup
1 parent 65b636f commit 81e8d34

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

firedrake/preconditioners/bddc.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from firedrake.functionspace import FunctionSpace, VectorFunctionSpace, TensorFunctionSpace
99
from firedrake.preconditioners.fdm import tabulate_exterior_derivative
1010
from firedrake.preconditioners.hiptmair import curl_to_grad
11-
from ufl import curl, div, H1, H2, HCurl, HDiv, inner, dx, JacobianDeterminant
11+
from ufl import H1, H2, HCurl, inner, dx, JacobianDeterminant
1212
from pyop2.utils import as_tuple
1313
import numpy
1414

@@ -140,28 +140,18 @@ def get_vertex_dofs(V):
140140

141141
def get_divergence_mat(V, mat_type="aij", allow_repeated=False):
142142
from firedrake import assemble
143-
sobolev_space = V.ufl_element().sobolev_space
144143
degree = max(as_tuple(V.ufl_element().degree()))
145-
d = {HCurl: curl, HDiv: div}[sobolev_space]
146-
if V.shape == ():
147-
make_function_space = FunctionSpace
148-
elif len(V.shape) == 1:
149-
make_function_space = VectorFunctionSpace
150-
else:
151-
make_function_space = TensorFunctionSpace
152-
153-
qdegree = degree-1
154-
Q = make_function_space(V.mesh(), "DG", 0, variant=f"integral({qdegree})")
155-
if False:
156-
b = inner(d(TrialFunction(V)), TestFunction(Q)) * dx(degree=qdegree)
157-
B = assemble(b, mat_type=mat_type).petscmat
158-
else:
159-
B = tabulate_exterior_derivative(V, Q, mat_type=mat_type, allow_repeated=allow_repeated)
160-
# Fix scale
161-
Jdet = JacobianDeterminant(V.mesh())
162-
s = assemble(inner(TrialFunction(Q)*(1/Jdet), TestFunction(Q))*dx(degree=0), diagonal=True)
163-
with s.dat.vec as svec:
164-
B.diagonalScale(svec, None)
144+
145+
Q = TensorFunctionSpace(V.mesh(), "DG", 0, variant=f"integral({degree-1})", shape=V.value_shape[:-1])
146+
# d = {HCurl: curl, HDiv: div}[V.ufl_element().sobolev_space]
147+
# b = inner(d(TrialFunction(V)), TestFunction(Q)) * dx(degree=degree-1)
148+
# B = assemble(b, mat_type=mat_type).petscmat
149+
150+
B = tabulate_exterior_derivative(V, Q, mat_type=mat_type, allow_repeated=allow_repeated)
151+
Jdet = JacobianDeterminant(V.mesh())
152+
s = assemble(inner(TrialFunction(Q)*(1/Jdet), TestFunction(Q))*dx(degree=0), diagonal=True)
153+
with s.dat.vec as svec:
154+
B.diagonalScale(svec, None)
165155

166156
return (B,), dict()
167157

firedrake/preconditioners/facet_split.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import partial
22
from mpi4py import MPI
33
from pyop2 import op2, PermutedMap
4-
from finat.ufl import RestrictedElement, MixedElement, TensorElement, VectorElement
4+
from finat.ufl import BrokenElement, RestrictedElement, MixedElement, TensorElement, VectorElement
55
from firedrake.petsc import PETSc
66
from firedrake.preconditioners.base import PCBase
77
import firedrake.dmhooks as dmhooks
@@ -206,7 +206,9 @@ def restrict(ele, restriction_domain):
206206
if isinstance(ele, VectorElement):
207207
return type(ele)(restrict(ele._sub_element, restriction_domain), dim=ele.num_sub_elements)
208208
elif isinstance(ele, TensorElement):
209-
return type(ele)(restrict(ele._sub_element, restriction_domain), shape=ele._shape, symmetry=ele._symmety)
209+
return type(ele)(restrict(ele._sub_element, restriction_domain), shape=ele._shape, symmetry=ele._symmetry)
210+
elif restriction_domain == "broken":
211+
return BrokenElement(ele)
210212
else:
211213
return RestrictedElement(ele, restriction_domain)
212214

firedrake/preconditioners/fdm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
evaluate_dual,
99
get_permutation_to_nodal_elements,
1010
cache_generate_code)
11-
from firedrake.preconditioners.facet_split import split_dofs, restricted_dofs
11+
from firedrake.preconditioners.facet_split import restrict, restricted_dofs, split_dofs
1212
from firedrake.formmanipulation import ExtractSubBlock
1313
from firedrake.functionspace import FunctionSpace, MixedFunctionSpace
1414
from firedrake.function import Function
@@ -41,7 +41,7 @@
4141

4242

4343
def broken_function(V, val):
44-
W = FunctionSpace(V.mesh(), finat.ufl.BrokenElement(V.ufl_element()))
44+
W = FunctionSpace(V.mesh(), restrict(V.ufl_element(), "broken"))
4545
w = Function(W, dtype=val.dtype)
4646
v = Function(V, val=val)
4747
domain = "{[i]: 0 <= i < v.dofs}"

0 commit comments

Comments
 (0)