@@ -347,6 +347,8 @@ def __init__(
347347 psi1D ,
348348 fpol1D ,
349349 pressure = None ,
350+ fprime = None ,
351+ pprime = None ,
350352 wall = None ,
351353 psi_axis_gfile = None ,
352354 psi_bdry_gfile = None ,
@@ -370,6 +372,8 @@ def __init__(
370372 --------
371373
372374 pressure[nf] = 1D array of pressure as a function of psi1D [Pa]
375+ fprime[nf] = 1D array of df / dpsi
376+ pprime[nf] = 1D array of dp / dpsi . If set then pressure must also be set.
373377
374378 wall = [(R0,Z0), (R1, Z1), ...]
375379 A list of coordinate pairs, defining the vessel wall.
@@ -392,6 +396,9 @@ def __init__(
392396
393397 """
394398
399+ if pprime is not None :
400+ assert pressure is not None
401+
395402 self .user_options = self .user_options_factory .create (settings )
396403
397404 if self .user_options .reverse_current :
@@ -439,12 +446,22 @@ def __init__(
439446 # fpol constant in SOL
440447 fpol1D = np .concatenate ([fpol1D , np .full (psiSOL .shape , fpol1D [- 1 ])])
441448
449+ if fprime is not None :
450+ fprime = np .concatenate ([fprime , np .full (psiSOL .shape , 0.0 )])
451+
442452 if pressure is not None :
443453 # Use an exponential decay for the pressure, based on
444454 # the value and gradient at the plasma edge
445455 p0 = pressure [- 1 ]
446456 # p = p0 * exp( (psi - psi0) * dpdpsi / p0)
447- pressure = np .concatenate ([pressure , p0 * np .exp (psiSOL * dpdpsi / p0 )])
457+ pressure = np .concatenate (
458+ [pressure , p0 * np .exp ((psiSOL - psi1D [- 1 ]) * dpdpsi / p0 )]
459+ )
460+
461+ if pprime is not None :
462+ pprime = np .concatenate (
463+ [pprime , dpdpsi * np .exp ((psiSOL - psi1D [- 1 ]) * dpdpsi / p0 )]
464+ )
448465
449466 self .magneticFunctionsFromGrid (
450467 R1D , Z1D , psi2D , self .user_options .psi_interpolation_method
@@ -464,19 +481,32 @@ def __init__(
464481 # ext=3 specifies that boundary values are used outside range
465482
466483 # Spline representing the derivative of f
467- self .fprime_spl = self .f_spl .derivative ()
484+ if fprime is not None :
485+ self .fprime_spl = interpolate .InterpolatedUnivariateSpline (
486+ psi1D * self .f_psi_sign , fprime , ext = 3
487+ )
488+ else :
489+ self .fprime_spl = self .f_spl .derivative ()
468490 else :
469- self .f_spl = lambda psi : 0.0
470- self .fprime_spl = lambda psi : 0.0
491+ self .f_spl = lambda psi : 0.0 * psi
492+ self .fprime_spl = lambda psi : 0.0 * psi
471493
472494 # Optional pressure profile
473495 if pressure is not None :
474496 self .p_spl = interpolate .InterpolatedUnivariateSpline (
475497 psi1D * self .f_psi_sign , pressure , ext = 3
476498 )
499+
500+ if pprime is not None :
501+ self .pprime_spl = interpolate .InterpolatedUnivariateSpline (
502+ psi1D * self .f_psi_sign , pprime , ext = 3
503+ )
504+ else :
505+ self .pprime_spl = self .p_spl .derivative ()
477506 else :
478507 # If no pressure, then not output to grid file
479508 self .p_spl = None
509+ self .pprime_spl = None
480510
481511 # Find critical points (O- and X-points)
482512 R2D , Z2D = np .meshgrid (R1D , Z1D , indexing = "ij" )
@@ -506,6 +536,8 @@ def __init__(
506536
507537 if len (xpoints ) == 0 :
508538 warnings .warn ("No X-points found in TokamakEquilibrium input" )
539+ self .psi_bdry = psi_bdry_gfile
540+ self .psi_bdry_gfile = psi_bdry_gfile
509541 else :
510542 self .psi_bdry = xpoints [0 ][2 ] # Psi on primary X-point
511543 self .x_point = Point2D (xpoints [0 ][0 ], xpoints [0 ][1 ])
@@ -1685,9 +1717,14 @@ def createRegionObjects(self, all_regions, segments):
16851717 eqreg .pressure = lambda psi : self .pressure (
16861718 leg_psi + sign * abs (psi - leg_psi )
16871719 )
1720+ # Set pprime and fprime to zero so Jpar0 = 0
1721+ eqreg .pprime = lambda psi : 0.0
1722+ eqreg .fprime = lambda psi : 0.0
16881723 else :
1689- # Core region, so use the core pressure
1724+ # Core region, so use the core profiles
16901725 eqreg .pressure = self .pressure
1726+ eqreg .pprime = self .pprime
1727+ eqreg .fprime = self .fpolprime
16911728
16921729 region_objects [name ] = eqreg
16931730 # The region objects need to be sorted, so that the
@@ -1741,8 +1778,17 @@ def fpol(self, psi):
17411778
17421779 @Equilibrium .handleMultiLocationArray
17431780 def fpolprime (self , psi ):
1744- """psi-derivative of fpol"""
1745- return self .fprime_spl (psi * self .f_psi_sign )
1781+ """psi-derivative of fpol
1782+ Note: Zero outside core."""
1783+ fprime = self .fprime_spl (psi * self .f_psi_sign )
1784+ if self .psi_bdry is not None :
1785+ psinorm = (psi - self .psi_axis ) / (self .psi_bdry - self .psi_axis )
1786+ if np .isscalar (psi ):
1787+ if psinorm > 1.0 :
1788+ fprime = 0.0
1789+ else :
1790+ fprime [psinorm > 1.0 ] = 0.0
1791+ return fprime
17461792
17471793 @Equilibrium .handleMultiLocationArray
17481794 def pressure (self , psi ):
@@ -1751,6 +1797,21 @@ def pressure(self, psi):
17511797 return None
17521798 return self .p_spl (psi * self .f_psi_sign )
17531799
1800+ @Equilibrium .handleMultiLocationArray
1801+ def pprime (self , psi ):
1802+ """psi-derivative of plasma pressure
1803+ Note: Zero outside the core"""
1804+ if self .pprime_spl is None :
1805+ return None
1806+ pprime = self .pprime_spl (psi * self .f_psi_sign )
1807+ if self .psi_bdry is not None :
1808+ psinorm = (psi - self .psi_axis ) / (self .psi_bdry - self .psi_axis )
1809+ if np .isscalar (psi ) and psinorm > 1.0 :
1810+ pprime = 0.0
1811+ else :
1812+ pprime [psinorm > 1.0 ] = 0.0
1813+ return pprime
1814+
17541815 @property
17551816 def Bt_axis (self ):
17561817 """Calculate toroidal field on axis"""
@@ -1815,6 +1876,8 @@ def read_geqdsk(
18151876
18161877 pressure = data ["pres" ]
18171878 fpol = data ["fpol" ]
1879+ fprime = data ["ffprime" ] / fpol
1880+ pprime = data ["pprime" ]
18181881
18191882 # Call __new__() first in case there is an exception in __init__(), we can still
18201883 # return a partially-initialised TokamakEquilibrium object
@@ -1840,6 +1903,8 @@ def read_geqdsk(
18401903 psi_bdry_gfile = psi_bdry_gfile ,
18411904 psi_axis_gfile = psi_axis_gfile ,
18421905 pressure = pressure ,
1906+ fprime = fprime ,
1907+ pprime = pprime ,
18431908 wall = wall ,
18441909 make_regions = make_regions ,
18451910 settings = settings ,
0 commit comments