Skip to content

Commit

Permalink
Ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgensd committed Dec 5, 2024
1 parent 047ded5 commit 6d16784
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 55 deletions.
1 change: 1 addition & 0 deletions ufl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@
"dP",
"dc",
"dC",
"dl",
"dO",
"dI",
"dX",
Expand Down
39 changes: 13 additions & 26 deletions ufl/algorithms/apply_geometry_lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ def cell_volume(self, o):
if not domain.is_piecewise_linear_simplex_domain():
# Don't lower for non-affine cells, instead leave it to
# form compiler
warnings.warn(
"Only know how to compute the cell volume of an affine cell.")
warnings.warn("Only know how to compute the cell volume of an affine cell.")
return o

r = self.jacobian_determinant(JacobianDeterminant(domain))
Expand All @@ -270,8 +269,7 @@ def facet_area(self, o):
if not domain.is_piecewise_linear_simplex_domain():
# Don't lower for non-affine cells, instead leave it to
# form compiler
warnings.warn(
"Only know how to compute the facet area of an affine cell.")
warnings.warn("Only know how to compute the facet area of an affine cell.")
return o

# Area of "facet" of interval (i.e. "area" of a vertex) is defined as 1.0
Expand All @@ -291,8 +289,7 @@ def circumradius(self, o):
domain = extract_unique_domain(o)

if not domain.is_piecewise_linear_simplex_domain():
raise ValueError(
"Circumradius only makes sense for affine simplex cells")
raise ValueError("Circumradius only makes sense for affine simplex cells")

cellname = domain.ufl_cell().cellname()
cellvolume = self.cell_volume(CellVolume(domain))
Expand All @@ -305,8 +302,7 @@ def circumradius(self, o):
edges = CellEdgeVectors(domain)
num_edges = edges.ufl_shape[0]
j = Index()
elen = [real(sqrt(real(edges[e, j] * conj(edges[e, j]))))
for e in range(num_edges)]
elen = [real(sqrt(real(edges[e, j] * conj(edges[e, j])))) for e in range(num_edges)]

if cellname == "triangle":
return (elen[0] * elen[1] * elen[2]) / (4.0 * cellvolume)
Expand Down Expand Up @@ -344,8 +340,7 @@ def _reduce_cell_edge_length(self, o, reduction_op):

if domain.ufl_coordinate_element().embedded_subdegree > 1:
# Don't lower bendy cells, instead leave it to form compiler
warnings.warn(
"Only know how to compute cell edge lengths of P1 or Q1 cell.")
warnings.warn("Only know how to compute cell edge lengths of P1 or Q1 cell.")
return o

elif domain.ufl_cell().cellname() == "interval":
Expand All @@ -357,8 +352,7 @@ def _reduce_cell_edge_length(self, o, reduction_op):
edges = CellEdgeVectors(domain)
num_edges = edges.ufl_shape[0]
j = Index()
elen2 = [real(edges[e, j] * conj(edges[e, j]))
for e in range(num_edges)]
elen2 = [real(edges[e, j] * conj(edges[e, j])) for e in range(num_edges)]
return real(sqrt(reduce(reduction_op, elen2)))

@memoized_handler
Expand All @@ -371,8 +365,7 @@ def cell_diameter(self, o):

if domain.ufl_coordinate_element().embedded_subdegree > 1:
# Don't lower bendy cells, instead leave it to form compiler
warnings.warn(
"Only know how to compute cell diameter of P1 or Q1 cell.")
warnings.warn("Only know how to compute cell diameter of P1 or Q1 cell.")
return o

elif domain.is_piecewise_linear_simplex_domain():
Expand All @@ -384,8 +377,7 @@ def cell_diameter(self, o):
verts = CellVertices(domain)
verts = [verts[v, ...] for v in range(verts.ufl_shape[0])]
j = Index()
elen2 = (real((v0 - v1)[j] * conj((v0 - v1)[j]))
for v0, v1 in combinations(verts, 2))
elen2 = (real((v0 - v1)[j] * conj((v0 - v1)[j])) for v0, v1 in combinations(verts, 2))
return real(sqrt(reduce(max_value, elen2)))

