51
MPhys Final Year Project Dissertation by Andrew Jackson 1. Introduction Charged particle optics forms an important part of modern physical research, and the simulation of such devices forms an important part of their development. The computational techniques used in the software written to assist the design process can be broken down into two parts. Firstly, the determination of the electric and/or magnetic fields inside the device (via the boundary element [1,11] , finite difference [1,3,4,5] or finite element [1,6,9] methods), and secondly the simulation of the trajectories of charged particles through those fields (via the paraxial approximation [1,5,9] or by direct ray tracing [1,3,4] ). While the existing software is capable of producing reliable and accurate data in most cases, it is generally difficult to use and restrictive in the kinds of behaviour it can simulate. The difficulty for the user arises from the fact that the software usually requires a grid or mesh in order to find the electric and/or magnetic fields, and that this mesh must be completely defined by the user (as opposed to implementing any form of automatic mesh generation). The restriction on the kind of behaviour to be simulated is a consequence of the dependance of most of the software on the paraxial approximation, which while accurate for particle trajectories near the optical axis, cannot simulate the particle motion near the boundaries of the device. This project concerned the development of a user-friendly piece of software designed to allow the finite element solution of the electric field of any rotationally symmetric electrostatic electro-optical device (assisted by semi-automatic mesh generation), and the simulation of the electron trajectories inside the 1 Development of software for the computation of the properties of electrostatic electro-optical devices via both the direct ray tracing and paraxial approximation techniques. Abstract: This project concerns the development of software designed to simulate electro-optical devices; the potential being calculated via the finite element method, and the optical behaviour determined by paraxial and direct ray racing. The direct ray tracing technique, previously only used for finite difference grids, has been developed by using new interpolation techniques (to cope with the variability in mesh point distribution inherent in the finite element technique), and also by testing various different integration algorithms under these conditions. The new software has been found to be act as a useful tool for visualisation of lens behaviour, and has been found to give reasonable quantitative results for the predicted lens properties in comparison to the paraxial approximation and to the results published in the literature for the standardised two-tube electron lens.

Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

MPhys Final Year Project Dissertation by Andrew Jackson

1. IntroductionCharged particle optics forms an important part of modern physical research, and the simulation of

such devices forms an important part of their development. The computational techniques used in the

software written to assist the design process can be broken down into two parts. Firstly, the

determination of the electric and/or magnetic fields inside the device (via the boundary element[1,11],

finite difference[1,3,4,5] or finite element[1,6,9] methods), and secondly the simulation of the trajectories of

charged particles through those fields (via the paraxial approximation[1,5,9] or by direct ray tracing[1,3,4]).

While the existing software is capable of producing reliable and accurate data in most cases, it is

generally difficult to use and restrictive in the kinds of behaviour it can simulate. The difficulty for the

user arises from the fact that the software usually requires a grid or mesh in order to find the electric

and/or magnetic fields, and that this mesh must be completely defined by the user (as opposed to

implementing any form of automatic mesh generation). The restriction on the kind of behaviour to be

simulated is a consequence of the dependance of most of the software on the paraxial approximation,

which while accurate for particle trajectories near the optical axis, cannot simulate the particle motion

near the boundaries of the device.

This project concerned the development of a user-friendly piece of software designed to allow the finite

element solution of the electric field of any rotationally symmetric electrostatic electro-optical device

(assisted by semi-automatic mesh generation), and the simulation of the electron trajectories inside the

1

Development of software for the computation of the properties of electrostatic electro-optical devices via both the direct ray tracing

and paraxial approximation techniques.

Abstract: This project concerns the development of software designed

to simulate electro-optical devices; the potential being calculated via the

finite element method, and the optical behaviour determined by paraxial

and direct ray racing. The direct ray tracing technique, previously only

used for finite difference grids, has been developed by using new

interpolation techniques (to cope with the variability in mesh point

distribution inherent in the finite element technique), and also by testing

various different integration algorithms under these conditions. The

new software has been found to be act as a useful tool for visualisation

of lens behaviour, and has been found to give reasonable quantitative

results for the predicted lens properties in comparison to the paraxial

approximation and to the results published in the literature for the

standardised two-tube electron lens.

Page 2: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

device both under the paraxial approximation and by direct ray tracing. Before this project began a

significant amount of code had already been written, but while the electric field solution and paraxial

ray tracing parts of the code were thought to be working reasonably well, the code designed to carry out

the direct ray tracing was working somewhat inaccurately, leading to the prediction of clearly non-

physical behaviour. Thus, the aim of this project was primarily to re-write the direct ray tracing code to

give more realistic behaviour and more accurate results, and also to check the electric field and paraxial

ray solutions produced by the original code. In order to ascertain the accuracy of the code, results from

the different techniques can be compared with the published results of others, for example the predicted

potential and lensing properties of a standard configuration two-tube electron lens[3,5,11]. Once the direct

ray tracing results have been compared with those of the paraxial approximation and the theoretical and

experimental results of others, then the validity of this implementation of the direct ray technique can

be determined, it’s weaknesses noted and possibilities for further development can be proposed.

2. Theory2.1 Physcial Pr inciples

The software under development concerns only electrostatic devices, and so the field problem reduces

to the solution of the Laplace equation for the electrostatic potential:

Ñ2V = 0 (1)

This simplification, coupled with the rotational symmetry of the devices we wish to investigate, means

that the software needs only to consider the axial plane in order to completely describe the behaviour of

the system. In this way the problem becomes the determination the two-dimensional potential V(r,z),

such that:

(2)

Which is the expanded form of the Laplace equation in cylindrical polar coordinates for the axial plane.The potential is thus defined by the boundary conditions of the system, in other words, by the charged

plates which make up the electrostatic electro-optical device being simulated. Once the potential has

been found, then the electric field is defined by the gradient of the potential:

E = - ÑV (3)

Which for this two-dimensional problem is equivalent to:

(4)

Direct ray tracing can now be carried out by calculating the trajectories of electrons as they move

through the device, their motion being governed by the Lorentz force:

(5)

2

d2V(r,z)

dr2+ 1

rdV(r,z)

dr+

d2V(r,z)

dz2= 0

Er=- dV

drE

z=- dV

dz

ddt

(mv) = eE(r)

Page 3: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

Where the magnetic field component has been neglected. For this two dimensional problem, we find:

(6)

Thus the high accuracy integration of the Newtonian equations of motion of an electron being acted on

by the Lorentz force, with a range of initial conditions (position and velocity), can be used to

investigate the properties of the electro-optical device.

It should be noted that this formulation of the problem is not complete and does place some restrictions

on the kinds of behaviour being simulated. Firstly, the behaviour of a beam of electrons is calculated

by the simulation of single electron trajectories through the electrostatic field, and so this approach

cannot take the space charge effect into account. Fortunately, this effect is only significant for

relatively high charge densities, and electron beams of sufficient concentration only occur in some

electron guns. Secondly, the equations of motion are classical, and so relativistic effects are not taken

into account. However, these effects only become noticable for beam energies greater than 1keV[8, pp 91],

and so we only consider devices which function at energies below this level.

2.2 The Paraxial Approximation

Much of the work on electron optical devices makes use of the concepts and terminology of ray optics,

as these concepts provide a concise way of describing the behaviour of a given device. The basis of ray

optics theory is the paraxial approximation, and added on to this is the theory of aberrations which

accounts for the deviations from first order (paraxial) behaviour.

The paraxial approximation[1,9,7] assumes that the electrons remain close to the optical axis of the lens,

and this allows the variation of the field perpendicular to the optical axis to be simplified. By using this

simplification we find we only need to know the electric field along the optical axis to carry out our

calculations. However, when the electrons are not moving close to the axis, then the basic

approximation begins to fail and aberrations start to form. Although there are various types of

aberration, especially for non-rotationally symmetric devices, for our purposes the most important is

spherical aberration.

Spherical aberration occurs when a change in the angle at which the electron beam enters the lens

causes the focal point of the beam to move along the optical axis. Figure 1 compares the idealised

paraxial approximation behaviour with the behaviour of the more realistic case of spherical aberration

for a plane lens. From this diagram it can be seen that spherical aberration alters the effective focal

length of the lens, forming not a point focus, but a circle of least confusion (or spot). Thus the paraxial

approximation has to be modified in order that spherical aberration may be taken into account. This

3

ddt

(mvr) = eEr(r,z)ddt

(mvz) = eEz(r,z)

Page 4: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

behaviour is best described in terms of an aberration coefficient such that:

Dr = MCs q3 (7)

Where M is the linear magnification, and Dr is the transverse displacement at the paraxial image plane

of a ray which leaves the point object at an angle q to the axis[11]. The scaling factor Cs is known as the

third order aberration coefficient. However, when carrying out direct ray tracing, it is more convenient

to use the form:

zf = zfp - Cs tan2a (8)

Where zfp is the paraxial focal length, and where zf is the focal point and a is the angle of the calculated

electron trajectory as it crosses the optical axis[4]. The fifth order abberation term has been omitted as

this relatively small effect is negligible whilst this piece of software is under development. It should be

noted that the electron optical lenses considered here generally behave more like thick lenses than thin

lenses, and so the focal length and aberration coefficents will depend on whether the rays enter the lens

from the left or right hand side of the lens.

While spherical aberration is by far the most prominent, it should also be noted that two other

aberrations can become significant in some cases. The first is relativistic aberration, where the focal

point moves as a consequence of the relativistic mass of the particle, and the second is chromatic

aberration, where the fact that any charged particle beam will have some variation in the velocities of

each of the particles means that the focal point becomes blurred. Relativistic aberration is significant

only for devices using relatively high potentials, and as noted above, we can ignore these cases and still

produce useful results. Unfortunately, the same cannot generally be said for chromatic aberration,

because for the focussing properties of any device using a small aperture chromatic aberration will

dominate over spherical aberration[12]. However, the effect does not significantly affect the focal

properties of devices using weaker potentials, and so for the time being we ignore the chromatic

aberration in the direct ray calculation.

4

Figure 1: Focussing properties of a plane lens demonstrating (a) idealised paraxial behaviour and (b) spherical abberation, showing theposition of the circle of least confusion, or spot.

(a) (b)object image

lens plane

paraxial focusspot

object imagelens plane

Page 5: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

2.3 Examples of Electro-Optical Devices

The simplest electro-optical device is the two-tube electrostatic electron lens, and numerous examples

of the predicted properties of this standardised form of this device have been published in the past[3,5,11].

The device is composed of two cylindrical electrodes of identical diameter, with a small gap between

them (see figure 2). In order to ensure the device has a standard definition, the parameter for the gap,

g, and for the lengths of the two cylinders, L1 and L2, are all expressed in terms of the lens diameter D.

The properties of the device can then tabulated for a range of g/D, and for a range of potential

differences, V2/V1.

The work of Natali et al[3] provides an excellent example of the high accuracy computation of the

potential, and so can be used to check the finite element code, whereas the papers by Liu & Ximen[5]

and Read et al[11] provide tabulated values for the focal length and spherical abberation coefficients, and

so can be used to check the paraxial and direct ray tracing.

3. Method & DevelopmentAs mentioned in the introduction, a significant amount of code had already been written when this

project began. This meant that much time was spend simply getting used to the code, understanding

the way in which devices are describe and how to use and adapt the user interface. Also, as the main

aim of this project was to improve the direct ray tracing code, only a basic outline of the finite element

and paraxial approximation ray tracing code will be given here. However, the following breakdown of

the various techniques that have been incorporated into the code will follow the structure of the

program and also of it's development.

3.1 Method for the Finite Element Solution of the Electrostatic Potential

When we wish to simulate a device using this software, we must first define the physical space which

the device occupies so that it may be broken up into a finite element mesh, and then define the

potentials that lie along the boundaries of that mesh. First we note that the symmetry of the problem

means that given the rotational axis at r=0, we only need define the problem for r>0, as V(-r,z) must be

equal to V(r,z). From this geometrical basis, the structure of the device is broken down to a set of

nodes, which when entered into the program can be joined up to form a set of (usually quadrilateral)

5

Figure 2: Schematic representation of a simple two-tubeelectrostatic electron lens.

g

D

L L1 2

V V1 2

Page 6: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

polygons covering the domain of the device. Then, an automatic mesh generation program is used to

break each polygon up into a set of triangular elements according to user specified information on how

fine the mesh should be, and on how the mesh within each polygon should be graded (ie whether the

mesh should be uniform of whether it should become finer towards one side or corner).

In order to solve this finite element problem, the potential must be specified along the boundaries of the

mesh. These boundaries fall into one of two catagories, Neumann and Dirichlet. The optical axis (r=0)

represents a Neumann boundary, a where the gradient of the potential across the boundary is known

(due to symmetry, the gradient must be zero). All the other boundaries are Dirichlet boundaries, where

the value of the potential is known. A set of electrodes, each of a given potential, is entered by the

user, along with any gaps (in which the program assumes the potential to be varying linearly with z).

This information, combined with the left and right hand end potentials, completely defines the problem.

The finite element solution then proceeds by the solution of a matrix problem (ie a set of linear

simultaneous equations defined by the mesh and it's boundaries). In order to make the solution of the

matrix problem more efficient, the mesh points are re-numbered so that the matrix becomes tri-diagonal

in form. For more details on the nature of the finite element method, see Kikuchi[10].

Once the potential has been found, the optical properties can be calculated by tracing a set of electrons

thought the potential, from a point electron source with a user specified position, energy and angular

range. This calculation was carried out by the subroutine TRAJEC, and the development of the

program consisted of alterations and modifications to this part of the code (supplied in appendix B).

3.2 Ray Tracing Via The Paraxial Approximation

This part of the code creates a cubic spline of the axial potential for interpolation purposes (subroutine

AXPOT), and then uses this potential V(z) to find for the paraxial trajectories by solving the

differential equation describing the first order properties of the device, as derived from the theory of

Hamiltonian optics (in AXPATHS). The exact form of this approach in not considered here (see refs.[1,4,5,9,12]), and it is sufficient simply to note that the paraxial approximation plots the calculated

trajectories on a plot of the lens, and reports the focal point position to the user, along with the third

order spherical and first order chromatic aberration coefficients (PARAXABBERS, ABBERS)

3.3 Direct Ray Tracing

While the finite difference and paraxial approximation code have undergone no development during

this project, the direct ray tracing code (controlled by the PATHS routine) has been altered many times,

with many different algorithms being tested. The direct ray tracing calculation breaks down into three

main tasks. The accurate interpolation of the finite element mesh, the differentiation of the potential to

6

Page 7: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

find the electric field, and the integration of the equations of motion of the electron. The following

three sections addresses each of these tasks by explaining the initial state of the code, and then covering

the other techniques which have been implemented.

3.3.1 Interpolation of the potential mesh:

In order to solve the equations of motion for the electron in this electrostatic potential, it is necessary to

be able to calculate the potential at any point, V(z,r), in other words to find the value of the potential by

interpolation inside each mesh element. While this poses no problem in a finite difference calculation

(where the mesh points follow a simple geometrical form, eg cartesian, for which high accuracy

interpolation is well understood[1,3,4,5]), the finite element method can allow any arrangement of mesh

points, and so while it is more flexible in terms of the kinds of device geometry it can accurately

represent, it requires that the interpolation technique is equally as flexible. It should be noted that of all

the published work that has been examined, none have used direct ray tracing in combination with the

finite element approach, presumably because of the difficulties in creating an accurate interpolation

algorithm.

3.3.1.1 Nearest Neighbour Averaged Linear Interpolation:

This technique uses the routine FINDEL to find the reference number of the element at the current

point, and the uses FINDNN to find the reference numbers of the three neighbouring elements. The

geometrical centres of each of the neighbouring elements can then be determined, and the value of the

potential at the three elements centres calculated by linear interpolation of the values of the potential at

the three nodes of each element (using LINPOT). The way in which this is done refers back to the

roots of the finite element method (by expressing the geometrical centre of each element in terms of

areal coordinates), and is equivalent to fitting a plane to each of the elements nodes (in z,r,V space) and

then using this plane to find the value of V at the midpoint. The three sets of (z,r,V) coordinates for the

cell centres are then expressed as another plane, and this can then be used to find the electric field. The

main problem with this method is that it uses a very simple linear approximation over a relatively wide

physical range, and so can miss the finer details of the shape of the potential surface.

3.3.1.2 Linear Interpolation:

This approach is closely related to the nearest neighbour averaging algorithm above, but much

simplified. Instead of averaging the potential over the three nearest neighbour elements, it simply takes

the linear interpolation of the three nodes of the currently occupied element. This means that the

potential being used is exactly that which was calculated by the finite element method, and while it take

no account of the general form of the potential in the region surrounding the current element, and so is

not a particularly accurate approach, it does have the advantage of simplicity, and of forming a reliable

7

Page 8: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

base on which more complex techniques can be developed.

3.3.1.3 Localised Nth Order Spline:

This technique attempts to better describe the potential surface by fitting a non-linear spline it's form as

opposed to using a linear approximation. The technique is related to the Chebyshev algorithm (see

Press et al[2]), except that the spline is fitted locally to the point at which we require to know the

potential (as opposed to a set of splines over the whole domain), and that it must work in two

dimensions. Each spline has the form:

y = an+1xn + anxn-1 + an-1xn-2 + ... + a2x + a1 (9)

And so clearly an nth order spline required n+1 coefficients (ai) in order for it to be properly defined,

and so we need n+1 data points (xi,yi) in order to form the n+1 linear simultaneous equations required

to find the set of coefficients ai). This straightforward concept is complicated by the two-dimensional

