Exemplo n.º 1
0
 def test_dynamic(self):
     dynamic_simulation = DynamicSimulation(self.time_steps, self.fiber)
     dynamic_simulation.add_forward_signal(wl=self.signal_wl,
                                           input_power=self.signal_power,
                                           loss=decibel_to_exp(1))
     dynamic_simulation.add_backward_pump(wl=self.pump_wl,
                                          input_power=self.pump_power,
                                          loss=decibel_to_exp(2))
     dynamic_simulation.add_forward_pump(wl=self.pump_wl,
                                         input_power=self.pump_power)
     dynamic_result = dynamic_simulation.run(self.z_nodes,
                                             stop_at_steady_state=True,
                                             dt=1e-7)
     dyn_losses = dynamic_result.powers_at_fiber_end() / np.array(
         [self.signal_power, self.pump_power, self.pump_power])
     self.assertTrue(
         np.allclose(to_db(dyn_losses),
                     self.expected_losses,
                     atol=1e-2,
                     rtol=1e-5))
Exemplo n.º 2
0
    def test_steady_state_python_and_cpp_two_rings(self):
        fiber_with_rings = deepcopy(self.fiber)
        dynamic_simulation = DynamicSimulation(self.time_steps, fiber_with_rings)
        fiber_with_rings.doping_profile = DopingProfile(ion_number_densities=[self.nt, self.nt],
                                                        radii=[self.fiber.core_radius / 2, self.fiber.core_radius],
                                                        num_of_angular_sections=1,
                                                        core_radius=fiber_with_rings.core_radius)
        dynamic_simulation.add_forward_signal(wl=self.signal_wl, input_power=self.signal_power)
        dynamic_simulation.add_backward_pump(wl=self.pump_wl, input_power=self.pump_power / 2)
        dynamic_simulation.add_forward_pump(wl=self.pump_wl, input_power=self.pump_power / 2)
        dynamic_simulation.add_ase(wl_start=1020e-9, wl_end=1040e-9, n_bins=3)

        dynamic_simulation.use_cpp_backend()
        cpp_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt, stop_at_steady_state=True)

        dynamic_simulation.use_python_backend()
        python_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt, stop_at_steady_state=True)

        dynamic_simulation.use_pythran_backend()
        pythran_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt,
                                                stop_at_steady_state=True)

        dynamic_simulation.use_numba_backend()
        numba_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt, stop_at_steady_state=True)

        cpp_output_powers = cpp_result.powers_at_fiber_end()
        python_output_powers = python_result.powers_at_fiber_end()
        pythran_output_powers = pythran_result.powers_at_fiber_end()
        numba_output_powers = numba_result.powers_at_fiber_end()

        expected_output_regression = np.array([1.24777744e-01, 3.00422189e-01, 2.20328594e-07,
                                               2.32154962e-07, 1.80296310e-07, 3.01232103e-01,
                                               2.42163293e-07, 2.52449606e-07, 1.91762700e-07])
        self.assertTrue(np.allclose(cpp_output_powers, python_output_powers, rtol=1e-6))
        self.assertTrue(np.allclose(cpp_output_powers, expected_output_regression, rtol=1e-6))
        self.assertTrue(np.allclose(pythran_output_powers, expected_output_regression, rtol=1e-6))
        self.assertTrue(np.allclose(numba_output_powers, expected_output_regression, rtol=1e-6))
Exemplo n.º 3
0
    def test_steady_state_python_and_cpp_single_ring(self):
        steady_state_simulation = SteadyStateSimulation(self.fiber)
        steady_state_simulation.add_forward_signal(wl=self.signal_wl, input_power=self.signal_power)
        steady_state_simulation.add_backward_pump(wl=self.pump_wl, input_power=self.pump_power / 2)
        steady_state_simulation.add_forward_pump(wl=self.pump_wl, input_power=self.pump_power / 2)
        steady_state_simulation.add_ase(wl_start=1020e-9, wl_end=1040e-9, n_bins=3)
        steady_state_result = steady_state_simulation.run(tol=1e-5)

        dynamic_simulation = DynamicSimulation(self.time_steps, self.fiber)
        dynamic_simulation.add_forward_signal(wl=self.signal_wl, input_power=self.signal_power)
        dynamic_simulation.add_backward_pump(wl=self.pump_wl, input_power=self.pump_power / 2)
        dynamic_simulation.add_forward_pump(wl=self.pump_wl, input_power=self.pump_power / 2)
        dynamic_simulation.add_ase(wl_start=1020e-9, wl_end=1040e-9, n_bins=3)

        dynamic_simulation.use_cpp_backend()
        cpp_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt, stop_at_steady_state=True)

        dynamic_simulation.use_python_backend()
        python_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt, stop_at_steady_state=True)

        dynamic_simulation.use_pythran_backend()
        pythran_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt,
                                                stop_at_steady_state=True)

        dynamic_simulation.use_numba_backend()
        numba_result = dynamic_simulation.run(z_nodes=self.z_nodes, dt=self.steady_state_dt, stop_at_steady_state=True)

        steady_state_output_powers = steady_state_result.powers_at_fiber_end()
        cpp_output_powers = cpp_result.powers_at_fiber_end()
        python_output_powers = python_result.powers_at_fiber_end()
        pythran_output_powers = pythran_result.powers_at_fiber_end()
        numba_output_powers = numba_result.powers_at_fiber_end()
        self.assertTrue(np.allclose(steady_state_output_powers, cpp_output_powers, rtol=1e-3))
        self.assertTrue(np.allclose(cpp_output_powers, python_output_powers, rtol=1e-6))
        self.assertTrue(np.allclose(pythran_output_powers, python_output_powers, rtol=1e-6))
        self.assertTrue(np.allclose(numba_output_powers, python_output_powers, rtol=1e-6))
