From 0eeb02f4f42199a4baacd15f784be5a9eb0c4ec7 Mon Sep 17 00:00:00 2001 From: ksagiyam Date: Wed, 21 Aug 2024 10:57:25 +0100 Subject: [PATCH] ruff format --- test/test_external_operator.py | 28 ++++++++++----- test/test_interpolate.py | 7 ++-- ...st_mixed_function_space_with_mixed_mesh.py | 36 ++++++++++--------- ufl/action.py | 5 +-- ufl/algorithms/analysis.py | 6 ++-- ufl/algorithms/apply_derivatives.py | 14 ++++---- ufl/algorithms/estimate_degrees.py | 7 ++-- ufl/domain.py | 23 ++++++------ ufl/form.py | 15 ++++---- 9 files changed, 77 insertions(+), 64 deletions(-) diff --git a/test/test_external_operator.py b/test/test_external_operator.py index 978a6e27f..8359138b4 100644 --- a/test/test_external_operator.py +++ b/test/test_external_operator.py @@ -236,16 +236,22 @@ def test_extractions(domain_2d, V1): assert extract_coefficients(e) == [u] assert extract_arguments(e) == [vstar_e, u_hat] - assert extract_arguments_and_coefficients_and_geometric_quantities(e) == \ - ([vstar_e, u_hat], [u], []) + assert extract_arguments_and_coefficients_and_geometric_quantities(e) == ( + [vstar_e, u_hat], + [u], + [], + ) assert extract_base_form_operators(e) == [e] F = e * dx assert extract_coefficients(F) == [u] assert extract_arguments(e) == [vstar_e, u_hat] - assert extract_arguments_and_coefficients_and_geometric_quantities(e) == \ - ([vstar_e, u_hat], [u], []) + assert extract_arguments_and_coefficients_and_geometric_quantities(e) == ( + [vstar_e, u_hat], + [u], + [], + ) assert F.base_form_operators() == (e,) w = Coefficient(V1) @@ -254,16 +260,22 @@ def test_extractions(domain_2d, V1): assert extract_coefficients(e2) == [u, w] assert extract_arguments(e2) == [vstar_e2, u_hat] - assert extract_arguments_and_coefficients_and_geometric_quantities(e2) == \ - ([vstar_e2, u_hat], [u, w], []) + assert extract_arguments_and_coefficients_and_geometric_quantities(e2) == ( + [vstar_e2, u_hat], + [u, w], + [], + ) assert extract_base_form_operators(e2) == [e, e2] F = e2 * dx assert extract_coefficients(e2) == [u, w] assert extract_arguments(e2) == [vstar_e2, u_hat] - assert extract_arguments_and_coefficients_and_geometric_quantities(e2) == \ - ([vstar_e2, u_hat], [u, w], []) + assert extract_arguments_and_coefficients_and_geometric_quantities(e2) == ( + [vstar_e2, u_hat], + [u, w], + [], + ) assert F.base_form_operators() == (e, e2) diff --git a/test/test_interpolate.py b/test/test_interpolate.py index b70a62bf1..646f2ff5b 100644 --- a/test/test_interpolate.py +++ b/test/test_interpolate.py @@ -171,8 +171,11 @@ def test_extract_base_form_operators(V1, V2): # -- Interpolate(u, V2) -- # Iv = Interpolate(uhat, V2) assert extract_arguments(Iv) == [vstar, uhat] - assert extract_arguments_and_coefficients_and_geometric_quantities(Iv) == \ - ([vstar, uhat], [], []) + assert extract_arguments_and_coefficients_and_geometric_quantities(Iv) == ( + [vstar, uhat], + [], + [], + ) assert extract_coefficients(Iv) == [] assert extract_base_form_operators(Iv) == [Iv] diff --git a/test/test_mixed_function_space_with_mixed_mesh.py b/test/test_mixed_function_space_with_mixed_mesh.py index 178320dd5..238f4e0df 100644 --- a/test/test_mixed_function_space_with_mixed_mesh.py +++ b/test/test_mixed_function_space_with_mixed_mesh.py @@ -25,12 +25,12 @@ def test_mixed_function_space_with_mixed_mesh_basic(): cell = triangle elem0 = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1) - elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2, ), contravariant_piola, HDiv) + elem1 = FiniteElement("Brezzi-Douglas-Marini", cell, 1, (2,), contravariant_piola, HDiv) elem2 = FiniteElement("Discontinuous Lagrange", cell, 0, (), identity_pullback, L2) elem = MixedElement([elem0, elem1, elem2]) - mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100) - mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101) - mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=102) + mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=100) + mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=101) + mesh2 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=102) domain = MixedMesh(mesh0, mesh1, mesh2) V = FunctionSpace(domain, elem) u = TrialFunction(V) @@ -44,21 +44,23 @@ def test_mixed_function_space_with_mixed_mesh_basic(): dx1 = Measure("dx", mesh1) x = SpatialCoordinate(mesh1) form = x[1] * f0 * inner(grad(u0), v1) * dx1(999) - fd = compute_form_data(form, - do_apply_function_pullbacks=True, - do_apply_integral_scaling=True, - do_apply_geometry_lowering=True, - preserve_geometry_types=(CellVolume, FacetArea), - do_apply_restrictions=True, - do_estimate_degrees=True, - complex_mode=False) - id0, = fd.integral_data + fd = compute_form_data( + form, + do_apply_function_pullbacks=True, + do_apply_integral_scaling=True, + do_apply_geometry_lowering=True, + preserve_geometry_types=(CellVolume, FacetArea), + do_apply_restrictions=True, + do_estimate_degrees=True, + complex_mode=False, + ) + (id0,) = fd.integral_data assert fd.preprocessed_form.arguments() == (v, u) assert fd.reduced_coefficients == [f] assert form.coefficients()[fd.original_coefficient_positions[0]] is f assert id0.domain is mesh1 - assert id0.integral_type == 'cell' - assert id0.subdomain_id == (999, ) + assert id0.integral_type == "cell" + assert id0.subdomain_id == (999,) assert fd.original_form.domain_numbering()[id0.domain] == 0 assert id0.integral_coefficients == set([f]) assert id0.enabled_coefficients == [True] @@ -66,8 +68,8 @@ def test_mixed_function_space_with_mixed_mesh_basic(): def test_mixed_function_space_with_mixed_mesh_signature(): cell = triangle - mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=100) - mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1), ufl_id=101) + mesh0 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=100) + mesh1 = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1), ufl_id=101) dx0 = Measure("dx", mesh0) dx1 = Measure("dx", mesh1) n0 = FacetNormal(mesh0) diff --git a/ufl/action.py b/ufl/action.py index bb20c4f81..016ccb6f5 100644 --- a/ufl/action.py +++ b/ufl/action.py @@ -192,8 +192,9 @@ def _get_action_form_arguments(left, right): extract_arguments_and_coefficients_and_geometric_quantities, ) - right_args, right_coeffs, _ = \ - extract_arguments_and_coefficients_and_geometric_quantities(right) + right_args, right_coeffs, _ = extract_arguments_and_coefficients_and_geometric_quantities( + right + ) arguments = left_args + tuple(right_args) coefficients += tuple(right_coeffs) elif isinstance(right, (BaseCoefficient, Zero)): diff --git a/ufl/algorithms/analysis.py b/ufl/algorithms/analysis.py index 18597439d..457ead7fb 100644 --- a/ufl/algorithms/analysis.py +++ b/ufl/algorithms/analysis.py @@ -214,9 +214,9 @@ def extract_arguments_and_coefficients_and_geometric_quantities(a): base_coeff_and_args_and_gq = extract_type(a, (BaseArgument, BaseCoefficient, GeometricQuantity)) arguments = [f for f in base_coeff_and_args_and_gq if isinstance(f, BaseArgument)] coefficients = [f for f in base_coeff_and_args_and_gq if isinstance(f, BaseCoefficient)] - geometric_quantities = [f - for f in base_coeff_and_args_and_gq - if isinstance(f, GeometricQuantity)] + geometric_quantities = [ + f for f in base_coeff_and_args_and_gq if isinstance(f, GeometricQuantity) + ] # Build number,part: instance mappings, should be one to one bfnp = dict((f, (f.number(), f.part())) for f in arguments) diff --git a/ufl/algorithms/apply_derivatives.py b/ufl/algorithms/apply_derivatives.py index f88affa2f..ba8f1198b 100644 --- a/ufl/algorithms/apply_derivatives.py +++ b/ufl/algorithms/apply_derivatives.py @@ -87,7 +87,7 @@ def flatten_domain_element(domain, element): """Return the flattened (domain, element) pairs for mixed domain problems.""" if not isinstance(domain, MixedMesh): - return ((domain, element), ) + return ((domain, element),) flattened = () assert len(domain) == len(element.sub_elements) for d, e in zip(domain, element.sub_elements): @@ -683,7 +683,7 @@ def reference_value(self, o): for d, e in flatten_domain_element(domain, element): esh = e.reference_value_shape if esh == (): - esh = (1, ) + esh = (1,) if isinstance(e.pullback, PhysicalPullback): if ref_dim != self._var_shape[0]: raise NotImplementedError(""" @@ -691,7 +691,7 @@ def reference_value(self, o): reference dim ({ref_dim}) != physical dim (self._var_shape[0])""") for idx in range(int(np.prod(esh))): for i in range(ref_dim): - components.append(g[(dofoffset + idx, ) + (i, )]) + components.append(g[(dofoffset + idx,) + (i,)]) else: K = JacobianInverse(d) rdim, gdim = K.ufl_shape @@ -703,7 +703,7 @@ def reference_value(self, o): for i in range(gdim): temp = Zero() for j in range(rdim): - temp += g[(dofoffset + idx, ) + (j, )] * K[j, i] + temp += g[(dofoffset + idx,) + (j,)] * K[j, i] components.append(temp) dofoffset += int(np.prod(esh)) return as_tensor(np.asarray(components).reshape(vsh + self._var_shape)) @@ -730,7 +730,7 @@ def reference_grad(self, o): if not f._ufl_is_in_reference_frame_: raise RuntimeError("Expecting a reference frame type") while not f._ufl_is_terminal_: - f, = f.ufl_operands + (f,) = f.ufl_operands element = f.ufl_function_space().ufl_element() if element.num_sub_elements != len(domain): raise RuntimeError(f"{element.num_sub_elements} != {len(domain)}") @@ -742,7 +742,7 @@ def reference_grad(self, o): for d, e in flatten_domain_element(domain, element): esh = e.reference_value_shape if esh == (): - esh = (1, ) + esh = (1,) K = JacobianInverse(d) rdim, gdim = K.ufl_shape if rdim != ref_dim: @@ -754,7 +754,7 @@ def reference_grad(self, o): for i in range(gdim): temp = Zero() for j in range(rdim): - temp += g[(dofoffset + idx, ) + midx + (j, )] * K[j, i] + temp += g[(dofoffset + idx,) + midx + (j,)] * K[j, i] components.append(temp) dofoffset += int(np.prod(esh)) if g.ufl_shape[0] != dofoffset: diff --git a/ufl/algorithms/estimate_degrees.py b/ufl/algorithms/estimate_degrees.py index fe3ff2952..1cc42e998 100644 --- a/ufl/algorithms/estimate_degrees.py +++ b/ufl/algorithms/estimate_degrees.py @@ -99,11 +99,8 @@ def _reduce_degree(self, v, f): TensorProduct elements or quadrilateral elements are involved. """ # Can have multiple domains of the same cell type. - cell, = set(d.ufl_cell() for d in extract_domains(v)) - if isinstance(f, int) and cell.cellname() not in [ - "quadrilateral", - "hexahedron" - ]: + (cell,) = set(d.ufl_cell() for d in extract_domains(v)) + if isinstance(f, int) and cell.cellname() not in ["quadrilateral", "hexahedron"]: return max(f - 1, 0) else: return f diff --git a/ufl/domain.py b/ufl/domain.py index 8d2f603e7..2f2ab2784 100644 --- a/ufl/domain.py +++ b/ufl/domain.py @@ -148,7 +148,7 @@ def _ufl_sort_key_(self): @property def meshes(self): """Return the component meshes.""" - return (self, ) + return (self,) @attach_ufl_id @@ -166,10 +166,10 @@ def __init__(self, *meshes, ufl_id=None, cargo=None): raise NotImplementedError(""" Currently component meshes can not include MixedMesh instances""") # currently only support single cell type. - self._ufl_cell, = set(m.ufl_cell() for m in meshes) - gdim, = set(m.geometric_dimension() for m in meshes) + (self._ufl_cell,) = set(m.ufl_cell() for m in meshes) + (gdim,) = set(m.geometric_dimension() for m in meshes) # TODO: Need to change for more general mixed meshes. - tdim, = set(m.topological_dimension() for m in meshes) + (tdim,) = set(m.topological_dimension() for m in meshes) AbstractDomain.__init__(self, tdim, gdim) self._meshes = tuple(meshes) @@ -200,9 +200,8 @@ def _ufl_signature_data_(self, renumbering): def _ufl_sort_key_(self): """UFL sort key.""" - typespecific = (self._ufl_id, ) - return (self.geometric_dimension(), self.topological_dimension(), - "MixedMesh", typespecific) + typespecific = (self._ufl_id,) + return (self.geometric_dimension(), self.topological_dimension(), "MixedMesh", typespecific) @property def meshes(self): @@ -273,13 +272,13 @@ def as_domain(domain): """Convert any valid object to an AbstractDomain type.""" if isinstance(domain, AbstractDomain): # Modern UFL files and dolfin behaviour - domain, = set(domain.meshes) + (domain,) = set(domain.meshes) return domain try: return extract_unique_domain(domain) except AttributeError: domain = domain.ufl_domain() - domain, = set(domain.meshes) + (domain,) = set(domain.meshes) return domain @@ -328,9 +327,7 @@ def extract_domains(expr, expand_mixed_mesh=True): domainlist = [] for t in traverse_unique_terminals(expr): domainlist.extend(t.ufl_domains()) - return sort_domains( - join_domains(domainlist, expand_mixed_mesh=expand_mixed_mesh) - ) + return sort_domains(join_domains(domainlist, expand_mixed_mesh=expand_mixed_mesh)) def extract_unique_domain(expr, expand_mixed_mesh=True): @@ -351,7 +348,7 @@ def find_geometric_dimension(expr): # Can have multiple domains of the same cell type. domains = extract_domains(t) if len(domains) > 0: - gdim, = set(domain.geometric_dimension() for domain in domains) + (gdim,) = set(domain.geometric_dimension() for domain in domains) gdims.add(gdim) if len(gdims) != 1: diff --git a/ufl/form.py b/ufl/form.py index 00fa71ca8..a6b6bbb72 100644 --- a/ufl/form.py +++ b/ufl/form.py @@ -607,14 +607,14 @@ def _analyze_domains(self): from ufl.domain import join_domains, sort_domains # Collect integration domains. - self._integration_domains = \ - sort_domains(join_domains([itg.ufl_domain() for itg in self._integrals])) + self._integration_domains = sort_domains( + join_domains([itg.ufl_domain() for itg in self._integrals]) + ) # Collect domains in integrands. domains_in_integrands = set() - for o in chain(self.arguments(), - self.coefficients(), - self.constants(), - self.geometric_quantities()): + for o in chain( + self.arguments(), self.coefficients(), self.constants(), self.geometric_quantities() + ): domain = extract_unique_domain(o, expand_mixed_mesh=False) domains_in_integrands.update(domain.meshes) domains_in_integrands -= set(self._integration_domains) @@ -652,8 +652,9 @@ def _analyze_form_arguments(self): extract_arguments_and_coefficients_and_geometric_quantities, ) - arguments, coefficients, geometric_quantities = \ + arguments, coefficients, geometric_quantities = ( extract_arguments_and_coefficients_and_geometric_quantities(self) + ) # Define canonical numbering of arguments and coefficients self._arguments = tuple(sorted(set(arguments), key=lambda x: x.number()))