def plotNodeSpacing(rsec,smax,pmin,fun,nodegap,L=200.,pbeam=True): """ Plot mirror positions and beam extent for each mirror node """ plt.figure('Nodes') plt.clf() for i in range(len(smax)): for r in rsec[i]: #Mirror parameters z = np.sqrt(1e4**2-r**2) psi = np.polyval(fun[i],r) psi = np.max([.01,psi]) #Plot mirrors rp1 = wsPrimrad(pmin[i]+L,r,z,psi) rp2 = wsPrimrad(pmin[i],r,z,psi) rs1 = wsSecrad(smax[i],r,z,psi) rs2 = wsSecrad(smax[i]-L,r,z,psi) plt.plot([rp1,rp2],[pmin[i]+L,pmin[i]],'k') plt.plot([rs1,rs2],[smax[i],smax[i]-L],'k') if np.where(r==rsec[i])[0] == 136: pdb.set_trace() if pbeam is True: #Plot beam #Set up ray ray = sources.pointsource(0.,1) ray[6] = -ray[6] ray[1][0] = rp1 tran.transform(ray,0,0,-1e4,0,0,0) #Trace to shell surf.wsPrimary(ray,r,z,psi) tran.reflect(ray) surf.wsSecondary(ray,r,z,psi) tran.reflect(ray) rb1 = ray[1][0] z1 = ray[3][0] #Set up ray ray = sources.pointsource(0.,1) ray[6] = -ray[6] ray[1][0] = rp2 tran.transform(ray,0,0,-1e4,0,0,0) #Trace to shell surf.wsPrimary(ray,r,z,psi) tran.reflect(ray) surf.wsSecondary(ray,r,z,psi) tran.reflect(ray) rb2 = ray[1][0] z2 = ray[3][0] plt.plot([rp1,rp1,rb1,0],[1e4+500.,pmin[i]+L,z1,0],'b--') plt.plot([rp2,rp2,rb2,0],[1e4+500.,pmin[i],z2,0],'b--') return None
def wsSecrad(z,r0,z0,psi=1.): """ Determine radius of WS primary """ #Set up ray ray = sources.pointsource(0.,1) tran.transform(ray,0,0,0,0,-np.pi/2,0) tran.transform(ray,-r0-2.,0,-z,0,0,0) surf.wsSecondary(ray,r0,z0,psi) return ray[1][0]
def traceSingleRay(rtrace,zexit,R0,Z0,zeta,rpos=False): """ Trace single ray through WS shell and return ray at a given exit aperture z position """ #Set up ray ray = sources.pointsource(0.,1) ray[6] = -ray[6] ray[1][0] = rtrace tran.transform(ray,0,0,-Z0,0,0,0) #Trace to shell surf.wsPrimary(ray,R0,Z0,zeta) tran.reflect(ray) surf.wsSecondary(ray,R0,Z0,zeta) tran.reflect(ray) if rpos is True: return ray[1][0],ray[3][0] #Go to exit aperture tran.transform(ray,0,0,zexit,0,0,0) surf.flat(ray) return ray
def getfirstray(rays): opd, x, y, z, l, m, n, ux, uy, uz = rays return [opd[0], x[0], y[0], z[0], l[0], m[0], n[0], ux[0], uy[0], uz[0]] def checkerror(ray1, ray2): errors = [] for i in range(len(ray1)): errors.append((ray1[i] - ray2[i]) / ray1[i]) for e in errors: print(e) num = 1 rays = sources.pointsource(.5, num) rays[2] += 0 rays[3] += 0 rays[7] += 0 rays[8] += 0 rays[9] += 0 opd, x, y, z, l, m, n, ux, uy, uz = rays ## Testing below this line amp = 10 freq = 1 printrays(rays, 3) print('-------------')