-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchebSolver.py
More file actions
2009 lines (1584 loc) · 81.4 KB
/
chebSolver.py
File metadata and controls
2009 lines (1584 loc) · 81.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import numpy as np
import numpy.polynomial.chebyshev as cheb
import time
from Liu2014Properties import setLiu2014Properties
from psaapPropertiesTestArm import setPsaapPropertiesTestArm
from psaapPropertiesTestArmInterpTrans import setPsaapPropertiesTestArmInterpTrans
from psaapProperties_6Species_Nominal import setPsaapProperties_6Species_Nominal
class modelClosures:
"""Class providing model parameters."""
def __init__(self, Ns, Nr):
"""Set model parameter values. These values are non-dimensionalized
using the following quantities:
L: the half-gap-width of the device
\tau: the period of the driving RF voltage
V_0: the amplitude of the driving RF voltage
n_b: the "background" number density
n_0: the "nominal" electron number density
e_0: the "nominal" electron energy
The non-dimensional parameters provided by the class are
mue: Electron mobility
mu_e^{\ast} = \frac{mu_e V_0 \tau}{L^2}
mui: Ion mobility (non-dimensionalized same as mue)
De: Electron diffusivity
D_e^{\ast} = \frac{D_e \tau}{L^2}
Di: Ion diffusivity (non-dimensionalized same as Di)
Ck: Ionization rate pre-exponential factor
C_k^{\ast} = C_k \tau n_b
A: Ionization rate "activation energy"
A^{\ast} = A / e_0
dH: Energy lost per electron in ionization reaction
dH^{\ast} = dH / e_0
qStar: Multiplier in front of Joule heating term (denoted
qStar since it takes place of unit charge in dimensional
equations)
qStar = \frac{q_e V_0}{e_0} (where q_e is unit charge)
alpha: Multiplier in Poisson eqn (Gauss' law)
\alpha = \frac{q_e n_p L^2}{V_0 \epsilon_0}
(where \epsilon_0 is permittivity of free space)
"""
self.Ns = Ns # number of species
self.Nr = Nr # number of reactions
# charge number
self.Z = np.zeros(Ns)
self.Z[0] = -1 # electrons are always -1
self.Z[1] = 1 # ions are always 1
self.Z[2] = 0 # background specie should be 0
# mobility
self.mu = np.zeros(Ns)
# diffusivity
self.D = np.zeros(Ns)
# reaction rate data
# Modified Arrhenius rxn rate coefficients for now
# kf(T) = A*(T**B)*exp(-C/T)
self.A = np.zeros(Nr) #self.Ck = 272.0
self.B = np.zeros(Nr)
self.C = np.zeros(Nr) #18.687*(3./2.);
# energy gain/loss in electrons
self.dH = np.zeros(Nr) #15.7
self.dEps = np.zeros(Ns)
# stoichiometric coefficients (Ns+1 b/c we store coefficient
# for the background gas... it is only used for
# non-dimensionalization purposes)
self.beta = np.zeros((Ns,Nr),dtype=np.int64) # products
self.alfa = np.zeros((Ns,Nr),dtype=np.int64) # reactants
# this represents a single rxn: Ar+e -> Ar+ + e + e
#self.beta[0,0] = 2
#self.beta[1,0] = 1
#self.beta[2,0] = 0
#self.alfa[0,0] = 1
#self.alfa[1,0] = 0
#self.alfa[2,0] = 1
# other non-dimensional parameters
self.qStar = 100.0
self.alpha = 2.33e3
# boundary condition parameters
self.gam = 0.01
self.ks = 6.89e-1
self.ksion = 0.0
# background specie density
self.kappaB = 4.42
self.p0 = 133.3224*1.5/1.6e-19/8e16
self.nAronp0 = 3.22e22 / 8e16
self.Tg0 = 0.038778
# coefficient for the elastic collision term
self.EC = 2.0 * 0.511e6 / 37.2158e9 * 3.8e9 * (1./13.6e6)
# DC voltage (vertical shift in the driving voltage)
self.verticalShift = 0.0
# electron energy Dirichlet BC
self.EeBC = 0.75
# Parameters needed to compute the current with dimensions
self.V0Ltau = 100 / (2.54 * 0.005 * (1./13.6e6))
self.V0L = 100 / (2.54 * 0.005)
self.LLV0tau = (2.54 * 0.005)**2 / (100 * (1./13.6e6))
self.tauL = 2.54 * 0.005 / (1./13.6e6)
self.np0 = 8e16 # "nominal" electron density [1/m^3]
self.qe = 1.6e-19 # unit charge [C]
self.eps0 = 8.86e-12 # unit charge [C]
self.eArea = np.pi * 0.05**2 # electrode area [m^2]
self.reactionsList =[]
self.diffusivityList =[]
self.mobilityList =[]
def charge(self,i):
return self.Z[i]
def mobility(self, i, energy, nb):
mu = np.zeros((nb.shape[0],1),dtype=np.float64)
if (len(self.mobilityList)>i and self.mobilityList[i].interpolate):
indFix = (energy[:,0]<=0.0)
energy[indFix,0] = 0.0
indFix = (energy[:,0]>10.0)
energy[indFix,0] = 10.0
mu = self.mobilityList[i].mu_expression((2./3)*energy[:,[i]]) / nb
else:
mu[:,0] = self.mu[i] / nb
return mu[:,0]
def mobility_U(self, i, j, energy, energy_U, mu, nb):
mu_U = np.zeros((nb.shape[0],nb.shape[0]),dtype=np.float64)
if (len(self.mobilityList) > i and self.mobilityList[i].interpolate):
indFixL = (energy[:,i]<=0.0)
energy[indFixL,i] = 0.0
energy_U[i,j,indFixL,:] = 0.0
indFixH = (energy[:,i]>10.0)
energy[indFixH,i] = 10.0
energy_U[i,j,indFixH,:] = 0.0
mu_ee = (2./3)*self.mobilityList[i].mu_T_expression((2./3)*energy[:,i]) / nb
mu_U_tmp = mu_ee * np.diag(energy_U[i,j,:,:])
mu_U[:,:] = np.diag(mu_U_tmp)
if (j == self.Ns - 1):
mu_U -= np.diag(mu[:,i] / nb)
return mu_U
def diffusivity(self, i, energy, mu, nb, EinsteinForm):
DEf = np.zeros((energy.shape[0],1),dtype=np.float64)
if (len(self.diffusivityList) > i and self.diffusivityList[i].interpolate):
indFix = (energy[:,0]<=0.0)
energy[indFix,0] = 0.0
indFix = (energy[:,0]>10.0)
energy[indFix,0] = 10.0
DEf[:,0] = self.diffusivityList[i].D_expression((2./3)*energy[:,i]) / nb
elif EinsteinForm and self.Z[i] == -1:
V0 = self.qStar * 1.0 # V0 = qStar * 1eV
DEf = 2.0 / 3.0 * np.multiply(energy[:,[i]], mu[:,[i]]) / V0
else:
DEf[:,0] = self.D[i] / nb
return DEf[:,0]
def diffusivity_U(self, i, j, energy, energy_U, mu, D, nb, EinsteinForm):
D_U = np.zeros((energy_U.shape[2], energy_U.shape[2]),dtype=np.float64)
if (len(self.diffusivityList) > i and self.diffusivityList[i].interpolate):
indFixL = (energy[:,i]<=0.0)
energy[indFixL,i] = 0.0
energy_U[i,j,indFixL,:] = 0.0
indFixH = (energy[:,i]>10.0)
energy[indFixH,i] = 10.0
energy_U[i,j,indFixH,:] = 0.0
D_ee = (2./3)*self.diffusivityList[i].D_T_expression((2./3)*energy[:,i]) / nb
D_U_tmp = D_ee * np.diag(energy_U[i,j,:,:])
D_U[:,:] = np.diag(D_U_tmp)
elif EinsteinForm and self.Z[i] == -1:
V0 = self.qStar * 1.0 # V0 = qStar * 1eV
D_U = 2.0 / 3.0 * np.multiply(mu[:,[i]], energy_U[i,j,:,:]) / V0
if (j == self.Ns - 1):
D_U[:,:] -= np.diag(D[:,i] / nb)
return D_U
def rxnSourceTerm(self, energy, density):
G = self.progressRate(energy,density)
omega = np.zeros((energy.shape[0], self.Ns+1),dtype=np.float64)
for i in range(0,self.Ns):
for j in range(0,self.Nr):
omega[:,i] += (self.reactionsList[j].rxnBeta[i,0] - self.reactionsList[j].rxnAlfa[i,0])*G[:,j]
for j in range(0,self.Nr):
omega[:,self.Ns] -= self.dH[j]*G[:,j]
return omega
def rxnSourceTermJac(self, energy, density):
G_U = self.progressRateJac(energy,density)
omega_U = np.zeros((self.Ns+1,self.Ns+1,energy.shape[0]),dtype=np.float64)
for i in range(0,self.Ns):
for j in range(0,self.Nr):
omega_U[i,:,:] += (self.reactionsList[j].rxnBeta[i,0] - self.reactionsList[j].rxnAlfa[i,0])*G_U[j,:,:]
for j in range(0,self.Nr):
omega_U[self.Ns,:,:] -= self.dH[j]*G_U[j,:,:]
return omega_U
def progressRate(self, energy, density):
G = np.zeros((energy.shape[0],self.Nr))
for i in range(0,self.Nr):
kf = self.rxnRateCoefficient(energy, i)
G[:,i] = kf[:,0]
for j in range(0,self.Ns):
if (self.reactionsList[i].rxnAlfa[j,0]>0):
G[:,i] *= density[:,j]**self.reactionsList[i].rxnAlfa[j,0]
return G
def progressRateJac(self, energy, density):
G = self.progressRate(energy,density)
G_U = np.zeros((self.Nr,self.Ns+1, energy.shape[0]))
for i in range(0,self.Nr):
kf = self.rxnRateCoefficient(energy, i)
kf_T = self.rxnRateCoefficientJac(energy,i)
#G[:,i] *= density[:,j]**self.reactionsList[i].rxnAlfa[j,0]
G_U[i,self.Ns,:] = kf_T[:,0]
for k in range(0,self.Ns):
#G_U[i,k,:] = self.reactionsList[i].rxnAlfa[k,0]*G[:,i]/density[:,k]
if (self.reactionsList[i].rxnAlfa[k,0]==0):
G_U[i,k,:] = 0
else:
G_U[i,k,:] = kf[:,0]
for j in range(0,self.Ns):
if (j==k):
G_U[i,k,:] *= self.reactionsList[i].rxnAlfa[k,0]*density[:,k]**(self.reactionsList[i].rxnAlfa[j,0]-1)
else:
G_U[i,k,:] *= density[:,j]**self.reactionsList[i].rxnAlfa[j,0]
G_U[i,self.Ns,:] *= density[:,k]**self.reactionsList[i].rxnAlfa[k,0]
#G_U[i,self.Ns,:] = kf_T[:,0]*G[:,i]/kf[:,0]
return G_U
def rxnRateCoefficient(self, energy, i):
"""Returns ionization reaction rate constant"""
indFix = (energy[:,0]<=0.0)
energy[indFix,0] = 1.0
if self.reactionsList[i].rxnBolsig:
kf = np.exp(self.reactionsList[i].kf_log(np.log(energy)))
else:
kf = self.reactionsList[i].kf(energy)
kf[indFix,0] = 0
return kf #a * (energy**b) * np.exp(-Ea/energy)
def rxnRateCoefficientJac(self, energy, i):
"""Returns derivative of ionization reaction rate constant wrt
energy
"""
indFix = (energy[:,0]<=0.0)
energy[indFix,0] = 1.0
if self.reactionsList[i].rxnBolsig:
kf_T = self.reactionsList[i].kf_T_log(np.log(energy)) \
* np.exp(self.reactionsList[i].kf_log(np.log(energy))) / energy
else:
kf_T = self.reactionsList[i].kf_T(energy)
kf_T[indFix,0] = 0
return kf_T #a * (energy**(b-1)) * np.exp(-Ea/energy) * (b + Ea/energy)
def print(self):
"""Print parameters to the screen"""
print("# The non-dimensional transport and chemstry properties are")
print("# De = {0:.6e}".format(self.D[0]))
print("# Di = {0:.6e}".format(self.D[1]))
print("# mue = {0:.6e}".format(self.mu[0]))
print("# mui = {0:.6e}".format(self.mu[1]))
print("# A = {}".format(self.A))
print("# B = {}".format(self.B))
print("# C = {}".format(self.C))
print("# dH = {}".format(self.dH))
print("# alfa = {}".format(self.alfa))
print("# beta = {}".format(self.beta))
print("# qStar = {0:.6e}".format(self.qStar))
print("# alpha = {0:.6e}".format(self.alpha))
print("# ks = {0:.6e}".format(self.ks))
print("# gam = {0:.6e}".format(self.gam))
class timeDomainCollocationSolver:
"""Provides ability to solve a drift-diffusion approximation of an RF
glow discharge device using a Chebyshev-collocation approach in
space coupled with a backward-difference-formula (BDF1 or BDF2) in
time.
Attributes:
Ns -- Number of species
NT -- Number of temperatures
Nv -- Number of state variables (Ns+NT)
Np -- Number of Chebyshev DOFs per state variable
deg -- Degree of Chebyshev polynomials (Np-1)
Ndof -- Total number of degrees of freedom
U0, U1, U2 -- State vectors necessary for BDF2 time step
phi -- Electric potential
params -- modelClosures class (provides model parameters)
xp -- Gauss-Chebyshev-Lobatto points corresponding to
Chebyshev polynomials of degree deg. The state vectors
U0,U1,U2 hold the value of the state at these points
xc -- Collocation points (allowed to different from xp for now)
"""
def __init__(self, Ns, NT, Np, elasticCollisionActivationFactor,
backgroundSpecieActivationFactor, EinsteinForm,
gam=0.01, V0 = 100.0, VDC = 0.0,
scenario=0, scheme="BE", iSample = 0):
"""Initializes storage and operaters required for solve."""
# parameters of the time marching scheme
self.temporal_scheme = scheme
if not (self.temporal_scheme in ["BE", "CN", "LCN"]):
print("ERROR: Unrecognized temporal scheme.")
print("Please use 'BE' (backward Euler), 'CN' (Crank-Nicolson), or 'LCN' (linearized Crank-Nicolson).")
exit(-1)
self.Ns = Ns # Number of species
self.NT = NT # Number of temperatures
self.Nv = Ns+NT # Total number of 'state' variables
self.deg = Np-1 # degree of Chebyshev polys we use
self.Np = Np # Number of points used to define state in space
self.Nc = Np-2 # number of collocation pts (Np-2 b/c BCs)
self.Ndof = self.Nv*self.Np # total number of dofs
# state (3 vectors for BDF2)
self.U2 = np.zeros((self.Ndof,1))
self.U1 = np.zeros((self.Ndof,1))
self.U0 = np.zeros((self.Ndof,1))
# electric potential (not part of state b/c we solve for it
# given state)
self.phi = np.zeros((self.Np,1))
# closures
if(scenario==0):
Nr = 1
elif(scenario==1):
Nr = 1
elif(scenario==2):
Nr = 8
elif(scenario==3):
Nr = 8
elif(scenario==4):
Nr = 9
elif(scenario==5):
Nr = 7
elif(scenario==6):
Nr = 23
elif(scenario==7):
Nr = 23
elif(scenario==8):
Nr = 23
elif(scenario==9):
Nr = 23
elif(scenario==10):
Nr = 34
elif(scenario==12):
Nr = 23
elif(scenario==13):
Nr = 23
elif(scenario==14):
Nr = 23
elif(scenario==16):
Nr = 23
elif(scenario==21):
Nr = 8
else:
print("ERROR: scenario = {} not understood.".format(scenario))
exit(-1)
self.elasticCollisionActivationFactor = elasticCollisionActivationFactor
self.backgroundSpecieActivationFactor = backgroundSpecieActivationFactor
self.EinsteinForm = EinsteinForm
self.params = modelClosures(self.Ns, Nr)
if(scenario==0):
setLiu2014Properties(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==1):
setPsaapProperties(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==2):
setPsaapPropertiesTestArm(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==3):
setPsaapPropertiesCurrentTestCase(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==4):
setPsaapProperties_4Species_Nominal(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==5):
setPsaapPropertiesWithSampling(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==6):
setPsaapProperties_6Species_Sampling(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==7):
setPsaapProperties_6Species_Sampling_250mTorr(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==8):
setPsaapProperties_6Species_Sampling_500mTorr(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==9):
setPsaapProperties_6Species(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==10):
setPsaapProperties_6Species_100mTorr_Expanded(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==12):
setPsaapProperties_6Species_Nominal(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==13):
setPsaapProperties_6Species_500mTorr(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==14):
setPsaapProperties_6Species_1Torr_Expanded(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==15):
setPsaapProperties_6Species_Sampling_1Torr_Expanded(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==16):
setPsaapProperties_6Species_5Torr(gam, V0, VDC, self.params, Nr, iSample)
elif(scenario==21):
setPsaapPropertiesTestArmInterpTrans(gam, V0, VDC, self.params, Nr, iSample)
# Points used to define state and collocation
# (Gauss-Lobatto-Chebyshev points)
self.xp = -np.cos(np.pi*np.linspace(0,self.deg,self.Np)/self.deg)
# Jacobian storage
self.jac = np.zeros((self.Ndof, self.Ndof))
self.jac0 = np.zeros((self.Ndof, self.Ndof))
self.A1 = np.zeros((self.Ndof, self.Ndof))
self.A0 = np.identity(self.Ndof)
self.rhsSens = np.zeros((self.Ndof, self.Ndof))
# Operators
ident = np.identity(self.Np)
# V0p: Coefficients to values at xp
self.V0p = cheb.chebvander(self.xp, self.deg)
# V0pinv: xp values to coefficients
self.V0pinv = np.linalg.solve(self.V0p, ident)
# V1p: coefficients to derivatives at xp
self.V1p = np.zeros((self.Np,self.Np))
for i in range(0,self.Np):
self.V1p[:,i] = cheb.chebval(self.xp, cheb.chebder(ident[i,:], m=1))
# Dp: values at xp to derivatives at xp
self.Dp = self.V1p @ self.V0pinv
# V2p: coefficients to 2nd derivatives at xp
self.V2p = np.zeros((self.Np,self.Np))
for i in range(0,self.Np):
self.V2p[:,i] = cheb.chebval(self.xp, cheb.chebder(ident[i,:], m=2))
# Lp: values at xp to 2nd derivatives at xp
self.Lp = self.V2p @ self.V0pinv
# LpD: values at xp to 2nd derivatives at xc, with identity
# for top and bottom row (for Dirichlet BCs)
self.LpD = np.identity(self.Np)
self.LpD[1:-1,:] = self.Lp[1:-1,:]
self.totalCurrent = np.zeros((2,1),dtype=np.float64)
self.electronCurrent = np.zeros((2,1),dtype=np.float64)
self.ionCurrent = np.zeros((2,1),dtype=np.float64)
def filter(self):
"""Filter state by zeroing out the last Chebyshev coefficient.
This feature is experimental.
"""
ind = int(self.Np-1)
U0 = self.V0pinv @ self.U2[0:self.Np]
U0[ind:] = 0.0
self.U2[0:self.Np] = self.V0p @ U0
U0 = self.V0pinv @ self.U2[self.Np:2*self.Np]
U0[ind:] = 0.0
self.U2[self.Np:2*self.Np] = self.V0p @ U0
U0 = self.V0pinv @ self.U2[2*self.Np:]
U0[ind:] = 0.0
self.U2[2*self.Np:] = self.V0p @ U0
def solve_poisson(self, ne,ni,time):
"""Solve Gauss' law for the electric potential.
Inputs:
ne : Values of electron density at xp
ni : Values of ion density at xp
time : Current time
Outputs: None (sets self.phi to computed potential)
"""
r = -self.params.alpha*(ni-ne)
r[0] = 0.0
r[-1] = np.sin(2*np.pi*time) + self.params.verticalShift
self.phi = np.linalg.solve(self.LpD, r)
def spatial_residual(self, Uin, time, dt, weak_bc=False):
"""Evaluates the residual.
Inputs:
Uin : Current state
time : Current time
dt : Time step
Outputs:
returns residual vector
Notes:
This function currently assumes that Ns=2 and NT=1
"""
# indices of electrons/ions (in list s.t. dens[:,iele].shape = (Np,1)
iele = [0]
iion = [1]
# pull off state for convenience
dens = np.ndarray((self.Np, self.Ns),dtype=np.float64)
for i in range(0,self.Ns):
dens[:,i] = Uin[i*self.Np:(i+1)*self.Np,0]
nT = np.zeros((self.Np, 1),dtype=np.float64)
nT = Uin[self.Ns*self.Np:] # assumes just 1 temperature!
Te = nT/dens[:,iele]
ntot = np.zeros((self.Np, 1),dtype=np.float64)
# add all heavies but background
for i in range(1, self.Ns-1):
ntot[:,0] += dens[:,i]
# add background contribution (accounting for non-dim difference)
ntot[:,0] += self.params.nAronp0 * dens[:,self.Ns-1]
# Temperature (from ideal gas law)
Tg = np.zeros((self.Np, 1),dtype=np.float64)
Tg = (self.params.p0 - nT)/ntot
# solve poisson equation for phi
# now have self.phi
self.solve_poisson(dens[:,iele],dens[:,iion],time)
# form fluxes at grid points
dens_x = self.Dp @ dens
nT_x = self.Dp @ nT
phi_x = self.Dp @ self.phi
energy = np.zeros((self.Np, self.Ns),dtype=np.float64)
mu = np.zeros((self.Np, self.Ns),dtype=np.float64)
diffusivity = np.zeros((self.Np, self.Ns),dtype=np.float64)
energy[:,0] = Te[:,0]
for i in range(1,self.Ns):
energy[:,i] = Tg[:,0]
for i in range(0,self.Ns):
mu[:,i] = self.params.mobility(i, energy, dens[:,self.Ns-1])
diffusivity[:,i] = self.params.diffusivity(i, energy, mu,
dens[:,self.Ns-1],
self.EinsteinForm)
fspec = np.ndarray((self.Np, self.Ns),dtype=np.float64)
for i in range(0,self.Ns):
fspec[:,i] = ( self.params.charge(i)*np.multiply(mu[:,i], dens[:,i])*(-phi_x[:,0])
- np.multiply(diffusivity[:,i],dens_x[:,i]) )
fT = np.zeros((self.Np, 1),dtype=np.float64)
fT[:,0] = (5./3.)*(-mu[:,0]*nT[:,0]*(-phi_x[:,0]) - np.multiply(diffusivity[:,0], nT_x[:,0]))
# overwrite endpoints in fi (weakly impose BC)
fspec[ 0,1] = -self.params.ksion*dens[ 0,iion] + mu[0,1]*dens[ 0,iion]*(-phi_x[ 0])
fspec[-1,1] = self.params.ksion*dens[-1,iion] + mu[-1,1]*dens[-1,iion]*(-phi_x[-1])
# overwrite endpoints in fe (weakly impose BC)
rstrg = np.zeros(2)
if (weak_bc):
fspec[ 0,0] = (- self.params.ks*dens[ 0,iele] * Te[0,0]**0.5
- self.params.gam*fspec[ 0,iion])
fspec[-1,0] = (+ self.params.ks*dens[-1,iele] * Te[-1,0]**0.5
- self.params.gam*fspec[-1,iion])
else:
rstrg[0] = fspec[ 0,iele] - (- self.params.ks*dens[ 0,iele] * Te[0,0]**0.5
- self.params.gam*fspec[ 0,iion])
rstrg[1] = fspec[-1,iele] - (+ self.params.ks*dens[-1,iele] * Te[-1,0]**0.5
- self.params.gam*fspec[-1,iion])
#if (self.Ns>2):
# fspec[ 0,2:self.Ns] = 0.0
# fspec[-1,2:self.Ns] = 0.0
# form derivatives of fluxes at collocation points
fspec_x = self.Dp @ fspec
fT_x = self.Dp @ fT
# form source terms at collocation points
omega = self.params.rxnSourceTerm(Te, dens)
SJ = -self.params.qStar*fspec[:,iele]*(-phi_x)
# elastic collision term at collocation points
SEC = -self.params.EC * (nT - np.multiply(dens[0, iele], Tg))
SEC *= self.elasticCollisionActivationFactor
# evaluate S---the source term required in the background
# specie evolution to ensure constant pressure
fa = np.copy(fT)
for i in range(1,self.Ns-1):
fa[:,0] += (5./3.)*(self.params.charge(i) * np.multiply(mu[:,i],
np.multiply(dens[:,i],Tg[:,0]) * (-phi_x[:,0]))
- np.multiply(diffusivity[:,i], (self.Dp @ np.multiply(dens[:,i],Tg[:,0]))))
# background thermal conductivity contribution
fa[:,0] += - self.params.kappaB * (self.Dp @ Tg[:,0])
fa_x = self.Dp @ fa
sOmEp = np.zeros((self.Np,1),dtype=np.float64)
for i in range(0, self.Ns-1):
sOmEp[:,0] += omega[:,i]*self.params.dEps[i]
joule = np.zeros((self.Np,1),dtype=np.float64)
for i in range(0, self.Ns-1):
joule[:,0] += self.params.qStar*self.params.charge(i)*fspec[:,i]*(-phi_x[:,0])
S = np.zeros((self.Np,1),dtype=np.float64)
S[:,0] = (sOmEp[:,0] + fa_x[:,0] - joule[:,0])/Tg[:,0]/self.params.nAronp0
# form full residual
res = np.zeros((self.Nv*self.Np,1))
# spatial part
# standard species
for i in range(0,self.Ns-1):
res[i*self.Np:(i+1)*self.Np,0] = dt*(fspec_x[:,i] - omega[:,i])
# background specie (fixed at IC for now)
res[(self.Ns-1)*self.Np:self.Ns*self.Np] = -dt*S
res[(self.Ns-1)*self.Np:self.Ns*self.Np,0] *= self.backgroundSpecieActivationFactor
# energy
res[self.Ns*self.Np:] = dt*(fT_x - omega[:,[self.Ns]] - SJ - SEC)
############################################################
# Computation of total, displacement, and particle current #
############################################################
E_currentTimeStep = - phi_x
# pull off state for convenience
dens_previousTimeStep = np.ndarray((self.Np, self.Ns),dtype=np.float64)
for i in range(0,self.Ns):
dens_previousTimeStep[:,i] = self.U1[i*self.Np:(i+1)*self.Np,0]
# solve poisson equation for phi
# now have self.phi
self.solve_poisson(dens_previousTimeStep[:,iele],dens_previousTimeStep[:,iion],time)
# form fluxes at grid points
E_previousTimeStep = -self.Dp @ self.phi
displacementCurrent = self.params.eps0 \
* (E_currentTimeStep - E_previousTimeStep) / dt * self.params.V0Ltau
particleCurrent = np.zeros((2,self.Ns),dtype=np.float64)
particleCurrent[0,iion] = mu[0,1] * self.params.LLV0tau \
* dens[ 0,iion] * self.params.np0 * (-phi_x[ 0]) * self.params.V0L \
* self.params.qe * self.params.charge(1)
particleCurrent[-1,iion] = mu[-1,1] * self.params.LLV0tau \
* dens[-1,iion] * self.params.np0 * (-phi_x[-1]) * self.params.V0L \
* self.params.qe * self.params.charge(1)
particleCurrent[0,iele] = (- self.params.ks * self.params.tauL \
* dens[ 0,iele] * self.params.np0 * Te[0,0]**0.5 * self.params.qe \
- self.params.gam * particleCurrent[0,iion]) * self.params.charge(0)
particleCurrent[-1,iele] = (+ self.params.ks * self.params.tauL \
* dens[-1,iele] * self.params.np0 * Te[-1,0]**0.5 * self.params.qe \
- self.params.gam * particleCurrent[-1,iion]) * self.params.charge(0)
self.totalCurrent[ 0,0] = displacementCurrent[ 0] \
+ particleCurrent[ 0,iion] + particleCurrent[ 0,iele]
self.totalCurrent[-1,0] = displacementCurrent[-1] \
+ particleCurrent[-1,iion] + particleCurrent[-1,iele]
self.ionCurrent[:] = particleCurrent[:,iion]
self.electronCurrent[:] = particleCurrent[:,iele]
return res, rstrg
def residual(self, Uin, time, dt, weak_bc=False):
"""Evaluates the residual.
Inputs:
Uin : Current state
time : Current time
dt : Time step
weak_bc: Weak electron flux BC flag (boolean)
scheme : Temporal scheme indicator (string)
Outputs:
returns residual vector
Notes:
This function currently assumes that Ns=2 and NT=1
"""
if (self.temporal_scheme=="BE"):
res = self.residualBE(Uin, time, dt, weak_bc)
elif (self.temporal_scheme=="CN"):
res = self.residualCN(Uin, time, dt, weak_bc)
else:
print("Time marching scheme not recognized")
exit(-1)
return res
def residualBE(self, Uin, time, dt, weak_bc=False):
"""Evaluates the residual for backward Euler. See
timeDomainCollocationSolver.residua() for additional documentation.
"""
res, rstrg = self.spatial_residual(Uin, time, dt, weak_bc)
# indices of electrons/ions (in list s.t. dens[:,iele].shape = (Np,1)
iele = [0]
iion = [1]
# pull off state for convenience
dens = np.ndarray((self.Np, self.Ns),dtype=np.float64)
for i in range(0,self.Ns):
dens[:,i] = Uin[i*self.Np:(i+1)*self.Np,0]
nT = Uin[self.Ns*self.Np:] # assumes just 1 temperature!
Te = nT/dens[:,iele]
# time derivative part (backward Euler)
res += Uin - self.U1
# boundary conditions (strongly enforced)
# electron flux
if (not weak_bc):
res[0] = rstrg[0] #fspec[ 0,iele] - (-self.params.ks*dens[ 0,iele] - self.params.gam*fspec[ 0,iion])
res[self.Np-1] = rstrg[1] #fspec[-1,iele] - ( self.params.ks*dens[-1,iele] - self.params.gam*fspec[-1,iion])
for i in range(2,self.Ns-1):
res[i*self.Np ] = dens[ 0,i] - 0.0
res[(i+1)*self.Np-1] = dens[-1,i] - 0.0
# if solving for background density, enforce Dirichlet condition on heavy species temperature
if (self.backgroundSpecieActivationFactor > 0):
ntot = np.zeros(self.Np)
# add all heavies but background
for i in range(1, self.Ns-1):
ntot += dens[:,i]
# add background contribution (accounting for non-dim difference)
#ntot += self.params.nAronp0 * dens[:,self.Ns-1]
res[(self.Ns-1)*self.Np] = dens[ 0,self.Ns-1] \
- ((self.params.p0 - nT[ 0]) / self.params.Tg0 - ntot[ 0]) / self.params.nAronp0
res[ self.Ns*self.Np-1 ] = dens[ -1,self.Ns-1] \
- ((self.params.p0 - nT[ -1]) / self.params.Tg0 - ntot[-1]) / self.params.nAronp0
# electron temperature
res[self.Ns*self.Np ] = (nT[ 0] - self.params.EeBC * dens[0,iele])
res[(self.Ns+1)*self.Np-1] = (nT[-1] - self.params.EeBC * dens[-1,iele])
return res
def residualCN(self, Uin, time, dt, weak_bc=False):
"""Evaluates the residual for Crank-Nicolson. See
timeDomainCollocationSolver.residua() for additional documentation.
"""
res0, rstrgold = self.spatial_residual(self.U1, time-dt, dt, weak_bc)
res1, rstrg = self.spatial_residual( Uin, time , dt, weak_bc)
res = 0.5*(res0+res1)
# indices of electrons/ions (in list s.t. dens[:,iele].shape = (Np,1)
iele = [0]
iion = [1]
# pull off state for convenience
dens = np.ndarray((self.Np, self.Ns),dtype=np.float64)
for i in range(0,self.Ns):
dens[:,i] = Uin[i*self.Np:(i+1)*self.Np,0]
nT = Uin[self.Ns*self.Np:] # assumes just 1 temperature!
Te = nT/dens[:,iele]
# time derivative part (backward Euler)
res += Uin - self.U1
# boundary conditions (strongly enforced)
# electron flux
if (not weak_bc):
res[0] = rstrg[0] #fspec[ 0,iele] - (-self.params.ks*dens[ 0,iele] - self.params.gam*fspec[ 0,iion])
res[self.Np-1] = rstrg[1] #fspec[-1,iele] - ( self.params.ks*dens[-1,iele] - self.params.gam*fspec[-1,iion])
for i in range(2,self.Ns-1):
res[i*self.Np ] = dens[ 0,i] - 0.0
res[(i+1)*self.Np-1] = dens[-1,i] - 0.0
# if solving for background density, enforce Dirichlet condition on heavy species temperature
if (self.backgroundSpecieActivationFactor > 0):
ntot = np.zeros(self.Np)
# add all heavies but background
for i in range(1, self.Ns-1):
ntot += dens[:,i]
# add background contribution (accounting for non-dim difference)
#ntot += self.params.nAronp0 * dens[:,self.Ns-1]
res[(self.Ns-1)*self.Np] = dens[ 0,self.Ns-1] \
- ((self.params.p0 - nT[ 0]) / self.params.Tg0 - ntot[ 0]) / self.params.nAronp0
res[ self.Ns*self.Np-1 ] = dens[ -1,self.Ns-1] \
- ((self.params.p0 - nT[ -1]) / self.params.Tg0 - ntot[-1]) / self.params.nAronp0
# electron temperature
res[self.Ns*self.Np ] = (nT[ 0] - self.params.EeBC*dens[0,iele])
res[(self.Ns+1)*self.Np-1] = (nT[-1] - self.params.EeBC*dens[-1,iele])
return res
def residualLCN(self, Uin, time, dt, weak_bc=False):
"""Evaluates the residual for linearized Crank-Nicolson. See
timeDomainCollocationSolver.residua() for additional documentation.
"""
res0, rstrgold = self.spatial_residual(self.U1, time-dt, dt, weak_bc)
res1, rstrg = self.spatial_residual( Uin, time , dt, weak_bc)
res = 0.5*(res0+res1)
# indices of electrons/ions (in list s.t. dens[:,iele].shape = (Np,1)
iele = [0]
iion = [1]
# pull off state for convenience
dens = np.ndarray((self.Np, self.Ns),dtype=np.float64)
for i in range(0,self.Ns):
dens[:,i] = Uin[i*self.Np:(i+1)*self.Np,0]
nT = Uin[self.Ns*self.Np:] # assumes just 1 temperature!
Te = nT/dens[:,iele]
# time derivative part
# no contribution from time derivative in LCN, so do nothing here
# boundary conditions (strongly enforced)
# electron flux
if (not weak_bc):
print("Error: Only weak electron flux BCs supported for linearized CN.")
exit(-1)
# NB: Setting residuals to zero here enforces that the correct
# change in the associated variables is zero. However, this
# *only* works if the IC satisfies the BC. Any errors
# introduced by the IC will never be eliminated.
#if (self.Ns>2):
# res[2*self.Np ] = 0.0 #dens[ 0,2] - 0.0
# res[3*self.Np-1] = 0.0 #dens[-1,2] - 0.0
if (self.Ns > 2):
for i in range(2, self.Ns-1):
res[i*self.Np ] = 0.0
res[(i+1)*self.Np-1] = 0.0
#if (self.Ns == 6):
#res[2*self.Np ] = 0.0
#res[3*self.Np-1] = 0.0
# res[3*self.Np ] = 0.0
# res[4*self.Np-1] = 0.0
# res[4*self.Np ] = 0.0
# res[5*self.Np-1] = 0.0
# electron temperature
res[self.Ns*self.Np ] = 0.0 #(nT[ 0] - 0.75*dens[0,iele])
res[(self.Ns+1)*self.Np-1] = 0.0 #(nT[-1] - 0.75*dens[-1,iele])
return res
def spatial_jacobian(self, Uin, time, dt, weak_bc=False, solve_poisson=False):
"""Evaluates the residual.
Inputs:
Uin : Current state
time : Current time
dt : Time step
Outputs: None (sets self.jac)
Notes:
This function currently assumes that Ns=2 and NT=1
"""
# indices of electrons/ions (in list s.t. dens[:,iele].shape = (Np,1)
iele = [0]
iion = [1]
# pull off state for convenience
dens = np.ndarray((self.Np, self.Ns),dtype=np.float64)
for i in range(0,self.Ns):
dens[:,i] = Uin[i*self.Np:(i+1)*self.Np,0]
nT = Uin[self.Ns*self.Np:] # assumes just 1 temperature!
Te = nT/dens[:,iele]
Te_ne = -np.multiply(Te/dens[:,iele],np.identity(self.Np))
Te_nT = np.multiply(np.identity(self.Np),1./dens[:,iele])
ntot = np.zeros((self.Np,1),dtype=np.float64)
ntot_U = np.zeros((self.Np, self.Nv))
# all but background
for i in range(1, self.Ns-1):
ntot[:,0] += dens[:,i]
ntot_U[:,i] += np.ones(self.Np)
# background contribution
ntot[:,0] += self.params.nAronp0 * dens[:,self.Ns-1]
ntot_U[:,self.Ns-1] += self.params.nAronp0*np.ones(self.Np)
# Temperature (from ideal gas law)
Tg = np.zeros((self.Np, 1),dtype=np.float64)
Tg = (self.params.p0 - nT)/ntot
Tg_U = np.zeros((self.Np, self.Nv))
for i in range(0, self.Nv):
Tg_U[:,i] = -(Tg[:,0]/ntot[:,0])*ntot_U[:,i]
Tg_U[:,-1] += -np.ones(self.Np)/ntot[:,0]
#print("Mean gas temperature = {0:.6e}".format((2./3)*np.mean(Tg)*11604.))
# force solving poisson equation again
if (solve_poisson):
self.solve_poisson(dens[:,iele],dens[:,iion],time)
energy = np.zeros((self.Np, self.Ns),dtype=np.float64)
mu = np.zeros((self.Np, self.Ns),dtype=np.float64)
diffusivity = np.zeros((self.Np, self.Ns),dtype=np.float64)
energy[:,0] = Te[:,0]
for i in range(1,self.Ns):
energy[:,i] = Tg[:,0]
for i in range(0,self.Ns):
mu[:,i] = self.params.mobility(i, energy, dens[:,self.Ns-1])
diffusivity[:,i] = self.params.diffusivity(i, energy, mu,
dens[:,self.Ns-1],
self.EinsteinForm)