2424def ions_mass_density_func1d (x , ** kwargs ):
2525 masses = kwargs ["masses" ] # list of float : the ion pop masses
2626 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" )
2729
28- assert len (masses ) == len (densities )
2930 funcs = np .zeros ((x .size , len (masses )))
3031
3132 for i , (mass , density ) in enumerate (zip (masses , densities )):
@@ -37,8 +38,8 @@ def ions_mass_density_func1d(x, **kwargs):
3738def ions_charge_density_func1d (x , ** kwargs ):
3839 charges = kwargs ["charges" ] # list of float : the ion pop charges
3940 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" )
4243
4344 funcs = np .zeros ((x .size , len (charges )))
4445
@@ -52,10 +53,11 @@ def ions_charge_density_func1d(x, **kwargs):
5253def ions_mass_density_func2d (x , y , ** kwargs ):
5354 masses = kwargs ["masses" ] # list of float : the ion pop masses
5455 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" )
5558
5659 yv , xv = np .meshgrid (y , x )
5760
58- assert len (masses ) == len (densities )
5961 funcs = np .zeros ((x .size , y .size , len (masses )))
6062
6163 for i , (mass , density ) in enumerate (zip (masses , densities )):
@@ -67,10 +69,11 @@ def ions_mass_density_func2d(x, y, **kwargs):
6769def ions_charge_density_func2d (x , y , ** kwargs ):
6870 charges = kwargs ["charges" ] # list of float : the ion pop charges
6971 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" )
7074
7175 yv , xv = np .meshgrid (y , x )
7276
73- assert len (charges ) == len (densities )
7477 funcs = np .zeros ((x .size , y .size , len (charges )))
7578
7679 for i , (charge , density ) in enumerate (zip (charges , densities )):
@@ -140,8 +143,8 @@ def config_1d():
140143 bx = bx_1d ,
141144 by = by_1d ,
142145 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 },
145148 )
146149
147150 ph .ElectronModel (closure = "isothermal" , Te = 0.0 )
@@ -222,8 +225,8 @@ def config_2d():
222225 bx = bx_2d ,
223226 by = by_2d ,
224227 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 },
227230 )
228231
229232 ph .ElectronModel (closure = "isothermal" , Te = 0.0 )
@@ -255,23 +258,21 @@ def main():
255258 ph .global_vars .sim = None
256259 Simulator (config_2d ()).run ().reset ()
257260
258-
259- def assert_close_enough ( h , H ):
261+ def noise_level ( h , H ):
262+ noises = list ()
260263 for lvl_h , lvl_H in zip (h .levels (time ).values (), H .levels (time ).values ()):
261264 for patch_h , patch_H in zip (lvl_h .patches , lvl_H .patches ):
262265 pd_h = patch_h .patch_datas ["value" ]
263266 pd_H = patch_H .patch_datas ["value" ]
264- ghosts_num = pd_h .ghosts_nbr [0 ]
265267
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
272275
273- for h_ , H_ in zip (dset_h , dset_H ):
274- np .testing .assert_almost_equal (h_ , H_ , decimal = 1 )
275276
276277
277278 fig , ((ax1 , ax2 ), (ax3 , ax4 ), (ax5 , ax6 )) = plt .subplots (3 , 2 , figsize = (6 , 8 ))
@@ -287,8 +288,8 @@ def assert_close_enough(h, H):
287288 H1 = hierarchy_from (hier = h1 , func = ions_mass_density_func1d , masses = masses , densities = (densityMain_1d , densityBeam_1d ))
288289 H2 = hierarchy_from (hier = h2 , func = ions_charge_density_func1d , charges = charges , densities = (densityMain_1d , densityBeam_1d ))
289290
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
292293
293294 cycle = plt .rcParams ['axes.prop_cycle' ].by_key ()['color' ]
294295
@@ -313,8 +314,8 @@ def assert_close_enough(h, H):
313314 H1 = hierarchy_from (hier = h1 , func = ions_mass_density_func2d , masses = masses , densities = (densityMain_2d , densityBeam_2d ))
314315 H2 = hierarchy_from (hier = h2 , func = ions_charge_density_func2d , charges = charges , densities = (densityMain_2d , densityBeam_2d ))
315316
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
318319
319320 cmap = mpl .colormaps ['viridis' ]
320321
@@ -327,8 +328,5 @@ def assert_close_enough(h, H):
327328 plt .savefig ("nCheck.pdf" , dpi = 300 )
328329
329330
330-
331- # /home/smets/codes/far/PHARE/tests/simulator/initialize
332-
333331if __name__ == "__main__" :
334332 main ()
0 commit comments