CSRBendDrift.in 8 KB
Newer Older
1 2 3 4
Option, ECHO=FALSE;
Option, INFO=FALSE;
Option, AUTOPHASE=0;
Option, CSRDUMP=TRUE;
5
Option, VERSION=10900;
6 7 8 9 10 11 12 13

Title, string="FEL ERL";

//******************************************************************************************************************
// GLOBAL PARAMETERS
//
// Here we define some global simulation parameters.

14 15
REAL RF_FREQUENCY = 100.0e6;			     // Reference frequency of problem (Hz).
REAL RF_WAVELENGTH = CLIGHT / RF_FREQUENCY; 	     // Reference wavelength (m).
16

17 18
REAL Q_E = 1.60217653e-19;  	 		     // Elementary charge (C).
REAL E_MASS = 9.10938188e-31;		     // Mass of electron (kg).
19

20 21
REAL BEAM_BUNCH_CHARGE = 1.0e-9;     	     // Beam bunch charge (C).
REAL NUMBER_OF_PARTICLES = 5000; 	 	     // Number of particles in simulation
22

23 24
REAL PS_DUMP_FREQUENCY = 20;     		     // How often (time steps) that the phase space of the beam is output.
REAL STAT_DUMP_FREQUENCY = 1; 		     // How often (time steps) beam statistical properties are output.
25 26 27 28 29 30 31 32 33 34 35 36 37 38

value, {RF_FREQUENCY,
        RF_WAVELENGTH,
        BEAM_BUNCH_CHARGE,
	NUMBER_OF_PARTICLES,
	PS_DUMP_FREQUENCY,
	STAT_DUMP_FREQUENCY};

//============================================
// Timestep information.
//================================================

// Time steps defined.

39
REAL TIME_STEP_1 = 4.3734562802893905e-12;		// Time step (s). We only need one for this simulation.
40 41

value, {TIME_STEP_1};
42

43 44 45 46 47 48 49 50
//******************************************************************************************************************
// FIELD SOLVERS
//
// Here we define the field solvers (FS) to be used in the simulation.

// First define the space charge (SC) mesh.

// Space charge mesh.
51 52
REAL FS_SC1_X_BINS = 8; // Number of mesh bins in x direction for space charge field solver.
REAL FS_SC1_Y_BINS = 8; // Number of mesh bins in y direction for space charge field solver.
53
REAL FS_SC1_Z_BINS = 64; // Number of mesh bins in z direction for space charge field solver.
54 55 56 57 58 59 60

value, {FS_SC1_X_BINS,
        FS_SC1_Y_BINS,
	FS_SC1_Z_BINS};


// CSR.
61
REAL CSR_ON = 1;		       // If greater than 0, use the CSR calculation in the bends.
62

63
REAL CSR_FFT_FREQ = -1; 	       // Specifies the number of FFT frequencies to keep in FFT low pass filter.
64 65
	       		       // If less than zero the FFT filter is not used.

66 67 68
REAL CSR_SG_NLEFT = 4;              // Number of points to the left of the mesh point to use in Savitzky-Golay smoothing.
REAL CSR_SG_NRIGHT = 4;             // Number of points to the the right of the mesh point to use in Savitzky-Golay smoothing.
REAL CSR_SG_POLYORDER = 4; 	       // The polynomial order to use in Savitzky-Golay smoothing.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

value, {CSR_ON,
        CSR_FFT_FREQ,
	CSR_SG_NLEFT,
	CSR_SG_NRIGHT,
	CSR_SG_POLYORDER};

//******************************************************************************************************************
// BEAM LINE
//
// Here we define lengths, positions, phases, field multipliers/strengths etc. for the various components of the
// accelerator.

// Beam line offset. This is global shift of the entire line (m).
//===============================================================
84
REAL global_shift = 1.0;
85 86 87 88 89 90 91 92 93


// Bend.
//
// We have one bend in the system for checking CSR
// calculations.
//================================================

// drift before bend (m).
94
REAL drift_before_bend = 0.1;
95 96

// Bend angle (radians).
97
REAL bend_angle = 0.5235987755982988;
98

99
// Bend design energy (MeV).
100 101 102 103 104 105
REAL bend_energy = 6.50762633;

REAL gamma = (bend_energy * 1e-3 + EMASS)/EMASS;
REAL beta = sqrt(1-(1/gamma^2));
REAL gambet = gamma*beta;
REAL P0 = gamma*beta*EMASS;
106 107

// Bend length (m).
108
REAL bend_length = 0.129409522551;
109 110 111 112 113 114 115 116 117 118 119 120 121 122


value, {drift_before_bend,
        bend_angle,
	bend_energy,
	bend_length};

//******************************************************************************************************************
// DEFINE FIELD SOLVERS
//
// Here we define field solvers (FS) using the parameters defined in the layout section.

// First space charge field solver.

adelmann's avatar
adelmann committed
123
FS_SC1: Fieldsolver, FSTYPE = NONE,
124 125 126 127 128
		     MX = FS_SC1_X_BINS,
		     MY = FS_SC1_Y_BINS,
		     MT = FS_SC1_Z_BINS,
		     PARFFTX = true,
		     PARFFTY = true,
