cfsem 2.7.0__tar.gz → 3.0.1__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.
Files changed (74) hide show
  1. cfsem-3.0.1/.cargo/config.toml +2 -0
  2. {cfsem-2.7.0 → cfsem-3.0.1}/.github/workflows/release_python.yml +5 -7
  3. {cfsem-2.7.0 → cfsem-3.0.1}/.github/workflows/release_rust.yml +2 -3
  4. {cfsem-2.7.0 → cfsem-3.0.1}/.github/workflows/test_python.yml +3 -2
  5. {cfsem-2.7.0 → cfsem-3.0.1}/.github/workflows/test_rust.yml +1 -0
  6. cfsem-3.0.1/CHANGELOG.md +79 -0
  7. {cfsem-2.7.0 → cfsem-3.0.1}/Cargo.lock +21 -41
  8. {cfsem-2.7.0 → cfsem-3.0.1}/Cargo.toml +10 -6
  9. {cfsem-2.7.0 → cfsem-3.0.1}/PKG-INFO +3 -3
  10. {cfsem-2.7.0 → cfsem-3.0.1}/benches/circular_filament.rs +2 -0
  11. {cfsem-2.7.0 → cfsem-3.0.1}/benches/linear_filament.rs +2 -0
  12. cfsem-3.0.1/benches/point_source.rs +180 -0
  13. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/__init__.py +7 -5
  14. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/bindings.py +47 -9
  15. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/solenoid_stress/solenoid_1d.py +2 -1
  16. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/solenoid_stress/thick_wall_cylinder_handcalc.py +1 -3
  17. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/types.py +1 -3
  18. {cfsem-2.7.0 → cfsem-3.0.1}/pyproject.toml +3 -6
  19. {cfsem-2.7.0 → cfsem-3.0.1}/src/math.rs +35 -1
  20. {cfsem-2.7.0 → cfsem-3.0.1}/src/physics/circular_filament.rs +6 -5
  21. {cfsem-2.7.0 → cfsem-3.0.1}/src/physics/mod.rs +1 -0
  22. cfsem-3.0.1/src/physics/point_source.rs +458 -0
  23. cfsem-3.0.1/src/physics/volumetric.rs +100 -0
  24. {cfsem-2.7.0 → cfsem-3.0.1}/src/python.rs +61 -1
  25. {cfsem-2.7.0 → cfsem-3.0.1}/test/test_electromagnetics.py +96 -84
  26. {cfsem-2.7.0 → cfsem-3.0.1}/uv.lock +52 -596
  27. cfsem-2.7.0/.cargo/config.toml +0 -2
  28. cfsem-2.7.0/CHANGELOG.md +0 -37
  29. cfsem-2.7.0/src/physics/point_source.rs +0 -205
  30. {cfsem-2.7.0 → cfsem-3.0.1}/.gitignore +0 -0
  31. {cfsem-2.7.0 → cfsem-3.0.1}/.readthedocs.yml +0 -0
  32. {cfsem-2.7.0 → cfsem-3.0.1}/CHANGELOG_PYTHON_ARCHIVE.md +0 -0
  33. {cfsem-2.7.0 → cfsem-3.0.1}/CHANGELOG_RUST_ARCHIVE.md +0 -0
  34. {cfsem-2.7.0 → cfsem-3.0.1}/CONTRIBUTING.md +0 -0
  35. {cfsem-2.7.0 → cfsem-3.0.1}/LICENSE +0 -0
  36. {cfsem-2.7.0 → cfsem-3.0.1}/README.md +0 -0
  37. {cfsem-2.7.0 → cfsem-3.0.1}/build_docs.sh +0 -0
  38. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/py.typed +0 -0
  39. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/solenoid_stress/__init__.py +0 -0
  40. {cfsem-2.7.0 → cfsem-3.0.1}/cfsem/solenoid_stress/solenoid_handcalc.py +0 -0
  41. {cfsem-2.7.0 → cfsem-3.0.1}/docs/assets/logo.svg +0 -0
  42. {cfsem-2.7.0 → cfsem-3.0.1}/docs/index.md +0 -0
  43. {cfsem-2.7.0 → cfsem-3.0.1}/docs/javascripts/mathjax.js +0 -0
  44. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/example_outputs/.placeholder +0 -0
  45. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/examples.md +0 -0
  46. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/filament.md +0 -0
  47. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/flux_density.md +0 -0
  48. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/force.md +0 -0
  49. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/grad_shafranov.md +0 -0
  50. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/inductance.md +0 -0
  51. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/math.md +0 -0
  52. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/solenoid_stress.md +0 -0
  53. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/types.md +0 -0
  54. {cfsem-2.7.0 → cfsem-3.0.1}/docs/python/vector_potential.md +0 -0
  55. {cfsem-2.7.0 → cfsem-3.0.1}/docs/requirements.txt +0 -0
  56. {cfsem-2.7.0 → cfsem-3.0.1}/docs/stylesheets/extra.css +0 -0
  57. {cfsem-2.7.0 → cfsem-3.0.1}/examples/helmholtz.py +0 -0
  58. {cfsem-2.7.0 → cfsem-3.0.1}/examples/inductance.py +0 -0
  59. {cfsem-2.7.0 → cfsem-3.0.1}/katex-header.html +0 -0
  60. {cfsem-2.7.0 → cfsem-3.0.1}/mkdocs.yml +0 -0
  61. {cfsem-2.7.0 → cfsem-3.0.1}/src/lib.rs +0 -0
  62. {cfsem-2.7.0 → cfsem-3.0.1}/src/mesh.rs +0 -0
  63. {cfsem-2.7.0 → cfsem-3.0.1}/src/physics/biotsavart.rs +0 -0
  64. {cfsem-2.7.0 → cfsem-3.0.1}/src/physics/gradshafranov.rs +0 -0
  65. {cfsem-2.7.0 → cfsem-3.0.1}/src/physics/linear_filament.rs +0 -0
  66. {cfsem-2.7.0 → cfsem-3.0.1}/src/physics/mesh_filament.rs +0 -0
  67. {cfsem-2.7.0 → cfsem-3.0.1}/src/testing.rs +0 -0
  68. {cfsem-2.7.0 → cfsem-3.0.1}/test/__init__.py +0 -0
  69. {cfsem-2.7.0 → cfsem-3.0.1}/test/test_examples.py +0 -0
  70. {cfsem-2.7.0 → cfsem-3.0.1}/test/test_filaments.py +0 -0
  71. {cfsem-2.7.0 → cfsem-3.0.1}/test/test_funcs.py +0 -0
  72. {cfsem-2.7.0 → cfsem-3.0.1}/test/test_gradshafranov.py +0 -0
  73. {cfsem-2.7.0 → cfsem-3.0.1}/test/test_math.py +0 -0
  74. {cfsem-2.7.0 → cfsem-3.0.1}/test/test_solenoid_stress.py +0 -0
