Skip to content

Commit

Permalink
v0.2.0 (#63)
Browse files Browse the repository at this point in the history
* version number -> 0.2.0

* Python exceptions rather than Rust panics for linalg-rs/rlst#98

* format
  • Loading branch information
mscroggs authored Nov 27, 2024
1 parent 3b93051 commit 3a39a74
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default = ["sleef"]

[package]
name = "ndelement"
version = "0.1.3-dev"
version = "0.2.0"
edition = "2021"
authors = ["Matthew Scroggs <[email protected]>"]
description = "n-dimensional finite element definition library."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 = "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"
Expand Down
59 changes: 55 additions & 4 deletions python/ndelement/ciarlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand All @@ -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}")

0 comments on commit 3a39a74

Please sign in to comment.