Skip to content

Commit 988189f

Browse files
committed
ruff format .
1 parent 20495df commit 988189f

File tree

4 files changed

+103
-87
lines changed

4 files changed

+103
-87
lines changed

test/test_mixed_function_space_with_mixed_mesh.py

+75-63
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
def test_mixed_function_space_with_mixed_mesh_cell():
2929
cell = triangle
3030
elem0 = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
31-
elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2, ), contravariant_piola, HDiv)
31+
elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2,), contravariant_piola, HDiv)
3232
elem2 = FiniteElement("Discontinuous Lagrange", cell, 0, (), identity_pullback, L2)
3333
elem = MixedElement([elem0, elem1, elem2])
3434
mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=100)
@@ -48,17 +48,19 @@ def test_mixed_function_space_with_mixed_mesh_cell():
4848
x1 = SpatialCoordinate(mesh1)
4949
# Assemble (0, 1)-block.
5050
form = x1[1] * f0 * div(g1) * inner(u1, grad(v0)) * dx2(999)
51-
fd = compute_form_data(form,
52-
do_apply_function_pullbacks=True,
53-
do_apply_integral_scaling=True,
54-
do_apply_geometry_lowering=True,
55-
preserve_geometry_types=(CellVolume, FacetArea),
56-
do_apply_restrictions=True,
57-
do_estimate_degrees=True,
58-
do_split_coefficients=(f, g),
59-
do_assume_single_integral_type=False,
60-
complex_mode=False)
61-
id0, = fd.integral_data
51+
fd = compute_form_data(
52+
form,
53+
do_apply_function_pullbacks=True,
54+
do_apply_integral_scaling=True,
55+
do_apply_geometry_lowering=True,
56+
preserve_geometry_types=(CellVolume, FacetArea),
57+
do_apply_restrictions=True,
58+
do_estimate_degrees=True,
59+
do_split_coefficients=(f, g),
60+
do_assume_single_integral_type=False,
61+
complex_mode=False,
62+
)
63+
(id0,) = fd.integral_data
6264
assert fd.preprocessed_form.arguments() == (v0, u1)
6365
assert fd.reduced_coefficients == [f, g]
6466
assert form.coefficients()[fd.original_coefficient_positions[0]] is f
@@ -67,8 +69,8 @@ def test_mixed_function_space_with_mixed_mesh_cell():
6769
assert id0.domain_integral_type_map[mesh1] == "cell"
6870
assert id0.domain_integral_type_map[mesh2] == "cell"
6971
assert id0.domain is mesh2
70-
assert id0.integral_type == 'cell'
71-
assert id0.subdomain_id == (999, )
72+
assert id0.integral_type == "cell"
73+
assert id0.subdomain_id == (999,)
7274
assert fd.original_form.domain_numbering()[id0.domain] == 0
7375
assert id0.integral_coefficients == set([f, g])
7476
assert id0.enabled_coefficients == [True, True]
@@ -77,12 +79,12 @@ def test_mixed_function_space_with_mixed_mesh_cell():
7779
def test_mixed_function_space_with_mixed_mesh_facet():
7880
cell = triangle
7981
elem0 = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
80-
elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2, ), contravariant_piola, HDiv)
82+
elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2,), contravariant_piola, HDiv)
8183
elem2 = FiniteElement("Discontinuous Lagrange", cell, 0, (), identity_pullback, L2)
8284
elem = MixedElement([elem0, elem1, elem2])
83-
mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100)
84-
mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101)
85-
mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=102)
85+
mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=100)
86+
mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=101)
87+
mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=102)
8688
domain = MeshSequence([mesh0, mesh1, mesh2])
8789
V = FunctionSpace(domain, elem)
8890
V1 = FunctionSpace(mesh1, elem1)
@@ -97,37 +99,43 @@ def test_mixed_function_space_with_mixed_mesh_facet():
9799
ds2 = Measure("ds", mesh2)
98100
x2 = SpatialCoordinate(mesh2)
99101
# Assemble (2, 1)-block.
100-
form = inner(x2, g1('+')) * g2 * inner(u1('-'), grad(v2)) * dS1(999) + \
101-
f0('-') * div(f1) * inner(div(u1), v2) * ds2(777)
102-
fd = compute_form_data(form,
103-
do_apply_function_pullbacks=True,
104-
do_apply_integral_scaling=True,
105-
do_apply_geometry_lowering=True,
106-
preserve_geometry_types=(CellVolume, FacetArea),
107-
do_apply_restrictions=True,
108-
do_estimate_degrees=True,
109-
do_split_coefficients=(f, g),
110-
do_assume_single_integral_type=False,
111-
complex_mode=False)
112-
id0, id1, = fd.integral_data
102+
form = inner(x2, g1("+")) * g2 * inner(u1("-"), grad(v2)) * dS1(999) + f0("-") * div(
103+
f1
104+
) * inner(div(u1), v2) * ds2(777)
105+
fd = compute_form_data(
106+
form,
107+
do_apply_function_pullbacks=True,
108+
do_apply_integral_scaling=True,
109+
do_apply_geometry_lowering=True,
110+
preserve_geometry_types=(CellVolume, FacetArea),
111+
do_apply_restrictions=True,
112+
do_estimate_degrees=True,
113+
do_split_coefficients=(f, g),
114+
do_assume_single_integral_type=False,
115+
complex_mode=False,
116+
)
117+
(
118+
id0,
119+
id1,
120+
) = fd.integral_data
113121
assert fd.preprocessed_form.arguments() == (v2, u1)
114122
assert fd.reduced_coefficients == [f, g]
115123
assert form.coefficients()[fd.original_coefficient_positions[0]] is f
116124
assert form.coefficients()[fd.original_coefficient_positions[1]] is g
117125
assert id0.domain_integral_type_map[mesh1] == "interior_facet"
118126
assert id0.domain_integral_type_map[mesh2] == "exterior_facet"
119127
assert id0.domain is mesh1
120-
assert id0.integral_type == 'interior_facet'
121-
assert id0.subdomain_id == (999, )
128+
assert id0.integral_type == "interior_facet"
129+
assert id0.subdomain_id == (999,)
122130
assert fd.original_form.domain_numbering()[id0.domain] == 0
123131
assert id0.integral_coefficients == set([g])
124132
assert id0.enabled_coefficients == [False, True]
125133
assert id1.domain_integral_type_map[mesh0] == "interior_facet"
126134
assert id1.domain_integral_type_map[mesh1] == "exterior_facet"
127135
assert id1.domain_integral_type_map[mesh2] == "exterior_facet"
128136
assert id1.domain is mesh2
129-
assert id1.integral_type == 'exterior_facet'
130-
assert id1.subdomain_id == (777, )
137+
assert id1.integral_type == "exterior_facet"
138+
assert id1.subdomain_id == (777,)
131139
assert fd.original_form.domain_numbering()[id1.domain] == 1
132140
assert id1.integral_coefficients == set([f])
133141
assert id1.enabled_coefficients == [True, False]
@@ -136,12 +144,12 @@ def test_mixed_function_space_with_mixed_mesh_facet():
136144
def test_mixed_function_space_with_mixed_mesh_raise():
137145
cell = triangle
138146
elem0 = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
139-
elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2, ), contravariant_piola, HDiv)
147+
elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2,), contravariant_piola, HDiv)
140148
elem2 = FiniteElement("Discontinuous Lagrange", cell, 0, (), identity_pullback, L2)
141149
elem = MixedElement([elem0, elem1, elem2])
142-
mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100)
143-
mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101)
144-
mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=102)
150+
mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=100)
151+
mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=101)
152+
mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=102)
145153
domain = MeshSequence([mesh0, mesh1, mesh2])
146154
V = FunctionSpace(domain, elem)
147155
f = Coefficient(V, count=1000)
@@ -150,39 +158,43 @@ def test_mixed_function_space_with_mixed_mesh_raise():
150158
_, g1, _ = split(g)
151159
dS1 = Measure("dS", mesh1)
152160
# Make sure that all mixed functions are split when applying default restrictions.
153-
form = div(g1('+')) * div(f1('-')) * dS1
161+
form = div(g1("+")) * div(f1("-")) * dS1
154162
with pytest.raises(RuntimeError) as e_info:
155-
_ = compute_form_data(form,
156-
do_apply_function_pullbacks=True,
157-
do_apply_integral_scaling=True,
158-
do_apply_geometry_lowering=True,
159-
preserve_geometry_types=(CellVolume, FacetArea),
160-
do_apply_restrictions=True,
161-
do_estimate_degrees=True,
162-
do_split_coefficients=(f,),
163-
do_assume_single_integral_type=False,
164-
complex_mode=False)
163+
_ = compute_form_data(
164+
form,
165+
do_apply_function_pullbacks=True,
166+
do_apply_integral_scaling=True,
167+
do_apply_geometry_lowering=True,
168+
preserve_geometry_types=(CellVolume, FacetArea),
169+
do_apply_restrictions=True,
170+
do_estimate_degrees=True,
171+
do_split_coefficients=(f,),
172+
do_assume_single_integral_type=False,
173+
complex_mode=False,
174+
)
165175
assert e_info.match("Not expecting a terminal object on a mixed mesh at this stage")
166176
# Make sure that g1 is restricted as f1.
167-
form = div(g1) * div(f1('-')) * dS1
177+
form = div(g1) * div(f1("-")) * dS1
168178
with pytest.raises(ValueError) as e_info:
169-
_ = compute_form_data(form,
170-
do_apply_function_pullbacks=True,
171-
do_apply_integral_scaling=True,
172-
do_apply_geometry_lowering=True,
173-
preserve_geometry_types=(CellVolume, FacetArea),
174-
do_apply_restrictions=True,
175-
do_estimate_degrees=True,
176-
do_split_coefficients=(f, g),
177-
do_assume_single_integral_type=False,
178-
complex_mode=False)
179+
_ = compute_form_data(
180+
form,
181+
do_apply_function_pullbacks=True,
182+
do_apply_integral_scaling=True,
183+
do_apply_geometry_lowering=True,
184+
preserve_geometry_types=(CellVolume, FacetArea),
185+
do_apply_restrictions=True,
186+
do_estimate_degrees=True,
187+
do_split_coefficients=(f, g),
188+
do_assume_single_integral_type=False,
189+
complex_mode=False,
190+
)
179191
assert e_info.match("Discontinuous type Coefficient must be restricted.")
180192

