|
8 | 8 | from firedrake.functionspace import FunctionSpace, VectorFunctionSpace, TensorFunctionSpace |
9 | 9 | from firedrake.preconditioners.fdm import tabulate_exterior_derivative |
10 | 10 | 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 |
12 | 12 | from pyop2.utils import as_tuple |
13 | 13 | import numpy |
14 | 14 |
|
@@ -140,28 +140,18 @@ def get_vertex_dofs(V): |
140 | 140 |
|
141 | 141 | def get_divergence_mat(V, mat_type="aij", allow_repeated=False): |
142 | 142 | from firedrake import assemble |
143 | | - sobolev_space = V.ufl_element().sobolev_space |
144 | 143 | 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) |
165 | 155 |
|
166 | 156 | return (B,), dict() |
167 | 157 |
|
|
0 commit comments