def generate_map_and_waterfall_plots(domain): """ Generate map and waterfall plots to visualise pulse propagation. """ system = System(domain) system.add(Sech(peak_power=4.0, width=1.0)) system.add( Fibre("fibre", length=0.5 * np.pi, beta=[0.0, 0.0, -1.0, 0.0], gamma=1.0, method="rk4ip", total_steps=1000, traces=50)) system.run() storage = system['fibre'].stepper.storage (x, y, z) = storage.get_plot_data(reduced_range=(95.0, 105.0)) map_plot(x, y, z, labels["t"], labels["P_t"], labels["z"], filename="soliton_map") waterfall_plot(x, y, z, labels["t"], labels["z"], labels["P_t"], filename="soliton_waterfall", y_range=(0.0, 16.0))
def generate_overview_plots(domain): """ Generate single, map, and waterfall plots of the soliton collision. """ system = System(domain) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.625)) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.375, offset_nu=-0.8)) system.add(Fibre(length=400.0, beta=[0.0, 0.0, -0.1, 0.0], gamma=2.2, total_steps=400, traces=100, method='ARK4IP', local_error=1e-6)) system.run() storage = system['fibre'].stepper.storage (x, y, z) = storage.get_plot_data(reduced_range=(140.0, 360.0)) # Split step_sizes (list of tuples) into separate lists; # distances and steps: (distances, steps) = zip(*storage.step_sizes) print np.sum(steps) single_plot(distances, steps, labels["z"], "Step size, h (km)", filename="soliton_collision_steps") map_plot(x, y, z, labels["t"], labels["P_t"], labels["z"], filename="soliton_collision_map") waterfall_plot(x, y, z, labels["t"], labels["z"], labels["P_t"], filename="soliton_collision_waterfall", y_range=(0.0, 0.02))
def save_simulations(domain, data_directory, methods, target_errors): """ Save simulation data for each method to file. """ for method in methods: print("%s" % method) for target_error in target_errors: print("\t%.1e" % target_error) method_error = "-".join([method, "%.0e" % (target_error)]) filename = os.path.join(data_directory, method_error) system = System(domain) system.add( Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.625)) system.add( Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.375, offset_nu=-0.8)) system.add( Fibre("fibre", length=400.0, beta=[0.0, 0.0, -0.1, 0.0], gamma=2.2, method=method, local_error=target_error)) system.run() A_calc = system.fields['fibre'] storage = system["fibre"].stepper.storage np.savez(filename, field=A_calc, ffts=storage.fft_total)
def save_simulations(domain, data_directory, methods, target_errors): """ Save simulation data for each method to file. """ for method in methods: print "%s" % method for target_error in target_errors: print "\t%.1e" % target_error method_error = "-".join([method, "%.0e" % (target_error)]) filename = os.path.join(data_directory, method_error) system = System(domain) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.625)) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.375, offset_nu=-0.8)) system.add(Fibre("fibre", length=400.0, beta=[0.0, 0.0, -0.1, 0.0], gamma=2.2, method=method, local_error=target_error)) system.run() A_calc = system.fields['fibre'] storage = system["fibre"].stepper.storage np.savez(filename, field=A_calc, ffts=storage.fft_total)
def generate_overview_plots(domain): """ Generate single, map, and waterfall plots of the soliton collision. """ system = System(domain) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.625)) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.375, offset_nu=-0.8)) system.add(Fibre(length=400.0, beta=[0.0, 0.0, -0.1, 0.0], gamma=2.2, total_steps=400, traces=100, method='ARK4IP', local_error=1e-6)) system.run() storage = system['fibre'].stepper.storage (x, y, z) = storage.get_plot_data(reduced_range=(140.0, 360.0)) # Split step_sizes (list of tuples) into separate lists; # distances and steps: (distances, steps) = list(zip(*storage.step_sizes)) print(np.sum(steps)) single_plot(distances, steps, labels["z"], "Step size, h (km)", filename="soliton_collision_steps") map_plot(x, y, z, labels["t"], labels["P_t"], labels["z"], filename="soliton_collision_map") waterfall_plot(x, y, z, labels["t"], labels["z"], labels["P_t"], filename="soliton_collision_waterfall", y_range=(0.0, 0.02))
def save_simulations(domain, data_directory, methods, target_errors): """ Save data for each method and target error to file. """ for method in methods: print("%s" % method) for target_error in target_errors: print("\t%.1e" % target_error) method_error = "-".join([method, "%.0e" % (target_error)]) filename = os.path.join(data_directory, method_error) system = System(domain) system.add(Sech(peak_power=4.0, width=1.0)) system.add( Fibre("fibre", length=0.5 * np.pi, beta=[0.0, 0.0, -1.0, 0.0], gamma=1.0, method=method, local_error=target_error)) system.run() A_calc = system.fields['fibre'] storage = system["fibre"].stepper.storage np.savez(filename, field=A_calc, ffts=storage.fft_total)
def generate_reference(domain, data_directory): """ Generate a reference field (to machine precision), used as A_true. """ system = System(domain) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.125)) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=-0.125, offset_nu=-0.8)) system.add(Fibre("fibre", length=400.0, beta=[0.0, 0.0, -0.1, 0.0], gamma=2.2, method="ark4ip", local_error=1e-14)) system.run() A_true = system.field filename = os.path.join(data_directory, "reference_field") np.save(filename, A_true)
def generate_reference(domain, data_directory): """ Generate a reference field (to machine precision), used as A_true. """ system = System(domain) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.625)) system.add(Sech(peak_power=8.8e-3, width=(1.0 / 0.44), position=0.375, offset_nu=-0.8)) system.add(Fibre("fibre", length=400.0, beta=[0.0, 0.0, -0.1, 0.0], gamma=2.2, method="ark4ip", local_error=1e-14)) system.run() A_true = system.field filename = os.path.join(data_directory, "reference_field") np.save(filename, A_true)
def save_simulations(domain, data_directory, methods, steps): """ Save data for each method and step to file. """ for method in methods: print "%s" % method for step in steps: print "\t%d" % step method_step = "-".join([method, str(step)]) filename = os.path.join(data_directory, method_step) system = System(domain) system.add(Sech(peak_power=4.0, width=1.0)) system.add( Fibre( "fibre", length=0.5 * np.pi, beta=[0.0, 0.0, -1.0, 0.0], gamma=1.0, method=method, total_steps=step ) ) system.run() A_calc = system.fields["fibre"] np.save(filename, A_calc)
def save_simulations(domain, data_directory, methods, target_errors): """ Save data for each method and target error to file. """ for method in methods: print "%s" % method for target_error in target_errors: print "\t%.1e" % target_error method_error = "-".join([method, "%.0e" % (target_error)]) filename = os.path.join(data_directory, method_error) system = System(domain) system.add(Sech(peak_power=4.0, width=1.0)) system.add(Fibre("fibre", length=0.5 * np.pi, beta=[0.0, 0.0, -1.0, 0.0], gamma=1.0, method=method, local_error=target_error)) system.run() A_calc = system.fields['fibre'] storage = system["fibre"].stepper.storage np.savez(filename, field=A_calc, ffts=storage.fft_total)
def generate_map_and_waterfall_plots(domain): """ Generate map and waterfall plots to visualise pulse propagation. """ system = System(domain) system.add(Sech(peak_power=4.0, width=1.0)) system.add( Fibre( "fibre", length=0.5 * np.pi, beta=[0.0, 0.0, -1.0, 0.0], gamma=1.0, method="rk4ip", total_steps=1000, traces=50, ) ) system.run() storage = system["fibre"].stepper.storage (x, y, z) = storage.get_plot_data(reduced_range=(95.0, 105.0)) map_plot(x, y, z, labels["t"], labels["P_t"], labels["z"], filename="soliton_map") waterfall_plot(x, y, z, labels["t"], labels["z"], labels["P_t"], filename="soliton_waterfall", y_range=(0.0, 16.0))
def save_simulations(domain, data_directory, methods, steps): """ Save data for each method and step to file. """ for method in methods: print "%s" % method for step in steps: print "\t%d" % step method_step = "-".join([method, str(step)]) filename = os.path.join(data_directory, method_step) system = System(domain) system.add(Sech(peak_power=4.0, width=1.0)) system.add( Fibre("fibre", length=0.5 * np.pi, beta=[0.0, 0.0, -1.0, 0.0], gamma=1.0, method=method, total_steps=step)) system.run() A_calc = system.fields['fibre'] np.save(filename, A_calc)
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from pyofss import Domain, System, Gaussian, Fibre from pyofss import temporal_power, multi_plot, labels system = System(Domain(bit_width=200.0, samples_per_bit=2048)) system.add(Gaussian("gaussian", peak_power=1.0, width=1.0)) system.run() P_ts = [temporal_power(system.fields['gaussian'])] fibres = [ Fibre(length=5.0, beta=[0.0, 0.0, 0.0, 1.0], total_steps=100), Fibre(length=5.0, beta=[0.0, 0.0, 1.0, 1.0], total_steps=100) ] for fibre in fibres: system = System(Domain(bit_width=200.0, samples_per_bit=2048)) system.add(Gaussian(peak_power=1.0, width=1.0)) system.add(fibre) system.run() P_ts.append(temporal_power(system.fields['fibre'])) z_labels = [
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from pyofss import Domain, System, Gaussian, Fibre from pyofss import temporal_power, spectral_power, double_plot, labels system = System(Domain(bit_width=200.0, samples_per_bit=2048)) system.add(Gaussian(peak_power=1.0, width=1.0)) system.add(Fibre(length=5.0, beta=[0.0, 0.0, 0.0, 1.0], gamma=1.0, total_steps=100)) system.run() P_t = temporal_power(system.fields['fibre']) P_nu_normalised = spectral_power(system.fields['fibre'], True) double_plot(system.domain.t, P_t, system.domain.nu, P_nu_normalised, labels['t'], labels['P_t'], labels['nu'], labels['P_nu'], x_range=(95.0, 120.0), X_range=(192.6, 193.7), filename="4-15")
a high zoom level. """ from pyofss import Domain, System, Gaussian, Fibre from pyofss import temporal_power, multi_plot, labels domain = Domain(bit_width=200.0, samples_per_bit=2048) gaussian = Gaussian(peak_power=1.0, width=1.0) P_ts = [] methods = ['ss_simple', 'ss_symmetric', 'ss_sym_rk4', 'rk4ip'] for m in methods: sys = System(domain) sys.add(gaussian) sys.add( Fibre(length=5.0, method=m, total_steps=50, beta=[0.0, 0.0, 0.0, 1.0], gamma=1.0)) sys.run() P_ts.append(temporal_power(sys.field)) multi_plot(sys.domain.t, P_ts, methods, labels["t"], labels["P_t"], methods, x_range=(80.0, 140.0))
import time TS = 4096 GAMMA = 100.0 STEPS = 800 LENGTH = 0.1 DOMAIN = Domain(bit_width=30.0, samples_per_bit=TS) SYS = System(DOMAIN) SYS.add(Gaussian("gaussian", peak_power=1.0, width=1.0)) SYS.add(Fibre("fibre", beta=[0.0, 0.0, 0.0, 1.0], gamma=GAMMA, length=LENGTH, total_steps=STEPS, method="RK4IP")) start = time.clock() SYS.run() stop = time.clock() NO_OCL_DURATION = (stop - start) / 1000.0 NO_OCL_OUT = SYS.fields["fibre"] sys = System(DOMAIN) sys.add(Gaussian("gaussian", peak_power=1.0, width=1.0)) sys.add(OpenclFibre(TS, dorf="float", length=LENGTH, total_steps=STEPS)) start = time.clock() sys.run() stop = time.clock() OCL_DURATION = (stop - start) / 1000.0 OCL_OUT = sys.fields["ocl_fibre"] NO_OCL_POWER = temporal_power(NO_OCL_OUT)
return self.nonlinearity.exp_non(A, h, B) if __name__ == "__main__": """ Plot the result of a Gaussian pulse propagating through optical fibre. Simulates both (third-order) dispersion and nonlinearity. Use five different methods: ss_simple, ss_symmetric, ss_sym_rk4, ss_sym_rkf, and rk4ip. Expect all five methods to produce similar results; plot traces should all overlap. Separate traces should only be seen at a high zoom level. """ from pyofss import Domain, System, Gaussian, Fibre from pyofss import temporal_power, multi_plot, labels domain = Domain(bit_width=200.0, samples_per_bit=2048) gaussian = Gaussian(peak_power=1.0, width=1.0) P_ts = [] methods = ['ss_simple', 'ss_symmetric', 'ss_sym_rk4', 'rk4ip'] for m in methods: sys = System(domain) sys.add(gaussian) sys.add(Fibre(length=5.0, method=m, total_steps=50, beta=[0.0, 0.0, 0.0, 1.0], gamma=1.0)) sys.run() P_ts.append(temporal_power(sys.field)) multi_plot(sys.domain.t, P_ts, methods, labels["t"], labels["P_t"], methods, x_range=(80.0, 140.0))