Skip to content

Commit

Permalink
Add app IOTA lens example.
Browse files Browse the repository at this point in the history
  • Loading branch information
cemitch99 committed Nov 29, 2023
1 parent a676d5d commit 00b2d2a
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 8 deletions.
109 changes: 109 additions & 0 deletions examples/iota_lens/input_iotalens_sdep.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
###############################################################################
# Particle Beam(s)
###############################################################################
beam.npart = 10000
beam.units = static
beam.kin_energy = 2.5
beam.charge = 1.0e-9
beam.particle = proton
beam.distribution = waterbag
#beam.sigmaX = 2.0e-3
#beam.sigmaY = 2.0e-3
#beam.sigmaT = 1.0e-3
#beam.sigmaPx = 3.0e-4
#beam.sigmaPy = 3.0e-4
#beam.sigmaPt = 0.0
#beam.muxpx = 0.0
#beam.muypy = 0.0
#beam.mutpt = 0.0
beam.sigmaX = 1.397456296195e-003
beam.sigmaY = 1.397456296195e-003
beam.sigmaT = 1.0e-4
beam.sigmaPx = 1.256184325020e-003
beam.sigmaPy = 1.256184325020e-003
beam.sigmaPt = 0.0
beam.muxpx = 0.8090169943749474
beam.muypy = 0.8090169943749474
beam.mutpt = 0.0


###############################################################################
# Beamline: lattice elements and segments
###############################################################################
lattice.elements = monitor lens const monitor

lens.type = line
lens.elements = = dr_end nll1 dr nll2 dr nll3 dr nll4 dr nll5 dr nll6 \
dr nll7 dr nll8 dr nll9 dr nll9 dr nll8 dr nll7 \
dr nll6 dr nll5 dr nll4 dr nll3 dr nll2 dr nll1 \
dr_end

# Nonlinear lens segments
nll1.type = nonlinear_lens
nll1.knll = 2.2742558121e-6
nll1.cnll = 0.013262040169952

nll2.type = nonlinear_lens
nll2.knll = 2.641786366e-6
nll2.cnll = 0.012304986694423

nll3.type = nonlinear_lens
nll3.knll = 3.076868353e-6
nll3.cnll = 0.011401855643727

nll4.type = nonlinear_lens
nll4.knll = 3.582606522e-6
nll4.cnll = 0.010566482535866

nll5.type = nonlinear_lens
nll5.knll = 4.151211157e-6
nll5.cnll = 0.009816181575902

nll6.type = nonlinear_lens
nll6.knll = 4.754946985e-6
nll6.cnll = 0.0091718544892154

nll7.type = nonlinear_lens
nll7.knll = 5.337102374e-6
nll7.cnll = 0.008657195579489

nll8.type = nonlinear_lens
nll8.knll = 5.811437818e-6
nll8.cnll = 0.008296371635942

nll9.type = nonlinear_lens
nll9.knll = 6.081693334e-6
nll9.cnll = 0.008109941789663

dr.type = drift
dr.ds = 0.1

dr_end.type = drift
dr_end.ds = 0.05

# Focusing of the external lattice
const.type = constf
const.ds = 1.0e-8
const.kx = 12060.113295833
const.ky = 12060.113295833
const.kt = 1.0e-12
const.nslice = 1

# Beam Monitor: Diagnostics
monitor.type = beam_monitor
monitor.backend = h5

###############################################################################
# Algorithms
###############################################################################
algo.particle_shape = 2
algo.space_charge = false


###############################################################################
# Diagnostics
###############################################################################
diag.alpha = 1.376381920471173
diag.beta = 1.892632003628881
diag.tn = 0.4
diag.cn = 0.01
42 changes: 36 additions & 6 deletions examples/iota_lens/run_iotalens_sdep.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,34 @@

# particle bunch
distr = distribution.Waterbag(
sigmaX=2.0e-3,
sigmaY=2.0e-3,
sigmaT=1.0e-3,
sigmaPx=3.0e-4,
sigmaPy=3.0e-4,
sigmaX=1.397456296195e-003,
sigmaY=1.397456296195e-003,
sigmaT=1.0e-4,
sigmaPx=1.256184325020e-003,
sigmaPy=1.256184325020e-003,
sigmaPt=0.0,
muxpx=0.8090169943749474,
muypy=0.8090169943749474,
mutpt=0.0,
)
#distr = distribution.Waterbag(
# sigmaX=1.865379469388e-003,
# sigmaY=2.0192133150418e-003,
# sigmaT=1.0e-4,
# sigmaPx=1.402566720991e-003,
# sigmaPy=9.57593913381e-004,
# sigmaPt=0.0,
# muxpx=-0.482260919078473,
# muypy=-0.762127656873158,
# mutpt=0.0,
#)

sim.add_particles(bunch_charge_C, distr, npart)

# add beam diagnostics
monitor = elements.BeamMonitor("monitor", backend="h5")
sim.lattice.append(monitor)

# defining parameters of the nonlinear lens
lens_length = 1.8
num_lenses = 18
Expand All @@ -57,13 +76,24 @@
# define the nonlinear lens segments
for j in range(0, num_lenses):
s = -lens_length / 2.0 + ds_half + j * ds
beta = 1.0 + 4.0 * s**2 * math.tan(math.pi * tune_advance) ** 2 / lens_length**2
beta_star = lens_length/2.0 * 1.0/math.tan(math.pi * tune_advance)
# beta = beta_star * (1.0 + 4.0 * s**2 * math.tan(math.pi * tune_advance) ** 2 / lens_length**2)
beta = beta_star * (1.0 + (2.0 * s * math.tan(math.pi * tune_advance) / lens_length)**2)
knll_s = t_strength * c_parameter**2 * ds / beta
cnll_s = c_parameter * math.sqrt(beta)
nllens = elements.NonlinearLens(knll=knll_s, cnll=cnll_s)
segments = [dr, nllens, dr]
# segments = [dr, dr]
sim.lattice.extend(segments)

# focusing lens
const = elements.ConstF(ds=1.0e-8, kx=12060.113295833, ky=12060.113295833, kt=1.0e-12, nslice=1)
sim.lattice.append(const)
sim.lattice.append(monitor)

# number of periods
sim.periods = 1

# run simulation
sim.evolve()

Expand Down
4 changes: 2 additions & 2 deletions src/particles/diagnostics/NonlinearLensInvariants.H
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ namespace impactx::diagnostics
// convert transverse phase space coordinates to normalized units
amrex::ParticleReal const xn = x/(m_cn*sqrt(m_beta));
amrex::ParticleReal const yn = y/(m_cn*sqrt(m_beta));
amrex::ParticleReal const pxn = px*sqrt(m_beta)/m_cn + m_alpha*x;
amrex::ParticleReal const pyn = py*sqrt(m_beta)/m_cn + m_alpha*y;
amrex::ParticleReal const pxn = px*sqrt(m_beta)/m_cn + m_alpha*xn;
amrex::ParticleReal const pyn = py*sqrt(m_beta)/m_cn + m_alpha*yn;

// assign complex position zeta = x + iy
Complex const zeta(xn, yn);
Expand Down

0 comments on commit 00b2d2a

Please sign in to comment.