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

Feature/sc linedensity interpolation #50

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0fe80aa
Spacecharge: renaming properties of coasting beam...
aoeftiger Jun 12, 2020
25c7a40
spacecharge: renaming SpaceChargeBunched to SpaceChargeQGaussianProfi…
aoeftiger Jun 12, 2020
ec91688
space charge: copy from SpaceChargeBunched to new interpolated profil…
aoeftiger Jun 12, 2020
7dc1b9b
space charge: fixing hard coded min_sigma_diff
aoeftiger Jun 12, 2020
7daf5c4
space charge: first working interpolation version
aoeftiger Jun 12, 2020
1e4875d
space charge test & examples: update for new QGaussianProfile named c…
aoeftiger Jun 12, 2020
da92ecd
space charge: changing all line_density appearances in ...
aoeftiger Jun 12, 2020
4866d6c
Merge remote-tracking branch 'ao/feature/sc-linedensity-interpolation…
Aug 21, 2020
dc7be9c
interpolated profile SC: adding MAD-X loader and unifying setup_SC_in…
aoeftiger Aug 21, 2020
33f9c35
spacecharge: added semantics in tools and removal of duplicate...
aoeftiger Aug 24, 2020
830b1fc
Merge pull request #2 from aoeftiger/pr37and50
aoeftiger Aug 24, 2020
ad264cd
Merge branch 'master' into feature/sc-linedensity-interpolation
aoeftiger Aug 26, 2020
f766877
elements: register new SpaceChargeInterpolatedProfile
aoeftiger Aug 26, 2020
bc6c303
elements: register new SpaceChargeInterpolatedProfile
aoeftiger Aug 26, 2020
c7bfd79
added helper class to calculate q-gaussian distributions
martinschwinzerl Sep 1, 2020
e08fab8
use proper q-gaussian distribution inside SpaceChargeQGaussianProfile
martinschwinzerl Sep 1, 2020
7aa8265
rename SpaceChargeQGaussianProfile to ScQGaussProfile
martinschwinzerl Sep 1, 2020
c0e3109
add gamma and pow functions to MathlibDefault
martinschwinzerl Sep 1, 2020
794e7b3
update SpaceChargeInterpolatedProfile
martinschwinzerl Sep 1, 2020
a5c0af4
remove not needed lines from the SpaceChargeInterpolatedProfile track…
martinschwinzerl Sep 1, 2020
9a2e2fd
renamed SpaceChargeInterpolatedProfile to ScInterpolatedProfile, cosm…
martinschwinzerl Sep 1, 2020
5089b18
cosmetic changes to ScQGaussProfile
martinschwinzerl Sep 1, 2020
464cf03
linter/cosmetic changes to be_beamfields/tools.py
martinschwinzerl Sep 1, 2020
d5399b0
added method parameter to setup_spacecharge_interpolated_in_line, cos…
martinschwinzerl Sep 1, 2020
7348ad4
uses upated space-charge element names
martinschwinzerl Sep 1, 2020
d9d0fe9
linter/cosmetic changes
martinschwinzerl Sep 1, 2020
409b3c2
uses upated space-charge element names
martinschwinzerl Sep 1, 2020
254d034
linter/cosmetic changes
martinschwinzerl Sep 1, 2020
4e03e43
uses upated space-charge element names
martinschwinzerl Sep 1, 2020
ada75cc
uses upated space-charge element names
martinschwinzerl Sep 1, 2020
d643e1f
linter/cosmetic changes
martinschwinzerl Sep 1, 2020
56de1fb
uses upated space-charge element names
martinschwinzerl Sep 1, 2020
9c3c939
uses upated space-charge element names
martinschwinzerl Sep 1, 2020
724cb1e
linter/cosmetic changes
martinschwinzerl Sep 1, 2020
f796875
Merge remote-tracking branch 'aoeftiger/feature/sc-linedensity-interp…
martinschwinzerl Sep 1, 2020
6c4ef04
Fix wrong attribute name in ScQGaussProfile
martinschwinzerl Sep 2, 2020
4a3a714
Update spacecharge.py
martinschwinzerl Sep 2, 2020
5da8d57
Update qgauss.py
martinschwinzerl Sep 2, 2020
8c0b3c4
fixes bug in calculating sqrt_beta for gaussian distributions
martinschwinzerl Sep 15, 2020
6acd66c
adds cq getter for the Q-Gaussian distribution
martinschwinzerl Sep 15, 2020
4bbfef4
fixes wrong decorator for the setter of q for the QGauss distribution
martinschwinzerl Sep 15, 2020
08f2f69
rename ScCoasting -> SCCoasting
martinschwinzerl Sep 15, 2020
69a1fe2
streamline the SCCoasting track() implementation
martinschwinzerl Sep 15, 2020
56f312b
rename ScQGaussProfile -> SCQGaussProfile
martinschwinzerl Sep 15, 2020
12b7d03
streamline track() implementation for SCQGaussProfile
martinschwinzerl Sep 15, 2020
cdd6d5f
rename ScInterpolatedProfile -> SCInterpolatedProfile
martinschwinzerl Sep 15, 2020
9a1327b
streamline implementation of track() method for SCInterpolatedProfile
martinschwinzerl Sep 15, 2020
655058a
reflect the rename of space-charge class names
martinschwinzerl Sep 15, 2020
71df3b0
adds unit-test for calculating gaussian distributions from QGauss
martinschwinzerl Sep 15, 2020
9098e6c
reflects the renaming of space-charge elements in tests
martinschwinzerl Sep 15, 2020
3c2bb4e
adds block to allow stand-alone running of the test, cosmetic changes
martinschwinzerl Sep 15, 2020
fb4c160
reflects the renaming of the space-charge elements in the examples
martinschwinzerl Sep 15, 2020
8250b8b
Merge pull request #3 from martinschwinzerl/feature/sc-linedensity-in…
aoeftiger Sep 16, 2020
1d342d1
bumps version number
martinschwinzerl Oct 13, 2020
bd06e83
adds method to get the num. indices in a line for given types
martinschwinzerl Oct 14, 2020
b363afe
Merge remote-tracking branch 'mschwinz/feature/sc-linedensity-interpo…
martinschwinzerl Oct 14, 2020
2b96cc9
Merge pull request #4 from martinschwinzerl/feature/sc-linedensity-in…
aoeftiger Oct 14, 2020
7a25d03
Typo in particles.py docstring
aoeftiger Nov 2, 2020
d2fe384
Addressing issue #61: 1. adding kwargs to find_closed_orbit...
aoeftiger Nov 4, 2020
2dd7445
Addressing issue #61: 2. fixing coord to use zeta both times
aoeftiger Nov 4, 2020
ef63efd
Merge branch 'master' into feature/sc-linedensity-interpolation
aoeftiger Nov 4, 2020
730d42a
Fixing test_madx_import for the test_zero_error
aoeftiger Nov 4, 2020
0755d6a
Fixing test_madx_import for new order of arguments
aoeftiger Nov 4, 2020
a52aeb8
new closed_orbit module: add **kwargs for particles...
aoeftiger Nov 4, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

