1. Tutorial
This chapter will provide a jump start describing some of the most common used features of OPAL. The complete set of examples can be found and downloaded at https://gitlab.psi.ch/OPAL/src/wikis/home. All examples are requiring a small amount of computing resources and run on a single core, but can be used efficiently on up to 8 cores. OPAL scales in the weak sense, hence for a higher concurrency one has to increase the problem size i.e. number of macro particles and the grid size, which is beyond this tutorial.
1.1. Starting OPAL
The name of the application is opal
. When called without any argument
an interactive session is started.
\$ opal Ippl> CommMPI: Parent process waiting for children ... Ippl> CommMPI: Initialization complete. > ____ _____ ___ > / __ \| __ \ /\ | | > | | | | |__) / \ | | > | | | | ___/ /\ \ | | > | |__| | | / ____ \| |____ > \____/|_| /_/ \_\______| OPAL > OPAL > This is OPAL (Object Oriented Parallel Accelerator Library) Version 2.0.0 ... OPAL > OPAL > Please send cookies, goodies or other motivations (wine and beer ... ) OPAL > to the OPAL developers opal@lists.psi.ch OPAL > OPAL > Time: 16.43.23 date: 30/05/2017 OPAL > Reading startup file "/Users/adelmann/init.opal". OPAL > Finished reading startup file. ==>
One can exit from this session with the command QUIT;
(including the
semicolon).
For batch runs OPAL accepts the following command line arguments:
Argument | Values | Function |
---|---|---|
--input |
<file > |
the input file. Using "--input" is optional. Instead the input file can be provided either as first or as last argument. |
--info |
0 – 5 |
controls the amount of output to the command line. 0
means no or scarce output, 5 means a lot of output. Default: 1. |
--restart |
-1 – <Integer> |
restarts from given step in file with saved phase space. Per default OPAL tries to restart from a file <file>.h5 where <file>is the input file without extension. -1 stands for the last step in the file. If no other file is specified to restart from and if the last step of the file is chosen, then the new data is appended to the file. Otherwise the data from this particular step is copied to a new file and all new data appended to the new file. |
--restartfn |
<file> |
a file in H5hut format from which OPAL should restart. |
--help |
Displays a summary of all command-line arguments and then quits. |
|
--version |
Prints the version and then quits. |
Example:
opal input.in --restartfn input.h5 --restart -1 --info 3
1.2. Auto-phase Example
This is a partial complete example. First we have to set OPAL in
AUTOPHASE
mode, as described in Section [option] and for example set
the nominal phase to
Option, AUTOPHASE=4; REAL FINSS_RGUN_phi= (-3.5/180*Pi);
The cavity would be defined like
FINSS_RGUN: RFCavity, L = 0.17493, VOLT = 100.0, FMAPFN = "FINSS-RGUN.dat", ELEMEDGE =0.0, TYPE = "STANDING", FREQ = 2998.0, LAG = FINSS_RGUN_phi;
with FINSS_RGUN_phi
defining the off crest phase. Now a normal TRACK
command can be executed. A file containing the values of maximum phases
is created, and has the format like:
1 FINSS_RGUN 2.22793
with the first entry defining the number of cavities in the simulation.
1.3. Examples of Particle Accelerators and Beamlines
Title,string="OBLA Gun"; Option, ECHO=FALSE; Option, PSDUMPFREQ=10; Option, VERSION=10600; REAL Edes=1.0E-9; REAL gamma=(Edes+EMASS)/EMASS; REAL beta=sqrt(1-(1/gamma^2)); REAL gambet=gamma*beta; REAL P0 = gamma*beta*EMASS; REAL brho = (EMASS*1.0e9*gambet) / CLIGHT; value,{gamma,brho,Edes,beta,gambet}; // L: physical element length (real) // KS: field scaling factor (real) // FMAPFN: field file name (string) // ELEMEDGE: physical start of the element on the floor (real) SP1: Solenoid, L=1.20, ELEMEDGE=-0.5335, FMAPFN="1T2.T7", KS=0.00011; SP2: Solenoid, L=1.20, ELEMEDGE=-0.399, FMAPFN="1T3.T7", KS=0.0; SP3: Solenoid, L=1.20, ELEMEDGE=-0.269, FMAPFN="1T3.T7", KS=0.0; gun: RFCavity, L=0.011, VOLT=-102.28, FMAPFN="1T1.T7", ELEMEDGE=0.00, TYPE="STANDING", FREQ=1.0e-6; l1: Line = (gun,sp1,sp2,sp3); REAL rf=1498.956; REAL v0=beta*CLIGHT; REAL lz = 6.5E-12*v0; value,{v0,lz}; Dist1:DISTRIBUTION, TYPE=gungauss, sigmax= 0.00030, sigmapx=0.0, corrx=0.0, sigmay= 0.00030, sigmapy=0.0, corry=0.0, sigmat= lz, sigmapt=1.0, corrt=0.0 , NBIN=39; Fs1:FIELDSOLVER, FSTYPE=FFT, MX=32, MY=32, MT=32, PARFFTX=true, PARFFTY=true, PARFFTT=false, BCFFTX=open, BCFFTY=open, BCFFTT=open, BBOXINCR=1, GREENSF=STANDARD; beam1: BEAM, PARTICLE=ELECTRON, pc=P0, NPART=50000, BCURRENT=0.008993736, BFREQ=rf, CHARGE=-1; Select, Line=l1; track,line=l1, beam=beam1, MAXSTEPS=2000, DT=1.0e-13; run, method = "PARALLEL-T", beam=beam1, fieldsolver=Fs1, distribution=Dist1; endtrack; Stop;
1.3.1. PSI XFEL 250 MeV Injector
Option, ECHO=FALSE; Option, TFS=FALSE; Option, PSDUMPFREQ=10; Option, VERSION=10600; Title,string="OPAL Diagnostics test"; REAL Edes=0.0307; //GeV REAL gamma=(Edes+EMASS)/EMASS; REAL beta=sqrt(1-(1/gamma^2)); REAL gambet=gamma*beta; REAL P0 = gamma*beta*EMASS; REAL brho = (EMASS*1.0e9*gambet) / CLIGHT; value,{gamma,brho,Edes,beta,gambet}; FINLB02_MSLAC40: Solenoid, L=0.001, KS=0.05, FMAPFN="FINLB02-MSLAC.T7", ELEMEDGE=4.554; FIND1_MQ10: Quadrupole, L=0.1, K1=2.788, ELEMEDGE=5.874; FIND1_MQ20: Quadrupole, L=0.1, K1=-3.517, ELEMEDGE=6.074; SCREEN: Monitor, L=0.01, ELEMEDGE=7.3867, OUTFN="Screen.h5"; FIND1: Line = (FINLB02_MSLAC40, FIND1_MQ10, FIND1_MQ20, SCREEN); Dist1:DISTRIBUTION, TYPE=gauss, sigmax= 1.0e-03, sigmapx=1.0e-4, corrx=0.5, sigmay= 2.0e-03, sigmapy=1.0e-4, corry=-0.5, sigmat= 3.0e-03, sigmapt=1.0e-4, corrt=0.0; Fs2:FIELDSOLVER, FSTYPE=FFT, MX=32, MY=32, MT=64, PARFFTX=false, PARFFTY=false, PARFFTT=true, BCFFTX=open, BCFFTY=open, BCFFTT=open, BBOXINCR=1.0, GREENSF=INTEGRATED; beam1: BEAM, PARTICLE=ELECTRON, pc=P0, NPART=1e5, BFREQ=1498.953425154, BCURRENT=0.299598, CHARGE=-1; Select, Line=FIND1; track,line=FIND1, beam=beam1, MAXSTEPS=10000, DT=1.0e-12; run, method = "PARALLEL-T", beam=beam1, fieldsolver=Fs2, distribution=Dist1; endtrack; Stop;
1.3.2. PSI Injector II Cyclotron
Injector II is a separated sector cyclotron specially designed for pre-acceleration (inject: 870 keV, extract: 72 MeV) of high intensity proton beam for Ring cyclotron. It has 4 sector magnets, two double-gap acceleration cavities (represented by 2 single-gap cavities here) and two single-gap flat-top cavities.
Following is an input file of Single Particle Tracking mode for PSI Injector II cyclotron.
Title,string="OPAL-CyclT test"; Option, ECHO=FALSE; Option, PSDUMPFREQ=100000; Option, SPTDUMPFREQ=5; Option, VERSION=10600; // define some physical parameters REAL Edes=0.002; REAL gamma=(Edes+PMASS)/PMASS; REAL beta=sqrt(1-(1/gamma^2)); REAL gambet=gamma*beta; REAL P0 = gamma*beta*PMASS; REAL brho = (PMASS*1.0e9*gambet) / CLIGHT; value,{gamma,brho,Edes,beta,gambet}; REAL phi01= 48.4812-15.0; REAL phi02=phi01+200.0; REAL phi03=phi01+1800.0; REAL phi04=phi01+2000.0; REAL phi05=(phi01+820.0)*3.0; REAL phi06=(phi01+2620.0)*3.0; REAL turns = 106; REAL nstep=5000; // define elements and beamline inj2: Cyclotron, TYPE="Injector2", CYHARMON=10, PHIINIT=30.0, PRINIT=-0.0067, RINIT=392.5, SYMMETRY=1.0, RFFREQ=frequency, FMAPFN="../ZYKL9Z.NAR"; rf0: RFCavity, VOLT=0.25796, FMAPFN="../av1.dat", TYPE="SINGLEGAP", FREQ=frequency, ANGLE=35.0, PHI0=phi01, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf1: RFCavity, VOLT=0.25796, FMAPFN="../av1.dat", TYPE="SINGLEGAP", FREQ=frequency, ANGLE=55.0, PHI0=phi02, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf2: RFCavity, VOLT=0.25796, FMAPFN="../av1.dat", TYPE="SINGLEGAP", FREQ=frequency, ANGLE=215.0, PHI0=phi03, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf3: RFCavity, VOLT=0.25796, FMAPFN="../av1.dat", TYPE="SINGLEGAP", FREQ=frequency, ANGLE=235.0, PHI0=phi04, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf4: RFCavity, VOLT=0.06380, FMAPFN="../av3.dat", TYPE="SINGLEGAP", FREQ=frequency3, ANGLE=135.0, PHI0=phi05, RMIN = 830.0, RMAX = 3330.0, PDIS = 0.0, GAPWIDTH = 0.0; rf5: RFCavity, VOLT=0.06380, FMAPFN="../av3.dat", TYPE="SINGLEGAP", FREQ=frequency3, ANGLE=315.0, PHI0=phi06, RMIN = 830.0, RMAX = 3330.0, PDIS = 0.0, GAPWIDTH = 0.0; l1: Line = (inj2,rf0,rf1,rf2,rf3,rf4,rf5); // define particles distribution, read from file Dist1:DISTRIBUTION, TYPE=fromfile, FNAME="PartDatabase.dat"; // usset define fieldsolver, useless for single particle track mode Fs1:FIELDSOLVER, FSTYPE=NONE, MX=64, MY=64, MT=64, PARFFTX=true, PARFFTY=true, PARFFTT=false, BCFFTX=open, BCFFTY=open, BCFFTT=open; // define beam parameters beam1: BEAM, PARTICLE=PROTON, pc=P0, NPART=1, BCURRENT=0.0; // select beamline Select, Line=l1; // start tracking track,line=l1, beam=beam1, MAXSTEPS=nstep*turns, STEPSPERTURN=nstep,TIMEINTEGRATOR="RK-4"; run, method = "CYCLOTRON-T", beam=beam1, fieldsolver=Fs1, distribution=Dist1; endtrack; Stop;
To run opal on a single node, just use this command:
opal testinj2-1.in
Here shows some pictures using the resulting data from single particle tracking using OPAL-cycl.
Left plot of Figure 1 shows the accelerating orbit of reference particle. After 106 turns, the energy increases from 870 keV at the injection point to 72.16 MeV at the deflection point.
From theoretic view, there should be an eigen ellipse for any given energy in stable area of a fixed accelerator structure. Only when the initial phase space shape matches its eigen ellipse, the oscillation of beam envelop amplitude will get minimal and the transmission efficiency get maximal. We can calculate the eigen ellipse by single particle tracking using betatron oscillation property of off-centered particle as following: track an off-centered particle and record its coordinates and momenta at the same azimuthal position for each revolution. Figure 2 shows the eigen ellipse at symmetric line of sector magnet for energy of 2 MeV in Injector II.
Right plot of Figure 1 shows very good agreement of the tune diagram by OPAL-cycl and FIXPO. The trivial discrepancy should come from the methods they used. In FIXPO, the tune values are obtained according to the crossing points of the initially displaced particle. Meanwhile, in OPAL-cycl, the Fourier analysis method is used to manipulate orbit difference between the reference particle and an initially displaced particle. The frequency point with the biggest amplitude is the betatron tune value at the given energy.
Following is the input file for single bunch tracking with space charge effects in Injector II.
// file name ''testinj2-2.in'' // Define Option parameters Option, ECHO=FALSE; Option, PSDUMPFREQ=10; Option, SPTDUMPFREQ=5; Option, REPARTFREQ=10; Option, VERSION=10600; // Define title Title,string="OPAL-CyclT-SC test"; // define some physical parameters REAL Edes=0.000870; REAL gamma=(Edes+PMASS)/PMASS; REAL beta=sqrt(1-(1/gamma^2)); REAL gambet=gamma*beta; REAL P0 = gamma*beta*PMASS; REAL brho = (PMASS*1.0e9*gambet) / CLIGHT; REAL phi01= 48.4812-15.0; REAL phi02=phi01+200.0; REAL phi03=phi01+1800.0; REAL phi04=phi01+2000.0; REAL phi05=(phi01+820.0)*3.0; REAL phi06=(phi01+2620.0)*3.0; REAL frequency=50.6370; REAL frequency3=3.0*frequency; REAL turns = 106; REAL nstep=5000; // define elements and beamline inj2: Cyclotron, TYPE="Injector2", CYHARMON=10, PHIINIT=30.0, PRINIT=-0.0067, RINIT=392.5, SYMMETRY=1.0, RFFREQ=50.6370, FMAPFN="../../ZYKL9Z.NAR"; rf0: RFCavity, VOLT=0.25796, FMAPFN="../../Cav1.dat", TYPE="SINGLEGAP", FREQ=50.637, ANGLE=35.0, PHI0=phi01, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf1: RFCavity, VOLT=0.25796, FMAPFN="../../Cav1.dat", TYPE="SINGLEGAP", FREQ=50.637, ANGLE=55.0, PHI0=phi02, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf2: RFCavity, VOLT=0.25796, FMAPFN="../../Cav1.dat", TYPE="SINGLEGAP", FREQ=50.637, ANGLE=215.0, PHI0=phi03, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf3: RFCavity, VOLT=0.25796, FMAPFN="../../Cav1.dat", TYPE="SINGLEGAP", FREQ=50.637, ANGLE=235.0, PHI0=phi04, RMIN = 350.0, RMAX = 3350.0, PDIS = 0.0, GAPWIDTH = 0.0; rf4: RFCavity, VOLT=0.06380, FMAPFN="../../Cav3.dat", TYPE="SINGLEGAP", FREQ=151.911, ANGLE=135.0, PHI0=phi05, RMIN = 830.0, RMAX = 3330.0, PDIS = 0.0, GAPWIDTH = 0.0; rf5: RFCavity, VOLT=0.06380, FMAPFN="../../Cav3.dat", TYPE="SINGLEGAP", FREQ=151.911, ANGLE=315.0, PHI0=phi06, RMIN = 830.0, RMAX = 3330.0, PDIS = 0.0, GAPWIDTH = 0.0; l1: Line = (inj2,rf0,rf1,rf2,rf3,rf4,rf5); // define particles distribution, generate Gaussion type Dist1:DISTRIBUTION, TYPE=gauss, sigmax= 2.0e-03, sigmapx=1.0e-7, corrx=0.0, sigmay= 2.0e-03, sigmapy=1.0e-7, corry=0.0, sigmat= 2.0e-03, sigmapt=1.8e-4, corrt=0.0; // define parallel FFT fieldsolver, parallel in x y direction Fs1:FIELDSOLVER, FSTYPE=FFT, MX=32, MY=32, MT=32, PARFFTX=true, PARFFTY=true, PARFFTT=false, BCFFTX=open, BCFFTY=open, BCFFTT=open,BBOXINCR=5; // define beam parameters beam1: BEAM, PARTICLE=PROTON, pc=P0, NPART=1e5, BCURRENT=3.0E-3, CHARGE=1.0, BFREQ= frequency; // select beamline Select, Line=l1; // start tracking track,line=l1, beam=beam1, MAXSTEPS=nstep*turns, STEPSPERTURN=nstep, TIMEINTEGRATOR="LF-2"; run, method = "CYCLOTRON-T", beam=beam1, fieldsolver=Fs1, distribution=Dist1; endtrack; Stop;
To run opal on single node, just use this command:
# opal testinj2-2.in
To run opal on N nodes in parallel environment interactively, use this command instead:
# mpirun -np N opal testinj2-2.in
If restart a job from the last step of an existing .h5 file, add a new argument like this:
# mpirun -np N opal testinj2-2.in --restart -1
1.3.3. PSI Ring Cyclotron
From the view of numerical simulation, the difference between Injector II and Ring cyclotron comes from two aspects:
- B Field
-
The structure of Ring is totally symmetric, the field on median plain is periodic along azimuthal direction, OPAL-cycl take this advantage to only store field data to save memory.
- RF Cavity
-
In the Ring, all the cavities are typically single gap with some parallel displacement from its radial position.OPAL-cycl have an argument
PDIS
to manipulate this issue.
Figure 5 shows a single particle tracking result and tune calculation result in the PSI Ring cyclotron. Limited by size of the user guide, we don’t plan to show too much details as in Injector II.
1.4. Translate Old to New Distribution Commands
As of OPAL 1.2, the distribution command see Chapter [distribution] was changed significantly. Many of the changes were internal to the code, allowing us to more easily add new distribution command options. However, other changes were made to make creating a distribution easier, clearer and so that the command attributes were more consistent across distribution types. Therefore, we encourage our users to refer to when creating any new input files, or if they wish to update existing input files.
With the new distribution command, we did attempt as much as possible to make it backward compatible so that existing OPAL input files would still work the same as before, or with small modifications. In this section of the manual, we will give several examples of distribution commands that will still work as before, even though they have antiquated command attributes. We will also provide examples of commonly used distribution commands that need small modifications to work as they did before.
An important point to note is that it is very likely you will see small changes in your simulation even when the new distribution command is nominally generating particles in exactly the same way. This is because random number generators and their seeds will likely not be the same as before. These changes are only due to OPAL using a different sequence of numbers to create your distribution, and not because of errors in the calculation. (Or at least we hope not.)
1.4.1. GUNGAUSSFLATTOPTH
and ASTRAFLATTOPTH
Distribution Types
The GUNGAUSSFLATTOPTH
and ASTRAFLATTOPTH
distribution types
see Section astraflattopthdisttype are two
common types previously implemented to simulate electron beams emitted
from photocathodes in an electron photoinjector. These are no longer
explicitly supported and are instead now defined as specialized
sub-types of the distribution type FLATTOP
. That is, the emitted
distributions represented by GUNGAUSSFLATTOPTH
and ASTRAFLATTOPTH
can now be easily reproduced by using the FLATTOP
distribution type
and we would encourage use of the new command structure.
Having said this, however, old input files that use the
GUNGAUSSFLATTOPTH
and ASTRAFLATTOPTH
distribution types will still
work as before, with the following exception. Previously, OPAL had a
Boolean OPTION
command FINEEMISSION
(default value was TRUE
). This
OPTION
is no longer supported. Instead you will need to set the
distribution attribute EMISSIONSTEPS
see Table [distattremitted] to a
value that is 10
NBIN
see Table [distattruniversal] in order for your
simulation to behave the same as before.
1.4.2. FROMFILE
, GAUSS
and BINOMIAL
Distribution Types
The FROMFILE
see Section [fromfiledisttype], GAUSS
see Section [gaussdisttype] and BINOMIAL
see Section [binomialdisttype] distribution types have changed from
previous versions of OPAL. However, legacy distribution commands
should work as before with one exception. If you are using OPAL-cycl
then your old input files will work just fine. However, if you are using
OPAL-t then you will need to set the distribution attribute
INPUTMOUNITS
see Section [unitsdistattributes] to:
INPUTMOUNITS = EV