讲义参考讲稿day_第1页
讲义参考讲稿day_第2页
讲义参考讲稿day_第3页
讲义参考讲稿day_第4页
讲义参考讲稿day_第5页
已阅读5页,还剩96页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Programming ZemaxUser-Defined Surfaces2 - 2 User-Defined SurfaceUser-defined surfaces (UDS) are sequential surfaces defined in external programsPowerful capability for defining unique surfaces that arent built-inUDS can be:Refractive, reflective or diffractiveAny shape or size Any phase profileAny t

2、ransmission profileAny index profileAny polarization propertiesNearly all properties of a UDS are user-definable!2 - 3 UDS DetailsAll the code that defines a UDS is contained in a separate program, compiled as a “Dynamic Link Library” (DLL)UDS DLLs are placed in Program FilesZemaxDLLSurfaces“User De

3、fined” is a surface type that can be defined on any surfaceZemax calls the DLL whenever ray-tracing to the surface is required, or when Zemax needs any specific data from the DLLCompiled and linked DLLs are nearly as fast as internally compiled (built-in) surfaces (tiny overhead for calling the DLL)

4、Easily disseminated without revealing source code2 - 4 UDS RequirementsTo define a UDS requires:Some C/C+ programming experienceCould use Delphi, Visual BasicA suitable C/C+ compilerBorland, Microsoft and all make cheap compilersA clear vision how to define your surface mathematicallyPatience and TL

5、C!Zemax gives you full control over the program while within your DLLZemax cannot prevent program crashes, loss of data, or erroneous results in your code!We do write custom DLLs for users without the time or experience to do so themselves2 - 5 Dynamic Link LibraryA DLL is a Windows program that can

6、not run directly (like an EXE) but which is called by another program (could be an EXE or another DLL)Can be considered a function called by a programA DLL is called as required, and then closed when finishedMakes programs efficient because memory is only used when the DLL is required2 - 6 Starting

7、DataTo begin with, the DLL must give Zemax:The names of all parameter and extra data editor columns to be usedThe “safe” data to be used by default when the surface is first loaded (i.e. radius = infinity, conic = 0, etc.) 2 - 7 Input and OutputZemax treats UDS as a “black box”Zemax provides: Ray st

8、arting coordinates x,y,z on plane tangent to surface vertexRay direction cosines l,m,nThe wavelengthThe raytrace mode: real or paraxialAll data from LDE and EDEDLL returns:The x,y,z intercept coordinates at exact surfaceThe l,m,n departure direction cosinesThe optical path added or subtracted from t

9、he raySag data when requested by the layout drawingsError codes, if necessaryThe supplied UDS are excellent templates! (more soon)Programming ZemaxAnatomy of a UDS2 - 9 USERSURF.HUSERSURF.H is a header file that contains definitions of the ray and surface properties that your DLL can access Located

10、in Program FilesZemaxDLLSurfacesMust be included in every UDSTwo types of data structures passed between Zemax and DLL: User Data and Fixed Data2 - 10 User Data OverviewZemax passes a data structure called USER_DATA containing:Ray x, y, z locations on a plane tangent to the surface vertexDLL must it

11、erate to the real surface and returnOr calculate intercept analytically if possible (e.g. sphere)l, m, n direction cosines of the rayln, mn, nn surface normals, to be computed and returnedOther data like index for gradient index, transmission, path lengthDLL must compute all new ray data after inter

12、acting with surface2 - 11 User Data Structure2 - 12 Fixed Data OverviewThe FIXED_DATA array mainly contains data the DLL cannot change:All surface data in LDE and EDE (radius, conic, parameters, etc.)Ray wavelength, polarization stateType and Numb parameters indicating what data Zemax wants from a g

13、iven call to the DLLRay polarization state and scaling of parameters/extra data columns are only data that DLL may modifyFIXED_DATA3 is the current structure Zemax usesFIXED_DATA and FIXED_DATA2 included for backward compatibility2 - 13 Fixed Data Structure2 - 14 UDS Type Codes0: surface name (numb

14、= 0), radial symmetry status (numb = 1), gradient index status (numb = 2)1: parameter column names2: extra data column names3: surface sag and alternate sag4: paraxial ray trace data5: real ray trace data6: index and first derivatives for GRIN surfaces7: default/safe values8: DLL initialization (mem

15、ory allocation, etc.)9: DLL termination (memory release, etc.)10: scaling parameter and extra data values2 - 15 Sample UDSZemax provides numerous (30+) sample UDSSee “User Defined” in Chp. 11 of the manual for a complete tableDLL samples to learn from:US_STAND, US_STAND2: standard surface (good star

16、ting point for learning DLL syntax)US_ARRAY: lens arrayUS_FILT1 US_FILT8: transmission filtersUS_GRIN1: gradient index surfaceUS_ITERA: standard surface with ray iteration (useful for learning ray iteration to steep surfaces)US_POLARIZATION: modifies ray polarization based upon user input in LDEMany

