@@ -111,8 +111,8 @@ def dx_dy(arr, grid_step_size):
111
111
return dx / (grid_step_size * 2 ), dy / (grid_step_size * 2 )
112
112
113
113
114
- def calculate_Ex_Ey_Bx_By_predictor (
115
- grid_step_size , xi_step_size , const , fields_prev , ro_beam_full , ro_beam_prev ,
114
+ def calculate_Ex_Ey_Bx_By (
115
+ grid_step_size , xi_step_size , const , fields , ro_beam_full , ro_beam_prev ,
116
116
currents_full , currents_prev
117
117
):
118
118
"""
@@ -138,10 +138,10 @@ def calculate_Ex_Ey_Bx_By_predictor(
138
138
djy_dxi = (jy_prev - jy_full ) / xi_step_size # - ?
139
139
140
140
# We are solving a Helmholtz equation
141
- Ex_rhs = - (dro_dx - djx_dxi - fields_prev .Ex ) # -?
142
- Ey_rhs = - (dro_dy - djy_dxi - fields_prev .Ey )
143
- Bx_rhs = + (djz_dy - djy_dxi + fields_prev .Bx )
144
- By_rhs = - (djz_dx - djx_dxi - fields_prev .By )
141
+ Ex_rhs = - (dro_dx - djx_dxi - fields .Ex ) # -?
142
+ Ey_rhs = - (dro_dy - djy_dxi - fields .Ey )
143
+ Bx_rhs = + (djz_dy - djy_dxi + fields .Bx )
144
+ By_rhs = - (djz_dx - djx_dxi - fields .By )
145
145
146
146
# Boundary conditions application (for future reference, ours are zero):
147
147
# rhs[:, 0] -= bound_bottom[:] * (2 / grid_step_size)
@@ -155,68 +155,14 @@ def calculate_Ex_Ey_Bx_By_predictor(
155
155
Ey_f *= mix_mat
156
156
157
157
# 3. Apply our mixed DCT-DST transform again.
158
- Ey_half = mix2d (Ey_f )
158
+ Ey = mix2d (Ey_f )
159
159
160
160
# Likewise for other fields:
161
- Bx_half = mix2d (mix_mat * mix2d (Bx_rhs [1 :- 1 , :])[1 :- 1 , :])
162
- By_half = mix2d (mix_mat * mix2d (By_rhs .T [1 :- 1 , :])[1 :- 1 , :]).T
163
- Ex_half = mix2d (mix_mat * mix2d (Ex_rhs .T [1 :- 1 , :])[1 :- 1 , :]).T
161
+ Bx = mix2d (mix_mat * mix2d (Bx_rhs [1 :- 1 , :])[1 :- 1 , :])
162
+ By = mix2d (mix_mat * mix2d (By_rhs .T [1 :- 1 , :])[1 :- 1 , :]).T
163
+ Ex = mix2d (mix_mat * mix2d (Ex_rhs .T [1 :- 1 , :])[1 :- 1 , :]).T
164
164
165
- return Ex_half , Ey_half , Bx_half , By_half
166
-
167
-
168
- def calculate_Ex_Ey_Bx_By_corrector (
169
- grid_step_size , xi_step_size , const , fields_full , ro_beam_full ,
170
- currents_full , currents_prev , currents_prevprev
171
- ):
172
- """
173
- Calculate transverse fields as iDST-DCT(mixed_matrix * DST-DCT(RHS.T)).T,
174
- with and without transposition depending on the field component.
175
- NOTE: density and currents are assumed to be zero on the perimeter
176
- (no plasma particles must reach the wall, so the reflection boundary
177
- must be closer to the center than the simulation window boundary
178
- minus the coarse plasma particle cloud width).
179
- """
180
- jx_prevprev , jy_prevprev = currents_prevprev .jx , currents_prevprev .jy
181
- jx_prev , jy_prev = currents_prev .jx , currents_prev .jy
182
- jx_full , jy_full = currents_full .jx , currents_full .jy
183
-
184
- ro_full = currents_full .ro
185
- jz_full = currents_full .jz
186
-
187
- # 0. Calculate gradients and RHS.
188
- dro_dx , dro_dy = dx_dy (ro_full + ro_beam_full , grid_step_size )
189
- djz_dx , djz_dy = dx_dy (jz_full + ro_beam_full , grid_step_size )
190
-
191
- djx_dxi = (- jx_prevprev + 4 * jx_prev - 3 * jx_full ) / (2 * xi_step_size )
192
- djy_dxi = (- jy_prevprev + 4 * jy_prev - 3 * jy_full ) / (2 * xi_step_size )
193
-
194
- # We are solving a Helmholtz equation
195
- Ex_rhs = - (dro_dx - djx_dxi - fields_full .Ex ) # -?
196
- Ey_rhs = - (dro_dy - djy_dxi - fields_full .Ey )
197
- Bx_rhs = + (djz_dy - djy_dxi + fields_full .Bx )
198
- By_rhs = - (djz_dx - djx_dxi - fields_full .By )
199
-
200
- # Boundary conditions application (for future reference, ours are zero):
201
- # rhs[:, 0] -= bound_bottom[:] * (2 / grid_step_size)
202
- # rhs[:, -1] += bound_top[:] * (2 / grid_step_size)
203
-
204
- # 1. Apply our mixed DCT-DST transform to RHS.
205
- Ey_f = mix2d (Ey_rhs [1 :- 1 , :])[1 :- 1 , :]
206
-
207
- # 2. Multiply f by the magic matrix.
208
- mix_mat = const .field_mixed_matrix
209
- Ey_f *= mix_mat
210
-
211
- # 3. Apply our mixed DCT-DST transform again.
212
- Ey_full = mix2d (Ey_f )
213
-
214
- # Likewise for other fields:
215
- Bx_full = mix2d (mix_mat * mix2d (Bx_rhs [1 :- 1 , :])[1 :- 1 , :])
216
- By_full = mix2d (mix_mat * mix2d (By_rhs .T [1 :- 1 , :])[1 :- 1 , :]).T
217
- Ex_full = mix2d (mix_mat * mix2d (Ex_rhs .T [1 :- 1 , :])[1 :- 1 , :]).T
218
-
219
- return Ex_full , Ey_full , Bx_full , By_full
165
+ return Ex , Ey , Bx , By
220
166
221
167
222
168
# Pushing particles without any fields (used for initial halfstep estimation) #
@@ -297,25 +243,25 @@ def __init__(self, config: Config):
297
243
self .trick = config .getfloat ('field-solver-subtraction-trick' )
298
244
self .variant_A = config .getbool ('field-solver-variant-A' )
299
245
300
- def compute_fields_predictor (
301
- self , fields_prev , const , rho_beam , rho_beam_prev , currents_prev ,
302
- currents_full
246
+ def compute_fields (
247
+ self , fields , fields_prev , const , rho_beam_full , rho_beam_prev ,
248
+ currents_prev , currents_full
303
249
):
304
250
# Looks terrible! TODO: rewrite this function entirely
305
251
306
- Ex_half , Ey_half , Bx_half , By_half = calculate_Ex_Ey_Bx_By_predictor (
307
- self .grid_step_size , self .xi_step_size , const , fields_prev ,
308
- rho_beam , rho_beam_prev , currents_full , currents_prev
252
+ Ex_half , Ey_half , Bx_half , By_half = calculate_Ex_Ey_Bx_By (
253
+ self .grid_step_size , self .xi_step_size , const , fields ,
254
+ rho_beam_full , rho_beam_prev , currents_full , currents_prev
309
255
)
310
256
311
257
Ex_full = 2 * Ex_half - fields_prev .Ex
312
258
Ey_full = 2 * Ey_half - fields_prev .Ey
313
259
Bx_full = 2 * Bx_half - fields_prev .Bx
314
260
By_full = 2 * By_half - fields_prev .By
315
261
316
- Ez_full = calculate_Ez (self .grid_step_size , const , currents_full )
317
- Bz_full = calculate_Bz (self .grid_step_size , const , currents_full )
318
- Phi = fields_prev . Phi # calculate_Phi(const, currents_full)
262
+ Ez_full = calculate_Ez (self .grid_step_size , const , currents_full )
263
+ Bz_full = calculate_Bz (self .grid_step_size , const , currents_full )
264
+ Phi = calculate_Phi (const , currents_full )
319
265
320
266
fields_full = GPUArrays (
321
267
Ex = Ex_full , Ey = Ey_full , Ez = Ez_full ,
@@ -333,25 +279,3 @@ def compute_fields_predictor(
333
279
)
334
280
335
281
return fields_full , fields_half
336
-
337
- def compute_fields_corrector (
338
- self , fields_full , fields_prev , const , rho_beam , currents_prevprev ,
339
- currents_prev , currents_full
340
- ):
341
-
342
- Ex_full , Ey_full , Bx_full , By_full = calculate_Ex_Ey_Bx_By_corrector (
343
- self .grid_step_size , self .xi_step_size , const , fields_full ,
344
- rho_beam , currents_full , currents_prev , currents_prevprev
345
- )
346
-
347
- Ez_full = calculate_Ez (self .grid_step_size , const , currents_full )
348
- Bz_full = calculate_Bz (self .grid_step_size , const , currents_full )
349
- Phi_full = calculate_Phi (const , currents_full )
350
-
351
- fields_full = GPUArrays (
352
- Ex = Ex_full , Ey = Ey_full , Ez = Ez_full ,
353
- Bx = Bx_full , By = By_full , Bz = Bz_full ,
354
- Phi = Phi_full
355
- )
356
-
357
- return fields_full , fields_average (fields_full , fields_prev )
0 commit comments