The purpose of this tutorial is to examine several advanced uses of TurboTrace by way of example.
system = {GaussianBeam[20,.01,NumberOfRays->51],
Move[PlanoConvexLens[100,50,10],25],
Move[Window[50,10],130]}
tracedsystem = TurboPlot[system, PlotType->TopView]
ColorView
ColorView can be used to give a pesudocolor ray map of a selected ray-parameter.
?ColorView
TurboPlot[tracedsystem,PlotType->TopView,ColorView->Intensity];
PlotRange
You can use the PlotRange option to "zoom-in" on a particular ray-traced feature of an optical system.
?PlotRange
When PlotType->TopView is used, the resulting plot is two-dimensional and the PlotRange settings must also be given as two-dimensional quantities.
TurboPlot[tracedsystem,PlotType->TopView,PlotRange->{{127,134},{-3.5,3.5}}]
Note that you also can combine PlotRange with ColorView results.
TurboPlot[tracedsystem,PlotType->TopView,PlotRange->{{127,134},{-3.5,3.5}},ColorView->Intensity]
When no PlotType is specified, the resulting plot is three-dimensional and the PlotRange settings must also be given as three-dimensional quantities.
TurboPlot[tracedsystem,PlotRange->{{127,134},{-3.5,3.5},{-1,1}}]
ReportedParameters
ReportedParameters can be used as an alternative to ReadRays to directly extract numeric results by TurboTrace.
?ReportedParameters
TurboTrace[system,ReportedParameters->{ComponentNumber,SurfaceNumber}]
As an alternative to specifying ReportedParameters as an option, TurboTrace also allows you to include parameters as a follow-on argument after the optical system argument.
TurboTrace[system,{ComponentNumber,SurfaceNumber}]
ReportedSurfaces
In TurboTrace, the surface results for final component present in the system is automatically reported. In the previous example, the final component has two optical surfaces. Consequently, the trace information from both surfaces are reported. In some cases, however, you may wish to obtain information from a single surface or a selected set of surfaces in the system. In such instances, you can use ReportedSurfaces.
?ReportedSurfaces
Here we use ReportedSurfaces->{{2,1}} to isolate specific information for the first surface (SurfaceNumber->1) of the second component (ComponentNumber->2)
TurboTrace[system,{ComponentNumber,SurfaceNumber},ReportedSurfaces->{{2,1}}]
OutputType
?OutputType
system = {GaussianBeam[20,.01,NumberOfRays->51],
Move[PlanoConvexLens[100,50,10],25],
Move[Screen[50],{x,130}]}
AnalyzeSystem[system,PlotType->TopView];
The OutputType option is used by TurboTrace to determine the format of the final result. OutputType -> Numeric is used to directly get a numeric result from the trace. In the previous examples, when the ReportedParameters option is given, OutputType -> Numeric was automatically used by TurboTrace.
TurboTrace[system, OpticalLength, OutputType->Numeric]
When iterative trace calculations are required, it is more efficient to work use RayTraceFunction ray-trace code directly rather than generating a list of numbers from TurboTrace each time. For this OutputType -> RayTraceFunction is used instead.
turboresult = TurboTrace[system,OpticalLength, OutputType->RayTraceFunction]
tracefunction = RayTraceFunction/.turboresult
Here we have stored the RayTraceFunction in the tracefunction variable. To obtain a trace-trace result, we can now evaulate this function with a value for the input x argument:
tracefunction[130.]
EmbedRays
You can use the EmbedRays option to control whether the ray source information is built into the compiled ray-trace function or left as an input argument to the function.
?EmbedRays
When different ray sources need to be separately traced through the same optical system, you can use the EmbedRays->False with TurboTrace together with OutputType->RayTrace Function.
turboresult = TurboTrace[system,OpticalLength, OutputType->RayTraceFunction, EmbedRays->False]
tracefunction = RayTraceFunction/.turboresult
Now we can separately trace with LineOfRays and GaussianBeam light sources.
tracefunction[LineOfRays[40],130.]
tracefunction[GaussianBeam[20,.01,NumberOfRays->51],130.]
ReportedFunction
ReportedFunction is used to make a user-defined calculation of the ray-trace results given from ReportedParameters.
?ReportedFunction
In the following example, we use ReportedFunction to selectively filter out ray internsities that are less than 50.
TurboTrace[system, ReportedParameters -> {OpticalLength,Intensity}, OutputType->Numeric, ReportedFunction->Function[Select[#,(#[[2]]>50)&]]]
As a different example, we use ReportedFunction to determine the average optical path length value.
TurboTrace[system, ReportedParameters -> OpticalLength, OutputType->Numeric, ReportedFunction->Function[Apply[Plus,#]/Length[#]]]
Otherwise, we can use OutputType->RayTraceFunction to be able to iteratively change the value of x.
tracefunction = RayTraceFunction/.TurboTrace[system, ReportedParameters -> OpticalLength, OutputType->RayTraceFunction, ReportedFunction->Function[Apply[Plus,#]/Length[#]]]
tracefunction[130.]
Now we can plot the average optical length as a function of x.
Plot[tracefunction[x],{x,125,135}];
Reporting vector quantities
Sometimes, you may wish to work with ray-trace parameters that contains vector quantities. If a single parameter is present, then its quantity will be reported in the usual way.
TurboTrace[system,RayTilt,OutputType->Numeric]
However, if more than one parameter is to be reported then the calculation returns a flattened list of parameter results.
TurboTrace[system,{RayTilt,Intensity,ComponentNumber,SurfaceNumber},OutputType->Numeric]
When ReportedFunction is used in such instances, it is important to the flattened listing into account. In the following example, the Intensity parameter appears in the 4th position of the reported parameter result.
TurboTrace[system,OutputType->Numeric,ReportedParameters->{RayTilt,Intensity},ReportedFunction->Function[Select[#,#[[4]]>50&]], ReportedSurfaces->{{2,1}}]
In this case, the ReportedFunction must address the Intensity parameter as #[[4]] rather than #[[2]].
ConstructMeritFunction
You can use ConstructMeritFunction to produce a RayTraceFunction that directly the caculates the ray-trace spot size.
?ConstructMeritFunction
?MeritType
ConstructMeritFunction provides a short-hand way of specifies a suitable ReportedParameters and ReportedFunction for merit-related calculations. We will now consider two separate examples to use ConstructMeritFunction.
SphericalMirror example
sys = {Move[WedgeOfRays[4,NumberOfRays->11],{0,{y,0}}],Move[SphericalMirror[-500,50],500],Screen[50]};
AnalyzeSystem[sys,PlotType->TopView];
merit = ConstructMeritFunction[sys,MeritType->RMSFocus]
tracefunction = RayTraceFunction/.merit
Plot[tracefunction[y],{y,0,6}];
ParabolicMirror example
sys = {Move[WedgeOfRays[4,NumberOfRays->11],{0,{y,0}}],Move[ParabolicMirror[250,50],250],Move[ParabolicMirror[250,50],100,180],Move[Screen[50],350]};
AnalyzeSystem[sys,PlotType->TopView];
Options[ConstructMeritFunction]
merit = ConstructMeritFunction[sys,MeritType->RMSFocus]
tracefunction = RayTraceFunction/.merit
Plot[tracefunction[y],{y,0,6}];
Saving your results
Sometimes it is helpful to be able to save your intermediate results to a file on the hard disk. This allows you to recover your ray-trace data analysis in a future work session without having to re-calculate it. You can do this with the Put and Get commands.
?Put
?Get
As an example, we will take the results from TurboPlot below and store it on a disk.
results = TurboPlot[{LineOfRays[45],Move[PlanoConvexLens[{f,100},50,10],50],Boundary[170]},PlotType->TopView]
Before storing the file, we will use SetDirectory to set the current working directory of the system.
?SetDirectory
$HomeDirectory
SetDirectory[$HomeDirectory]
Next we use Put to write a file on the disk with our results.
Put[results,"lenssystem"]
Finally, we can use Get to recover the results calculation from the disk.
newresults = Get["lenssystem"]
We are now able to start working once again with our previous results.
TurboPlot[newresults,PlotType->TopView,SymbolicValues->{f->75}];
Created by Mathematica (July 29, 2005)