17、 more exist, all with source code included!Programming ZemaxExample: Off-Axis Conic UDS2 - 17 Without UDSTo define an off-axis section of a surface requires a decentered aperture and coordinate breaksOpen a new sequential system, define parabolic mirror:EPD = 10 mmS1 to Mirror = 50 mmMirror radius =

18、 -20 mmMirror conic = -1Mirror to IMA = -10 mmSave the file as OAP.zmx2 - 18 Surface DecenterDecenter surface with ToolsCoordinatesTilt/Decenter Elements2 - 19 Image Surface PositionAdd chief ray solves to the y-decenter and x-tilt on the second CBMakes image plane centered and perpendicular to chie

19、f rayUse ToolsMiscQuick Focus to get best spot radius2 - 20 Surface Aperture DecenterAdd a circular aperture to the mirrorMax Radius = 5.1, Aperture Y-Decenter = -102 - 21 Off-Axis User-Defined SurfaceLets create the same off-axis section with a UDS that allows definition of the aperture decenter di

20、rectly in the LDEUse US_Itera.c as the starting pointCopy to a new filename: Offset.cA note about user privileges:Windows is allowing you to modify data in the Program Files folder because you have administrator privilegesYou may not have these privileges on your office computerIn this case, work in

21、 My Documents folder and only copy over to Program Files once final DLL is createdPrivileges are more tightly controlled on Windows Vista and 7 than on XP2 - 22 Creating the ProjectStart MS Visual C+ Express EditionGo to FileNewProjectChoose Win 32 Project, name it Offset_Surface, specify location2

22、- 23 Application SettingsCreate an empty DLL project2 - 24 Configuration ManagerUnder BuildConfiguration Manager, set the configuration to Release2 - 25 Source and Header FilesRight click Header Files folder and add the existing usersurf.hThis is required for all UDSRight click Source Files folder a

23、nd add the existing Offset.cMake sure header and source files are in same folder or you will get compile errors2 - 26 Compiling Multi-threaded CodeIt is critical that any DLL you compile be multithreadedZemax maintains several copies of a system and more than one may be attempting to access your DLL

24、 simultaneouslyCrashes can occur if this isnt set properlyRight click “Offset_Surface” and select Properties(/MT) option ensures users without C libraries on their computer can run the DLL2 - 27 Compiling 64-bit CodeZemax is offered as either a 32-bit or 64-bit programDLLs must be correctly compiled

25、 as 32-bit or 64-bit to work properlyMS Visual C+ Express Edition doesnt allow 64-bit compilation without modifications to the registryIn the full version of MS Visual Studio, you would do the following:BuildConfiguration Manager, Active solution platform: Select x64 from the drop down list; thats a

26、ll!2 - 28 Accessing DataDLL accesses the data structures in usersurf.h with special operatorx = UD-x;Statement reads: “set the value of variable x to be equal to the x-member of the UD data structure”Operators used directly in statements:power = (FD-n2 FD-n1)*FD-cv;DLL knows UD corresponds to USER_D

27、ATA based upon following:Zemax currently uses UserDefinedSurface3 and FIXED_DATA3, so modify both occurrences (function declaration and function definition):2 - 29 Error CheckingDLL should return(value) depending on e:Value = 0 if DLL executed successfullyValue = -1 if an error occurredDuring raytra

28、cing (case 4 or 5)Value = surface number if ray misses surfaceValue = -(surface number) if ray TIRs at surface2 - 30 Initial Compile CheckGood habit to compile first to ensure no project setting mistakesChange surface name to “Offset”, make it asymmetric2 - 31 CompileSave Offset.c, click BuildBuild

29、SolutionCheck output window for compilation errors2 - 32 DLL TestCopy Offset.dll to Program FilesZemaxDLLSurfacesRecall our discussion on privileges Reopen starting point, convert parabolic surface to Offset_Surface.dll2 - 33 DLL Test, Contd.Success! Surface name appears and we get an error if we tr

30、y to open a 2D layout (asymmetry)2 - 34 Parameter Column NamesMake the following changes to case 1 of FD-type2 - 35 Test Parameter ModificationsSave Offset.c and pileRemove Offset_Surface.dll from surface 2 (change back to standard)Windows complains when attempting to overwrite a file in useMove new

