-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
482 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: 🧪 | ||
name: 🧪📅 | ||
|
||
on: | ||
schedule: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
fn main() { | ||
let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
|
||
// Determine the target directory within the workspace root | ||
let target_dir = env::var("CARGO_TARGET_DIR") | ||
.map(PathBuf::from) | ||
.unwrap_or_else(|_| crate_dir.join("target")); | ||
|
||
// Ensure the target directory exists | ||
fs::create_dir_all(&target_dir).expect("Unable to create target directory"); | ||
|
||
// Create the header file path | ||
let header_path = Path::new(&target_dir).join("include").join("_bempprs.h"); | ||
|
||
let config_path = Path::new(&crate_dir).join("cbindgen.toml"); | ||
let config = cbindgen::Config::from_file(config_path).expect("Unable to load cbindgen config"); | ||
|
||
// Generate the bindings | ||
let bindings = cbindgen::Builder::new() | ||
.with_crate(crate_dir) | ||
.with_config(config) | ||
.generate() | ||
.expect("Unable to generate bindings"); | ||
|
||
// Write the bindings to the header file | ||
bindings.write_to_file(header_path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language = "C" | ||
|
||
[export] | ||
exclude = [] | ||
|
||
[enum] | ||
prefix_with_name = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[build-system] | ||
requires = ["maturin>=1,<2"] | ||
build-backend = "maturin" | ||
|
||
[project] | ||
name = "bempp-rs" | ||
version = "0.1.0-dev" | ||
description = "Boundary element method library" | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
license = { file = "LICENSE" } | ||
authors = [ | ||
{name = "Timo Betcke", email = "[email protected]"}, | ||
{name = "Srinath Kailasa", email = "[email protected]"}, | ||
{name = "Matthew Scroggs", email = "[email protected]"} | ||
] | ||
classifiers = [ | ||
"Programming Language :: Rust", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
] | ||
dependencies = [ | ||
"maturin>=1.7", | ||
"numpy", | ||
"cffi", | ||
'patchelf; platform_system == "Linux"', | ||
"ndelement", | ||
"ndgrid" | ||
] | ||
packages = ["bempp"] | ||
|
||
[project.urls] | ||
homepage = "https://github.com/bempp/bempp-rs" | ||
repository = "https://github.com/bempp/bempp-rs" | ||
|
||
[tool.maturin] | ||
python-source = "python" | ||
module-name = "bempp._bempprs" | ||
|
||
[tool.ruff] | ||
line-length = 100 | ||
indent-width = 4 | ||
|
||
[tool.ruff.lint.per-file-ignores] | ||
"__init__.py" = ["F401"] | ||
|
||
[tool.ruff.lint.pydocstyle] | ||
convention = "google" | ||
|
||
[tool.mypy] | ||
ignore_missing_imports = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""Bempp.""" | ||
|
||
from bempp import function_space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Function space.""" | ||
|
||
from bempp._bempprs import lib as _lib, ffi as _ffi | ||
from ndgrid.grid import Grid | ||
from ndelement.ciarlet import ElementFamily | ||
|
||
|
||
class FunctionSpace(object): | ||
"""Function space.""" | ||
|
||
def __init__(self, rs_space): | ||
"""Initialise.""" | ||
self._rs_space = rs_space | ||
|
||
def __del__(self): | ||
"""Delete.""" | ||
_lib.free_space(self._rs_space) | ||
|
||
@property | ||
def local_size(self) -> int: | ||
"""Number of DOFs on current process.""" | ||
return _lib.space_local_size(self._rs_space) | ||
|
||
@property | ||
def global_size(self) -> int: | ||
"""Number of DOFs on all processes.""" | ||
return _lib.space_global_size(self._rs_space) | ||
|
||
|
||
def function_space(grid: Grid, family: ElementFamily) -> FunctionSpace: | ||
return FunctionSpace( | ||
_lib.space_new(_ffi.cast("void*", grid._rs_grid), _ffi.cast("void*", family._rs_family)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
from bempp.function_space import function_space | ||
from ndgrid.shapes import regular_sphere | ||
from ndelement.ciarlet import create_family, Family, Continuity | ||
from ndelement.reference_cell import ReferenceCellType | ||
|
||
|
||
@pytest.mark.parametrize("level", range(4)) | ||
def test_create_space_dp0(level): | ||
grid = regular_sphere(level) | ||
element = create_family(Family.Lagrange, 0, Continuity.Discontinuous) | ||
|
||
space = function_space(grid, element) | ||
|
||
assert space.local_size == grid.entity_count(ReferenceCellType.Triangle) | ||
assert space.local_size == space.global_size | ||
|
||
|
||
@pytest.mark.parametrize("level", range(4)) | ||
def test_create_space_p1(level): | ||
grid = regular_sphere(level) | ||
element = create_family(Family.Lagrange, 1) | ||
|
||
space = function_space(grid, element) | ||
|
||
assert space.local_size == grid.entity_count(ReferenceCellType.Point) | ||
assert space.local_size == space.global_size | ||
|
||
|
||
@pytest.mark.parametrize("level", range(4)) | ||
def test_create_space_p2(level): | ||
grid = regular_sphere(level) | ||
element = create_family(Family.Lagrange, 2) | ||
|
||
space = function_space(grid, element) | ||
|
||
assert space.local_size == grid.entity_count(ReferenceCellType.Point) + grid.entity_count( | ||
ReferenceCellType.Interval | ||
) | ||
assert space.local_size == space.global_size |
Oops, something went wrong.