Exemplo n.º 4
0
 def test_available_backends(self):
     dynamic_simulation = DynamicSimulation(self.time_steps, self.fiber)
     print('Tested dynamic backends: {}'.format(dynamic_simulation.backends))
Exemplo n.º 5
0
    def test_steady_state_reflection(self):
        dynamic_simulation = DynamicSimulation(self.time_steps, self.fiber)
        dynamic_simulation.add_forward_signal(wl=self.signal_wl,
                                              input_power=self.signal_power,
                                              channel_id='forward_signal',
                                              reflection_target_id='reflected_signal',
                                              reflectance=0.04)
        dynamic_simulation.add_backward_signal(wl=self.signal_wl,
                                               input_power=1e-15,
                                               channel_id='reflected_signal')
        dynamic_simulation.add_backward_pump(wl=self.pump_wl,
                                             input_power=self.pump_power)

        dynamic_simulation.use_cpp_backend()
        cpp_res = dynamic_simulation.run(z_nodes=self.z_nodes,
                                         dt=self.steady_state_dt,
                                         stop_at_steady_state=True)

        dynamic_simulation.use_python_backend()
        python_res = dynamic_simulation.run(z_nodes=self.z_nodes,
                                            dt=self.steady_state_dt,
                                            stop_at_steady_state=True)

        dynamic_simulation.use_pythran_backend()
        pythran_res = dynamic_simulation.run(z_nodes=self.z_nodes,
                                             dt=self.steady_state_dt,
                                             stop_at_steady_state=True)

        dynamic_simulation.use_numba_backend()
        numba_res = dynamic_simulation.run(z_nodes=self.z_nodes,
                                           dt=self.steady_state_dt,
                                           stop_at_steady_state=True)

        cpp_output = cpp_res.powers_at_fiber_end()
        python_output = python_res.powers_at_fiber_end()
        pythran_output = pythran_res.powers_at_fiber_end()
        numba_output = numba_res.powers_at_fiber_end()
        expected_output = np.array([0.11878692, 0.00564412, 0.47651562])
        self.assertTrue(np.allclose(cpp_output, python_output, rtol=1e-6))
        self.assertTrue(np.allclose(cpp_output, expected_output, rtol=1e-6))
        self.assertTrue(np.allclose(pythran_output, expected_output, rtol=1e-6))
        self.assertTrue(np.allclose(numba_output, expected_output, rtol=1e-6))
Exemplo n.º 6
0
    def test_steady_state_python_and_cpp_two_rings(self):
        dynamic_simulation = DynamicSimulation(self.time_steps)
        fiber_with_rings = deepcopy(self.fiber)
        fiber_with_rings.set_doping_profile(
            ion_number_densities=[self.nt, self.nt],
            radii=[self.fiber.core_radius / 2, self.fiber.core_radius])
        dynamic_simulation.fiber = fiber_with_rings
        dynamic_simulation.add_forward_signal(wl=self.signal_wl,
                                              input_power=self.signal_power)
        dynamic_simulation.add_backward_pump(wl=self.pump_wl,
                                             input_power=self.pump_power / 2)
        dynamic_simulation.add_forward_pump(wl=self.pump_wl,
                                            input_power=self.pump_power / 2)
        dynamic_simulation.add_ase(wl_start=1020e-9, wl_end=1040e-9, n_bins=3)

        dynamic_simulation.use_cpp_backend()
        cpp_result = dynamic_simulation.run(z_nodes=self.z_nodes,
                                            dt=self.steady_state_dt,
                                            stop_at_steady_state=True)

        dynamic_simulation.use_python_backend()
        python_result = dynamic_simulation.run(z_nodes=self.z_nodes,
                                               dt=self.steady_state_dt,
                                               stop_at_steady_state=True)

        cpp_output_powers = cpp_result.powers_at_fiber_end()
        python_output_powers = python_result.powers_at_fiber_end()

        expected_output_regression = np.array([
            1.24777656e-01, 3.00423131e-01, 2.20330515e-07, 2.32158298e-07,
            1.80295869e-07, 3.01233048e-01, 2.42165526e-07, 2.52453304e-07,
            1.91762386e-07
        ])
        self.assertTrue(
            np.allclose(cpp_output_powers, python_output_powers, rtol=1e-6))
        self.assertTrue(
            np.allclose(cpp_output_powers,
                        expected_output_regression,
                        rtol=1e-6))
