forked from ammarhakim/gkyl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGkIonization.lua
367 lines (326 loc) · 12.3 KB
/
GkIonization.lua
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
-- Gkyl ------------------------------------------------------------------------
--
-- PlasmaOnCartGrid support code: Ionization operator using Voronov
-- reaction rate.
-- See:
-- Voronov, G.S., 1997. A practical fit formula for ionization rate
-- coefficients of atoms and ions by electron impact: Z= 1–28. Atomic
-- Data and Nuclear Data Tables, 65(1), pp.1-35.
--
--------------------------------------------------------------------------------
local CollisionsBase = require "App.Collisions.CollisionsBase"
local Constants = require "Lib.Constants"
local DataStruct = require "DataStruct"
local DiagsImplBase = require "App.Diagnostics.DiagnosticsImplBase"
local DiagsApp = require "App.Diagnostics.SpeciesDiagnostics"
local Proto = require "Lib.Proto"
local Time = require "Lib.Time"
local Updater = require "Updater"
local Mpi = require "Comm.Mpi"
local lume = require "Lib.lume"
local xsys = require "xsys"
-- GkIonization -----------------------------------------------------------
--
-- Voronov ionization operator.
---------------------------------------------------------------------------
-- ............... IMPLEMENTATION OF DIAGNOSTICS ................. --
-- Diagnostics could be placed in a separate file if they balloon in
-- number. But if we only have one or two we can just place it here.
local gkIzDiagImpl = function()
local _M0 = Proto(DiagsImplBase)
function _M0:fullInit(diagApp, mySpecies, fieldIn, owner)
self.field = mySpecies:allocMoment()
self.updater = mySpecies.numDensityCalc
self.owner = owner
self.done = false
end
function _M0:getType() return "grid" end
function _M0:advance(tm, inFlds, outFlds)
self.updater:advance(tm, {self.owner.ionizSrc}, {self.field})
end
local _intM0 = Proto(DiagsImplBase)
function _intM0:fullInit(diagApp, mySpecies, fieldIn, owner)
self.fieldAux = mySpecies:allocMoment()
self.updatersAux = mySpecies.numDensityCalc
self.field = DataStruct.DynVector { numComponents = 1 }
self.updater = mySpecies.volIntegral.scalar
self.owner = owner
self.done = false
end
function _intM0:getType() return "integrated" end
function _intM0:advance(tm, inFlds, outFlds)
self.updatersAux:advance(tm, {self.owner.ionizSrc}, {self.fieldAux})
self.updater:advance(tm, {self.fieldAux}, {self.field})
end
local _reactRate = Proto(DiagsImplBase)
function _reactRate:fullInit(diagApp, mySpecies, fieldIn, owner)
self.field = mySpecies:allocMoment()
self.owner = owner
self.done = false
end
function _reactRate:getType() return "grid" end
function _reactRate:advance(tm, inFlds, outFlds)
if self.owner.reactRate then
self.field:copy(self.owner.reactRate)
end
end
local _source = Proto(DiagsImplBase)
function _source:fullInit(diagApp, mySpecies, fieldIn, owner)
self.field = mySpecies:allocDistf()
self.owner = owner
self.done = false
end
function _source:getType() return "grid" end
function _source:advance(tm, inFlds, outFlds)
self.field:copy(self.owner.ionizSrc)
end
return {
M0 = _M0,
intM0 = _intM0,
reactRate = _reactRate,
source = _source
}
end
-- .................... END OF DIAGNOSTICS ...................... --
local GkIonization = Proto(CollisionsBase)
-- This ctor simply stores what is passed to it and defers actual
-- construction to the fullInit() method below.
function GkIonization:init(tbl)
self.tbl = tbl
end
-- Actual function for initialization. This indirection is needed as
-- we need the app top-level table for proper initialization.
function GkIonization:fullInit(speciesTbl)
local tbl = self.tbl -- Previously store table.
self.cfl = 0.1
self.collKind = "Ionization"
self.collidingSpecies = assert(tbl.collideWith, "App.GkIonization: Must specify names of species to collide with in 'collideWith'.")
-- Set these values to be consistent with other collision apps
self.selfCollisions = false
self.crossCollisions = true
self.varNu = false
self.timeDepNu = false
self.collFreqs = {1}
self.collideNm = tbl.collideWith[1]
self.elcNm = assert(tbl.electrons, "App.GkIonization: Must specify electron species name in 'electrons'.")
self.neutNm = assert(tbl.neutrals, "App.GkIonization: Must specify electron species name in 'neutrals'.")
self.plasma = tbl.plasma
self.mass = tbl.elcMass
self.charge = tbl.elemCharge
if self.plasma == "H" then
self._E = 13.6
self._P = 0
self._A = 0.291e-7
self._K = 0.39
self._X = 0.232
end
if self.plasma == "Ar" then
self._E = 15.8
self._P = 1
self._A = 0.599e-7
self._K = 0.26
self._X = 0.136
end
self.timers = {nonSlvr = 0.}
end
function GkIonization:createDiagnostics(mySpecies, field)
-- Create source diagnostics.
self.diagnostics = nil
if self.tbl.diagnostics then
self.diagnostics = DiagsApp{implementation = gkIzDiagImpl()}
self.diagnostics:fullInit(mySpecies, field, self)
end
return self.diagnostics
end
function GkIonization:setName(nm)
self.name = self.speciesName.."_"..nm
self.collNm = nm
end
function GkIonization:setSpeciesName(nm) self.speciesName = nm end
function GkIonization:setCfl(cfl) self.cfl = cfl end
function GkIonization:setConfBasis(basis) self.confBasis = basis end
function GkIonization:setConfGrid(grid) self.confGrid = grid end
function GkIonization:setPhaseBasis(basis) self.phaseBasis = basis end
function GkIonization:setPhaseGrid(grid) self.phaseGrid = grid end
function GkIonization:createSolver(funcField)
self.collisionSlvr = Updater.Ionization {
onGrid = self.confGrid,
confBasis = self.confBasis,
phaseGrid = self.phaseGrid,
phaseBasis = self.phaseBasis,
elcMass = self.mass,
elemCharge = self.charge,
reactRate = true,
-- Voronov parameters
A = self._A,
E = self._E,
K = self._K,
P = self._P,
X = self._X,
}
if (self.speciesName == self.elcNm) then
self.calcIonizationTemp = Updater.Ionization {
onGrid = self.confGrid,
confBasis = self.confBasis,
phaseGrid = self.phaseGrid,
phaseBasis = self.phaseBasis,
elcMass = self.mass,
elemCharge = self.charge,
reactRate = false,
E = self._E,
}
self.reactRate = DataStruct.Field {
onGrid = self.confGrid,
numComponents = self.confBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.confBasis:polyOrder(),
basisType = self.confBasis:id()
},
}
self.vtSqIz = DataStruct.Field {
onGrid = self.confGrid,
numComponents = self.confBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.confBasis:polyOrder(),
basisType = self.confBasis:id()
},
}
self.m0fMax = DataStruct.Field {
onGrid = self.confGrid,
numComponents = self.confBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.confBasis:polyOrder(),
basisType = self.confBasis:id()
},
}
self.m0mod = DataStruct.Field {
onGrid = self.confGrid,
numComponents = self.confBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.confBasis:polyOrder(),
basisType = self.confBasis:id()
},
}
self.fMaxElc = DataStruct.Field {
onGrid = self.phaseGrid,
numComponents = self.phaseBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.phaseBasis:polyOrder(),
basisType = self.phaseBasis:id()
},
}
self.sumDistF = DataStruct.Field {
onGrid = self.phaseGrid,
numComponents = self.phaseBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.phaseBasis:polyOrder(),
basisType = self.phaseBasis:id()
},
}
end
self.m0elc = DataStruct.Field {
onGrid = self.confGrid,
numComponents = self.confBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.confBasis:polyOrder(),
basisType = self.confBasis:id()
},
}
self.coefM0 = DataStruct.Field {
onGrid = self.confGrid,
numComponents = self.confBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.confBasis:polyOrder(),
basisType = self.confBasis:id()
},
}
self.fMaxNeut = DataStruct.Field {
onGrid = self.phaseGrid,
numComponents = self.phaseBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.phaseBasis:polyOrder(),
basisType = self.phaseBasis:id()
},
}
self.ionizSrc = DataStruct.Field {
onGrid = self.phaseGrid,
numComponents = self.phaseBasis:numBasis(),
ghost = {1, 1},
metaData = {
polyOrder = self.phaseBasis:polyOrder(),
basisType = self.phaseBasis:id()
},
}
end
function GkIonization:advance(tCurr, fIn, species, fRhsOut)
local tmNonSlvrStart = Time.clock()
local reactRate = species[self.elcNm].collisions[self.collNm].reactRate
local elcM0 = species[self.elcNm]:fluidMoments()[1]
-- Check whether particle is electron, neutral or ion species.
if (self.speciesName == self.elcNm) then
-- Electrons.
self.m0elc:copy(elcM0)
local neutM0 = species[self.neutNm]:fluidMoments()[1]
local neutU = species[self.neutNm]:selfPrimitiveMoments()[1]
local elcVtSq = species[self.elcNm]:selfPrimitiveMoments()[2]
local elcDistF = species[self.elcNm]:getDistF()
-- Calculate ioniz fMax
self.calcIonizationTemp:advance(tCurr, {elcVtSq}, {self.vtSqIz})
species[self.speciesName].calcMaxwell:advance(tCurr, {self.m0elc, neutU, self.vtSqIz, species[self.speciesName].bmag}, {self.fMaxElc})
species[self.speciesName].numDensityCalc:advance(tCurr, {self.fMaxElc}, {self.m0fMax})
species[self.speciesName].confWeakDivide:advance(tCurr, {self.m0fMax, self.m0elc}, {self.m0mod})
species[self.speciesName].confPhaseWeakMultiply:advance(tCurr, {self.m0mod, self.fMaxElc}, {self.fMaxElc})
self.sumDistF:combine(2.0,self.fMaxElc,-1.0,elcDistF)
species[self.speciesName].confWeakMultiply:advance(tCurr, {reactRate, neutM0}, {self.coefM0})
species[self.speciesName].confPhaseWeakMultiply:advance(tCurr, {self.coefM0, self.sumDistF}, {self.ionizSrc})
-- Uncomment to test without fMaxwellian(Tiz)
--self.confPhaseMult:advance(tCurr, {self.coefM0, elcDistF}, {self.ionizSrc})
fRhsOut:accumulate(1.0,self.ionizSrc)
elseif (species[self.speciesName].charge == 0) then
-- Neutrals, on Vlasov grid.
local neutDistF = species[self.neutNm]:getDistF()
self.m0elc:copy(elcM0)
species[self.speciesName].confWeakMultiply:advance(tCurr, {reactRate, self.m0elc}, {self.coefM0})
species[self.speciesName].confPhaseWeakMultiply:advance(tCurr, {self.coefM0, neutDistF}, {self.ionizSrc})
self.ionizSrc:scale(-1.0)
fRhsOut:accumulate(1.0,self.ionizSrc)
else
-- Ions.
self.m0elc:copy(elcM0)
local neutM0 = species[self.neutNm]:fluidMoments()[1]
local neutU = species[self.neutNm]:selfPrimitiveMoments()[1]
local neutVtSq = species[self.neutNm]:selfPrimitiveMoments()[2]
-- Include only z-component of neutU.
species[self.speciesName].confWeakMultiply:advance(tCurr, {reactRate, self.m0elc}, {self.coefM0})
species[self.speciesName].calcMaxwell:advance(tCurr,
{neutM0, neutU, neutVtSq, species[self.speciesName].bmag}, {self.fMaxNeut})
species[self.speciesName].confPhaseWeakMultiply:advance(tCurr, {self.coefM0, self.fMaxNeut}, {self.ionizSrc})
fRhsOut:accumulate(1.0,self.ionizSrc)
end
self.timers.nonSlvr = self.timers.nonSlvr + Time.clock() - tmNonSlvrStart
end
function GkIonization:write(tm, frame) end
function GkIonization:setCfl(cfl)
self.cfl = cfl
end
function GkIonization:slvrTime()
return 0.
end
function GkIonization:nonSlvrTime()
return self.timers.nonSlvr
end
function GkIonization:projectMaxwellTime()
local time = self.confMult.projectMaxwellTime()
time = time + self.confPhaseMult.projectMaxwellTime
return time
end
return GkIonization