cfsem 3.0.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 (71) hide show
  1. {cfsem-3.0.0 → cfsem-3.0.1}/.github/workflows/release_python.yml +4 -4
  2. {cfsem-3.0.0 → cfsem-3.0.1}/.github/workflows/test_python.yml +2 -2
  3. {cfsem-3.0.0 → cfsem-3.0.1}/CHANGELOG.md +16 -0
  4. {cfsem-3.0.0 → cfsem-3.0.1}/Cargo.lock +9 -29
  5. {cfsem-3.0.0 → cfsem-3.0.1}/Cargo.toml +2 -2
  6. {cfsem-3.0.0 → cfsem-3.0.1}/PKG-INFO +3 -3
  7. {cfsem-3.0.0 → cfsem-3.0.1}/benches/circular_filament.rs +2 -0
  8. {cfsem-3.0.0 → cfsem-3.0.1}/benches/linear_filament.rs +2 -0
  9. {cfsem-3.0.0 → cfsem-3.0.1}/benches/point_source.rs +8 -6
  10. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/__init__.py +2 -2
  11. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/bindings.py +2 -4
  12. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/solenoid_stress/solenoid_1d.py +2 -1
  13. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/types.py +1 -3
  14. {cfsem-3.0.0 → cfsem-3.0.1}/pyproject.toml +3 -4
  15. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/point_source.rs +43 -29
  16. {cfsem-3.0.0 → cfsem-3.0.1}/uv.lock +46 -797
  17. {cfsem-3.0.0 → cfsem-3.0.1}/.cargo/config.toml +0 -0
  18. {cfsem-3.0.0 → cfsem-3.0.1}/.github/workflows/release_rust.yml +0 -0
  19. {cfsem-3.0.0 → cfsem-3.0.1}/.github/workflows/test_rust.yml +0 -0
  20. {cfsem-3.0.0 → cfsem-3.0.1}/.gitignore +0 -0
  21. {cfsem-3.0.0 → cfsem-3.0.1}/.readthedocs.yml +0 -0
  22. {cfsem-3.0.0 → cfsem-3.0.1}/CHANGELOG_PYTHON_ARCHIVE.md +0 -0
  23. {cfsem-3.0.0 → cfsem-3.0.1}/CHANGELOG_RUST_ARCHIVE.md +0 -0
  24. {cfsem-3.0.0 → cfsem-3.0.1}/CONTRIBUTING.md +0 -0
  25. {cfsem-3.0.0 → cfsem-3.0.1}/LICENSE +0 -0
  26. {cfsem-3.0.0 → cfsem-3.0.1}/README.md +0 -0
  27. {cfsem-3.0.0 → cfsem-3.0.1}/build_docs.sh +0 -0
  28. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/py.typed +0 -0
  29. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/solenoid_stress/__init__.py +0 -0
  30. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/solenoid_stress/solenoid_handcalc.py +0 -0
  31. {cfsem-3.0.0 → cfsem-3.0.1}/cfsem/solenoid_stress/thick_wall_cylinder_handcalc.py +0 -0
  32. {cfsem-3.0.0 → cfsem-3.0.1}/docs/assets/logo.svg +0 -0
  33. {cfsem-3.0.0 → cfsem-3.0.1}/docs/index.md +0 -0
  34. {cfsem-3.0.0 → cfsem-3.0.1}/docs/javascripts/mathjax.js +0 -0
  35. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/example_outputs/.placeholder +0 -0
  36. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/examples.md +0 -0
  37. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/filament.md +0 -0
  38. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/flux_density.md +0 -0
  39. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/force.md +0 -0
  40. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/grad_shafranov.md +0 -0
  41. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/inductance.md +0 -0
  42. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/math.md +0 -0
  43. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/solenoid_stress.md +0 -0
  44. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/types.md +0 -0
  45. {cfsem-3.0.0 → cfsem-3.0.1}/docs/python/vector_potential.md +0 -0
  46. {cfsem-3.0.0 → cfsem-3.0.1}/docs/requirements.txt +0 -0
  47. {cfsem-3.0.0 → cfsem-3.0.1}/docs/stylesheets/extra.css +0 -0
  48. {cfsem-3.0.0 → cfsem-3.0.1}/examples/helmholtz.py +0 -0
  49. {cfsem-3.0.0 → cfsem-3.0.1}/examples/inductance.py +0 -0
  50. {cfsem-3.0.0 → cfsem-3.0.1}/katex-header.html +0 -0
  51. {cfsem-3.0.0 → cfsem-3.0.1}/mkdocs.yml +0 -0
  52. {cfsem-3.0.0 → cfsem-3.0.1}/src/lib.rs +0 -0
  53. {cfsem-3.0.0 → cfsem-3.0.1}/src/math.rs +0 -0
  54. {cfsem-3.0.0 → cfsem-3.0.1}/src/mesh.rs +0 -0
  55. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/biotsavart.rs +0 -0
  56. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/circular_filament.rs +0 -0
  57. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/gradshafranov.rs +0 -0
  58. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/linear_filament.rs +0 -0
  59. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/mesh_filament.rs +0 -0
  60. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/mod.rs +0 -0
  61. {cfsem-3.0.0 → cfsem-3.0.1}/src/physics/volumetric.rs +0 -0
  62. {cfsem-3.0.0 → cfsem-3.0.1}/src/python.rs +0 -0
  63. {cfsem-3.0.0 → cfsem-3.0.1}/src/testing.rs +0 -0
  64. {cfsem-3.0.0 → cfsem-3.0.1}/test/__init__.py +0 -0
  65. {cfsem-3.0.0 → cfsem-3.0.1}/test/test_electromagnetics.py +0 -0
  66. {cfsem-3.0.0 → cfsem-3.0.1}/test/test_examples.py +0 -0
  67. {cfsem-3.0.0 → cfsem-3.0.1}/test/test_filaments.py +0 -0
  68. {cfsem-3.0.0 → cfsem-3.0.1}/test/test_funcs.py +0 -0
  69. {cfsem-3.0.0 → cfsem-3.0.1}/test/test_gradshafranov.py +0 -0
  70. {cfsem-3.0.0 → cfsem-3.0.1}/test/test_math.py +0 -0
  71. {cfsem-3.0.0 → cfsem-3.0.1}/test/test_solenoid_stress.py +0 -0
