Repository navigation
Take physical constants from scipy.constants - #686
Conversation
util/constants.py and the hardcoded mu_0 = 4*pi*1e-7 in Python now come from scipy.constants, so they follow new CODATA releases. Since the 2019 SI redefinition mu_0 differs from 4*pi*1e-7 by ~1.4e-10 (relative). The C++ core hardcoded mu_0/(4 pi) = 1e-7; it now uses MU0_OVER_4PI from the new simsoptpp/constants.h (CODATA 2022), exposed as simsoptpp.MU0. C++ cannot read scipy at compile time, so tests/field/test_constants.py checks it against scipy.constants.mu_0 and against analytic Biot-Savart and dipole fields.
mishapadidar
left a comment
There was a problem hiding this comment.
A couple things to resolve before we move on:
- VMEC uses its own hard coded value of mu0.
- The Boozer/surface-objective default G still uses 4π×10⁻⁷;
- which CODATA is used, depends on the scipy version. We may want to bump the version requirement to be after 2022 CODATA.
|
- Revert vmec.py and vmec_diagnostics.py to VMEC's own 4*pi*1e-7. - Use constants.mu_0 for the Boozer/surface-objective default G. - CircularCoil.I inverts Inorm with mu_0. - Import constants explicitly in wireframefield.py. - Require scipy>=1.15 (CODATA 2022) and Python>=3.10.
jurasic-pf
left a comment
There was a problem hiding this comment.
Let's try again
mishapadidar
left a comment
There was a problem hiding this comment.
Thanks. It all looks good.
The last thing I will flag is that some examples still rely on manually set values. It is best to change those so users dont copy/paste bad behavior.
See:
Boozer: initial guess for G only
- examples/2_Intermediate/boozer.py:25: G0 = 2. * np.pi * current_sum * (4 * np.pi * 10**(-7) / (2 * np.pi))
- examples/2_Intermediate/boozerQA.py:45: same line
Permanent magnets: mu0 = 4 * np.pi * 1e-7
- examples/1_Simple/permanent_magnet_simple.py:50
- examples/2_Intermediate/permanent_magnet_MUSE.py:189
- examples/2_Intermediate/permanent_magnet_PM4Stell.py:143
- examples/2_Intermediate/permanent_magnet_QA.py:173
Wireframe: mu0 = 4.0 * np.pi * 1e-7
- examples/2_Intermediate/wireframe_gsco_modular.py:87
- examples/2_Intermediate/wireframe_gsco_sector_saddle.py:97
- examples/2_Intermediate/wireframe_rcls_basic.py:62
- examples/2_Intermediate/wireframe_rcls_with_ports.py:108
- examples/3_Advanced/wireframe_gsco_multistep.py:220
and the documentation,
Example walkthroughs (code copied from the example scripts)
- docs/source/example_permanent_magnets.rst:112: mu0 = 4 * np.pi * 1e-7
- docs/source/example_wireframe.rst:145: mu0 = 4.0 * np.pi * 1e-7
- docs/source/example_wireframe.rst:505: mu0 = 4.0 * np.pi * 1e-7
Prose
- docs/source/fields.rst:39: "where μ₀ = 4π × 10⁻⁷ is the vacuum permitivity". This also has the wrong term: μ₀ is the
vacuum permeability, and "permitivity" is misspelled.
Replace hand-written 4*pi*1e-7 in the Boozer, permanent-magnet and wireframe examples and their documentation walkthroughs so users do not copy a value that disagrees with the library. Fix 'permitivity' -> 'permeability' in fields.rst.
The C++ kernels use mu_0/(4 pi) from CODATA 2022, so the 1e-7 prefactor and 4*pi*1e-7 initial G guess in these tests no longer match the code under test. Tests that compare against VMEC output keep VMEC's value.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #686 +/- ##
==========================================
- Coverage 90.95% 90.94% -0.01%
==========================================
Files 86 86
Lines 18781 18606 -175
==========================================
- Hits 17082 16921 -161
+ Misses 1699 1685 -14
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
These were written by a local run of tests/mhd/test_virtual_casing.py (VirtualCasing.from_vmec saves vcasing_<ext>.nc next to the wout file) and are not used by any test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mishapadidar
left a comment
There was a problem hiding this comment.
thanks @jurasic-pf!
I think the two new test files vcasing...nc are not used here so i made a commit removing them. I think everything else looks good
Physical constants now follow new CODATA releases.
Since the 2019 SI redefinition,
mu_0differs from4*pi*1e-7by about 1.4e-10 (relative), so results shift at that level.As agreed in todays developer meeting