@memoized_handler
Expand All @@ -406,22 +398,19 @@ def _reduce_facet_edge_length(self, o, reduction_op):
domain = extract_unique_domain(o)

if domain.ufl_cell().topological_dimension() < 3:
raise ValueError(
"Facet edge lengths only make sense for topological dimension >= 3.")
raise ValueError("Facet edge lengths only make sense for topological dimension >= 3.")

elif domain.ufl_coordinate_element().embedded_subdegree > 1:
# Don't lower bendy cells, instead leave it to form compiler
warnings.warn(
"Only know how to compute facet edge lengths of P1 or Q1 cell.")
warnings.warn("Only know how to compute facet edge lengths of P1 or Q1 cell.")
return o

else:
# P1 tetrahedron or Q1 hexahedron
edges = FacetEdgeVectors(domain)
num_edges = edges.ufl_shape[0]
j = Index()
elen2 = [real(edges[e, j] * conj(edges[e, j]))
for e in range(num_edges)]
elen2 = [real(edges[e, j] * conj(edges[e, j])) for e in range(num_edges)]
return real(sqrt(reduce(reduction_op, elen2)))

@memoized_handler
Expand All @@ -448,16 +437,14 @@ def cell_normal(self, o):
# to the 'right')
cell_normal = as_vector((-J[1, 0], J[0, 0]))
else:
raise ValueError(
f"Cell normal not implemented for tdim {tdim}, gdim {gdim}")
raise ValueError(f"Cell normal not implemented for tdim {tdim}, gdim {gdim}")

# Return normalized vector, sign corrected by cell
# orientation
co = CellOrientation(domain)
return co * cell_normal / sqrt(cell_normal[i] * cell_normal[i])
else:
raise ValueError(
f"Cell normal undefined for tdim {tdim}, gdim {gdim}")
raise ValueError(f"Cell normal undefined for tdim {tdim}, gdim {gdim}")

@memoized_handler
def facet_normal(self, o):
Expand Down
9 changes: 0 additions & 9 deletions ufl/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,6 @@ def facet_types(self) -> typing.Tuple[AbstractCell, ...]:
tdim = self.topological_dimension()
return self.sub_entity_types(tdim - 1)

def edge_types(self) -> typing.Tuple[AbstractCell, ...]:
"""Get the unique edge types.
Edges are entities of dimension tdim-2.
"""
tdim = self.topological_dimension()
assert tdim == 3, "Edges only make sense for cells of dimension 2 or higher."
return self.sub_entity_types(1)

def ridge_types(self) -> typing.Tuple[AbstractCell, ...]:
"""Get the unique ridge types.
Expand Down
61 changes: 41 additions & 20 deletions ufl/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@
FacetCoordinate = FacetJacobianInverse * (SpatialCoordinate - FacetOrigin)
Xf = CFK * (X - X0f)
FacetCoordinate = CellFacetJacobianInverse * (CellCoordinate - CellFacetOrigin)
FacetCoordinate = CellFacetJacobianInverse * \
(CellCoordinate - CellFacetOrigin)
Xe = EK * (x - x0e)
EdgeCoordinate = EdgeJacobianInverse * (SpatialCoordinate - EdgeOrigin)
Xe = CEK * (X - X0e)
EdgeCoordinate = CellEdgeJacobianInverse * (CellCoordinate - CellEdgeOrigin)
EdgeCoordinate = CellEdgeJacobianInverse * \
(CellCoordinate - CellEdgeOrigin)
"""

# --- Expression node types
Expand Down Expand Up @@ -168,6 +170,8 @@ class GeometricFacetQuantity(GeometricQuantity):

@ufl_type(is_abstract=True)
class GeometricEdgeQuantity(GeometricQuantity):
"""Geometric edge quantity."""

__slots__ = ()


Expand Down Expand Up @@ -281,7 +285,7 @@ def is_cellwise_constant(self):

