cfsem 2.6.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.6.0 → cfsem-3.0.0}/.github/workflows/release_python.yml +1 -3
- {cfsem-2.6.0 → cfsem-3.0.0}/.github/workflows/release_rust.yml +2 -3
- {cfsem-2.6.0 → cfsem-3.0.0}/.github/workflows/test_python.yml +1 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/.github/workflows/test_rust.yml +1 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/CHANGELOG.md +32 -1
- {cfsem-2.6.0 → cfsem-3.0.0}/Cargo.lock +13 -13
- {cfsem-2.6.0 → cfsem-3.0.0}/Cargo.toml +9 -5
- {cfsem-2.6.0 → cfsem-3.0.0}/PKG-INFO +2 -2
- cfsem-3.0.0/benches/point_source.rs +178 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/__init__.py +105 -3
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/bindings.py +49 -9
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/solenoid_stress/thick_wall_cylinder_handcalc.py +1 -3
- {cfsem-2.6.0 → cfsem-3.0.0}/examples/inductance.py +24 -8
- {cfsem-2.6.0 → cfsem-3.0.0}/pyproject.toml +2 -4
- {cfsem-2.6.0 → cfsem-3.0.0}/src/math.rs +35 -1
- {cfsem-2.6.0 → cfsem-3.0.0}/src/physics/circular_filament.rs +6 -5
- {cfsem-2.6.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.6.0 → cfsem-3.0.0}/src/python.rs +61 -1
- {cfsem-2.6.0 → cfsem-3.0.0}/test/test_electromagnetics.py +137 -78
- {cfsem-2.6.0 → cfsem-3.0.0}/uv.lock +238 -31
- cfsem-2.6.0/.cargo/config.toml +0 -2
- cfsem-2.6.0/src/physics/point_source.rs +0 -205
- {cfsem-2.6.0 → cfsem-3.0.0}/.gitignore +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/.readthedocs.yml +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/CHANGELOG_PYTHON_ARCHIVE.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/CHANGELOG_RUST_ARCHIVE.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/CONTRIBUTING.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/LICENSE +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/README.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/benches/circular_filament.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/benches/linear_filament.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/build_docs.sh +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/py.typed +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/solenoid_stress/__init__.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/solenoid_stress/solenoid_1d.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/solenoid_stress/solenoid_handcalc.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/cfsem/types.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/assets/logo.svg +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/index.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/javascripts/mathjax.js +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/example_outputs/.placeholder +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/examples.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/filament.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/flux_density.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/force.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/grad_shafranov.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/inductance.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/math.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/solenoid_stress.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/types.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/python/vector_potential.md +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/requirements.txt +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/docs/stylesheets/extra.css +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/examples/helmholtz.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/katex-header.html +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/mkdocs.yml +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/src/lib.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/src/mesh.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/src/physics/biotsavart.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/src/physics/gradshafranov.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/src/physics/linear_filament.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/src/physics/mesh_filament.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/src/testing.rs +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/test/__init__.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/test/test_examples.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/test/test_filaments.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/test/test_funcs.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/test/test_gradshafranov.py +0 -0
- {cfsem-2.6.0 → cfsem-3.0.0}/test/test_math.py +0 -0
- {cfsem-2.6.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,33 @@
|
|
|
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
|
|
26
|
+
|
|
27
|
+
## 2.7.0 2025-10-15
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
* Add method for calculating self-inductance for coaxial collection of ideal circular filaments.
|
|
4
31
|
|
|
5
32
|
## 2.6.0 2025-10-15
|
|
6
33
|
|
|
@@ -30,3 +57,7 @@ body force density calcs.
|
|
|
30
57
|
* Python
|
|
31
58
|
* Update dep versions
|
|
32
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);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Quasi-steady electromagnetics calcs"""
|
|
2
2
|
|
|
3
|
+
from typing import Literal, Union
|
|
4
|
+
|
|
3
5
|
import numpy as np
|
|
4
6
|
from interpn import MulticubicRectilinear
|
|
5
7
|
from numpy.typing import NDArray
|
|
@@ -21,6 +23,7 @@ from cfsem.bindings import (
|
|
|
21
23
|
rotate_filaments_about_path,
|
|
22
24
|
vector_potential_circular_filament,
|
|
23
25
|
vector_potential_linear_filament,
|
|
26
|
+
vector_potential_dipole,
|
|
24
27
|
)
|
|
25
28
|
from cfsem.types import Array3xN
|
|
26
29
|
|
|
@@ -42,6 +45,7 @@ __all__ = [
|
|
|
42
45
|
"filament_helix_path",
|
|
43
46
|
"inductance_piecewise_linear_filaments",
|
|
44
47
|
"self_inductance_piecewise_linear_filaments",
|
|
48
|
+
"self_inductance_axisymmetric_coil",
|
|
45
49
|
"mutual_inductance_piecewise_linear_filaments",
|
|
46
50
|
"flux_density_ideal_solenoid",
|
|
47
51
|
"self_inductance_lyle6",
|
|
@@ -59,6 +63,7 @@ __all__ = [
|
|
|
59
63
|
"flux_density_circular_filament_cartesian",
|
|
60
64
|
"mutual_inductance_circular_to_linear",
|
|
61
65
|
"flux_density_dipole",
|
|
66
|
+
"vector_potential_dipole",
|
|
62
67
|
"body_force_density_circular_filament_cartesian",
|
|
63
68
|
"body_force_density_linear_filament",
|
|
64
69
|
]
|
|
@@ -287,6 +292,103 @@ def mutual_inductance_of_circular_filaments(rzn1: NDArray, rzn2: NDArray, par: b
|
|
|
287
292
|
return m # [H]
|
|
288
293
|
|
|
289
294
|
|
|
295
|
+
def self_inductance_axisymmetric_coil(
|
|
296
|
+
f: NDArray,
|
|
297
|
+
section_kind: Literal["rectangular", "circular", "annular"],
|
|
298
|
+
section_size: Union[tuple[float, float], float],
|
|
299
|
+
par: bool = True,
|
|
300
|
+
) -> float:
|
|
301
|
+
"""
|
|
302
|
+
Self-inductance of a coaxial collection of ideal circular filaments.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
f: 3 x N array of filament definitions like (r [m], z [m], n []) coordinates and number of turns
|
|
306
|
+
section_kind: Kind of conductor cross-section to use for self-inductance correction
|
|
307
|
+
section_size: Size of the conductor cross-section
|
|
308
|
+
* For "rectangular", a tuple (width [m], height [m])
|
|
309
|
+
* For "circular", a single float (radius [m])
|
|
310
|
+
* For "annular", a tuple (inner radius [m], outer radius [m])
|
|
311
|
+
|
|
312
|
+
Returns:
|
|
313
|
+
float: Self-inductance [H]
|
|
314
|
+
"""
|
|
315
|
+
|
|
316
|
+
# Validate valid section_kind and section_size
|
|
317
|
+
assert section_kind in ("rectangular", "circular", "annular"), (
|
|
318
|
+
"section_kind must be one of 'rectangular', 'circular', or 'annular'"
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
if section_kind == "rectangular":
|
|
322
|
+
assert isinstance(section_size, tuple), (
|
|
323
|
+
"For rectangular section, section_size must be a tuple (conductor width and height)"
|
|
324
|
+
)
|
|
325
|
+
assert len(section_size) == 2, "For rectangular section, section_size must be a tuple of length 2"
|
|
326
|
+
assert section_size[0] > 0.0 and section_size[1] > 0.0, (
|
|
327
|
+
"Conductor section sizes (width and height) must be positive"
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
if section_kind == "circular":
|
|
331
|
+
assert isinstance(section_size, float) and section_size > 0.0, (
|
|
332
|
+
"For circular section, section size must be a non-negative float (conductor radius)"
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
if section_kind == "annular":
|
|
336
|
+
assert isinstance(section_size, tuple) and len(section_size) == 2, (
|
|
337
|
+
"For annular section, section_size must be a tuple (inner and outer conductor radius)"
|
|
338
|
+
)
|
|
339
|
+
assert section_size[0] >= 0.0 and section_size[1] > section_size[0], (
|
|
340
|
+
"For annular section, "
|
|
341
|
+
"inner radius must be non-negative and outer radius must be larger than inner radius"
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
m = 0.0
|
|
345
|
+
rs, zs, ns = f
|
|
346
|
+
|
|
347
|
+
# Iterate over filaments
|
|
348
|
+
for i in range(f.shape[1]):
|
|
349
|
+
# Get mutual inductance of i-th filament to all other filaments
|
|
350
|
+
m_contribs = ns * flux_circular_filament(ns[i], rs[i], zs[i], rs, zs, par)
|
|
351
|
+
|
|
352
|
+
# Get self-inductance of i-th filament
|
|
353
|
+
if section_kind == "rectangular":
|
|
354
|
+
assert isinstance(section_size, tuple)
|
|
355
|
+
m_self = self_inductance_lyle6(
|
|
356
|
+
r=rs[i], # coil center radius
|
|
357
|
+
dr=section_size[0], # width of the rectangular conductor section
|
|
358
|
+
dz=section_size[1], # height of the rectangular conductor section
|
|
359
|
+
n=ns[i],
|
|
360
|
+
)
|
|
361
|
+
elif section_kind == "circular":
|
|
362
|
+
# Wien formula for circular cross-section
|
|
363
|
+
assert isinstance(section_size, float)
|
|
364
|
+
m_self = (
|
|
365
|
+
self_inductance_circular_ring_wien(
|
|
366
|
+
major_radius=rs[i], # coil center radius
|
|
367
|
+
minor_radius=np.atleast_1d(section_size),
|
|
368
|
+
)
|
|
369
|
+
* ns[i] ** 2
|
|
370
|
+
)
|
|
371
|
+
m_self = float(m_self.item()) # Convert to float
|
|
372
|
+
|
|
373
|
+
elif section_kind == "annular":
|
|
374
|
+
# Wien formula for annular cross-section
|
|
375
|
+
assert isinstance(section_size, tuple)
|
|
376
|
+
m_self = (
|
|
377
|
+
self_inductance_annular_ring(
|
|
378
|
+
r=rs[i], # major radius
|
|
379
|
+
a=section_size[0], # inner minor radius (tube inside radius)
|
|
380
|
+
b=section_size[1], # outer minor radius (tube outside radius)
|
|
381
|
+
)
|
|
382
|
+
* ns[i] ** 2
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
# Replace self-pairing with self-inductance
|
|
386
|
+
m_contribs[i] = m_self
|
|
387
|
+
m += np.sum(m_contribs)
|
|
388
|
+
|
|
389
|
+
return m # [H]
|
|
390
|
+
|
|
391
|
+
|
|
290
392
|
def mutual_inductance_of_cylindrical_coils(f1: NDArray, f2: NDArray, par: bool = True) -> float:
|
|
291
393
|
"""
|
|
292
394
|
Analytical mutual inductance between two coaxial collections of ideal filaments.
|
|
@@ -337,10 +439,10 @@ def filament_coil(r: float, z: float, w: float, h: float, nt: float, nr: int, nz
|
|
|
337
439
|
rmesh, zmesh = np.meshgrid(rs, zs, indexing="ij") # [m]
|
|
338
440
|
|
|
339
441
|
# Number of turns attributed to each point is not necessarily an integer
|
|
340
|
-
n = np.full_like(rmesh.
|
|
442
|
+
n = np.full_like(rmesh.ravel(), float(nt) / (nr * nz))
|
|
341
443
|
|
|
342
444
|
# Pack filament locations and number of turns into an array together
|
|
343
|
-
filaments = np.dstack([rmesh.
|
|
445
|
+
filaments = np.dstack([rmesh.ravel(), zmesh.ravel(), n]).reshape(nr * nz, 3)
|
|
344
446
|
|
|
345
447
|
return filaments # [m], [m], [dimensionless]
|
|
346
448
|
|
|
@@ -442,7 +544,7 @@ def self_inductance_distributed_axisymmetric_conductor(
|
|
|
442
544
|
# Set up
|
|
443
545
|
nr = rgrid.size
|
|
444
546
|
nz = zgrid.size
|
|
445
|
-
psi_interpolator = MulticubicRectilinear.new([rgrid, zgrid], psi_part.
|
|
547
|
+
psi_interpolator = MulticubicRectilinear.new([rgrid, zgrid], psi_part.ravel())
|
|
446
548
|
|
|
447
549
|
# Same-length diffs assuming last grid cell is the same size
|
|
448
550
|
# as the previous one. In general the conductor can't touch the
|