Skip to content

Commit

Permalink
Merge branch 'main' into tidy-up-rebase
Browse files Browse the repository at this point in the history
* main:
  Use `scipy.integrate.trapezoid` instead of `numpy.trapezoid`
  • Loading branch information
ZedThree committed Aug 6, 2024
2 parents 745cdaa + facd309 commit f1a6674
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/fusiondls/Iterate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from scipy.integrate import solve_ivp
from scipy.integrate import solve_ivp, trapezoid


def LengFunc(s, y, si, st):
Expand Down Expand Up @@ -80,15 +80,15 @@ def iterate(si, st):
st.cz = si.cz0
st.nu = st.cvar

st.qradial = (si.qpllu0 / si.Btot[si.Xpoint]) / np.trapezoid(
st.qradial = (si.qpllu0 / si.Btot[si.Xpoint]) / trapezoid(
1 / si.Btot[si.Xpoint :], x=si.S[si.Xpoint :]
)

if si.control_variable == "power":
st.cz = si.cz0
st.nu = si.nu0
# This is needed so that too high a cvar gives positive error
st.qradial = (1 / st.cvar / si.Btot[si.Xpoint]) / np.trapezoid(
st.qradial = (1 / st.cvar / si.Btot[si.Xpoint]) / trapezoid(
1 / si.Btot[si.Xpoint :], x=si.S[si.Xpoint :]
)

Expand Down
8 changes: 4 additions & 4 deletions src/fusiondls/LRBv21.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
from scipy import interpolate
from scipy.integrate import cumulative_trapezoid
from scipy.integrate import cumulative_trapezoid, trapezoid

from .DLScommonTools import pad_profile
from .Iterate import iterate
Expand Down Expand Up @@ -371,8 +371,8 @@ def run_dls(
# nu0 and cz0 guesses are from Lengyel which depends on an estimate of Tu using qpllu0
# This means we cannot make a more clever guess for qpllu0 based on cz0 or nu0
qpllu0_guess = si.qpllu0
# qradial_guess = qpllu0_guess / np.trapezoid(si.Btot[si.Xpoint:] / si.Btot[si.Xpoint], x = si.S[si.Xpoint:])
qradial_guess = (qpllu0_guess / si.Btot[si.Xpoint]) / np.trapezoid(
# qradial_guess = qpllu0_guess / trapezoid(si.Btot[si.Xpoint:] / si.Btot[si.Xpoint], x = si.S[si.Xpoint:])
qradial_guess = (qpllu0_guess / si.Btot[si.Xpoint]) / trapezoid(
1 / si.Btot[si.Xpoint :], x=si.S[si.Xpoint :]
)
st.cvar = 1 / qradial_guess
Expand All @@ -396,7 +396,7 @@ def run_dls(
# Upstream conditions
st.nu = si.nu0
st.cz = si.cz0
st.qradial = (si.qpllu0 / si.Btot[si.Xpoint]) / np.trapezoid(
st.qradial = (si.qpllu0 / si.Btot[si.Xpoint]) / trapezoid(
1 / si.Btot[si.Xpoint :], x=si.S[si.Xpoint :]
)

Expand Down
5 changes: 3 additions & 2 deletions src/fusiondls/Profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
from scipy.integrate import trapezoid


class Profile:
Expand Down Expand Up @@ -71,7 +72,7 @@ def get_gradB_integral(self):
Return the integral of the fractional Btot gradient
below the X-point
"""
return np.trapezoid(
return trapezoid(
(np.gradient(self.Btot, self.Spol) / self.Btot)[: self.Xpoint],
self.Spol[: self.Xpoint],
)
Expand All @@ -88,7 +89,7 @@ def get_Bpitch_integral(self):
Return the integral of the pitch angle Bpol/Btot
below the X-point
"""
return np.trapezoid(
return trapezoid(
(self.Bpol / self.Btot)[: self.Xpoint], self.Spol[: self.Xpoint]
)

Expand Down

0 comments on commit f1a6674

Please sign in to comment.