if particle_type == "protons":

# For bunched
# Space charge:
number_of_particles = 2e11

# For bunched
bunchlength_rms = 0.22

# For coasting
line_density = 2e11 / 0.5
circumference = 0.5

mass = pysixtrack.Particles.pmass
p0c = 25.92e9
Expand All @@ -37,20 +39,22 @@

if particle_type == "ions":

# For bunched
# Space charge:
number_of_particles = 3.5e8

# For bunched
bunchlength_rms = 0.22

# For coasting
line_density = 3.5e8 / 0.5
circumference = 0.5

mass = 193.7e9
p0c = 1402.406299e9
charge_state = 82.0
neps_x = 1.63e-6
neps_y = 0.86e-6
neps_x = 1.63e-6
neps_y = 0.86e-6
delta_rms = 1.0e-3
V_RF_MV = 3
V_RF_MV = 3
lag_RF_deg = 0.0
n_SCkicks = 250
length_fuzzy = 1.5
Expand Down Expand Up @@ -90,11 +94,11 @@
# Check consistency
if sc_mode == "Bunched":
sc_elements, sc_names = line.get_elements_of_type(
pysixtrack.elements.SpaceChargeBunched
pysixtrack.elements.SCQGaussProfile
)
elif sc_mode == "Coasting":
sc_elements, sc_names = line.get_elements_of_type(
pysixtrack.elements.SpaceChargeCoasting
pysixtrack.elements.SCCoasting
)
else:
raise ValueError("mode not understood")
Expand Down Expand Up @@ -148,7 +152,8 @@
sc_lengths,
sc_twdata,
betagamma,
line_density,
number_of_particles,
circumference,
delta_rms,
neps_x,
neps_y,
Expand Down Expand Up @@ -177,7 +182,7 @@
with open("particle_on_CO.pkl", "rb") as fid:
part_on_CO = pysixtrack.Particles.from_dict(pickle.load(fid))

