model.components['qwpMes'].retardance = 2 * np.pi / 4 model.components['qwpMes'].rotation = np.pi / 4 model.components['qwpMes'].update() model.components['qwpCos'].retardance = 2 * np.pi / 4 model.components['qwpCos'].rotation = 0 #20*np.pi/180 model.components['qwpCos'].update() model.components['polCos'].rotation = np.pi / 4 model.components['polCos'].update() model.components['polSin'].rotation = np.pi / 4 model.components['polSin'].update() stack = pyctmm.create_stack(2, model.wavelength, 0) pyctmm.set_ind(stack, 0, 3, 0) pyctmm.set_ind(stack, 1, 1., 0) pyctmm.set_d(stack, 0, 0) pyctmm.set_d(stack, 1, 0) model.components['sMesA'].set_pyctmm(stack) nPoints = 100 xs = np.linspace(0, 1, nPoints) ints1 = np.empty(xs.shape, dtype=float) ints2 = np.empty(xs.shape, dtype=float) ints1analytic = np.empty(xs.shape, dtype=float) ints2analytic = np.empty(xs.shape, dtype=float) iAir = 1 iGlass = 3
model.components['qwpMes'].retardance = 2*np.pi/4 model.components['qwpMes'].rotation = np.pi/4 model.components['qwpMes'].update() model.components['qwpCos'].retardance = 2*np.pi/4 model.components['qwpCos'].rotation = 0#20*np.pi/180 model.components['qwpCos'].update() model.components['polCos'].rotation = np.pi/4 model.components['polCos'].update() model.components['polSin'].rotation = np.pi/4 model.components['polSin'].update() stack = pyctmm.create_stack(2, model.wavelength, 0) pyctmm.set_ind(stack, 0, 1, 0) pyctmm.set_ind(stack, 1, 1, 0) pyctmm.set_d(stack, 0, 0) pyctmm.set_d(stack, 1, 0) model.components['sMesA'].set_pyctmm(stack) nPoints = 100 xs = np.linspace(0, 1, nPoints) ints1 = np.empty(xs.shape, dtype=float) ints2 = np.empty(xs.shape, dtype=float) for i, x in enumerate(xs): model.components['sMesB'].set_length(x) model.evaluate() ints1[i] = model.detectors['pd1'].intensity
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../lib import pyctmm import sys stack = pyctmm.create_stack(3, 633e-9, 0) pyctmm.set_ind(stack, 0, 1, 0) pyctmm.set_ind(stack, 1, 3, -2.999) pyctmm.set_ind(stack, 2, 1, 0) pyctmm.set_d(stack, 0, 0) pyctmm.set_d(stack, 1, 50e-9) pyctmm.set_d(stack, 2, 0) pyctmm.evaluate(stack) power_coefs = pyctmm.get_power(stack) print('\n', power_coefs)
def test_set_pyctmm_free_space(self): """Test that the set_ctmm method produces the correct results. This does not aim to fully test the pyctmm library, but tests a few simple cases: phase change through free space reflection from air-glass interface destructive interference at air-glass interface (half-wave layer) """ model = ts.Model() model.wavelength = 633e-9 model.add_component(ts.components.Source, 'laser', 'n0') model.add_component(ts.components.Dump, 'dump', 'n1') model.add_component(ts.components.Stack, 'stack', ('n0', 'n1')) model.add_detector('out', 'n1', ('amplitude', 'intensity')) model.components['laser'].amplitude[0] = 0 model.components['laser'].amplitude[1] = 1 cstack = pyctmm.create_stack(1, model.wavelength, 0) pyctmm.set_ind(cstack, 0, 1, 0) pyctmm.set_d(cstack, 0, model.wavelength / 4) model.components['stack'].set_pyctmm(cstack) model.build() model.evaluate() self.assertAlmostEqual(model.detectors['out'].amplitudes[0], 0) self.assertAlmostEqual(model.detectors['out'].amplitudes[1], np.exp(-1j * np.pi / 2)) self.assertAlmostEqual(model.detectors['out'].amplitudes[2], 0) self.assertAlmostEqual(model.detectors['out'].amplitudes[3], 0) del cstack del model model = ts.Model() model.wavelength = 633e-9 model.add_component(ts.components.Source, 'laser', 'n0') model.add_component(ts.components.Dump, 'dump', 'n1') model.add_component(ts.components.Stack, 'stack', ('n0', 'n1')) model.add_detector('in', 'n0', ('amplitude', 'intensity')) model.add_detector('out', 'n1', ('amplitude', 'intensity')) model.components['laser'].amplitude[0] = 0 model.components['laser'].amplitude[1] = 1 cstack = pyctmm.create_stack(2, model.wavelength, 0) pyctmm.set_ind(cstack, 0, 1, 0) pyctmm.set_ind(cstack, 1, 1.5, 0) pyctmm.set_d(cstack, 0, 0) pyctmm.set_d(cstack, 1, 0) model.components['stack'].set_pyctmm(cstack) model.build() model.evaluate() self.assertAlmostEqual(model.detectors['in'].intensity - 1, ((1 - 1.5) / (1 + 1.5))**2) del cstack del model model = ts.Model() model.wavelength = 633e-9 model.add_component(ts.components.Source, 'laser', 'n0') model.add_component(ts.components.Dump, 'dump', 'n1') model.add_component(ts.components.Stack, 'stack', ('n0', 'n1')) model.add_detector('in', 'n0', ('amplitude', 'intensity')) model.add_detector('out', 'n1', ('amplitude', 'intensity')) model.components['laser'].amplitude[0] = 0 model.components['laser'].amplitude[1] = 1 cstack = pyctmm.create_stack(3, model.wavelength, 0) pyctmm.set_ind(cstack, 0, 1, 0) pyctmm.set_ind(cstack, 1, 1.515, 0) pyctmm.set_ind(cstack, 2, 1, 0) pyctmm.set_d(cstack, 0, 0) pyctmm.set_d(cstack, 1, (model.wavelength / 1.515) / 2) pyctmm.set_d(cstack, 2, 0) model.components['stack'].set_pyctmm(cstack) model.build() model.evaluate() self.assertAlmostEqual(model.detectors['in'].intensity - 1, 0) self.assertAlmostEqual(model.detectors['out'].intensity, 1)
model.components['qwpMes'].retardance = 2*np.pi/4 model.components['qwpMes'].rotation = np.pi/4 model.components['qwpMes'].update() model.components['qwpCos'].retardance = 2*np.pi/4 model.components['qwpCos'].rotation = 0#20*np.pi/180 model.components['qwpCos'].update() model.components['polCos'].rotation = np.pi/4 model.components['polCos'].update() model.components['polSin'].rotation = np.pi/4 model.components['polSin'].update() stack = pyctmm.create_stack(2, model.wavelength, 0) pyctmm.set_ind(stack, 0, 1.515, 0) pyctmm.set_ind(stack, 1, 1., 0) pyctmm.set_d(stack, 0, 0) pyctmm.set_d(stack, 1, 0) model.components['sMesA'].set_pyctmm(stack) nPoints = 100 xs = np.linspace(0, 1, nPoints) ints1 = np.empty(xs.shape, dtype=float) ints2 = np.empty(xs.shape, dtype=float) ints1analytic = np.empty(xs.shape, dtype=float) ints2analytic = np.empty(xs.shape, dtype=float) iAir = 1 iGlass = 1.515
model.components['Mmes'].rP = 1 model.components['Mmes'].rS = 1 model.components['Mref'].rP = 1 model.components['Mref'].rS = 1 model.components['pol'].rotation = 0 model.components['pol'].extinction = 0 model.components['pol'].loss = 0 model.components['pol'].update() stack = pyctmm.create_stack(3, 633e-9, 0) pyctmm.set_ind(stack, 0, 1, 0) pyctmm.set_ind(stack, 1, 0.2, -3) pyctmm.set_ind(stack, 2, 1, 0) pyctmm.set_d(stack, 0, 0) pyctmm.set_d(stack, 1, 10e-9) pyctmm.set_d(stack, 2, 0) model.components['s47'].set_pyctmm(stack) model.build() xs = np.linspace(0, 1, 100) ys = np.linspace(0, 1, 100) ints = np.empty((len(xs), len(ys)), dtype=float)