Lattice elements for applied fields to focus, accelerate, and bend the beam (and/or the coordinate system) can be added using using Lattice Element Scripts, MAD Style Input, or by Directly Setting Lattice Arrays that the code uses. These are outlined below. Warp users are encouraged to use the lattice element scripts as a first option. Mad style input is retained for legacy compatibility and directly setting lattice arrays used by the code should be reserved for special cases by expert users. Most classes of lattice elements have many possible options and are compatible with ring (multiple pass) and linear (single pass) architecture machines. For rings, periodicity variables should be consistently set. More information on this topic can also be found in the lattice documentation. For time dependent lattice elements, see Time dependent lattice elements. Lattice Element Scripts To simplify the process of adding lattice elements, python functions are available that set the appropriate Warp variables to add elements to the simulation. These functions are recommended as the preferred method to construct a lattice. For each type of lattice element, there is a corresponding function addnewelemement() with "element" replaced with the class of lattice element. For example: addnewquad(zs=...,ze=...,db=...) addnewquad(zs=...,ze=...,de=...) Alternatively to these scripts, the relevant lattice arrays that Warp employs and the lattice element scripts set can be sized appropriately and set as desired as described below under Directly Setting Lattice Arrays. However, this can become complicated due to the general nature of the problem and should only be applied in special cases by expert code users.The complexity results from lattice element arrays needing to be sufficiently general to cover cases such as periodic errors in rings. Available addnewelement() functions for creating lattice elements include: addnewdrft(...) # Drift element (can be used to load aperture/pipe structure in some field solvers) addnewquad(...) # Hard-edged or self-consistent quadrupole (magnetic or electric) focusing elements addnewbend(...) # Bending lattice elements addnewdipo(...) # Hard-edged or self-consistent dipole bending elements addnewaccl(...) # Hard-edged accelerating gaps addnewsext(...) # Hard-edged sextupole elements addnewhele(...) # Hard-edged arbitrary electric and magnetic multipole moments addnewemlt(...) # Axially varying arbitrary electric multipole moments addnewmmlt(...) # Axially varying arbitrary magnetic multipole moments addnewbgrd(...) # Magnetic field specified on a two or three-dimensional grid addnewegrd(...) # Electric field specified on a two or three-dimensional grid addnewpgrd(...) # Electrostatic potential specified on a two or three-dimensional grid Below we setup a simple hard-edge magnetic FODO quadrupole focusing lattice to illustrate how lattice element scripts can be applied. The FODO lattice has 50% magnetic occupancy and starts at z=0 entering a hard-edge quadrupole with a positive field gradient. rp = 2.*cm # aperture radius [m] Bp = 1. # pole tip field at aperture [Tesla] lq = 20.*cm # Quadrupole hard-edge axial length [m] ld = 20.*cm # Drift length between hard-edge quadrupoles [m] dbdx = Bp/rp addnewquad(zs=0.,ze=lq,db=dbdx,ap=rp) addnewdrift(zs=lq,ze=lq+ld,ap=rp) addnewquad(zs=lq+ld,ze=2.*lq+ld,db=-dbdx,ap=rp) addnewdrift(zs=2.*lq+ld,ze=2.*lq+2.*ld,ap=rp) This lattice can then be continued periodically by setting lattice periodicity with:. top.zlatstrt = 0. # z of lattice start (added to element z's on generate). top.zlatperi = 2.*(lq+ld) # lattice periodicity For more detailed electric and magnetic element descriptions such as gridded field elements [egrd,bgrd] and 3d multipole moments [emlt,mmlt] it may be desirable to have several elements in the lattice use a common data file describing the field. In this case, the file data might be entered functions like: addnewbgrddataset(...) # Add new data set for bgrd applied B-field elements addnewegrddataset(...) # Add new data set for egrd applied E-field elements addnewmmltdataset(...) # Add new data set for 3d magnetic multipole moment addnewemltdataset(...) # Add new data set for 3d electric multipole moment ibgrd = addnewbgrddataset(bx=bx,by=by,bz=bz,dx=dx,dy=dy,zlength=zlen) and the corresponding unique bgrd data set index ibgrd returned in the call to addnewbrddataset() can then be used to setup optical elements using the same data set in two instances with addnewbgrd(id=ibgrd,zs=0.,ze=zlen) addnewbgrd(id=ibgrd,zs =1.,ze=1.+zlen,sc=-1) Various diagnostic functions are useful to verify that the lattice is loaded correctly. Useful functions to plot applied fields loaded associated with more detailed element descriptions include: plotmmlt() # Plot magnetic multipole moments plotemlt() # Plot electric multipole moments plotacclet() # Plot time dependent fields of an acceleration element plotbgrd() # Plot components of gridded applied magnetic field element plotegrd() # Plot components of gridded applied electric field element getappliedfields() # Returns tuple of applied fields (ex,ey,ez,bx,by,bz) at specified position(s) x,y,z getappliedfieldsongrid() # Analogous to getappliedfields() but on a specified uniform mesh MAD Style Input The MAD family of codes (MAD, MAD-X, MAD-8, diMAD, ...) employ a commonly used syntax for lattice descriptions in accelerator physics. Warp has scripts that part replicate this syntax: Drft() # Create drift instance Bend() # Create bend instance Dipo() # Create dipole instance Quad() # Create quadrupole instance Sext() # Create sextupole instance Hele() # Create hard edge multipole moment instance Accl() # Create acceleration instance Emlt() # Create electric multipole moment instance Mmlt() # Create magnetic multipole moment instance Bgrd() # Create gridded B-field instance Pgrd() # Create gridded E-field instance qf = Quad(l=10.*cm,db= 1.5,ap=3.*cm) # focusing magnetic quadrupole qd = Quad(l=10.*cm,db=-1.5,ap=3.*cm) # defocusing magnetic quadrupole dd = Drft(l=5.*cm,ap=3.*cm) # drift Then we define the lattice period and setup the underlying Warp lattice element arrays used by the code with lp = qf + dd + qd + dd madtowarp(lp) Alternatively, one could then define a section which was 10 of these lattice periods in a row using: s1 = 10*lp For an accelerator made up of 3 sections, named s1, s2, and s3, the underlying Warp lattice arrays are setup with: lattice = s1 + s2 + s3
madtowarp(lattice) There is also a function to read in MAD style input files to generate a Warp lattice: getlattice() Directly Setting Lattice Arrays In principle, users can directly set variables in the lattice arrays/variables that the code uses to generate the desired lattice. However, it is recommended that the user NOT do this because many quantities must be set consistently to properly function. This also bypasses numerous error checks that the methods in the Lattice Element Scripts or the scripts for MAD Style Input provide. Nevertheless, directly accessing the lattice arrays can be useful for debugging. To understand how to do this, examine variable blocks defined in the source code within top.v. For example, top.quads # logical variable flagging the existance of quadrupole hard-edge elements top.quadzs # Array (if allocated) of hard-edge quadrupole z-start coordinatesMany lattice element arrays are dynamic and must, if set, be sized appropriately. For example, if 10 quadrupoles will be defined in the lattice, you should first allocate memory in the dynamic lattice arrays calling: top.quads = true top.nquad = 10 gchange("Lattice") and then set relevant quadrupole lattice arrays defined in top.v to specify the elements. Here, top.quads is set to true so the lattice fields corresponding to the quad lattice element arrays will be set in the applied field gather. If top.quads is not set to true, the corresponding element fields will not be set in the applied field gather. This illustrates a simple case of many potential subtleties and pitfalls associated with directly setting lattice arrays. |