Skip to content

Commit

Permalink
Fix so ramper elements where no slave has the attribute to be control…
Browse files Browse the repository at this point in the history
…led generates an error message. (#1122)
  • Loading branch information
DavidSagan authored Aug 4, 2024
1 parent 515512a commit f6ceae6
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
13 changes: 8 additions & 5 deletions bmad-doc/tutorial_bmad_tao/doc/tutorial_bmad_tao.tex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

\title{An Introduction and Tutorial to Bmad and Tao}
\author{}
\date{David Sagan and Chris Mayes \\ July 18, 2024}
\date{David Sagan and Chris Mayes \\ August 3, 2024}

\begin{document}

Expand Down Expand Up @@ -2788,13 +2788,16 @@ \subsection{Exercises [Answers in Section \sref{s:ans.uni}]}
%----------------------------------------------------------
\subsection{Overview}
Control elements are elements that control the parameters of other elements. There are three types
of control elements: \vn{groups}, \vn{overlays}, and \vn{girders}. \vn{Groups} and
Control elements are elements that control the parameters of other elements. There are four types
of control elements: \vn{groups}, \vn{overlays}, \vn{girders}, and \vn{rampers}. \vn{Groups} and
\vn{overlays} are convenient to do such things as simulate control room "knobs". For example a power
supply that powers a chain of magnets. \vn{Girder} elements (\sref{s:girder})
are used for simulating lattice element support structures.
are used for simulating lattice element support structures. And \vn{ramper} elements are used to
vary lattice parameters over many turns which is useful for long term (that is multi-turn) tracking.
\vn{Ramper} elements are not covered in this tutorial and the interested reader is referred to the \bmad
manual for more details.
Note: \vn{Group}, \vn{overlay}, and \vn{girder} elements are known as ``\vn{minor} \vn{lords}'' since they
Note: Control elements are known as ``\vn{minor} \vn{lords}'' since they
only control a subset of an element's attributes. The other type of \vn{lord} elements, \vn{multipass} lords
(\sref{s:multipass}) and \vn{superposition} lords (\sref{s:super}) are called ``\vn{major lords}''.
Expand Down
13 changes: 12 additions & 1 deletion bmad/doc/elements.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4545,7 +4545,18 @@ \section{Ramper}
elements it is not permitted to use wild card characters. That is, in the above example, ``\vn{*}''
will not match to any controller elements.
Do to the way bookkeeping is done for ramper elmeents, and unlike \vn{group} or \vn{overlay}
If a slave name contains wild card characters, for a given lattice element that the slave name
matches to, it is not required that the controlled attribute be a valid attribute of the element. In
the case where the controlled attribute is not valid for a given lattice element, no attributes of
the given lattice element are varied when and the ramper is varied. For example:
\begin{example}
rz: ramper = \{*[k1]: ...
\end{example}
In this example the \vn{k1} attribute of all those elements that have a \vn{k1} attribute will be
controlled but something like a \vn{sextupole} element which does not have a \vn{k1} attribute will
not be controlled.
Due to the way bookkeeping is done for ramper elmeents, and unlike \vn{group} or \vn{overlay}
elements, it is not permitted for different \vn{ramper} elements to control the same parameter of a
given slave element. Additionally, parameters that \vn{ramper} elements control must not be
controlled by any \vn{overlay} (but a \vn{ramper} can control an \vn{overlay}).
Expand Down
18 changes: 13 additions & 5 deletions bmad/low_level/ramper_slave_setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ subroutine ramper_slave_setup (lat, force_setup)

integer ib, ie, ir, iv, n_loc, n_slave
logical, optional :: force_setup
logical err
logical err, attrib_matched
character(*), parameter :: r_name = 'ramper_slave_setup'

! Clean
Expand All @@ -51,10 +51,17 @@ subroutine ramper_slave_setup (lat, force_setup)
call lat_ele_locator(r1%slave_name, lat, eles, n_loc, err)
if (err) return
n_slave = n_slave + n_loc
attrib_matched = .false.
do ie = 1, n_loc
call set_this_slave(eles(ie)%ele, lord, iv, r1, lat, n_slave, err)
call set_this_slave(eles(ie)%ele, lord, iv, r1, lat, n_slave, attrib_matched, err)
if (err) return
enddo
if (.not. attrib_matched) then
call out_io (s_error$, r_name, 'Ramper: ' // lord%name, &
'Cannot find any slave elements with name: ' // r1%slave_name, &
'that has the attribute: ' // r1%attribute)
return
endif
enddo

if (n_slave == 0) then
Expand All @@ -68,7 +75,7 @@ subroutine ramper_slave_setup (lat, force_setup)
!----------------------------------------------------------------------------------
contains

recursive subroutine set_this_slave (slave, lord, ix_control, r1, lat, n_slave, err_flag)
recursive subroutine set_this_slave (slave, lord, ix_control, r1, lat, n_slave, attrib_matched, err_flag)

type (ele_struct), target :: slave, lord
type (ele_struct), pointer :: slave2
Expand All @@ -79,7 +86,7 @@ recursive subroutine set_this_slave (slave, lord, ix_control, r1, lat, n_slave,
type (all_pointer_struct) a_ptr

integer ix_control, is, n_slave
logical err_flag, err, has_wild, free, energy_ramp
logical attrib_matched, err_flag, err, has_wild, free, energy_ramp

! If the slave name has wild card characters, do not match to controllers.

Expand Down Expand Up @@ -122,7 +129,6 @@ recursive subroutine set_this_slave (slave, lord, ix_control, r1, lat, n_slave,

! Is free


free = attribute_free(slave, r1%attribute, .false.)

if (.not. free .and. .not. energy_ramp) then
Expand Down Expand Up @@ -155,6 +161,8 @@ recursive subroutine set_this_slave (slave, lord, ix_control, r1, lat, n_slave,
endif
endif

attrib_matched = .true.

end subroutine set_this_slave

end subroutine
20 changes: 10 additions & 10 deletions bmad/parsing/bmad_parser_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6621,6 +6621,15 @@ subroutine parser_add_lords (lord_lat, n_ele_max, plat, lat, check_lat)
!-----------------------------------------------------
! overlays, groups, and rampers

! If a slave name does not match any name in lat and lord_lat then this is an error (to catch typos).
! If a slave is defined in lord_lat but not present in lat then the slave is ignored.
! If all slave elements are defined in lord_lat, but are not present in lat, then
! this lord can be ignored.
! Variation used by bmad_parser2: Check for missing slaves in check_lat instead of lord_lat.
! Exception: If slave is overlay or group and is present later in the list of lords to be installed then
! this is an error.
! For rampers check that if there is a match then parameter matches a valid slave element.

select case (lord%key)

case (ramper$)
Expand Down Expand Up @@ -6681,16 +6690,7 @@ subroutine parser_add_lords (lord_lat, n_ele_max, plat, lat, check_lat)
call create_ramper (lat%ele(ix_lord), cs(1:nn), err)

case (overlay$, group$)

! If a slave name does not match any name in lat and lord_lat then this is an error (to catch typos).
! If a slave is defined in lord_lat but not present in lat then the slave is ignored.
! If all slave elements are defined in lord_lat, but are not present in lat, then
! this lord can be ignored.
! Variation used by bmad_parser2: Check for missing slaves in check_lat instead of lord_lat.
! Exception: If slave is overlay or group and is present later in the list of lords to be installed then
! this is an error.

n_slave = 0
n_slave = 0

if (allocated(m_eles)) deallocate (m_eles)
allocate (m_eles(size(pele%control)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ltt%ele_start = '' ! Where to start in the lattice
ltt%ele_stop = '' ! Where to start in the lattice

ltt%beam_output_file = 'beam.h5'
ltt%phase_space_output_file = ''
ltt%averages_output_file = 'out'
ltt%custom_output_file = 'custom.dat'
Expand Down
2 changes: 1 addition & 1 deletion bsim/modules/lt_tracking_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module lt_tracking_mod
character(40) :: ele_extract = ''
character(100) :: ele_write_at = ''
character(200) :: lat_file = ''
character(200) :: beam_output_file = 'beam.h5'
character(200) :: beam_output_file = ''
character(200) :: custom_output_file = ''
character(200) :: map_file_prefix = ''
character(200) :: map_ascii_output_file = ''
Expand Down
2 changes: 1 addition & 1 deletion tao/version/tao_version_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
!-

module tao_version_mod
character(*), parameter :: tao_version_date = "2024/08/02 09:48:49"
character(*), parameter :: tao_version_date = "2024/08/02 23:02:22"
end module

0 comments on commit f6ceae6

Please sign in to comment.