Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fnal booster input files #408

Open
wants to merge 49 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
369c897
Examples for 3D space charge benchmarking
cemitch99 Jun 7, 2022
d073bcf
Update input_kurth_10nC.in
cemitch99 Dec 5, 2022
a773807
Add MAD-X, SXF input files for Fermilab Booster.
cemitch99 Jul 31, 2023
366be57
Delete input_kurth_10nC.in
cemitch99 Jul 31, 2023
e5960d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
b8b2369
Write SXF Parser
ax3l Aug 3, 2023
9d3d0e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 3, 2023
823c4bb
Add F. Schmidt updated SXF file and new Python script.
cemitch99 Dec 21, 2023
920958e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 21, 2023
f8cf0b4
Delete examples/fnal_booster/fermi-booster-madx-sxf
cemitch99 Dec 21, 2023
2d7bffb
Fix merge.
cemitch99 Dec 21, 2023
1260f5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 21, 2023
0534676
Delete examples/fnal_booster/main_deb_mad_6c.madx
cemitch99 Jan 18, 2024
079687a
Delete examples/fnal_booster/match_chrom.madx
cemitch99 Jan 18, 2024
89a628a
Delete examples/fnal_booster/ring_seq_bb_spch_thin.madx
cemitch99 Jan 18, 2024
c60f529
Delete examples/fnal_booster/match_tunes.madx
cemitch99 Jan 18, 2024
42f7da2
Delete examples/fnal_booster/spcharge_beam_command.madx
cemitch99 Jan 18, 2024
def0096
Update fnal_booster.py
cemitch99 Jan 18, 2024
a5107d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
a9872b0
Add FNAL Booster execution test.
cemitch99 Jan 18, 2024
16e31cc
Merge branch 'development' into add_fnal_booster
cemitch99 Jan 18, 2024
66d2830
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
66e70f1
Update examples/fnal_booster/fnal_booster.py
cemitch99 Feb 9, 2024
07152fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 9, 2024
bc5a380
Update CMakeLists.txt
cemitch99 Feb 9, 2024
5f808dd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 9, 2024
6da5b0d
Update CMakeLists.txt
cemitch99 Feb 9, 2024
d00b6e4
Update CMakeLists.txt
cemitch99 Feb 9, 2024
38278e2
Update CMakeLists.txt
cemitch99 Feb 10, 2024
cad00e3
Merge remote-tracking branch 'mainline/development' into add_fnal_boo…
ax3l Feb 10, 2024
456bac1
Fix: CMake Copy, Imports, Global Var
ax3l Feb 10, 2024
acfac82
Test: Mark as Slow
ax3l Feb 10, 2024
eae91e5
Update fnal_booster.py
cemitch99 Feb 21, 2024
e2d5589
Update fnal_booster.py
cemitch99 Feb 21, 2024
e8b4e54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2024
0f5df30
Update fnal_booster.py
cemitch99 Feb 23, 2024
33fdb84
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2024
354f9c2
Update fnal_booster.py
cemitch99 Feb 23, 2024
d135246
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2024
6000f45
Add new SXF input file and corrected Python parsing script.
cemitch99 Jun 13, 2024
538c235
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
a54647d
Update CMakeLists.txt
cemitch99 Jun 13, 2024
909ca2d
Delete examples/fnal_booster/fnal_booster.py
cemitch99 Jun 13, 2024
6f0a3e8
Update CMakeLists.txt
cemitch99 Jun 13, 2024
5484bcc
Update fnal_booster_no-sc.py
cemitch99 Jun 14, 2024
64f1101
Update fnal_booster_no-sc.py
cemitch99 Jun 17, 2024
12ca7f1
Add README and analysis.
cemitch99 Jun 17, 2024
0fcfaf9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 17, 2024
8d68018
Link to documentation.
cemitch99 Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59,296 changes: 59,296 additions & 0 deletions examples/fnal_booster/fermi-booster-madx-sxf_corr_new

Large diffs are not rendered by default.

265 changes: 265 additions & 0 deletions examples/fnal_booster/fnal_booster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
#!/usr/bin/env python3
#
# Copyright 2022-2023 ImpactX contributors
# Authors: Axel Huebl, Chad Mitchell
# License: BSD-3-Clause-LBNL
#
# -*- coding: utf-8 -*-

# The following script is intended to parse the file 'fermi-booster-madx-sxf'
# corresponding to a thin-kick reduced model of the Fermilab Booster
# lattice (from F. Schmidt), for space charge studies in ImpactX.
# The input file is provided in Standard eXchange Format (SXF),
# described here: https://doi.org/10.2172/1119545
# The present version is a draft for preliminary testing only.
# Authors: C. Mitchell, A. Huebl


# Import the required Python packages

import re

