Skip to content

Commit

Permalink
Add typing hinting and docstrings for majority of codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Jun 28, 2024
1 parent 1be97cd commit 24bea62
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 92 deletions.
150 changes: 121 additions & 29 deletions src/fusiondls/AnalyticCoolingCurves.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import numpy as np
from scipy import interpolate
from collections.abc import Callable

from .typing import PathLike

def LfuncN(T):
"""Nitrogen based cooling curve used in Lipschultz 2016"""

def LfuncN(T: float) -> float:
"""Nitrogen based cooling curve used in Lipschultz 2016
Parameters
----------
T:
Temperature [eV]
"""
answer = 0
if T >= 1 and T <= 80:
answer = 5.9e-34 * (T - 1) ** (0.5)
Expand All @@ -14,8 +23,14 @@ def LfuncN(T):
return answer


def LfuncNe(T):
"""Ne based cooling curve produced by Matlab polynominal curve fitting "polyval" (Ryoko 2020 Nov)"""
def LfuncNe(T: float) -> float:
"""Ne based cooling curve produced by Matlab polynominal curve fitting "polyval" (Ryoko 2020 Nov)
Parameters
----------
T:
Temperature [eV]
"""
answer = 0
if T >= 3 and T <= 100:
answer = (
Expand All @@ -35,8 +50,14 @@ def LfuncNe(T):
return answer


def LfuncAr(T):
"""Ar based cooling curve produced by Matlab polynominal curve fitting "polyval" (Ryoko 2020 Nov)"""
def LfuncAr(T: float) -> float:
"""Ar based cooling curve produced by Matlab polynominal curve fitting "polyval" (Ryoko 2020 Nov)
Parameters
----------
T:
Temperature [eV]
"""
answer = 0
if T >= 1.5 and T <= 100:
answer = (
Expand All @@ -59,8 +80,14 @@ def LfuncAr(T):
return answer


def LfuncKallenbachN(T):
"""Nitrogen, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3"""
def LfuncKallenbachN(T: float) -> float:
"""Nitrogen, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3
Parameters
----------
T:
Temperature [eV]
"""
if T >= 1 and T < 5:
Lz = np.poly1d(
[
Expand Down Expand Up @@ -126,8 +153,14 @@ def LfuncKallenbachN(T):
return Lz


def LfuncKallenbachAr(T):
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3"""
def LfuncKallenbachAr(T: float) -> float:
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3
Parameters
----------
T:
Temperature [eV]
"""
if T >= 1 and T < 5:
Lz = np.poly1d(
[
Expand Down Expand Up @@ -193,8 +226,14 @@ def LfuncKallenbachAr(T):
return Lz


def LfuncKallenbachAr100B(T):
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3"""
def LfuncKallenbachAr100B(T: float) -> float:
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3
Parameters
----------
T:
Temperature [eV]
"""
if T >= 1 and T < 5:
Lz = np.poly1d(
[
Expand Down Expand Up @@ -277,8 +316,14 @@ def LfuncKallenbachAr100B(T):
return Lz


def LfuncKallenbachAr200(T):
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3"""
def LfuncKallenbachAr200(T: float) -> float:
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3
Parameters
----------
T:
Temperature [eV]
"""
if T >= 1 and T < 5:
Lz = np.poly1d(
[
Expand Down Expand Up @@ -344,8 +389,14 @@ def LfuncKallenbachAr200(T):
return Lz


def LfuncKallenbachAr100(T):
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3"""
def LfuncKallenbachAr100(T: float) -> float:
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3
Parameters
----------
T:
Temperature [eV]
"""
if T >= 1 and T < 5:
Lz = np.poly1d(
[
Expand Down Expand Up @@ -411,8 +462,14 @@ def LfuncKallenbachAr100(T):
return Lz


def LfuncKallenbachAr150(T):
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3"""
def LfuncKallenbachAr150(T: float) -> float:
"""Argon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3
Parameters
----------
T:
Temperature [eV]
"""
if T >= 1 and T < 5:
Lz = np.poly1d(
[
Expand Down Expand Up @@ -478,8 +535,14 @@ def LfuncKallenbachAr150(T):
return Lz


def LfuncKallenbachNe(T):
"""Neon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3"""
def LfuncKallenbachNe(T: float) -> float:
"""Neon, Tau = 1ms, Kallenbach 2018, xlsx from David Moulton, units W/m3
Parameters
----------
T:
Temperature [eV]
"""
if T >= 1 and T < 5:
Lz = np.poly1d(
[
Expand Down Expand Up @@ -548,7 +611,8 @@ def LfuncKallenbachNe(T):
from scipy import interpolate


def LfuncKallenbach(species_choice):
def LfuncKallenbach(species_choice: str) -> Callable[[float], float]:

radiation = dict()

# Temperature array
Expand Down Expand Up @@ -1396,14 +1460,32 @@ def LfuncKallenbach(species_choice):
return Lfunc


def LfunLengFunccGauss(T, width=2):
"""Custom gaussian impurity cooling curve if desired"""
def LfunLengFunccGauss(T: float, width: float = 2) -> float:
"""Custom gaussian impurity cooling curve if desired
Parameters
----------
T:
Temperature [eV]
width:
Gaussian width [eV^2]
"""
return 1e-31 * np.exp(-((T - 5) ** 2) / (width))


def ratesAmjul(file, T, n):
"""Reader for AMJUL files"""
rawdata = np.loadtxt(file)
def ratesAmjul(filename: PathLike, T: float, n: float) -> float:
"""Reader for AMJUL files
Parameters
----------
filename:
Path to AMJUL file
T:
Temperature [eV]
n:
Density (FIXME)
"""
rawdata = np.loadtxt(filename)
unpackedData = []
counter = 0
rates = 0
Expand All @@ -1423,9 +1505,19 @@ def ratesAmjul(file, T, n):
return rates * 1e-6


def ratesAmjulCX(file, T, E):
"""Reader for AMJUL CX files"""
rawdata = np.loadtxt(file)
def ratesAmjulCX(filename: PathLike, T: float, E: float) -> float:
"""Reader for AMJUL CX files
Parameters
----------
filename:
Path to AMJUL file
T:
Temperature [eV]
E:
Energy (FIXME)
"""
rawdata = np.loadtxt(filename)
unpackedData = []
counter = 0
rates = 0
Expand Down
10 changes: 6 additions & 4 deletions src/fusiondls/Analytic_DLS.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ def CfInt(spar, B_field, sx, L, sh=0, kappa1=2500):
spar, B_field, kind="cubic", fill_value="extrapolate"
)
# calculate Tu/qpll**(2/7) by integrating over heat flux density
Tu = quad(integrand, sh, sx, args=(sx, L, B_field), epsabs=0.0000000000000000001)[0]
Tu = quad(_integrand, sh, sx, args=(sx, L, B_field), epsabs=0.0000000000000000001)[
0
]
if sx < L:
Tu = (
Tu
+ quad(
integrand2, sx, L, args=(sx, L, B_field), epsabs=0.0000000000000000001
_integrand2, sx, L, args=(sx, L, B_field), epsabs=0.0000000000000000001
)[0]
)
Tu = (Tu * 7 / (2 * kappa1)) ** (-2 / 7)
Expand All @@ -50,9 +52,9 @@ def CfInt(spar, B_field, sx, L, sh=0, kappa1=2500):
return Cf


def integrand(s, sx, L, B_field):
def _integrand(s, sx, L, B_field):
return B_field(s) / B_field(sx)


def integrand2(s, sx, L, B_field):
def _integrand2(s, sx, L, B_field):
return (L - s) * (B_field(s) / B_field(sx)) / (L - sx)
Loading

0 comments on commit 24bea62

Please sign in to comment.