nature of the problem in that in order to fit a nth order spline surface to the potential we need enough

sets of n+1 points to create at least two splines. For this problem two sets have been used, one parallel

to the z axis, and one parallel to the r axis (using these two perpendicular splines not only improves the

accuracy of the interpolated potential surface, but also assists the differentiation of the surface to find

the electric field). This concept is illustrated in figure 3 below:

In order for this approach the work, the code must find the appropriate length scales to fit the splines

over, and this must take into account of the variation of element size in the positive and negative z and r

directions. This is achieved by finding the relative positions of the centres of the nearest neighbour

elements (using FINDNN and FINDELCENT), and then finding the overall z/r span of this set of

spatial vectors in both the positive and negative directions. These span lengths are then scaled

according to the order of the approximation so that enough different elements will be covered to supply

enough different information to make the approximation meaningful, although the best value for the

scaling parameter is by no means immediately apparent. The n+1 points are distributed over these z/r

ranges, and then LINPOT is then used to find the potential at these 2(n+1) points (note that this means

LINPOT now has to call FINDEL as the 2(n+1) point are not necessarily inside the current element).

8

Figure 3: Schematic example of averaging two perpendicular cubic splines for the purpose of two dimensional interpolation.

Spatial coordinate

Potential

InterpolatedvalueÞ

Page 9: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

This method also requires that no spline points lie outside the boundary of the finite element mesh,

where the potential is undefined, and so the code must also find the maximum spline in the positive and

negative z and r directions and make sure the interpolation splines fit within these maximum values

(MinSplin). The only exception to this is the case of interpolation near the rotational axis, where the

spline must be allowed to fall outside the mesh (ie into negative r values) by using the fact that V(-r,z)

is equal to V(r,z).

The computational solution proceeds as follows. The subroutine MeshSpline uses FINDEL to find the

element at the current point, then uses FINDNN to find it's nearest neighbours, and then uses

FINDELCENT to calculate the centres of these cells. This data is then used to construct the

characteristic cell dimensions in the positive and negative z and r directions (Zmax, Zmin & Rmax,

Rmin). These characteristic lengths are then modified such that they cover a sufficiently large spatial

range, using the expressions:

Zmin := nthsc × (n+1) × Zmin

Zmax := nthsc × (n+1) × Zmax

Rmin := nthsc × (n+1) × Rmin

Rmax := nthsc × (n+1) × Rmax

Where nthsc is the scaling parameter mentioned above. Once a set of spline lengths have been found,

the code calls MinSplin, which returns the largest allowed values of Zmax, Zmin, Rmax and Rmin as

defined by the boundary conditions for the current point. These two sets of values are then compared,

and the spline lengths are made to fit the boundaries of the device where necessary.

The process continues by breaking the spline lengths down into n+1 evenly spaced point (z1 - zn+1 and r1

- rn+1), and using LINPOT to find the values of the potential at these points (ie Vi(zi,r) and Vi(z,ri)).

These two sets of data are then passed to the routine nthapprox, which uses a fully-pivoting Gauss-

Jordan matrix routine (from Press et al[2]) to solve for the spline coefficients for each set of data. Once

the coefficients have been found, nthaeval can be used to evaluate the approximation to the potential

for any point z,r in the region of the spline.

3.3.1.4 Localised Nth Order Least-Squares Fit Polynomial:

This fourth technique is closely related to the localised spline calculation, and differs only on the fact

that instead of using n+1 points to find an nth order spline to approximate the potential surface, it uses

2n points and fits a least squares polynomial to potential data. As this technique uses more data from

the mesh to form the same order of interpolation over the same spatial area, the form of the polynomial

should more closely approximate the potential surface. The routine used to perform this approximation

is SVDFIT (from Press et al[2]) which replaces my own nthapprox routine, and has the advantage of

9

Page 10: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

using single value decomposition as opposed to Gauss-Jordan elimination (which can cope better with

extreme cases such as near singular matricies).

In order to find out which of the above methods of interpolation performs the best, the code can be

made to produce a interpolated version of the axial potential, and then this can be compared with the

potential on each of the nodes along the axis. If the interpolation is working well, the form of the

interpolated potential curve should be smooth, and should agree with the potential from the finite

element calculation at each node. In this way it should be possible to determine which approach works

the best, and in the case of the latter two to find the optimum values for the order of the interpolation

(n) and the scaling parameter (nthsc).

It should be noted here that during the development of the program, some of the most basic routines,

which existed before this project began, were found to be working incorrectly. Firstly, the routine to

identify the element whose area includes a given point r,z, FINDEL, was searching the element array

incorrectly, and somtimes assumed a point to be outside the finite element domain when this was not

the case. Also, the routine designed to find the nearest neighbour elements (FINDNN) was failing, and

returning invalid element reference numbers. Both these faults have bee corrected. Also, the optimum

element numbering for the finite element solution need not correspond the the spatial arrangement of

the cells, but FINDEL works more quickly when the reference numbers of the cells are arranged so that

they correspond to the spatial order, and so the code runs much faster if the elements have been sorted

according to their position. Before the project began, a very basic sorting was being used (taking tens

of seconds to sort the mesh data), and during the codes development this routine has been replaced by

QuickSort from Press et al[2], with the consequence that the sorting process is now at least one order of

magnitude faster than before.

3.3.2 Calculation of the Electr ic Field:

Given the potential in it's interpolated form, we need to find the derivative of the potential at the current

point, in other words the electric field (Ez, Er), in order to integrate the equations of motion of the

electron. Two different schemes were compared for this calculation.

3.3.2.1 Linear Surface Gradient:

This technique was applied to both the linear interpolation technique results, and is the original routine

from the code before this project began. When called, the routine GRAD takes the plane formed by the

interpolation code and returns the gradient of the plane in the z and r directions as the values for the

electric field. The main drawback of this approach is that as the interpolation uses the same single

linear approximation for each element, then no matter where the electron lies in that element the

10

Page 11: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

electric field will be found to be the same. In other words, this technique cannot take the general form

of the potential into account, and so it can be expected to perform badly when it comes to finding the

derivative of the potential.

3.3.2.2 Nth order polynomial derivative:

In the case of the two nth order polynomial interpolation routines, the derivative of the potential at the

current point can be calculated by direct differentiation of equation (9) such that:

dy/dx = n an+1xn-1 + (n-1) anxn-2 + (n-2) an-1xn-3 + ... + 2a3x + a2 (10)

As the interpolation routine takes a broad physical range into account, this approach should form a

better approximation to the form of the potential and so form a much more accurate representation of

the electric field than the linear gradient approach.

The validity of these routines can be checked in a similar way to the interpolation. Instead of plotting

V as a function of z, the two derivatives Ez and Er can be plotted as a function of z and r respectively

for any arbitrary trajectory through the device. Although there is no exact form of the electric field

with which we can compare these results, as there was with the interpolation check, we can still use

these plots to check that the calculated electric field is varying smoothly and consistently. Also, if the

results of the tests of the different interpolation are inconclusive as to which is better, then the more

challenging differentiation check can be used.

3.3.3 Integration of the equations of motion

Whilst the details of the different integration routines vary, the general structure of the integration does

not. Each is designed to solve a set of N first-order differential equations, and so in order to solve the

problem the equations of motion (6) are re-expressed to form a set of four coupled first order

differential equations:

dvz = e Ez dz = vz (11)

dt m dt

and

dvr = e Er dr = vr (12)

dt m dt

The integration routine, when called from PATHS, calculates the change in velocity and position for

one time step, h, and the DERIVS routine supplies the values of the electric field and velocity at the

current position (using one of the sets of interpolation and differentiation routines outlined previously).

The new point of the trajectory is then stored and plotted on the screen.

11

Page 12: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

For this process to work at all, it is necessary to know what value of h would be reasonable for the

integration, and this cannot be set arbitrarily because the potential of the system (and so the velocities

involved) can differ greatly between devices. To get around this problem, PATHS looks at the

potentials on the plates and uses this to estimate the speed of an electron moving through the device

along the axis. This is then used as the basis for the estimation of the required timestep. The different

integration algorithms that have been implemented are as follows:

3.3.3.1 Adaptive Runge-Kutta

This routine, taken from Press et al[2], takes the fourth order Runge-Kutta routine (see 3.3.3.3 below),

and modifies it's implementation such that the time step, h, can be altered during the course of the

integration. In this way many small steps can be used to tiptoe through the quickly varying parts of the

potential, and a few much larger steps employed to cover the smoother areas, thus making the process

more time-efficient. However, this routine was suspected not to be working correctly, and so was

replaced with a somewhat simpler method.

3.3.3.2 Simple Euler Integration

This routine is extreme easy to implement, and represents the simplest possible method of integration,

where equations of the form:

dx/dt = f(x)

are solved using

Dx = Dt f(x)

expressed in the program as:

xn+1 = xn + h f(x)

While this routine is not particularly accurate (error ~ h2), and occasionally unstable, it has the

advantage of being almost impossible to implement wrongly. In this way, the possible failure of the

adaptive Runge-Kutta algorithm can be checked.

3.3.3.3 Runge-Kutta

The Runge-Kutta algorithm is based of the principle of taking set of Euler type steps, and then using