@@ -0,0 +1,2 @@
1
+ [target.'cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "x64"))']
2
+ rustflags = ["-C", "target-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b,+avx,+avx2,+fma,+bmi1,+bmi2,+lzcnt,+pclmulqdq,+movbe"]
@@ -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:
@@ -23,7 +20,7 @@ jobs:
23
20
  runs-on: ${{ matrix.platform.runner }}
24
21
  strategy:
25
22
  matrix:
26
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
23
+ python-version: ['3.13']
27
24
  platform:
28
25
  - runner: ubuntu-22.04
29
26
  target: x86_64
@@ -59,7 +56,7 @@ jobs:
59
56
  runs-on: ${{ matrix.platform.runner }}
60
57
  strategy:
61
58
  matrix:
62
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
59
+ python-version: ['3.13']
63
60
  platform:
64
61
  - runner: ubuntu-22.04
65
62
  target: x86_64
@@ -91,7 +88,7 @@ jobs:
91
88
  runs-on: ${{ matrix.platform.runner }}
92
89
  strategy:
93
90
  matrix:
94
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
91
+ python-version: ['3.13']
95
92
  platform:
96
93
  - runner: windows-latest
97
94
  target: x64
@@ -119,7 +116,7 @@ jobs:
119
116
  runs-on: ${{ matrix.platform.runner }}