@ufl_type()
class EdgeCoordinate(GeometricEdgeQuantity):
"""UFL geometry representation: The coordinate in a reference cell of an edge.
"""The coordinate in a reference cell of an edge.
In the context of expression integration over an edge,
represents the reference edge coordinate of each quadrature point.
Expand All @@ -294,13 +298,15 @@ class EdgeCoordinate(GeometricEdgeQuantity):
name = "Xe"

def __init__(self, domain):
"""Initialise."""
GeometricEdgeQuantity.__init__(self, domain)
t = self._domain.topological_dimension()
if t < 3:
error("EdgeCoordinate is only defined for topological dimensions >= 3.")
raise ValueError("EdgeCoordinate is only defined for topological dimensions >= 3.")

@property
def ufl_shape(self):
"""Get the UFL shape."""
t = self._domain.topological_dimension()
return (t - 2,)

Expand Down Expand Up @@ -346,13 +352,14 @@ def ufl_shape(self):

@ufl_type()
class EdgeOrigin(GeometricEdgeQuantity):
"""UFL geometry representation: The spatial coordinate corresponding to origin of a reference edge."""
"""The spatial coordinate corresponding to origin of a reference edge."""

__slots__ = ()
name = "x0e"

@property
def ufl_shape(self):
"""Get the UFL shape."""
g = self._domain.geometric_dimension()
return (g,)

Expand All @@ -373,13 +380,14 @@ def ufl_shape(self):

@ufl_type()
class CellEdgeOrigin(GeometricEdgeQuantity):
"""UFL geometry representation: The reference cell coordinate corresponding to origin of a reference edge."""
"""The reference cell coordinate corresponding to origin of a reference edge."""

__slots__ = ()
name = "X0e"

@property
def ufl_shape(self):
"""Get the UFL shape."""
t = self._domain.topological_dimension()
return (t,)

Expand Down Expand Up @@ -447,7 +455,7 @@ def is_cellwise_constant(self):

@ufl_type()
class EdgeJacobian(GeometricEdgeQuantity):
"""UFL geometry representation: The Jacobian of the mapping from reference edge to spatial coordinates.
"""The Jacobian of the mapping from reference edge to spatial coordinates.
EJ_ij = dx_i/dXe_j
Expand All @@ -461,13 +469,15 @@ class EdgeJacobian(GeometricEdgeQuantity):
name = "EJ"

def __init__(self, domain):
"""Initialise."""
GeometricEdgeQuantity.__init__(self, domain)
t = self._domain.topological_dimension()
if t < 3:
error("EdgeJacobian is only defined for topological dimensions >= 3.")
raise ValueError("EdgeJacobian is only defined for topological dimensions >= 3.")

@property
def ufl_shape(self):
"""Get the UFL shape."""
g = self._domain.geometric_dimension()
t = self._domain.topological_dimension()
return (g, t - 2)
Expand Down Expand Up @@ -511,7 +521,7 @@ def is_cellwise_constant(self):

@ufl_type()
class CellEdgeJacobian(GeometricEdgeQuantity): # dX/dXe
"""UFL geometry representation: The Jacobian of the mapping from reference edge to reference cell coordinates.
"""The Jacobian of the mapping from reference edge to reference cell coordinates.
CEJ_ij = dX_i/dXe_j
"""
Expand All @@ -520,13 +530,15 @@ class CellEdgeJacobian(GeometricEdgeQuantity): # dX/dXe
name = "CEJ"

def __init__(self, domain):
"""Initialise."""
GeometricEdgeQuantity.__init__(self, domain)
t = self._domain.topological_dimension()
if t < 3:
error("CellEdgeJacobian is only defined for topological dimensions >= 3.")
raise ValueError("CellEdgeJacobian is only defined for topological dimensions >= 3.")

@property
def ufl_shape(self):
"""Get the UFL shape."""
t = self._domain.topological_dimension()
return (t, t - 2)

Expand All @@ -539,7 +551,7 @@ def is_cellwise_constant(self):

@ufl_type()
class FacetEdgeJacobian(GeometricEdgeQuantity): # dXf/dXe
"""UFL geometry representation: The Jacobian of the mapping from reference edge to reference facet coordinates.
"""The Jacobian of the mapping from reference edge to reference facet coordinates.
FEJ_ij = dXf_i/dXe_j
"""
Expand All @@ -548,13 +560,15 @@ class FacetEdgeJacobian(GeometricEdgeQuantity): # dXf/dXe
name = "FEJ"

