Skip to content

Commit 6bfb340

Browse files
committed
Merge branch 'optimizing'
2 parents 4a0ee8d + 70bfda2 commit 6bfb340

File tree

5 files changed

+121
-40
lines changed

5 files changed

+121
-40
lines changed

langmuir/finite_length.py

Lines changed: 91 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from langmuir.geometry import *
2525
from langmuir.species import *
2626
from langmuir.misc import *
27-
from scipy.interpolate import griddata
27+
from scipy.interpolate import griddata, RectBivariateSpline
2828
from scipy.constants import value as constants
2929
from copy import deepcopy
3030
import numpy as np
@@ -101,7 +101,7 @@ def finite_length_current_density(geometry, species, V=None, eta=None,
101101
eta_isarray = isinstance(eta, (np.ndarray, list, tuple))
102102
eta = make_array(eta)
103103

104-
eta = eta[:, None] # Make eta rows
104+
# eta = eta[:, None] # Make eta rows
105105

106106
if not isinstance(geometry, Cylinder):
107107
raise ValueError('Geometry not supported: {}'.format(geometry))
@@ -124,6 +124,13 @@ def finite_length_current_density(geometry, species, V=None, eta=None,
124124

125125
C, A, alpha, delta = get_lerped_coeffs(lambd_t, eta)
126126

127+
# Make these column vectors, i.e. one eta per row
128+
C = C[:, None]
129+
A = A[:, None]
130+
alpha = alpha[:, None]
131+
delta = delta[:, None]
132+
eta = eta[:, None]
133+
127134
if normalization is None: # i0 = i_OML => i = i_OML * g
128135
geonorm = deepcopy(geometry)
129136
geonorm.l = 1
@@ -253,47 +260,97 @@ def H(zeta):
253260

254261
return I if eta_isarray else I[0]
255262

256-
def get_lerped_coeffs(lambd, eta):
257-
"""
258-
Fetches and interpolates Marholm-Marchand coefficients.
263+
# def get_lerped_coeffs(lambd, eta):
264+
# """
265+
# Fetches and interpolates Marholm-Marchand coefficients.
259266

260-
Parameters
261-
----------
262-
lambd: float
263-
Normalized probe length (lambda) to get coefficients for
267+
# Parameters
268+
# ----------
269+
# lambd: float
270+
# Normalized probe length (lambda) to get coefficients for
264271

265-
eta: float
266-
Normalized probe voltage (eta) to get coefficients for
272+
# eta: float
273+
# Normalized probe voltage (eta) to get coefficients for
267274

268-
Returns
269-
-------
270-
4-tuple of coefficients (C, A, alpha, delta)
271-
"""
275+
# Returns
276+
# -------
277+
# 4-tuple of coefficients (C, A, alpha, delta)
278+
# """
272279

273-
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),'params.npz')
274-
file = np.load(fname)
280+
# fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),'params.npz')
281+
# file = np.load(fname)
282+
283+
# lambds = file['lambds']
284+
# etas = file['etas']
285+
# Cs = file['Cs']
286+
# As = file['As']
287+
# alphas = file['alphas']
288+
# deltas = file['deltas']
289+
290+
# # Extrapolate for larger lambda by using the largest available
291+
# lambd_coeff = min(lambd, max(lambds))
292+
293+
# # Tabulated values contains datapoints as described in paper
294+
# C = griddata((lambds, etas), Cs , (lambd_coeff, eta))
295+
# A = griddata((lambds, etas), As , (lambd_coeff, eta))
296+
# alpha = griddata((lambds, etas), alphas, (lambd_coeff, eta))
297+
# delta = griddata((lambds, etas), deltas, (lambd_coeff, eta))
298+
299+
# # Make repelled species identical to OML through these coefficients
300+
# ind = np.where(eta>=0)[0]
301+
# C[ind] = 1
302+
# A[ind] = 0
303+
# alpha[ind] = 1
304+
# delta[ind] = 1
305+
306+
# return C, A, alpha, delta
275307

308+
class lerper(RectBivariateSpline):
309+
def __init__(self, coeffname, degree=1):
310+
311+
assert coeffname in ['C', 'A', 'alpha', 'delta']
312+
coeffname += 's'
313+
314+
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),'params_structured.npz')
315+
file = np.load(fname)
316+
317+
lambds = file['lambds']
318+
etas = file['etas']
319+
coeff = file[coeffname]
320+
321+
super(lerper, self).__init__(lambds, etas, coeff, kx=degree, ky=degree)
322+
323+
def get_max_lambd():
324+
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),'params_structured.npz')
325+
file = np.load(fname)
276326
lambds = file['lambds']
277-
etas = file['etas']
278-
Cs = file['Cs']
279-
As = file['As']
280-
alphas = file['alphas']
281-
deltas = file['deltas']
327+
return max(lambds)
282328

283-
# Extrapolate for larger lambda by using the largest available
284-
lambd_coeff = min(lambd, max(lambds))
329+
lerp_C = lerper('C')
330+
lerp_A = lerper('A')
331+
lerp_alpha = lerper('alpha')
332+
lerp_delta = lerper('delta')
333+
max_lambd = get_max_lambd()
285334