the information obtained to fit a Taylor expansion up to some higher order. The routine RK4 (from

Press et al[2] used here represents the form of this technique when four Euler steps are taken, leading to

a Taylor approximation with an error of the order of h5. While this technique represents a great

increase in accuracy over the Euler approach, a simple way to improve it is by using extrapolation.

12

Page 13: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

3.3.3.4 Extrapolative Runge-Kutta

This technique, taken from Hawkes & Kasper[1], increases the accuracy of the Runge-Kutta routine by

means of an extrapolation of the form:

xn+1 = x(2)n+1 + 1/15 (x(2)

n+1 - x(1)n+1)

where x(1)n+1 represents the results of a single Runge-Kutta step over an interval h, and where x(2)

n+1

represents the results obtained by using two steps of interval h/2. The main draw back is that the Runge-

Kutta routine needs to evaluate the electric field four times, and so the extrapolating algorithm requires

16 evaluations per time step. This can lead to a rather slow integration process when, as in this case,

the value of the electric field requires quite a degree of computation. Because of this the structure of

the code was changed so that instead of constructing a new interpolation for the mesh every time the

DERVIS routine is called, the interpolation is only constructed for every time step. This makes the

assumption that the form of the potential does not change significantly over the distance covered in the

time interval h, and as this is required to be true in order for the integration to work accurately anyway,

this assumption perfectly reasonable.

3.3.3.5 Hamming Predictor-Corrector

This multistep algorithm (also from Hawkes & Kasper[1], and similar to that used by Natali et al[3])

differs from the previous routines in that instead of using only the current point to predict the next point

via Euler type steps, the new point is calculated by forming an appropriate linear combination of the

preceeding ones. Since this can be done in different ways, it automatically provides an accuracy

control, Whereas all of the other routines tend to propagate and accumilate errors as the integration

proceeds. The Hamming algorithm breaks down into two parts, the predictor (which uses the previous

four positions to predict the next one), and the corredtor (which corrects the predicted position by using

information supplied by the DERIVS routine). The accuracy check comes from comparing the

predicted and corrected results, such that the time step is halved if the accuracy falls below some user

defined level (errs), and doubled if the accuracy is significantly better than errs (two hundred times

better in this particular case). While this changing time step should mean that the code works

efficiently and accuratly, the code does have the drawback that it is not self-starting, requiring four

Runge-Kutta steps to be carried out before it can be used, and also for restarting the algorithm when the

time step is altered (as the stored points correspond to the old time step). From Natali et al[3], this

drawback should lead to an error of only 0.01%.

Clearly, the extrapolative Runge-Kutta will perform better than the Euler and basic Runge-Kutta

routines, and so the question that remains is whether the Adaptive Runge-Kutta, the Extrapolative

Runge-Kutta or the Hamming Predictor corrector is the most accurate. This can be ascertained firstly

be simply checking that the electron trajectories have a single, well defined focal point for rays near the

13

Page 14: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

axis, and also by checking that at higher angles the focal point follows the expected form due to

spherical aberration. As well as this, we know that the potential and particle form a energetically

closed system, and so if we add together the potential energy for the electron at it's current position and

it's kinetic energy, then we can check whether this figure is constant, as it should be. This technique

can also be used to investigate the quality of the interpolation and differentation algorithms.

3.4 Calculation of Lens Proper ties:

As the electron trajectories are calculated, part of the PATHS routine checks whether the last step has

caused the electron to cross the optical axis, in other words to see if the focal point has been calculated.

Using this condition the routine then stores the focal point (zf) and the slope of the ray (tan(a)) in an

array, which can then be used to calculate the paraxial focus (zfp) and the third-order spherical

aberration coefficient (Cs) using equation 8. This is achieved by the FINELABBERS routine by using

the SVDFIT least-square algorithm to finding the coefficients of a polynomial of the form:

y = a2x2 + a1

Where x corresponds to the slope tan(a), y corresponds to the direct ray focal point zf, and a1 and a2

correspond to the paraxial focus and the aberration coefficient respectively. When the coefficients have

been found they are printed to the screen, along with an estimate of the error in each figure (calculated

by SVDVAR, another routine from Press et al[2]). Unlike the paraxial routine, the direct ray calculation

only returns the value of the spherical aberration when it is actually affecting the focal length, and the

quality of the fit depends on the number of trajectories that have been calculated.

14

Page 15: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

4. Results & Discussion4.1 Validation Of The Finite Element Potential

The axial potential of a standardised two-tube electrostatic electron lens was compared with the

published results of Natali et al[3]. As the published data consists of tabulated potential values (for one

half of the electron lens), the finite element mesh was defined such that the points on the axis for the

mesh match up with the tabulated values (Appendix A.1 shows the finite element mesh used). The

tabulated values are presented below, along with a graph of the axial potential from both tables, with

the present result plotted as points and the previous paper's potential plotted as a line (figure 4). Just by

visual comparison the two results clearly agree, and analysis of the tabulated data has shown that the

difference between the two calculations was only 0.02%. On the basis of this evidence, the finite

element potential calculation is seen to be working well.

15

z/D Electrostatic Potential

Present results Natali et al0.00000000 0.50000000 0.50000000

0.02500000 0.46714915 0.46711500

0.05000000 0.43459568 0.43453200

0.07500000 0.40262572 0.40253800

0.10000000 0.37150388 0.37139900

0.12500000 0.34146465 0.34135100

0.15000000 0.31270599 0.31259200

0.17500000 0.28538560 0.28527900

0.20000000 0.25961956 0.25952800

0.22500000 0.23548332 0.23541300

0.25000000 0.21301910 0.21296900

0.30000000 0.17307084 0.17307900

0.35000000 0.13948118 0.13956600

0.40000000 0.11168299 0.11185100

0.45000000 0.08895959 0.08921200

0.50000000 0.07055776 0.07089700

0.60000000 0.04412242 0.04443600

0.70000000 0.02741136 0.02767600

0.80000000 0.01697056 0.01717800

0.90000000 0.01048736 0.01064200

1.00000000 0.00647471 0.00658600

1.10000000 0.00399538 0.00407400

1.20000000 0.00246481 0.00251600

1.30000000 0.00152037 0.00155700

1.40000000 0.00093774 0.00096200

1.50000000 0.00057837 0.00059500

1.60000000 0.00035671 0.00036800

1.70000000 0.00022000 0.00022700

1.80000000 0.00013568 0.00014100

1.90000000 0.00008368 0.00008700

2.00000000 0.00005161 0.00005400

2.10000000 0.00003183 0.00003300

2.20000000 0.00001963 0.00002000

2.30000000 0.00001211 0.00001300

2.40000000 0.00000747 0.00000800

2.50000000 0.00000461 0.00000500

Figure 4: Comparison of the present results with those of Natali et al[3].

0

0.1

0.5

0 0.5 1 1.5 2 2.5

Data from Natali et alFinite Element Result

Page 16: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

4.2 Analyis And Development Of The Direct Ray Tracing Approach

All the following results were taken for the same thin lens as that used by Liu & Ximen[5] (the form of

the finite mesh used to describe it is supplied in appendix A.2).

4.2.1 Interpolation Of The Axial Potential From The Finite Element Mesh

The first test carried out on the interpolation was to check that the interpolated axial potential agreed

with the values of the potential on the finite element nodes along the axis. Figure 5 compares the four

interpolation techniques against the node potential.

Unfortunately, these results give no clear evidence of any one routine performing any better than any of

the others, all of them agreeing reasonably with the finite element node potentials. This being the case,

the differential of the potential must be examined in order to determine which between of the

techniques is the best.

16

Figure 5: Comparison of the axial potential for the four methods of interpolation with the nodal potential from the finite element calculation.

0

0.2

0.4

0.6

0.8

1

1.2

0 0.05 0.1 0.15 0.2

Nearest Neighbour Linear InterpolationNodal Potential

0

0.2

0.4

0.6

0.8

1

1.2

0 0.05 0.1 0.15 0.2

Cubic Least-Squares Polynomial InterpolationNodal Potential

0

0.2

0.4

0.6

0.8

1

1.2

0 0.05 0.1 0.15 0.2

Cubic Spline InterpolationNodal Potential

0

0.2

0.4

0.6

0.8

1

1.2

0 0.05 0.1 0.15 0.2

Linear InterpolationNodal Potential

Page 17: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

4.2.2 Differentiation Of The Electrostatic Potential

Figure 6 presents the z component of the electric field for the two linear interpolation techniques, and

figures 7 and 8 compare the same quantity calculated by the spline and least-squares approaches

respectively. For these latter two, the left-hand plot corresponds to linear interpolation, the middle plot

to quadratic and the right-hand plot to cubic interpolation. For each of these a range of scaling factors

are compared (nthsc = 1, 2, 3).

17

Figure 6: Plots of Ez as calculated by the nearest neighbour and single element linear interpolation.

0

20

40

60

80

100

120

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

NN Linear

0

20

40

60

80

100

120

140

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

Linear element technique

Figure 7: Comparison of the spline interpolation routines for linear, quadratic and cubic splines left to right. Each diagram compares the results from using a scaling factor of 1, 2 and 3.

0

20

40

60

80

100

120

140

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

nthsc = 1nthsc = 2nthsc = 3

0

20

40

60

80

100

120

140

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

nthsc = 1nthsc = 2nthsc = 3

0

20

40

60

80

100

120

140

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

nthsc = 1nthsc = 2nthsc = 3

Figure 8: Comparison of the least-squares polynomial interpolation routines for linear, quadratic and cubic splines left to right. Each diagram compares the results from using a scaling factor of 1, 2 and 3.

0

20

40

60

80

100

120

140

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

nthsc = 1nthsc = 2nthsc = 3

0

20

40

60

80

100

120

140

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

nthsc = 1nthsc = 2nthsc = 3

-20

0

20

40

60

80

100

120

140

0.08 0.085 0.09 0.095 0.1 0.105 0.11 0.115 0.12

nthsc = 1nthsc = 2nthsc = 3

Page 18: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

Both of the linear interpolation techniques can clearly be seen to form a poor approximation to the

electric field, and closer inspection of the results in figures 7 and 8 (by checking which best conserves

the total energy of the potential and the electron) has shown that the least-squares cubic approximation

forms the smoothst interpolation, whilst also being least dependant on the scaling factor. This means

that the technique should be able to cope better with the different variations in any finite element mesh

it is applied to. The routine was refined by searching for the value for the scaling factor which

minimised the error in the total energy for a ray passing through the lens, and this investigation found

that the best value of the scaling factor for the cubic interpolation is nthsc = 1.75 (which correspond

energy being conserved with 0.01% accuracy.

4.2.3 Integration Of The Equations Of Motion

When the Adaptive Runge-Kutta routine was removed, and then replaced with the theoretically less

accurate Euler routine, there was an immediate improvement in the quality of the results. This apparent

paradox occurred because while the Adaptive Runge-Kutta works well with most smoothly varying

data, it appeared to be unable to cope with data that has a very small degree of variation. After

discovering this, the Euler alrogithm was replace with the fourth order Runge-Kutta routine, and then

with the extrapolative Runge-Kutta, with the accuracy of the results improving along the way.

However, it was not immediately apparent whether the Hamming Predictor-Corrector or the

extrapolative Runge-Kutta was giving the best results, and this section deals with the differentiation

between the quality of these two routines.

The extrapolative Runge-Kutta routine was tested by calculating the error in the total energy for a

single ray passing through the lens at a fixed angle (1° to the optical axis, starting on the axis at the left-

hand side of the device) for a range of values for the time step. The time step was altered by taking the

estimated time step value and multiplying it by an constant less than or equal to 1.0. In the case of the

Hamming predictor corrector routine, the same calculation was carried out using the best time step

from the Runge-Kutta results as the initial time step and then setting the error parameter (errs) to a

range of values to see how it affected the results. The data from these tests is presented in the table

overleaf.

18

Page 19: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

The result for the extrapolative Runge-Kutta routine is as would be expected for any single step

algorithm. While decreasing the time step initially decreases the error in the results, for very small time

steps the accumulated errors begin to become significant, and so the accuracy of the integration

decreases. The balance between these two types of behaviour is therefore found to occur at a time step

factor value of 0.5, and so this value gives the best results for the Runge-Kutta integration. This figure

was then used to find the initial time-step for the Hamming routine.

The behaviour of the Hamming routine can be explained in terms of the accuracy factor (errs) as

follows. For the larger values of the accuracy factor (errs = 1.0e-2 - 1.0e-5), the initial time step is

sufficient to satisfy the error criterion, but as it is decreased furthur the routine has to change the time-

step in order to satisfy the same accuracy condition. Unfortunately, when this happens the Hamming

code has to be restarted with the extrapolative Runge-Kutta, and this causes errors to form in the results

(especially if the time step is changing rapidly, in which case the Runge-Kutta accumulates errors as

before). However, in this region, the calculated error is approximately constant for the different values

of errs, which implies that while the Hamming code is less accurate than an extrapolative Runge-Kutta

routine with an optimised time step, it is more consistently accurate than the Runge-Kutta for a range of

accuracy conditions. This means that the Hamming code is more flexible and so more likely to work

well for different problems, where the optimum time step may differ from the value found here.

The only drawback is that while the Runge-Kutta is always reasonable quick (~ 20-30s per ray), the

Hamming code slows down as the accuracy criterion starts to work, and so when a device is being

simulated it is best to start with errs ~ 1.0e-4 (to get a rough estimate of lens behaviour) and then

change this to errs ~ 1.0e-9 when more accuracy is required. Although the accuracy factor can be set

higher than this, the code starts to run very slow indeed (~ 2-3 minutes per ray) and there is very little

increase in accuracy (due to the Runge-Kutta/Hamming interface).

19

Runge-Kutta Hamming Precitor-Corrector

Time Step × Energy Error Accuracy Factor Energy Error

1.000 1.166e-02 1.0e-02 7.481e-05

0.550 4.735e-04 1.0e-03 7.460e-05

0.525 1.974e-04 1.0e-04 7.434e-05

0.500 7.439e-05 1.0e-05 7.439e-05

0.475 1.942e-04 1.0e-06 1.661e-03

0.450 1.339e-04 1.0e-07 1.401e-03

0.400 2.735e-04 1.0e-08 1.212e-03

0.300 2.570e-03 1.0e-09 8.180e-04

0.200 1.206e-03 1.0e-10 8.219e-04

0.100 9.000e-03 1.0e-11 8.138e-04

0.050 1.038e-03 1.0e-12 8.111e-04

Page 20: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

4.3 Example Ray Diagrams For The Different Techniques

The overall ray diagram results from various techniques are presented here for direct visual

comparison. Figure 9 shows the ray diagram for a simple two-tube electron lens as calculated by the

paraxial approximation, and figures 10 and 11 compare the results for the same lens as calculated by

the direct ray tracing code before this project began with the results the code now produces.

20

Figure 9: Ray diagram for a simple two-tube electron lens as calculated by the paraxial approximation.

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

0 2 4 6 8 10 12 14 16 18 20

Figure 10: Ray diagram for a simple two-tube electron lens as calculated by the direct ray tracing code before this project began.

-0.01

-0.008

-0.006

-0.004

-0.002

0

0.002

0.004

0.006

0.008

0.01

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2

Figure 11: Ray diagram for a simple two-tube electron lens as calculated by the new direct ray trading algorithm.

-0.01

-0.005

0

0.005

0.01

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22

Page 21: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

The non-physical behaviour of the old code has been eliminated from the direct ray tracing code to the

point that the ray diagrams now agree with the paraxial ray diagrams for low angle rays. Moreover, the

effect of spherical aberration is now clear, with the direct ray focus moving inward from the paraxial

focal point as the angle increases. The degree of agreement between the paraxial and direct ray tracing

will be examined further in the next section.

4.4 Compar ison With Published Data For The Two-Tube Electron Lens

The table below gives the results from a series of simulations of the standardised two-tube electron lens

(with g/D = 0.1) for a range of voltage ratios. The paraxial focus and third order spherical aberration

coefficients from the direct ray calculation are compared with those from the paraxial approximation

code and the published results of Liu & Ximen[5]. The direct ray calculations were carried out using the

Hamming PC code (errs = 0.1e-6) and the mesh interpolation performed by the cubic least-squares

approximation (nthsc = 1.75).

Examining the progression in the focal point with increasing voltage ratio, it appears that while the

direct raytracing code works well at lower voltage ratios, as that ratio increases the accuracy of the

code decreases. This is because the more rapidly changing electric field is more difficult to describe

accurately, and so greater errors are made by the approximation which are then carried through into the

integration. The reason for the discrepancy between the paraxial approximation and the published

results is unknown, as the details of the paraxial algorithm have not been studied here. However, the

paraxial approximation consistently gives a reasonable approximation to the published results.

The direct calculation of the third-order aberration coefficient is somewhat more troublesome. This is

mainly because the direct technique requires a number of rays to be simulated where the effect of the

aberration is fairly pronounced (due to the errors in the ray tracing process), and so when the aberration

is small, it becomes more difficult to get the simulation to actually display spherical aberration

behaviour so that it can be calculated. The discrepancy between the published results and the results of

both the paraxial and direct ray tracing code is of unknown origin, but the fact that the paraxial code

and direct code approximately agree (coupled with the consistently reasonable behaviour of these

methods for all the other results) implies that the published results may be incorrect for this particular

lens definition.

21

f Cs

V1/V2 Direct Paraxial Published Direct Paraxial Published

5 2.4561 2.4414 2.465 1308.03 1194.20 57.83

10 1.1770 1.1661 1.179 11.7703 15.11 10.10

20 0.6426 0.6314 0.630 8.3571 4.88 3.511

40 0.3332 0.3218 0.319 4.7209 1.96 1.922

Page 22: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

5. ConclusionsThe primary aim of this project was to improved the direct ray tracing code to the point that it's

predictions are useful, and this has been achieved. While the paraxial approximation generally tends to

gives more accurate results in any given situation, the ray diagrams produced do not show exactly what

is happening whereas the direct ray tracing approach vividly illustrates the effect of spherical aberration

on the focal properties of a device. For this reason I believe the approach is of great use in terms of

device design by allowing the user to see roughly how significant the spherical aberration is and to get

an idea of the general behaviour of the lens. Also, the finite element solution for the potential has been

show to be good (although recent work suggests there may be advantages in using the more complex

second order finite element method[6]), and the paraxial approximation code shown to work to

consistently reasonable accuracy.

The most important development in this project has been the successful interpolation of a two-

dimensional finite element mesh, which to my knowledge has not been achieved before (at least in the

field of electro-optics). Previous direct ray tracing software has used a set of cartesian mesh points for

which high accuracy interpolation is elementary, at the cost of restricting the types of device geometry

that can be described. The new code uses the more flexible finite element approach, and the

interpolation is flexible enough to cope with awkward arrangements of elements, for example when

moving into the gap of a two-tube lens, where the size of the elements changes rapidly.

In my opinion, the integration code is the main cause of the remaining errors in the direct ray

simulation, and can be improved in a number of ways. The inaccuracies in the Hamming predictor-

corrector routine are mainly a consequence of the need for the code to be restarted with the Runge-

Kutta routine every time the time step is halved or doubled, and this could possibly be rectified by

using the more complex HPCD algorithm[1]. This version of the Hamming code gets around the

problem of restarting the predictor-corrector by storing a greater number of the previous points, and

then using this data to find the appropriate set of previous points for the halved/doubled time step by

rearrangement and interpolation of the stored points.

For more accurate results still, there are a number of ways in which the interpolation might be

improved. Firstly, only polynomials up to third order have been investigated, and quartic or quintic

interpolation may well produce even better results (at the cost of slowing down the integration process,

as a matrix of 2n × n elements must be solved). Secondly, the accuracy of the current interpolation was

improved by finding the scaling factor which most successfully conserved total energy, but the best

scaling factor will change a little for different mesh geometries, and so higher accuracy might be

obtained by making the code automatically search for the best scaling factor via the total energy

condition (although this will slow the integration down).

22

Page 23: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

This automated total energy check leads naturally to a new approach to the ray tracing problem.

Instead of integrating the equations of motion of an electron whilst monitoring it's progress via a total

energy check, the code could use the conservation of energy principle more directly via the principle of

least action. The integration would be broken up into a set of small time steps (as before) and then the

movement of the electron from one point to the next would be achieved by finding the speed and angle

(and thus the kinetic and potential energy at the end of the interval) which gave the minimum action for

that step, perhaps by Monte Carlo methods. This would naturally lead to the path of least action

through the lens for an electron with a particular set of initial conditions, and has the advantage that the

derivative of the potential is not required. This means that the accuracy of the simulation would be

more directly defined by the quality of the finite element mesh. As this represents a significant

departure from the technique used in the current program, there was not enough time to investigate this

possibility. However, in my opinion this could form an interesting source of future research.

6. References

[1] Hawkes P.W. & Kasper E. (1989) Principles Of Electron Optics, Volume 1 (Academic Press).

[2] Press W.H. et al (1992) Numerical Recipes in FORTRAN, 2nd Ed (Cambridge).

[3] Natali S. Chio D.Di Kuyatt C.E. (1971) Accurate Calculations of Properties of the Two-Tube Electrostatic Lens.I. Improved Digital Methods for the Precise Calculation of Electric Field and Trajectories (Journal of research of the National Bureau of Standards, 76A, no. 1, pp 27-35).

[4] Munro E. (1990) Numerical modelling of electron and ion optics on personal computers (Journal of Vacuum Science Technology, 8B, no.6, pp 1657-1665).

[5] Liu Z. & Ximen J. (1993) Numerical analysis of higher-order geometrical aberrations for a two-tube electrostatic lens (Journal of Applied Physics, 74, no. 10, pp 5946-5950).

[6] Zhu X. & Munro E. (1995) Second-order finite element method and its practical application in charged particle optics (Journal of Microscopy, 179, pt. 2, August, pp 170-180).

[7] Hecht E. (1987) Optics, 2nd edition (Addison-Wesley).

[8] Sturrock P. A. (1955) Static & Dynamic Electron Optics (Cambridge).

[9] Munro E. (1975) A Set Of Computer Programs For Calculating The Properties Of Electron Lenses (Engineering Department, University of Cambridge ref: CUED/B- Elect TR45).

[10] Kikuchi M. (1986) Finite Element Methods In Mechanics (Cambridge).

[11] Liu Z. & Ximen J. (1992) - (Journal of Applied Physics E, 72, pp 28).

23

Page 24: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

Appendix A: The Finite Element MeshesA.1 Finite Element Mesh Used For Compar ison With Natali Et Al[3]:

A.2 Finite Element Mesh Used For Compar ison With L iu & Ximen:

24

Page 25: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

Appendix B: The Ray Tracing Code: TRAJEC.FOR:$not st r i ct$not r uncat e

SUBROUTI NE TRAJECC Pr ogr amme t o r ead i n dat a cr eat ed by BUI LD and cal cul at e t he pat hs,C Ver si on 6. 1 MP 24. 10. 96CC The f i l e cour b. f on must be pr esent i n t he envi r onment set by DOS

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ gr acol . def ’$i ncl ude: ‘ t r aj ec. def ’

I NTEGER X, Y, STAT, TRAJCODE REAL EE, L, VP LOGI CAL OVLY, PLOT REAL* 8 SLOPE

X = 1 Y = 3 STAT = 0 DATA X00, Y00, NRAYS, THETA1, THETA2/ 0. 05, 0. 0, 5, 0. 2, 1. 0/ TRAJED = . FALSE. TRAJCODE = 0 EE = 0. 0 I F ( EE. GT. 0. 0) THEN VP = SQRT( 2* EE* EMR) ELSE VP = 0. 0e0 ENDI F EPS = 1. E- 5 5 CALL MNEW( ’ TRAJECTORY’ , ’ TRAJEC. HLP’ ) CALL MROW( ’ Fi l e: %8! 15St ar t KE: %7 eV! 35St ar t at Z: %7 cm’ / / + ‘ ! 58R: %7 cm ! 71Pat hs: %2’ ) CALL MROW( ’ Accur acy: %9 ! 44Angl es: St ar t %5 ! 55St op %5’ / / + ‘ degs’ ) CALL MROW( ’ Cal cul at e: Pat hs $Fi ni t e El . or ! 31$Par axi al ’ / / + ‘ ! 44$Aber r at i ons ! 61$Magni f i cat i on’ ) CALL MROW( ’ $Exi t t o mai n menu’ ) CALL MENTS( 1, 1, NAME) CALL MREAL( 1, 2, ’ F%7. 1’ , EE) CALL MREAL( 1, 3, ’ F%7. 4’ , X00) CALL MREAL( 1, 4, ’ F%7. 4’ , Y00) CALL MI NT( 1, 5, ’ %2’ , NRAYS) CALL MREAL( 2, 1, ’ E%7. 1’ , EPS) CALL MREAL( 2, 2, ’ F%5. 2’ , THETA1) CALL MREAL( 2, 3, ’ F%5. 2’ , THETA2) 10 CALL GCMD( ’ Your choi ce?’ , Y, X, STAT, * 900) GOTO( 100, 200, 300, 400) Y

100 GOTO( 110, 120, 130, 140, 150) X 110 Y = 2 X = 1 GOTO 5

C Ent er t he st ar t k i net i c ener gy

120 CALL GREAL( ’ Ent er ener gy ( eV) at st ar t of pat hs’ , + Y, X, EE, EE, 0. , 20000. , STAT, * 900)C I ni t i al vel oci t y of el ect r ons VP VP = SQRT( 2* EE* EMR) VAXED = . FALSE. GOTO 5

C Ent er t he x, y coor di nat es f or t he st ar t of t he pat hs

130 CALL GREAL( ’ Ent er Z coor d. f or st ar t of pat hs ( cm) ’ ,

25

Page 26: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

+ Y, X, X00, X00, - 100. , ETDE2X( TEDT) , STAT, * 900) GOTO 5

140 CALL GREAL( ’ Ent er R coor d. f or st ar t of pat hs ( cm) ’ , + Y, X, Y00, Y00, - 10. , 10. , STAT, * 900) GOTO 5 C Ent er t he number of pat hs t o be t r aced

150 CALL GI NT( ’ Ent er no. of r ays t o be t r aced’ , + Y, X, NRAYS, NRAYS, 1, LI MNOR, STAT, * 900) GOTO 5

200 GOTO( 210, 220, 230) X

210 CALL GREAL( ’ Ent er accur acy r equi r ed’ , + Y, X, EPS, EPS, 1. e- 12, 1. e- 2, STAT, * 900) GOTO 5 220 CALL GREAL( ’ Ent er l owest angl e f or a r ay’ , + Y, X, THETA1, THETA1, - 90. , 90. , STAT, * 900) GOTO 5

230 CALL GREAL( ’ Ent er hi ghest angl e f or a r ay’ , + Y, X, THETA2, THETA2, THETA1, 90. , STAT, * 900) GOTO 5

300 GOTO( 310, 320, 330, 340) X C Mai n cal cul at i on of pat hs usi ng f i ni t e el ement model l i ng 310 CALL MPUTS( ’ $FI NI TE ELEMENT TRAJECTORI ES: $’ ) CALL PATHS( VP, EPS, OVLY) TRAJED = . TRUE. TRAJCODE = 1 CALL GRAI SE( 3) CALL GRAI SE( 2) OVLY = . FALSE. Y = 3 X = 3 GOTO 5 C Cal cul at i on of pat hs usi ng t he par axi al r ay equat i on and t he axi alC pot ent i al comput ed f r om t he f i ni t e el ement model .

320 CALL FI NDAXPOT( EE, OVLY) C Now use t he i nt er pol at ed axi al pot ent i al st or ed i n t he common ar r ay C VZI NT t o f i nd t he par axi al pat hs usi ng Pi cht ’ s al gor i t hm.

PLOT = . TRUE. TRAJED = . TRUE. TRAJCODE = 2 CALL MPUTS( ’ $PARAXI AL TRAJECTORI ES: $’ ) CALL AXPATHS( EE, PLOT, OVLY, SLOPE) CALL GRAI SE( 3) CALL GRAI SE( 2) CALL PREAL( ’ Sour ce at F%5. 2 cm. ’ , X00) CALL PREAL( ’ wi t h ener gy % eV’ , EE) CALL SPOTAT( L) CALL PREAL( ’ ! 40Spot at F%6. 2 cm$’ , L) I F ( ETDPOT( 12) . NE. 0. 0) THEN CALL PREAL( ’ Gun Lens % eV’ , ETDPOT( 12) ) ENDI F I F ( ETDPOT( 23) . NE. 0. 0) THEN CALL PREAL( ’ ! 40Obj ect i ve Lens % eV$’ , ETDPOT( 23) ) ENDI F Y = 3 X = 3 GOTO 5

330 I F ( . NOT. TRAJED) THEN CALL WARN( ’ Cal cul at e t r aj ect or i es f i r st ’ ) Y = 3

26

Page 27: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

X = 2 ELSE CALL ABBERS( TRAJCODE) Y = 3 X = 3 ENDI F GOTO 5

340 CALL MAGNI F Y = 3 X = 4 GOTO 5 400 RETURN 900 STAT = MAX( STAT, 0) GOTO 5

END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE PARAXABBERS$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ LOGI CAL PLOT, OVLY I NTEGER I , J, K, NL, NSTART, NRAYSOLD REAL L, THETA1OLD, X00OLD REAL* 8 ASUM, SLOPE

C I ni t i al i ze al l t he var i abl es used f or cal cul at i on of abber r at i ons

PLOT = . FALSE. OVLY = . FALSE. NRAYSOLD = NRAYS THETA1OLD = THETA1 X00OLD = X00 NRAYS = 1 THETA1 = 5. 0 CS = 0. 0D0 CC = 0. 0D0

C Fi nd t he t r aj ect or y RAD f or t he speci al r ay ar r i v i ng at t he i mage at 45 C degr ees t o t he axi s.

CALL AXPATHS( EE, PLOT, OVLY, SLOPE) THETA1 = THETA1/ SLOPE CALL AXPATHS( EE, PLOT, OVLY, SLOPE) C Cal cul at e t he di f f er ent i al RPRI ME of RAD wr t Z

NSTART = 1+I NT( X00/ DELZ) DO 10 I =NSTART+1, NAXPTS- 1 J = I - 1 K = I +1 RPRI ME( I ) = ( RAD( K) - RAD( J) ) / ( 2. 0D0* DELZ) 10 CONTI NUE RPRI ME( NSTART) = RPRI ME( NSTART+1) RPRI ME( NAXPTS) = RPRI ME( NAXPTS- 1) C For m t he i nt egr and f or t he spher i cal abber r at i on coef f .C Uses Munr o, p131. T and TPRI ME wer e cal cul at ed i n t he C subr out i ne AXPOT bel ow.

CALL SPOTAT( L) NL =1+I NT( L/ DELZ)

DO 20 I = NSTART+1, NL I F ( RAD( I ) . EQ. 0. 0) RAD( I ) = 1. 0D- 6 AI NT( I ) = 5. 833333333D0* T( I ) * * 4 + 1. 0D1* T( I ) * T( I ) * TPRI ME( I ) AI NT( I ) = AI NT( I ) + 5. 0D0* TPRI ME( I ) * TPRI ME( I ) AI NT( I ) = AI NT( I ) +1. 866666667D1* ( T( I ) * * 3) * RPRI ME( I ) / RAD( I ) AI NT( I ) = AI NT( I ) - 6. 0D0* ( T( I ) * * 2) * ( ( RPRI ME( I ) / RAD( I ) ) * * 2) AI NT( I ) = AI NT( I ) * SQRT( VZI NT( I ) ) * RAD( I ) * * 4 20 CONTI NUE

27

Page 28: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

ASUM = 0. 0D0 DO 30, I =NSTART+2, NL ASUM = ASUM + ( AI NT( I - 1) +AI NT( I ) ) * DELZ/ 2. 0D0 30 CONTI NUE C Now get Cs i n mm

CS = ASUM/ ( 6. 4D0* SQRT( ABS( ETDPOT( TEDT) ) ) )

C Now cal cul at e t he chr omat i c abber r at i on coef f i c i ent

DO 40 I =NSTART+1, NL I F ( RAD( I ) . EQ. 0. 0) RAD( I ) = 1. 0D- 6 AI NT( I ) = 0. 5D0* T( I ) * RPRI ME( I ) AI NT( I ) = AI NT( I ) + 0. 25D0* RAD( I ) * TPRI ME( I ) AI NT( I ) = AI NT( I ) + 0. 25D0* RAD( I ) * T( I ) * * 2 AI NT( I ) = AI NT( I ) * RAD( I ) / SQRT( VZI NT( I ) ) 40 CONTI NUE ASUM = 0. 0D0 DO 50 I =NSTART+2, NL ASUM = ASUM + ( AI NT( I - 1) +AI NT( I ) ) * DELZ/ 2. 0D0 50 CONTI NUE CC = 1. 0D1* SQRT( ETDPOT( TEDT) ) * ASUM

C Reset t he val ues of some of t he var i abl es

THETA1 = THETA1OLD NRAYS = NRAYSOLD

RETURN ENDC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE BOUNDELS

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’

XMAX = - 1. E8 YMAX = - 1. E8 XMI N = 1. E8 YMI N = 1. E8 DO 5 I = 1, TEDT I F ( ETDE1X( I ) . LT. XMI N) XMI N = ETDE1X( I ) I F ( ETDE1Y( I ) . LT. YMI N) YMI N = ETDE1Y( I ) I F ( ETDE2X( I ) . GT. XMAX) XMAX = ETDE2X( I ) I F ( ETDE2Y( I ) . GT. YMAX) YMAX = ETDE2Y( I ) 5 CONTI NUE RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE FI NDEL( ZP, RP, NEL, OUT)

C Fi nds t he number NEL of t he el ement cont ai ni ng poi nt Zp, Rp. I f i tC f ai l s t hen i t r et ur ns FALSE i n OUT.

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’

REAL* 8 AREA, DET, ZP, RP REAL XE( 3) , YE( 3) , A( 3) I NTEGER I , I EL, J, NEL LOGI CAL OUT OUT = . FALSE. c Sear ch whol e ar r ay, f i r st set t i ng coor ds f or a gi ven el ement J

28

Page 29: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

DO 10 J = 1, TEMT JI NC = 2* J I F ( J. EQ. 1) JI NC = 1 J1 = CURREL + J J2 = CURREL - J DO 15 K = J1, J2, - JI NC I F ( K. GE. 1 . AND. K. LE. TEMT) THEN DO 20 I = 1, 3 I EL = ELCONN( I , K) XE( I ) = POI NTX( I EL) * SCALE YE( I ) = POI NTY( I EL) * SCALE 20 CONTI NUE

c Comput e ar ea of el ement K

DET = XE( 2) * ( YE( 3) - YE( 1) ) +XE( 3) * ( YE( 1) - YE( 2) ) DET = DET + XE( 1) * ( YE( 2) - YE( 3) ) AREA = 0. 5* DET

c Fi nd ar eal coor ds of zp, r p r el at i ve t o el ement J

A( 1) = ( ZP* ( YE( 2) - YE( 3) ) + RP* ( XE( 3) - XE( 2) ) + + ( XE( 2) * YE( 3) - XE( 3) * YE( 2) ) ) / DET A( 2) = ( ZP* ( YE( 3) - YE( 1) ) + RP* ( XE( 1) - XE( 3) ) + + ( XE( 3) * YE( 1) - XE( 1) * YE( 3) ) ) / DET A( 3) = ( ZP* ( YE( 1) - YE( 2) ) +RP* ( XE( 2) - XE( 1) ) + + ( XE( 1) * YE( 2) - XE( 2) * YE( 1) ) ) / DET

c Test whet her zp, r p i s i nsi de el ement J. i e 0<=A( I ) <=1

I F( A( 1) . GE. 0. 0. AND. A( 1) . LE. 1. 0) THEN I F( A( 2) . GE. 0. 0. AND. A( 2) . LE. 1. 0) THEN I F( A( 3) . GE. 0. 0. AND. A( 3) . LE. 1. 0) THEN NEL = K CURREL = NEL GOTO 30 ENDI F END I F END I F ENDI F 15 CONTI NUE 10 CONTI NUE

C I f i t i s not i n any of t he el ement s, t hen say so: OUT = . TRUE. 30 RETURN END

c ______________________________________________________________

SUBROUTI NE FI NDNN( N, NN, POSN) C Thi s cal cul at es t he el ement number s of t he t hr ee nei ghbour i ng el ement sC t o t he one number ed N. I t passes back t hhei r number s i n NN( 3) andC si gnal s v i a POSN i f N i s on t he axi s ( POSN=’ A’ ) or on el ect r ode sur f aceC ( POSN=’ E’ ) or at l ef t hand end ( ’ L’ ) or r i ght hand end ( ’ R’ ) . C I f N i s sur r ounded by ot her el ement s t hen POSN=’ F’ ( f or f r ee) .

$i ncl ude: ‘ l ens. def ’

CHARACTER* 1 POSN I NTEGER NN( 3) , NELEM( 17) I NTEGER FN, BN, N, LENGTH, NAX, NLH, NRH, NRE, BAND I NTEGER I , J, K, L

BAND = 17 POSN = ‘ F’

C I s base of el ement N on t he axi s? Zer o NN at same t i me.

NAX = 0 DO 10 I =1, 3 I F ( POI NTY( ELCONN( I , N) ) . EQ. 0. 0) NAX = NAX + 1

29

Page 30: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

NN( I ) = 0 10 CONTI NUE I F ( NAX. EQ. 2) THEN POSN = ‘ A’ BAND = 8 GOTO 18 ENDI F

C I s el ement such t hat one si de i s on l ef t hand end?

NLH = 0 DO 12 I =1, 3 I F ( POI NTX( ELCONN( I , N) ) . EQ. 0. 0) NLH = NLH + 1 NN( I ) = 0 12 CONTI NUE I F ( NLH. EQ. 2) THEN POSN = ‘ L’ GOTO 18 ENDI F

C I s el ement such t hat one si de i s on r i ght hand end?

NRH = 0 LENGTH = ETDE2X( TEDT) DO 14 I =1, 3 I F ( POI NTX( ELCONN( I , N) ) . EQ. LENGTH) NRH = NRH + 1 NN( I ) = 0 14 CONTI NUE I F ( NRH. EQ. 2) THEN POSN = ‘ R’ GOTO 18 ENDI F C I s el ement on an el ect r ode? NRE = 0

C Put code t o f i nd ext r ema her e when el ement has one si de on an el ect r ode I F ( NRE. EQ. 2) POSN = ‘ E’

C I dent i f y t he el ement s adj acent t o N 18 DO 20 I =1, BAND NELEM( I ) = 0 20 CONTI NUE K = 0

DO 200 I =1, TEMT/ 2

C NN( K) wi l l cont ai n 3 el ement number s of t he next near est nei ghbourC el ement s. Count f or war ds f i r st FN = N + I I F ( FN. GT. TEMT) GOTO 60 DO 50 J=1, 3 DO 40 NE=1, 3 I F ( ELCONN( NE, FN) . EQ. ELCONN( J, N) ) THEN K = K + 1 NELEM( K) = FN I F ( K. EQ. BAND) GOTO 300 ENDI F 40 CONTI NUE 50 CONTI NUE C Backwar d count 60 BN = N - I I F ( BN. LT. 1) GOTO 200 I F ( ( BN. LT. 1) . AND. ( FN. GT. TEMT) ) GOTO 300 DO 80 J=1, 3 DO 70 NE=1, 3 I F ( ELCONN( NE, BN) . EQ. ELCONN( J, N) ) THEN K = K + 1 NELEM( K) = BN I F ( K. EQ. BAND) GOTO 300 ENDI F 70 CONTI NUE

30

Page 31: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

80 CONTI NUE 200 CONTI NUE C Fi nd el ement s wi t h t wo nodes common t o cur r ent el ement : 300 L = 0 DO I =1, BAND K = 0 BN=NELEM( I ) DO NE=1, 3 DO J=1, 3 I F ( ELCONN( NE, BN) . EQ. ELCONN( J, N) ) K=K+1 ENDDO ENDDO I F ( K. EQ. 2 . AND. BN. NE. 0) THEN L = L + 1 NN( L) = BN ENDI F ENDDO RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE GRAD( M, EZM, ERM, ZC, RC, POS) C Fi nds t he el ect r i c f i el d component s EZM, ERM at t he cent r e ZC, RC of cel l M

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ I NTEGER M, I , J REAL* 8 EZM, ERM, X( 3) , Y( 3) , Z( 3) , D( 3, 2) , DET, ZC, RC CHARACTER* 1 POS C Set up coor di nat es of el ement M

DO 10 I =1, 3 J = ELCONN( I , M) X( I ) = POI NTX( J) * SCALE Y( I ) = POI NTY( J) * SCALE Z( I ) = F( J) C Does t he cur r ent el ement have i t s base si t uat ed on t he axi s or at ei t her C end of t he l ens? I f so r ever se t he si gn of X or Y f or t he non- zer o apex.C I f at r i ght hand end t hen ext end apex beyond l engt h of l ens.

I F ( POS. EQ. ’ A’ ) THEN I F ( POI NTY( J) . EQ. 0. 0) GOTO 10 Y( I ) = - Y( I ) ENDI F I F ( POS. EQ. ’ L’ ) THEN I F ( POI NTX( J) . EQ. 0. 0) GOTO 10 X( I ) = - X( I ) ENDI F I F ( POS. EQ. ’ R’ ) THEN I F ( POI NTX( J) . EQ. ETDE2X( TEDT) ) GOTO 10 X( I ) = 2* ETDE2X( TEDT) - POI NTX( J) ENDI FC NOTE TO MP - Add code t o l ook af t er case when POS=’ E’ - el ement has C one si de on an el ect r ode.

10 CONTI NUE C Fi nd t he det er mi nant of el ement M coor di nat es

DET = X( 2) * ( Y( 3) - Y( 1) ) + X( 3) * ( Y( 1) - Y( 2) ) + X( 1) * ( Y( 2) - Y( 3) ) D( 1, 1) = ( Y( 2) - Y( 3) ) / DET D( 2, 1) = ( Y( 3) - Y( 1) ) / DET D( 3, 1) = ( Y( 1) - Y( 2) ) / DET D( 1, 2) = ( X( 3) - X( 2) ) / DET D( 2, 2) = ( X( 1) - X( 3) ) / DET D( 3, 2) = ( X( 2) - X( 1) ) / DET EZM = 0. 0

31

Page 32: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

ERM = 0. 0 DO 20 I =1, 3 EZM = EZM + Z( I ) * D( I , 1) ERM = ERM + Z( I ) * D( I , 2) 20 CONTI NUE ZC = ( X( 1) + X( 2) + X( 3) ) / 3. 0 RC = ( Y( 1) + Y( 2) + Y( 3) ) / 3. 0 RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE I SI TOUT( ZP, RP, OUT) $i ncl ude: ‘ t r aj ec. def ’ LOGI CAL OUT REAL* 8 ZP, RP

I F ( ( ZP. GT. XMAX* SCALE) . OR. + ( ZP. LT. XMI N* SCALE) . OR. + ( RP. GT. YMAX* SCALE) ) THEN OUT = . TRUE. ENDI F RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE MAGNI F

CALL WARN( ’ Code not r eady yet ’ )

RETURN ENDC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE PLANE( AX, AY, AZ, X, Y, Z)

C Fi t s a pl ane t o t he 3 poi nt s ( ax, ay, az) and r et ur ns t he val ue of zC at t he poi nt ( x, y)

REAL* 8 X, Y, AX( 3) , AY( 3) , AZ( 3) REAL* 8 Z, A, B, C, DEN REAL* 8 BX1, BX2, BY1, BY2, BZ1, BZ2

BZ1 = AZ( 1) - AZ( 2) BZ2 = AZ( 2) - AZ( 3) BY1 = AY( 1) - AY( 2) BY2 = AY( 2) - AY( 3) BX1 = AX( 1) - AX( 2) BX2 = AX( 2) - AX( 3) DEN = BX1* BY2 - BX2* BY1 A = ( BZ1* BY2 - BZ2* BY1) / DEN B = ( BZ2* BX1 - BZ1* BX2) / DEN C = AZ( 1) - A* AX( 1) - B* AY( 1) Z = A* X + B* Y + C RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE SORTI T c Rout i ne t o or der t he mesh used i n POTGEN.c Re- or der t he ar r ays I JK, X, Y, and F.

32

Page 33: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

c Uses an i ndex poi nt er met hod t o change t he ar r ay number i ng.c The ar r ays f r om POTGEN ar e number ed t o mi ni mi ze t he bandwi dt hc i n t he f i ni t e el ement anal ysi s. I n or der t o sear ch t he ar r aysc l ogi cal l y i n TRAJ t hey need t o be number ed i n a spat i al l y c sequence, ( i e wi t h i ncr easi ng z) .

$i ncl ude: ‘ l ens. def ’ I NTEGER I NDEX( LI MPTS) , I JKT( 3, LI MPTS) REAL XC( LI MPTS) , XEE( 3) , XX, YYC CHARACTER* 12 FNAME CHARACTER* 60 MESS

XX = 0. 0 YY = 0. 0 c I ni t i al i ze I NDEX t o t he r ange 1 t o TEMT

DO 10 I = 1, TEMT I NDEX( I ) = I10 CONTI NUE

c Fi nd t he cent r oi ds ( XC, YC) of each el ement . MESS = ‘ Mesh sor t i ng. . . f i ndi ng el ement cent r oi ds. . . ’ CALL MBUSY( 0, 0, MESS) DO 30 I = 1, TEMT DO 20 J = 1, 3 I EL = ELCONN( J, I ) XEE( J) = POI NTX( I EL)20 CONTI NUE XC( I ) = ( XEE( 1) +XEE( 2) +XEE( 3) ) / 3. 0E030 CONTI NUE

c Sor t i ng Rout i ne.

MESS = ‘ Mesh sor t i ng. . . exchangi ng poi nt er s. . . ’ CALL MBUSY( 0, 0, MESS) CALL QSORT( TEMT, XC, I NDEX)

c The code above has r enumber ed I as I NDEX( I ) .c Rear r ange ot her ar r ays wi t h I NDEX( I ) f or I .

DO 60 J=1, TEMT DO 60 I =1, 3 I JKT( I , J) = ELCONN( I , I NDEX( J) )60 CONTI NUE

c Wr i t e cont ent s of I JKT back i nt o ELCONN

DO 70 J = 1, TEMT DO 70 I = 1, 3 ELCONN( I , J) = I JKT( I , J)70 CONTI NUE

C Save Modi f i ed, Sor t ed, Mesh Fi l e. Use l at er when r equi r ed - decl ar e FNAMEC FNAME = NAMEC CALL CONCAT( FNAME, ’ . MMH’ )C OPEN( UNI T=21, FI LE=FNAME, STATUS=’ UNKNOWN’ )C WRI TE( 21, 80) TEMT, TPOI NT, MBC80 FORMAT( 3I 5)C WRI TE( 21, 90) ( XX, YY, I =1, TPOI NT)C90 FORMAT( 2( 2F10. 4, 4X) )C WRI TE( 21, 100) ( ( ELCONN( I , J) , I =1, 3) , J=1, TEMT)C100 FORMAT( 12I 5)C CLOSE( UNI T=21)C CALL MPUTS( ’ Sor t ed connect i v i t i es i n f i l e: ‘ )C CALL MPUTS( FNAME)C CALL MPUTS( ’ $’ )C CALL MBUSY( 0, 0, ’ ‘ )

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

33

Page 34: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

SUBROUTI NE WRTRAJ( NR, NI R)

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ CHARACTER* 12 FNAME

FNAME = NAME CALL CONCAT( FNAME, ’ . TRJ’ )

I F ( NI R. EQ. 1) THEN OPEN( UNI T=21, FI LE=FNAME, STATUS=’ UNKNOWN’ ) WRI TE( 21, * ) ‘ # Set of r ays f r om f i l e: ‘ , NAME WRI TE( 21, * ) ‘ # Angul ar r ange: ‘ , THETA1, ’ t o ‘ , THETA2 WRI TE( 21, * ) ‘ # No of r ays: ‘ , NR WRI TE( 21, * ) ‘ # Ray or i gi n at : ‘ , X00, ’ , ’ , Y00 WRI TE( 21, * ) ‘ #’ ENDI F WRI TE( 21, * ) ‘ # Angl e of r ay: ‘ , THETA1+DTHETAR* ( NI R- 1) WRI TE( 21, * ) ‘ # No of poi nt s i n r ay: ‘ , KOUNT WRI TE( 21, * ) ‘ ‘ DO 18 I = 1, KOUNT WRI TE( 21, 12) YP( 3, I ) / SCALE, YP( 4, I ) / SCALE18 CONTI NUE I F ( NI R. EQ. NR) CLOSE( UNI T=21)10 FORMAT( I 5)12 FORMAT( 2E25. 16) RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE SPLI NE( X, Y, N, YP1, YPN, Y2) C Rout i ne f r om Pr ess f or cubi c spl i ne i nt er pol at i on usi ng ar r ays X and Y.C Gi ven ar r ays X( 1: n) and Y( 1: n) cont ai ni ng a t abul at ed f unct i on i . e. C yi = f ( x i ) , wi t h x1<x2<. . . xn, and gi ven val ues yp1 and ypn f or t he f i r st C der i vat i ve of t he i nt er pol at i ng f unct i on at poi nt s 1 and n r espect i vel y,C t hi s r out i ne r et ur ns an ar r ay y2( 1: n) of l engt h n whi ch cont ai ns t he C second der i vat i ve of t he i nt er pol at i ng f unct i on at t he t abul at ed poi nt sC xi . I f yp1 and/ or ypn ar e equal t o 1. E30 or l ar ger , t he r out i ne i s s i gnal edC t o set t he cor r espondi ng boundar y condi t i on f or a nat ur al spl i ne, wi t hC zer o 2nd der i vat i ve on t hat boundar y.C Par amet er NMAX i s t he l ar gest ant i c i pat ed val ue f or N.

I NTEGER I , K, NMAX, N PARAMETER( NMAX=2000) REAL* 8 YP1, YPN, X( N) , Y( N) , Y2( N) , U( NMAX) , P, QN, SI G, UN

I F ( YP1. GT. . 99D30) THEN Y2( 1) = 0. 0 U( 1) = 0. 0 ELSE Y2( 1) = - 0. 5 U( 1) = ( 0. 3D1/ ( X( 2) - X( 1) ) ) * ( ( Y( 2) - Y( 1) ) / ( X( 2) - X( 1) ) - YP1) ENDI F

DO 11 I =2, N- 1 SI G = ( X( I ) - X( I - 1) ) / ( X( I +1) - X( I - 1) ) P = SI G* Y2( I - 1) +2. Y2( I ) = ( SI G- 1. ) / P U( I ) = ( 6. * ( ( Y( I +1) - Y( I ) ) / ( X( I +1) - X( I ) ) - ( Y( I ) - Y( I - 1) ) + / ( X( I ) - X( I - 1) ) ) / ( X( I +1) - X( I - 1) ) - SI G* U( I - 1) ) / P 11 CONTI NUE

I F ( YPN. GT. . 99D30) THEN QN = 0. UN = 0. ELSE QN = 0. 5 UN = ( 3. / ( X( N) - X( N- 1) ) ) * ( YPN- ( Y( N) - Y( N- 1) ) / ( X( N) - X( N- 1) ) ) ENDI F Y2( N) = ( UN- QN* U( N- 1) ) / ( QN* Y2( N- 1) +1. ) DO 12 K=N- 1, 1, - 1

34

Page 35: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

Y2( K) = Y2( K) * Y2( K+1) +U( K) 12 CONTI NUE RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE SPLI NT( XA, YA, Y2A, N, X, Y) C Gi ven t he ar r ays XA( 1: n) and YA( 1: n) of l engt h N, whi ch t abul at e a f unct i onC ( wi t h t he XAi ’ s i n or der ) and gi ven t he ar r ay Y2A( 1: n) whi ch i s t he out put C f r om SPLI NE above, and gi ven a val ue of X, t hi s r out i ne r et ur ns a cubi c-C spl i ne i nt er pol at ed val ue Y.

I NTEGER N, K, KHI , KLO REAL* 8 X, Y, XA( N) , YA( N) , Y2A( N) , A, B, H KLO = 1 KHI = N

1 I F ( KHI - KLO. GT. 1) THEN K = ( KHI +KLO) / 2 I F ( XA( K) . GT. X) THEN KHI = K ELSE KLO = K ENDI F GOTO 1 ENDI F H = XA( KHI ) - XA( KLO) I F ( H. EQ. 0. ) PAUSE A = ( XA( KHI ) - X) / H B = ( X- XA( KLO) ) / H Y = A* YA( KLO) +B* YA( KHI ) + + ( ( A* * 3- A) * Y2A( KLO) +( B* * 3- B) * Y2A( KHI ) ) * ( H* * 2) / 6. RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE FI NDAXPOT( EE, OVLY)

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ REAL EE REAL* 8 TZ, TV, LENGTH, Z I NTEGER I , J, K LOGI CAL OVLY OVLY = . FALSE. I F ( . NOT. SORTED) THEN CALL SORTI T SORTED = . TRUE. ENDI F

C Col l ect al l t he axi al coor di nat es and t hei r pot ent i al s i nt o ZAX and VAX I F ( . NOT. VAXED) THEN CALL MBUSY( 0, 0, ’ Cal cul at i ng axi al pot ent i al . . . ’ ) K = 1 DO 10, I = 1, TEMT DO 10, J = 1, 3 I F ( POI NTY( ELCONN( J, I ) ) . EQ. 0. 0) THEN TZ = POI NTX( ELCONN( J, I ) ) TV = F( ELCONN( J, I ) ) I F ( K. EQ. 1) THEN ZAX( K) = TZ VAX( K) = TV K = K+1 ELSE I F ( TZ. EQ. ZAX( K- 1) ) GOTO 10 ZAX( K) = TZ VAX( K) = TVC CALL PREAL( ’ % ‘ , REAL( TZ) )

35

Page 36: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

C CALL PREAL( ’ %$’ , REAL( TV) ) K = K+1 ENDI F ENDI F NPTS = K- 1 10 CONTI NUE C I nt er pol at e t he axi al pot ent i al ont o NAXPTS evenl y spaced i nt er val s

CALL SPLI NE( ZAX, VAX, NPTS, 1. D30, 1. D30, VAXI NT) LENGTH = DBLE( NODEX( TNODE) ) DELZ = LENGTH/ ( NAXPTS- 1) DO 20 K = 1, NAXPTS Z = ( K- 1) * DELZ CALL SPLI NT( ZAX, VAX, VAXI NT, NPTS, Z, VZI NT( K) )

C Pr ot ect agai nst subsequent di v i de by zer o er r or s I F ( VZI NT( K) . LE. 0. 0) VZI NT( K) =1. 0D- 10C CALL PREAL( ’ %’ , REAL( Z) )C CALL PREAL( ’ %$’ , REAL( VZI NT( K) ) ) 20 CONTI NUE

C Now cal cul at e t he l ens st r engt h f unct i on T T( 1) = 0. 0 DO 30 K=1, NAXPTS- 2 I = K+1 J = K+2 T( I ) = ( VZI NT( J) - VZI NT( K) ) / ( 2. 0D0* DELZ* ( EE+VZI NT( I ) ) ) 30 CONTI NUE T( NAXPTS- 1) = T( NAXPTS- 2) T( NAXPTS) = T( NAXPTS- 1) C Now di f f er ent i at e T wr t Z f or T pr i me t o be used t o f i nd t heC aber r at i on coef f i c i ent s

DO 40, K = 2, NAXPTS- 1 I = K- 1 J = K+1 TPRI ME( K) = ( T( J) - T( I ) ) / ( 2. 0D0* DELZ) 40 CONTI NUE TPRI ME( 1) = TPRI ME( 2) TPRI ME( NAXPTS) = TPRI ME( NAXPTS- 1) ENDI F VAXED = . TRUE. RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE AXPATHS( EE, PLOT, OVLY, SLOPE)

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’$i ncl ude: ‘ gr acol . def ’

REAL EE REAL* 8 Z, THETAR1, THETAR2, SLOPE I NTEGER NR, XS, YS, NSTART LOGI CAL OVLY, PLOT CALL MBUSY( 0, 0, ’ Cal cul at i ng par axi al t r aj ect or i es. . . ’ ) OPEN( UNI T=41, FI LE=’ PARAX. TRJ’ , STATUS=’ UNKNOWN’ )

C Fi r st set up t he val ues RHO( 1) and RHO( 2) f or t he st ar t of each pat h. THETAR1 = PI * DBLE( THETA1/ 1. 8D2) THETAR2 = PI * DBLE( THETA2/ 1. 8D2) I F ( NRAYS. GT. 1) THEN DTHETAR = ( THETAR2- THETAR1) / ( NRAYS- 1) ENDI F

C Set up t he gr aphi cs scr een wi t h an out l i ne of l ens sur f aces I F ( PLOT) THEN CALL GCLS

36

Page 37: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

CALL DTRAJ( OVLY, XSCA, YSCA, RMI N) CALL GPROMP( 1, TI TLE) CALL GPROMP( 2, ’ Hi t ESCAPE t o exi t pl ot t i ng’ ) XORG = 50 YORG = 20 CALL GSPAL( RAI PAL) CALL GSCOL( WHI TE) ENDI F NSTART = 1+I NT( X00/ DELZ) DO 3300 NR=1, NRAYS RAD( NSTART) = Y00 RAD( NSTART+1) = Y00 + ( THETAR1 + ( NR- 1) * DTHETAR) * DELZ RHO( NSTART) = RAD( NSTART) * ( ( EE+VZI NT( NSTART) ) * * 0. 25) RHO( NSTART+1) = RAD( NSTART+1) * ( ( EE+VZI NT( NSTART+1) ) * * 0. 25)

C Now comput e Pi cht ’ s Rho and est i mat e t he r adi us of t he pat h at each Z

T( 1) = 0. 0 DO 323 K = NSTART, NAXPTS- 2 I = K+1 J = K+2 RHO( J) = 2. 0D0* RHO( I ) - RHO( K) RHO( J) = RHO( J) - 0. 1875D0* DELZ* DELZ* T( I ) * T( I ) * RHO( I ) 323 CONTI NUE DO 324 K=NSTART+2, NAXPTS RAD( K) = RHO( K) / ( ( EE+VZI NT( K) ) * * 0. 25) 324 CONTI NUE

C Pl ot t he cal cul at ed t r aj ect or y

I F ( PLOT) THEN XS = XORG + I NT( X00* XSCA) YS = YORG + I NT( ( Y00- RMI N) * YSCA) WRI TE( 41, * ) X00, Y00 CALL GMOVE( XS, YS) DO 325 K=NSTART, NAXPTS- 1 Z = X00 + ( K- NSTART+1) * DELZ XS = XORG + I NT( Z* XSCA) YS = YORG + I NT( ( RAD( K) - RMI N) * YSCA) CALL GLI NE( XS, YS) WRI TE( 41, * ) Z, RAD( K) 325 CONTI NUE XS = XORG + I NT( X00* XSCA) YS = YORG + I NT( ( - Y00- RMI N) * YSCA) CALL GMOVE( XS, YS) DO 326 K=NSTART, NAXPTS- 1 Z = X00 + ( K- NSTART+1) * DELZ XS = XORG + I NT( Z* XSCA) YS = YORG + I NT( ( - RAD( K) - RMI N) * YSCA) CALL GLI NE( XS, YS) 326 CONTI NUE ENDI F 3300 CONTI NUE C Now sear ch one of pat hs f or t he cr ossover s

XSOLD = 0 I CROSS = 0 DO 3310, K=NSTART+1, NAXPTS- 1 Z = X00 + ( K- NSTART) * DELZ I F ( ( RAD( K- 1) . NE. 0. 0) . AND. ( ( RAD( K) / RAD( K- 1) ) . LT. 0. 0) ) THEN I CROSS = I CROSS + 1 SLOPE = ( RAD( K- 1) - RAD( K) ) / ( Z- XSOLD) CROSSZ( I CROSS) = XSOLD+RAD( K- 1) / SLOPE

I F ( PLOT) THEN CALL PREAL( ’ Xover at z = F%8. 4 cm ‘ , REAL( CROSSZ( I CROSS) ) ) CALL PREAL( ’ ! 40Sl ope =F%6. 4 $’ , REAL( SLOPE) ) ENDI F ENDI F XSOLD = Z 3310 CONTI NUE

37

Page 38: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

CLOSE( UNI T=41) RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE SPOTAT( L) C Fi nds t he cr ossover most di st ant f r om t he sour ce. Thi s i s t aken as t heC f ocal poi nt f or t he gun

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ REAL L I NTEGER I L = 0. 0 DO 10, I =1, I CROSS I F( CROSSZ( I ) . GT. L) L = CROSSZ( I ) 10 CONTI NUE RETURN END C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SUBROUTI NE QSORT( N, ARR, I BRR) C Subr out i ne SORT2 f r om Pr ess et al . p326. Sor t s an ar r ay ARR( 1: N) i nt oC ascendi ng or der usi ng Qui cksor t , whi l st maki ng t he cor r espondi ng r e -C ar r angement of t he ar r ay I BRR( 1: N) . Her e i t i s mi di f i ed t o sor t t heC X coor di nat es XC of t he f i ni t e el ement cent r oi ds i nt o ascendi ng or derC whi l st al so r ear r angi ng t he i nt eger ar r ay I NDEX i nt o t he cor r espondi ngC sequence.

I NTEGER N, M, NSTACK, I BRR( N) REAL ARR( N) PARAMETER( M=7, NSTACK=50) I NTEGER I , I B, I R, J, JSTACK, K, L, I STACK( NSTACK) , I TEMP REAL A, TEMP JSTACK = 0 L = 1 I R = N 1 I F ( I R- L. LT. M) THENC I nser t i on sor t when subar r ay i s smal l enough DO 12 J=L+1, I R A = ARR( J) I B = I BRR( J) DO 11 I =J- 1, 1, - 1 I F ( ARR( I ) . LE. A) GOTO 2 ARR( I +1) = ARR( I ) I BRR( I +1) = I BRR( I ) 11 CONTI NUE I = 0 2 ARR( I +1) = A I BRR( I +1) = I B 12 CONTI NUE I F ( JSTACK. EQ. 0) RETURNC Pop st ack and begi n a new r ound of par t i t i oni ng I R = I STACK( JSTACK) L = I STACK( JSTACK- 1) JSTACK = JSTACK - 2 ELSEC Choose medi an of l ef t , r i ght and cent r e el ement s as par t i t i oni ngC el ement A. Al so r e- ar r ange so t hat A( L+1) <= A( 1) <= A( I R) K = ( L+I R) / 2 TEMP = ARR( K) ARR( K) = ARR( L+1) ARR( L+1) = TEMP I TEMP = I BRR( K) I BRR( K) = I BRR( L+1) I BRR( L+1) = I TEMP

38

Page 39: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

I F ( ARR( L+1) . GT. ARR( I R) ) THEN TEMP = ARR( L+1) ARR( L+1) = ARR( I R) ARR( I R) = TEMP I TEMP = I BRR( L+1) I BRR( L+1) = I BRR( I R) I BRR( I R) = I TEMP ENDI F I F ( ARR( L) . GT. ARR( I R) ) THEN TEMP = ARR( L) ARR( L) = ARR( I R) ARR( I R) = TEMP I TEMP = I BRR( L) I BRR( L) = I BRR( I R) I BRR( I R) = I TEMP ENDI F I F ( ARR( L+1) . GT. ARR( L) ) THEN TEMP = ARR( L+1) ARR( L+1) = ARR( L) ARR( L) = TEMP I TEMP = I BRR( L+1) I BRR( L+1) = I BRR( L) I BRR( L) = I TEMP ENDI FC I ni t i at e poi nt er s f or par t i t i oni ng I = L + 1 J = I R A = ARR( L) I B = I BRR( L)

C Begi nni ng of i nner most l oopC Scan up t o f i nd el ement > A 3 CONTI NUE I = I + 1 I F ( ARR( I ) . LT. A) GOTO 3C Scan down t o f i nd el ement < A 4 CONTI NUE J = J - 1 I F ( ARR( J) . GT. A) GOTO 4C I f poi nt er s cr ossed. Exi t wi t h par t i t i oni ng compl et e. I F ( J. LT. I ) GOTO 5C Exchange el ement s of bot h ar r ays. TEMP = ARR( I ) ARR( I ) = ARR( J) ARR( J) = TEMP I TEMP = I BRR( I ) I BRR( I ) = I BRR( J) I BRR( J) = I TEMP GOTO 3C End of i nner most l oop.

5 ARR( L) = ARR( J) ARR( J) = A I BRR( L) = I BRR( J) I BRR( J) = I B JSTACK = JSTACK + 2C Push poi nt er s t o l ar ger subar r ay on st ack, pr ocess smal l er subar r ayC i mmedi at el y. I F ( JSTACK. GT. NSTACK) THEN CALL PI NT( ’ JSTACK = %’ , JSTACK) CALL PI NT( ’ N = %’ , N) CALL PI NT( ’ NSTACK = %$’ , NSTACK) CALL WARN( ’ Fat al Er r or - - NSTACK t oo smal l i n QSORT’ ) RETURN ENDI F I F ( I R- I +1. GE. J- 1) THEN I STACK( JSTACK) = I R I STACK( JSTACK- 1) = I I R = J - 1 ELSE I STACK( JSTACK) = J - 1 I STACK( JSTACK- 1) = L L = I ENDI F

39

Page 40: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

ENDI F GOTO 1 END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -C New wor k by Andr ew Jackson:C ( & al t er at i ons t o or i gi nal code)CC v1. 23 28/ 2/ 97C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE Wr i t ePot$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ PARAMETER ( NMAX=10) DI MENSI ON nCz( NMAX) , nCr ( NMAX) REAL* 8 Yi K( 4) , Z, R, Pot , Di f , nCz, nCr I NTEGER nt h, I , r es, cycl e LOGI CAL URK COMMON / SPLI N/ nt h, nCz, nCr COMMON / TEMP/ cycl e cycl e=1

r es=100

OPEN( UNI T=21, FI LE=’ AxNodes. dat ’ , STATUS=’ UNKNOWN’ ) WRI TE( 21, * ) ‘ # Axi al node pot ent i al dat a: ’ DO I =TPOI NT, 1, - 1 I F ( POI NTY( I ) . EQ. 0. 0d0) THEN WRI TE( 21, 112) POI NTX( I ) * SCALE* 100. 0, F( I ) ENDI F ENDDO CLOSE( UNI T=21)

c OPEN( UNI T=21, FI LE=’ svd. dat ’ , STATUS=’ UNKNOWN’ )c R=0. 0d0c WRI TE( 21, * ) ‘ # Pot ent i al di st f or r ays’c DO I =1, r esc Z=I * ( 0. 101/ r es)c Yi k( 3) =Zc Yi k( 4) =Rc CALL MeshSpl i ne( Yi k, URK)c CALL nt haeval ( nt h, nCz, Yi k( 3) , Pot )c CALL nt hadi f f ( nt h, nCz, Yi k( 3) , Di f )c WRI TE( 21, 113) Z, Pot , Di fc ENDDOc CLOSE( UNI T=21)

112 FORMAT( 2F15. 8) 113 FORMAT( 3F15. 8)

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE FI NELABBERSC Take X- over poi nt s f r om Fi nEl Cal c and f i nd spher i cal abber at i on CS$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ PARAMETER ( NMAX=20, MMAX=10) REAL* 8 AAB( 5, 5) , BAB( 5, 5) , al pha, sl ope, si g( NMAX) , AbCo( MMAX) REAL* 8 xC( NMAX) , yC( NMAX) , chi sq, covar ( MMAX, MMAX) I NTEGER ABNP, I , J, R, ABM, ABN

C Set number of coef f i c i ent t o f i nd ( f +Cs3+Cs5+. . . ) : ABNP = 3

C Least squar es svd al gor i t hm: DO I =1, I CROSS s i g( I ) =1. 0d0 xC( I ) =DATAN( DBLE( CROSSLOPE( I ) ) ) yC( I ) =DBLE( CROSSZ( I ) ) ENDDO CALL SVDFI T( xC, yC, si g, I CROSS, AbCo, ABNP, chi sq, 2)

40

Page 41: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

CALL SVDVAR( ABNP, covar )

C Tr anf er r esul t s t o an ar r ay i n a shar ed common bl ock: DO I =1, ABNP AbCoEr r ( I , 1) =AbCo( I ) AbCoEr r ( I , 2) =SQRT( covar ( I , I ) ) ENDDO

RETURN ENDC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE ABBERS( TRAJCODE)$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ I NTEGER TRAJCODE

I F ( TRAJCODE. EQ. 1 . AND. I CROSS. EQ. 0) THEN CALL WARN( ’ Need at l east 1 X- over f or t hi s cal cul at i on. ’ ) RETURN ELSEI F ( TRAJCODE. EQ. 1) THEN CALL FI NELABBERS ELSEI F ( TRAJCODE. EQ. 2) THEN CALL PARAXABBERS ENDI F I F ( TRAJCODE. EQ. 1) THEN CALL PREAL( ’ Posi t i on of f ocus: F%10. 4 cm$’ , AbCoEr r ( 1, 1) ) CALL PREAL( ’ +/ - : F%10. 4 cm$’ , AbCoEr r ( 1, 2) ) CALL PREAL( ’ 3r d or der : F%10. 4 cm$’ , AbCoEr r ( 2, 1) ) CALL PREAL( ’ +/ - : F%8. 2 cm$’ , AbCoEr r ( 2, 2) ) CALL PREAL( ’ 5t h or der : F%10. 4 cm$’ , AbCoEr r ( 3, 1) ) CALL PREAL( ’ +/ - : F%8. 2 cm$’ , AbCoEr r ( 3, 2) ) ELSEI F ( TRAJCODE. EQ. 2) THEN CALL PREAL( ’ Aber . coef f s: Spher i cal : F%8. 1 mm’ , REAL( CS) ) CALL PREAL( ’ ! 40Chr omat i c: F%7. 1 mm$’ , REAL( CC) ) ENDI F

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE PATHS( VP, EPS, OVLY)$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’$i ncl ude: ‘ gr acol . def ’ LOGI CAL OVLY, OUT, PLOTEL, CROSSED I NTEGER KEY, NP, I , J, I EL, si gn1, si gn2, I NTK, OLDKOUNT REAL* 8 TSTART, TEND, LI NPOT, Zi ni t , Ri ni t , VPP, Hi ni t , Hmax REAL* 8 Xpawet , Ypawet REAL* 8 H1, YST( 4) , Y( 4) , HMI N, er r s REAL Sl ope, I nt er , r esl ut n EXTERNAL LI NPOT

C Wr i t e out pot ent i al dat a et c f or anal ysi s: CALL Wr i t ePot OPEN( UNI T=23, FI LE=’ Z. dat ’ , STATUS=’ UNKNOWN’ ) OPEN( UNI T=24, FI LE=’ R. dat ’ , STATUS=’ UNKNOWN’ ) OPEN( UNI T=25, FI LE=’ E. dat ’ , STATUS=’ UNKNOWN’ )

PLOTEL = . FALSE. I CROSS = 0 NP=4 r esl ut n=0. 2d0

C Def i ne angul ar var i at i on of r ays: THETAR = PI * DBLE( THETA1/ 1. 8D2) I F ( NRAYS. GT. 1) THEN DTHETAR = PI * ( THETA2- THETA1) / ( ( NRAYS- 1) * 180. 0) ENDI F

C Sor t t he dat a i f necessar y: I F ( . NOT. SORTED) THEN CALL SORTI T SORTED = . TRUE. ENDI F

41

Page 42: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

OVLY = . TRUE. CALL GCLS CALL DTRAJ( OVLY, XSCA, YSCA, RMI N) CALL GPROMP( 1, TI TLE) CALL GPROMP( 2, ’ Hi t ESC t o escape’ ) XORG = 50 YORG = 20 CALL GSPAL( RAI PAL) CALL GSCOL( WHI TE) C Mai n Loop ar ound NRAYS TSTART = 0. 0 KMAX = LI MNNT TEND = 0. 0 er r s=DBLE( EPS)

C Make a r ough est i mat e of t r ansi t t i me t hr ough st r uct ur eC Then f i nd t i mest ep f r om t hat : DO 350 I = 1, TEDT VEL = SQRT( 2* EMR* ETDPOT( I ) ) I F ( VEL. NE. 0. 0) THEN FLEN = ( ETDE2X( I ) - ETDE1X( I ) ) * SCALE TEND = TEND + FLEN/ VEL ENDI F 350 CONTI NUE TEND = TEND CALL PREAL( ’ Tr ansi t i on t i me %10. 4 secs$’ , REAL( TEND) ) Hi ni t = ( TEND- TSTART) / 200. 0d0

C Fi nd t he l i mi t i ng val ues of t he el ect r odes out si de whi ch t he meshC does not ext end CALL BOUNDELS

C Pl ot nodes f or al l t he el ement s: I F ( PLOTEL) THEN DO J = 1, TEMT DO I = 1, 3 I EL = ELCONN( I , J) Xpawet =DBLE( POI NTX( I EL) * SCALE) Ypawet =DBLE( POI NTY( I EL) * SCALE) CALL SCLI NE( Xpawet , Ypawet , Xpawet , Ypawet ) ENDDO ENDDO ENDI F

C Mai n r ay l oop: DO 500 I = 1, NRAYS CALL TKHI T( KEY) CALL PI NT( ’ Pat h % ‘ , I ) CURREL = 1

C Cor r ect i ni t i al el ect r on ener gy by pot ent i al at cur r ent poi nt Zi ni t = X00* SCALE Ri ni t = Y00* SCALE VPP = VP + SQRT( 2* LI NPOT( Zi ni t , Ri ni t ) * EMR)

C Set up i ni t i al condi t i ons YST( 1) = VPP* COS( THETAR) YST( 2) = VPP* SI N( THETAR) YST( 3) = Zi ni t YST( 4) = Ri ni t DXSAV = H1 WRI TE( 23, * ) YST( 1) * * 2+YST( 2) * * 2, LI NPOT( Zi ni t , Ri ni t ) , EMR WRI TE( 23, * ) VP, VPP

C I nt egr at i on l oop f or each pat h. I ni t i al i s i ng: KOUNT = 1 I NTK = - 1 t i me = 0. 0d0 OUT = . FALSE. CROSSED = . FALSE.

C St or e i ni t i al condi t i ons and set up cal c ar r ay:

42

Page 43: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

DO J=1, NP Y( J) =YST( J) YP( J, KOUNT) =Y( J) ENDDO Hmi n = 0. 0d0c Hmi n = Hi ni t * er r s Hmax = Hi ni t * r esl ut n H1 = Hmax/ 2. 0d0

C Mai n l oop over t he i nt egr at i on f or a s i ngl e r ay: 400 OLDKOUNT=KOUNT

C Fi nd t he appr oxi mat i on t o t he pot ent i al sur f ace at Z, R: CALL MeshSpl i ne( Y, OUT)

C Hammi ng Pr edi ct or - Cor r ect er : CALL HPCD( Y, NP, H1, Hmax, Hmi n, er r s, I NTK)

C I ncr ement t he t i me count er : t i me=t i me+H1

C Do we have a new r ay sect i on? KOUNT=I NT( t i me/ Hmax) +2 I F ( KOUNT. NE. OLDKOUNT) THEN

C St or e el ect r on pat h i n an ar r ay: DO J=1, NP YP( J, KOUNT) =Y( J) ENDDO

C Pl ot new l i ne sect i on: CALL SCLI NE( YP( 3, KOUNT- 1) , YP( 4, KOUNT- 1) , YP( 3, KOUNT) , YP( 4, KOUNT) )

C Check f or cr oss- over : s i gn1 = SI GN( 1, YP( 4, KOUNT) ) s i gn2 = SI GN( 1, YP( 4, KOUNT- 1) ) I F ( s i gn1. NE. si gn2. AND. ( THETAR. GT. 0. 0. OR. Ri ni t . NE. 0. 0) ) THEN Sl ope = ( YP( 4, KOUNT- 1) - YP( 4, KOUNT) ) + / ( YP( 3, KOUNT- 1) - YP( 3, KOUNT) ) I nt er = YP( 4, KOUNT) - Sl ope* YP( 3, KOUNT) I nt er = - ( I nt er / Sl ope) / SCALE I F ( . NOT. CROSSED) THEN I CROSS = I CROSS + 1 CROSSZ( I CROSS) = I nt er CROSSLOPE( I CROSS) = Sl ope CROSSED = . TRUE. ELSE I F ( I nt er . GT. CROSSZ( I CROSS) ) CROSSZ( I CROSS) =I nt er CROSSLOPE( I CROSS) = Sl ope ENDI FC Out put cr oss- over t o user : CALL PREAL( ’ Xover at z = F%6. 2 cm ‘ , CROSSZ( I CROSS) )c CALL PREAL( ’ ! 40Sl ope =F%6. 4 $’ , REAL( SLOPE) ) ENDI F

C End of new- sect i on I F const r uct : ENDI F

C I f t he el ect r on has l ef t t he syst em, qui t t he l oop:c I F ( OUT) WRI TE( * , * ) ‘ PATHS: OUT’ I F ( OUT) GOTO 410

C Check f or escape key: CALL TKHI T( KEY)c I F ( KEY. EQ. 27) WRI TE( * , * ) ‘ PATHS: ESC’ I F ( KEY. EQ. 27) GOTO 410

C Loop back t hr ough i nt egr at i on. . . GOTO 400

C Pl ot t he mi r r or i mage pat h 410 KEY=0 WRI TE( 23, * ) WRI TE( 24, * )

43

Page 44: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

WRI TE( 25, * ) WRI TE( * , * ) KOUNT DO 449 J=1, KOUNT 449 CONTI NUEC Wr i t e mi r r or ed pat h t o f i l e and pl ot i t t oo: DO 450 J=2, KOUNT- 1 CALL SCLI NE( YP( 3, J- 1) , - YP( 4, J- 1) , YP( 3, J) , - YP( 4, J) ) 450 CONTI NUE

C Wr i t e t r aj ect or i es t o dat a f i l e ‘ <NAME>. TRJ’ : CALL WRTRAJ( NRAYS, I )

C Wr i t e t he number of poi nt s i n t hi s r ay t o t he scr een: CALL PI NT( ’ % pt s$’ , KOUNT)

C I f escape has been pr essed, t hen qui t f r om PATHS: CALL TKHI T( KEY) I F ( KEY. EQ. 27) GOTO 600

C I ncr ease r ay l aunch angl e: 490 THETAR = THETAR + DTHETAR 500 CONTI NUE

C End: 600 CLOSE( UNI T=23) CLOSE( UNI T=24) CLOSE( UNI T=25) RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE RungeKut t a( Y, NP, h, hmi n, hmax, er r s, I NTK)$i ncl ude: ‘ l ens. def ’ $i ncl ude: ‘ t r aj ec. def ’

REAL* 8 Y( 4) , Y1( 4) , Y2a( 4) , Y2b( 4) , DYDX( 4) , h REAL* 8 hmi n, hmax, er r s, Der r I NTEGER I , I NTK, FLAG

C Once wi t h st ep = h: 17 FLAG=0 CALL RK4( Y, DYDX, NP, 0. 0d0, h, Y1)C And t wi ce wi t h st ep = h/ 2: CALL RK4( Y, DYDX, NP, 0. 0d0, 0. 5d0* h, Y2a) CALL RK4( Y2a, DYDX, NP, 0. 0d0, 0. 5d0* h, Y2b)

I F ( I NTK. EQ. - 2) THENC Adapt i ve ext r apol at i ve RK er r or l evel check: DO I =1, NP Der r =Y2b( I ) - Y1( I ) I F ( Der r . GE. er r s . AND. 0. 5d0* h. GT. hmi n) FLAG=1 I F ( Der r . LT. 0. 02d0* er r s . AND. 2. 0d0* h. LT. hmax) FLAG=2 ENDDO ENDI F I F ( FLAG. EQ. 1) h=0. 5d0* h I F ( FLAG. EQ. 2) h=2. 0d0* h

C I F st epsi ze has changed, r edo l ast st ep:c I F ( FLAG. NE. 0) GOTO 17

C Ext r apol at e: DO I =1, NP Y( I ) =Y2b( I ) +( 1. 0d0/ 15. 0d0) * ( Y2b( I ) - Y1( I ) )C Or nor mal Runge- Kut t a:c Y( I ) =Y1( I ) ENDDO

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE HPCD( Y, NP, h, hmax, hmi n, er r s, I NTK)$i ncl ude: ‘ l ens. def ’ $i ncl ude: ‘ t r aj ec. def ’

44

Page 45: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

REAL* 8 Y( 4) , DYDX( 4) , h, Yol d( 4) , DQDX( 4) REAL* 8 DH( 4, - 8: 1) , DYH( 4, - 8: 1) , Del ( 4) , P( 4) , Q( 4) REAL* 8 DH2( 4, - 8: 1) , DYH2( 4, - 8: 1) , Yt ( 4) REAL* 8 er r s, hmax, hmi n I NTEGER I , J, I NTK, RKSTPS, FLAG COMMON / HPCDBK/ DH, DYH, Del

C I ni t i al i s i ng et cet er a:c RKSTPS = 5 RKSTPS = 3 I F ( I NTK. EQ. - 1) THEN DO I =1, NP DO J=- RKSTPS, 1 DH( I , J) =0. 0d0 DYH( I , J) =0. 0d0 ENDDO ENDDO I NTK=0 ENDI F

C Fi r st shi f t t he el ement s of t he hi st or y ar r ays: DO I =1, NP DO J=- RKSTPS, 0 DH( I , J) =DH( I , J+1) DYH( I , J) =DYH( I , J+1) ENDDO Yol d( I ) =Y( I ) ENDDO

C Use t hi s l i ne f or ext r apol at i ve RK: I NTK=0C Use t hi s l i ne t o use adapt i ve RK:c I NTK=- 2 C Now use Runge- Kut t a or Hammi ng dependi ng on st eps t aken: 10 FLAG = 0 I F ( I NTK. LE. RKSTPS) THEN CALL RungeKut t a( Y, NP, h, hmi n, hmax, er r s, I NTK) CALL DERI VS( Y, DYDX) DO I =1, NP DH( I , 1) =Y( I ) - Yol d( I ) DYH( I , 1) =DYDX( I ) Del ( I ) =0. 0d0 ENDDO I NTK=I NTK+1 ELSEC Hammi ng pr edi ct or cor r ect or : 20 DO I =1, NP P( I ) =( h/ 3. 0d0) * ( 7. 0d0* ( DYH( I , 0) +DYH( I , - 2) ) + - 8. 0d0* DYH( I , - 1) ) - DH( I , - 2) Q( I ) =Y( I ) +P( I ) +( 116. 0d0/ 125. 0d0) * Del ( I ) ENDDO CALL DERI VS( Q, DQDX) DO I =1, NP DYH( I , 1) =DQDX( I ) DH( I , 1) =( 1. 0d0/ 8. 0d0) * ( DH( I , 0) +DH( I , - 1) +3. 0d0* h + * ( DYH( I , 1) +2. 0d0* DYH( I , 0) - DYH( I , - 1) ) ) Del ( I ) =DH( I , 1) - P( I )C Change i nt egr at i on st ep or car r y on: I F ( Del ( I ) . GE. er r s . AND. 0. 5d0* h. GE. hmi n) FLAG=1 I F ( Del ( I ) . LT. 0. 02d0* er r s . AND. 2. 0d0* h. LE. hmax) FLAG=2 I F ( FLAG. EQ. 0) THEN DH( I , 1) =DH( I , 1) - ( 9. 0d0/ 125. 0d0) * Del ( I ) Y( I ) =Y( I ) +DH( I , 1) ENDI F ENDDO ENDI F

C Under st epsi ze change condi t i on, r ear r ange dat a t o r epeat cal c: I F ( FLAG. EQ. 1) THENc DO I =1, NPc DH2( I , - 1) =( 176. 0d0* DH( I , 0) +41. 0d0* DH( I , - 1) +DH( I , - 2) ) / 256. 0d0c + - h* ( - 15. 0d0* DYH( I , 0) +90. 0d0* DYH( I , - 1) +15. 0d0* DYH( I , - 2) ) / 256. 0d0

45

Page 46: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

c DH2( I , - 2) =DH( I , - 1)c DH2( I , - 3) =( - 112. 0d0* DH( I , 0) +109. 0d0* DH( I , - 1) +DH( I , - 2) ) / 256. 0d0c + - h* ( 3. 0d0* DYH( I , 0) +54. 0d0* DYH( I , - 1) - 27. 0d0* DYH( I , - 2) ) / 256. 0d0c DH2( I , - 4) =DH( I , - 2)c Del ( I ) =0. 0d0c ENDDOc DO I =1, NPc DO J=0, - 2, - 1c DH( I , J) =DH2( I , J)c Yt ( I ) =DH2( I , J)c CALL DERI VS( Yt , DYDX)c DYH( I , J) =DYDX( I )c ENDDOc ENDDO h=0. 5d0* hc I NTK=RKSTPS+1 I NTK=0 ENDI F I F ( FLAG. EQ. 2) THENc DO I =1, NPc DO J=0, - 2, - 1c DH( I , J) =DH( I , J* 2)c DYH( I , J) =DYH( I , J* 2)c ENDDOc Del ( I ) =0. 0d0c ENDDOc h=2. 0d0* hc I NTK=RKSTPS+1 I NTK=0 ENDI F

C I F st epsi ze has changed, r edo l ast st ep: I F ( FLAG. NE. 0) GOTO 10

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE MeshSpl i ne( Y, OUT)$i ncl ude: ‘ l ens. def ’ $i ncl ude: ‘ t r aj ec. def ’ PARAMETER ( MMAX=10, NMAX=20) REAL* 8 Z, R, Y( 4) , LI NPOT REAL* 8 ZC, RC, negZ, posZ, negR, posR REAL* 8 nCz( MMAX) , nCr ( MMAX) , nZ( NMAX) , nR( NMAX) REAL* 8 nPz( NMAX) , nPr ( NMAX) , noksc REAL* 8 nZm, pZm, nRm, pRm, El k, Pot , chi sq, s i gz( NMAX) , si gr ( NMAX) I NTEGER CEL, NN( 3) , nt h, nok LOGI CAL OUT, NEG, AXI S CHARACTER* 1 POSN EXTERNAL LI NPOT COMMON / SPLI N/ nt h, nCz, nCr OUT = . FALSE. NEG = . FALSE. ma = 4

C SVD poi nt par amet er : nok = 2* maC Spl i ne poi nt par amet erc nok = ma

nt h = ma noksc = 1. 75d0* ( DBLE( nok) / 2. 0d0) Z = Y( 3) R = Y( 4) I F ( R. LT. 0. 0) THEN NEG = . TRUE. ENDI F DO I =1, NMAX s i gz( I ) =1. 0d0 s i gr ( I ) =1. 0d0 ENDDO

46

Page 47: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

C Fi nd el ement number whi ch el ect r on occupi es CALL FI NDEL( Z, ABS( R) , CEL, OUT)

C Fi nd near est nei ghbour el ement s CALL FI NDNN( CEL, NN, POSN) C Fi nd Z and R r anges such t hat pol yn. appr ox. cover s mor e t han one el ement posZ=+1. 0d- 20 negZ=- 1. 0d- 20 posR=+1. 0d- 20 negR=- 1. 0d- 20 AXI S=. FALSE. DO i =1, 3 I F ( POSN. EQ. ’ F’ . AND. NN( i ) . EQ. 0) WRI TE( * , * ) POSN I F ( POSN. EQ. ’ A’ . AND. NN( i ) . EQ. 0) THEN CALL FI NDELCENT( CEL, ZC, RC) AXI S=. TRUE. RC=- RC NN( i ) =CEL ELSE CALL FI NDELCENT( NN( i ) , ZC, RC)c CALL SCLI NE( ZC, RC, ZC, RC) ENDI F I F ( NEG) RC=- RC ZC=ZC- Z RC=RC- R I F ( ZC. GT. posZ) posZ = ZC I F ( ZC. LT. negZ) negZ = ZC I F ( RC. GT. posR) posR = RC I F ( RC. LT. negR) negR = RC ENDDO

C Asymmet r i c spl i ne axi al symmet r y f i x :c I F ( AXI S) negR=- posRC Symmet r i c spl i ne span aver agi ng: posR=noksc* ( ABS( posR) +ABS( negR) ) / 2. 0d0 posZ=noksc* ( ABS( posZ) +ABS( negZ) ) / 2. 0d0 negR=- posR negZ=- posZ

C Fi nd t he mi ni mum span si ze at t he cur r ent poi nt and check t hatC t he cur r ent spl i nes f i t wi t hi n i t : CALL Mi nSpl i n( Z, R, nZm, pZm, nRm, pRm) I F ( negZ. LT. nZm) negZ=nZm I F ( posZ. GT. pZm) posZ=pZm I F ( posR. GT. pRm) posR=pRm

C Const r uct t he t wo pol ynomi al appoxi mat i ons t o t he pot ent i al : DO i =1, nokC Symmet r i c spl i ne def : nZ( i ) =Z+negZ+DBLE( i - 1) * ( ABS( posZ) +ABS( negZ) ) / DBLE( nok- 1) nPz( i ) =LI NPOT( nZ( i ) , R) nR( i ) =R+negR+( i - 1) * ( ABS( posR) +ABS( negR) ) / ( nok- 1) nPr ( i ) =LI NPOT( Z, nR( i ) )C Asymmet r i c spl i ne def :c nZ( i ) =Z+noksc* negZ+noksc* ( i - 1) * ( posZ- negZ) / ( nok- 1)c nPz( i ) =LI NPOT( nZ( i ) , R)c nR( i ) =R+noksc* negR+noksc* ( i - 1) * ( posR- negR) / ( nok- 1)c nPr ( i ) =LI NPOT( Z, nR( i ) ) ENDDO

C Pl ot spans of spl i nes on t he scr een:cc DO i =1, nokcc CALL SCLI NE( nZ( i ) , R, nZ( i ) , R)cc CALL SCLI NE( Z, nR( i ) , Z, nR( i ) ) cc ENDDOcc CALL SCLI NE( Z, R, Z, R)

C Fi nd t he appr oxi mat i on coef f i c i ent s:c CALL nt happr ox( nok, nZ, nPz, nCz)c CALL nt happr ox( nok, nR, nPr , nCr )

C Fi nd t he pol ynomi al coef f i c i ent s v i a l east - sqr s SVDecomp: CALL SVDFI T( nZ, nPz, si gz, nok, nCz, ma, chi sq, 1)

47

Page 48: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

CALL SVDFI T( nR, nPr , s i gr , nok, nCr , ma, chi sq, 1) RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE DERI VS( Y, DYDX)$i ncl ude: ‘ l ens. def ’ $i ncl ude: ‘ t r aj ec. def ’ PARAMETER ( NMAX=10) DI MENSI ON nCz( NMAX) , nCr ( NMAX) REAL* 8 Y( 4) , DYDX( 4) , EZP, ERP, nCz, nCr , ZC, RC, Pot , LI NPOT, vsq I NTEGER nt h, CEL, NN( 3) , cycl e LOGI CAL OUT, DATOUT CHARACTER* 1 POSN COMMON / SPLI N/ nt h, nCz, nCr COMMON / TEMP/ cycl e EXTERNAL LI NPOT

C Fl ag f or det ai l ed t r aj ect or y out put : DATOUT=. TRUE. C Fi nd di f f er ent i al of el ect r i c f i el d at Z, R f r om pol yn. appr ox. CALL nt hadi f f ( nt h, nCz, Y( 3) , EZP) CALL nt hadi f f ( nt h, nCr , Y( 4) , ERP) CALL nt haeval ( nt h, nCz, Y( 3) , Pot )

C Ol d st y l e l i near gr adi ent code:c CALL FI NDEL( Y( 3) , ABS( Y( 4) ) , CEL, OUT)c CALL FI NDNN( CEL, NN, POSN)c CALL GRAD( CEL, EZP, ERP, ZC, RC, POSN)c Pot =LI NPOT( Y( 3) , Y( 4) )

C Check by pot out put I F ( DATOUT) THEN cycl e=cycl e+1 I F ( cycl e. GT. 25) THEN vsq=Y( 1) * * 2+Y( 2) * * 2 WRI TE( 23, 131) Y( 3) , Pot , EZP WRI TE( 24, 131) Y( 4) , Pot , ERP WRI TE( 25, 132) t i me, Pot - vsq/ ( 2. 0d0* EMR) cycl e=1 ENDI F ENDI F 131 FORMAT( 2F14. 6, E13. 5) 132 FORMAT( 2E14. 6)

C Ret ur n i nf or mat i on t o i nt egr at i on r out i nes i n t he r equi r ed f or mat . DYDX( 1) = EMR* EZP DYDX( 2) = EMR* ERP DYDX( 3) = Y( 1) DYDX( 4) = Y( 2)

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE Mi nSpl i n( X, Y, nXm, pXm, nYm, pYm)$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ REAL* 8 X, Y, nXm, pXm, nYm, pYm, Ex1, Ey1, Ex2, Ey2 REAL* 8 Xt st , Yt st , Del t X, Del t Y, Gr ad I NTEGER I , Si gn

nXm=XMI N* SCALE- X pXm=XMAX* SCALE- X nYm=YMI N* SCALE- Y pYm=YMAX* SCALE- Y

C Loop over el ect r odes: DO I = 1, TEDT

48

Page 49: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

Ex1 = ETDE1X( I ) * SCALE- X Ex2 = ETDE2X( I ) * SCALE- X Ey1 = ETDE1Y( I ) * SCALE- Y Ey2 = ETDE2Y( I ) * SCALE- Y Del t X = Ex2- Ex1 Del t Y = Ey2- Ey1C Check f or new y- mi n/ y- max: Si gn = DSI GN( 1, Ex1) + DSI GN( 1, Ex2) I F ( Si gn. EQ. 0. AND. ( Del t X. GT. 0. 0d0. OR. Del t X. LT. 0. 0d0) ) THEN Gr ad = Del t Y/ Del t X Yt st = Ey1 - Gr ad* Ex1 I F ( Yt st . GT. 0. 0d0 . AND. Yt st . LT. pYm) pYm=Yt st I F ( Yt st . LT. 0. 0d0 . AND. Yt st . GT. nYm) nYm=Yt st ENDI FC Check f or new x- mi n/ x- max: Si gn = DSI GN( 1, Ey1) + DSI GN( 1, Ey2) I F ( Si gn. EQ. 0. AND. ( Del t Y. GT. 0. 0d0. OR. Del t Y. LT. 0. 0d0) ) THEN Gr ad = Del t X/ Del t Y Xt st = Ex1 - Gr ad* Ey1 I F ( Xt st . GT. 0. 0d0 . AND. Xt st . LT. pXm) pXm=Xt st I F ( Xt st . LT. 0. 0d0 . AND. Xt st . GT. nXm) nXm=Xt st ENDI F ENDDO

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE SCLI NE( z1, r 1, z2, r 2)$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ REAL* 8 z1, r 1, z2, r 2 I NTEGER px, py px=XORG+I NT( z1* XSCA/ SCALE) py=YORG+I NT( ( r 1/ SCALE- RMI N) * YSCA) CALL GMOVE( px, py) px=XORG+I NT( z2* XSCA/ SCALE) py=YORG+I NT( ( r 2/ SCALE- RMI N) * YSCA) CALL GLI NE( px, py) END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FUNCTI ON LI NPOT( X, Y) C Code f i r st f i nds t he el ement t hat X and Y l i e i n. ThenC t ake t he number N of an el ement and f i t a pl ane t o t heC t hr ee cor ner s. Then i t f i nds t he val ue of z at t he poi nt C x, y ent er ed and out put s i t f or f ur t her wor k. Used t o l i near l yC i nt er pol at e V f or t he el ement N.

$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ I NTEGER N, I , J REAL* 8 X, Y, LI NPOT REAL* 8 AX( 3) , AY( 3) , AZ( 3) LOGI CAL ELOUT, YNEG

I F ( Y. LT. 0. 0) THEN Y = - Y YNEG=. TRUE. ELSE YNEG=. FALSE. ENDI F

CALL FI NDEL( X, Y, N, ELOUT) DO I = 1, 3 J = ELCONN( I , N) AX( I ) = POI NTX( J) * SCALE AY( I ) = POI NTY( J) * SCALE AZ( I ) = F( J) ENDDO

49

Page 50: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

CALL PLANE( AX, AY, AZ, X, Y, LI NPOT)

I F ( YNEG) Y = - Y RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE FI NDELCENT( N, ZC, RC)$i ncl ude: ‘ l ens. def ’$i ncl ude: ‘ t r aj ec. def ’ I NTEGER N REAL* 8 ZC, RCC ZC=0. 0d0 RC=0. 0d0 DO i =1, 3 j =ELCONN( i , N) ZC=ZC+POI NTX( j ) * SCALE RC=RC+POI NTY( j ) * SCALE ENDDO ZC=ZC/ 3. 0d0 RC=RC/ 3. 0d0C END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE nt hadi f f ( N, C, x, dy) PARAMETER ( NMAX=10) DI MENSI ON C( NMAX) I NTEGER N REAL* 8 C, x, dyC dy=0. 0d0 DO i =2, N dy=dy+C( i ) * ( i - 1) * ( x* * ( i - 2) ) ENDDOC END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE nt haeval ( N, C, x, y) PARAMETER ( NMAX=10) DI MENSI ON C( NMAX) I NTEGER N REAL* 8 C, x, yC y=C( 1) DO i =2, N y=y+C( i ) * ( x* * ( i - 1) ) ENDDOC END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE nt happr ox( N, X, Y, C) PARAMETER ( NMAX=10) DI MENSI ON X( NMAX) , Y( NMAX) , C( NMAX) , A( NMAX, NMAX) , B( NMAX, NMAX) I NTEGER N REAL* 8 X, Y, C, A, BC DO j =1, N A( j , 1) =1. 0d0 DO i =2, N A( j , i ) =X( j ) * * ( i - 1) ENDDO B( j , 1) =Y( j ) ENDDOC CALL GAUSSJ( A, N, NMAX, B, 1, NMAX)C DO j =1, N C( j ) =B( j , 1) ENDDO

50

Page 51: Development of software for the computation of the ...finite element method, and the optical behaviour determined by paraxial ... optics theory is the paraxial approximation, and added

C END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE FUNCS( X, P, NP, I ) I MPLI CI T REAL* 8 ( a- h, o- z) PARAMETER( NMAX=20, MMAX=10) REAL* 8 P( NMAX) I NTEGER I , J

C St andar d nt h or der pol ynomi al : I F ( I . EQ. 1) THEN P( 1) =1. 0d0 DO J=2, NP P( J) =P( J- 1) * X ENDDOC Abber at i on pol ynomi al of f or m 1 - t an2( x) - t an4( x) - . . . : ELSEI F ( I . EQ. 2) THEN P( 1) =1. 0d0 DO J=2, NPc P( J) =- ( DTAN( X) ) * * ( 2* ( J- 1) ) P( J) =- ( X* * ( 2* ( J- 1) +1) ) / ( TAN( X) ) ENDDO ENDI F

RETURN END

C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -C Rout i nes adapt ed f r om Pr ess et al :C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE GAUSSJ( A, N, NP, B, M, MP)C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE RK4( Y, DYDX, N, X, H, YOUT)C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE SVDFI T( X, Y, SI G, NDATA, A, MA, CHI SQ, I FUNC)C- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE SVBKSB( M, N, B, X)C- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE SVDVAR( MA, CVM)C- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SUBROUTI NE SVDCMP( A, M, N)C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -C End of TRAJEC. FOR

51