Skip to content

Commit

Permalink
Unique API for single/multi-patch Domain objects (#173)
Browse files Browse the repository at this point in the history
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ü <yaman.guclu@gmail.com>
  • Loading branch information
campospinto and yguclu authored Mar 5, 2025
1 parent 623d6f8 commit b2cced3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 20 additions & 1 deletion sympde/topology/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b2cced3

Please sign in to comment.