Navigation: Tutorials and Examples > Spatially Resample Scalar Field in Script

 

Spatially Resample Scalar Field in Script

 

Contact Us: fredsupport@photonengr.com

 

 

 

Description


The Resample feature computes the scalar complex field from an existing coherent rayset and creates a new scalar coherent rayset on a rectilinear grid defined by a user-selected Analysis Surface grid spacing. Field resampling provides an essential solution to troublesome issues encountered with coherent sources.

 

 

Script Command Syntax


The script command for Field Resampling contains arguments which correlate one-to-one with the dialog box options.

 

nrays = SpatiallyResampleScalarField( nAna, RefWfShp, RefWfPrm, NumGuess, ReplRays, dRelPowCut, nEnt, nMat, FldFil, ResFldFil, NRaysDel, MeritVal )

 

nAna

Node number of Analysis Surface. The Analysis Surface must be "attached" to the surface on which the rays to be resampled currently reside. All Ray Specifications on the Analysis Surface are implemented.

RefWfShp

Type of wavefront specification: 0 for tilt vector and curvature, 1 for sphere XYZ center. If the fitting algorithm is used (NumGuess<>0), this variable determines the dimension of the array RefWfPrm and the whether the array holds tilt vector and curvature, or sphere XYZ center.

RefWfPrm()

Double precision array containing wavefront parameters. This array can function as input or output. If used as input, the array must be properly dimensioned before use. The dimension of the array depends upon RefWfShp. For RefWfShp = 0, the array has four elements; elements 0 through 2 contain the X,Y,Z tilt vector and element 3 contains the wavefront curvature. For RefWfShp = 1, the array has three elements; elements 0 through 2 contain the sphere X,Y,Z center coordinates. The tilt vector and the sphere center coordinates are given in the coordinate system of the Analysis Surface node nAna.

NumGuess

Number of guesses allowed during wavefront fitting. For NumGuess=0, fitting is disabled. In this case, RefWfPrm must be dimensioned correctly and supplied values consistent with RefWfShp.

ReplRays

Flag enabling deletion of old rays after new rays are created. True=delete old rays, False=do not delete old rays.

dRelPowCut

Rays are not created at pixel locations when the field magnitude falls below this cutoff value relative to the field power maximum.

nEnt

Node number of entity rays are associated with after creation.

nMat

Immersion material identifier for new rayset.

FldFil

File name (*.fgd) where the scalar field of the original rayset will be stored. If a null string is used, no file is written.

ResFldFile

File name (*.fgd) where the residual scalar field will be stored. This residual is the difference between the original scalar field and the field after wavefront parameters have been removed. If a null string is used, no file is written.

NRaysDel

Number of rays deleted.  Only rays used in the calculation will be deleted.

MeritVal

Value of merit function when wavefront fitting option is invoked.

 

 

Application Notes


Tilt vector and sphere center

The tilt vector and sphere center for the reference wavefront are specified in the coordinate system of the selected Analysis Surface.

 

 

Beamlet overlap

The Beam overlap factor for each resampled coherent ray is 1.5 and is not directly adjustable by the user.

 

 

Analysis surface sizing

Upon resampling, a coherent ray is created at the center of each pixel of the selected Analysis Surface. Consideration must therefore be given to Analysis Surface pixel spacing with respect to the fundamental limitations of complex raytracing. As a general rule, the pixel spacing should be much greater than a wavelength to avoid coherent ray errors related to Invariant violations or secondary ray failures. For more information on this topic, see Introduction to Coherent Sources.

 

 

Examples


The following are several examples illustrating the implementation of the Field Resample feature using the geometry shown below. Each example uses a different form of SpatiallyResampleScalarField. Note that in each case, rays must be traced to a tilted surface to which an Analysis Surface is "attached" before the Field Resampling can be performed.

 

 

 

Example 1 - Auto determine tilt and curvature

