Apr 29, 2004
The Sequential Ray Tracing (SRT) code is an application package within the Q data analysis system. The ray tracing is sequential in the sense that rays are expected to follow a particular sequence through the optical elements specified, however, by careful setting of flags associated with each element the sequence can be controlled dynamically to handle multiple reflections (recursion) between various elements.
The code was primarily written for modelling grazing incidence telescopes but it includes comprehensive algorithms to cover normal incidence instruments and many common optical elements.
The essential sequence of elements is:
source --> mirrors/stops/lenses/gratings/etc --> detector
Each of the elements, including the source and detector, are specified by:
There is no fixed coordinate system and elements can be set/defined at any orientation. However it is conventional to use the X-axis as the optical axis (which defines the direction of paraxial rays) and the Y-axis as the nominal tangent reference axis. Of course given elements may not be aligned exactly with the X-axis and Y-axis. In most cases the local coordinates in the detector plane are nominally aligned with the Y-axis and Z-axis. Rays are usually traced from right to left travelling in the -X direction but this is not necessary and it is possible for rays to bounce back and forth as in, for example, a cassegrain system.
The source is always the first element in the sequence. All other elements are placed in sequence as they are defined. If the source command is used repeatedly the source specification will be overwritten. If the detector command is used repeatedly a new detector will be added to the sequence each time.
Local surface coordinates for planar spherical surfaces are specified using the tangent plane to the surface at the point defined as the surface origin. For a sphere points on this tangent plane are projected onto the surface along the normal to the surface at the surface origin (Lambert's projection). The local x-axis is specified by a tangent vector at the surface origin. The local y-axis is the cross product of the normal and tangent vector at the surface origin.
Rectangular apertures are specified using local coordinates:
xmin, ymin, xmax, ymax
Annular apertures are specified in local polar coordinates about the origin using:
Nested annular apertures are specified by a sequence of radii in local polar coordinates.
rmin, rmax, rmin, rmax...
A cartesian grid aperture is specified in local coordinates by:
pitchx, pitchy, ribx, riby
The local coordinates used for surfaces of revolution generated from conic sections (hyperbola, parabola, ellipse) depend on whether the surface is designated as being "normal" or "grazing" incidence. For normal incidence they are defined in a similar way to the planar or spherical surfaces as given above. For grazing incidence a cylindrical coordinate system is used where the axis is the normal to the surface at the surface origin and the azimuth is the rotation about this axis with zero at the surface reference axis at the surface origin. Local coordinates are given as axial position and azimuthal position (radians). The limits of such surfaces are specified by axial and/or radial limits corresponding to the bottom and top edges of the surface of revolution.
The source consists of annular or rectangular aperture on a planar surface. The origin of each ray is a random point within the aperture. The direction of the rays is specified either by a source at infinity, a source at a finite distance or diffuse. For a source at infinity all rays are parallel with the direction set by direction cosines. A source at a finite distance is specified by a position vector somewhere behind the aperture. Diffuse rays are generated so as to give a uniform random distribution over a hemisphere. The total number of rays generated is either set explicitly or by using an aperture area per ray.
The Q command and parameters for the source are:
Q>show source SOURCE Define source parameters primitive Q_SRT TRS_SRCE parameters _STYPE 1 or 2 inf, 3 or 4 fin, 5 or 6 dif, (1,3 or 5 radial limits) _SDIR direction cosines of rays from infinite source _SPOS position of finite point source _APOS reference position in source aperture _ANML normal to source aperture _ARFX reference axis in source aperture _ALIM limits in aperture (xmin,ymin,xmax,ymax or rmin,rmax) _APRY aperture area per ray (0.0 to specify number of rays) _NRAY number of rays over source aperture _DEFI deformation index
Only one source can be specified. If the source command is used in a loop then the source will change on each pass through the loop.
The deformation index is used to specify a pixel array which spreads out a point source into an angular distribution. The deformation data are set using two commands DEFORM and DEFMAT (see section 2.6).
If the source is at infinity the XSAM and YSAM arrays must be radians measured from the direction SDIR along the reference axis ARFX and the other axis (ANML cross ARFX).
If the source is at a finite distance then XSAM and YSAM are displacements in mm (or whatever distance unit is used) of the position SPOS along the reference axis ARFX and the other axis (ANML cross ARFX).
The command DEFORM sets up a deformation. For SOURCE only 1 matrix is required so DEFT=1. The command DEFMAT is used to populate the matrix and sample arrays for a particular deformation. The following lines of Q code show how a SOURCE pixel array can be set up. In this example the source is an annular ring specified by radii 7 to 8 degrees.
ispic=1 nd=100 deform(ispic,1,1,nd,nd) rsrce=dtor(10) xsam=rsrce*2/nd x=(index([_real](nd))-1)*xsam-rsrce ii=index([_real](nd,nd))-1 xx=mod(ii,nd)*xsam-rsrce yy=int(ii/nd)*xsam-rsrce rr=rtod(sqrt(xx*xx+yy*yy)) zx=abs((rr>7)and(rr<8)) defmat(ispic,1,x,x,zx)
The detector consists of an annular or rectangular aperture on a planar or spherical surface.
The Q command and parameters for the detector are:
Q>show detector DETECTOR Define detector parameters primitive Q_SRT TRS_DETR parameters _DTYPE 1,3 rad. limits, 2,4 cart. limits, 1,2 planar, 3,4 spherical _DPOS reference position on detector _DNML normal to detector surface _DRFX reference axis in surface _DLIM limits of detector (xmin,ymin,xmax,ymax or rmin,rmax) _RADET radius of curvature for spherical detector
More than one detector can be specified for an instrument. Each definition occupies a given position within the sequence of optical elements specified. Therefore the Q code line in which the detector is specified is important.
Several surface qualities can be set up for the simulation of a given instrument. Each is referenced using a surface quality index (integer 1,2,3...). The type of surface can be reflecting (with reflectivity specified using Fresnel's equations or a lookup table), refracting or diffracting. The roughness of the surface can also be specified using a power law distribution.
The Q command and parameters for specifying surface quality are:
Q>show surface SURFACE Define surface quality primitive Q_SRT TRS_SQUL parameters _QIND surface quality index _QTYPE 1 refl. (Fresnel), 2 refl. (look-up), 3 refract, 4 diffract _WLNG wavelength (Angstoms) _SRGH Specific roughness (A**2 mm) _FMIN Minimum surface spatial frequency _PIND Surface roughness power spectrum index _ALPHA real part of diel. constant or refractive index ratio N1/N2 _GAMMA imaginary part of dielectric constant _ANGS incidence angles (degrees increasing) _REFS reflectivity values
Stops which are intended to block radiation have a surface quality index set to 0. When rays hit such surfaces they are terminated (absorbed). Detectors have surface quality index -1. If a ray hits such a surface it is terminated (detected). The source aperture surface has quality index -2. The quality indices of the source, stops and detectors are set automatically. As ray tracing proceeds rays can be stored for further analysis. Each position along a ray where an intersection with a surface element occured is labelled with the quality index of the surface.
Deformations of surfaces are specified using matricies which span a grid of points in the local coordinate system of the surface. A set of deformations pertaining to a single surface or group of related surfaces are given a deformation index (integer 1,2,3...). The positions of the deformation grid points in local coordinates are specified by two 1-dimensional arrays.
The Q command to set the dimensionality of a particular deformation must be used first.
Q>show deform DEFORM Define surface deformation primitive Q_SRT TRS_DEFS parameters _DIND deformation index _DEFT 1 for matrices _NSUB number of sub-matrices _NX number of x samples _NY number of y samples
The Q command to set the component matrices is then:
Q>show defmat DEFMAT Set deformation sub-matrices primitive Q_SRT TRS_MATS parameters _DIND deformation index _MIND sub-matrix index (shell number) _XSAM x samples _YSAM Y samples _ZDEF deformation displacement matrix
A deformation can also used to spread a point source into a pixel array. See section 2.3.
The following command can be used to generate a tabulation of a deformation which is already set. This can be useful to check that the interpolation of the matrix is working as required/expected.
Q>show tabdef TABDEF Tabulate deformation primitive Q_SRT TRS_TDEF parameters _DIND deformation index _NSUB number of sub-matrices _XSAM x samples _YSAM Y samples _TABOUT structure for results\TABDATA[TOP]
The following command is used to specify an aperture or stop.
Q>show aperture APERTURE Define aperture stop primitive Q_SRT TRS_STOP parameters _ATYPE 1 radial, 2 nested rad., 3 cart.hole, 4 cart.block, 5 grid _DEFI deformation index _APOS reference position in aperture _ANML normal to aperture _ARFX reference axis in aperture _ALIM aperture limits ([aref,rmin,rmax,..]) _NSURF number of subsequent surfaces per aperture
The format for the limits ALIM is given in section 2.2. The parameter NSURF is used for radially nested apertures so that the code knows how many surface elements to skip if a ray penitrates a particular annulus.
A plane mirror is specified by:
Q>show mirror MIRROR Define plane mirror primitive Q_SRT TRS_MIRROR parameters _ATYPE 1 radial, 2 nested rad., 4 cart., 6 slats _DEFI deformation index _QIND surface quality index _APOS reference position in aperture _ANML normal to aperture _ARFX reference axis in aperture _ALIM aperture limits ([aref,rmin,rmax,..]) _NSURF number of subsequent surfaces per aperture
The aperture limits of the mirror are specified in the same way as for a stop, see sections 2.2 and 2.7.
The sector apertures imposed by a spider support structure as used in the construction of Wolter I telescopes are specified by:
Q>show spider SPIDER Define spider support primitive Q_SRT TRS_SPIDER parameters _CONE 90-half cone angle (degrees) 0.0 for plane \0.0 _APOS axial position of vertex (centre) _ANML direction of normal _ARFX reference axis perpendicular to normal _NSEC number of sectors in spider _CWID constant width of spider arms _AWID angular width of spider arms (degrees)
The surface figure of the spider aperture is a cone. The width of the arms is given by CWID+AW*R where R is the radial distance from the axis of the cone and AW is AWID degrees converted into radians.
A cylindrical baffle is defined by:
Q>show baffle BAFFLE Define cylindrical baffle primitive Q_SRT TRS_BAFFLE parameters _XMIN axial position of base _XMAX axial position of top _RAD radius of cylinder _AXIS direction of axis _ARFX reference axis perpendicular to normal _APOS axial position of vertex (centre) _QIND surface quality index
The axial positions of the base and top, XMIN and XMAX are local coordinates wrt APOS along the AXIS direction.
Q>show wolter1 WOLTER1 Define Wolter I telescope primitive Q_SRT TRS_WLT1 parameters _XJOIN axial position of join plane _RJOIN radius at join plane _RATIO ratio of grazing angles\1.0 _PARL axial position of parabola near join _PARH axial position of parabola at entrance aperture _HYPL axial position of hyperbola at exit aperture _HYPH axial position of hyperbola near join _WLTOUT structure for resulting parameters\WLTDATA[TOP] _AXIS direction of axis of optic _WRFX reference direction perpendicular to axis _FOCUS position of focus of telescope _DEFI deformation index _QIND surface quality index
Q>show sph1 SPH1 Define Spherical approximation Wolter I telescope primitive Q_SRT TRS_SPH1 parameters _XJOIN axial position of join plane _RJOIN radius at join plane _RATIO ratio of grazing angles\1.0 _PARL axial position of parabola near join _PARH axial position of parabola at entrance aperture _HYPL axial position of hyperbola at exit aperture _HYPH axial position of hyperbola near join _RW Tangential width of sector _WLTOUT structure for resulting parameters\WLTDATA[TOP] _AXIS direction of axis of optic _WRFX reference direction perpendicular to axis _FOCUS position of focus of telescope _DEFI deformation index _QIND surface quality index
Q>show sphg SPHG Define spherical mirror at grazing incidence primitive Q_SRT TRS_SPHG parameters _CENS centre of sphere _ORGS local origin on surface of sphere _AXIS direction of axis of optic _RL Tangential length of sector (axial direction) _RW Tangential width of sector _SPHOUT structure for resulting parameters\SPHDATA[TOP] _DEFI deformation index _QIND surface quality index
Q>show lens LENS Define spherical or cylindrical lens primitive Q_SRT TRS_LENS parameters _LTYPE spherical lens 1, cylindrical lens 2 _DEFI deformation index _QIND surface quality index _AXIS direction of optical axis of lens _WRFX reference direction perpendicular to axis _APOS position of centre of lens _RAP aperture radius _R1 radius of curvature of 1st surface _R2 radius of curvature of 2nd surface _REFIND refractive index of lens material (or n2/n1) _THICK lens thickness
Q>show prism PRISM Define prism primitive Q_SRT TRS_PRISM parameters _PTYPE small angle prism 1, right-angled prism 2 _DEFI deformation index _QIND surface quality index _AXIS direction of optical axis of lens _WRFX reference direction perpendicular to axis _APOS position of centre of lens _RAP aperture radius _REFIND refractive index of lens material (or n2/n1) _THICK lens thickness _D1 small angle radians on entry side _D2 small angle radians on exit side
Q>show w1nest W1NEST Define Wolter I telescope nest primitive Q_SRT TRS_W1NST parameters _XJ axial position of join plane _RJ radii at join plane (last is shell dummy) _RA ratio of grazing angles\1.0 _PL axial position of parabola near join _PH axial position of parabola at entrance aperture _HL axial position of hyperbola at exit aperture _HH axial position of hyperbola near join _WLTOUT structure for resulting parameters\WLTDATA[TOP] _THI shell thicknesses at input aperture _THJ shell thicknesses at join plane _THO shell thicknesses at output plane _AXIS direction of axis of telescope _WRFX reference direction perpendicular to axis _FOCUS position of focus of telescope _DEFI deformation index _QIND surface quality index _BIND surface quality index for backs of shells
Q>show c1nest C1NEST Define conical Wolter I telescope nest primitive Q_SRT TRS_C1NST parameters _XJ axial position of join plane _PL axial position of parabola near join _PH axial position of parabola at entrance aperture _HL axial position of hyperbola at exit aperture _HH axial position of hyperbola near join _RPL radii of parabola near join _RPH radii of parabola at entrance aperture _RHL radii of hyperbola at exit aperture _RHH radii of hyperbola near join _THI shell thicknesses at input aperture _THJ shell thicknesses at join plane _THO shell thicknesses at output plane _AXIS direction of axis of telescope _WRFX reference direction perpendicular to axis _FOCS position of focus of telescope _DEFI deformation index _QIND surface quality index _BIND surface quality index for backs of shells
Q>show wolter2 WOLTER2 Define Wolter II telescope primitive Q_SRT TRS_WLT2 parameters _RP maximum radius of parabola _GP grazing angle (degrees) at maximum radius on parabola _RH maximum radius of hyperbola _GH grazing angle (degrees) at maximum radius on hyperbola _RM minimum radius of parabola _FOVR radius of field of view degrees _WLTOUT structure for resulting parameters\WLTDATA[TOP] _AXIS direction of axis of telescope _WRFX reference direction perpendicular to axis _FOCUS position of focus of telescope _DEFI deformation index _QINDP surface quality index of parabola _QINDH surface quality index of hyperbola
Q>show mcp MCP Define slumped MCP with square pores primitive Q_SRT TRS_PORE parameters _PCEN centre of plate _PNORM normal at centre of plate _RAXIS reference axis at centre of plate _RCUR radius of curvature of plate _IPACK pore packing, 1 cartesian, 2 radial, 3 waffle _RAP Radius or half width of plate aperture _PITCH pitch of channels on cartesian grid _PLEN length of channels _WALL wall thickness of channels _DEFI deformation index _QIND surface quality index
A full listing of all the currently defined elements and their parameters is provided by:
Q>show srtlist SRTLIST List all surface parameters primitive Q_SRT TRS_LIST parameters _ICHAN channel number for listing
Channel 6 is used for terminal output. If ICHAN=1 and no file name has been allocated to that channel then the text file fort.1 will be created.
Once elements have been defined they can be shifted and/or rotated using the following commands:
Q>show shift SHIFT shift surface element primitive Q_SRT TRS_SHIFT parameters _ISURF surface element number _VSHIFT shift vector Q>show rotate ROTATE rotate surface element primitive Q_SRT TRS_ROTATE parameters _ISURF surface element number _RPOS position of rotation centre _RAXIS rotation axis _RANGLE rotation angle
Q>show mlayer MLAYER Calculate reflectivities from a multilayer primitive Q_SRT TRS_MLTR parameters _DLAY thickness of layers (Angstoms) _NRLAY real part of refractive index of layers _NILAY imaginary part of refractive index of layers _NPERS number of periods of interfaces between layers 2 to n-1 _WLNG wavelength (Angstoms) _IANGS array of incidence angles (degrees) _MULOUT structure for results \MULDATA[top] Q>show mlier MLIER Integrated energy response of multilayer primitive Q_SRT TRS_MLIER parameters _DMIN minimum periodic spacing (A) _DMAX maximum periodic spacing (A) _HRAT fraction of period for heavy element _NPERS number of periods for multilayer _EKEV array of energies (ascending) _IANGS array of incidence angles (degrees) _HRLAY real part of refractive index for heavy element _HILAY imaginary part of refractive index for heavy element _LRLAY real part of refractive index for light element _LILAY imaginary part of refractive index for light element _NREF number of reflections _MULOUT structure for results \MULDATA[top] Q>show finter FINTER Calculate Fresnel coefficients of interface primitive Q_SRT TRS_FPOR parameters _REFR1 real part of refractive index 1 _REFI1 imaginary part of refractive index 1 _REFR2 real part of refractive index 2 _REFI2 imaginary part of refractive index 2 _IANGS array of incidence angles (degrees) _RTOUT structure for results \RTDATA[top] Q>show fresnel FRESNEL Calculate Fresnel reflectivity of surface primitive Q_SHARE FRESNEL parameters _NREAL real part of refractive index _KIMAG imaginary part of refractive index _ANGS incidence angles (degrees increasing) _FRESOUT structure for results\FRESDATA[FRESNEL] Q>show xfresnel XFRESNEL Calculate X-ray reflectivity of surface primitive Q_SHARE XFRESNEL parameters _ALPHA real incremental part of dielectric constant _GAMMA imaginary part of dielectric constant _ANGS incidence angles (degrees increasing) _FRESOUT structure for results\FRESDATA[FRESNEL]
Once the source, detector and other elements have been defined rays can be traced through the instrument using:
Q>show srt SRT Sequential Ray Tracing primitive Q_SRT TRS_TRC parameters _IDEBUG 0 no debugging, 1 list rays\\0
IDEBUG=1 should only be used for a small number of rays because the volume of information listed is considerable! This command puts the results onto a scratch file. The following command must be used to generate a structure which holds the final results.
Q>show saverays SAVERAYS Save rays on structure primitive Q_SRT TRS_SAVE parameters _IWHAT 1 rays, 2 detections, 3 both\2 _SRTOUT structure for rays\srtdata[top] _RIRIS radius for rms blur analysis about detector origin _ADJUST adjust axial position of detector for minimum rms blur\0 _PSAS pixel arc seconds for diff. limited image (0 for no image) _NDIFF dimension of diffraction limited image (pref. power 2) _PPLANE position of principal plane wrt detector
If IWHAT=3 then everything is saved. A typical results is shown below.
HDS_SCRATCH.TEMP_89[TOP] RPOS(3,90969) = 53.000000000000 5.3920102119446 IQU(90969) = -2 1 RDIR(3,30000) = -0.99418958000000 -0.10764221818986 RQU(3,30000) = 1550.0000000000 7.33725590040900E-03 XD(15214) = -2.5664098203356 0.16883392687399 YD(15214) = -4.19275695900581E-02 7.44368856405007E-02 ZD(15214) = -16.311208613014 8.51345355159442E-02 XR(15214) = 47.629996564540 48.555786359612 YR(15214) = 5.3929036106238 5.9553042748787 ZR(15214) = -16.286895672311 10.117202434805 XC(15214) = -0.99418958000000 -0.97231500000000 YC(15214) = -0.10764221818986 -0.11817350107998 ZC(15214) = -4.81541888086971E-04 -0.20159009007761 DYDX(15214) = 0.10827132003321 0.12153828859987 DZDX(15214) = 4.84356201044645E-04 0.20733002172919 AREA(15214) = 7.33725590040900E-03 2.24834706533962E-02 DIST(15214) = 55.861474243539 54.178327156951 NHIT1(15214) = 3 2 NHIT2(15214) = 0 0 NHIT3(15214) = 0 0 YDET(15214) = -4.19275695900581E-02 7.44368856405007E-02 ZDET(15214) = -16.311208613014 8.51345355159442E-02 WLENGTH(15214) = 1550.0000000000 1550.0000000000 RIRIS = 1.0000000000000 ADJUST = 1 DSHFT = -3.10210657909058E-02 YBAR = 4.10487855949513E-04 ZBAR = -1.93143438583830E-03 RMSRAD = 0.10456194961276 PSAS = 0.0000000000000 PPLANE = 6.01347001699907-154
The arrays RPOS and IQU are a record of all the rays traced. RPOS are the intersection points and IQU is the surface quality index at the intersection points. Using these data you can reconstruct the paths of the rays, see section 3.3.
The array RDIR holds the direction cosines of the rays when they were terminated (absorbed, detected or missed the last element). RQU holds the quality of the rays at termination. RQU(1,N) and RQU(3,N) are unused, RQU(2,N) is the effective aperture area associated with the ray allowing for the reflectivities of the surfaces etc..
The remaining arrays are associated with the rays which were detected. (XD,YD,ZD) is the detected position. (XR,YR,ZR) is the last ray position before detection. (XC,YC,ZC) is the ray direction at detection.
DYDX and DZDX are the gradient of the ray wrt a detector shift along the X axis.
AREA is the effective aperture area associated with the detected rays and DIST is the distance along the ray from the source to detector.
NHIT1, NHIT2 and NHIT3 record the number of hits on surface qualities 1 (Fresnel reflection), 2 (Lookup table reflection) and 3 (refraction).
YDET,ZDET are the local detector coordinates.
WLENGTH is the wavelength in Angstroms picked up from the surface quality used in reflection/refraction/scattering.
RIRIS, ADJUST, PSAS and PPLANE are the parameter values passed to the SAVERAYS command.
If ADJUST=1 then DSHFT is the axial shift required to get the best focus, YBAR and ZBAR are the mean position of the focused spot in local detector coordinates and RMSRAD is the rms radius of the detected distribution within the RIRIS set.
The following command can be used to produce an image of the detected rays.
Q>show srtsort SRTSORT Sort detected impact positions from ray tracing procedure parameters _NPMM number of pixels across image _PMM pixel size in mm _XCEN centre in mm\0 _YCEN centre in mm\0
This bins up the effective area associated with the rays into a flux or area image. It is assumed that the ray data is held on the structure SRTDATA which is the default used by the command SAVERAYS. The following lines of code indicate how an image can generated and plotted:
nn=450 pix=0.1 hw=nn*pix/2 srtsort(nn,pix,0,0) opendev /xs uselut(6) display(srtimage.data_array,0,0)
The snippet of Q code below will plot np (X,Y) intersection positions of rays from the structure srtdata generated by the SAVERAYS command.
do(1,np,1) if(srtdata.iqu(k)=(-2)) position(srtdata.rpos(1,k),srtdata.rpos(2,k)) else join(srtdata.rpos(1,k),srtdata.rpos(2,k)) endif loop
The subroutines are divided into 2 groups. Those prefixed by TRS_ provide the user interface, prompting for parameters and setting numerical data to define the optical elements. Routines prefixed by SRT_ do the ray tracing and analysis.
The driving routine is SRT_TRC. Within this routine there are two loops. The outer loop is definite and works through the NRAYS which are to be generated by the source. The inner loop is indefinite and traces each ray through the surface elements. The next surface in the sequence is determined by the outcome of encounters with elements and multiple reflections between surfaces are allowed. This inner loop is terminated when the ray is absorbed, detected or finally misses the last element in the sequence.
The subroutine used for a given type of surface is specified by a type index as listed in the table below.
surface form deform limits single/nest code ikon 1 plane open normal cartesian single plna 1 2 plane open normal radial single plna 2 3 plane open radial radial single plna 3 4 plane open radial radial nested plna -n 5 plane closed normal cartesian single plne 1 6 plane closed normal radial single plne 2 7 plane closed radial radial single plne 3 8 plane closed radial radial nested plne -n 9 conic grazing radial axial single cnic 1 10 conic normal axial radial single cnin 1 11 conic normal axial cartesian single cnin 2 12 sphere grazing radial cartesian single sphr 1 13 sphere grazing radial radial single sphr 2 14 sphere normal radial cartesian single sphr 3 15 sphere normal radial radial single sphr 4 16 conic normal azimuthal cartesian single cnin 3 17 plane open normal azimuthal single plna 4 18 plane open normal cartesian grid single plna 6 19 conic grazing radial axial+azimuthal single cnic 2 20 plane closed normal cartesian slat single plna 7 21 sphere pore normal pore multiple sphr+pore 5
Each of these surface types has a subroutine SRT_SUnn associated with it where nn is the type index. These routines call 1 of 6 routines which find the intersection of rays with a plane, sphere, conic or square pore. The pore routine sets up the parameters for 4 plane surfaces which are then serviced by the SRT_PLNE routine.
SRT_PLNA aperture on plane surface SRT_PLNE plane surface SRT_CNIC conic at grazing incidence SRT_CNIN conic at normal incidence SRT_SPHR spherical surface SRT_PORE square pore
The combination of form, deformation, limits and single/nested used in each of these routines is set by the integer argument IKON (see table above). Full details about these configurations and the parameters which they use are given in the comments at the start of the code for each routine.
All the surface parameters etc. are held in a common area. Individual surfaces pick up their parameters using an index into this area. The parameters are set by the following routines:
SRT_SETF set surface parameters used by TRS_MIRROR, TRS_BAFFLE etc. SRT_SETT set surface quality used by TRS_SQUL, TRS_LENS, TRS_PRISM SRT_SETD set deformation parameters used by TRS_DEFS SRT_SETS set source parameters used by TRS_SRCE
The TRS_ routines prompt for parameter values and pack them in sequence into an array. The SRT_SET routines then put the parameters into common. The order of the parameters is important and must match the order expected by the target routine. The sequence of parameters expected is specified in the comment lines at the top of the surface element routines.
All the SRT code is held in a Q directory. On mcp0 this is:
This directory contains a Makefile used to compile the routines, create an object library libsrt.a and install the library in:
All the subroutines are held in source files with names in lower case. The subroutine which services all the Q commands is called Q_SRT in the source file q_srt.f. The SRT code uses a common block declared in the file SRT_COM. Routines which access this common block must use:
In order to introduce a new type of optical element the programmer should check the list of available surface types. For example a spherical mirror at normal incidence using radial limits would be implemented using TYPE=15. If the required surface type exists then the programmer only needs to write a TRS_new routine which prompts the user for parameters and then sets the parameters in common. This is easily done by copying and editing an existing routine such as TRS_MIRROR. The steps required to compose, compile and link are as follows:
1) Go to directory q/srt
2) Write the new TRS_new routine in file trs_new.f. Note down the parameters names required by this routine.
3) Edit a reference to TRS_new into the file q_srt.f. TRS_new must be declared EXTERNAL and included at the bottom of the IF ELSEIF chain. The existing routines referenced in q_srt.f can be used as a template.
4) Edit the Makefile to include trs_new.f in the source file list.
5) Use make to compile the new routine. If successful use make install to shift the new code into the libsrt.a file.
6) Go to directory q/main and use make to compile and link a new version of q. If successful use make install to install the new version of q.
7) Go to directory q/qin and edit a new command into the srt.qin file. This will require reference to the list of parameter names noted in 2) above. You can use an existing command definition like MIRROR as a template.
8) Use make to compile a new version of the q dictionary. If successful use make install to install this new dictionary.
9) Go to directory q/test and write a test procedure to use the new optical element.
If the new optical element is not supported by any existing surface type then a new type must be invented. The programmer must write a new SRT_SUnn routine and modify and existing or produce a new SRT_type routine. A call to the new SRT_SUnn must be included in the inner loop of the srt_trc.f file. The new SRT_SUnn and SR_type routines must be edited into the makefile. Otherwise the process is the same as indicated above.
It is important that the parameters gathered by TRS_new are packed into common in the right order so that the relevant surface routine (SRT_PLNE etc.) access the parameters correctly. The programmer must check this by reading the comment lines at the start of the relevant surface routine.
The routine SRT_SETF is used to push the parameters into common. This has the following interface:
*+SRT_SETF Set surface form and limits parameters SUBROUTINE SRT_SETF(NS,IT,NP,P,IDEF,IQ,IH,IM,ISTAT) IMPLICIT NONE INTEGER NS,IT,NP,IDEF(2),IQ,IH,IM,ISTAT DOUBLE PRECISION P(NP) *NS input surface number (0 for new entry) *IT input surface type *NP input number of parameters *P input array of parameters *IDEF input deformation *IQ input surface quality *IH input hit index (-ve for next in sequence) *IM input miss index (-ve for next in sequence) *ISTAT in/out returned status *-Author Dick Willingale 1996-Dec-6
NS=0 if you want the surface to be allocated the next free index in the sequence. IT is the surface index and determines which SRT_SUnn routine is going to be called in the ray tracing loop. Note that the parameters are held in a double precision array. IDEF and IQ are deformation and surface quality indices that have already be set by DEFORM and SURFACE commands. If IDEF=0 no deformation will be used. If IQ=0 then the surface will act as a stop. IH and IM are used to steer the sequence in the ray tracing. They specify which surface in the sequence should be next depending on whether or not the present surface is hit or missed. In most case IH=-1 and IM=-1. Examples of cases where a more complicated behaviour is required are SRT_PORE and TRS_W1NDT.