Note
Go to the end to download the full example code.
Field-grid scaling#
Measure the cost of evaluating three vector components on increasing grids.

from PyFiberModes.units import ureg
from time import perf_counter
import matplotlib.pyplot as plt
from PyFiberModes import HE11
from PyFiberModes.fiber import load_fiber
fiber = load_fiber("SMF28", wavelength=1550e-9 * ureg.meter)
sizes = (51, 101, 151, 201)
elapsed = []
for size in sizes:
field = fiber.get_mode_field(HE11, limit=12e-6 * ureg.meter, n_point=size)
start = perf_counter()
field.get_components(("Ex", "Ey", "Ez"))
elapsed.append(perf_counter() - start)
figure, axis = plt.subplots()
axis.plot(sizes, elapsed, marker="o")
axis.set(xlabel="Grid width [points]", ylabel="Elapsed time [s]", title="Field evaluation")
plt.show()
Total running time of the script: (0 minutes 0.564 seconds)