181193

182194
def test_mixed_function_space_with_mixed_mesh_signature():
183195
cell = triangle
184-
mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100)
185-
mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101)
196+
mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=100)
197+
mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=101)
186198
dx0 = Measure("dx", mesh0)
187199
dx1 = Measure("dx", mesh1)
188200
n0 = FacetNormal(mesh0)

ufl/algorithms/apply_coefficient_split.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def modified_terminal(self, o):
5555
if isinstance(t, ReferenceValue):
5656
assert not reference_value, "Got twice pulled back terminal!"
5757
reference_value = True
58-
t, = t.ufl_operands
58+
(t,) = t.ufl_operands
5959
elif isinstance(t, ReferenceGrad):
6060
local_derivatives += 1
61-
t, = t.ufl_operands
61+
(t,) = t.ufl_operands
6262
elif isinstance(t, Restricted):
6363
assert restriction is None, "Got twice restricted terminal!"
6464
restriction = t._side
65-
t, = t.ufl_operands
65+
(t,) = t.ufl_operands
6666
elif t._ufl_terminal_modifiers_:
6767
raise ValueError(
6868
f"Missing handler for terminal modifier type {type(t)}, object is {t!r}."
@@ -95,9 +95,9 @@ def modified_terminal(self, o):
9595
c = Zero(c.ufl_shape + (dim,), c.ufl_free_indices, c.ufl_index_dimensions)
9696
else:
9797
c = ReferenceGrad(c)
98-
if restriction == '+':
98+
if restriction == "+":
9999
c = PositiveRestricted(c)
100-
elif restriction == '-':
100+
elif restriction == "-":
101101
c = NegativeRestricted(c)
102102
elif restriction is not None:
103103
raise RuntimeError(f"Got unknown restriction: {restriction}")
@@ -106,7 +106,7 @@ def modified_terminal(self, o):
106106
# New modified terminal: component[alpha + beta]
107107
components.append(c[alpha + beta])
108108
# Repack derivative indices to shape
109-
c, = indices(1)
109+
(c,) = indices(1)
110110
return ComponentTensor(as_tensor(components)[c], MultiIndex((c,) + beta))
111111

112112
positive_restricted = modified_terminal
@@ -163,7 +163,7 @@ def zero(self, o):
163163
return Zero(
164164
shape=o.ufl_shape,
165165
free_indices=tuple(free_indices),
166-
index_dimensions=tuple(index_dimensions)
166+
index_dimensions=tuple(index_dimensions),
167167
)
168168

169169
@memoized_handler
@@ -194,13 +194,13 @@ def __init__(self):
194194
@memoized_handler
195195
def _zero_simplify(self, o):
196196
"""Apply simplification for Zero()."""
197-
operand, = o.ufl_operands
197+
(operand,) = o.ufl_operands
198198
operand = map_expr_dag(self, operand)
199199
if isinstance(operand, Zero):
200200
return Zero(
201201
shape=o.ufl_shape,
202202
free_indices=o.ufl_free_indices,
203-
index_dimensions=o.ufl_index_dimensions
203+
index_dimensions=o.ufl_index_dimensions,
204204
)
205205
else:
206206
return o._ufl_expr_reconstruct_(operand)

ufl/algorithms/apply_restrictions.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ def __init__(self, side=None, assume_single_integral_type=True, default_restrict
2929
self.current_restriction = side
3030
self.default_restriction = default_restriction
3131
# Caches for propagating the restriction with map_expr_dag
32-
self.vcaches = {"+": {}, "-": {},}
33-
self.rcaches = {"+": {}, "-": {},}
32+
self.vcaches = {
33+
"+": {},
34+
"-": {},
35+
}
36+
self.rcaches = {
37+
"+": {},
38+
"-": {},
39+
}
3440
if self.current_restriction is None:
3541
self._rp = {
3642
"+": RestrictionPropagator("+", assume_single_integral_type, default_restriction),
@@ -247,11 +253,7 @@ def facet_normal(self, o):
247253
return self._require_restriction(o)
248254

249255

250-
def apply_restrictions(
251-
expression,
252-
assume_single_integral_type=True,
253-
domain_integral_type_map=None
254-
):
256+
def apply_restrictions(expression, assume_single_integral_type=True, domain_integral_type_map=None):
255257
"""Propagate restriction nodes to wrap differential terminals directly."""
256258
if assume_single_integral_type:
257259
# Hnadle the conventional single-domain case.
@@ -285,7 +287,7 @@ def apply_restrictions(
285287
integral_types = None
286288
rules = RestrictionPropagator(
287289
assume_single_integral_type=assume_single_integral_type,
288-
default_restriction=default_restriction
290+
default_restriction=default_restriction,
289291
)
290292
if isinstance(expression, FormData):
291293
for integral_data in expression.integral_data:
@@ -305,6 +307,7 @@ class DomainRestrictionMapMaker(MultiFunction):
305307
This must be done per integral_data.
306308
307309
"""
310+
308311
def __init__(self, domain_restriction_map: dict):
309312
"""Initialise.
310313
@@ -327,14 +330,14 @@ def _modifier(self, o):
327330
if isinstance(t, ReferenceValue):
328331
assert not reference_value, "Got twice pulled back terminal"
329332
reference_value = True
330-
t, = t.ufl_operands
333+
(t,) = t.ufl_operands
331334
elif isinstance(t, ReferenceGrad):
332335
local_derivatives += 1
333-
t, = t.ufl_operands
336+
(t,) = t.ufl_operands
334337
elif isinstance(t, Restricted):
335338
assert restriction is None, "Got twice restricted terminal"
336339
restriction = t._side
337-
t, = t.ufl_operands
340+
(t,) = t.ufl_operands
338341
elif t._ufl_terminal_modifiers_:
339342
raise ValueError(
340343
f"Missing handler for terminal modifier type {type(t)}, object is {t!r}."
@@ -349,7 +352,7 @@ def _modifier(self, o):
349352
if domain is not None:
350353
if domain not in self._domain_restriction_map:
351354
self._domain_restriction_map[domain] = set()
352-
if restriction in ['+', '-']:
355+
if restriction in ["+", "-"]:
353356
self._domain_restriction_map[domain].add(restriction)
354357
elif restriction is not None:
355358
raise RuntimeError(f"Got unknown restriction: {restriction}")
@@ -378,7 +381,7 @@ def make_domain_integral_type_map(integral_data):
378381
integration_type = integral_data.integral_type
379382
domain_integral_type_dict = {}
380383
for d, rs in domain_restriction_map.items():
381-
if rs in [{'+'}, {'-'}, {'+', '-'}]:
384+
if rs in [{"+"}, {"-"}, {"+", "-"}]:
382385
domain_integral_type_dict[d] = "interior_facet"
383386
elif rs == set():
384387
if d.topological_dimension() == integration_domain.topological_dimension():

ufl/algorithms/compute_form_data.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,9 @@ def compute_form_data(
466466
# -- isinstance(elem.pullback, MixedPullback)
467467
if isinstance(mesh, MeshSequence) and o in do_split_coefficients:
468468
assert len(mesh) == len(elem.sub_elements)
469-
coefficient_split[c] = [Coefficient(FunctionSpace(m, e))
470-
for m, e in zip(mesh, elem.sub_elements)]
469+
coefficient_split[c] = [
470+
Coefficient(FunctionSpace(m, e)) for m, e in zip(mesh, elem.sub_elements)
471+
]
471472
self.coefficient_split = coefficient_split
472473
for itg_data in self.integral_data:
473474
new_integrals = []

0 commit comments

Comments
 (0)