31、 DLL to correct folder and overwrite previous oneRedefine Offset_Surface.dll on surface 22 - 36 Sag CalculationNeed to offset the sag by the amount specified in the LDE (Case = 3)2 - 37 Test Sag ModificationsAfter compiling and reloading the DLL, set Y-Decenter = -10Case = 3 only controls sag calcul

32、ationRays dont see decenter yet!2 - 38 Separation of FunctionsCase = 3 only used by layout plots, AnalysisSurface features, or any other features that require sag dataRay tracing features use Case = 4 (paraxial) or Case = 5 (real)If GRIN, Case = 6 called for raytracing2 - 39 Paraxial RaytracingCase

33、= 4 is used for paraxial raytracingParaxial rays are traced using formulas which assume the optical surface power is based only upon the vertex radius of curvature, ignoring local linear tilts and higher order curvature of the surfaceAssumes vertex curvature approximates power over entire surfaceDon

34、t need to change for this example2 - 40 Real RaytracingEdit Case 5 as followsX,Y coordinates used for calculating sag of surface use decenterRay intercept coordinates returned without decenterSurface normal calculation (sag) uses decentered x,y coordinates2 - 41 Test Real RaytracingSave, pile, reloa

35、d DLL It works! We have an off-axis section of a surface2 - 42 Locating Image SurfaceRays travel away from mirrors coordinate systemNeed coordinate break to correctly locate image planeAdd CB before image plane, use chief ray solves on y-decenter, x-tilt2 - 43 Sag FunctionCases 3 and 5 both use the

36、same calculation to compute surface sagIt is easier and less error-prone to write a sag function, and call function when needed to compute sag in both casesSteps involvedDeclare sag function at beginning of Offset.cReplace sag calculation lines in cases 3 and 5 with function callsDefine function at

37、end of Offset.c2 - 44 Sag Function ModificationsDeclare sag function at beginning of Offset.cDefine sag function at end of Offset.cRedefine case 3Replace same block of code with function call in case 52 - 45 Test Sag FunctionSave, compile, reload the DLLShould get the exact same results if everythin

38、g is done correctly2 - 46 SummaryJust like optical design, start with a sample close to what you wantDetermine mathematical model of surface before you beginMake changes one at a time, compile, and testStart with easiest modifications, then do more difficult ones:Parameter names, extra data names, r

39、otational symmetrySag calculationParaxial raytraceReal raytraceGRIN propertiesTest each step as you go until it behaves correctlyProgramming ZemaxExample: Phase Quadrant UDS2 - 48 Phase UDSUser-defined surfaces can add phase, as well as reflect/refract raysPhase adds to the path length of the rayPat

40、h = path + added phase (expressed as path length)Phase slope actually bends the rays2 - 49 Phase Quadrant SurfaceLets write a standard surface that allows the user to add phase to each quadrant of the surface independently2 - 50 AssumptionsAssume quadrants steps are infinite and no ray can land on t

41、he edgeSurface adds phase, but doesnt bend rays (no phase slope)No ray can hit the edges (phase slope infinite at edges)Significant assumption!We will discuss improvements laterd/dx = d/dy = 0d/dx = d/dy = 2 - 51 SetupStart with US_stand2.c; rename “Phase_Quadrant.c”Set up new project (Phase Quadran

42、t), add source and header filesOpen source code for editingSet the runtime library to multi-threadedBegin by modifying UserSurface and FIXED_DATA to new type (3)Remember both function declaration and definition2 - 52 Initial ModificationsDeclare new variables, change surface name, rotational symmetr

43、y flag2 - 53 Parameter ColumnsChange the names of parameter columns 1-42 - 54 Default/Safe ValuesDefault values are useful during testing process to check that values have been calculated correctlyWe use pi here, but set them to zero for the final DLL compilation2 - 55 Test Initial ModificationsSave

44、, compile, move the DLLDisregard compiler warnings about unreferenced variables2 - 56 Phase ProfileSet the default/safe values back to zero (case 7)Values entered in parameter columns will be in units of 2Sag and paraxial raytracing not affected by phase profileAll the modifications are to the real

45、raytracing (case 5)2 - 57 Loop ModificationsReplace refract function and return command2 - 58 Phase CalculationsNow add the code to calculate the phase and apply the correct amount in each quadrant2 - 59 Test Phase Quadrant SurfaceSave, compile, reload the DLLSet EPD = 10, Q1 = 1, Q2 = 2, Q3 = 3, Q4