120
117
  strategy:
121
118
  matrix:
122
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
119
+ python-version: ['3.13']
123
120
  platform:
124
121
  - runner: macos-13
125
122
  target: x86_64
@@ -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
- push:
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
@@ -19,7 +19,7 @@ jobs:
19
19
  timeout-minutes: 15
20
20
  strategy:
21
21
  matrix:
22
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
22
+ python-version: ['3.10', '3.11', '3.12', '3.13']
23
23
 
24
24
  steps:
25
25
 
@@ -45,7 +45,8 @@ jobs:
45
45
 
46
46
  # Python lint, test, and coverage
47
47
  uv run --locked ruff check ./cfsem
48
- uv run --locked pyright ./cfsem --pythonversion 3.11
48
+ uv run --locked ruff format ./cfsem --check
49
+ uv run --locked pyright ./cfsem --pythonversion 3.10
49
50
  uv run --locked coverage run --source=./cfsem -m pytest ./test/
50
51
  uv run --locked coverage report
51
52
 
@@ -6,6 +6,7 @@ on:
6
6
  push:
7
7
  branches: [ "main", "develop", "release" ]
8
8
  workflow_call:
9
+ workflow_dispatch:
9
10
 
10
11
  env:
11
12
  CARGO_TERM_COLOR: always
