Skip to content

Commit

Permalink
changed inductances docstrings and reltols
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacSavona committed Nov 16, 2023
1 parent cddf6f8 commit 7d3c03e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
8 changes: 2 additions & 6 deletions cfspopcon/formulas/inductances.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,10 @@ def calc_internal_inductance(
A power-balance model for local helicity injection startup in a spherical tokamak :cite:`Barr_2018`
Args:
plasma_volume: [m^3] : term:`glossary link<plasma_volume>`
poloidal_circumference: [m] :term:`glossary link<poloidal_circumference>`
major_radius: [m] :term:`glossary link<major_radius>`
plasma_current: [A] :term:`glossary link<plasma_current>`
magnetic_field_on_axis: [T] :term:`glossary link<magnetic_field_on_axis>`
minor_radius: [m] :term:`glossary link<minor_radius>`
internal_inductivity: [~] :term:`glossary link<internal_inductivity>`
plasma_volume: [m^3] : term:`glossary link<plasma_volume>`
poloidal_circumference: [m] :term:`glossary link<poloidal_circumference>`
internal_inductance_geometry : [] :term:`glossary link<internal_inductance_geometry>`
Returns:
Expand Down Expand Up @@ -164,7 +161,6 @@ def calc_vertical_field_mutual_inductance(
Args:
inverse_aspect_ratio: [~] :term:`glossary link<inverse_aspect_ratio>`
areal_elongation: [~] :term:`glossary link<areal_elongation>`
major_radius: [m] :term:`glossary link<major_radius>`
surface_inductance_coefficients: [~] :term:`glossary link<surface_inductance_coefficients>`
Returns:
Expand Down
50 changes: 25 additions & 25 deletions tests/test_fluxes_and_inductances.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_calc_flux_internal():
shape = InternalInductanceGeometry.Cylindrical
internal_inductance = calc_internal_inductance(1.85 * ureg.m, 0.8, 0 * ureg.m**3, 0 * ureg.m, shape)
internal_flux = calc_flux_internal(8.7e6 * ureg.A, internal_inductance).item()
np.testing.assert_allclose(internal_flux.to("weber").magnitude, 8.090229405928559, rtol=5e-2, atol=0)
np.testing.assert_allclose(internal_flux.to("weber").magnitude, 8.090229405928559, rtol=1e-5, atol=0)


def test_calc_flux_external():
Expand All @@ -76,30 +76,30 @@ def test_calc_flux_external():
0.3 * ureg.dimensionless, 1.7 * ureg.dimensionless, 0.3 * ureg.dimensionless, 1.85 * ureg.m, 0.8 * ureg.dimensionless, coeffs
)
external_flux = calc_flux_external(8.7e6 * ureg.A, external_inductance).item()
np.testing.assert_allclose(external_flux.to("weber").magnitude, 24.21256335948457, rtol=5e-2, atol=0)
np.testing.assert_allclose(external_flux.to("weber").magnitude, 24.21256335948457, rtol=1e-5, atol=0)


def test_calc_flux_PF():
coeffs = SurfaceInductanceCoeffs.Barr
vertical_field_mutual_inductance = calc_vertical_field_mutual_inductance(0.3, 1.7, coeffs)
PF_flux = calc_flux_PF(vertical_field_mutual_inductance, 0.6 * ureg.T, 1.85 * ureg.m).item()
np.testing.assert_allclose(PF_flux.to("weber").magnitude, 6.629771312025196, rtol=5e-2, atol=0)
np.testing.assert_allclose(PF_flux.to("weber").magnitude, 6.629771312025196, rtol=1e-5, atol=0)


def test_calc_flux_resistive():
resistive_flux = calc_flux_res(8.7e6 * ureg.A, 1.85 * ureg.m, 0.45).item()
np.testing.assert_allclose(resistive_flux.to("weber").magnitude, 9.10150808166963, rtol=5e-2, atol=0)
np.testing.assert_allclose(resistive_flux.to("weber").magnitude, 9.10150808166963, rtol=1e-5, atol=0)


def test_calc_internal_inductivity():
internal_inductivity = calc_internal_inductivity(8.7e6 * ureg.A, 1.85 * ureg.m, 12.2 * ureg.T, 1.85 * ureg.m * 0.3, 1.01).item()
np.testing.assert_allclose(internal_inductivity.to("dimensionless").magnitude, 0.5814953402118008, rtol=5e-2, atol=0)
np.testing.assert_allclose(internal_inductivity.to("dimensionless").magnitude, 0.5814953402118008, rtol=1e-5, atol=0)


def test_calc_vertical_field_mutual_inductance():
coeffs = SurfaceInductanceCoeffs.Barr
vertical_field_mutual_inductance = calc_vertical_field_mutual_inductance(0.3, 1.7, coeffs).item()
np.testing.assert_allclose(vertical_field_mutual_inductance.to("dimensionless").magnitude, 1.027670685052496, rtol=5e-2, atol=0)
np.testing.assert_allclose(vertical_field_mutual_inductance.to("dimensionless").magnitude, 1.027670685052496, rtol=1e-5, atol=0)


def test_calc_vertical_magnetic_field():
Expand All @@ -111,101 +111,101 @@ def test_calc_vertical_magnetic_field():
vertical_magnetic_field = calc_vertical_magnetic_field(
0.3, 1.7, 0.3, 0.8, external_inductance, 1.85 * ureg.m, 8.7e6 * ureg.A, vertical_magnetic_field_eq, coeffs
).item()
np.testing.assert_allclose(vertical_magnetic_field.to("tesla").magnitude, 1.1286206938400316, rtol=5e-2, atol=0)
np.testing.assert_allclose(vertical_magnetic_field.to("tesla").magnitude, 1.1286206938400316, rtol=1e-5, atol=0)


def test_calc_external_inductance():
coeffs = SurfaceInductanceCoeffs.Barr
external_inductance = calc_external_inductance(0.3, 1.7, 0.3, 1.85 * ureg.m, 0.8, coeffs).item()
np.testing.assert_allclose(external_inductance.to("henry").magnitude, 2.78305325971087e-06, rtol=5e-2, atol=0)
np.testing.assert_allclose(external_inductance.to("henry").magnitude, 2.78305325971087e-06, rtol=1e-5, atol=0)


def test_calc_invmu_0_dLedR():
coeffs = SurfaceInductanceCoeffs.Barr
external_inductance = calc_external_inductance(0.3, 1.7, 0.3, 1.85 * ureg.m, 0.8, coeffs)
invmu_0_dLedR = calc_invmu_0_dLedR(0.3, 1.7, 0.3, 0.8, external_inductance, 1.85 * ureg.m, coeffs).item()
np.testing.assert_allclose(invmu_0_dLedR.to("dimensionless").magnitude, 2.1999405545602646, rtol=5e-2, atol=0)
np.testing.assert_allclose(invmu_0_dLedR.to("dimensionless").magnitude, 2.1999405545602646, rtol=1e-5, atol=0)


def test_calc_fa():
coeffs = SurfaceInductanceCoeffs.Barr
fa = calc_fa(0.3, 0.3, 0.8, coeffs).item()
np.testing.assert_allclose(fa.to("dimensionless").magnitude, 1.4335756919903129, rtol=5e-2, atol=0)
np.testing.assert_allclose(fa.to("dimensionless").magnitude, 1.4335756919903129, rtol=1e-5, atol=0)


def test_calc_fa_Sum_Ne():
coeffs = SurfaceInductanceCoeffs.Barr
fa_Sum_Ne = calc_fa_Sum_Ne(0.3, coeffs).item()
np.testing.assert_allclose(fa_Sum_Ne.to("dimensionless").magnitude, 0.024095227744249464, rtol=5e-2, atol=0)
np.testing.assert_allclose(fa_Sum_Ne.to("dimensionless").magnitude, 0.024095227744249464, rtol=1e-5, atol=0)


def test_calc_fa_Sums_Na():
coeffs = SurfaceInductanceCoeffs.Barr
np.testing.assert_allclose(calc_fa_Sums_Na.__wrapped__(0.3, coeffs)[0], 1.4293250376924287, rtol=5e-2, atol=0)
np.testing.assert_allclose(calc_fa_Sums_Na.__wrapped__(0.3, coeffs)[1], 4.559771647300995, rtol=5e-2, atol=0)
np.testing.assert_allclose(calc_fa_Sums_Na.__wrapped__(0.3, coeffs)[0], 1.4293250376924287, rtol=1e-5, atol=0)
np.testing.assert_allclose(calc_fa_Sums_Na.__wrapped__(0.3, coeffs)[1], 4.559771647300995, rtol=1e-5, atol=0)


def test_calc_fb():
coeffs = SurfaceInductanceCoeffs.Barr
np.testing.assert_allclose(calc_fb.__wrapped__(0.3, coeffs), 0.08132941228621908, rtol=5e-2, atol=0)
np.testing.assert_allclose(calc_fb.__wrapped__(0.3, coeffs), 0.08132941228621908, rtol=1e-5, atol=0)


def test_calc_fb_Sum_Nb():
coeffs = SurfaceInductanceCoeffs.Barr
np.testing.assert_allclose(calc_fb_Sum_Nb.__wrapped__(0.3, coeffs), -0.003446225999999998, rtol=5e-2, atol=0)
np.testing.assert_allclose(calc_fb_Sum_Nb.__wrapped__(0.3, coeffs), -0.003446225999999998, rtol=1e-5, atol=0)


def test_calc_fc():
coeffs = SurfaceInductanceCoeffs.Barr
np.testing.assert_allclose(calc_fc.__wrapped__(0.3, coeffs), 0.970874542, rtol=5e-2, atol=0)
np.testing.assert_allclose(calc_fc.__wrapped__(0.3, coeffs), 0.970874542, rtol=1e-5, atol=0)


def test_calc_fc_Sum_Nc():
coeffs = SurfaceInductanceCoeffs.Barr
fc_Sum_Nc = calc_fc_Sum_Nc(0.3, coeffs).item()
np.testing.assert_allclose(fc_Sum_Nc.to("dimensionless").magnitude, -0.029125457999999996, rtol=5e-2, atol=0)
np.testing.assert_allclose(fc_Sum_Nc.to("dimensionless").magnitude, -0.029125457999999996, rtol=1e-5, atol=0)


def test_calc_fd():
coeffs = SurfaceInductanceCoeffs.Barr
fd = calc_fd(0.3, 1.7, coeffs).item()
np.testing.assert_allclose(fd.to("dimensionless").magnitude, 0.000826722, rtol=5e-2, atol=0)
np.testing.assert_allclose(fd.to("dimensionless").magnitude, 0.000826722, rtol=1e-5, atol=0)


def test_calc_fd_Sum_Nd():
coeffs = SurfaceInductanceCoeffs.Barr
fd_Sum_Nd = calc_fd_Sum_Nd(0.3, coeffs).item()
np.testing.assert_allclose(fd_Sum_Nd.to("dimensionless").magnitude, -0.08141999999999998, rtol=5e-2, atol=0)
np.testing.assert_allclose(fd_Sum_Nd.to("dimensionless").magnitude, -0.08141999999999998, rtol=1e-5, atol=0)


def test_calc_fg():
coeffs = SurfaceInductanceCoeffs.Barr
fg = calc_fg(0.3, 0.3, 0.8, coeffs).item()
np.testing.assert_allclose(fg.to("dimensionless").magnitude, -3.2891718339522056, rtol=5e-2, atol=0)
np.testing.assert_allclose(fg.to("dimensionless").magnitude, -3.2891718339522056, rtol=1e-5, atol=0)


def test_calc_fg_Sum_Ne():
coeffs = SurfaceInductanceCoeffs.Barr
fg_Sum_Ce = calc_fg_Sum_Ce(0.3, coeffs).item()
np.testing.assert_allclose(fg_Sum_Ce.to("dimensionless").magnitude, 0.15044119670967493, rtol=5e-2, atol=0)
np.testing.assert_allclose(fg_Sum_Ce.to("dimensionless").magnitude, 0.15044119670967493, rtol=1e-5, atol=0)


def test_calc_fg_Sums_Na():
coeffs = SurfaceInductanceCoeffs.Barr
np.testing.assert_allclose(calc_fg_Sums_Na.__wrapped__(0.3, coeffs)[0], 3.4517083961540482, rtol=5e-2, atol=0)
np.testing.assert_allclose(calc_fg_Sums_Na.__wrapped__(0.3, coeffs)[1], 11.39453620447642, rtol=5e-2, atol=0)
np.testing.assert_allclose(calc_fg_Sums_Na.__wrapped__(0.3, coeffs)[0], 3.4517083961540482, rtol=1e-5, atol=0)
np.testing.assert_allclose(calc_fg_Sums_Na.__wrapped__(0.3, coeffs)[1], 11.39453620447642, rtol=1e-5, atol=0)


def test_calc_fh():
coeffs = SurfaceInductanceCoeffs.Barr
fh = calc_fh(0.3, 1.7, coeffs).item()
np.testing.assert_allclose(fh.to("dimensionless").magnitude, -0.77315961077771, rtol=5e-2, atol=0)
np.testing.assert_allclose(fh.to("dimensionless").magnitude, -0.77315961077771, rtol=1e-5, atol=0)


def test_calc_fh_Sum_Cb():
coeffs = SurfaceInductanceCoeffs.Barr
fh_Sum_Cb = calc_fh_Sum_Cb(0.3, coeffs).item()
np.testing.assert_allclose(fh_Sum_Cb.to("dimensionless").magnitude, -0.024597188999999988, rtol=5e-2, atol=0)
np.testing.assert_allclose(fh_Sum_Cb.to("dimensionless").magnitude, -0.024597188999999988, rtol=1e-5, atol=0)


def test_functionals_against_hirshman():
Expand Down

0 comments on commit 7d3c03e

Please sign in to comment.