Skip to content

Commit 7f12115

Browse files
authored
Merge pull request #130 from freegs-plasma/fix-scipy-deprecation
Replace remove `interp2d` with `RectBivariateSpline`
2 parents de6ae95 + 358fab4 commit 7f12115

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

freegs/equilibrium.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def _updateBoundaryPsi(self, psi=None):
559559
Z = np.asarray(self.Z[0, :])
560560

561561
# psi is transposed due to how FreeGS meshgrids R,Z
562-
psi_2d = interpolate.interp2d(x=R, y=Z, z=psi.T)
562+
psi_2d = interpolate.RectBivariateSpline(x=R, y=Z, z=psi.T)
563563

564564
# Get psi at the limit points
565565
psi_limit_points = np.zeros(len(Rlimit))
@@ -1414,13 +1414,11 @@ def newDomain(eq, Rmin=None, Rmax=None, Zmin=None, Zmax=None, nx=None, ny=None):
14141414

14151415
tck = interpolate.bisplrep(ravel(eq.R), ravel(eq.Z), ravel(psi))
14161416
spline = interpolate.RectBivariateSpline(eq.R[:, 0], eq.Z[0, :], psi)
1417-
f = interpolate.interp2d(eq.R[:, 0], eq.Z[0, :], psi, kind="cubic")
14181417

14191418
plt.plot(eq.R[:, 10], psi[:, 10], "o")
14201419

14211420
r = linspace(Rmin, Rmax, 1000)
14221421
z = eq.Z[0, 10]
1423-
plt.plot(r, f(r, z), label="f")
14241422

14251423
plt.plot(r, spline(r, z), label="spline")
14261424

freegs/test_equilibrium.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from . import boundary
33
from . import jtor
44
from . import picard
5+
from .machine import TestTokamak
56

67
import numpy as np
78

@@ -51,6 +52,38 @@ def test_fixed_boundary_psi():
5152
assert eq.poloidalBeta() > 0.0
5253

5354

55+
def test_fixed_boundary_psi_check_limited():
56+
# This is adapted from example 5
57+
58+
tokamak = TestTokamak()
59+
60+
eq = equilibrium.Equilibrium(
61+
tokamak=tokamak,
62+
Rmin=0.1,
63+
Rmax=2.0,
64+
Zmin=-1.0,
65+
Zmax=1.0,
66+
nx=65,
67+
ny=65,
68+
boundary=boundary.fixedBoundary,
69+
check_limited=True,
70+
)
71+
72+
profiles = jtor.ConstrainPaxisIp(
73+
eq, 1e3, 1e5, 1.0 # Plasma pressure on axis [Pascals] # Plasma current [Amps]
74+
) # fvac = R*Bt
75+
76+
# Nonlinear solve
77+
picard.solve(eq, profiles)
78+
79+
psi = eq.psi()
80+
assert psi[0, 0] == 0.0 # Boundary is fixed
81+
assert psi[32, 32] != 0.0 # Solution is not all zero
82+
83+
assert eq.psi_bndry == 0.0
84+
assert eq.poloidalBeta() > 0.0
85+
86+
5487
def test_setSolverVcycle():
5588
eq = equilibrium.Equilibrium(Rmin=0.1, Rmax=2.0, Zmin=-1.0, Zmax=1.0, nx=65, ny=65)
5689

0 commit comments

Comments
 (0)