@@ -20,7 +20,7 @@ jobs:
20
20
  runs-on: ${{ matrix.platform.runner }}
21
21
  strategy:
22
22
  matrix:
23
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
23
+ python-version: ['3.13']
24
24
  platform:
25
25
  - runner: ubuntu-22.04
26
26
  target: x86_64
@@ -56,7 +56,7 @@ jobs:
56
56
  runs-on: ${{ matrix.platform.runner }}
57
57
  strategy:
58
58
  matrix:
59
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
59
+ python-version: ['3.13']
60
60
  platform:
61
61
  - runner: ubuntu-22.04
62
62
  target: x86_64
@@ -88,7 +88,7 @@ jobs:
88
88
  runs-on: ${{ matrix.platform.runner }}
89
89
  strategy:
90
90
  matrix:
91
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
91
+ python-version: ['3.13']
92
92
  platform:
93
93
  - runner: windows-latest
94
94
  target: x64
@@ -116,7 +116,7 @@ jobs:
116
116
  runs-on: ${{ matrix.platform.runner }}
117
117
  strategy:
118
118
  matrix:
119
- python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
119
+ python-version: ['3.13']
120
120
  platform:
121
121
  - runner: macos-13
122
122
  target: x86_64
@@ -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
 
@@ -46,7 +46,7 @@ jobs:
46
46
  # Python lint, test, and coverage
47
47
  uv run --locked ruff check ./cfsem
48
48
  uv run --locked ruff format ./cfsem --check
