Skip to content

Commit

Permalink
Convert jcrit_nbti to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
timothy-nunn committed Oct 11, 2023
1 parent 23496bc commit 284ad9d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 75 deletions.
22 changes: 15 additions & 7 deletions process/pfcoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,7 @@ def deltaj_nbti(temperature):
:return: difference in current density
:rtype: float
"""
jcrit0, t = sc.jcrit_nbti(temperature, bmax, c0, bc20m, tc0m)
jcrit0, _ = superconductors.jcrit_nbti(temperature, bmax, c0, bc20m, tc0m)
if ml.variable_error(jcrit0): # superconductors.jcrit_nbti has failed.
print(f"superconductors.jcrit_nbti: {bmax=} {temperature=} {jcrit0=}")

Expand Down Expand Up @@ -2879,14 +2879,14 @@ def deltaj_hijc_rebco(temperature):
bc20m = 15.0e0
tc0m = 9.3e0
c0 = 1.0e10
jcritsc, tcrit = sc.jcrit_nbti(thelium, bmax, c0, bc20m, tc0m)
jcritsc, _ = superconductors.jcrit_nbti(thelium, bmax, c0, bc20m, tc0m)
jcritstr = jcritsc * (1.0e0 - fcu)

elif isumat == 4:
# As (1), but user-defined parameters
bc20m = bcritsc
tc0m = tcritsc
jcritsc, bcrit, tcrit = sc.itersc(thelium, bmax, strain, bc20m, tc0m)
jcritsc, _, _ = superconductors.itersc(thelium, bmax, strain, bc20m, tc0m)
jcritstr = jcritsc * (1.0e0 - fcu)

elif isumat == 5:
Expand Down Expand Up @@ -2980,14 +2980,20 @@ def deltaj_hijc_rebco(temperature):
ttestp = ttest + delt

if isumat in [1, 4]:
jcrit0, b, t = sc.itersc(ttest, bmax, strain, bc20m, tc0m)
jcrit0, _, _ = superconductors.itersc(
ttest, bmax, strain, bc20m, tc0m
)
if (abs(jsc - jcrit0) <= jtol) and (
abs((jsc - jcrit0) / jsc) <= 0.01
):
break

jcritm, b, t = sc.itersc(ttestm, bmax, strain, bc20m, tc0m)
jcritp, b, t = sc.itersc(ttestp, bmax, strain, bc20m, tc0m)
jcritm, _, _ = superconductors.itersc(
ttestm, bmax, strain, bc20m, tc0m
)
jcritp, _, _ = superconductors.itersc(
ttestp, bmax, strain, bc20m, tc0m
)

# Kludge to avoid divide by 0
if jcritm == jcritp:
Expand All @@ -3006,7 +3012,9 @@ def deltaj_hijc_rebco(temperature):
deltaj_nbti, x1, x2, 100e0
)
tmarg = current_sharing_t - thelium
jcrit0, t = sc.jcrit_nbti(current_sharing_t, bmax, c0, bc20m, tc0m)
jcrit0, _ = superconductors.jcrit_nbti(
current_sharing_t, bmax, c0, bc20m, tc0m
)
if ml.variable_error(
current_sharing_t
): # current sharing secant solver has failed.
Expand Down
20 changes: 7 additions & 13 deletions process/sctfcoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,7 @@ def supercon(
bc20m = 15.0e0
tc0m = 9.3e0
c0 = 1.0e10
jcritsc, tcrit = superconductorsf90.jcrit_nbti(
thelium, bmax, c0, bc20m, tc0m
)
jcritsc, _ = superconductors.jcrit_nbti(thelium, bmax, c0, bc20m, tc0m)
jcritstr = jcritsc * (1.0e0 - fcu)
# Critical current in cable
icrit = jcritstr * acs * fcond
Expand Down Expand Up @@ -823,31 +821,27 @@ def supercon(

# Issue #483 to be on the safe side, check the fractional as well as the absolute error
if isumat in (1, 4):
jcrit0, b, t = superconductorsf90.itersc(
jcrit0, _, _ = superconductors.itersc(
ttest, bmax, strain, bc20m, tc0m
)
if (abs(jsc - jcrit0) <= jtol) and (
abs((jsc - jcrit0) / jsc) <= 0.01
):
break
jcritm, b, t = superconductorsf90.itersc(
jcritm, _, _ = superconductors.itersc(
ttestm, bmax, strain, bc20m, tc0m
)
jcritp, b, t = superconductorsf90.itersc(
jcritp, _, _ = superconductors.itersc(
ttestp, bmax, strain, bc20m, tc0m
)
elif isumat == 3:
jcrit0, t = superconductorsf90.jcrit_nbti(
ttest, bmax, c0, bc20m, tc0m
)
jcrit0, _ = superconductors.jcrit_nbti(ttest, bmax, c0, bc20m, tc0m)
if (abs(jsc - jcrit0) <= jtol) and (
abs((jsc - jcrit0) / jsc) <= 0.01
):
break
jcritm, t = superconductorsf90.jcrit_nbti(
ttestm, bmax, c0, bc20m, tc0m
)
jcritp, t = superconductorsf90.jcrit_nbti(
jcritm, _ = super.jcrit_nbti(ttestm, bmax, c0, bc20m, tc0m)
jcritp, _ = superconductors.jcrit_nbti(
ttestp, bmax, c0, bc20m, tc0m
)
elif isumat == 5:
Expand Down
40 changes: 40 additions & 0 deletions process/superconductors.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,43 @@ def itersc(thelium, bmax, strain, bc20max, tc0max):
jcrit = jc1 * jc2 * jc3 / scalefac

return jcrit, bcrit, tcrit


def jcrit_nbti(temperature, bmax, c0, bc20max, tc0max):
"""Critical current density in a NbTi superconductor strand
author: P J Knight, CCFE, Culham Science Centre
temperature : input real : SC temperature (K)
bmax : input real : Magnetic field at conductor (T)
c0 : input real : Scaling constant (A/m2)
bc20max : input real : Upper critical field (T) for superconductor
at zero temperature and strain
tc0max : input real : Critical temperature (K) at zero field and strain
jcrit : output real : Critical current density in superconductor (A/m2)
tcrit : output real : Critical temperature (K)
This routine calculates the critical current density and
temperature in superconducting TF coils using NbTi
as the superconductor.
"""

bratio = bmax / bc20max

if bmax < bc20max:
# Critical temperature (K)
tcrit = tc0max * (1.0 - bratio) ** 0.59
else:
# Allow bmax > bc20max but set error flag
# Fudge to give real (negative) value if bratio < 1
tcrit = tc0max * (1.0 - bratio)

# Allow tbar to be negative but set error flag
tbar = 1.0 - temperature / tcrit

# Critical current density (A/m2)
jcrit = c0 * (1.0 - bratio) * tbar

# if ((temperature > tcrit).or.(bmax > bc20max))then
# write(*,*)'jcrit_nbti: out of range: ', 'bmax =', bmax, ' bc20max =', bc20max, &
# ' temperature =',temperature, ' tcrit =',tcrit
# end if

return jcrit, tcrit
53 changes: 0 additions & 53 deletions source/fortran/superconductors.f90
Original file line number Diff line number Diff line change
Expand Up @@ -206,59 +206,6 @@ subroutine bi2212(bmax,jstrand,tsc,fhts,jcrit,tmarg)
end if

end subroutine bi2212
!------------------------------------------------------------------
subroutine jcrit_nbti(temperature,bmax,c0,bc20max,tc0max,jcrit,tcrit)

!! Critical current density in a NbTi superconductor strand
!! author: P J Knight, CCFE, Culham Science Centre
!! temperature : input real : SC temperature (K)
!! bmax : input real : Magnetic field at conductor (T)
!! c0 : input real : Scaling constant (A/m2)
!! bc20max : input real : Upper critical field (T) for superconductor
!! at zero temperature and strain
!! tc0max : input real : Critical temperature (K) at zero field and strain
!! jcrit : output real : Critical current density in superconductor (A/m2)
!! tcrit : output real : Critical temperature (K)
!! This routine calculates the critical current density and
!! temperature in superconducting TF coils using NbTi
!! as the superconductor.
!! None
!
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

use constants, only: pi
implicit none

! Arguments
real(dp), intent(in) :: temperature, bmax, c0, bc20max, tc0max
real(dp), intent(out) :: jcrit, tcrit

! Local variables
real(dp) :: bratio, tbar
!-----------------------------------
bratio = bmax/bc20max

if (bmax < bc20max) then
! Critical temperature (K)
tcrit = tc0max * (1.0D0 - bratio)**0.59D0
else
! Allow bmax > bc20max but set error flag
! Fudge to give real (negative) value if bratio < 1
tcrit = tc0max * (1.0D0 - bratio)
end if

! Allow tbar to be negative but set error flag
tbar = 1.0D0 - temperature/tcrit

! Critical current density (A/m2)
jcrit = c0 * (1.0D0 - bratio) * tbar

! if ((temperature > tcrit).or.(bmax > bc20max))then
! write(*,*)'jcrit_nbti: out of range: ', 'bmax =', bmax, ' bc20max =', bc20max, &
! ' temperature =',temperature, ' tcrit =',tcrit
! end if

end subroutine jcrit_nbti
!--------------------------------------------------------------------
subroutine GL_nbti(thelium,bmax,strain,bc20max,t_c0,jcrit,bcrit,tcrit)

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_superconductors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from typing import NamedTuple, Any

from process.fortran import superconductors as superconductorsf90
import process.superconductors as superconductors


Expand Down Expand Up @@ -128,7 +127,7 @@ def test_jcrit_nbti(jcritnbtiparam, monkeypatch):
:type monkeypatch: _pytest.monkeypatch.monkeypatch
"""

jcrit, tcrit = superconductorsf90.jcrit_nbti(
jcrit, tcrit = superconductors.jcrit_nbti(
temperature=jcritnbtiparam.temperature,
bmax=jcritnbtiparam.bmax,
c0=jcritnbtiparam.c0,
Expand Down

0 comments on commit 284ad9d

Please sign in to comment.