cfsem 2.7.0__tar.gz → 3.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cfsem-3.0.0/.cargo/config.toml +2 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/.github/workflows/release_python.yml +1 -3
- {cfsem-2.7.0 → cfsem-3.0.0}/.github/workflows/release_rust.yml +2 -3
- {cfsem-2.7.0 → cfsem-3.0.0}/.github/workflows/test_python.yml +1 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/.github/workflows/test_rust.yml +1 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/CHANGELOG.md +27 -1
- {cfsem-2.7.0 → cfsem-3.0.0}/Cargo.lock +13 -13
- {cfsem-2.7.0 → cfsem-3.0.0}/Cargo.toml +9 -5
- {cfsem-2.7.0 → cfsem-3.0.0}/PKG-INFO +2 -2
- cfsem-3.0.0/benches/point_source.rs +178 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/__init__.py +5 -3
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/bindings.py +49 -9
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/solenoid_stress/thick_wall_cylinder_handcalc.py +1 -3
- {cfsem-2.7.0 → cfsem-3.0.0}/pyproject.toml +2 -4
- {cfsem-2.7.0 → cfsem-3.0.0}/src/math.rs +35 -1
- {cfsem-2.7.0 → cfsem-3.0.0}/src/physics/circular_filament.rs +6 -5
- {cfsem-2.7.0 → cfsem-3.0.0}/src/physics/mod.rs +1 -0
- cfsem-3.0.0/src/physics/point_source.rs +444 -0
- cfsem-3.0.0/src/physics/volumetric.rs +100 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/python.rs +61 -1
- {cfsem-2.7.0 → cfsem-3.0.0}/test/test_electromagnetics.py +96 -84
- {cfsem-2.7.0 → cfsem-3.0.0}/uv.lock +239 -32
- cfsem-2.7.0/.cargo/config.toml +0 -2
- cfsem-2.7.0/src/physics/point_source.rs +0 -205
- {cfsem-2.7.0 → cfsem-3.0.0}/.gitignore +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/.readthedocs.yml +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/CHANGELOG_PYTHON_ARCHIVE.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/CHANGELOG_RUST_ARCHIVE.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/CONTRIBUTING.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/LICENSE +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/README.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/benches/circular_filament.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/benches/linear_filament.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/build_docs.sh +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/py.typed +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/solenoid_stress/__init__.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/solenoid_stress/solenoid_1d.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/solenoid_stress/solenoid_handcalc.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/cfsem/types.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/assets/logo.svg +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/index.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/javascripts/mathjax.js +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/example_outputs/.placeholder +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/examples.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/filament.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/flux_density.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/force.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/grad_shafranov.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/inductance.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/math.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/solenoid_stress.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/types.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/python/vector_potential.md +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/requirements.txt +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/docs/stylesheets/extra.css +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/examples/helmholtz.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/examples/inductance.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/katex-header.html +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/mkdocs.yml +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/lib.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/mesh.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/physics/biotsavart.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/physics/gradshafranov.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/physics/linear_filament.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/physics/mesh_filament.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/src/testing.rs +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/test/__init__.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/test/test_examples.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/test/test_filaments.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/test/test_funcs.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/test/test_gradshafranov.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/test/test_math.py +0 -0
- {cfsem-2.7.0 → cfsem-3.0.0}/test/test_solenoid_stress.py +0 -0
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
name: release_python
|
|
7
7
|
|
|
8
8
|
on:
|
|
9
|
-
push:
|
|
10
|
-
branches:
|
|
11
|
-
- release
|
|
12
9
|
workflow_dispatch:
|
|
13
10
|
|
|
14
11
|
permissions:
|
|
@@ -177,6 +174,7 @@ jobs:
|
|
|
177
174
|
subject-path: 'wheels-*/*'
|
|
178
175
|
- name: Publish to PyPI
|
|
179
176
|
#if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
|
177
|
+
if: github.ref == 'refs/heads/release'
|
|
180
178
|
uses: PyO3/maturin-action@v1
|
|
181
179
|
env:
|
|
182
180
|
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PASSWORD }}
|
|
@@ -5,9 +5,7 @@ permissions:
|
|
|
5
5
|
contents: write
|
|
6
6
|
|
|
7
7
|
on:
|
|
8
|
-
|
|
9
|
-
branches:
|
|
10
|
-
- release
|
|
8
|
+
workflow_dispatch:
|
|
11
9
|
|
|
12
10
|
jobs:
|
|
13
11
|
|
|
@@ -24,6 +22,7 @@ jobs:
|
|
|
24
22
|
- name: Check semver
|
|
25
23
|
uses: obi1kenobi/cargo-semver-checks-action@v2
|
|
26
24
|
- name: Publish
|
|
25
|
+
if: github.ref == 'refs/heads/release'
|
|
27
26
|
env:
|
|
28
27
|
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
29
28
|
run: cargo publish
|
|
@@ -45,6 +45,7 @@ jobs:
|
|
|
45
45
|
|
|
46
46
|
# Python lint, test, and coverage
|
|
47
47
|
uv run --locked ruff check ./cfsem
|
|
48
|
+
uv run --locked ruff format ./cfsem --check
|
|
48
49
|
uv run --locked pyright ./cfsem --pythonversion 3.11
|
|
49
50
|
uv run --locked coverage run --source=./cfsem -m pytest ./test/
|
|
50
51
|
uv run --locked coverage report
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 3.0.0 2025-10-29
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
* Rust
|
|
8
|
+
* Add methods for vector potential of a dipole in `physics::point_source` and `python.rs` bindings
|
|
9
|
+
* Add `physics::volumetric` module with methods for fields inside a uniformly magnetized sphere
|
|
10
|
+
* Add `math::{clip_nan, switch_float}` functions for branchless-in-assembly float selection operations
|
|
11
|
+
* Python
|
|
12
|
+
* Add `vector_potential_dipole` function
|
|
13
|
+
* Add optional sphere radius input for dipole flux density
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
* Rust
|
|
18
|
+
* !Require sphere radius input for dipole flux density
|
|
19
|
+
* Update dependencies
|
|
20
|
+
* Use more codegen units and don't do LTO for debug builds
|
|
21
|
+
* Use more mul_add in flux_circular_filament
|
|
22
|
+
* Use multiplication instead of pow in dipole calcs
|
|
23
|
+
* Python
|
|
24
|
+
* !Enable more instruction sets for x86 processors
|
|
25
|
+
* Replace flatten() with ravel() everywhere to reduce copies
|
|
4
26
|
|
|
5
27
|
## 2.7.0 2025-10-15
|
|
6
28
|
|
|
@@ -35,3 +57,7 @@ body force density calcs.
|
|
|
35
57
|
* Python
|
|
36
58
|
* Update dep versions
|
|
37
59
|
* Use latest rust backend version, which includes 1.4-2x speedup for flux_density_linear_filament Biot-Savart calcs
|
|
60
|
+
|
|
61
|
+
## Earlier Versions
|
|
62
|
+
|
|
63
|
+
See archived changelogs for versions prior to 2.6.0.
|
|
@@ -64,7 +64,7 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
|
|
64
64
|
|
|
65
65
|
[[package]]
|
|
66
66
|
name = "cfsem"
|
|
67
|
-
version = "
|
|
67
|
+
version = "3.0.0"
|
|
68
68
|
dependencies = [
|
|
69
69
|
"criterion",
|
|
70
70
|
"itertools 0.14.0",
|
|
@@ -522,9 +522,9 @@ dependencies = [
|
|
|
522
522
|
|
|
523
523
|
[[package]]
|
|
524
524
|
name = "numpy"
|
|
525
|
-
version = "0.
|
|
525
|
+
version = "0.27.0"
|
|
526
526
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
527
|
-
checksum = "
|
|
527
|
+
checksum = "0fa24ffc88cf9d43f7269d6b6a0d0a00010924a8cc90604a21ef9c433b66998d"
|
|
528
528
|
dependencies = [
|
|
529
529
|
"libc",
|
|
530
530
|
"ndarray",
|
|
@@ -608,9 +608,9 @@ dependencies = [
|
|
|
608
608
|
|
|
609
609
|
[[package]]
|
|
610
610
|
name = "pyo3"
|
|
611
|
-
version = "0.
|
|
611
|
+
version = "0.27.1"
|
|
612
612
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
613
|
-
checksum = "
|
|
613
|
+
checksum = "37a6df7eab65fc7bee654a421404947e10a0f7085b6951bf2ea395f4659fb0cf"
|
|
614
614
|
dependencies = [
|
|
615
615
|
"indoc",
|
|
616
616
|
"libc",
|
|
@@ -625,18 +625,18 @@ dependencies = [
|
|
|
625
625
|
|
|
626
626
|
[[package]]
|
|
627
627
|
name = "pyo3-build-config"
|
|
628
|
-
version = "0.
|
|
628
|
+
version = "0.27.1"
|
|
629
629
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
630
|
-
checksum = "
|
|
630
|
+
checksum = "f77d387774f6f6eec64a004eac0ed525aab7fa1966d94b42f743797b3e395afb"
|
|
631
631
|
dependencies = [
|
|
632
632
|
"target-lexicon",
|
|
633
633
|
]
|
|
634
634
|
|
|
635
635
|
[[package]]
|
|
636
636
|
name = "pyo3-ffi"
|
|
637
|
-
version = "0.
|
|
637
|
+
version = "0.27.1"
|
|
638
638
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
639
|
-
checksum = "
|
|
639
|
+
checksum = "2dd13844a4242793e02df3e2ec093f540d948299a6a77ea9ce7afd8623f542be"
|
|
640
640
|
dependencies = [
|
|
641
641
|
"libc",
|
|
642
642
|
"pyo3-build-config",
|
|
@@ -644,9 +644,9 @@ dependencies = [
|
|
|
644
644
|
|
|
645
645
|
[[package]]
|
|
646
646
|
name = "pyo3-macros"
|
|
647
|
-
version = "0.
|
|
647
|
+
version = "0.27.1"
|
|
648
648
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
649
|
-
checksum = "
|
|
649
|
+
checksum = "eaf8f9f1108270b90d3676b8679586385430e5c0bb78bb5f043f95499c821a71"
|
|
650
650
|
dependencies = [
|
|
651
651
|
"proc-macro2",
|
|
652
652
|
"pyo3-macros-backend",
|
|
@@ -656,9 +656,9 @@ dependencies = [
|
|
|
656
656
|
|
|
657
657
|
[[package]]
|
|
658
658
|
name = "pyo3-macros-backend"
|
|
659
|
-
version = "0.
|
|
659
|
+
version = "0.27.1"
|
|
660
660
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
661
|
-
checksum = "
|
|
661
|
+
checksum = "70a3b2274450ba5288bc9b8c1b69ff569d1d61189d4bff38f8d22e03d17f932b"
|
|
662
662
|
dependencies = [
|
|
663
663
|
"heck",
|
|
664
664
|
"proc-macro2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "cfsem"
|
|
3
|
-
version = "
|
|
3
|
+
version = "3.0.0"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
authors = ["Commonwealth Fusion Systems <jlogan@cfs.energy>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -15,8 +15,8 @@ name = "cfsem"
|
|
|
15
15
|
crate-type = ["cdylib", "rlib"]
|
|
16
16
|
|
|
17
17
|
[dependencies]
|
|
18
|
-
pyo3 = { version="0.
|
|
19
|
-
numpy = { version="0.
|
|
18
|
+
pyo3 = { version="0.27.1", features=["extension-module"], optional=true }
|
|
19
|
+
numpy = { version="0.27.0", optional=true } # This must match pyo3 version!
|
|
20
20
|
|
|
21
21
|
nalgebra = "^0.34.1"
|
|
22
22
|
rayon = "^1.11.0"
|
|
@@ -37,8 +37,8 @@ overflow-checks = true
|
|
|
37
37
|
# Nearly full optimizations for debug builds to test for perf regressions
|
|
38
38
|
# when using maturin develop
|
|
39
39
|
opt-level = 3
|
|
40
|
-
lto = true
|
|
41
|
-
codegen-units =
|
|
40
|
+
#lto = true
|
|
41
|
+
codegen-units = 16
|
|
42
42
|
|
|
43
43
|
[features]
|
|
44
44
|
default = []
|
|
@@ -52,5 +52,9 @@ harness = false
|
|
|
52
52
|
name = "circular_filament"
|
|
53
53
|
harness = false
|
|
54
54
|
|
|
55
|
+
[[bench]]
|
|
56
|
+
name = "point_source"
|
|
57
|
+
harness = false
|
|
58
|
+
|
|
55
59
|
[package.metadata.docs.rs]
|
|
56
60
|
rustdoc-args = [ "--html-in-header", "katex-header.html" ]
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cfsem
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
7
|
Requires-Dist: numpy>=2
|
|
8
|
-
Requires-Dist: interpn>=0.6.
|
|
8
|
+
Requires-Dist: interpn>=0.6.4
|
|
9
9
|
Requires-Dist: findiff>=0.12.1
|
|
10
10
|
Requires-Dist: pydantic>=2
|
|
11
11
|
Requires-Dist: pydantic-numpy>=6
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#![allow(clippy::all)] // Clippy will attempt to remove black_box() internals
|
|
2
|
+
|
|
3
|
+
use cfsem::physics::point_source::{
|
|
4
|
+
flux_density_dipole, flux_density_dipole_par, vector_potential_dipole,
|
|
5
|
+
vector_potential_dipole_par,
|
|
6
|
+
};
|
|
7
|
+
use criterion::*;
|
|
8
|
+
use std::time::Duration;
|
|
9
|
+
|
|
10
|
+
fn bench_flux_density_dipole(c: &mut Criterion) {
|
|
11
|
+
let mut group = c.benchmark_group("Flux Density of a Magnetic Dipole");
|
|
12
|
+
group.sample_size(10);
|
|
13
|
+
group.measurement_time(Duration::from_secs(5));
|
|
14
|
+
|
|
15
|
+
for ndipoles in [1, 1000] {
|
|
16
|
+
for nobs in [10, 10_000] {
|
|
17
|
+
let locx = vec![0.01_f64; ndipoles];
|
|
18
|
+
let locy = vec![0.02_f64; ndipoles];
|
|
19
|
+
let locz = vec![0.03_f64; ndipoles];
|
|
20
|
+
|
|
21
|
+
let momx = vec![0.0_f64; ndipoles];
|
|
22
|
+
let momy = vec![0.0_f64; ndipoles];
|
|
23
|
+
let momz = vec![1.0_f64; ndipoles];
|
|
24
|
+
|
|
25
|
+
let outer_radius = vec![0.0_f64; ndipoles];
|
|
26
|
+
|
|
27
|
+
let obsx = vec![0.7_f64; nobs];
|
|
28
|
+
let obsy = vec![-0.4_f64; nobs];
|
|
29
|
+
let obsz = vec![0.9_f64; nobs];
|
|
30
|
+
|
|
31
|
+
let mut outx = vec![0.0_f64; nobs];
|
|
32
|
+
let mut outy = vec![0.0_f64; nobs];
|
|
33
|
+
let mut outz = vec![0.0_f64; nobs];
|
|
34
|
+
|
|
35
|
+
let ntot = nobs * ndipoles;
|
|
36
|
+
group.throughput(Throughput::Elements(ntot as u64));
|
|
37
|
+
|
|
38
|
+
group.bench_with_input(
|
|
39
|
+
BenchmarkId::new(
|
|
40
|
+
format!(
|
|
41
|
+
"Flux Density of a Magnetic Dipole\n{} src × {} obs",
|
|
42
|
+
ndipoles, nobs
|
|
43
|
+
),
|
|
44
|
+
ntot,
|
|
45
|
+
),
|
|
46
|
+
&ntot,
|
|
47
|
+
|b, &_| {
|
|
48
|
+
b.iter(|| {
|
|
49
|
+
black_box(
|
|
50
|
+
flux_density_dipole(
|
|
51
|
+
(&locx, &locy, &locz),
|
|
52
|
+
(&momx, &momy, &momz),
|
|
53
|
+
&outer_radius,
|
|
54
|
+
(&obsx, &obsy, &obsz),
|
|
55
|
+
(&mut outx, &mut outy, &mut outz),
|
|
56
|
+
)
|
|
57
|
+
.unwrap(),
|
|
58
|
+
)
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
group.bench_with_input(
|
|
64
|
+
BenchmarkId::new(
|
|
65
|
+
format!(
|
|
66
|
+
"Flux Density of a Magnetic Dipole, Parallel\n{} src × {} obs",
|
|
67
|
+
ndipoles, nobs
|
|
68
|
+
),
|
|
69
|
+
ntot,
|
|
70
|
+
),
|
|
71
|
+
&ntot,
|
|
72
|
+
|b, &_| {
|
|
73
|
+
b.iter(|| {
|
|
74
|
+
black_box(
|
|
75
|
+
flux_density_dipole_par(
|
|
76
|
+
(&locx, &locy, &locz),
|
|
77
|
+
(&momx, &momy, &momz),
|
|
78
|
+
&outer_radius,
|
|
79
|
+
(&obsx, &obsy, &obsz),
|
|
80
|
+
(&mut outx, &mut outy, &mut outz),
|
|
81
|
+
)
|
|
82
|
+
.unwrap(),
|
|
83
|
+
)
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
group.finish();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fn bench_vector_potential_dipole(c: &mut Criterion) {
|
|
94
|
+
let mut group = c.benchmark_group("Vector Potential of a Magnetic Dipole");
|
|
95
|
+
group.sample_size(10);
|
|
96
|
+
group.measurement_time(Duration::from_secs(5));
|
|
97
|
+
|
|
98
|
+
for ndipoles in [1, 1000] {
|
|
99
|
+
for nobs in [10, 10_000] {
|
|
100
|
+
let locx = vec![0.01_f64; ndipoles];
|
|
101
|
+
let locy = vec![0.02_f64; ndipoles];
|
|
102
|
+
let locz = vec![0.03_f64; ndipoles];
|
|
103
|
+
|
|
104
|
+
let momx = vec![0.0_f64; ndipoles];
|
|
105
|
+
let momy = vec![0.0_f64; ndipoles];
|
|
106
|
+
let momz = vec![1.0_f64; ndipoles];
|
|
107
|
+
|
|
108
|
+
let outer_radius = vec![0.0_f64; ndipoles];
|
|
109
|
+
|
|
110
|
+
let obsx = vec![0.7_f64; nobs];
|
|
111
|
+
let obsy = vec![-0.4_f64; nobs];
|
|
112
|
+
let obsz = vec![0.9_f64; nobs];
|
|
113
|
+
|
|
114
|
+
let mut outx = vec![0.0_f64; nobs];
|
|
115
|
+
let mut outy = vec![0.0_f64; nobs];
|
|
116
|
+
let mut outz = vec![0.0_f64; nobs];
|
|
117
|
+
|
|
118
|
+
let ntot = nobs * ndipoles;
|
|
119
|
+
group.throughput(Throughput::Elements(ntot as u64));
|
|
120
|
+
|
|
121
|
+
group.bench_with_input(
|
|
122
|
+
BenchmarkId::new(
|
|
123
|
+
format!(
|
|
124
|
+
"Vector Potential of a Magnetic Dipole\n{} src × {} obs",
|
|
125
|
+
ndipoles, nobs
|
|
126
|
+
),
|
|
127
|
+
ntot,
|
|
128
|
+
),
|
|
129
|
+
&ntot,
|
|
130
|
+
|b, &_| {
|
|
131
|
+
b.iter(|| {
|
|
132
|
+
black_box(
|
|
133
|
+
vector_potential_dipole(
|
|
134
|
+
(&locx, &locy, &locz),
|
|
135
|
+
(&momx, &momy, &momz),
|
|
136
|
+
&outer_radius,
|
|
137
|
+
(&obsx, &obsy, &obsz),
|
|
138
|
+
(&mut outx, &mut outy, &mut outz),
|
|
139
|
+
)
|
|
140
|
+
.unwrap(),
|
|
141
|
+
)
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
group.bench_with_input(
|
|
147
|
+
BenchmarkId::new(
|
|
148
|
+
format!(
|
|
149
|
+
"Vector Potential of a Magnetic Dipole, Parallel\n{} src × {} obs",
|
|
150
|
+
ndipoles, nobs
|
|
151
|
+
),
|
|
152
|
+
ntot,
|
|
153
|
+
),
|
|
154
|
+
&ntot,
|
|
155
|
+
|b, &_| {
|
|
156
|
+
b.iter(|| {
|
|
157
|
+
black_box(
|
|
158
|
+
vector_potential_dipole_par(
|
|
159
|
+
(&locx, &locy, &locz),
|
|
160
|
+
(&momx, &momy, &momz),
|
|
161
|
+
&outer_radius,
|
|
162
|
+
(&obsx, &obsy, &obsz),
|
|
163
|
+
(&mut outx, &mut outy, &mut outz),
|
|
164
|
+
)
|
|
165
|
+
.unwrap(),
|
|
166
|
+
)
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
group.finish();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
criterion_group!(group_flux_density, bench_flux_density_dipole);
|
|
177
|
+
criterion_group!(group_vector_potential, bench_vector_potential_dipole);
|
|
178
|
+
criterion_main!(group_flux_density, group_vector_potential);
|
|
@@ -23,6 +23,7 @@ from cfsem.bindings import (
|
|
|
23
23
|
rotate_filaments_about_path,
|
|
24
24
|
vector_potential_circular_filament,
|
|
25
25
|
vector_potential_linear_filament,
|
|
26
|
+
vector_potential_dipole,
|
|
26
27
|
)
|
|
27
28
|
from cfsem.types import Array3xN
|
|
28
29
|
|
|
@@ -62,6 +63,7 @@ __all__ = [
|
|
|
62
63
|
"flux_density_circular_filament_cartesian",
|
|
63
64
|
"mutual_inductance_circular_to_linear",
|
|
64
65
|
"flux_density_dipole",
|
|
66
|
+
"vector_potential_dipole",
|
|
65
67
|
"body_force_density_circular_filament_cartesian",
|
|
66
68
|
"body_force_density_linear_filament",
|
|
67
69
|
]
|
|
@@ -437,10 +439,10 @@ def filament_coil(r: float, z: float, w: float, h: float, nt: float, nr: int, nz
|
|
|
437
439
|
rmesh, zmesh = np.meshgrid(rs, zs, indexing="ij") # [m]
|
|
438
440
|
|
|
439
441
|
# Number of turns attributed to each point is not necessarily an integer
|
|
440
|
-
n = np.full_like(rmesh.
|
|
442
|
+
n = np.full_like(rmesh.ravel(), float(nt) / (nr * nz))
|
|
441
443
|
|
|
442
444
|
# Pack filament locations and number of turns into an array together
|
|
443
|
-
filaments = np.dstack([rmesh.
|
|
445
|
+
filaments = np.dstack([rmesh.ravel(), zmesh.ravel(), n]).reshape(nr * nz, 3)
|
|
444
446
|
|
|
445
447
|
return filaments # [m], [m], [dimensionless]
|
|
446
448
|
|
|
@@ -542,7 +544,7 @@ def self_inductance_distributed_axisymmetric_conductor(
|
|
|
542
544
|
# Set up
|
|
543
545
|
nr = rgrid.size
|
|
544
546
|
nz = zgrid.size
|
|
545
|
-
psi_interpolator = MulticubicRectilinear.new([rgrid, zgrid], psi_part.
|
|
547
|
+
psi_interpolator = MulticubicRectilinear.new([rgrid, zgrid], psi_part.ravel())
|
|
546
548
|
|
|
547
549
|
# Same-length diffs assuming last grid cell is the same size
|
|
548
550
|
# as the previous one. In general the conductor can't touch the
|
|
@@ -5,6 +5,8 @@ This fulfills the function of typing stubs, while also guaranteeing arrays are
|
|
|
5
5
|
passed as contiguous and reallocating into contiguous inputs if necessary.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
8
10
|
from numpy import ascontiguousarray, float64, zeros_like
|
|
9
11
|
from numpy.typing import NDArray
|
|
10
12
|
|
|
@@ -23,6 +25,7 @@ from .cfsem import (
|
|
|
23
25
|
flux_density_circular_filament_cartesian as em_flux_density_circular_filament_cartesian,
|
|
24
26
|
)
|
|
25
27
|
from .cfsem import flux_density_dipole as em_flux_density_dipole
|
|
28
|
+
from .cfsem import vector_potential_dipole as em_vector_potential_dipole
|
|
26
29
|
from .cfsem import flux_density_linear_filament as em_flux_density_linear_filament
|
|
27
30
|
from .cfsem import gs_operator_order2 as em_gs_operator_order2
|
|
28
31
|
from .cfsem import gs_operator_order4 as em_gs_operator_order4
|
|
@@ -194,7 +197,7 @@ def flux_density_linear_filament(
|
|
|
194
197
|
xyzp = _3tup_contig(xyzp)
|
|
195
198
|
xyzfil = _3tup_contig(xyzfil)
|
|
196
199
|
dlxyzfil = _3tup_contig(dlxyzfil)
|
|
197
|
-
ifil = ascontiguousarray(ifil).
|
|
200
|
+
ifil = ascontiguousarray(ifil).ravel()
|
|
198
201
|
return em_flux_density_linear_filament(xyzp, xyzfil, dlxyzfil, ifil, par)
|
|
199
202
|
|
|
200
203
|
|
|
@@ -225,7 +228,7 @@ def vector_potential_linear_filament(
|
|
|
225
228
|
xyzp = _3tup_contig(xyzp)
|
|
226
229
|
xyzfil = _3tup_contig(xyzfil)
|
|
227
230
|
dlxyzfil = _3tup_contig(dlxyzfil)
|
|
228
|
-
ifil = ascontiguousarray(ifil).
|
|
231
|
+
ifil = ascontiguousarray(ifil).ravel()
|
|
229
232
|
return em_vector_potential_linear_filament(xyzp, xyzfil, dlxyzfil, ifil, par)
|
|
230
233
|
|
|
231
234
|
|
|
@@ -471,7 +474,8 @@ def flux_density_dipole(
|
|
|
471
474
|
loc: Array3xN,
|
|
472
475
|
moment: Array3xN,
|
|
473
476
|
xyzp: Array3xN,
|
|
474
|
-
par: bool = True,
|
|
477
|
+
par: bool = True, # Ordered for backwards compatibility
|
|
478
|
+
outer_radius: Optional[NDArray[float64]] = None,
|
|
475
479
|
) -> Array3xN:
|
|
476
480
|
"""
|
|
477
481
|
Magnetic flux density of a dipole in cartesian coordiantes.
|
|
@@ -481,6 +485,8 @@ def flux_density_dipole(
|
|
|
481
485
|
moment: [A-m^2] dipole magnetic moment vector
|
|
482
486
|
xyzp: [m] x,y,z coords of observation points
|
|
483
487
|
par: Whether to use CPU parallelism
|
|
488
|
+
outer_radius: [m] radius inside which to defer to magnetized sphere calc. Defaults to zeroes.
|
|
489
|
+
|
|
484
490
|
|
|
485
491
|
Returns:
|
|
486
492
|
[T] flux density
|
|
@@ -488,11 +494,45 @@ def flux_density_dipole(
|
|
|
488
494
|
loc = _3tup_contig(loc)
|
|
489
495
|
moment = _3tup_contig(moment)
|
|
490
496
|
xyzp = _3tup_contig(xyzp)
|
|
491
|
-
|
|
497
|
+
outer_radius = outer_radius or zeros_like(loc[0])
|
|
498
|
+
outer_radius = ascontiguousarray(outer_radius).ravel()
|
|
499
|
+
|
|
500
|
+
bx, by, bz = em_flux_density_dipole(loc, moment, xyzp, outer_radius, par) # [T]
|
|
492
501
|
|
|
493
502
|
return bx, by, bz # type: ignore
|
|
494
503
|
|
|
495
504
|
|
|
505
|
+
def vector_potential_dipole(
|
|
506
|
+
loc: Array3xN,
|
|
507
|
+
moment: Array3xN,
|
|
508
|
+
xyzp: Array3xN,
|
|
509
|
+
par: bool = True, # Ordered for backwards compatibility
|
|
510
|
+
outer_radius: Optional[NDArray[float64]] = None,
|
|
511
|
+
) -> Array3xN:
|
|
512
|
+
"""
|
|
513
|
+
Magnetic vector potential of a dipole in cartesian coordiantes.
|
|
514
|
+
|
|
515
|
+
Args:
|
|
516
|
+
loc: [m] x,y,z coordinates of dipole
|
|
517
|
+
moment: [A-m^2] dipole magnetic moment vector
|
|
518
|
+
xyzp: [m] x,y,z coords of observation points
|
|
519
|
+
par: Whether to use CPU parallelism
|
|
520
|
+
outer_radius: [m] radius inside which to defer to magnetized sphere calc. Defaults to zeroes.
|
|
521
|
+
|
|
522
|
+
Returns:
|
|
523
|
+
[V⋅s⋅m-1] vector potential
|
|
524
|
+
"""
|
|
525
|
+
loc = _3tup_contig(loc)
|
|
526
|
+
moment = _3tup_contig(moment)
|
|
527
|
+
xyzp = _3tup_contig(xyzp)
|
|
528
|
+
outer_radius = outer_radius or zeros_like(loc[0])
|
|
529
|
+
outer_radius = ascontiguousarray(outer_radius).ravel()
|
|
530
|
+
|
|
531
|
+
ax, ay, az = em_vector_potential_dipole(loc, moment, xyzp, outer_radius, par) # [T]
|
|
532
|
+
|
|
533
|
+
return ax, ay, az # type: ignore
|
|
534
|
+
|
|
535
|
+
|
|
496
536
|
def body_force_density_circular_filament_cartesian(
|
|
497
537
|
ifil: NDArray[float64],
|
|
498
538
|
rfil: NDArray[float64],
|
|
@@ -551,7 +591,7 @@ def body_force_density_linear_filament(
|
|
|
551
591
|
"""
|
|
552
592
|
xyzfil = _3tup_contig(xyzfil)
|
|
553
593
|
dlxyzfil = _3tup_contig(dlxyzfil)
|
|
554
|
-
ifil = ascontiguousarray(ifil).
|
|
594
|
+
ifil = ascontiguousarray(ifil).ravel()
|
|
555
595
|
obs = _3tup_contig(obs)
|
|
556
596
|
j = _3tup_contig(j)
|
|
557
597
|
jxbx, jxby, jxbz = em_body_force_density_linear_filament(xyzfil, dlxyzfil, ifil, obs, j, par) # [N/m^3]
|
|
@@ -565,9 +605,9 @@ def _3tup_contig(
|
|
|
565
605
|
"""Make contiguous references or copies to arrays in a 3-tuple.
|
|
566
606
|
Only copies data if it is not already contiguous."""
|
|
567
607
|
return (
|
|
568
|
-
ascontiguousarray(t[0]).
|
|
569
|
-
ascontiguousarray(t[1]).
|
|
570
|
-
ascontiguousarray(t[2]).
|
|
608
|
+
ascontiguousarray(t[0]).ravel(),
|
|
609
|
+
ascontiguousarray(t[1]).ravel(),
|
|
610
|
+
ascontiguousarray(t[2]).ravel(),
|
|
571
611
|
)
|
|
572
612
|
|
|
573
613
|
|
|
@@ -576,4 +616,4 @@ def _2tup_contig(
|
|
|
576
616
|
) -> tuple[NDArray[float64], NDArray[float64]]:
|
|
577
617
|
"""Make contiguous references or copies to arrays in a 2-tuple.
|
|
578
618
|
Only copies data if it is not already contiguous."""
|
|
579
|
-
return (ascontiguousarray(t[0]).
|
|
619
|
+
return (ascontiguousarray(t[0]).ravel(), ascontiguousarray(t[1]).ravel())
|
|
@@ -7,9 +7,7 @@ with constant and isotropic material properties and small displacements.
|
|
|
7
7
|
from numpy.typing import NDArray
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def s_hoop_thick_wall_cylinder(
|
|
11
|
-
r: NDArray, ri: float, ro: float, pin: float, pout: float
|
|
12
|
-
) -> NDArray:
|
|
10
|
+
def s_hoop_thick_wall_cylinder(r: NDArray, ri: float, ro: float, pin: float, pout: float) -> NDArray:
|
|
13
11
|
"""
|
|
14
12
|
Hoop stress at a location in a thick walled cylinder under pressure load
|
|
15
13
|
with ends "capped", although the capped constraint does not affect the hoop or radial stress
|
|
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cfsem"
|
|
7
|
-
version = "
|
|
7
|
+
version = "3.0.0"
|
|
8
8
|
description = "Quasi-steady electromagnetics including filamentized approximations, Biot-Savart, and Grad-Shafranov."
|
|
9
9
|
authors = [{name = "Commonwealth Fusion Systems", email = "jlogan@cfs.energy"}]
|
|
10
10
|
requires-python = ">=3.9, <3.14"
|
|
@@ -15,7 +15,7 @@ classifiers = [
|
|
|
15
15
|
]
|
|
16
16
|
dependencies = [
|
|
17
17
|
"numpy >= 2",
|
|
18
|
-
"interpn >= 0.6.
|
|
18
|
+
"interpn >= 0.6.4",
|
|
19
19
|
"findiff >= 0.12.1",
|
|
20
20
|
"pydantic >= 2",
|
|
21
21
|
"pydantic-numpy >= 6"
|
|
@@ -58,8 +58,6 @@ select = [
|
|
|
58
58
|
"B",
|
|
59
59
|
# flake8-simplify
|
|
60
60
|
"SIM",
|
|
61
|
-
# isort
|
|
62
|
-
"I",
|
|
63
61
|
]
|
|
64
62
|
|
|
65
63
|
[tool.coverage.report]
|
|
@@ -84,7 +84,7 @@ pub fn ellipe(m: f64) -> f64 {
|
|
|
84
84
|
ellip
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/// 3D $(x^2 + y^2 + z^2)^{1/2}$ using `mul_add` to
|
|
87
|
+
/// 3D $(x^2 + y^2 + z^2)^{1/2}$ using `mul_add` to reduce roundoff error.
|
|
88
88
|
#[inline]
|
|
89
89
|
pub fn rss3(x: f64, y: f64, z: f64) -> f64 {
|
|
90
90
|
x.mul_add(x, y.mul_add(y, z.powi(2))).sqrt()
|
|
@@ -166,3 +166,37 @@ pub fn decompose_filament(
|
|
|
166
166
|
|
|
167
167
|
(midpoint, dl)
|
|
168
168
|
}
|
|
169
|
+
|
|
170
|
+
/// Clip NaN values to the provided value.
|
|
171
|
+
/// This is carefully organized to avoid producing any `jmp`
|
|
172
|
+
/// instructions on modern-as-of-2025 systems.
|
|
173
|
+
#[inline]
|
|
174
|
+
pub fn clip_nan(x: f64, v: f64) -> f64 {
|
|
175
|
+
if x.is_nan() { v } else { x }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/// Defer between two float values (left and right)
|
|
179
|
+
/// depending on some condition.
|
|
180
|
+
///
|
|
181
|
+
/// Evaluates like `left if cond else right`, clipping
|
|
182
|
+
/// either value to zero if it is non-finite.
|
|
183
|
+
///
|
|
184
|
+
/// If the condition is based on a float comparison, this
|
|
185
|
+
/// will evaluate without producing any `jmp`
|
|
186
|
+
/// instructions on modern-as-of-2025 systems.
|
|
187
|
+
#[inline(always)] // Must be inlined to eliminate jmp
|
|
188
|
+
pub fn switch_float(left: f64, right: f64, cond: bool) -> f64 {
|
|
189
|
+
// Convert the boolean check to floating-point factors
|
|
190
|
+
// for each branch without producing a true branch
|
|
191
|
+
let left_factor: f64 = match cond {
|
|
192
|
+
true => 1.0, // This does not produce a jmp!
|
|
193
|
+
false => 0.0,
|
|
194
|
+
};
|
|
195
|
+
let right_factor: f64 = 1.0 - left_factor;
|
|
196
|
+
|
|
197
|
+
// Use float factors instead of a true branch
|
|
198
|
+
let left_part = left * left_factor;
|
|
199
|
+
let right_part = right * right_factor;
|
|
200
|
+
|
|
201
|
+
clip_nan(left_part, 0.0) + clip_nan(right_part, 0.0)
|
|
202
|
+
}
|