part = part_on_CO.copy()
part = part_on_CO.copy()

# get beta functions from twiss table
with open("twiss_at_start.pkl", "rb") as fid:
Expand Down
2 changes: 1 addition & 1 deletion pysixtrack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.5"
__version__ = "0.0.6"

from . import base_classes
from . import elements
Expand Down
75 changes: 75 additions & 0 deletions pysixtrack/be_beamfields/qgauss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from pysixtrack.mathlibs import MathlibDefault


class QGauss(object):
@staticmethod
def calc_cq(q, mathlib=MathlibDefault, EPS=1e-6):
assert q < 3
cq = mathlib.sqrt(mathlib.pi)
if q >= (1 + EPS):
cq *= mathlib.gamma((3 - q) / (2 * q - 2))
cq /= mathlib.sqrt((q - 1)) * mathlib.gamma(1 / (q - 1))
elif q <= (1 - EPS):
cq *= 2 * mathlib.gamma(1 / (1 - q))
cq /= (
(3 - q)
* mathlib.sqrt(1 - q)
* mathlib.gamma((3 - q) / (2 - 2 * q))
)
return cq

@staticmethod
def sqrt_beta(sigma, mathlib=MathlibDefault):
assert sigma > 0
return 1 / (mathlib.sqrt(2) * sigma)

@staticmethod
def exp_q(x, q, mathlib=MathlibDefault, EPS=1e-6):
assert q < 3
if mathlib.abs(1 - q) > EPS:
u_plus = 1 + x * (1 - q)
if u_plus < 0:
u_plus = 0
return mathlib.pow(u_plus, 1 / (1 - q))
else:
return mathlib.exp(x)

def __init__(self, q=1.0, mathlib=MathlibDefault, cq_eps=1e-6):
assert q < 3
self._m = mathlib
self._q = q
self._cq = QGauss.calc_cq(q, mathlib=mathlib, EPS=cq_eps)

@property
def q(self):
return self._q

@q.setter
def q(self, q_value):
assert q_value < 3
self._q = q_value
self._cq = QGauss.calc_cq(self._q, self._m)

@property
def cq(self):
return self._cq

def min_support(self, sqrt_beta):
assert self._q < 3
assert sqrt_beta > 0
if self._q >= 1:
return -1e10
else:
return -1 / self._m.sqrt(sqrt_beta * sqrt_beta * (1 - self._q))

def max_support(self, sqrt_beta):
return -(self.min_support(sqrt_beta))

def eval(self, x, sqrt_beta, mu=0.0):
assert self._m.abs(self._cq) > 0
assert self._q < 3
assert sqrt_beta > 0
factor = sqrt_beta / self._cq
arg = sqrt_beta * sqrt_beta
arg *= (x - mu) * (x - mu)
return factor * QGauss.exp_q(-arg, self._q, self._m)
Loading