1111 Otherwise, one can just type exit()
1212"""
1313# Import warp-specific packages
14- from warp_init_tools import *
14+ from warp . init_tools import *
1515
1616# -----------------------------------------------------------------------------
1717# Parameters (Modify the values below to suit your needs)
2424# Number of azimuthal modes beyond m=0, for "circ" (not used for "2d" and "3d")
2525circ_m = 1
2626# Total number of timesteps in the simulation
27- N_steps = 500
27+ N_steps = 401
2828# Whether to run the simulation interactively (0:off, 1:on)
2929interactive = 0
3030
5959# Diagnostics
6060# -----------
6161# Period of diagnostics (in number of timesteps)
62- diag_period = 100
62+ diag_period = 5
6363# Whether to write the fields
6464write_fields = 1
6565# Whether to write the particles
8181# Current smoothing parameters
8282# ----------------------------
8383# Turn current smoothing on or off (0:off; 1:on)
84- use_smooth = 1
84+ use_smooth = 1
8585# Number of passes of smoother and compensator in each direction (x, y, z)
8686npass_smooth = array ([[ 0 , 0 ], [ 0 , 0 ], [ 1 , 1 ]])
8787# Smoothing coefficients in each direction (x, y, z)
128128# Number of macroparticles per cell in each direction
129129# In Circ, nppcelly is the number of particles along the
130130# azimuthal direction. Use a multiple of 4*circ_m
131- plasma_nx = 2
131+ plasma_nx = 1
132132plasma_ny = 4
133- plasma_nz = 2
133+ plasma_nz = 1
134134
135135# Plasma content and profile
136136# --------------------------
159159def plasma_dens_func ( x , y , z ):
160160 """
161161 User-defined function: density profile of the plasma
162-
162+
163163 It should return the relative density with respect to n_plasma,
164164 at the position x, y, z (i.e. return a number between 0 and 1)
165165
@@ -189,7 +189,7 @@ def plasma_dens_func( x, y, z ):
189189# -----------------
190190# Initialize beam electrons (0:off, 1:on)
191191# (Please be aware that initializing a beam in 2D geometry makes very little
192- # physical sense, because of the long range of its space-charge fields)
192+ # physical sense, because of the long range of its space-charge fields)
193193use_beam = 0
194194# Longitudinal momentum of the beam
195195beam_uz = 100.
@@ -212,7 +212,7 @@ def plasma_dens_func( x, y, z ):
212212def beam_dens_func (x , y , z ):
213213 """
214214 User-defined function: density profile of the beam
215-
215+
216216 It should return the relative density with respect to n_beam,
217217 at the position x, y, z (i.e. return a number between 0 and 1)
218218
@@ -274,6 +274,7 @@ def beam_dens_func(x, y, z):
274274 beam_nz , dim , circ_m )
275275 beam = Species (type = Electron , weight = beam_weight , name = 'beam' )
276276# Set the numerical parameters only now: they affect the newly created species
277+ top .ssnpid = nextpid ()
277278set_numerics ( depos_order , efetch , particle_pusher , dim )
278279
279280# Setup the field solver object
@@ -316,35 +317,37 @@ def beam_dens_func(x, y, z):
316317# Continuously inject the plasma, if the moving window is on
317318if use_moving_window :
318319 installuserinjection ( plasma_injector .continuous_injection )
319-
320+
320321# Setup the diagnostics
321322# ---------------------
322323if write_fields == 1 :
323324 diag1 = FieldDiagnostic ( period = diag_period , top = top , w3d = w3d , em = em ,
324325 comm_world = comm_world , lparallel_output = parallel_output ,
325- write_dir = './example-2d' )
326- installafterstep ( diag1 .write )
326+ write_dir = './example-2d' , fieldtypes = ["E" , "rho" ] )
327327if write_particles == 1 :
328328 species_dict = { species .name : species for species in listofallspecies \
329- if not ( species .name in [ "Hydrogen0+" , "electron from Hydrogen" ] ) }
329+ if species .name == "electrons" }
330330 diag2 = ParticleDiagnostic ( period = diag_period , top = top , w3d = w3d ,
331331 species = species_dict , write_dir = './example-2d' ,
332+ particle_data = {"position" ,"momentum" ,"weighting" ,"id" },
333+ comm_world = comm_world , lparallel_output = parallel_output )
334+ species_dict = { species .name : species for species in listofallspecies \
335+ if species .name == "Hydrogen1+" }
336+ diag3 = ParticleDiagnostic ( period = diag_period , top = top , w3d = w3d ,
337+ species = species_dict , write_dir = './example-2d' ,
338+ sub_sample = 10 ,
332339 comm_world = comm_world , lparallel_output = parallel_output )
333- installafterstep ( diag2 .write )
334340
335341print ('\n Initialization complete\n ' )
336342
337343# -----------------------------------------------------------------------------
338344# Simulation loop (Normal users should not modify this part either.)
339345# -----------------------------------------------------------------------------
340346
341- # Non-interactive mode
342- if interactive == 0 :
343- n_stepped = 0
344- while n_stepped < N_steps :
345- step (10 )
346- n_stepped = n_stepped + 10
347-
348- # Interactive mode
349- elif interactive == 1 :
350- print '<<< To execute n steps, type "step(n)" at the prompt >>>'
347+ step (250 )
348+ installafterstep ( diag1 .write )
349+ installafterstep ( diag2 .write )
350+ installafterstep ( diag3 .write )
351+ step (151 )
352+
353+
0 commit comments