@@ -0,0 +1,79 @@
1
+ # Changelog
2
+
3
+ ## 3.0.1 2025-11-05
4
+
5
+ ### Changed
6
+
7
+ * Rust
8
+ * Improve performance of dipole calcs
9
+ * Now >1Gelem/s throughput including magnetized sphere fallback and nan clipping
10
+ * Update benchmarks to use latest version of criterion
11
+ * Python
12
+ * Use latest rust backend with improved dipole calc perf
13
+ * Eliminate duplicate wheel builds during deployment
14
+ * Maturin now builds for all supported python versions automatically in the same job;
15
+ matrix on python versions is no longer necessary
16
+ * Later, this can be further reduced to single wheels by building for a stable abi3 target
17
+ * Remove support for python 3.9 (leaving long term support)
18
+
19
+ ## 3.0.0 2025-10-29
20
+
21
+ ### Added
22
+
23
+ * Rust
24
+ * Add methods for vector potential of a dipole in `physics::point_source` and `python.rs` bindings
25
+ * Add `physics::volumetric` module with methods for fields inside a uniformly magnetized sphere
26
+ * Add `math::{clip_nan, switch_float}` functions for branchless-in-assembly float selection operations
27
+ * Python
28
+ * Add `vector_potential_dipole` function
29
+ * Add optional sphere radius input for dipole flux density
30
+
31
+ ### Changed
32
+
33
+ * Rust
34
+ * !Require sphere radius input for dipole flux density
35
+ * Update dependencies
36
+ * Use more codegen units and don't do LTO for debug builds
37
+ * Use more mul_add in flux_circular_filament
38
+ * Use multiplication instead of pow in dipole calcs
39
+ * Python
40
+ * !Enable more instruction sets for x86 processors
41
+ * Replace flatten() with ravel() everywhere to reduce copies
42
+
43
+ ## 2.7.0 2025-10-15
44
+
45
+ ### Added
46
+ * Add method for calculating self-inductance for coaxial collection of ideal circular filaments.
47
+
48
+ ## 2.6.0 2025-10-15
49
+
50
+ Substantial performance improvement for `flux_density_linear_filament` Biot-Savart methods.
51
+ This also improves performance in calculations that use these methods, such as linear filament
52
+ body force density calcs.
53
+
54
+ ### Added
55
+
56
+ * Rust
57
+ * Add `dot3f` and `cross3f` 32-bit float variants
58
+
59
+ ### Changed
60
+
61
+ * Rust
62
+ * Use mixed-precision method for `flux_density_linear_filament_scalar`
63
+ * High-dynamic-range part of the calc is still done using 64-bit floats
64
+ * Low-dynamic-range part of the calc is now done using 32-bit floats
65
+ * _All_ addition operations in 32-bit section are done using
66
+ fused multiply-add operations, usually chained to defer
67
+ roundoff to final operation. As a result, total roundoff error
68
+ accumulated in this section is minimal.
69
+ * Return is upcast back to 64-bit float to support precise summation downstream
70
+ * 1.4-2x speedup without any meaningful loss of precision
71
+ * No change to unit test tolerances needed; unlike an all-32-bit implementation,
72
+ this mixed-precision method passes all the same tests as the 64-bit-only method
73
+ * Python
74
+ * Update dep versions
75
+ * Use latest rust backend version, which includes 1.4-2x speedup for flux_density_linear_filament Biot-Savart calcs
76
+
77
+ ## Earlier Versions
78
+
79
+ 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 = "2.6.0"
67
+ version = "3.0.1"
68
68
  dependencies = [
69
69
  "criterion",
70
70
  "itertools 0.14.0",
@@ -130,25 +130,22 @@ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
130
130
 
131
131
  [[package]]
132
132
  name = "criterion"
133
- version = "0.5.1"
133
+ version = "0.7.0"
134
134
  source = "registry+https://github.com/rust-lang/crates.io-index"
135
- checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f"
135
+ checksum = "e1c047a62b0cc3e145fa84415a3191f628e980b194c2755aa12300a4e6cbd928"
136
136
  dependencies = [
137
137
  "anes",
138
138
  "cast",
139
139
  "ciborium",
140
140
  "clap",
141
141
  "criterion-plot",
142
- "is-terminal",
143
- "itertools 0.10.5",
142
+ "itertools 0.13.0",
144
143
  "num-traits",
145
- "once_cell",
146
144
  "oorandom",
147
145
  "plotters",
148
146
  "rayon",
149
147
  "regex",
150
148
  "serde",
151
- "serde_derive",
152
149
  "serde_json",
153
150
  "tinytemplate",
154
151
  "walkdir",
@@ -156,12 +153,12 @@ dependencies = [
156
153
 
157
154
  [[package]]
158
155
  name = "criterion-plot"
159
- version = "0.5.0"
156
+ version = "0.6.0"
160
157
  source = "registry+https://github.com/rust-lang/crates.io-index"
161
- checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1"
158
+ checksum = "9b1bcc0dc7dfae599d84ad0b1a55f80cde8af3725da8313b528da95ef783e338"
162
159
  dependencies = [
163
160
  "cast",
164
- "itertools 0.10.5",
161
+ "itertools 0.13.0",
165
162
  ]
166
163
 
167
164
  [[package]]
@@ -313,34 +310,17 @@ version = "0.5.0"
313
310
  source = "registry+https://github.com/rust-lang/crates.io-index"
314
311
  checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
315
312
 
316
- [[package]]
317
- name = "hermit-abi"
318
- version = "0.5.2"
319
- source = "registry+https://github.com/rust-lang/crates.io-index"
320
- checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
321
-
322
313
  [[package]]
323
314
  name = "indoc"
324
315
  version = "2.0.6"
325
316
  source = "registry+https://github.com/rust-lang/crates.io-index"
326
317
  checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
327
318
 
328
- [[package]]
329
- name = "is-terminal"
330
- version = "0.4.16"
331
- source = "registry+https://github.com/rust-lang/crates.io-index"
332
- checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
333
- dependencies = [
334
- "hermit-abi",
335
- "libc",
336
- "windows-sys",
337
- ]
338
-
339
319
  [[package]]
340
320
  name = "itertools"
341
- version = "0.10.5"
321
+ version = "0.13.0"
342
322
  source = "registry+https://github.com/rust-lang/crates.io-index"
343
- checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
323
+ checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
344
324
  dependencies = [
345
325
  "either",
346
326
  ]
@@ -522,9 +502,9 @@ dependencies = [
522
502
 
523
503
  [[package]]
524
504
  name = "numpy"
525
- version = "0.26.0"
505
+ version = "0.27.0"
526
506
  source = "registry+https://github.com/rust-lang/crates.io-index"
527
- checksum = "9b2dba356160b54f5371b550575b78130a54718b4c6e46b3f33a6da74a27e78b"
507
+ checksum = "0fa24ffc88cf9d43f7269d6b6a0d0a00010924a8cc90604a21ef9c433b66998d"
528
508
  dependencies = [
529
509
  "libc",
530
510
  "ndarray",
@@ -608,9 +588,9 @@ dependencies = [
608
588
 
609
589
  [[package]]
610
590
  name = "pyo3"
611
- version = "0.26.0"
591
+ version = "0.27.1"
612
592
  source = "registry+https://github.com/rust-lang/crates.io-index"
613
- checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383"
593
+ checksum = "37a6df7eab65fc7bee654a421404947e10a0f7085b6951bf2ea395f4659fb0cf"
614
594
  dependencies = [
615
595
  "indoc",
616
596
  "libc",
@@ -625,18 +605,18 @@ dependencies = [
625
605
 
626
606
  [[package]]
627
607
  name = "pyo3-build-config"
628
- version = "0.26.0"
608
+ version = "0.27.1"
629
609
  source = "registry+https://github.com/rust-lang/crates.io-index"
630
- checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f"
610
+ checksum = "f77d387774f6f6eec64a004eac0ed525aab7fa1966d94b42f743797b3e395afb"
631
611
  dependencies = [
632
612
  "target-lexicon",
633
613
  ]
634
614
 
635
615
  [[package]]
636
616
  name = "pyo3-ffi"
637
- version = "0.26.0"
617
+ version = "0.27.1"
638
618
  source = "registry+https://github.com/rust-lang/crates.io-index"
639
- checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105"
619
+ checksum = "2dd13844a4242793e02df3e2ec093f540d948299a6a77ea9ce7afd8623f542be"
640
620
  dependencies = [
641
621
  "libc",
642
622
  "pyo3-build-config",
@@ -644,9 +624,9 @@ dependencies = [
644
624
 
645
625
  [[package]]
646
626
  name = "pyo3-macros"
647
- version = "0.26.0"
627
+ version = "0.27.1"
648
628
  source = "registry+https://github.com/rust-lang/crates.io-index"
649
- checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded"
629
+ checksum = "eaf8f9f1108270b90d3676b8679586385430e5c0bb78bb5f043f95499c821a71"
650
630
  dependencies = [
651
631
  "proc-macro2",
652
632
  "pyo3-macros-backend",
@@ -656,9 +636,9 @@ dependencies = [
656
636
 
657
637
  [[package]]
658
638
  name = "pyo3-macros-backend"
659
- version = "0.26.0"
639
+ version = "0.27.1"
660
640
  source = "registry+https://github.com/rust-lang/crates.io-index"
661
- checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf"
641
+ checksum = "70a3b2274450ba5288bc9b8c1b69ff569d1d61189d4bff38f8d22e03d17f932b"
662
642
  dependencies = [
663
643
  "heck",
664
644
  "proc-macro2",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "cfsem"
3
- version = "2.6.0"
3
+ version = "3.0.1"
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.26.0", features=["extension-module"], optional=true }
19
- numpy = { version="0.26.0", optional=true } # This must match pyo3 version!
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"
@@ -24,7 +24,7 @@ libm = "^0.2"
24
24
  num-traits = { version = "0.2.19", features = ["libm"] }
25
25
 
26
26
  [dev-dependencies]
27
- criterion = "0.5.1"
27
+ criterion = "0.7.0"
28
28
  itertools = "0.14.0"
29
29
 
30
30
  [profile.release]
@@ -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 = 1
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: 2.7.0
3
+ Version: 3.0.1
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.1
8
+ Requires-Dist: interpn[pydantic]>=0.7
9
9
  Requires-Dist: findiff>=0.12.1
10
10
  Requires-Dist: pydantic>=2
11
11
  Requires-Dist: pydantic-numpy>=6
@@ -24,4 +24,4 @@ Summary: Quasi-steady electromagnetics including filamentized approximations, Bi
24
24
  Home-Page: https://github.com/cfs-energy/cfsem-py
25
25
  Author-email: Commonwealth Fusion Systems <jlogan@cfs.energy>
26
26
  License-Expression: MIT
27
- Requires-Python: >=3.9, <3.14
27
+ Requires-Python: >=3.10, <3.14
@@ -10,6 +10,8 @@ use cfsem::physics::{
10
10
  use criterion::*;
11
11
  use std::time::Duration;
12
12
 
13
+ use std::hint::black_box;
14
+
13
15
  fn bench_flux_circular_filament(c: &mut Criterion) {
14
16
  let mut group = c.benchmark_group("Poloidal Flux of a Circular Filament");
15
17
  group.sample_size(10);
@@ -7,6 +7,8 @@ use cfsem::physics::linear_filament::{
7
7
  use criterion::*;
8
8
  use std::time::Duration;
9
9
 
10
+ use std::hint::black_box;
11
+
10
12
  fn bench_flux_density_linear_filament(c: &mut Criterion) {
11
13
  let mut group = c.benchmark_group("Flux Density of Linear Filaments");
12
14
  group.sample_size(10);
@@ -0,0 +1,180 @@
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
+ use std::hint::black_box;
11
+
12
+ fn bench_flux_density_dipole(c: &mut Criterion) {
13
+ let mut group = c.benchmark_group("Flux Density of a Magnetic Dipole");
14
+ group.sample_size(10);
15
+ group.measurement_time(Duration::from_secs(5));
16
+
17
+ for ndipoles in [1, 1000] {
18
+ for nobs in [10, 10_000] {
19
+ let locx = vec![0.01_f64; ndipoles];
20
+ let locy = vec![0.02_f64; ndipoles];
21
+ let locz = vec![0.03_f64; ndipoles];
22
+
23
+ let momx = vec![0.17_f64; ndipoles];
24
+ let momy = vec![0.077_f64; ndipoles];
25
+ let momz = vec![1.0_f64; ndipoles];
26
+
27
+ let outer_radius = vec![0.001_f64; ndipoles];
28
+
29
+ let obsx = vec![0.7_f64; nobs];
30
+ let obsy = vec![-0.4_f64; nobs];
31
+ let obsz = vec![0.9_f64; nobs];
32
+
33
+ let mut outx = vec![0.0_f64; nobs];
34
+ let mut outy = vec![0.0_f64; nobs];
35
+ let mut outz = vec![0.0_f64; nobs];
36
+
37
+ let ntot = nobs * ndipoles;
38
+ group.throughput(Throughput::Elements(ntot as u64));
39
+
40
+ group.bench_with_input(
41
+ BenchmarkId::new(
42
+ format!(
43
+ "Flux Density of a Magnetic Dipole\n{} src × {} obs",
44
+ ndipoles, nobs
45
+ ),
46
+ ntot,
47
+ ),
48
+ &ntot,
49
+ |b, &_| {
50
+ b.iter(|| {
51
+ black_box(
52
+ flux_density_dipole(
53
+ (&locx, &locy, &locz),
54
+ (&momx, &momy, &momz),
55
+ &outer_radius,
56
+ (&obsx, &obsy, &obsz),
57
+ (&mut outx, &mut outy, &mut outz),
58
+ )
59
+ .unwrap(),
60
+ )
61
+ });
62
+ },
63
+ );
64
+
65
+ group.bench_with_input(
66
+ BenchmarkId::new(
67
+ format!(
68
+ "Flux Density of a Magnetic Dipole, Parallel\n{} src × {} obs",
69
+ ndipoles, nobs
70
+ ),
71
+ ntot,
72
+ ),
73
+ &ntot,
74
+ |b, &_| {
75
+ b.iter(|| {
76
+ black_box(
77
+ flux_density_dipole_par(
78
+ (&locx, &locy, &locz),
79
+ (&momx, &momy, &momz),
80
+ &outer_radius,
81
+ (&obsx, &obsy, &obsz),
82
+ (&mut outx, &mut outy, &mut outz),
83
+ )
84
+ .unwrap(),
85
+ )
86
+ });
87
+ },
88
+ );
89
+ }
90
+ }
91
+
92
+ group.finish();
93
+ }
94
+
95
+ fn bench_vector_potential_dipole(c: &mut Criterion) {
96
+ let mut group = c.benchmark_group("Vector Potential of a Magnetic Dipole");
97
+ group.sample_size(10);
98
+ group.measurement_time(Duration::from_secs(5));
99
+
100
+ for ndipoles in [1, 1000] {
101
+ for nobs in [10, 10_000] {
102
+ let locx = vec![0.01_f64; ndipoles];
103
+ let locy = vec![0.02_f64; ndipoles];
104
+ let locz = vec![0.03_f64; ndipoles];
105
+
106
+ let momx = vec![0.17_f64; ndipoles];
107
+ let momy = vec![0.077_f64; ndipoles];
108
+ let momz = vec![1.0_f64; ndipoles];
109
+
110
+ let outer_radius = vec![0.001_f64; ndipoles];
111
+
112
+ let obsx = vec![0.7_f64; nobs];
113
+ let obsy = vec![-0.4_f64; nobs];
114
+ let obsz = vec![0.9_f64; nobs];
115
+
116
+ let mut outx = vec![0.0_f64; nobs];
117
+ let mut outy = vec![0.0_f64; nobs];
118
+ let mut outz = vec![0.0_f64; nobs];
119
+
120
+ let ntot = nobs * ndipoles;
121
+ group.throughput(Throughput::Elements(ntot as u64));
122
+
123
+ group.bench_with_input(
124
+ BenchmarkId::new(
125
+ format!(
126
+ "Vector Potential of a Magnetic Dipole\n{} src × {} obs",
127
+ ndipoles, nobs
128
+ ),
129
+ ntot,
130
+ ),
131
+ &ntot,
132
+ |b, &_| {
133
+ b.iter(|| {
134
+ black_box(
135
+ vector_potential_dipole(
136
+ (&locx, &locy, &locz),
137
+ (&momx, &momy, &momz),
138
+ &outer_radius,
139
+ (&obsx, &obsy, &obsz),
140
+ (&mut outx, &mut outy, &mut outz),
141
+ )
142
+ .unwrap(),
143
+ )
144
+ });
145
+ },
146
+ );
147
+
148
+ group.bench_with_input(
149
+ BenchmarkId::new(
150
+ format!(
151
+ "Vector Potential of a Magnetic Dipole, Parallel\n{} src × {} obs",
152
+ ndipoles, nobs
153
+ ),
154
+ ntot,
155
+ ),
156
+ &ntot,
157
+ |b, &_| {
158
+ b.iter(|| {
159
+ black_box(
160
+ vector_potential_dipole_par(
161
+ (&locx, &locy, &locz),
162
+ (&momx, &momy, &momz),
163
+ &outer_radius,
164
+ (&obsx, &obsy, &obsz),
165
+ (&mut outx, &mut outy, &mut outz),
166
+ )
167
+ .unwrap(),
168
+ )
169
+ });
170
+ },
171
+ );
172
+ }
173
+ }
174
+
175
+ group.finish();
176
+ }
177
+
178
+ criterion_group!(group_flux_density, bench_flux_density_dipole);
179
+ criterion_group!(group_vector_potential, bench_vector_potential_dipole);
180
+ criterion_main!(group_flux_density, group_vector_potential);
@@ -1,6 +1,6 @@
1
1
  """Quasi-steady electromagnetics calcs"""
2
2
 
3
- from typing import Literal, Union
3
+ from typing import Literal
4
4
 
5
5
  import numpy as np
6
6
  from interpn import MulticubicRectilinear
@@ -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
  ]
@@ -293,7 +295,7 @@ def mutual_inductance_of_circular_filaments(rzn1: NDArray, rzn2: NDArray, par: b
293
295
  def self_inductance_axisymmetric_coil(
294
296
  f: NDArray,
295
297
  section_kind: Literal["rectangular", "circular", "annular"],
296
- section_size: Union[tuple[float, float], float],
298
+ section_size: tuple[float, float] | float,
297
299
  par: bool = True,
298
300
  ) -> float:
299
301
  """
@@ -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.flatten(), float(nt) / (nr * nz))
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.flatten(), zmesh.flatten(), n]).reshape(nr * nz, 3)
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.flatten())
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