Exemplo n.º 7
0
    def test_steady_state_python_and_cpp_preset_areas_and_overlaps(self):
        dynamic_simulation = DynamicSimulation(self.time_steps)
        fiber_with_rings = deepcopy(self.fiber)
        r = self.fiber.core_radius
        areas = np.pi * (np.array([r / 2, r])**2 - np.array([0, r / 2])**2)
        overlaps = [0.5, 0.2]
        fiber_with_rings.set_doping_profile(
            ion_number_densities=[self.nt, self.nt], areas=areas)
        dynamic_simulation.fiber = fiber_with_rings
        dynamic_simulation.add_forward_signal(
            wl=self.signal_wl,
            input_power=self.signal_power,
            mode_shape_parameters={'overlaps': overlaps})
        dynamic_simulation.add_backward_pump(
            wl=self.pump_wl,
            input_power=self.pump_power / 2,
            mode_shape_parameters={'overlaps': overlaps})
        dynamic_simulation.add_forward_pump(
            wl=self.pump_wl,
            input_power=self.pump_power / 2,
            mode_shape_parameters={'overlaps': overlaps})

        dynamic_simulation.use_cpp_backend()
        cpp_result = dynamic_simulation.run(z_nodes=self.z_nodes,
                                            dt=self.steady_state_dt / 10,
                                            stop_at_steady_state=True)

        dynamic_simulation.use_python_backend()
        python_result = dynamic_simulation.run(z_nodes=self.z_nodes,
                                               dt=self.steady_state_dt / 10,
                                               stop_at_steady_state=True)

        expected_output_regression = np.array(
            [0.1166232, 0.23989275, 0.23988858])
        cpp_output_powers = cpp_result.powers_at_fiber_end()
        python_output_powers = python_result.powers_at_fiber_end()
        self.assertTrue(
            np.allclose(cpp_output_powers, python_output_powers, rtol=1e-6))
        self.assertTrue(
            np.allclose(cpp_output_powers,
                        expected_output_regression,
                        rtol=1e-6))
    def setUpClass(cls):
        yb_number_density = 5e25
        radii = np.array([2, 4, 6, 8, 10]) * 1e-6
        core_radius = 10e-6
        doping_radius = 6e-6
        confined_doping_profile = DopingProfile(
            radii=radii[:-2],
            num_of_angular_sections=6,
            ion_number_densities=[yb_number_density] * 18,
            core_radius=core_radius)

        confined_fiber_length = 30
        core_na = 0.065
        core_clad_ratio = 20 / 400
        signal_wl = 1064e-9
        pump_wl = 976e-9
        confined_fiber_20_400 = YbDopedDoubleCladFiber(
            length=confined_fiber_length,
            core_radius=core_radius,
            ion_number_density=0,
            background_loss=0,
            core_na=core_na,
            ratio_of_core_and_cladding_diameters=core_clad_ratio)
        confined_fiber_20_400.doping_profile = confined_doping_profile
        fundamental_mode_content = 0.98
        lp11_content = (1 - fundamental_mode_content)
        signal_power = 5  # W
        LP01_power = fundamental_mode_content * signal_power
        LP11_cos_power = 0.5 * lp11_content * signal_power
        LP11_sin_power = 0.5 * lp11_content * signal_power
        pump_power = 1000
        max_time_steps = 1_000_000
        z_nodes = 200
        fiber_modes = mode_solver.find_all_modes(core_radius, core_na,
                                                 signal_wl)
        confined_fiber_simulation = DynamicSimulation(max_time_steps,
                                                      confined_fiber_20_400)
        confined_fiber_simulation.add_forward_signal(wl=signal_wl,
                                                     input_power=LP01_power,
                                                     mode=fiber_modes[0],
                                                     channel_id='LP01')
        confined_fiber_simulation.add_forward_signal(
            wl=signal_wl,
            input_power=LP11_cos_power,
            mode=fiber_modes[1],
            channel_id='LP11_cos')
        confined_fiber_simulation.add_forward_signal(
            wl=signal_wl,
            input_power=LP11_sin_power,
            mode=fiber_modes[2],
            channel_id='LP11_sin')

        confined_fiber_simulation.add_backward_pump(wl=pump_wl,
                                                    input_power=pump_power,
                                                    channel_id='Pump')
        cls.confined_res = confined_fiber_simulation.run(
            z_nodes, dt=1e-7, stop_at_steady_state=True)