Ejemplo n.º 1
0
    def test_steady_state_python_and_cpp_single_ring(self):
        steady_state_simulation = SteadyStateSimulation()
        steady_state_simulation.fiber = self.fiber
        steady_state_simulation.add_cw_signal(wl=self.signal_wl,
                                              power=self.signal_power)
        steady_state_simulation.add_backward_pump(wl=self.pump_wl,
                                                  power=self.pump_power / 2)
        steady_state_simulation.add_forward_pump(wl=self.pump_wl,
                                                 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)
        dynamic_simulation.fiber = 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))
Ejemplo n.º 2
0
 def test_steady_state(self):
     steady_state_simulation = SteadyStateSimulation(self.fiber)
     steady_state_simulation.add_forward_signal(
         wl=self.signal_wl,
         input_power=self.signal_power,
         loss=self.signal_loss)
     steady_state_simulation.add_forward_pump(wl=self.pump_wl,
                                              input_power=self.pump_power)
     steady_state_simulation.add_backward_pump(wl=self.pump_wl,
                                               input_power=self.pump_power,
                                               loss=self.bw_pump_loss)
     steady_state_result = steady_state_simulation.run(tol=1e-5)
     ss_losses = steady_state_result.powers_at_fiber_end() / np.array(
         [self.signal_power, self.pump_power, self.pump_power])
     self.assertTrue(
         np.allclose(to_db(ss_losses),
                     self.expected_losses,
                     atol=1e-3,
                     rtol=1e-5))