Trace to the surface "Geometry.tilted.Surf 1" with an Analysis Surface "tilted plane in converging space" attached using the Advanced Raytrace option. Allow FRED to auto-determine tilt and/or field curvature using up to 150 guesses. Delete the old rayset and create a new rayset of dimensions and spatial sampling matching "tilted plane in converging space" with a beamlet at each pixel site. Continue trace to "Geometry.image.Surf 2".

 

Dim art As T_ADVANCEDRAYTRACE

Dim id As Long, ida As Long, count As Long

Dim rc As Long, wfpar() As Double, fname1 As String, fname2 As String, nD As Long, mV As Double

 

fname1=GetDocDir() & "\field.fgd"   :  fname2=GetDocDir() & "\residfield.fgd"

 

InitAdvancedRayTrace(art)

id = FindFullName("Geometry.tilted.Surf 1")

ida = FindName("tilted plane in converging space")

 

art.stopSurfID = id

count = AdvancedRaytrace(art)

 

rc = SpatiallyResampleScalarField(ida,0,wfpar,150,True,0,id,FindMaterial("Air"),fname1,fname2,nD,mV)

 

Print nD & " old rays deleted, " & rc & " new rays created"

For i=0 To UBound(wfpar)

 Print wfpar(i)

Next i

Print "Merit Function= " & mV

 

TraceExistingDraw

 

 

Example 2 - Using Best Geometric Focus to determine the reference sphere 

Trace ray through a lens to the surface "Geometry.tilted.Surf 1" with an Analysis Surface "tilted plane in converging space" attached using the Advanced Raytrace option. Compute best focus in the coordinate system of "tilted plane in converging space" for use as sphere center coordinates X Y and Z. Delete the old rayset and create a new rayset of dimensions matching "tilted plane in converging space" and a beamlet at each pixel site. Continue trace to "Geometry.image.Surf 2".

 

Dim art As T_ADVANCEDRAYTRACE

Dim bf As T_BESTFOCUS

Dim id As Long, ida As Long, count As Long

Dim rc As Long, wfpar(2) As Double, fname1 As String, fname2 As String, nD As Long, mV As Double

Dim x As Double, y As Double, z As Double

 

fname1=GetDocDir() & "\field.fgd"   :  fname2=GetDocDir() & "\residfield.fgd"

 

InitAdvancedRayTrace(art)

id = FindFullName("Geometry.tilted.Surf 1")

ida = FindName("tilted plane in converging space")

 

art.stopSurfID = id

count = AdvancedRaytrace(art)

 

BestFocus id, ida, bf

wfpar(0)=bf.x : wfpar(1)=bf.y : wfpar(2)=bf.z

 

rc = SpatiallyResampleScalarField(ida,1,wfpar,0,True,0,id,FindMaterial("Air"),fname1,fname2,nD,mV)

Print nD & " old rays deleted, " & rc & " new rays created"

 

TraceExistingDraw

 

 

Example 3 - Using Best Geometric Focus to determine reference sphere and tilt 

Trace rays to "Geometry.tilted.Surf 1" with Analysis Surface "tilted plane in converging space" attached using the Advanced Raytrace option. Find the tilt vector in the coordinate system of "tilted plane in converging space" and the curvature using BestFocus. Delete the old rayset and create a new rayset of dimensions matching "tilted plane in converging space" and a beamlet at each pixel site. Continue trace to "Geometry.image.Surf 2".

 

Dim art As T_ADVANCEDRAYTRACE

Dim bf As T_BESTFOCUS

Dim cs As T_COORDSYS

Dim id As Long, ida As Long, idp As Long, count As Long, n As Long

Dim rc As Long, wfpar(3) As Double, fname1 As String, fname2 As String, nD As Long, mV As Double

Dim a As Double, b As Double, c As Double, crv As Double

 

fname1=GetDocDir() & "\field.fgd"   :  fname2=GetDocDir() & "\residfield.fgd"

 