49
- uv run --locked pyright ./cfsem --pythonversion 3.11
49
+ uv run --locked pyright ./cfsem --pythonversion 3.10
50
50
  uv run --locked coverage run --source=./cfsem -m pytest ./test/
51
51
  uv run --locked coverage report
52
52
 
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
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
+
3
19
  ## 3.0.0 2025-10-29
4
20
 
5
21
  ### Added
@@ -64,7 +64,7 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
64
64
 
65
65
  [[package]]
66
66
  name = "cfsem"
67
- version = "3.0.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
  ]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "cfsem"
3
- version = "3.0.0"
3
+ version = "3.0.1"
4
4
  edition = "2024"
5
5
  authors = ["Commonwealth Fusion Systems <jlogan@cfs.energy>"]
6
6
  license = "MIT"
@@ -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]
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cfsem
3
- Version: 3.0.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.4
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);
@@ -7,6 +7,8 @@ use cfsem::physics::point_source::{
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_dipole(c: &mut Criterion) {
11
13
  let mut group = c.benchmark_group("Flux Density of a Magnetic Dipole");
12
14
  group.sample_size(10);
@@ -18,11 +20,11 @@ fn bench_flux_density_dipole(c: &mut Criterion) {
18
20
  let locy = vec![0.02_f64; ndipoles];
19
21
  let locz = vec![0.03_f64; ndipoles];
20
22
 
21
- let momx = vec![0.0_f64; ndipoles];
22
- let momy = vec![0.0_f64; ndipoles];
23
+ let momx = vec![0.17_f64; ndipoles];
24
+ let momy = vec![0.077_f64; ndipoles];
23
25
  let momz = vec![1.0_f64; ndipoles];
24
26
 
25
- let outer_radius = vec![0.0_f64; ndipoles];
27
+ let outer_radius = vec![0.001_f64; ndipoles];
26
28
 
27
29
  let obsx = vec![0.7_f64; nobs];
28
30
  let obsy = vec![-0.4_f64; nobs];
@@ -101,11 +103,11 @@ fn bench_vector_potential_dipole(c: &mut Criterion) {
101
103
  let locy = vec![0.02_f64; ndipoles];
102
104
  let locz = vec![0.03_f64; ndipoles];
103
105
 
104
- let momx = vec![0.0_f64; ndipoles];
105
- let momy = vec![0.0_f64; ndipoles];
106
+ let momx = vec![0.17_f64; ndipoles];
107
+ let momy = vec![0.077_f64; ndipoles];
106
108
  let momz = vec![1.0_f64; ndipoles];
107
109
 
108
- let outer_radius = vec![0.0_f64; ndipoles];
110
+ let outer_radius = vec![0.001_f64; ndipoles];
109
111
 
110
112
  let obsx = vec![0.7_f64; nobs];
111
113
  let obsy = vec![-0.4_f64; nobs];
@@ -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
@@ -295,7 +295,7 @@ def mutual_inductance_of_circular_filaments(rzn1: NDArray, rzn2: NDArray, par: b
295
295
  def self_inductance_axisymmetric_coil(
296
296
  f: NDArray,
297
297
  section_kind: Literal["rectangular", "circular", "annular"],
298
- section_size: Union[tuple[float, float], float],
298
+ section_size: tuple[float, float] | float,
299
299
  par: bool = True,
300
300
  ) -> float:
301
301
  """
@@ -5,8 +5,6 @@ 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
-
10
8
  from numpy import ascontiguousarray, float64, zeros_like
11
9
  from numpy.typing import NDArray
12
10
 
@@ -475,7 +473,7 @@ def flux_density_dipole(
475
473
  moment: Array3xN,
476
474
  xyzp: Array3xN,
477
475
  par: bool = True, # Ordered for backwards compatibility
478
- outer_radius: Optional[NDArray[float64]] = None,
476
+ outer_radius: NDArray[float64] | None = None,
479
477
  ) -> Array3xN:
480
478
  """
481
479
  Magnetic flux density of a dipole in cartesian coordiantes.
@@ -507,7 +505,7 @@ def vector_potential_dipole(
507
505
  moment: Array3xN,
508
506
  xyzp: Array3xN,
509
507
  par: bool = True, # Ordered for backwards compatibility
510
- outer_radius: Optional[NDArray[float64]] = None,
508
+ outer_radius: NDArray[float64] | None = None,
511
509
  ) -> Array3xN:
512
510
  """
513
511
  Magnetic vector potential of a dipole in cartesian coordiantes.
@@ -24,7 +24,8 @@ from dataclasses import dataclass
24
24
  from functools import cached_property
25
25
  from logging import getLogger
26
26
  from pathlib import Path
27
- from typing import Callable, Literal
27
+ from typing import Literal
28
+ from collections.abc import Callable
28
29
 
29
30
  import findiff
30
31
  import numpy as np
@@ -1,7 +1,5 @@
1
- from typing import Union
2
-
3
1
  from numpy import float64
4
2
  from numpy.typing import NDArray
5
3
 
6
- Array3xN = Union[NDArray[float64], tuple[NDArray[float64], NDArray[float64], NDArray[float64]]]
4
+ Array3xN = NDArray[float64] | tuple[NDArray[float64], NDArray[float64], NDArray[float64]]
7
5
  """A 3xN array expressed as either a 2D numpy array or a tuple of 1D numpy arrays"""
@@ -4,10 +4,10 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "cfsem"
7
- version = "3.0.0"
7
+ version = "3.0.1"
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
- requires-python = ">=3.9, <3.14"
10
+ requires-python = ">=3.10, <3.14"
11
11
  classifiers = [
12
12
  "Programming Language :: Rust",
13
13
  "Programming Language :: Python :: Implementation :: CPython",
@@ -15,7 +15,7 @@ classifiers = [
15
15
  ]
16
16
  dependencies = [
17
17
  "numpy >= 2",
18
- "interpn >= 0.6.4",
18
+ "interpn[pydantic] >= 0.7",
19
19
  "findiff >= 0.12.1",
20
20
  "pydantic >= 2",
21
21
  "pydantic-numpy >= 6"
@@ -43,7 +43,6 @@ features = ["pyo3/extension-module", "python"]
43
43
  module-name = "cfsem.cfsem"
44
44
 
45
45
  [tool.ruff]
46
- target-version = "py39"
47
46
  line-length = 110
48
47
 
49
48
  [tool.ruff.lint]
@@ -8,7 +8,7 @@ use rayon::{
8
8
  use crate::{
9
9
  MU0_OVER_4PI, chunksize,
10
10
  macros::{check_length_3tup, mut_par_chunks_3tup, par_chunks_3tup},
11
- math::{cross3, dot3, rss3, switch_float},
11
+ math::{clip_nan, cross3, dot3, rss3},
12
12
  physics::volumetric::{
13
13
  flux_density_inside_magnetized_sphere, vector_potential_inside_magnetized_sphere,
14
14
  },
@@ -51,18 +51,23 @@ pub fn flux_density_dipole_scalar(
51
51
  rhat.1.mul_add(c1, -moment.1),
52
52
  rhat.2.mul_add(c1, -moment.2),
53
53
  );
54
- let (bx, by, bz) = (c * tsum.0, c * tsum.1, c * tsum.2);
55
54
 
56
55
  // Defer to magnetized sphere if necessary
57
- // Because this is done without producing a true branch,
58
- // it is only a 20-40% reduction in throughput, and does not disrupt
59
- // the autovectorizer.
56
+ // This branch does not cause a cache miss because the conditional
57
+ // does not require fetching any additional resources from RAM into cache.
58
+ // In fact, this has essentially no effect on performance because the
59
+ // branch is extremely predictable, and can be resolved consistently
60
+ // between when rmag is calculated and when the other dependencies are done.
60
61
  let inside = rmag < outer_radius;
61
- let (bx_inside, by_inside, bz_inside) =
62
- flux_density_inside_magnetized_sphere(moment, outer_radius);
63
- let bx = switch_float(bx_inside, bx, inside);
64
- let by = switch_float(by_inside, by, inside);
65
- let bz = switch_float(bz_inside, bz, inside);
62
+ let (mut bx, mut by, mut bz) = match inside {
63
+ true => flux_density_inside_magnetized_sphere(moment, outer_radius),
64
+ false => (c * tsum.0, c * tsum.1, c * tsum.2),
65
+ }; // [T]
66
+
67
+ // This does not produce a jmp
68
+ bx = clip_nan(bx, 0.0);
69
+ by = clip_nan(by, 0.0);
70
+ bz = clip_nan(bz, 0.0);
66
71
 
67
72
  (bx, by, bz) // [T]
68
73
  }
@@ -146,7 +151,7 @@ pub fn flux_density_dipole_par(
146
151
  ///
147
152
  /// Returns
148
153
  ///
149
- /// * (ax, ay, az) [V⋅s⋅m-1] vector potential components at observation point
154
+ /// * (ax, ay, az) [V-s/m] vector potential components at observation point
150
155
  #[inline]
151
156
  pub fn vector_potential_dipole_scalar(
152
157
  loc: (f64, f64, f64),
@@ -167,26 +172,35 @@ pub fn vector_potential_dipole_scalar(
167
172
  // Use normalized vectors for cross product to improve float roundoff
168
173
  let mhat_cross_rhat = cross3(mhat.0, mhat.1, mhat.2, rhat.0, rhat.1, rhat.2);
169
174
 
170
- // Assemble components
171
- let c = MU0_OVER_4PI * mmag / r2; // [V-s/m] Shared factor
172
- let (ax, ay, az) = (
173
- mhat_cross_rhat.0 * c,
174
- mhat_cross_rhat.1 * c,
175
- mhat_cross_rhat.2 * c,
176
- );
177
-
178
- // Defer to magnetized sphere if necessary
179
- // Because this is done without producing a true branch,
180
- // it is only a 20-40% reduction in throughput, and does not disrupt
181
- // the autovectorizer.
175
+ // Defer to magnetized sphere if necessary.
176
+ // This branch does not cause a cache miss because the conditional
177
+ // does not require fetching any additional resources from RAM into cache.
178
+ // In fact, this has essentially no effect on performance because the
179
+ // branch is extremely predictable, and can be resolved consistently
180
+ // between when rmag is calculated and when the other dependencies are done.
182
181
  let inside = rmag < outer_radius;
183
- let (ax_inside, ay_inside, az_inside) =
184
- vector_potential_inside_magnetized_sphere(mhat_cross_rhat, mmag, rmag, outer_radius);
185
- let ax = switch_float(ax_inside, ax, inside);
186
- let ay = switch_float(ay_inside, ay, inside);
187
- let az = switch_float(az_inside, az, inside);
182
+ let (mut ax, mut ay, mut az) = match inside {
183
+ // Magnetized sphere internal field
184
+ true => {
185
+ vector_potential_inside_magnetized_sphere(mhat_cross_rhat, mmag, rmag, outer_radius)
186
+ }
187
+ // Dipole field
188
+ false => {
189
+ let c = MU0_OVER_4PI * mmag / r2; // [V-s/m] Shared factor
190
+ (
191
+ mhat_cross_rhat.0 * c,
192
+ mhat_cross_rhat.1 * c,
193
+ mhat_cross_rhat.2 * c,
194
+ )
195
+ }
196
+ };
197
+
198
+ // This does not produce a jmp
199
+ ax = clip_nan(ax, 0.0);
200
+ ay = clip_nan(ay, 0.0);
201
+ az = clip_nan(az, 0.0);
188
202
 
189
- (ax, ay, az) // [V⋅s⋅m-1]
203
+ (ax, ay, az) // [V-s/m]
190
204
  }
191
205
 
192
206
  /// Magnetic vector potential of a dipole in cartesian coordinates.