Skip to content

Commit 26a110f

Browse files
committed
Adjust with latest nightly: codim
1 parent 9412820 commit 26a110f

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ ruff format .
161161

162162
```Shell
163163
pip install '.[test]'
164-
py.test -v tests/
164+
py.test -v test/
165165
```
166166

167167
### Releases

src/dolfinx_external_operator/external_operator.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,7 @@ def evaluate_operands(
137137
evaluated_operand = expr.eval(mesh, cells)
138138
elif codim == 1:
139139
assert entity_maps is not None
140-
# Invert entity map as it goes from parent to sub not sub to parent
141-
inverted_map = np.empty(len(cells), dtype=np.int32)
142-
indices = np.flatnonzero(entity_maps[mesh] >= 0)
143-
inverted_map[entity_maps[mesh][indices]] = indices
144-
integration_entities = fem.compute_integration_domains(
145-
fem.IntegralType.exterior_facet,
146-
operand.function_space.mesh.topology,
147-
inverted_map,
148-
)
149-
evaluated_operand = expr.eval(operand_mesh, integration_entities)
140+
evaluated_operand = expr.eval(operand_mesh, entity_maps[mesh])
150141
else:
151142
raise NotImplementedError("Only codim 0 and 1 are supported.")
152143
evaluated_operands[operand] = evaluated_operand

test/test_codim_external_operator.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ def test_external_operator_codim_1(quadrature_degree):
6060
"""Test assembly of codim 1 external operator"""
6161

6262
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 5, 5)
63-
mesh.topology.create_connectivity(mesh.topology.dim - 1, mesh.topology.dim)
63+
tdim = mesh.topology.dim
64+
mesh.topology.create_connectivity(tdim, tdim - 1)
65+
c_to_f = mesh.topology.connectivity(tdim, tdim - 1)
66+
mesh.topology.create_connectivity(tdim - 1, tdim)
67+
f_to_c = mesh.topology.connectivity(tdim - 1, tdim)
68+
6469
ext_facets = dolfinx.mesh.exterior_facet_indices(mesh.topology)
6570

6671
V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1))
@@ -69,10 +74,19 @@ def test_external_operator_codim_1(quadrature_degree):
6974

7075
submesh, sub_to_parent, _, _ = dolfinx.mesh.create_submesh(mesh, mesh.topology.dim - 1, ext_facets)
7176
num_entities = mesh.topology.index_map(mesh.topology.dim - 1).size_local
72-
parent_to_sub = np.full(num_entities, -1, dtype=np.int32)
73-
parent_to_sub[sub_to_parent] = np.arange(len(sub_to_parent), dtype=np.int32)
77+
parent_to_sub = np.empty((len(ext_facets), 2), dtype=np.int32)
78+
# print(num_entities)
79+
80+
for i, facet in enumerate(ext_facets):
81+
cells = f_to_c.links(facet)
82+
cell = cells[0]
83+
local_facets = c_to_f.links(cell)
84+
local_pos = np.flatnonzero(local_facets == facet)
85+
parent_to_sub[i, 0] = cell
86+
parent_to_sub[i, 1] = local_pos[0]
7487
entity_maps = {submesh: parent_to_sub}
7588

89+
# print(parent_to_sub)
7690
Qe = basix.ufl.quadrature_element(submesh.basix_cell(), degree=quadrature_degree, value_shape=())
7791
Q = dolfinx.fem.functionspace(submesh, Qe)
7892

@@ -90,7 +104,10 @@ def test_external_operator_codim_1(quadrature_degree):
90104
J = ufl.algorithms.expand_derivatives(ufl.derivative(g, u) * ds)
91105

92106
J_replaced, J_external_operators = replace_external_operators(J)
93-
J_compiled = dolfinx.fem.form(J_replaced, entity_maps=entity_maps)
107+
parent_to_sub2 = np.full(num_entities, -1, dtype=np.int32)
108+
parent_to_sub2[sub_to_parent] = np.arange(len(sub_to_parent), dtype=np.int32)
109+
entity_maps2 = {submesh: parent_to_sub2}
110+
J_compiled = dolfinx.fem.form(J_replaced, entity_maps=entity_maps2)
94111
# Pack coefficients for g
95112
evaluated_operands = evaluate_operands(J_external_operators, entity_maps=entity_maps)
96113
_ = evaluate_external_operators(J_external_operators, evaluated_operands)

0 commit comments

Comments
 (0)