InitAdvancedRayTrace(art)

id = FindFullName("Geometry.tilted.Surf 1")

ida = FindName("tilted plane in converging space")

idp = FindFullName("Geometry.image.Surf 2")

 

art.stopSurfID = id

count = AdvancedRaytrace(art)

 

GetCoordSys ida, cs

BestFocus id, -1, bf

 

a = bf.x-cs.PositionX : b = bf.y-cs.PositionY : c = bf.z-cs.PositionZ

crv = 1/Sqr(a^2 +b^2 +c^2)

SetLength3D a, b, c, 1

TransformDirection -1, ida, a, b, c

 

wfpar(0) = a : wfpar(1) = b : wfpar(2) = c : wfpar(3) = crv

 

rc = SpatiallyResampleScalarField(ida,0,wfpar,0,True,0,id,FindMaterial("Air"),fname1,fname2,nD,mV)

 

TraceExistingDraw

 

 

Example 4 - Afocal Telescope

This accompanying example file, exampleSpatiallyResampleAfocalTelescope.frd, can be found in the <install dir>\Resources\Samples\Tutorials & Examples directory and illustrates FRED’s Field Resampling feature applied to the case of a Galilean afocal which truncates the input from a Nd:YAG laser with 1/e2 half-width of 1 mm. As shown below, the beam enters the 1st lens (PCV) producing a divergent ray bundle which causes significant reduction in spatial sampling at the 2nd lens (PCX). If the source is incoherent, then simply increasing ray density entering PCV addresses the problem adequately. However, if the source is coherent, an arbitrary increase in ray grid density at PCV leads to complications which will be discussed in this example.

 

 

Each ray in a coherent source is treated as a Gaussian beamlet whose radius w0 is initially determined by source ray grid spacing, an increase in ray density leads to smaller w0 at PCV and a corresponding increase in beamlet divergence which is exacerbated by the lens. To illustrate this point, Table 1 lists the number of beamlets across the PCX aperture and corresponding beamlet diameter of the center ray upon reaching lens PCX for several initial grid spacings as PCV:

 

Rays across 4mm Grid @ 1st Lens (PCV)

Rays across 2nd Lens (PCX)

Diameter of Center Beamlet @ 2nd Lens (mm)

11

3

24.5

31

9

9

51

15

6.6

101

31

8.4

201

63

15.7

Table 1

 

Note that for 11 beamlets across the PCV aperture as shown in Figure 1, a clear case of under-sampling occurs since only three beamlets span the PCX aperture. Furthermore, each of these beamlets is nearly half the diameter of the lens. Increasing the number of rays across the PCV aperture appears to lead to better sampling of PCX although, in every case, the beamlets associated with the outermost rays passing the clear aperture of PCX sample far outside its boundary. Thus, these outermost rays acquire additional aberration for which the lens is not corrected and can lead to inaccurate results. Figures 2a-e shows sample Gaussian beamlets at the edge of PCX for the five grid densities in Table 1.

 

          

          

Figure 2. Gaussian Ray Size Spot diagrams for central and edge rays at PCX for selected source ray densities;

a) 11x11, b) 31x31, c) 51x51, d) 101x101, e) 201x201 from Table 1. The blue circle represents the clear aperture of PCX.

 

The Field Resampling feature offers a solution to this predicament by resampling the incident wavefront just before entering PCX and, in effect, resizing the beamlets such that they sample its aperture . To that end, two planes are created a small distance to the left of PCX. The first of these planes “.resample.Surf 1” is transmissive and sized such that it intercepts all the rays exiting PCV. This is of utmost importance since the field will be resampled at this plane and therefore must include the coherent contribution of each and every ray. Attached to “.resample.Surf 1” are two Analysis Surfaces, “full beam before L2” and “Resample AS”. The first of these, “full beam before L2” is used simply to examine the irradiance pattern in the resample plane. The second Analysis Surface, “Resample AS” will be used for the function of resampling the beam. Note that “Resample AS” is sized slightly larger (26mm half-height) than the 25mm clear aperture of PCX since it is only over this area resampled beamlets need be created. The second surface “.resample.Surf 2” is an absorbing surface located between “.resample.Surf 1” and PCX with a rectangular Outer Trim Volume of half-height 30mm and a circular Inner Trim Volume equal to the clear aperture of PCX. The surface “.resample.Surf 2” acts to block resampled beamlets outside the aperture of PCX as would any opto-mechanical mount.

 

