Closed snwdiphone1994 closed 3 years ago
In general there are two ways to combine beams. The simplest is to generate two beams and add them together. This is detailed in the basics.ipynb that you can get from the examples folder in the repo:
https://github.com/ColwynGulliford/distgen/blob/master/examples/basic.ipynb
Create the first beam and save it to a ParticleGroup object:
Create a second beam:
And add them together:
The resulting particle group can be used to access the combined beam. Please see the OpenPMD-beamphysics repository for details on how to output the particles to input files for various beam codes: https://github.com/ChristopherMayes/openPMD-beamphysics
You can also use the particle group to write your own particles to file. Coordinates are accessed like this: x_coordinates = pg['x]
Does this solve your problem? The other way to combine beams is to use the superposition operator, which is described in the example_dists notebook.
If that does not solve things, could you describe the beam you are trying to create?
@ColwynGulliford
Thank you very much for your reply. The fact that the different ParticleGroup objects can be added directly is very useful.
In the attached file, we want to set px = py =0 and import PDF in pz800.1d.txt to set the distribution of pz.
pz_dist: file: pz800.1d.txt type: file1d units: eV/c
But the program finally calculates the distribution of pz(as shown in Fig.1) which is not what we want((as shown in Fig.2)).Thanks for the feedback. Fig1 Fig2
Here is an example that I believe does what you want:
n_particle: 20000 output: file: example.out.txt type: gpt pz_dist: file: cutgauss.pz.txt type: file1d units: eV/c random_type: hammersley start: tstart: units: sec value: 0 type: time total_charge: units: pC value: 10
Where the file "cutlass.pz.txt" stores the same pz PDF you sent (I believe this comes from the distgen examples/data folder). Running the above yaml file gives:
which looks like your figure (1). One thing to be careful with is the "start" type used in the main yaml input file. If you use cathode, then distgen assumes a Gaussian distribution for the px, py, pz. In your example you want to have a non-Gaussian pz PDF, so make sure to have start:type: time (time start). When creating a bunch at a given time, the code does not assume a particle emission model from a cathode, and gives you full control over px, py, pz.
Thanks for you submission. Please let me know if you have any further questions.
@ColwynGulliford
If I set start:type: time, then I can not specified t distribution for time start. If I set start:type: cathode, then I can not specified Px,Py,Pz distributions. So is there a way to customize the time distribution (Gaussian) and momentum distributions (cutgauss.pz.txt)? Thanks again for your reply
I've added a feature that let's you remove the 'start' key from the input yaml file, and in that mode it will allow you to set: x, y, z, px, py, pz, t, however you like.
Here is an input file that set's pz and t (Gaussian):
n_particle: 20000 output: file: example.out.txt type: gpt pz_dist: file: cutgauss.pz.txt type: file1d units: eV/c t_dist: type: g sigma_t: value: 10 units: ps random_type: hammersley total_charge: units: pC value: 10
These changes have been pushed to the repo. Are you using Conda to install the package? If so I can issue a new release.
@ColwynGulliford ,Thank you for spending so much time and energy to solve my confusion. The problem has been well solved
Thanks you for using the code, I'm happy to help.
Recently we had a problem with distgen:How to use distgen to generate two different particle beams(Different time distributions, different space distributions, different momentum distributions)? Is it possible to make some changes in the YAML input file?