Skip to content

Commit b425d11

Browse files
authored
More fixer devel. (bmad-sim#1804)
* More fixer devel.
1 parent 485f920 commit b425d11

File tree

16 files changed

+243
-225
lines changed

16 files changed

+243
-225
lines changed

bmad/code/closed_orbit_calc.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
! the energy adjusted so that vec(5) is the same
5353
! at the beginning and at the end.
5454
! = 6 True closed orbit.
55-
! Default: Use 4 or 6 depending upon if RF is on or off.
55+
! Default: 4 if RF is off, 6 if RF is on.
5656
! direction -- Integer, optional: Direction of tracking.
5757
! +1 --> forwad (default), -1 --> backward.
5858
! The closed orbit will be dependent on direction only

bmad/custom/make_mat6_custom.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
!
1515
! Output:
1616
! ele -- Ele_struct: Element with transfer matrix.
17-
! %mat6 -- 6x6 transfer matrix.
17+
! %mat6(6,6) -- 6x6 transfer matrix (first order part of the transport map).
18+
! %vec6(6) -- zeroth order part of the transport map.
1819
! end_orb -- Coord_struct: Coordinates at the end of element.
1920
! err_flag -- Logical: Set true if there is an error. False otherwise.
2021
!+

bmad/doc/elements.tex

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,11 +2116,15 @@ \section{Fiducial}
21162116
\section{Fixer}
21172117
\label{s:fixer}
21182118

2119-
<b>This element is in construction and is not yet usable.</b>
2119+
{\bf This element is in construction. Status: Fixer elements can be used but testing is not yet complete.}
21202120

2121-
A \vn{fixer} element is used to set the particle orbit and/or the Twiss parameters at any point in
2122-
an open geometry lattice branch. The orbit and/or Twiss parameters can then be propagated from the
2123-
fixer element both forward and backwards to the ends of the branch.
2121+
A \vn{fixer} element is used to set the particle orbit and Twiss parameters at any point in an open
2122+
geometry lattice branch. The orbit and Twiss parameters can then be propagated from the fixer
2123+
element both forward and backwards to the ends of the branch. \vn{Fixe} elements are convenient, for
2124+
example, when it is desired to design a beam line with Twiss and/or orbit parameters that are fixed
2125+
at some point that is not the beginning of the line. Another example is when the orbit or Twiss parameters
2126+
have been measured at some point in a beam line and a calculation of the orbit or Twiss parameters at
2127+
other places in the line is desired consistent with the measured values.
21242128

21252129
Note: For the purposes of this discussion, the term ``Twiss'' parameters include coupling and
21262130
dispersion parameters and ``orbit'' includes both phase space and spin coordinates.
@@ -2171,24 +2175,24 @@ \section{Fixer}
21712175
If the geometry of a branch is \vn{closed} (\sref{s:param}), \vn{fixer} elements have no effect.
21722176
Thus, in the following discussion, it is assumed that the branch geometry is set to \vn{open}.
21732177
Additionally, for this discussion, the term ``\vn{fixer}'' element will include \vn{beginning_ele}
2174-
elements (\sref{s:begin.ele}) since, for the purposes of setting orbit and/or Twiss parameters
2175-
\vn{beginning_ele} elements essentially act as a fixer element at the beginning of a branch.
2176-
2177-
A fixer element is ``active'' if its \vn{is_on} parameter (\sref{s:is.on}) is True. One and only one
2178-
fixer element in a branch can be active at a given time. The \bmad bookkeeping routines will ensure
2179-
that this rule is enforced and turning on a given fixer will result in all others being turned off.
2180-
Turning off the active fixer will result in the \vn{beginning_ele} element being turned on. The
2181-
default for a fixer element defined in a lattice file is to be non-active except for the
2182-
\vn{beginning_ele} which defaults to being active. When a lattice is read in, for a given branch,
2183-
the last fixer that is set active will be the active fixer and if non are set the \vn{beginning_ele}
2184-
will be active.
2185-
2186-
Essentially, a fixer elements has two classes of Twiss and orbit parameters. There are the
2187-
``stored'' parameters listed above. These parameters may be set by the User. The other class are the
2188-
``actual'' parameters which cannot be set by the User. For a \vn{fixer} element that is active, the
2189-
actual parameters are set equal to the corresponding stored parameters and these actual parameters
2190-
are then used by \bmad to propagate the Twiss and orbit backwards and forwards through the rest of
2191-
the branch. For fixer elements that are not active, the actual Twiss and orbit is calculated in the
2178+
elements (\sref{s:begin.ele}) since, for the purposes of setting orbit and/or Twiss parameters,
2179+
\vn{beginning_ele} elements essentially act the same as a fixer element.
2180+
2181+
A fixer element is ``active'' if the value of its \vn{is_on} parameter (\sref{s:is.on}) is True. One
2182+
and only one fixer element in a branch can be active at any given time. The \bmad bookkeeping
2183+
routines will ensure that this rule is enforced and turning on a given fixer will result in all
2184+
others being turned off. Turning off the active fixer will result in the \vn{beginning_ele} element
2185+
being turned on. The default for a fixer element defined in a lattice file is to be non-active
2186+
except for the \vn{beginning_ele} which defaults to being active. When a lattice is read in, for a
2187+
given branch, the last fixer that is set active will be the active fixer and if no \vn{fixer}
2188+
elements are set active, the \vn{beginning_ele} will be active.
2189+
2190+
A fixer elements has two classes of Twiss and orbit parameters. There are the ``stored'' parameters
2191+
listed above. These parameters may be set in a lattice file. The other class are the ``actual''
2192+
parameters which cannot be set by the User. For a \vn{fixer} element that is active, the actual
2193+
parameters are set equal to the corresponding stored parameters and these actual parameters are then
2194+
used by \bmad to propagate the Twiss and orbit backwards and forwards through the rest of the
2195+
branch. For fixer elements that are not active, the actual Twiss and orbit is calculated in the
21922196
standard fashion by propagating the Twiss and orbit from the active fixer. The stored Twiss and
21932197
orbit parameter values in a non-active fixer do not affect the Twiss and orbit calculation.
21942198

bmad/modules/fixer_mod.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ subroutine set_active_fixer(fixer, is_on, orbit)
4848
return
4949
endif
5050

51+
if (fixer%value(beta_a_stored$) <= 0 .or. fixer%value(beta_b_stored$) <= 0) then
52+
call out_io(s_error$, r_name, 'Fixer element does not have beta_a or beta_b set!. Active fixer not set.')
53+
return
54+
endif
55+
5156
branch => fixer%branch
5257
on = logic_option(.true., is_on)
5358

bmad/modules/radiation_mod.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ subroutine track1_radiation (orbit, ele, edge)
7272

7373
real(rp) int_gx, int_gy, this_ran, mc2, int_g2, int_g3, ran6(6)
7474
real(rp) gamma_0, dE_p, fact_d, fact_f, p_spin, spin_norm(3), norm, rel_p, c_radius
75-
real(rp) damp_mat(6,6), stoc_mat(6,6), ref_orb(6)
75+
real(rp) damp_mat(6,6), stoc_mat(6,6), ref_orb(6), rr
7676
real(rp), parameter :: rad_fluct_const = 55.0_rp * h_bar_planck * c_light / (24.0_rp * sqrt_3)
7777
real(rp), parameter :: spin_const = 5.0_rp * sqrt_3 * h_bar_planck * c_light / 16.0_rp
7878
real(rp), parameter :: damp_const = 2.0_rp / 3.0_rp
@@ -109,8 +109,9 @@ subroutine track1_radiation (orbit, ele, edge)
109109
endif
110110

111111
if (bmad_com%radiation_damping_on) then
112-
orbit%vec = orbit%vec + bmad_com%synch_rad_scale * matmul(rad_map%damp_dmat, orbit%vec - rad_map%ref_orb)
113-
if (.not. bmad_com%radiation_zero_average) orbit%vec = orbit%vec + bmad_com%synch_rad_scale * rad_map%xfer_damp_vec
112+
rr = orbit%time_dir * bmad_com%synch_rad_scale
113+
orbit%vec = orbit%vec + rr * matmul(rad_map%damp_dmat, orbit%vec - rad_map%ref_orb)
114+
if (.not. bmad_com%radiation_zero_average) orbit%vec = orbit%vec + rr * rad_map%xfer_damp_vec
114115
endif
115116

116117
if (bmad_com%radiation_fluctuations_on) then

bsim/code/adjust_optics.f90

Lines changed: 0 additions & 46 deletions
This file was deleted.

regression_tests/fixer_test/fixer_test.bmad

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
parameter[geometry] = Open
44

5-
parameter[p0c] = 1.0E6*1e6
5+
parameter[p0c] = 1.0E10
66
parameter[particle] = Positron
77
bmad_com[spin_tracking_on] = T
8+
bmad_com[radiation_damping_on] = T
9+
bmad_com[spin_tracking_on] = T
810

911
beginning[beta_a] = 1.1E1
1012
beginning[alpha_a] = -1.7
@@ -42,7 +44,7 @@ particle_start[spin_z] = 0.5
4244
S1: Sextupole, L = 1.0E-2
4345
D: Drift, L = 2.9E-1
4446
Q1: Quadrupole, L = 5.0E-1, TILT = 5.0E-2, K1 = 5.9E-1, hkick = 1e-3*f, vkick = 2e-3*f
45-
B: SBend, L = 3.0, G = 1.3E-1, E1 = 7.0E-2, E2 = 7.0E-2
47+
B: SBend, L = 3.0, G = 1.3E-1, E2 = 7.0E-1
4648
Q2: Quadrupole, L = 5.0E-1, K1 = -5.0E-1
4749
S2: Sextupole, L = 1.0E-2
4850
Lc: LCavity, L = 1.1, VOLTAGE = 1.0E6*1e-10, phi0 = 0.1,
@@ -58,6 +60,6 @@ F2: Fixer
5860
! Lattice lines
5961

6062

61-
RING: line = ( S1, D, Q1, D, Lc, B, D, Q2, D, F1, S2, Lc, F2, B)
63+
RING: line = (S1, D, Q1, D, Lc, B, D, Q2, D, F1, S2, Lc, F2, B)
6264

6365
use, RING

regression_tests/fixer_test/fixer_test.f90

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,17 @@ subroutine orbit_delta_write(indx, ix_ele, orb1, orb2)
154154

155155
str = run_str(indx) // '-E' // int_str(ix_ele) // '-Orbit-'
156156

157-
write (1, '(2a, es16.8)') quote(trim(str) // 'X'), ' ABS 1E-10', orb1%vec(1) - orb2%vec(1)
158-
write (1, '(2a, es16.8)') quote(trim(str) // 'PX'), ' ABS 1E-10', orb1%vec(2) - orb2%vec(2)
159-
write (1, '(2a, es16.8)') quote(trim(str) // 'Y'), ' ABS 1E-10', orb1%vec(3) - orb2%vec(3)
160-
write (1, '(2a, es16.8)') quote(trim(str) // 'PY'), ' ABS 1E-10', orb1%vec(4) - orb2%vec(4)
161-
write (1, '(2a, es16.8)') quote(trim(str) // 'Z'), ' ABS 1E-10', orb1%vec(5) - orb2%vec(5)
162-
write (1, '(2a, es16.8)') quote(trim(str) // 'PZ'), ' ABS 1E-10', orb1%vec(6) - orb2%vec(6)
163-
write (1, '(2a, es16.8)') quote(trim(str) // 'T'), ' ABS 1E-10', orb1%t - orb2%t
157+
write (1, '(2a, es16.8)') quote(trim(str) // 'X'), ' ABS 1E-10', orb1%vec(1) - orb2%vec(1)
158+
write (1, '(2a, es16.8)') quote(trim(str) // 'PX'), ' ABS 1E-10', orb1%vec(2) - orb2%vec(2)
159+
write (1, '(2a, es16.8)') quote(trim(str) // 'Y'), ' ABS 1E-10', orb1%vec(3) - orb2%vec(3)
160+
write (1, '(2a, es16.8)') quote(trim(str) // 'PY'), ' ABS 1E-10', orb1%vec(4) - orb2%vec(4)
161+
write (1, '(2a, es16.8)') quote(trim(str) // 'Z'), ' ABS 1E-10', orb1%vec(5) - orb2%vec(5)
162+
write (1, '(2a, es16.8)') quote(trim(str) // 'PZ'), ' ABS 1E-10', orb1%vec(6) - orb2%vec(6)
163+
write (1, '(2a, es16.8)') quote(trim(str) // 'T'), ' ABS 1E-10', orb1%t - orb2%t
164164
write (1, '(2a, es16.8)') quote(trim(str) // 'P0C'), ' ABS 1E-10', orb1%p0c - orb2%p0c
165+
write (1, '(2a, es16.8)') quote(trim(str) // 'Spin-X'), ' ABS 1E-10', orb1%spin(1) - orb2%spin(1)
166+
write (1, '(2a, es16.8)') quote(trim(str) // 'Spin-Y'), ' ABS 1E-10', orb1%spin(2) - orb2%spin(2)
167+
write (1, '(2a, es16.8)') quote(trim(str) // 'Spin-Z'), ' ABS 1E-10', orb1%spin(3) - orb2%spin(3)
165168

166169
end subroutine orbit_delta_write
167170

0 commit comments

Comments
 (0)