286-
# Tabulated values contains datapoints as described in paper
287-
C = griddata((lambds, etas), Cs , (lambd_coeff, eta))
288-
A = griddata((lambds, etas), As , (lambd_coeff, eta))
289-
alpha = griddata((lambds, etas), alphas, (lambd_coeff, eta))
290-
delta = griddata((lambds, etas), deltas, (lambd_coeff, eta))
335+
def get_lerped_coeffs_new(lambd, eta):
336+
eta = -eta
337+
338+
# Extrapolate for larger lambda by using the largest available
339+
lambd_coeff = min(lambd, max_lambd)
291340

292341
# Make repelled species identical to OML through these coefficients
293-
ind = np.where(eta>=0)[0]
294-
C[ind] = 1
295-
A[ind] = 0
296-
alpha[ind] = 1
297-
delta[ind] = 1
342+
C = np.ones_like(eta)
343+
A = np.zeros_like(eta)
344+
alpha = np.ones_like(eta)
345+
delta = np.ones_like(eta)
346+
347+
# Tabulated values contains datapoints as described in paper
348+
ind = np.where(eta>0)[0]
349+
C[ind] = lerp_C(lambd_coeff, eta[ind], grid=False)
350+
A[ind] = lerp_A(lambd_coeff, eta[ind], grid=False)
351+
alpha[ind] = lerp_alpha(lambd_coeff, eta[ind], grid=False)
352+
delta[ind] = lerp_delta(lambd_coeff, eta[ind], grid=False)
298353

299354
return C, A, alpha, delta
355+
356+
get_lerped_coeffs=get_lerped_coeffs_new

langmuir/params_structured.npz

4.28 KB
Binary file not shown.

langmuir/species.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
from scipy.constants import value as constants
23+
from langmuir.misc import *
2324
import numpy as np
2425

2526
class Species(object):
@@ -109,6 +110,11 @@ def __init__(self, *args, **kwargs):
109110
else:
110111
self.T = kwargs['T']
111112

113+
if self.T<0:
114+
self.T=0
115+
logger.warning('Negative temperature interpreted as zero')
116+
117+
112118
self.vth = np.sqrt(k*self.T/self.m)
113119
self.eV = self.T*k/e
114120
self.omega_p = np.sqrt(self.q**2*self.n/(eps0*self.m))

langmuir/test_finite_length.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,16 @@ def test_current_interpolated_samples():
197197
r = 1e-3
198198
ls = np.array([7, 70, 700], dtype=np.float)*1e-3
199199
etas = np.array([65, 1, 90], dtype=np.float)
200-
Ifs = np.array([-6.2794005496528275e-06,
201-
-1.9760221828553347e-06,
202-
-0.00014456804182897328])
200+
201+
# Ground truth when using scipy.interpolate.griddata
202+
# Ifs = np.array([-6.2794005496528275e-06,
203+
# -1.9760221828553347e-06,
204+
# -0.00014456804182897328])
205+
206+
# Ground truth when using 1st order scipy.interpolate.RectBivariateSpline
207+
Ifs = np.array([-6.439906296987808e-06,
208+
-1.9562053783242e-06,
209+
-0.00014420124702985558])
203210

204211
for l, eta, If in zip(ls, etas, Ifs):
205212
geo = Cylinder(r=r, l=l)
@@ -217,9 +224,16 @@ def test_current_density_interpolated_samples():
217224
ls = np.array([7, 70, 700], dtype=np.float)*1e-3
218225
etas = np.array([65, 1, 90], dtype=np.float)
219226
zs = np.array([0, .4, .29, 1])
220-
Ifs = np.array([[-0.00045615, -0.00106614, -0.00099727, -0.00045615],
221-
[-2.92817683e-05, -2.75155255e-05, -2.76705163e-05, -2.92817683e-05],
222-
[-0.00036732, -0.00019135, -0.00019135, -0.00036732]])
227+
228+
# Ground truth when using scipy.interpolate.griddata
229+
# Ifs = np.array([[-0.00045615, -0.00106614, -0.00099727, -0.00045615],
230+
# [-2.92817683e-05, -2.75155255e-05, -2.76705163e-05, -2.92817683e-05],
231+
# [-0.00036732, -0.00019135, -0.00019135, -0.00036732]])
232+
233+
# Ground truth when using 1st order scipy.interpolate.RectBivariateSpline
234+
Ifs = np.array([[-0.00054336, -0.00105909, -0.00100473, -0.00054336],
235+
[-2.89516395e-05, -2.72642938e-05, -2.74123613e-05, -2.89516395e-05],
236+
[-0.00036957, -0.00019082, -0.00019082, -0.00036957]])
223237

224238
for l, eta, If in zip(ls, etas, Ifs):
225239
geo = Cylinder(r=r, l=l)

langmuir/test_species.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ def test_debye():
151151
plasma.append(Species('proton', n=1e11, T=1000))
152152
assert(debye(plasma[0])==plasma[0].debye)
153153
assert(debye(plasma) == approx(0.004879671013271479))
154+
155+
def test_negative_temperature(caplog):
156+
sp = Species(n=1e11, T=-1)
157+
assert(caplog.records[0].levelname == 'WARNING')

0 commit comments

Comments
 (0)