From 2f04498ef0596ce291dcc50efd71c306855d55b3 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Tue, 25 Mar 2025 17:55:35 +0000 Subject: [PATCH 1/3] add integral domains --- ufl/__init__.py | 1 + ufl/integral_domain.py | 71 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 ufl/integral_domain.py diff --git a/ufl/__init__.py b/ufl/__init__.py index 57884a507..e5d737364 100644 --- a/ufl/__init__.py +++ b/ufl/__init__.py @@ -303,6 +303,7 @@ SpatialCoordinate, ) from ufl.integral import Integral +from ufl.integral_domain import DxIntegralDomain, DsIntegralDomain, DSIntegralDomain from ufl.matrix import Matrix from ufl.measure import Measure, custom_integral_types, integral_types, register_integral_type from ufl.objects import ( diff --git a/ufl/integral_domain.py b/ufl/integral_domain.py new file mode 100644 index 000000000..b5158af73 --- /dev/null +++ b/ufl/integral_domain.py @@ -0,0 +1,71 @@ +"""Integral domains.""" + +from abc import ABC, abstractmethod +from ufl.finiteelement import AbstractFiniteElement +from ufl.cell import AbstractCell + + +class AbstractIntegralDomain(ABC): + """Abstract base class for integral domain.""" + + def __hash__(self) -> int: + """Hash.""" + return hash(self.__repr__()) + + @abstractmethod + def __repr__(self) -> str: + """Representation.""" + + @abstractmethod + def integral_type(self) -> str: + """Integral type.""" + + +class DxIntegralDomain(AbstractIntegralDomain): + """Integral domain for dx.""" + + def __init__(self, coordinate_element: AbstractFiniteElement): + self.coordinate_element = coordinate_element + + def __repr__(self) -> str: + return f"DxIntegralDomain({self.coordinate_element!r})" + + def integral_type(self) -> str: + return "cell" + + +class DsIntegralDomain(AbstractIntegralDomain): + """Integral domain for ds.""" + + def __init__(self, coordinate_element: AbstractFiniteElement, facet_type: AbstractCell): + self.coordinate_element = coordinate_element + self.facet_type = facet_type + + def __repr__(self) -> str: + return f"DsIntegralDomain({self.coordinate_element!r}, {self.facet_type!r})" + + def integral_type(self) -> str: + return "exterior_facet" + + +class DSIntegralDomain(AbstractIntegralDomain): + """Integral domain for ds.""" + + def __init__( + self, + coordinate_element_positive_side: AbstractFiniteElement, + coordinate_element_negative_side: AbstractFiniteElement, + facet_type: AbstractCell, + ): + self.coordinate_element_positive_side = coordinate_element_positive_side + self.coordinate_element_negative_side = coordinate_element_negative_side + self.facet_type = facet_type + + def __repr__(self) -> str: + return ( + f"DSIntegralDomain({self.coordinate_element_positive_side!r}, " + f"{self.coordinate_element_negative_side!r}, {self.facet_type!r})" + ) + + def integral_type(self) -> str: + return "interior_facet" From eda52527ed915cc2ee5d526bdec6bc6493e87e54 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Tue, 25 Mar 2025 18:05:38 +0000 Subject: [PATCH 2/3] rufff --- ufl/__init__.py | 5 ++++- ufl/integral_domain.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ufl/__init__.py b/ufl/__init__.py index e5d737364..0a48f8359 100644 --- a/ufl/__init__.py +++ b/ufl/__init__.py @@ -303,7 +303,7 @@ SpatialCoordinate, ) from ufl.integral import Integral -from ufl.integral_domain import DxIntegralDomain, DsIntegralDomain, DSIntegralDomain +from ufl.integral_domain import DSIntegralDomain, DsIntegralDomain, DxIntegralDomain from ufl.matrix import Matrix from ufl.measure import Measure, custom_integral_types, integral_types, register_integral_type from ufl.objects import ( @@ -464,8 +464,11 @@ "Coefficients", "Cofunction", "Constant", + "DSIntegralDomain", "Dn", + "DsIntegralDomain", "Dx", + "DxIntegralDomain", "ExternalOperator", "FacetArea", "FacetNormal", diff --git a/ufl/integral_domain.py b/ufl/integral_domain.py index b5158af73..40e9da3cb 100644 --- a/ufl/integral_domain.py +++ b/ufl/integral_domain.py @@ -1,8 +1,9 @@ """Integral domains.""" from abc import ABC, abstractmethod -from ufl.finiteelement import AbstractFiniteElement + from ufl.cell import AbstractCell +from ufl.finiteelement import AbstractFiniteElement class AbstractIntegralDomain(ABC): @@ -16,6 +17,7 @@ def __hash__(self) -> int: def __repr__(self) -> str: """Representation.""" + @property @abstractmethod def integral_type(self) -> str: """Integral type.""" @@ -25,12 +27,16 @@ class DxIntegralDomain(AbstractIntegralDomain): """Integral domain for dx.""" def __init__(self, coordinate_element: AbstractFiniteElement): + """Initialise.""" self.coordinate_element = coordinate_element def __repr__(self) -> str: + """Representation.""" return f"DxIntegralDomain({self.coordinate_element!r})" + @property def integral_type(self) -> str: + """Integral type.""" return "cell" @@ -38,13 +44,17 @@ class DsIntegralDomain(AbstractIntegralDomain): """Integral domain for ds.""" def __init__(self, coordinate_element: AbstractFiniteElement, facet_type: AbstractCell): + """Initialise.""" self.coordinate_element = coordinate_element self.facet_type = facet_type def __repr__(self) -> str: + """Representation.""" return f"DsIntegralDomain({self.coordinate_element!r}, {self.facet_type!r})" + @property def integral_type(self) -> str: + """Integral type.""" return "exterior_facet" @@ -57,15 +67,19 @@ def __init__( coordinate_element_negative_side: AbstractFiniteElement, facet_type: AbstractCell, ): + """Initialise.""" self.coordinate_element_positive_side = coordinate_element_positive_side self.coordinate_element_negative_side = coordinate_element_negative_side self.facet_type = facet_type def __repr__(self) -> str: + """Representation.""" return ( f"DSIntegralDomain({self.coordinate_element_positive_side!r}, " f"{self.coordinate_element_negative_side!r}, {self.facet_type!r})" ) + @property def integral_type(self) -> str: + """Integral type.""" return "interior_facet" From 6327a30917f4b19a3d475241680dbc4be2359996 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Thu, 10 Jul 2025 10:28:20 +0100 Subject: [PATCH 3/3] Update ufl/integral_domain.py --- ufl/integral_domain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufl/integral_domain.py b/ufl/integral_domain.py index 40e9da3cb..ea8138232 100644 --- a/ufl/integral_domain.py +++ b/ufl/integral_domain.py @@ -59,7 +59,7 @@ def integral_type(self) -> str: class DSIntegralDomain(AbstractIntegralDomain): - """Integral domain for ds.""" + """Integral domain for dS.""" def __init__( self,