Confusing number density when initializing particles from an array in cylindrical geometry #797
Replies: 2 comments 1 reply
-
I might not have understood your setup but you apparently set the weight from sizes in mm, whereas everything should be in code units (see the units documentation) Let me also convert this to a discussion as it is not a bug or a request |
Beta Was this translation helpful? Give feedback.
-
Hello, if some context info can help, I wrote those lines for the weight assuming a bunch with a Gaussian distribution in all directions, e.g. For cylindrical symmetry, I assumed This namelist uses the same principle, defining an electron bunch with 60 pC: Through the postprocessing script here: The |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I hope to create a gaussian number density in cylindrical geometry with a defined peak density from an python array. Therefore, I follow the method in the official tutorials(advanced_beam_driven_wake.py) to set up the array. (The whole code is in the attached file)
input.txt
proton bunch parameters
sigma_x = 20mm # initial longitudinal rms size
sigma_r = 3mm # initial transverse/radial rms size (cylindrical symmetry)
bunch_energy_spread = 0.000 # initial rms energy spread / average energy (not in percent)
bunch_normalized_emittance = 0.00000mm_mrad # initial rms emittance, same emittance for both transverse planes
gamma_bunch = mp_to_megammabeta # gammabeta for proton; initial relativistic Lorentz factor of the bunch
nb= 1e18/ncrit # max density of bunch
npart = 200000 # number of computational macro-particles to model the electron bunch
normalized_species_charge = 1 # For positive muons
weight = 2np.pinp.sqrt(2np.pi)nbsigma_r**2sigma_x/npart
initialize the bunch using numpy arrays
the bunch will have npart particles, so an array of npart elements is used to define the x coordinate of each particle and so on ...
array_position = np.zeros((4,npart)) # positions x,y,z weight
array_momentum = np.zeros((3,npart)) # momenta x,y,z
The proton bunch is supposed at waist. To make it convergent/divergent, transport matrices can be used
array_position[0,:] = np.random.normal(loc=center_bunch_x, scale=sigma_x, size=npart) # generate random number from gaussian distribution for x position
array_position[1,:] = np.random.normal(loc=center_bunch_y, scale=sigma_r, size=npart) # generate random number from gaussian distribution for y position
array_position[2,:] = np.random.normal(loc=center_bunch_y, scale=sigma_r, size=npart)
array_momentum[0,:] = np.random.normal(loc=gamma_bunch, scale=bunch_energy_spreadgamma_bunch, size=npart) # generate random number from gaussian distribution for px position # assumption: bunch defined at waist (zero rms divergence)
array_momentum[1,:] = np.random.normal(loc=0., scale=bunch_normalized_emittance/sigma_rgamma_bunch, size=npart) # generate random number from gaussian distribution for py position
array_momentum[2,:] = np.random.normal(loc=0., scale=bunch_normalized_emittance/sigma_r*gamma_bunch, size=npart) # generate random number from gaussian distribution for pz position
array_position[3,:] = np.multiply(np.ones(npart),weight)
However, the number density obtained from the ParticleBinning diagnostic does not match my expectations.
The related ParticleBinning diagnostic is shown below
DiagParticleBinning(
deposited_quantity = "weight",
every = 1,
time_average = 1,
species = ["bunch"],
axes = [
["moving_x", 0. , Lx , 200 ],
["y" , -Lr , Lr , 200],
]
)
Additionally, when I change the sigmar, I find that the peak density is changed in inverse proportion. Also when I let the weight be direct proportion to sigmar and sigmax, the peak density almost remains unchanged.
I wonder why this is happening and in which way I could initialize the particles as wanted.
update: I have found the weight should be set in direct proportion to sigmar _sigmax nb0 1/omega0(omega0 is the reference omega), but I cannot exactly understand or explain the reason.
Beta Was this translation helpful? Give feedback.
All reactions