Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.2.0 #63

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")