Note
Go to the end to download the full example code.
A Gaussian beam in a Kerr medium¶
The 2D solver on its own: a beam propagating through a saturable, lossy nonlinear medium.

/home/runner/work/NLSE/NLSE/NLSE/solvers/nlse.py:182: UserWarning: The CUPY backend is not installed here, so CPU will be used instead — the fastest one available. Install cupy to use CUPY, or pass backend='CPU' to silence this.
self._backend: Backend = get_backend(backend, grid_size=(NX, NY))
/home/runner/work/NLSE/NLSE/NLSE/solvers/nlse.py:380: UserWarning: delta_z=2.12e-04 exceeds split-step accuracy limit (1.55e-05). Reducing to 1.39e-05.
delta_z = self._capped_delta_z(delta_z, A, method)
Propagation: 0%| | 0.00/100 [00:00<?, ?%/s]
Propagation: 100%|██████████| 100/100 [00:41<00:00, 2.40%/s]
Time spent to solve : 41.58780547900005 s (CPU)
import numpy as np
from NLSE import NLSE
PRECISION_COMPLEX = np.complex64
PRECISION_REAL = np.float32
N = 2048
n2 = -1.6e-9
waist = 2.23e-3
window = 4 * waist
puiss = 1.05
Isat = 10e4 # saturation intensity in W/m^2
L = 10e-3
alpha = 20
def main():
simu = NLSE(
alpha,
puiss,
window,
n2,
None,
L,
NX=N,
NY=N,
Isat=Isat,
backend="CUPY",
)
E_0 = np.exp(-(simu.XX**2 + simu.YY**2) / waist**2).astype(PRECISION_COMPLEX)
simu.out_field(E_0, L, verbose=True, plot=True, splitting="lie")
if __name__ == "__main__":
main()
Total running time of the script: (0 minutes 43.407 seconds)