An example of using a matrix in place of a chicane to determine
the optimal R56 in a linac bunch compression system.

Example by M. Borland, APS, 2024.

===

cleanUp
        Script to clean up files after a run

compression.lte
        Lattice file. Basically, a matrix representation for the bunch
        compressor, bracketed by two linacs with wakefields.

compressionOpt.ele
        Optimizes R56, voltage, and phase to minimize bunch length
        while obtaining at least 90% of the beam through a +/-0.5% momentum filter

compression.ele
        Runs the optimized result

knsl45.liwake.sdds
        SLAC structure wake function, from P. Emma.

===

Sequence

# Determine the number of cores available
nc=`nproc`
# Optimize with Pelegant, leaving 2 cores unused
mpiexec -np $((nc-2)) Pelegant compressionOpt.ele
# Run optimized result with Pelegant, leaving 2 cores unsed
mpiexec -np $((nc-2)) Pelegant compression.ele
# Plot (dt, delta) phase space
sddsplot -offset=yp=pCentral,yinv -factor=yp=pCentral,yinv -ylabel='$gd$r' \
         -convert=col,dt,ps,s,1e12 -col=dt,p compression.w? -graph=dot,vary