adelmann's avatar
adelmann committed
129
		     PARFFTT = true,
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
		     BCFFTX = open,
		     BCFFTY = open,
		     BCFFTT = open,
		     BBOXINCR = 2,
		     GREENSF = INTEGRATED;


// CSR wake solver (CSR).
// Note that the maximum number of frequencies that can be used in FS_SC2_Z_BINS / 2 - 1.

SG_FILTER: Filter, TYPE = "Savitzky-Golay",
	   	   NPOINTS = CSR_SG_NLEFT + CSR_SG_NRIGHT + 1,
		   NLEFT = CSR_SG_NLEFT,
		   NRIGHT = CSR_SG_NRIGHT,
		   POLYORDER = CSR_SG_POLYORDER;

if (CSR_FFT_FREQ >= 1) {

   if (CSR_FFT_FREQ > FS_SC2_Z_BINS / 2 - 1) {

      CSR_FFT_FREQ = FS_SC2_Z_BINS / 2 - 1;

}

   FFT_Filter: Filter, TYPE = "FixedFFTLowPass",
	 	       NFREQ = CSR_FFT_FREQ

   FS_CSR_WAKE: Wake, TYPE = "1D-CSR",
	  	   FILTERS = {FFT_Filter,
159
		   	      SG_Filter};
160 161 162

} else {

163
   FS_CSR_WAKE: Wake, TYPE = "1D-CSR",
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	  	   FILTERS = {SG_Filter};

}

//******************************************************************************************************************
// COMPONENTS
//
// Here we define the actual accelerator components using the parameters from the layout section.
//******************************************************************************************************************
// Dipole
//
// L:			physical element length (real in m)
// K0: 		     	y magnetic field (real)
// FMAPFN:	     	field file name (string)
// ELEMEDGE:	     	physical start of the element on the floor (real in m)
// ALPHA:            	entrance angle (degrees). Exit angle is calculated automatically (bend is rectangular).
// DESIGNENERGY:     	energy of design beam
// WAKEF:		wake function attached to dipole
//

if (CSR_ON > 0) {
   bend1: SBend, ANGLE = bend_angle,
                E1 = 0.08726646259971647,
                E2 = 0.08726646259971647,
   	 	FMAPFN = "1DPROFILE1-DEFAULT",
	       	ELEMEDGE = drift_before_bend,
	       	DESIGNENERGY = bend_energy,
		L = bend_length,
                GAP = 0.02,
	       	WAKEF = FS_CSR_WAKE;
194 195 196 197
   drift2:DRIFT, L=0.4, ELEMEDGE=bend_length + drift_before_bend, WAKEF = FS_CSR_WAKE;
//     drift2:DRIFT, L=0.4, ELEMEDGE=0.225 , WAKEF = FS_CSR_WAKE;


198 199 200 201 202 203 204 205 206
} else {
   bend1: SBend, ANGLE = bend_angle,
                E1 = 0.08726646259971647,
                E2 = 0.08726646259971647,
   	 	FMAPFN = "1DPROFILE1-DEFAULT",
	       	ELEMEDGE = drift_before_bend,
	       	DESIGNENERGY = bend_energy,
		L = bend_length,
                GAP = 0.02;
207
   drift2:DRIFT, L=0.4, ELEMEDGE=0.4 + bend_length + drift_before_bend;
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
}

//******************************************************************************************************************
// DEFINE BEAM LINES
//
// Here we define beam lines using previously defined elements.

inputBeamline: Line = (bend1, drift2);

//******************************************************************************************************************
// INITIAL DISTRIBUTIONS
//
// Initial beam distributions.
//

223
dist1:DISTRIBUTION, TYPE=FROMFILE,
224 225 226 227 228 229 230 231 232 233 234 235 236 237
                    FNAME = "input_beam.dat";

//******************************************************************************************************************
// RUN SIMULATION
//
// Here we start simulation.

Option, PSDUMPFREQ = PS_DUMP_FREQUENCY;
Option, STATDUMPFREQ = STAT_DUMP_FREQUENCY;


//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// Here we define beam that will be transported.
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
238
beam1: BEAM, PARTICLE = ELECTRON, pc = P0, NPART = NUMBER_OF_PARTICLES, BFREQ = RF_FREQUENCY * 1e-6,
239
      	BCURRENT = BEAM_BUNCH_CHARGE * RF_FREQUENCY,
240 241 242 243 244 245 246
        CHARGE = -1;


//\\\\\\\\\\\\\\\\
// Run simulation.
//\\\\\\\\\\\\\\\\

247
TRACK, LINE = inputBeamline, BEAM = beam1, MAXSTEPS = 2000, DT = TIME_STEP_1, ZSTOP=0.63160;
248
  RUN, METHOD = "PARALLEL-T", BEAM = beam1, FIELDSOLVER = FS_SC1,
249 250 251 252
       DISTRIBUTION = dist1;
ENDTRACK;

Stop;
253
Quit;