From b2cced36a4bd21d430e4e99f84b92851a8937006 Mon Sep 17 00:00:00 2001 From: Martin Campos Pinto Date: Wed, 5 Mar 2025 12:40:07 +0100 Subject: [PATCH] Unique API for single/multi-patch `Domain` objects (#173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to improve the compatibility between single and multi-patch domains, we add: - `subdomains` and `mappings` attributes to the `Domain` class, which always return a tuple (fixes #171); - the possibility of calling the `join` function (which usually creates multipatch domains) with a single patch. We also increase the library version to 0.19.1. --------- Co-authored-by: Yaman Güçlü --- pyproject.toml | 2 +- sympde/topology/domain.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8b791aaf..077cb53d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "sympde" -version = "0.19.0" +version = "0.19.1" description = "Symbolic calculus for partial differential equations (and variational forms)" readme = "README.rst" requires-python = ">= 3.8, < 3.13" diff --git a/sympde/topology/domain.py b/sympde/topology/domain.py index 31c852dd..12627ac8 100644 --- a/sympde/topology/domain.py +++ b/sympde/topology/domain.py @@ -6,7 +6,7 @@ import yaml import os -from collections import abc +from collections import abc, OrderedDict from typing import Union as TypeUnion, Optional, List, Dict, Iterable, TYPE_CHECKING # Union clashes with core.basic.Union @@ -180,6 +180,20 @@ def mapping(self) -> Optional[Mapping]: """The mapping that maps the logical domain to the physical domain""" return self.args[3] + @property + def subdomains(self) -> tuple: + """returns subdomains as tuple of Domains""" + if isinstance( self.interior, iterable_types): + subs = self.interior + else: + subs = [self.interior] + return tuple(subs) + + @property + def mappings(self) -> OrderedDict: + return OrderedDict([(P.logical_domain, P.mapping) + for P in self.subdomains]) + @property def logical_domain(self) -> Domain: """The domain is the image of the logical_domain under the mapping""" @@ -481,6 +495,11 @@ def join(cls, patches, connectivity, name): assert isinstance(connectivity, (tuple, list)) assert isinstance(name, str) + if len(patches) == 1: + # single patch domain: return the patch + assert len(connectivity) == 0 + return patches[0] + assert all(p.dim==patches[0].dim for p in patches) dim = int(patches[0].dim)