Skip to content

Commit

Permalink
Name change: AlignmentGroup -> BodyShiftGroup. (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan authored Jan 2, 2025
1 parent ec45a01 commit b160e59
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 399 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ An individual element looks like:
Ele: "qf" (b1>>2) Quadrupole
branch Branch 1: "b1"
ix_ele 2
AlignmentGroup:
BodyShiftGroup:
offset [0.0, 0.0, 0.0] m offset_tot [0.0, 0.0, 0.0] m
x_rot 0 rad x_rot_tot 0 rad
y_rot 0 rad y_rot_tot 0 rad
Expand Down
4 changes: 3 additions & 1 deletion manual/construction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ \chapter{Constructing Lattices}

* Show how to construct a Bmad replacement line using a function.

* Show how to get the effect of a Bmad List by replacing elements after expansion.
* Show how to get the effect of a Bmad List by replacing elements after expansion.

* Default name for end element is \vn{"endN"} where N is the index of the branch.
4 changes: 2 additions & 2 deletions manual/ele-anatomy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ \section{Element Parameter Groups}
\begin{example}
julia> subtypes(EleParameterGroup)
28-element Vector{Any}:
AlignmentGroup
BodyShiftGroup
ApertureGroup
BMultipoleGroup
...
Expand All @@ -83,7 +83,7 @@ \section{Element Parameter Groups}

Associated parameter groups
===========================
AlignmentGroup -> Element position/orientation shift.
BodyShiftGroup -> Element position/orientation shift.
• ApertureGroup -> Vacuum chamber aperture.
• BMultipoleGroup -> Magnetic multipoles.
• EMultipoleGroup -> Electric multipoles.
Expand Down
24 changes: 12 additions & 12 deletions manual/ele-param-groups.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ \chapter{Element Parameter Groups}
{\it Group} & {\it Section} & {\it Group} & {\it Section} \\
\midrule
ACKickerGroup & \sref{s:ackicker.g} & LengthGroup & \sref{s:length.g} \\
AlignmentGroup & \sref{s:alignment.g} & LordSlaveStatusGroup & \sref{s:lord.slave.g} \\
BodyShiftGroup & \sref{s:alignment.g} & LordSlaveStatusGroup & \sref{s:lord.slave.g} \\
ApertureGroup & \sref{s:aperture.g} & MasterGroup & \sref{s:master.g} \\
BMultipoleGroup & \sref{s:bmultipole.g} & OrientationGroup & \sref{s:orientation.g} \\
BeamBeamGroup & \sref{s:beam.beam.g} & OriginEleGroup & \sref{s:origin.ele.g} \\
Expand Down Expand Up @@ -44,7 +44,7 @@ \chapter{Element Parameter Groups}
To see which element types contain a given group, use the \vn{info(::EleParameterGroup)}
method. Example:
\begin{example}
julia> info(AlignmentGroup)
julia> info(BodyShiftGroup)
ApertureGroup: Vacuum chamber aperture.
...
Found in:
Expand Down Expand Up @@ -104,13 +104,13 @@ \section{ACKickerGroup}
\newpage

%---------------------------------------------------------------------------------------------------
\section{AlignmentGroup}
\section{BodyShiftGroup}
\label{s:alignment.g}

\begin{figure}[bt]
\centering \includegraphics{alignment-ref.pdf}
\caption[Element alignment.]
{AlignmentGroup parameters The reference point is the origin
{BodyShiftGroup parameters The reference point is the origin
about which the element alignment is calculated.
A) For straight elements, the reference point is in the center of the element.
For \vn{Bend} elements, the reference point is at the midpoint of the chord connecting
Expand All @@ -127,7 +127,7 @@ \section{AlignmentGroup}
} \label{f:alignment}
\end{figure}

The \vn{AlignmentGroup} gives the alignment (position and angular orientation) of the physical element
The \vn{BodyShiftGroup} gives the alignment (position and angular orientation) of the physical element
relative to the nominal position defined by the branch coordinates (\sref{s:orient}).
Alignment is specified with respect to the ``alignment reference point'' of an element as shown
in Fig~\ref{s:alignment}. The \vn{Bend} reference point is chosen to be the center of the chord
Expand All @@ -136,7 +136,7 @@ \section{AlignmentGroup}
common simulation problem is to simulate a bend with a \vn{z_rot} keeping the entrance and exit
endpoints fixed.

The parameters of the \vn{AlignmentGroup} are:
The parameters of the \vn{BodyShiftGroup} are:
\begin{example}
offset::Vector - $[x, y, z]$ offset.
x_rot::Number - Rotation around the x-axis.
Expand All @@ -148,12 +148,12 @@ \section{AlignmentGroup}
parameters are with respect to the branch reference coordinates. There are output alignment
parameters:
\begin{example}
q_align::Quaternion - Quaternion representation of x_rot, y_rot, z_rot.
q_shift::Quaternion - Quaternion representation of x_rot, y_rot, z_rot.
offset_tot::Vector - $[x, y, z]$ offset.
x_rot_tot::Number - Rotation around the x-axis.
y_rot_tot::Number - Rotation around the z-axis.
z_rot_tot::Number - Rotation around the z-axis.
q_align_tot::Quaternion - Quaternion representation of tot rotations.
q_shift_tot::Quaternion - Quaternion representation of tot rotations.
\end{example}
The ``total alignment'' parameters which have a \vn{_tot} suffix are always the alignment
of the element with with respect to the branch coordinates.
Expand All @@ -165,8 +165,8 @@ \section{AlignmentGroup}
of any \vn{Girder}. \vn{Girder} elements themselves also have both relative and total
alignments since Girders can support other Girders.

The \vn{q_align} output parameter gives the quaternion representation of
\vn{x_rot}, \vn{y_rot} and \vn{z_rot}. Similarly, the\vn{q_align_tot} output parameter gives the
The \vn{q_shift} output parameter gives the quaternion representation of
\vn{x_rot}, \vn{y_rot} and \vn{z_rot}. Similarly, the\vn{q_shift_tot} output parameter gives the
quaternion representation of \vn{x_rot_tot}, \vn{y_rot_tot} and \vn{z_rot_tot}.

%---------------------------------------------------------------------------------------------------
Expand All @@ -191,7 +191,7 @@ \section{ApertureGroup}
aperture_at::BodyLoc.T - Aperture location. Default: BodyLoc.ENTRANCE_END
wall::Wall2D - Aperture defined by vertex array.
custom_aperture::Dict - Custom aperture information.
aperture_shifts_with_alignment::Bool
aperture_shifts_with_body::Bool
- Alignment affects aperture? Default: false.
\end{example}

Expand Down Expand Up @@ -895,7 +895,7 @@ \section{OriginEleGroup}

The \vn{OriginEleGroup} is used with \vn{Fiducial}, \vn{FloorShift}, and \vn{Girder} elements.
The \vn{OriginEleGroup} is used to set the coordinate reference frame from which
the orientation set by the \vn{AlignmentGroup} is measured. To specify that the floor coordinates are
the orientation set by the \vn{BodyShiftGroup} is measured. To specify that the floor coordinates are
to be used, set the \vn{origin_ele} to \vn{NULL_ELE}. Typically this is the same as using the
beginning element of the first branch of a lattice as long as the first element does not have
any orientation shifts.
Expand Down
8 changes: 4 additions & 4 deletions manual/ele-types.tex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ \section{ACKicker}
Element parameter groups associated with this element type are:
\TOPrule
\begin{example}
AlignmentGroup -> Element position/orientation shift. \sref{s:align.g}
BodyShiftGroup -> Element position/orientation shift. \sref{s:align.g}
ApertureGroup -> Vacuum chamber aperture. \sref{s:aperture.g}
BMultipoleGroup -> Magnetic multipoles. \sref{s:bmultipole.g}
OrientationGroup -> Floor floor position and orientation. \sref{s:orientation.g}
Expand Down Expand Up @@ -143,7 +143,7 @@ \section{Bend}
Element parameter groups associated with this element type are:
\TOPrule
\begin{example}
AlignmentGroup -> Element position/orientation shift. \sref{s:align.g}
BodyShiftGroup -> Element position/orientation shift. \sref{s:align.g}
ApertureGroup -> Vacuum chamber aperture. \sref{s:aperture.g}
BMultipoleGroup -> Magnetic multipoles. \sref{s:bmultipole.g}
BendGroup -> Bend element parameters. \sref{s:bend.g}
Expand Down Expand Up @@ -562,7 +562,7 @@ \section{Girder}
OrientationGroup -> Floor floor position and orientation. \sref{s:orientation.g}
LengthGroup -> Length and s-position parameters. \sref{s:length.g}
DescriptionGroup -> Element descriptive strings. \sref{s:descrip.g}
AlignmentGroup -> Alignment with respect to the reference. \sref{s:alignment.g}
BodyShiftGroup -> Alignment with respect to the reference. \sref{s:alignment.g}
\end{example}
\BOTTOMrule

Expand Down Expand Up @@ -601,7 +601,7 @@ \section{Girder}

The reference frame from which a \vn{Girder}'s orientation is measured is set by the
\vn{origin_ele} and \vn{origin_ele_ref_point} parameters (\sref{s:origin.ele.g}).
Orientation shifts are controlled by the \vn{AlignmentGroup} (\sref{s:align.g}).
Orientation shifts are controlled by the \vn{BodyShiftGroup} (\sref{s:align.g}).

When a girder is shifted in space, the elements
it supports are also shifted. In this case, the orientation
Expand Down
5 changes: 2 additions & 3 deletions src/AcceleratorLattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ include("lat_construction.jl")
include("output_lat.jl")
include("query.jl")
include("find.jl")
include("external_ele.jl")

# Note! Element types, enums, and Holy traits are exported automatically when constructed.

Expand All @@ -70,7 +69,7 @@ export split!, construct_ele_type, ele_at_s, toggle_integrated!
export eles_search, eles_substitute_lords!, eles_sort!
export next_ele, ele_at_offset, ele_param_value_str, strip_AL, ele_param_group_symbols
export branch, matches_branch, create_ele_vars, eval_str, Vertex1, LatticeGlobal
export EleParameterGroup, AlignmentGroup, OrientationGroup, BMultipole, BMultipoleGroup, BeamBeamGroup
export EleParameterGroup, BodyShiftGroup, OrientationGroup, BMultipole, BMultipoleGroup, BeamBeamGroup
export EMultipole, EMultipoleGroup, BendGroup, ApertureGroup, DescriptionGroup, RFGroup, SolenoidGroup
export TrackingGroup, LengthGroup, ReferenceGroup, DownstreamReferenceGroup, ForkGroup
export MasterGroup, LordSlaveStatusGroup, ACKickerGroup
Expand All @@ -83,7 +82,7 @@ export machine_location, body_location, EleRegion, holy_traits, output_parameter
export BranchType, LordBranch, TrackingBranch, MultipassBranch, SuperBranch, transform
export str_split, str_match, str_unquote, str_quote, str_to_int, associated_names
export ELE_PARAM_GROUP_INFO, ELE_TYPE_INFO, PARAM_GROUPS_LIST, OPEN, CLOSED
export rotX, rotY, rotZ, rot, rot!
export rotX, rotY, rotZ, rot, rot!, bend_quaternion, lat_ele_dict

# From LinearAlgebra
export norm
Expand Down
77 changes: 48 additions & 29 deletions src/accessor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ end
"""
Base.getindex(lat::Lattice, name::AbstractString)
Base.getindex(lat::Lattice, ix_branch::Int)
Base.getindex(lat::Lattice, typ::Type{T} where T <: BranchType)
If `lat[name]` matches a branch name, return the branch. No wild cards permitted here.
If `lat[name]` does not match a branch name, return list of matching lattice elements.
In this case the returned vector is equivalent to `eles_search(lat, name)`.
In this case, the returned vector is equivalent to `eles_search(lat, name)`.
For `lat[ix_branch]`, return `lat.branch[ix_branch]`.
""" Base.getindex(lat::Lattice, name::AbstractString)
Expand All @@ -223,26 +224,44 @@ function Base.getindex(lat::Lattice, name::AbstractString)
return eles_search(lat, name)
end

#------------

function Base.getindex(lat::Lattice, ix_branch::Int)
if ix_branch > length(lat.branch); error("Index above length of lat.branch[] array."); end
return lat.branch[ix_branch]
end

#------------

Base.getindex(lat::Lattice, typ::Type{T} where T <: BranchType) = lat.branch[typ]

#---------------------------------------------------------------------------------------------------
# Base.getindex(branch::Vector{Branch}, name::AbstractString)

"""
Base.getindex(branch::Vector{Branch}, name::AbstractString)
Base.getindex(branch::Vector{Branch}, typ::Type{T} where T <: BranchType)
Match `branch[name]` to branch in `branch[]` array using the names of the branches.
""" Base.getindex(branch::Vector{Branch}, name::AbstractString)
Match `branch[name]` or `branch[type]` to branch in `branch[]` array using the names or types
of the branches. If there are multiple matches the match with the smallest index is returned.
""" Base.getindex(branch::Vector{Branch})

function Base.getindex(branch::Vector{Branch}, name::AbstractString)
for br in branch
if br.name == name; return br; end
end

error(f"No branch with name: {name}")
error("Cannot find branch with name: $name")
end

#-----------

function Base.getindex(branch::Vector{Branch}, typ::Type{T} where T <: BranchType)
for br in branch
if br.type == typ; return br; end
end

error("Cannot find branch of type: $typ")
end

#---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -459,49 +478,49 @@ function output_parameter(sym::Symbol, ele::Ele, output_group::Type{T}) where T
if :DownstreamReferenceGroup keys(ele.pdict); return NaN; end
return ele.E_tot_ref_downstream / massof(ele.species_ref_downstream)

elseif sym == :q_align
if :AlignmentGroup keys(ele.pdict); return NaN; end
ag = ele.pdict[:AlignmentGroup]
elseif sym == :q_shift
if :BodyShiftGroup keys(ele.pdict); return NaN; end
ag = ele.pdict[:BodyShiftGroup]
return Quaternion(ag.x_rot, ag.y_rot, ag.z_rot)

elseif sym == :offset_tot
if :AlignmentGroup keys(ele.pdict); return NaN; end
if :BodyShiftGroup keys(ele.pdict); return NaN; end
if isnothing(girder(ele)); return ele.offset; end
ag = ele.pdict[:AlignmentGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_align_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_align)
ag = ele.pdict[:BodyShiftGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_shift_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_shift)
return coord_transform(orient_ele, orient_girder).r

elseif sym == :x_rot_tot
if :AlignmentGroup keys(ele.pdict); return NaN; end
if :BodyShiftGroup keys(ele.pdict); return NaN; end
if isnothing(girder(ele)); return ele.x_rot; end
ag = ele.pdict[:AlignmentGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_align_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_align)
ag = ele.pdict[:BodyShiftGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_shift_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_shift)
return rot_angles(coord_transform(orient_ele, orient_girder).q)[1]

elseif sym == :y_rot_tot
if :AlignmentGroup keys(ele.pdict); return NaN; end
if :BodyShiftGroup keys(ele.pdict); return NaN; end
if isnothing(girder(ele)); return ele.y_rot; end
ag = ele.pdict[:AlignmentGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_align_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_align)
ag = ele.pdict[:BodyShiftGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_shift_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_shift)
return rot_angles(coord_transform(orient_ele, orient_girder).q)[2]

elseif sym == :z_rot_tot
if :AlignmentGroup keys(ele.pdict); return NaN; end
if :BodyShiftGroup keys(ele.pdict); return NaN; end
if isnothing(girder(ele)); return ele.z_rot; end
ag = ele.pdict[:AlignmentGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_align_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_align)
ag = ele.pdict[:BodyShiftGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_shift_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_shift)
return rot_angles(coord_transform(orient_ele, orient_girder).q)[3]

elseif sym == :q_align_tot
if :AlignmentGroup keys(ele.pdict); return NaN; end
if isnothing(girder(ele)); return ele.q_align; end
ag = ele.pdict[:AlignmentGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_align_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_align)
elseif sym == :q_shift_tot
if :BodyShiftGroup keys(ele.pdict); return NaN; end
if isnothing(girder(ele)); return ele.q_shift; end
ag = ele.pdict[:BodyShiftGroup]
orient_girder = OrientationGroup(girder(ele).offset_tot, girder(ele).q_shift_tot)
orient_ele = OrientationGroup(ele.offset, ele.q_shift)
return coord_transform(orient_ele, orient_girder).q
end

Expand Down
Loading

0 comments on commit b160e59

Please sign in to comment.