Returning to “Resample AS”, the number of pixels across its area determines the number and size of resampled beamlets. The user has some flexibility here. Choosing too many pixels creates highly divergent beamlets while too few pixels offers poor resolution of the lens clear aperture. In this example, the Analysis Surface “Resample AS” is assigned 101x101 pixels resulting in base ray spacing of beamlet radii of

 

 

At the wavelength l=1.064mm, the divergence half angle is 0.77mrad, well within the paraxial regime. This condition is important when considering continued propagation of the rays through subsequent optical elements.

 

Upon executing the lines of code in the Embedded script "Field Resample", the resampled rayset is created, the initial rayset is deleted and a pair of charts are generated. Figure 3a shows the chart containing the field “Energy” with automatic tilt and spherical removal method while Figure 3b shows the same chart with the field “Phase” displayed. Note in Figure 3b some residual tilt remains due to the nature of the fitting routine and is of no consequence since the same tilt/spherical terms which were subtracted are added back when the new rayset is created. The salient point is that the phase is smoothly varying having no ambiguities. If the user can supply the field curvature prior to the calculation and make use of the 2nd form of the SpatiallyResampleScalarField command (see Script Example 2 above) rather than the fitting option, this phase is symmetric and nominally flat as shown in Figure 4. In either case, the final rayset yields identical results.

 

Figure 3. Auto-determined Scalar Field calculation. a) Energy, b) Wavefront.

 

Figure 4. Scalar Field calculated with wavefront curvature predetermined from Best Focus calculation. a) Energy, b) Wavefront.

 

Figure 5a shows the chart containing the field “Energy” without tilt and spherical removed while Figure 9b shows the same chart with the field “Phase” displayed. Significant phase ambiguity is clearly illustrated by the noisy nature of the plot. Given a sufficient number of pixels, the phase in this chart would be smooth following the actual field curvature but, in practice, that pixel count would excessively large. This illustration clearly highlights the value of FRED’s Field Resampling feature.

 

 

Figure 5. Scalar Field a) “Energy” and b) “Phase” of resampled field without tilt/spherical terms removed.

 

Having generated the resampled rayset in the plane of “.resample.Surf 1”, an Advanced Raytrace is used to trace the resampled rayset to the 1st surface of PCV. Note that “.resample.Surf 2” has blocked all rays outside the 25mm clear aperture of the lens. A Gaussian Ray Size Spot Diagram at the 1st  surface of PCX is shown in Figure 6.

 

Figure 6. Gaussian Ray Size Spot Diagram of resampled rayset. Again, the blue circle represents the clear aperture of PCX.

 

 

Finally, applying the TraceExisting and Render option found under the Raytrace Main Menu continues the raytrace to its termination, the output plane “.observation.plane” as shown in Figure 7. The subsequent Scalar Field “Energy” calculation on “.observation.plane” using Analysis Surface “Obs Plane” is shown in Figure 8.

 

Figure 7. Resampled rayset traced using Trace Existing and Render

 

Figure 8. Output beam profile on observation plane.

 

 

Related Topics


SpatiallyResampleScalarField (script command)

Spatially Resample Scalar Field (GUI)

Introduction to Coherent Sources

Coherent Scalar Wave Field

Coherent Field Synthesis

 

 

 

 

 

 

 

Copyright © Photon Engineering, LLC