46、 = 42 - 60 Realistic Phase StepsWe assumed (unrealistically) that phase steps are infiniteIf they arent, we would have to define the phase variation over stepWe wont take the time, but heres how:Step distance is + as we go from Q1 to Q2Assume cosine variation over distance of 2 Within region, phase

47、is:Similar code applies fortransitions between otherquadrantsProgramming ZemaxExample: Gradient Index UDS2 - 62 Gradient Index MaterialsA GRIN material has the property that refractive index is a function of position and possibly wavelength: n(,x,y,z)Relatively easy to write as far as UDS are concer

48、nedZemax needs to know index and gradients (dn/dx,dn/dy,dn/dz) at all points2 - 63 Index and GradientsImagine we want index profile:n = no + Ax2 + By2The gradients would be:dn/dx = 2Axdn/dy = 2Bydn/dz = 02 - 64 Starting PointStart with US_stand2.c again; copy and rename “XY_Gradient.c”Set up new pro

49、ject (XY Gradient), add source and header filesOpen source code for editingBegin by modifying UserSurface and FIXED_DATA to new type (3)Declare new variables2 - 65 General Info Modifications2 - 66 Parameter NamesAll GRIN UDS must use parameter 1 as delta T!2 - 67 Default/Safe Data2 - 68 Compile and

50、TestDisregard compiler warnings about unreferenced variables2 - 69 GRIN CalculationCase 6 is used for GRIN materials2 - 70 Compile and TestInsert GRIN UDS into system with EPD = 1mm, A = -0.04, B = 0.02Open AnalysisGlass and Gradient IndexGRIN ProfileSurf = 2, Min X/Y = -1, Max X/Y = +1Programming Z

51、emaxNon-Sequential Programming2 - 72 Non-Sequential ProgrammingIn NSC, we can program:User-defined objectsGRIN profiles (usable by any volume object)Diffraction algorithms (usable by any diffractive object)Surface scattering algorithms (usable by an object)Bulk scattering algorithms (usable by any v

52、olume object)User-defined sourcesDetectors (UD object can be used as a detector)All are coded via separate, independent DLLsAs opposed to sequential UDS where everything is in one DLL2 - 73 Folder LocationsEach of these user-defined capabilities is stored in a unique folderObject DLL: Program FilesZ

53、emaxDLLObjectsGRIN DLL: Program FilesZemaxDLLGradientIndexDiffraction DLL: Program FilesZemaxDLLDiffractiveSurface scatter DLL: Program FilesZemaxDLLSurfaceScatterBulk scatter DLL: Program FilesZemaxDLLBulkScatterSource DLL: Program FilesZemaxDLLSourcesZemax comes with samples of all these types of

54、DLL2 - 74 Basic StructureThere is enough NSC programming for a 2-day course of its own!User-defined NSC objects present some new concepts, so well focus on thisOther DLLs are similar in structure to what we have done previouslyZemax passes array of data to DLL; DLL computes info, enters data into st

55、ructure to pass backCommon handling of parameter names, safe values, etc.2 - 75 Source DLL ExampleOpen DLLSourcesfiber_1.cSee comments for description of data arrayProgramming ZemaxUser-Defined NSC Objects2 - 77 UDO AdvantagesAdvantages of defining object via a DLL, rather than POB, CAD, etc.UDO gen

56、erally traces faster, with higher numerical precisionAny mathematically describable shape can be createdDLL description is parametric: object dynamically regenerated as parameters changeIdeal for interactive design and optimizationSingle object can contain multiple complex curved surfaces, each with

57、 own defining function2 - 78 UDO DLL DetailsDLL first called to create list of triangular facets approximating shapeZemax traces rays non-sequentiallyIf ray hits tessellation, DLL called to determine exact intercept and normal vectorImplemented using an iterative routine (sample routine provided in

58、all sample UDOs)If object has multiple curves, each can have own iteration routineThese are the only purposes the DLL servesZemax handles NSC raytracing, object nesting, refraction, reflection, diffraction, optical path length, scattering, etc.Completely separates object definition from optical phys

59、ics2 - 79 DLL FunctionsValues are passed between Zemax and DLL with a data arrayArray contains all parameter data from NSC editor and ray dataDLL has two functionsUserParamNames(): returns parameter and face group namesUserObjectDefinition(): contains object definition2 - 80 UserParamNames FunctionD

60、ata value passed to DLLData face 1)Data 0: Zemax wants name of parameter names2 - 81 UserObjectDefinition FunctionData1 indicates what DLL should computeData1 = 0Place total number of triangular facets in Data10Indicate if object is volume or shell in Data11Indicate if object is diffractive in Data1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论