def __init__(self, domain):
"""Initialise."""
GeometricEdgeQuantity.__init__(self, domain)
t = self._domain.topological_dimension()
if t < 3:
error("FacetEdgeJacobian is only defined for topological dimensions >= 3.")
raise ValueError("FacetEdgeJacobian is only defined for topological dimensions >= 3.")

@property
def ufl_shape(self):
"""Get the UFL shape."""
t = self._domain.topological_dimension()
return (t - 1, t - 2)

Expand Down Expand Up @@ -753,7 +767,7 @@ def is_cellwise_constant(self):

@ufl_type()
class EdgeJacobianDeterminant(GeometricEdgeQuantity):
"""UFL geometry representation: The pseudo-determinant of the EdgeJacobian."""
"""The pseudo-determinant of the EdgeJacobian."""

__slots__ = ()
name = "detEJ"
Expand All @@ -780,7 +794,7 @@ def is_cellwise_constant(self):

@ufl_type()
class CellEdgeJacobianDeterminant(GeometricEdgeQuantity):
"""UFL geometry representation: The pseudo-determinant of the CellEdgeJacobian."""
"""The pseudo-determinant of the CellEdgeJacobian."""

__slots__ = ()
name = "detCEJ"
Expand Down Expand Up @@ -852,19 +866,21 @@ def is_cellwise_constant(self):

@ufl_type()
class EdgeJacobianInverse(GeometricEdgeQuantity):
"""UFL geometry representation: The pseudo-inverse of the EdgeJacobian."""
"""The pseudo-inverse of the EdgeJacobian."""

__slots__ = ()
name = "EK"

def __init__(self, domain):
"""Initialise."""
GeometricEdgeQuantity.__init__(self, domain)
t = self._domain.topological_dimension()
if t < 3:
error("EdgeJacobianInverse is only defined for topological dimensions >= 3.")
raise ValueError("EdgeJacobianInverse is only defined for topological dimensions >= 3.")

@property
def ufl_shape(self):
"""Get the UFL shape."""
g = self._domain.geometric_dimension()
t = self._domain.topological_dimension()
return (t - 2, g)
Expand Down Expand Up @@ -906,19 +922,23 @@ def is_cellwise_constant(self):

@ufl_type()
class CellEdgeJacobianInverse(GeometricEdgeQuantity):
"""UFL geometry representation: The pseudo-inverse of the EdgeFacetJacobian."""
"""The pseudo-inverse of the EdgeFacetJacobian."""

__slots__ = ()
name = "CEK"

def __init__(self, domain):
"""Initialise."""
GeometricEdgeQuantity.__init__(self, domain)
t = self._domain.topological_dimension()
if t < 3:
error("CellEdgeJacobianInverse is only defined for topological dimensions >= 3.")
raise ValueError(
"CellEdgeJacobianInverse is only defined for topological dimensions >= 3."
)

@property
def ufl_shape(self):
"""Get the UFL shape."""
t = self._domain.topological_dimension()
return (t - 2, t)

Expand Down Expand Up @@ -1014,7 +1034,7 @@ class ReferenceFacetVolume(GeometricFacetQuantity):

@ufl_type()
class ReferenceEdgeVolume(GeometricEdgeQuantity):
"""UFL geometry representation: The volume of the reference cell of the current edge."""
"""The volume of the reference cell of the current edge."""

__slots__ = ()
name = "reference_edge_volume"
Expand Down Expand Up @@ -1045,7 +1065,8 @@ class CellDiameter(GeometricCellQuantity):


@ufl_type()
class FacetArea(GeometricFacetQuantity): # FIXME: Should this be allowed for interval domain?
# FIXME: Should this be allowed for interval domain?
class FacetArea(GeometricFacetQuantity):
"""The area of the facet."""

__slots__ = ()
Expand Down

0 comments on commit 6d16784

Please sign in to comment.