cfsem 2.6.0__tar.gz → 2.7.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.
Files changed (69) hide show
  1. {cfsem-2.6.0 → cfsem-2.7.0}/CHANGELOG.md +5 -0
  2. {cfsem-2.6.0 → cfsem-2.7.0}/PKG-INFO +1 -1
  3. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/__init__.py +100 -0
  4. {cfsem-2.6.0 → cfsem-2.7.0}/examples/inductance.py +24 -8
  5. {cfsem-2.6.0 → cfsem-2.7.0}/pyproject.toml +1 -1
  6. {cfsem-2.6.0 → cfsem-2.7.0}/test/test_electromagnetics.py +48 -1
  7. {cfsem-2.6.0 → cfsem-2.7.0}/uv.lock +2 -2
  8. {cfsem-2.6.0 → cfsem-2.7.0}/.cargo/config.toml +0 -0
  9. {cfsem-2.6.0 → cfsem-2.7.0}/.github/workflows/release_python.yml +0 -0
  10. {cfsem-2.6.0 → cfsem-2.7.0}/.github/workflows/release_rust.yml +0 -0
  11. {cfsem-2.6.0 → cfsem-2.7.0}/.github/workflows/test_python.yml +0 -0
  12. {cfsem-2.6.0 → cfsem-2.7.0}/.github/workflows/test_rust.yml +0 -0
  13. {cfsem-2.6.0 → cfsem-2.7.0}/.gitignore +0 -0
  14. {cfsem-2.6.0 → cfsem-2.7.0}/.readthedocs.yml +0 -0
  15. {cfsem-2.6.0 → cfsem-2.7.0}/CHANGELOG_PYTHON_ARCHIVE.md +0 -0
  16. {cfsem-2.6.0 → cfsem-2.7.0}/CHANGELOG_RUST_ARCHIVE.md +0 -0
  17. {cfsem-2.6.0 → cfsem-2.7.0}/CONTRIBUTING.md +0 -0
  18. {cfsem-2.6.0 → cfsem-2.7.0}/Cargo.lock +0 -0
  19. {cfsem-2.6.0 → cfsem-2.7.0}/Cargo.toml +0 -0
  20. {cfsem-2.6.0 → cfsem-2.7.0}/LICENSE +0 -0
  21. {cfsem-2.6.0 → cfsem-2.7.0}/README.md +0 -0
  22. {cfsem-2.6.0 → cfsem-2.7.0}/benches/circular_filament.rs +0 -0
  23. {cfsem-2.6.0 → cfsem-2.7.0}/benches/linear_filament.rs +0 -0
  24. {cfsem-2.6.0 → cfsem-2.7.0}/build_docs.sh +0 -0
  25. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/bindings.py +0 -0
  26. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/py.typed +0 -0
  27. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/solenoid_stress/__init__.py +0 -0
  28. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/solenoid_stress/solenoid_1d.py +0 -0
  29. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/solenoid_stress/solenoid_handcalc.py +0 -0
  30. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/solenoid_stress/thick_wall_cylinder_handcalc.py +0 -0
  31. {cfsem-2.6.0 → cfsem-2.7.0}/cfsem/types.py +0 -0
  32. {cfsem-2.6.0 → cfsem-2.7.0}/docs/assets/logo.svg +0 -0
  33. {cfsem-2.6.0 → cfsem-2.7.0}/docs/index.md +0 -0
  34. {cfsem-2.6.0 → cfsem-2.7.0}/docs/javascripts/mathjax.js +0 -0
  35. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/example_outputs/.placeholder +0 -0
  36. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/examples.md +0 -0
  37. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/filament.md +0 -0
  38. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/flux_density.md +0 -0
  39. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/force.md +0 -0
  40. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/grad_shafranov.md +0 -0
  41. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/inductance.md +0 -0
  42. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/math.md +0 -0
  43. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/solenoid_stress.md +0 -0
  44. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/types.md +0 -0
  45. {cfsem-2.6.0 → cfsem-2.7.0}/docs/python/vector_potential.md +0 -0
  46. {cfsem-2.6.0 → cfsem-2.7.0}/docs/requirements.txt +0 -0
  47. {cfsem-2.6.0 → cfsem-2.7.0}/docs/stylesheets/extra.css +0 -0
  48. {cfsem-2.6.0 → cfsem-2.7.0}/examples/helmholtz.py +0 -0
  49. {cfsem-2.6.0 → cfsem-2.7.0}/katex-header.html +0 -0
  50. {cfsem-2.6.0 → cfsem-2.7.0}/mkdocs.yml +0 -0
  51. {cfsem-2.6.0 → cfsem-2.7.0}/src/lib.rs +0 -0
  52. {cfsem-2.6.0 → cfsem-2.7.0}/src/math.rs +0 -0
  53. {cfsem-2.6.0 → cfsem-2.7.0}/src/mesh.rs +0 -0
  54. {cfsem-2.6.0 → cfsem-2.7.0}/src/physics/biotsavart.rs +0 -0
  55. {cfsem-2.6.0 → cfsem-2.7.0}/src/physics/circular_filament.rs +0 -0
  56. {cfsem-2.6.0 → cfsem-2.7.0}/src/physics/gradshafranov.rs +0 -0
  57. {cfsem-2.6.0 → cfsem-2.7.0}/src/physics/linear_filament.rs +0 -0
  58. {cfsem-2.6.0 → cfsem-2.7.0}/src/physics/mesh_filament.rs +0 -0
  59. {cfsem-2.6.0 → cfsem-2.7.0}/src/physics/mod.rs +0 -0
  60. {cfsem-2.6.0 → cfsem-2.7.0}/src/physics/point_source.rs +0 -0
  61. {cfsem-2.6.0 → cfsem-2.7.0}/src/python.rs +0 -0
  62. {cfsem-2.6.0 → cfsem-2.7.0}/src/testing.rs +0 -0
  63. {cfsem-2.6.0 → cfsem-2.7.0}/test/__init__.py +0 -0
  64. {cfsem-2.6.0 → cfsem-2.7.0}/test/test_examples.py +0 -0
  65. {cfsem-2.6.0 → cfsem-2.7.0}/test/test_filaments.py +0 -0
  66. {cfsem-2.6.0 → cfsem-2.7.0}/test/test_funcs.py +0 -0
  67. {cfsem-2.6.0 → cfsem-2.7.0}/test/test_gradshafranov.py +0 -0
  68. {cfsem-2.6.0 → cfsem-2.7.0}/test/test_math.py +0 -0
  69. {cfsem-2.6.0 → cfsem-2.7.0}/test/test_solenoid_stress.py +0 -0