import pandas as pd
Fixed Show fixed Hide fixed

import amrex.space3d as amr
from impactx import ImpactX, RefPart, distribution, elements

# Read the input file as a single string, since elements span multiple lines

with open("fermi-booster-madx-sxf_corr_new") as f:
text = f.read()

# cut off the ring sequence wrapping lines (top/bottom of the file)
sequence = text[36:-45]

# Create list of element strings, which are separated by semicolon ;

element_list = sequence.split(";")

# print(element_list[0])
# print(element_list[1])


# Define some regular expressions (list to be expanded later)

# https://regex101.com
rx_dict = {
"name": re.compile(r"^\s*(?P<name>[\w\.]+)\s+"), # element name
"type": re.compile(r"^\s*[\w\.]+\s+(?P<type>[\w]+)\s*\{"), # element name
"tag": re.compile(r"tag = (?P<tag>[\w\.]+)"), # element tag (often same as name)
"zloc": re.compile(r"at\s*=\s*(?P<zloc>\d*\.?\d*)[\s\n\r\}]+"), # element location
"body": re.compile(r"body\s*=\s*\{(?P<body>.+)\s*\}.*\}"), # ...
# multipole
"lrad": re.compile(
r"lrad\s*=\s*(?P<lrad>\d*\.?\d*)[\s\n\r\}]+"
), # fictitious length
"kl": re.compile(
r"kl\s*=\s*\[(?P<kl>.*)\]"
), # coefficients for the multipole strength
# dipedge
"e1": re.compile(r"e1\s*=\s*(?P<e1>[+-]?\d*\.?\d*)[\s\n|r\}]+"), # ...
"e2": re.compile(r"e2\s*=\s*(?P<e2>[+-]?\d*\.?\d*)[\s\n|r\}]+"), # ...
"h": re.compile(r"h\s*=\s*(?P<h>[+-]?\d*\.?\d*)[\s?(\n|\r)\}]?+"), # ...
"tilt": re.compile(r"tilt\s*=\s*(?P<tilt>[+-]?\d*\.?\d*)[\s\n|r\}]?+"), # ...
# more in the MAD-X file? fint, hgap, h - always zero
# rfcavity
"volt": re.compile(r"volt\s*=\s*(?P<volt>[\w\.]+)\s+"), # ...
"harmon": re.compile(r"harmon\s*=\s*(?P<harmon>[\w\.]+)\s*"), # ...
}


# Basic function for parsing a single element


def parse_one_group(element, key):
Fixed Show fixed Hide fixed
"""Returns regex match or None"""
rx = rx_dict[key]
element = element.replace("\n", " ")
match = rx.search(element)
if match:
return match.group(key).strip()
else:
None
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed


def parse_element(element, zprev):
"""
Input: SXF Element String
Outpu: ImpactX Element
"""
name = parse_one_group(element, "name")
etyp = parse_one_group(element, "type")
tag = parse_one_group(element, "tag")
zloc = parse_one_group(element, "zloc")
print(f"name={name}")
print(f"etyp={etyp}")
print(f"tag={tag}")

# convert z-location to float
if zloc is None:
print("... empty zloc - ignored")
zloc = zprev
else:
zloc = float(zloc)
dz = zloc - zprev

print(f"elements.Drift(ds={dz})")
sim.lattice.append(elements.Drift(ds=dz))

# tag

# vkicker & hkicker: they all seem to be turned off in our file
ignored_types = ["beambeam", "marker", "hkicker", "vkicker", None]

if etyp in ignored_types:
print("... ignored")

elif etyp == "multipole":
body = parse_one_group(element, "body")

if body is not None:
lrad = parse_one_group(body, "lrad")
kl = parse_one_group(body, "kl")

if kl is None:
print("... empty kl - ignored")
else:
# simplify spaces to one
kl = re.sub(r"\s+", " ", kl)
# to list
kl = kl.split(" ")
# convert strings to floats
kl = list(map(float, kl))
print(f"lrad={lrad}")
print(f"kl={kl}")

for i in range(len(kl)):
print(
f"elements.Multipole(multiple={i}, K_normal={kl[i]}, K_skew=0.0)"
)
sim.lattice.append(
elements.Multipole(multiple=i, K_normal=kl[i], K_skew=0.0)
)
else:
print("... empty body - ignored")

elif etyp == "dipedge":
body = parse_one_group(element, "body")
# print(f"body={body}")

if body is not None:
e1 = parse_one_group(body, "e1")
# e2 = parse_one_group(body, "e2")
h = parse_one_group(body, "h")
tilt = parse_one_group(body, "tilt")

