def example5(): """Another code example, and loading / saving factory.""" code = """V = 10 ncl = 1.444 k0 = 2 * pi / 1550e-9 n = sqrt((V / (k0 * r[0]))**2 - ncl**2) return n """ factory = FiberFactory() factory.addLayer(radius={'start': 1e-6, 'end': 10e-6, 'num': 10}, index=code) factory.addLayer(index=1.444) print(len(factory)) print('crdate:', datetime.datetime.fromtimestamp( int(factory.crdate)).strftime('%Y-%m-%d %H:%M:%S')) print('tstamp:', datetime.datetime.fromtimestamp( int(factory.tstamp)).strftime('%Y-%m-%d %H:%M:%S')) with open('myfiber.json', 'w') as f: factory.dump(f) with open('myfiber.json', 'r') as f: factory.load(f) print(len(factory)) print('crdate:', datetime.datetime.fromtimestamp( int(factory.crdate)).strftime('%Y-%m-%d %H:%M:%S')) print('tstamp:', datetime.datetime.fromtimestamp( int(factory.tstamp)).strftime('%Y-%m-%d %H:%M:%S')) factory = FiberFactory('myfiber.json') print(len(factory)) print('crdate:', datetime.datetime.fromtimestamp( int(factory.crdate)).strftime('%Y-%m-%d %H:%M:%S')) print('tstamp:', datetime.datetime.fromtimestamp( int(factory.tstamp)).strftime('%Y-%m-%d %H:%M:%S'))
def example2(): """Plotting neff as function of the wavelength""" wavelengths = numpy.linspace(1530e-9, 1580e-9, 11) factory = FiberFactory() factory.addLayer(radius=4e-6, index=1.474) factory.addLayer() sim = Simulator(factory, wavelengths, delta=1e-5) neffiter = sim.neff() neffs = next(neffiter) for mode in next(sim.modes())[0]: neff = [] for neffwl in neffs: # for each wavelength try: neff.append(neffwl[mode]) except KeyError: # mode not supported neff.append(float("nan")) neffma = numpy.ma.masked_invalid(neff) # mask "nan" pyplot.plot(wavelengths*1e9, neffma, label=str(mode)) pyplot.title("neff as function of wavelength") pyplot.xlabel("wavelength (nm)") pyplot.ylabel("effective index") pyplot.legend() pyplot.show()
def testBures_4_2_8(self): n2 = 1.457420 n1 = 1.462420 rho = 8.335e-6 wl = Wavelength(0.6328e-6) f = FiberFactory() f.addLayer(radius=rho, index=n1) f.addLayer(index=n2) fiber = f[0] modes = fiber.findLPmodes(wl) sols = { Mode('LP', 0, 1): 2.1845, Mode('LP', 0, 2): 4.9966, Mode('LP', 0, 3): 7.7642, Mode('LP', 1, 1): 3.4770, Mode('LP', 1, 2): 6.3310, Mode('LP', 1, 3): 9.0463, Mode('LP', 2, 1): 4.6544, Mode('LP', 2, 2): 7.5667, Mode('LP', 3, 1): 5.7740, Mode('LP', 3, 2): 8.7290, Mode('LP', 4, 1): 6.8560, Mode('LP', 4, 2): 9.8153, Mode('LP', 5, 1): 7.9096, Mode('LP', 6, 1): 8.9390, Mode('LP', 7, 1): 9.9451 } self.assertEqual(len(modes), len(sols)) for m in modes: neff = fiber.neff(m, wl) u = wl.k0 * rho * sqrt(n1**2 - neff**2) self.assertAlmostEqual(u, sols[m], 3)
def testBures_4_2_8(self): n2 = 1.457420 n1 = 1.462420 rho = 8.335e-6 wl = Wavelength(0.6328e-6) f = FiberFactory() f.addLayer(radius=rho, index=n1) f.addLayer(index=n2) fiber = f[0] modes = fiber.findLPmodes(wl) sols = {Mode('LP', 0, 1): 2.1845, Mode('LP', 0, 2): 4.9966, Mode('LP', 0, 3): 7.7642, Mode('LP', 1, 1): 3.4770, Mode('LP', 1, 2): 6.3310, Mode('LP', 1, 3): 9.0463, Mode('LP', 2, 1): 4.6544, Mode('LP', 2, 2): 7.5667, Mode('LP', 3, 1): 5.7740, Mode('LP', 3, 2): 8.7290, Mode('LP', 4, 1): 6.8560, Mode('LP', 4, 2): 9.8153, Mode('LP', 5, 1): 7.9096, Mode('LP', 6, 1): 8.9390, Mode('LP', 7, 1): 9.9451} self.assertEqual(len(modes), len(sols)) for m in modes: neff = fiber.neff(m, wl) u = wl.k0 * rho * sqrt(n1**2 - neff**2) self.assertAlmostEqual(u, sols[m], 3)
def testCutoffV(self): """Values from Bures, Table 3.6.""" delta = 0.3 V = 5 wl = Wavelength(1.55e-6) n2 = 1.444 n1 = sqrt(n2**2 / (1 - 2 * delta)) rho = V / (sqrt(n1**2 - n2**2) * wl.k0) f = FiberFactory() f.addLayer(radius=rho, index=n1) f.addLayer(index=n2) fiber = f[0] sols = [(Mode('TE', 0, 1), 2.4048), (Mode('TM', 0, 1), 2.4048), (Mode('HE', 1, 1), 0), (Mode('EH', 1, 1), 3.8317), (Mode('TE', 0, 2), 5.5201), (Mode('TM', 0, 2), 5.5201), (Mode('HE', 1, 2), 3.8317), (Mode('EH', 1, 2), 7.0156), (Mode('HE', 2, 1), 2.8526), (Mode('EH', 2, 1), 5.1356), (Mode('HE', 3, 1), 4.3423), (Mode('EH', 2, 2), 8.4172)] for mode, V0 in sols: self.assertAlmostEqual(fiber.cutoff(mode), V0, 4, msg=str(mode))
def example3(): """Plotting modal map""" r2 = 10e-6 rho = numpy.linspace(0, 0.95) r1 = r2 * rho Vlim = (2, 6) # interval where to plot V factory = FiberFactory() factory.addLayer(radius=r1, index=1.444) factory.addLayer(radius=r2, index=1.474) factory.addLayer(index=1.444) sim = PSimulator(factory, [1550e-9], vectorial=False, scalar=True, numax=6, mmax=2) modes = set() for ml in sim.modes(): modes |= ml[0] CO = list(sim.cutoff()) for mode in sorted(modes): vco = numpy.fromiter((co[0][mode] if mode in co[0] else float("nan") for co in CO), dtype=float, count=rho.size) vco = numpy.ma.masked_invalid(vco) if vco.min() < Vlim[1] and vco.max() > Vlim[0]: pyplot.plot(vco, rho, label=str(mode)) pyplot.title("Modal map") pyplot.xlabel("V number") pyplot.ylabel("r1 / r2") pyplot.xlim(Vlim) pyplot.ylim((0, 1)) pyplot.show()
def testBures3_6(self): delta = 0.3 V = 5 wl = Wavelength(1.55e-6) n2 = 1.444 n1 = sqrt(n2**2 / (1 - 2 * delta)) rho = V / (sqrt(n1**2 - n2**2) * wl.k0) f = FiberFactory() f.addLayer(radius=rho, index=n1) f.addLayer(index=n2) fiber = f[0] modes = fiber.findVmodes(wl) sols = {Mode('HE', 1, 1): 2.119, Mode('TE', 0, 1): 3.153, Mode('TM', 0, 1): 3.446, Mode('HE', 2, 1): 3.377, Mode('EH', 1, 1): 4.235, Mode('HE', 3, 1): 4.507, Mode('HE', 1, 2): 4.638} self.assertEqual(len(modes), len(sols)) for m in modes: neff = fiber.neff(m, wl) u = wl.k0 * rho * sqrt(n1**2 - neff**2) self.assertAlmostEqual(u, sols[m], 3)
def plot_zoom(fiber, vlim=(4.6, 5.4), blim=(0, 0.04)): fig = pyplot.figure(figsize=(6, 5)) ax = fig.add_subplot(111, xlim=vlim, ylim=blim) sns.despine(fig) name, r, n = fiber ax.set_title(name) f = FiberFactory() for (r_, n_) in zip_longest(r, n): f.addLayer(radius=r_, index=n_) fiber = f[0] V = numpy.linspace(*vlim) wl = [fiber.toWl(v) for v in V[::-1]] sim = Simulator(f, wl, delta=1e-7) co = next(sim.cutoff()) b = next(sim.b()) for mode, cutoff in co[0].items(): if cutoff == 0: continue # skip HE(1,1) / LP(0,1) color = MODE_COLORS[str(mode)] ax.axvline(cutoff, ls=':', color=color) b_ = numpy.empty(len(wl)) for j, b__ in enumerate(b): b_[j] = b__.get(mode, float("nan")) ax.plot(V[::-1], b_, color=color, label=str(mode) if mode.nu in (1, 3) else None) ax.set_ylabel("Normalized propagation constant ($b$)") ax.set_xlabel("Normalized frequency ($V_0$)") ax.legend(loc='best') fig.tight_layout()
def testBures3_6(self): delta = 0.3 V = 5 wl = Wavelength(1.55e-6) n2 = 1.444 n1 = sqrt(n2**2 / (1 - 2 * delta)) rho = V / (sqrt(n1**2 - n2**2) * wl.k0) f = FiberFactory() f.addLayer(radius=rho, index=n1) f.addLayer(index=n2) fiber = f[0] modes = fiber.findVmodes(wl) sols = { Mode('HE', 1, 1): 2.119, Mode('TE', 0, 1): 3.153, Mode('TM', 0, 1): 3.446, Mode('HE', 2, 1): 3.377, Mode('EH', 1, 1): 4.235, Mode('HE', 3, 1): 4.507, Mode('HE', 1, 2): 4.638 } self.assertEqual(len(modes), len(sols)) for m in modes: neff = fiber.neff(m, wl) u = wl.k0 * rho * sqrt(n1**2 - neff**2) self.assertAlmostEqual(u, sols[m], 3)
def testCutoffV2(self): """Values from cutoff acticle, Table III.""" n1 = 1.474 n2 = 1.444 rho = 10e-6 f = FiberFactory() f.addLayer(radius=rho, index=n1) f.addLayer(index=n2) fiber = f[0] sols = [(Mode('TE', 0, 1), 2.4048), (Mode('HE', 2, 1), 2.4221), (Mode('TM', 0, 1), 2.4048), (Mode('EH', 1, 1), 3.8317), (Mode('HE', 3, 1), 3.8533), (Mode('HE', 1, 2), 3.8317), (Mode('EH', 2, 1), 5.1356), (Mode('HE', 4, 1), 5.1597), (Mode('TE', 0, 2), 5.5201), (Mode('HE', 2, 2), 5.5277), (Mode('TM', 0, 2), 5.5201)] for mode, V0 in sols: self.assertAlmostEqual(fiber.cutoff(mode), V0, 4, msg=str(mode))
def testEqualIndexes(self): f = FiberFactory() f.addLayer(radius=1e-6, index=1.474) f.addLayer(radius=4e-6, index=1.474) f.addLayer() fiber = f[0] self.assertEqual(len(fiber), 2)
def testDefaultLayerAttributes(self): f = FiberFactory() f.addLayer() self.assertEqual(f.layers[0].mparams[0], 1.444) self.assertEqual(f.layers[0].material, "Fixed") self.assertEqual(f.layers[0].type, "StepIndex") self.assertEqual(f.layers[0].radius, 0)
def example3(): """2. Creating families of fibers: range of parameters""" factory = FiberFactory() factory.addLayer(name="core", radius={'start': 2e-6, 'end': 5e-6, 'num': 10}, index=[1.454, 1.464, 1.474]) factory.addLayer(name="cladding") print('Number of generated fibers:', len(factory))
def plot_b_vs_V(vectorial=True, scalar=False): nf = len(FIBERS) fig, axes = pyplot.subplots(nf, 1, sharex=False, sharey=False, subplot_kw={ 'xlim': VLIM, 'ylim': (0, 0.3) }, figsize=(6, 9)) sns.despine(fig) lines = {} for i, (name, r, n) in enumerate(FIBERS): axes[i].set_title(name) f = FiberFactory() for (r_, n_) in zip_longest(r, n): f.addLayer(radius=r_, index=n_) fiber = f[0] V = numpy.linspace(*VLIM) wl = [fiber.toWl(v) for v in V[::-1]] sim = Simulator(f, wl, vectorial=vectorial, scalar=scalar, delta=1e-5) co = next(sim.cutoff()) b = next(sim.b()) assert len(b) == len(wl) for mode, cutoff in co[0].items(): if cutoff == 0: continue # skip HE(1,1) / LP(0,1) color = MODE_COLORS[str(mode)] axes[i].axvline(cutoff, ls=':', color=color) b_ = numpy.empty(len(wl)) for j, b__ in enumerate(b): b_[j] = b__.get(mode, float("nan")) lines[mode], = axes[i].plot(V[::-1], b_, color=color) if i == 1 and vectorial is True: # fiber b r = Rectangle((4.6, 0), 0.8, 0.04, alpha=.3, facecolor='grey') axes[i].add_patch(r) handles = [lines[k] for k in sorted(lines)] labels = [str(k) for k in sorted(lines)] leg = fig.legend(handles, labels, loc='upper left', bbox_to_anchor=(0.18, 1), frameon=True) frame = leg.get_frame() frame.set_linewidth(0) fig.text(0.04, 0.5, "Normalized propagation constant ($b$)", rotation='vertical', ha='center', va='center') axes[-1].set_xlabel("Normalized frequency ($V_0$)") fig.tight_layout(rect=(0.04, 0, 1, 1))
def testFindLPmodes(self): f = FiberFactory() f.addLayer(radius=4.5e-6, index=1.448918) f.addLayer(index=1.444418) fiber = f[0] wl = Wavelength(800e-9) modes = fiber.findLPmodes(wl) self.assertEqual(len(modes), 4)
def testSetAttributes(self): f = FiberFactory() f.name = "smf28" f.author = "Charles Brunet" f.description = "Single mode fiber" f.addLayer() f.layers[0].name = "core" self.assertEqual(f.name, "smf28") self.assertEqual(f.author, "Charles Brunet") self.assertEqual(f.description, "Single mode fiber") self.assertEqual(f.layers[0].name, "core")
def testFundamental(self): f = FiberFactory() f.addLayer(radius=4.5e-6, index=1.448918) f.addLayer(index=1.444418) fiber = f[0] wl = Wavelength(1550e-9) neff = fiber.neff(Mode('HE', 1, 1), wl) self.assertAlmostEqual(neff, 1.4464045, places=5) lp01 = fiber.neff(Mode('LP', 0, 1), wl) self.assertAlmostEqual(lp01, neff, places=5)
def testCutoffLP(self): f = FiberFactory() f.addLayer(radius=1e-5 / 3, index=5) f.addLayer(index=4) fiber = f[0] sols = [(Mode('LP', 0, 1), 0), (Mode('LP', 0, 2), 3.8317), (Mode('LP', 0, 3), 7.0156), (Mode('LP', 1, 1), 2.4048), (Mode('LP', 1, 2), 5.5201), (Mode('LP', 2, 1), 3.8317)] for mode, V0 in sols: self.assertAlmostEqual(fiber.cutoff(mode), V0, 4, msg=str(mode))
def example2(): """2. Creating families of fibers: list of parameters""" # Varying core radius factory = FiberFactory() factory.addLayer(name="core", radius=[1e-6, 2e-6, 3e-6, 4e-6, 5e-6], index=1.474) factory.addLayer() for i, fiber in enumerate(factory): print(factory.layers[0].radius[i], fiber.neff(Mode("HE", 1, 1), 1550e-9)) # Varying core index n = numpy.linspace(1.454, 1.494) factory = FiberFactory() factory.addLayer(name="core", radius=4e-6, index=n) factory.addLayer(name="cladding") fibers = list(factory) print(fibers) neff = numpy.zeros(n.shape) for i, fiber in enumerate(factory): neff[i] = fiber.neff(Mode("HE", 1, 1), 1550e-9) pyplot.plot(n, neff) pyplot.title("neff as function of core index (HE 1,1 mode)") pyplot.xlabel("core index") pyplot.ylabel("effective index") pyplot.show()
def main(): wl = Wavelength(1550e-9) ff1 = FiberFactory() ff1.addLayer(name="core", radius=8e-6, material="Fixed", geometry="StepIndex", index=1.454) ff1.addLayer(name="cladding", index=1.444) fiber1 = ff1[0] neff1 = fiber1.neff(Mode("HE", 1, 1), wl) print(neff1) ff2 = FiberFactory() ff2.addLayer(name="core", radius=8e-6, material="Fixed", geometry="SuperGaussian", tparams=[0, 2e-6, 1], index=1.454) ff2.addLayer(name="cladding", index=1.444) fiber2 = ff2[0] neff2 = fiber2.neff(Mode("HE", 1, 1), wl, lowbound=neff1) print(neff2)
def testSetFactory(self): sim = self.Simulator() sim.set_factory(os.path.join(__dir__, '..', 'fiber', 'rcfs.fiber')) self.assertEqual(len(sim.fibers), 5) f = FiberFactory() f.addLayer(radius=[4e-6, 5e-6, 6e-6], index=1.449) f.addLayer(index=1.444) sim.set_factory(f) self.assertEqual(len(sim.fibers), 3) with self.assertRaises(ValueError): sim.wavelengths self.assertFalse(sim.initialized) self.assertTrue(sim._fsims is None)
def fromVDelta(V, Delta, wl): """To match Bures examples params(3.9, 0.26, wl) # Bures 3.25 """ nco = numpy.sqrt(1.444**2 / (1 - Delta * 2)) rho = V / wl.k0 / numpy.sqrt(nco**2 - 1.444**2) f = FiberFactory() f.addLayer(name="core", radius=rho, index=nco) f.addLayer(name="cladding", index=1.444) fiber = f[0] print(fiber) return fiber
def fromVDelta(V, Delta, wl): """To match Bures examples params(3.9, 0.26, wl) # Bures 3.25 """ nco = numpy.sqrt(1.444**2 / (1 - Delta*2)) rho = V / wl.k0 / numpy.sqrt(nco**2 - 1.444**2) f = FiberFactory() f.addLayer(name="core", radius=rho, index=nco) f.addLayer(name="cladding", index=1.444) fiber = f[0] print(fiber) return fiber
def example4(): """2. Creating families of fibers: parameter as code""" factory = FiberFactory() factory.addLayer(radius="return 4e-6", index="return 1.474") factory.addLayer() fiber = factory[0] print('core radius:', fiber.outerRadius(0)) print('core index:', fiber.maxIndex(0, 1550e-9)) factory = FiberFactory() factory.addLayer(radius={'start': 1e-6, 'end': 10e-6, 'num': 10}) factory.addLayer(radius="return r[0] + 2e-6", index=1.474) factory.addLayer() print('layer 0 radius', '/', 'layer 1 radius') for fiber in factory: print(fiber.outerRadius(0), '/', fiber.outerRadius(1))
def ACF(): f = FiberFactory() f.addLayer(name="air", radius=9.1e-6, material="Air") f.addLayer(name="ring", radius=11.3e-6, material="SiO2GeO2", x=0.192) f.addLayer(name="trench", radius=16.2e-6, material="SiO2F", x=0.013) f.addLayer(name="cladding", material="Silica") fiber = f[0] print(fiber) return fiber
def testFindVmodes(self): f = FiberFactory() f.addLayer(radius=4.5e-6, index=1.448918) f.addLayer(index=1.444418) fiber = f[0] wl = Wavelength(800e-9) modes = fiber.findVmodes(wl) sols = [(Mode('HE', 1, 1), 1.4479082), (Mode('TE', 0, 1), 1.44643), (Mode('HE', 2, 1), 1.446427), (Mode('TM', 0, 1), 1.4464268), (Mode('EH', 1, 1), 1.444673), (Mode('HE', 3, 1), 1.444669), (Mode('HE', 1, 2), 1.4444531)] self.assertEqual(len(modes), len(sols)) for mode, neff in sols: self.assertTrue(mode in modes) self.assertAlmostEqual(fiber.neff(mode, wl), neff)
def main(): delta = 0.3 V = 5 wl = Wavelength(1.55e-6) n2 = 1.444 n1 = sqrt(n2**2 / (1 - 2 * delta)) rho = V / (sqrt(n1**2 - n2**2) * wl.k0) f = FiberFactory() f.addLayer(radius=rho, index=n1) f.addLayer(index=n2) fiber = f[0] modes = fiber.findVmodes(wl) for m in modes: neff = fiber.neff(m, wl, delta=1e-5)
def plot_b_vs_V(vectorial=True, scalar=False): nf = len(FIBERS) fig, axes = pyplot.subplots(nf, 1, sharex=False, sharey=False, subplot_kw={'xlim': VLIM, 'ylim': (0, 0.3)}, figsize=(6, 9)) sns.despine(fig) lines = {} for i, (name, r, n) in enumerate(FIBERS): axes[i].set_title(name) f = FiberFactory() for (r_, n_) in zip_longest(r, n): f.addLayer(radius=r_, index=n_) fiber = f[0] V = numpy.linspace(*VLIM) wl = [fiber.toWl(v) for v in V[::-1]] sim = Simulator(f, wl, vectorial=vectorial, scalar=scalar, delta=1e-5) co = next(sim.cutoff()) b = next(sim.b()) assert len(b) == len(wl) for mode, cutoff in co[0].items(): if cutoff == 0: continue # skip HE(1,1) / LP(0,1) color = MODE_COLORS[str(mode)] axes[i].axvline(cutoff, ls=':', color=color) b_ = numpy.empty(len(wl)) for j, b__ in enumerate(b): b_[j] = b__.get(mode, float("nan")) lines[mode], = axes[i].plot(V[::-1], b_, color=color) if i == 1 and vectorial is True: # fiber b r = Rectangle((4.6, 0), 0.8, 0.04, alpha=.3, facecolor='grey') axes[i].add_patch(r) handles = [lines[k] for k in sorted(lines)] labels = [str(k) for k in sorted(lines)] leg = fig.legend(handles, labels, loc='upper left', bbox_to_anchor=(0.18, 1), frameon=True) frame = leg.get_frame() frame.set_linewidth(0) fig.text(0.04, 0.5, "Normalized propagation constant ($b$)", rotation='vertical', ha='center', va='center') axes[-1].set_xlabel("Normalized frequency ($V_0$)") fig.tight_layout(rect=(0.04, 0, 1, 1))
def testToWl(self): f = FiberFactory(os.path.join(__dir__, 'smf28.fiber')) fiber = f[0] self.assertAlmostEqual(fiber.toWl(fiber.V0(1600e-9)), 1600e-9) f.layers[0].material = "Silica" f.layers[1].material = "Air" fiber = f[0] self.assertAlmostEqual(fiber.toWl(fiber.V0(1600e-9)), 1600e-9) self.assertEqual(fiber.toWl(float("inf")), 0) self.assertTrue(isinf(fiber.toWl(0))) with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=OutOfRangeWarning) f = FiberFactory() f.addLayer(radius=10e-6, material="SiO2GeO2", x=0.25) f.addLayer(material="Silica") fiber = f[0] wl = fiber.toWl(2.4) self.assertGreater(wl, 10e-6)
def example1(): """1. Defining fiber layers""" factory = FiberFactory() factory.name = "Name of your fiber" factory.author = "Your Name" factory.description = "Description of your fiber" print('crdate:', datetime.datetime.fromtimestamp( int(factory.crdate)).strftime('%Y-%m-%d %H:%M:%S')) print('tstamp:', datetime.datetime.fromtimestamp( int(factory.tstamp)).strftime('%Y-%m-%d %H:%M:%S')) # Default parameters factory.addLayer() # Comp material: molar fraction factory.addLayer(pos=0, name="core", geometry="StepIndex", radius=4e-6, material="SiO2GeO2", x=0.1) # Comp material: index and wavelength factory.addLayer(pos=1, name="trench", radius=6e-6, material="SiO2F", index=1.441, wl=1550e-9) # Getting information from layers print('Name of layer 0:', factory.layers[0].name) print('Radius of layer 1:', factory.layers[1].radius) factory.layers[2].name = "cladding" print('Name of layer 2:', factory.layers[2].name)
def testCutoffV3(self): """Same index for n1 and n2; therefore this is SSIF.""" n1 = 1.6 n2 = 1.6 n3 = 1.4 rho1 = 5e-6 rho2 = 6e-6 f = FiberFactory() f.addLayer(radius=rho1, index=n1) f.addLayer(radius=rho2, index=n2) f.addLayer(index=n3) fiber = f[0] sols = [(Mode('TE', 0, 1), 2.4048), (Mode('HE', 2, 1), 2.522748641920963), (Mode('TM', 0, 1), 2.4048), (Mode('EH', 1, 1), 3.8317), (Mode('HE', 3, 1), 3.9762622998101453), (Mode('HE', 1, 2), 3.8317)] for mode, V0 in sols: self.assertAlmostEqual(fiber.cutoff(mode), V0, 4, msg=str(mode))
def example1(): """Counting modes and finding cutoffs.""" factory = FiberFactory() factory.addLayer(radius=10e-6, index=1.474) factory.addLayer() # Print list of modes sim = Simulator(factory, [1550e-9]) modes = next(sim.modes())[0] # modes of first wavelength of next fiber print(", ".join(str(mode) for mode in sorted(modes))) print() # Print cutoff (as V number) cutoffs = next(sim.cutoff())[0] # first wavelength of next fiber for mode, co in cutoffs.items(): print(str(mode), co) print() # Print cutoff (as wavelength) cutoffswl = next(sim.cutoffWl())[0] # first wavelength of next fiber for mode, co in cutoffswl.items(): print(str(mode), str(co)) print()
def testImpossibleRadius(self): """TODO: not implemented yet""" f = FiberFactory() f.addLayer(radius=10e-6, index=1.174) f.addLayer(radius=4e-6, index=1.444) f.addLayer() self.assertEqual(len(f), 0)
def _testFiberCutoffs(self, r, n): f = FiberFactory() for r_, n_ in zip_longest(r, n): f.addLayer(radius=r_, index=n_) fiber = f[0] for nu in range(1, 5): pco = -1 for m in range(1, 5): for fam in (ModeFamily.HE, ModeFamily.EH): mode = Mode(fam, nu, m) co = fiber.cutoff(mode) self.assertGreater(co, pco, "Not greater "+str(mode)) if mode != HE11: d = 0. b = float("nan") while isnan(b): d += 0.25 wl = fiber.toWl(co + d) b = fiber.b(mode, wl, delta=1e-5) self.assertLess(b, 0.1, "Wrong b "+str(mode)) pco = co
def _testFiberCutoffs(self, r, n): f = FiberFactory() for r_, n_ in zip_longest(r, n): f.addLayer(radius=r_, index=n_) fiber = f[0] for nu in range(1, 5): pco = -1 for m in range(1, 5): for fam in (ModeFamily.HE, ModeFamily.EH): mode = Mode(fam, nu, m) co = fiber.cutoff(mode) self.assertGreater(co, pco, "Not greater " + str(mode)) if mode != HE11: d = 0. b = float("nan") while isnan(b): d += 0.25 wl = fiber.toWl(co + d) b = fiber.b(mode, wl, delta=1e-5) self.assertLess(b, 0.1, "Wrong b " + str(mode)) pco = co
def RCF2(): x = 0.19 r1 = 125 * 1.4 / 180 * 1e-6 r2 = 125 * 4 / 180 * 1e-6 f = FiberFactory() f.addLayer(name="center", radius=r1, material="Silica") f.addLayer(name="ring", radius=r2, material="SiO2GeO2", x=x) f.addLayer(name="cladding", material="Silica") fiber = f[0] print(fiber) return fiber
def compute_fiber(filename, nrho, R2, C2, wl, numax=None, mmax=None): # Initialize simulators sim = [] for i, r2 in enumerate(R2): r1 = numpy.linspace(0, r2, nrho, endpoint=False) factory = FiberFactory() factory.addLayer(radius=r1, material='Silica') factory.addLayer(radius=r2, material='SiO2GeO2', x=C2) factory.addLayer(material='Silica') sim.append(Simulator(factory, wl)) nr2 = R2.size nc2 = C2.size ckfile, _ = os.path.splitext(filename) ckfile += '.ckp.npz' if os.path.isfile(ckfile): # Restore checkpoint data = numpy.load(ckfile) modes = [Mode(*a) for a in data['modes']] results = {'modes': modes} for fct in ('cutoff', 'neff', 'beta1', 'beta2', 'beta3'): results[fct] = data[fct] else: # Find modes sim[-1].numax = numax sim[-1].mmax = mmax modes = find_mode_list(sim[-1]) # Initialize arrays shape = (nrho, nr2, C2.size, len(modes)) results = {'modes': modes} for fct in ('cutoff', 'neff', 'beta1', 'beta2', 'beta3'): results[fct] = numpy.empty(shape) results[fct].fill(numpy.nan) Rho = numpy.linspace(0, 1, nrho, endpoint=False) for i, r2 in enumerate(R2[::-1], 1): print("Solving when r2={:.3f}µm".format(r2 * 1e6)) if numpy.all(numpy.isnan(results['cutoff'][:, nr2 - i, :, :])): numax, mmax = compute_fiber_r2(results, modes, sim[-i], nr2 - i, Rho, r2, nc2, numax, mmax) numpy.savez_compressed(ckfile, **results) # Save checkpoint os.rename(ckfile, filename) return results
def build_factory(nr1, r2, cn2): """Create a FiberFactory for RCF from given arguments. Args: nr1(int): Number of points for r1 r2(float): Radius r2 cn2(float): Concentration for ring-core Returns; FiberFactory """ r1 = numpy.linspace(0, r2, nr1, endpoint=False) factory = FiberFactory() factory.addLayer(radius=r1, material='Silica') factory.addLayer(radius=r2, material='SiO2GeO2', x=cn2) factory.addLayer(material='Silica') return factory