From 3a39a74b6b38c62a2b5f3adbd62e76958d3cb826 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Wed, 27 Nov 2024 14:56:55 +0000 Subject: [PATCH] v0.2.0 (#63) * version number -> 0.2.0 * Python exceptions rather than Rust panics for https://github.com/linalg-rs/rlst/issues/98 * format --- Cargo.toml | 2 +- README.md | 2 +- pyproject.toml | 2 +- python/ndelement/ciarlet.py | 59 ++++++++++++++++++++++++++++++++++--- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ce4eb3..e27f132 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ default = ["sleef"] [package] name = "ndelement" -version = "0.1.3-dev" +version = "0.2.0" edition = "2021" authors = ["Matthew Scroggs "] description = "n-dimensional finite element definition library." diff --git a/README.md b/README.md index 026d0a2..636230e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ndelement is an open-source library written in Rust that can be used to create n You can use the latest release of ndelement by adding the following to `[dependencies]` section of your Cargo.toml file: ```toml -ndelement = "0.1.3" +ndelement = "0.2.0" ``` ### Python diff --git a/pyproject.toml b/pyproject.toml index 0a0f501..621cca7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "ndelement" -version = "0.1.3-dev" +version = "0.2.0" description = "n-dimensional finite element definition library." readme = "README.md" requires-python = ">=3.8" diff --git a/python/ndelement/ciarlet.py b/python/ndelement/ciarlet.py index 501fc05..2456d6e 100644 --- a/python/ndelement/ciarlet.py +++ b/python/ndelement/ciarlet.py @@ -186,17 +186,62 @@ def tabulate(self, points: npt.NDArray[np.floating], nderivs: int) -> npt.NDArra class ElementFamily(object): """Ciarlet element.""" - def __init__(self, rs_family: _CDataBase, owned: bool = True): + def __init__(self, family: Family, degree: int, rs_family: _CDataBase, owned: bool = True): """Initialise.""" self._rs_family = rs_family self._owned = owned + self._family = family + self._degree = degree def __del__(self): """Delete object.""" if self._owned: _lib.element_family_t_free(self._rs_family) + @property + def family(self) -> Family: + """The family.""" + return self._family + + @property + def degree(self) -> int: + """The degree.""" + return self._degree + def element(self, cell: ReferenceCellType) -> CiarletElement: + """Create an element.""" + # TODO: remove these error once https://github.com/linalg-rs/rlst/issues/98 is fixed + msg = "Cannot create element due to bug in RLST" + if self.family == Family.Lagrange: + if cell == ReferenceCellType.Interval and self.degree >= 99: + raise RuntimeError(msg) + if cell == ReferenceCellType.Triangle and self.degree >= 13: + raise RuntimeError(msg) + if cell == ReferenceCellType.Quadrilateral and self.degree >= 10: + raise RuntimeError(msg) + if cell == ReferenceCellType.Tetrahedron and self.degree >= 7: + raise RuntimeError(msg) + if cell == ReferenceCellType.Hexahedron and self.degree >= 5: + raise RuntimeError(msg) + if self.family == Family.RaviartThomas: + if cell == ReferenceCellType.Triangle and self.degree >= 10: + raise RuntimeError(msg) + if cell == ReferenceCellType.Quadrilateral and self.degree >= 7: + raise RuntimeError(msg) + if cell == ReferenceCellType.Tetrahedron and self.degree >= 5: + raise RuntimeError(msg) + if cell == ReferenceCellType.Hexahedron and self.degree >= 3: + raise RuntimeError(msg) + if self.family == Family.NedelecFirstKind: + if cell == ReferenceCellType.Triangle and self.degree >= 10: + raise RuntimeError(msg) + if cell == ReferenceCellType.Quadrilateral and self.degree >= 7: + raise RuntimeError(msg) + if cell == ReferenceCellType.Tetrahedron and self.degree >= 5: + raise RuntimeError(msg) + if cell == ReferenceCellType.Hexahedron and self.degree >= 3: + raise RuntimeError(msg) + return CiarletElement(_lib.element_family_create_element(self._rs_family, cell.value)) @@ -209,10 +254,16 @@ def create_family( """Create a new element family.""" rust_type = _rtypes[dtype] if family == Family.Lagrange: - return ElementFamily(_lib.create_lagrange_family(degree, continuity.value, rust_type)) + return ElementFamily( + family, degree, _lib.create_lagrange_family(degree, continuity.value, rust_type) + ) elif family == Family.RaviartThomas: - return ElementFamily(_lib.create_raviart_thomas_family(degree, continuity.value, rust_type)) + return ElementFamily( + family, degree, _lib.create_raviart_thomas_family(degree, continuity.value, rust_type) + ) elif family == Family.NedelecFirstKind: - return ElementFamily(_lib.create_nedelec_family(degree, continuity.value, rust_type)) + return ElementFamily( + family, degree, _lib.create_nedelec_family(degree, continuity.value, rust_type) + ) else: raise ValueError(f"Unsupported family: {family}")