if e1 is None:
print("... empty e1 - ignored")
elif h is None:
print("... empty h - ignored")
else:
e1 = float(e1)
print(f"e1={e1}")
h = float(h)
print(f"h={h}")
if tilt is None:
print("... empty tilt - ignored")
else:
tilt = float(tilt)
print(f"tilt={tilt}")
print(f"elements.DipEdge(psi={e1}, rc=1.0, g={h}, K2=0.125)")
sim.lattice.append(elements.DipEdge(psi=e1, rc=1.0, g=h, K2=0.125))

else:
print("... empty body - ignored")

elif etyp == "rfcavity":
body = parse_one_group(element, "body")
# print(f"body={body}")

if body is not None:
volt = parse_one_group(body, "volt")
harmon = parse_one_group(body, "harmon")

if volt is None or harmon is None:
print("... empty volt or harmon - ignored")
else:
volt = float(volt)
harmon = int(harmon)
print(f"volt={volt}")
print(f"harmon={harmon}")

f0 = 0.45079517081715459e6
Erest = 938.27208816
print(
f"elements.ShortRF(V={volt/Erest}, freq={harmon*f0}, phase=-90.0)"
)
sim.lattice.append(
elements.ShortRF(V=volt / Erest, freq=harmon * f0, phase=-90.0)
)

else:
print("... empty body - ignored")
else:
print(f"Unknown type: {etyp}")

return zloc


# Set up simulation input

sim = ImpactX()

# set numerical parameters and IO control
sim.particle_shape = 2 # B-spline order
sim.space_charge = False
# sim.diagnostics = False # benchmarking
sim.slice_step_diagnostics = True

# domain decomposition & space charge mesh
sim.init_grids()

# intial proton beam parameters
tot_energy_MeV = 1.3382720460000002e3 # reference energy
bunch_charge_C = 1.0e-9 # used with space charge
proton_mass_MeV = 938.27204600000003
kin_energy_MeV = tot_energy_MeV - proton_mass_MeV
npart = 10000 # number of macro particles

# reference particle
ref = sim.particle_container().ref_particle()
ref.set_charge_qe(1.0).set_mass_MeV(proton_mass_MeV).set_kin_energy_MeV(kin_energy_MeV)

# particle bunch
distr = distribution.Waterbag(
sigmaX=1.288697604e-6,
sigmaY=1.288697604e-6,
sigmaT=1.0e-6,
sigmaPx=3.965223396e-6,
sigmaPy=3.965223396e-6,
sigmaPt=0.01, # 1% energy spread
muxpx=0.0,
muypy=0.0,
mutpt=0.0,
)
sim.add_particles(bunch_charge_C, distr, npart)

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

# Loop over elements

zprev = 0.0
for element in element_list: # elements[0:12]:
zloc = parse_element(element, zprev)
zprev = zloc

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

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
28 changes: 28 additions & 0 deletions examples/fnal_booster/main_deb_mad_6c.madx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
option,bborbit=true; !!!!!!!
option,bb_sxy_update=false; !!!!!!!
option,bb_ultra_relati=true; !!!!!!!
option,sc_mytracksumm_end_particle= 1;
option,-info,warn,-echo;
option,-info,warn,-echo;
set,format="28.20e";
system, "date";
TITLE,"2023_June Booster Experiment";

CALL, FILE ="ring_seq_bb_spch_thin.madx"; ! <= read ring seq with spch

USE, PERIOD= ring;
show,beam;

call, file = "match_chrom.madx";
NPART0= BEAM->NPART;
NPART=0;
call,file="spcharge_beam_command.madx";
call, file = "match_tunes.madx";
select,flag="twiss",clear;
select,flag="twiss",column=name,keyword,s,
betx,bety,alfx,alfy,dx,dpx,dy,dpy,mux,muy;
twiss,file="twiss_SC-off.dat";
NPART=NPART0;
call,file="spcharge_beam_command.madx";
twiss,file="twiss_SC-on.dat";
STOP; !================================================================
9 changes: 9 additions & 0 deletions examples/fnal_booster/match_chrom.madx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
match,sequence=ring;
show, beam;
global,sequence=ring,DQ1=-12/beam->beta;
global,sequence=ring,DQ2= -6/beam->beta;
vary,name=I_DSXL;
vary,name=I_DSXS;
lmdif,calls=500,tolerance=1.e-8;
jacobian, calls=10, tolerance=1.0e-21;
endmatch;
8 changes: 8 additions & 0 deletions examples/fnal_booster/match_tunes.madx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
match,sequence=RING; ;
global,sequence=RING,Q1=6.6e+00 ;
global,sequence=RING,Q2=6.65e+00;
vary,name=I_DQL,step=1.0e-6;
vary,name=I_DQS,step=1.0e-6;
lmdif,calls=500,tolerance=1.e-8;
jacobian, calls=10, tolerance=1.0e-21;
endmatch;
Loading
Loading