24
24
def ions_mass_density_func1d (x , ** kwargs ):
25
25
masses = kwargs ["masses" ] # list of float : the ion pop masses
26
26
densities = kwargs ["densities" ] # list of callable : the ion pop density profiles
27
+ if len (masses ) != len (densities ):
28
+ raise ValueError ("Length of masses and densities must be equal" )
27
29
28
- assert len (masses ) == len (densities )
29
30
funcs = np .zeros ((x .size , len (masses )))
30
31
31
32
for i , (mass , density ) in enumerate (zip (masses , densities )):
@@ -37,8 +38,8 @@ def ions_mass_density_func1d(x, **kwargs):
37
38
def ions_charge_density_func1d (x , ** kwargs ):
38
39
charges = kwargs ["charges" ] # list of float : the ion pop charges
39
40
densities = kwargs ["densities" ] # list of callable : the ion pop density profiles
40
-
41
- assert len ( charges ) == len ( densities )
41
+ if len ( charges ) != len ( densities ):
42
+ raise ValueError ( "Length of charges and densities must be equal" )
42
43
43
44
funcs = np .zeros ((x .size , len (charges )))
44
45
@@ -52,10 +53,11 @@ def ions_charge_density_func1d(x, **kwargs):
52
53
def ions_mass_density_func2d (x , y , ** kwargs ):
53
54
masses = kwargs ["masses" ] # list of float : the ion pop masses
54
55
densities = kwargs ["densities" ] # list of callable : the ion pop density profiles
56
+ if len (masses ) != len (densities ):
57
+ raise ValueError ("Length of masses and densities must be equal" )
55
58
56
59
yv , xv = np .meshgrid (y , x )
57
60
58
- assert len (masses ) == len (densities )
59
61
funcs = np .zeros ((x .size , y .size , len (masses )))
60
62
61
63
for i , (mass , density ) in enumerate (zip (masses , densities )):
@@ -67,10 +69,11 @@ def ions_mass_density_func2d(x, y, **kwargs):
67
69
def ions_charge_density_func2d (x , y , ** kwargs ):
68
70
charges = kwargs ["charges" ] # list of float : the ion pop charges
69
71
densities = kwargs ["densities" ] # list of callable : the ion pop density profiles
72
+ if len (charges ) != len (densities ):
73
+ raise ValueError ("Length of charges and densities must be equal" )
70
74
71
75
yv , xv = np .meshgrid (y , x )
72
76
73
- assert len (charges ) == len (densities )
74
77
funcs = np .zeros ((x .size , y .size , len (charges )))
75
78
76
79
for i , (charge , density ) in enumerate (zip (charges , densities )):
@@ -140,8 +143,8 @@ def config_1d():
140
143
bx = bx_1d ,
141
144
by = by_1d ,
142
145
bz = bz_1d ,
143
- main = {"mass" : masses [0 ], "charge" : charges [0 ], "density" : densityMain_1d , "nbr_part_per_cell" : 1000 , ** v_pop },
144
- beam = {"mass" : masses [1 ], "charge" : charges [1 ], "density" : densityBeam_1d , "nbr_part_per_cell" : 1000 , ** v_pop },
146
+ main = {"mass" : masses [0 ], "charge" : charges [0 ], "density" : densityMain_1d , "nbr_part_per_cell" : 100 , ** v_pop },
147
+ beam = {"mass" : masses [1 ], "charge" : charges [1 ], "density" : densityBeam_1d , "nbr_part_per_cell" : 100 , ** v_pop },
145
148
)
146
149
147
150
ph .ElectronModel (closure = "isothermal" , Te = 0.0 )
@@ -222,8 +225,8 @@ def config_2d():
222
225
bx = bx_2d ,
223
226
by = by_2d ,
224
227
bz = bz_2d ,
225
- main = {"mass" : masses [0 ], "charge" : charges [0 ], "density" : densityMain_2d , "nbr_part_per_cell" : 2000 , ** v_pop },
226
- beam = {"mass" : masses [1 ], "charge" : charges [1 ], "density" : densityBeam_2d , "nbr_part_per_cell" : 2000 , ** v_pop },
228
+ main = {"mass" : masses [0 ], "charge" : charges [0 ], "density" : densityMain_2d , "nbr_part_per_cell" : 100 , ** v_pop },
229
+ beam = {"mass" : masses [1 ], "charge" : charges [1 ], "density" : densityBeam_2d , "nbr_part_per_cell" : 100 , ** v_pop },
227
230
)
228
231
229
232
ph .ElectronModel (closure = "isothermal" , Te = 0.0 )
@@ -255,23 +258,21 @@ def main():
255
258
ph .global_vars .sim = None
256
259
Simulator (config_2d ()).run ().reset ()
257
260
258
-
259
- def assert_close_enough ( h , H ):
261
+ def noise_level ( h , H ):
262
+ noises = list ()
260
263
for lvl_h , lvl_H in zip (h .levels (time ).values (), H .levels (time ).values ()):
261
264
for patch_h , patch_H in zip (lvl_h .patches , lvl_H .patches ):
262
265
pd_h = patch_h .patch_datas ["value" ]
263
266
pd_H = patch_H .patch_datas ["value" ]
264
- ghosts_num = pd_h .ghosts_nbr [0 ]
265
267
266
- if pd_H .ndim == 1 :
267
- dset_h = pd_h .dataset [ghosts_num :- ghosts_num ]
268
- dset_H = pd_H .dataset [ghosts_num :- ghosts_num ]
269
- if pd_H .ndim == 2 :
270
- dset_h = pd_h .dataset [ghosts_num :- ghosts_num , ghosts_num :- ghosts_num ]
271
- dset_H = pd_H .dataset [ghosts_num :- ghosts_num , ghosts_num :- ghosts_num ]
268
+ dset_h = pd_h [pd_h .box ]
269
+ dset_H = pd_H [pd_H .box ]
270
+
271
+ noise = np .std (dset_h - dset_H )
272
+ # print(f"noise = ", noise)
273
+ noises .append (noise )
274
+ return noises
272
275
273
- for h_ , H_ in zip (dset_h , dset_H ):
274
- np .testing .assert_almost_equal (h_ , H_ , decimal = 1 )
275
276
276
277
277
278
fig , ((ax1 , ax2 ), (ax3 , ax4 ), (ax5 , ax6 )) = plt .subplots (3 , 2 , figsize = (6 , 8 ))
@@ -287,8 +288,8 @@ def assert_close_enough(h, H):
287
288
H1 = hierarchy_from (hier = h1 , func = ions_mass_density_func1d , masses = masses , densities = (densityMain_1d , densityBeam_1d ))
288
289
H2 = hierarchy_from (hier = h2 , func = ions_charge_density_func1d , charges = charges , densities = (densityMain_1d , densityBeam_1d ))
289
290
290
- assert_close_enough ( h1 , H1 )
291
- assert_close_enough ( h2 , H2 )
291
+ assert np . mean ( noise_level ( h1 , H1 )) < 0.18
292
+ assert np . mean ( noise_level ( h2 , H2 )) < 0.12
292
293
293
294
cycle = plt .rcParams ['axes.prop_cycle' ].by_key ()['color' ]
294
295
@@ -313,8 +314,8 @@ def assert_close_enough(h, H):
313
314
H1 = hierarchy_from (hier = h1 , func = ions_mass_density_func2d , masses = masses , densities = (densityMain_2d , densityBeam_2d ))
314
315
H2 = hierarchy_from (hier = h2 , func = ions_charge_density_func2d , charges = charges , densities = (densityMain_2d , densityBeam_2d ))
315
316
316
- assert_close_enough ( h1 , H1 )
317
- assert_close_enough ( h2 , H2 )
317
+ assert np . mean ( noise_level ( h1 , H1 )) < 0.18
318
+ assert np . mean ( noise_level ( h2 , H2 )) < 0.12
318
319
319
320
cmap = mpl .colormaps ['viridis' ]
320
321
@@ -327,8 +328,5 @@ def assert_close_enough(h, H):
327
328
plt .savefig ("nCheck.pdf" , dpi = 300 )
328
329
329
330
330
-
331
- # /home/smets/codes/far/PHARE/tests/simulator/initialize
332
-
333
331
if __name__ == "__main__" :
334
332
main ()
0 commit comments