@@ -2,6 +2,11 @@
2
2
 
3
3
  See archived changelogs for versions prior to 2.6.0.
4
4
 
5
+ ## 2.7.0 2025-10-15
6
+
7
+ ### Added
8
+ * Add method for calculating self-inductance for coaxial collection of ideal circular filaments.
9
+
5
10
  ## 2.6.0 2025-10-15
6
11
 
7
12
  Substantial performance improvement for `flux_density_linear_filament` Biot-Savart methods.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cfsem
3
- Version: 2.6.0
3
+ Version: 2.7.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -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
@@ -42,6 +44,7 @@ __all__ = [
42
44
  "filament_helix_path",
43
45
  "inductance_piecewise_linear_filaments",
44
46
  "self_inductance_piecewise_linear_filaments",
47
+ "self_inductance_axisymmetric_coil",
45
48
  "mutual_inductance_piecewise_linear_filaments",
46
49
  "flux_density_ideal_solenoid",
47
50
  "self_inductance_lyle6",
@@ -287,6 +290,103 @@ def mutual_inductance_of_circular_filaments(rzn1: NDArray, rzn2: NDArray, par: b
287
290
  return m # [H]
288
291
 
289
292
 
293
+ def self_inductance_axisymmetric_coil(
294
+ f: NDArray,
295
+ section_kind: Literal["rectangular", "circular", "annular"],
296
+ section_size: Union[tuple[float, float], float],
297
+ par: bool = True,
298
+ ) -> float:
299
+ """
300
+ Self-inductance of a coaxial collection of ideal circular filaments.
301
+
302
+ Args:
303
+ f: 3 x N array of filament definitions like (r [m], z [m], n []) coordinates and number of turns
304
+ section_kind: Kind of conductor cross-section to use for self-inductance correction
305
+ section_size: Size of the conductor cross-section
306
+ * For "rectangular", a tuple (width [m], height [m])
307
+ * For "circular", a single float (radius [m])
308
+ * For "annular", a tuple (inner radius [m], outer radius [m])
309
+
310
+ Returns:
311
+ float: Self-inductance [H]
312
+ """
313
+
314
+ # Validate valid section_kind and section_size
315
+ assert section_kind in ("rectangular", "circular", "annular"), (
316
+ "section_kind must be one of 'rectangular', 'circular', or 'annular'"
317
+ )
318
+
319
+ if section_kind == "rectangular":
320
+ assert isinstance(section_size, tuple), (
321
+ "For rectangular section, section_size must be a tuple (conductor width and height)"
322
+ )
323
+ assert len(section_size) == 2, "For rectangular section, section_size must be a tuple of length 2"
324
+ assert section_size[0] > 0.0 and section_size[1] > 0.0, (
325
+ "Conductor section sizes (width and height) must be positive"
326
+ )
327
+
328
+ if section_kind == "circular":
329
+ assert isinstance(section_size, float) and section_size > 0.0, (
330
+ "For circular section, section size must be a non-negative float (conductor radius)"
331
+ )
332
+
333
+ if section_kind == "annular":
334
+ assert isinstance(section_size, tuple) and len(section_size) == 2, (
335
+ "For annular section, section_size must be a tuple (inner and outer conductor radius)"
336
+ )
337
+ assert section_size[0] >= 0.0 and section_size[1] > section_size[0], (
338
+ "For annular section, "
339
+ "inner radius must be non-negative and outer radius must be larger than inner radius"
340
+ )
341
+
342
+ m = 0.0
343
+ rs, zs, ns = f
344
+
345
+ # Iterate over filaments
346
+ for i in range(f.shape[1]):
347
+ # Get mutual inductance of i-th filament to all other filaments
348
+ m_contribs = ns * flux_circular_filament(ns[i], rs[i], zs[i], rs, zs, par)
349
+
350
+ # Get self-inductance of i-th filament
351
+ if section_kind == "rectangular":
352
+ assert isinstance(section_size, tuple)
353
+ m_self = self_inductance_lyle6(
354
+ r=rs[i], # coil center radius
355
+ dr=section_size[0], # width of the rectangular conductor section
356
+ dz=section_size[1], # height of the rectangular conductor section
357
+ n=ns[i],
358
+ )
359
+ elif section_kind == "circular":
360
+ # Wien formula for circular cross-section
361
+ assert isinstance(section_size, float)
362
+ m_self = (
363
+ self_inductance_circular_ring_wien(
364
+ major_radius=rs[i], # coil center radius
365
+ minor_radius=np.atleast_1d(section_size),
366
+ )
367
+ * ns[i] ** 2
368
+ )
369
+ m_self = float(m_self.item()) # Convert to float
370
+
371
+ elif section_kind == "annular":
372
+ # Wien formula for annular cross-section
373
+ assert isinstance(section_size, tuple)
374
+ m_self = (
375
+ self_inductance_annular_ring(
376
+ r=rs[i], # major radius
377
+ a=section_size[0], # inner minor radius (tube inside radius)
378
+ b=section_size[1], # outer minor radius (tube outside radius)
379
+ )
380
+ * ns[i] ** 2
381
+ )
382
+
383
+ # Replace self-pairing with self-inductance
384
+ m_contribs[i] = m_self
385
+ m += np.sum(m_contribs)
386
+
387
+ return m # [H]
388
+
389
+
290
390
  def mutual_inductance_of_cylindrical_coils(f1: NDArray, f2: NDArray, par: bool = True) -> float:
291
391
  """
292
392
  Analytical mutual inductance between two coaxial collections of ideal filaments.
@@ -13,6 +13,9 @@ import cfsem
13
13
  r1, z1, w1, h1, nr1, nz1 = (0.3, 0.0, 0.01, 1.0, 1, 10)
14
14
  r2, z2, w2, h2, nr2, nz2 = (0.5, 0.2, 0.01, 0.5, 1, 5)
15
15
 
16
+ cnd_w1, cnd_h1 = (0.02, 0.02) # Approximate conductor width and height for first coil
17
+ cnd_w2, cnd_h2 = (0.02, 0.02) # Approximate conductor width and height for second coil
18
+
16
19
  nt1 = nr1 * nz1 # Total number of turns for each coil
17
20
  nt2 = nr2 * nz2
18
21
 
@@ -47,13 +50,26 @@ self_inductance_helical_2 = cfsem.self_inductance_piecewise_linear_filaments(
47
50
  (xhelix2, yhelix2, zhelix2)
48
51
  )
49
52
 
53
+ self_inductance_axisymmetric_1 = cfsem.self_inductance_axisymmetric_coil(
54
+ f=filaments_1.T,
55
+ section_kind="rectangular",
56
+ section_size=(cnd_w1, cnd_h1),
57
+ )
58
+ self_inductance_axisymmetric_2 = cfsem.self_inductance_axisymmetric_coil(
59
+ f=filaments_2.T,
60
+ section_kind="rectangular",
61
+ section_size=(cnd_w2, cnd_h2),
62
+ )
63
+
50
64
  print("First coil self-inductance")
51
- print(f" Handcalc: {self_inductance_handcalc_1:.2e} [H]")
52
- print(f" Helical: {self_inductance_helical_1:.2e} [H]")
65
+ print(f" Handcalc: {self_inductance_handcalc_1:.2e} [H]")
66
+ print(f" Helical: {self_inductance_helical_1:.2e} [H]")
67
+ print(f" Axisymmetric: {self_inductance_axisymmetric_1:.2e} [H]")
53
68
 
54
69
  print("Second coil self-inductance")
55
- print(f" Handcalc: {self_inductance_handcalc_2:.2e} [H]")
56
- print(f" Helical: {self_inductance_helical_2:.2e} [H]")
70
+ print(f" Handcalc: {self_inductance_handcalc_2:.2e} [H]")
71
+ print(f" Helical: {self_inductance_helical_2:.2e} [H]")
72
+ print(f" Axisymmetric: {self_inductance_axisymmetric_2:.2e} [H]")
57
73
 
58
74
  # Estimate mutual inductance by 2 different methods,
59
75
  # axisymmetric filaments and helical filaments.
@@ -74,7 +90,7 @@ mutual_inductance_helical_reflexive = (
74
90
  )
75
91
 
76
92
  print("Mutual-inductance")
77
- print(f" Axisymmetric: {mutual_inductance_axisymmetric:.2e} [H]")
78
- print(f" Helical: {mutual_inductance_helical:.2e} [H]")
79
- print(f" Axisymmetric reflexive: {mutual_inductance_axisymmetric_reflexive:.2e} [H]")
80
- print(f" Helical reflexive: {mutual_inductance_helical_reflexive:.2e} [H]")
93
+ print(f" Axisymmetric: {mutual_inductance_axisymmetric:.2e} [H]")
94
+ print(f" Helical: {mutual_inductance_helical:.2e} [H]")
95
+ print(f" Axisymmetric reflexive: {mutual_inductance_axisymmetric_reflexive:.2e} [H]")
96
+ print(f" Helical reflexive: {mutual_inductance_helical_reflexive:.2e} [H]")
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "cfsem"
7
- version = "2.6.0"
7
+ version = "2.7.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"
@@ -426,7 +426,7 @@ def test_flux_density_circular_filament_against_numerical(a, z, par):
426
426
 
427
427
 
428
428
  @mark.parametrize("par", [True, False])
429
- def test_self_inductance_lyle6_against_filamentization_and_distributed(par):
429
+ def test_self_inductance_lyle6_against_filamentization_and_distributed_and_axisymmetric(par):
430
430
  # Test that the Lyle approximation gives a similar result to
431
431
  # a case done by brute-force filamentization w/ a heuristic for self-inductance of a loop
432
432
  r, z, dr, dz, nt, nr, nz = (0.8, 0.0, 0.5, 2.0, 3.0, 20, 20)
@@ -437,6 +437,9 @@ def test_self_inductance_lyle6_against_filamentization_and_distributed(par):
437
437
  r, z, dr, dz, nt, nr, nz
438
438
  ) # Estimate self-inductance via discretization
439
439
 
440
+ # Approximate conductor cross-section for axisymmetric calc
441
+ cnd_w, cnd_h = (dr/nr, dz/nz) # Approximate conductor width and height
442
+
440
443
  # Set up distributed-conductor solve
441
444
  fils = cfsem.filament_coil(r, z, dr, dz, nt, nr, nz)
442
445
  rfil, zfil, _ = fils.T
@@ -486,9 +489,52 @@ def test_self_inductance_lyle6_against_filamentization_and_distributed(par):
486
489
  edge_path=(rpath, zpath),
487
490
  )
488
491
 
492
+ # Do the axisymmetric run
493
+ L_axisymmetric = cfsem.self_inductance_axisymmetric_coil(
494
+ f=fils.T,
495
+ section_kind="rectangular",
496
+ section_size=(cnd_w, cnd_h),
497
+ )
498
+
489
499
  # Require 5% accuracy (seat of the pants, since we're comparing approximations)
490
500
  assert L_Lyle == approx(L_fil, 0.05)
491
501
  assert (nt**2 * L_distributed) == approx(L_fil, 0.05)
502
+ assert L_Lyle == approx(L_axisymmetric, 0.05)
503
+
504
+ @mark.parametrize("par", [True, False])
505
+ def test_self_inductance_axisymmetric_across_section_types(par):
506
+ """ Test that the different conductor cross-section types give similar results """
507
+ r, z, dr, dz, nt, nr, nz = (0.8, 0.0, 0.5, 2.0, 3.0, 20, 20)
508
+ # Approximate conductor cross-section for axisymmetric calc
509
+ cnd_w, cnd_h = (dr/nr, dz/nz) # Approximate conductor width and height
510
+
511
+ # Set up distributed-conductor solve
512
+ fils = cfsem.filament_coil(r, z, dr, dz, nt, nr, nz)
513
+
514
+ cnd_w, cnd_h = (dr/20, dz/20) # Approximate conductor width and height
515
+ cnd_r = (cnd_w * cnd_h / np.pi)**0.5 # Equivalent-area radius
516
+
517
+ # Use base height/width for rectangular
518
+ L_rect = cfsem.self_inductance_axisymmetric_coil(
519
+ f=fils.T,
520
+ section_kind="rectangular",
521
+ section_size=(cnd_w, cnd_h),
522
+ )
523
+ # Use equivalent-area radius for circular and annular
524
+ L_circle = cfsem.self_inductance_axisymmetric_coil(
525
+ f=fils.T,
526
+ section_kind="circular",
527
+ section_size=cnd_r,
528
+ )
529
+ # Use equivalent-area radius for major radius, and outer radius = 2*inner radius
530
+ L_annulus = cfsem.self_inductance_axisymmetric_coil(
531
+ f=fils.T,
532
+ section_kind="annular",
533
+ section_size=(cnd_r/2, cnd_r),
534
+ )
535
+
536
+ assert L_rect == approx(L_circle, rel=1e-2)
537
+ assert L_rect == approx(L_annulus, rel=1e-2)
492
538
 
493
539
 
494
540
  @mark.parametrize("r", [0.775, np.pi])
@@ -703,3 +749,4 @@ def test_vector_potential_linear_against_circular_filament(r, z, par):
703
749
  az, np.zeros_like(az), atol=1e-9
704
750
  ) # Should sum to zero everywhere
705
751
  assert np.allclose(ax, np.zeros_like(ax), atol=1e-9) # ...
752
+
@@ -1,5 +1,5 @@
1
1
  version = 1
2
- revision = 3
2
+ revision = 2
3
3
  requires-python = ">=3.9, <3.14"
4
4
  resolution-markers = [
5
5
  "python_full_version >= '3.11'",
@@ -49,7 +49,7 @@ wheels = [
49
49
 
50
50
  [[package]]
51
51
  name = "cfsem"
52
- version = "2.6.0"
52
+ version = "2.7.0"
53
53
  source = { editable = "." }
54
54
  dependencies = [
55
55
  { name = "findiff" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes