def test_dbgauss_s1(self): r1 = 56.20238 c1 = 1 / r1 y0 = 25.0 s1 = Spherical(c=c1) p1 = np.array([0., y0, 0.]) sag1 = r1 - sqrt(r1 * r1 - y0 * y0) # test for p0 ray, (0, 0, 0), (0, 0, 1) p0_truth = 1.0, np.array([0., 0., 0.]) p0s1 = s1.intersect(self.p0, self.dir0, self.eps, self.z_dir) assert ((p0s1[0], p0s1[1].all()) == (p0_truth[0], p0_truth[1].all())) self.assertEqual(p0s1[0], 1.0) npt.assert_allclose(p0s1[1], np.array([0., 0., 0.]), rtol=1e-14, atol=1e-14) # test for p1 ray, (0, 1, 0), (0, 0, 1) p1_truth = 5.866433424372758, np.array([0., y0, sag1]) p1s1 = s1.intersect(p1, self.dir0, self.eps, self.z_dir) assert p1s1[0] == approx(p1_truth[0], rel=1e-14, abs=1e-14) npt.assert_allclose(p1s1[1], p1_truth[1], rtol=1e-14) dir_p1s1 = s1.normal(p1s1[1]) dir_p1s1_truth = -normalize(p1_truth[1] - np.array([0, 0, r1])) assert dir_p1s1.all() == dir_p1s1_truth.all() npt.assert_allclose(dir_p1s1, dir_p1s1_truth, rtol=1e-14)
def create_cemented_doublet(power=0., bending=0., th=None, sd=1., glasses=('N-BK7,Schott', 'N-F2,Schott'), **kwargs): from opticalglass.spectral_lines import get_wavelength from opticalglass import glass wvls = np.array([get_wavelength(w) for w in ['d', 'F', 'C']]) gla_a = gfact.create_glass(glasses[0]) rndx_a = gla_a.calc_rindex(wvls) Va, PcDa = glass.calc_glass_constants(*rndx_a) gla_b = gfact.create_glass(glasses[1]) rndx_b = gla_b.calc_rindex(wvls) Vb, PcDb = glass.calc_glass_constants(*rndx_b) power_a, power_b = achromat(power, Va, Vb) if th is None: th = sd/4 t1 = 3*th/4 t2 = th/4 if power_a < 0: t1, t2 = t2, t1 lens_a = lens_from_power(power=power_a, bending=bending, th=t1, sd=sd, med=gla_a) cv1, cv2, t1, indx_a, sd = lens_a # cv1 = power_a/(rndx_a[0] - 1) # delta_cv = -cv1/2 # cv1 += delta_cv # cv2 = delta_cv # cv3 = power_b/(1 - rndx_b[0]) + delta_cv indx_b = rndx_b[0] cv3 = (power_b/(indx_b-1) - cv2)/((t2*cv2*(indx_b-1)/indx_b) - 1) s1 = Surface(profile=Spherical(c=cv1), max_ap=sd, delta_n=(rndx_a[0] - 1)) s2 = Surface(profile=Spherical(c=cv2), max_ap=sd, delta_n=(rndx_b[0] - rndx_a[0])) s3 = Surface(profile=Spherical(c=cv3), max_ap=sd, delta_n=(1 - rndx_b[0])) g1 = Gap(t=t1, med=gla_a) g2 = Gap(t=t2, med=gla_b) g_tfrm = np.identity(3), np.array([0., 0., 0.]) ifc_list = [] ifc_list.append([0, s1, g1, 1, g_tfrm]) ifc_list.append([1, s2, g2, 1, g_tfrm]) ifc_list.append([2, s3, None, 1, g_tfrm]) ce = CementedElement(ifc_list) tree = ce.tree() return [[s1, g1, None, rndx_a, 1], [s2, g2, None, rndx_b, 1], [s3, None, None, 1, 1]], [ce], tree
def create_mirror(c=0.0, r=None, cc=0.0, ec=None, power=None, profile=None, sd=None, **kwargs): '''Create a sequence and element for a mirror. Args: c: vertex curvature r: vertex radius of curvature cc: conic constant ec: 1 + cc power: optical power of the mirror sd: semi-diameter profile: Spherical or Conic type, or a profile instance ''' delta_n = kwargs['delta_n'] if 'delta_n' in kwargs else -2 if power: cv = power / delta_n elif r: cv = 1.0 / r else: cv = c if ec: k = ec - 1.0 else: k = cc if profile is Spherical: prf = Spherical(c=cv) elif profile is Conic: prf = Conic(c=cv, cc=k) elif profile is not None: prf = profile else: if k == 0.0: prf = Spherical(c=cv) else: prf = Conic(c=cv, cc=k) m = Surface(profile=prf, interact_mode='reflect', max_ap=sd, delta_n=delta_n, **kwargs) ele_kwargs = {'label': kwargs['label']} if 'label' in kwargs else {} me = Mirror(m, sd=sd, **ele_kwargs) tree = me.tree() return [[m, None, None, 1, -1]], [me], tree
def test_planar_sphere(self): s1 = Spherical(c=0.0) p_truth = 1.0, np.array([0., 0., 0.]) # test for p0 ray, (0, 0, 0), (0, 0, 1) p0s1 = s1.intersect(self.p0, self.dir0, self.eps, self.z_dir) assert (p0s1[0], p0s1[1].all()) == (p_truth[0], p_truth[1].all()) # test for p1 ray, (0, 1, 0), (0, 0, 1) p1s1 = s1.intersect(self.p1, self.dir0, self.eps, self.z_dir) assert ((p1s1[0], p1s1[1].all()) == (p_truth[0], np.array([0., 1., 0.]).all()))
def create_lens(power=0., bending=0., th=None, sd=1., med=None, **kwargs): if med is None: med = Glass() lens = lens_from_power(power=power, bending=bending, th=th, sd=sd, med=med) cv1, cv2, th, rndx, sd = lens s1 = Surface(profile=Spherical(c=cv1), max_ap=sd, delta_n=(rndx - 1)) s2 = Surface(profile=Spherical(c=cv2), max_ap=sd, delta_n=(1 - rndx)) g = Gap(t=th, med=med) le = Element(s1, s2, g, sd=sd) tree = le.tree() return [[s1, g, None, rndx, 1], [s2, None, None, 1, 1]], [le], tree
def create_lens(power=0., bending=0., th=None, sd=1., med=None): if med is None: med = Glass() rndx = med.rindex('d') cv1 = power / (2 * (rndx - 1)) cv2 = -power / (2 * (rndx - 1)) s1 = Surface(profile=Spherical(c=cv1), max_ap=sd, delta_n=(rndx - 1)) s2 = Surface(profile=Spherical(c=cv2), max_ap=sd, delta_n=(1 - rndx)) if th is None: th = sd / 5 g = Gap(t=th, med=med) le = Element(s1, s2, g, sd=sd) return [[s1, g, None, rndx, 1], [s2, None, None, 1, 1]], [le]
def test_concave_sphere(self): r3 = 10 s3 = Spherical(r=-r3) # test for p0 ray, (0, 0, 0), (0, 0, 1) p0_truth = 1.0, np.array([0., 0., 0.]) p0s3_dir = s3.intersect(self.p0, self.dir0, self.eps, self.z_dir) p0s3_tnp = s3.intersect_tangent_plane(self.p0, self.dir0, self.eps, self.z_dir) assert ((p0s3_dir[0], p0s3_dir[1].all()) == (p0s3_tnp[0], p0s3_tnp[1].all())) p0s3 = p0s3_dir assert ((p0s3[0], p0s3[1].all()) == (p0_truth[0], p0_truth[1].all())) # test for p1 ray, (0, 1, 0), (0, 0, 1) sag3 = r3 - sqrt(r3 * r3 - 1.0) p1_truth = 1 - sag3, np.array([0., 1., -sag3]) p1s3_tnp = s3.intersect_tangent_plane(self.p1, self.dir0, self.eps, self.z_dir) p1s3_dir = s3.intersect(self.p1, self.dir0, self.eps, self.z_dir) assert ((p1s3_dir[0], p1s3_dir[1].all()) == (p1s3_tnp[0], p1s3_tnp[1].all())) p1s3 = p1s3_dir assert p1s3[0] == approx(p1_truth[0], rel=1e-14, abs=1e-14) assert p1s3[1].all() == p1_truth[1].all() dir_p1s3 = s3.normal(p1s3[1]) dir_p1s3_truth = normalize(p1_truth[1] - np.array([0, 0, -r3])) assert dir_p1s3.all() == dir_p1s3_truth.all()
def test_convex_sphere(self): r2 = 10 c2 = 1 / r2 s2 = Spherical(c=c2) # test for p0 ray, (0, 0, 0), (0, 0, 1) p0_truth = 1.0, np.array([0., 0., 0.]) p0s2_dir = s2.intersect(self.p0, self.dir0, self.eps, self.z_dir) p0s2_tnp = s2.intersect_tangent_plane(self.p0, self.dir0, self.eps, self.z_dir) assert ((p0s2_dir[0], p0s2_dir[1].all()) == (p0s2_tnp[0], p0s2_tnp[1].all())) p0s2 = p0s2_dir assert ((p0s2[0], p0s2[1].all()) == (p0_truth[0], p0_truth[1].all())) # A spherical EvenPolynomial will use iteration to find the # intersection. Use this case to further check results sa2 = EvenPolynomial(c=c2) p0sa2 = sa2.intersect(self.p0, self.dir0, self.eps, self.z_dir) assert ((p0sa2[0], p0sa2[1].all()) == (p0_truth[0], p0_truth[1].all())) assert (p0s2_dir[0], p0s2_dir[1].all()) == (p0sa2[0], p0sa2[1].all()) # test for p1 ray, (0, 1, 0), (0, 0, 1) sag2 = r2 - sqrt(r2 * r2 - 1.0) p1_truth = 1 + sag2, np.array([0., 1., sag2]) p1s2_dir = s2.intersect(self.p1, self.dir0, self.eps, self.z_dir) p1s2_tnp = s2.intersect_tangent_plane(self.p1, self.dir0, self.eps, self.z_dir) assert ((p1s2_dir[0], p1s2_dir[1].all()) == (p1s2_tnp[0], p1s2_tnp[1].all())) p1s2 = p1s2_dir assert ((p1s2[0], p1s2[1].all()) == (p1_truth[0], p1_truth[1].all())) dir_p1s2 = s2.normal(p1s2[1]) dir_p1s2_truth = -normalize(p1_truth[1] - np.array([0, 0, r2])) assert dir_p1s2.all() == dir_p1s2_truth.all()