Skip to main content

A flexible and efficient solver for the 1D Nonlinear Schrödinger Equation

Project description

Simple Idealized 1D NLSE Solver

DOI Python License: WTFPL Code style: black Tests Coverage PyPI version Downloads Maintenance GitHub stars

A flexible and efficient solver for the 1D Nonlinear Schrödinger Equation (NLSE) using pseudo-spectral methods

Overview

This package provides a high-accuracy numerical framework for solving the 1D focusing NLSE:

$$i \frac{\partial \psi}{\partial t} + \frac{1}{2} \frac{\partial^2 \psi}{\partial x^2 } + |\psi|^2 \psi = 0,$$

where $\psi(x,t)$ is the complex wave function. This equation models various physical phenomena including Bose-Einstein condensates, nonlinear optics, and water waves.

Numerical Method

The solver employs a Fourier pseudo-spectral method combined with high-order time integration:

Spatial Discretization

Using the Fourier transform $\hat{\psi}(k,t) = \mathcal{F}[\psi(x,t)]$, the NLSE becomes:

$$\frac{\partial \hat{\psi}}{\partial t} = -\frac{i}{2}k^2\hat{\psi} + i\mathcal{F}[|\psi|^2\psi]$$

where spatial derivatives are computed spectrally:

  • $\mathcal{F}[\partial^2_x \psi] = -k^2 \hat{\psi}$
  • Wavenumbers: $k_j = 2\pi j/L$ for $j \in [-N/2, N/2)$

Anti-Aliasing Filter

To prevent aliasing from the nonlinear term, we apply an exponential filter (2/3 rule):

$$\sigma(k) = \exp\left[-36\left(\frac{|k|}{k_{max}}\right)^{36}\right], \quad k_{max} = \frac{2\pi N}{3L}$$

Time Integration

The filtered equation in Fourier space:

$$\frac{d\hat{\psi}_f}{dt} = -\frac{i}{2}k^2\hat{\psi}_f + i\sigma(k)\mathcal{F}[|\mathcal{F}^{-1}[\hat{\psi}_f]|^2 \mathcal{F}^{-1}[\hat{\psi}_f]]$$

is solved using the 8th-order Dormand-Prince method (DOP853) with adaptive time-stepping, achieving relative tolerances down to $10^{-9}$.

Conservation Laws

The solver monitors three conserved quantities to ensure numerical stability:

  1. Mass (L² norm): $M = \int_{-\infty}^{\infty} |\psi|^2 dx$

  2. Momentum: $P = \int_{-\infty}^{\infty} \text{Im}(\psi^* \partial_x \psi) dx$

  3. Energy (Hamiltonian): $E = \int_{-\infty}^{\infty} \left[\frac{1}{2}|\partial_x \psi|^2 - \frac{1}{2}|\psi|^4\right] dx$

Key Features

  • Spectral accuracy: Exponential convergence for smooth solutions
  • Adaptive time-stepping: Automatic step size control based on error estimates
  • JIT compilation: Optional Numba acceleration for performance-critical sections
  • Stability monitoring: Real-time tracking of conservation laws
  • Multiple initial conditions: Solitons, breathers, and modulation instability scenarios

Installation

From PyPI

pip install simple-idealized-1d-nlse

From source

git clone https://github.com/samuderasains/simple-idealized-1d-nlse.git
cd simple-idealized-1d-nlse
pip install -e .

Quick Start

# Run single scenario with YAML config
nlse-simulate single_soliton

# Run with TXT configuration file
nlse-simulate --config configs/txt/single_soliton.txt

# Run all predefined scenarios
nlse-simulate --all

# Run with verbose output
nlse-simulate single_soliton --verbose

Project Structure

simple_idealized_1d_nlse/
├── src/simple_idealized_1d_nlse/
│   ├── core/           # Core solver and numerical methods
│   ├── utils/          # Utility functions and helpers
│   ├── visualization/  # FiveThirtyEight-style plotting
│   └── io/            # Input/output handlers (YAML/TXT)
├── configs/           
│   ├── yaml/          # YAML configuration files
│   └── txt/           # TXT configuration files

../outputs/            # Simulation results (outside package)
../logs/              # Simulation logs (outside package)

Authors

  • Sandy H. S. Herho - sandy.herho@email.ucr.edu
  • Iwan P. Anwar
  • Faruq Khadami
  • Fikry P. Lugina
  • Rusmawan Suwarman
  • Dasapta E. Irawan

License

This project is licensed under the WTFPL License - see the LICENSE file for details.

Citation

If you use this software in your research, please cite:

@software{nlse_solver_2025,
  title = {Simple Idealized 1D NLSE Solver},
  author = {Herho, Sandy H. S. and Anwar, Iwan P. and Khadami, Faruq and 
            Lugina, Fikry P. and Suwarman, Rusmawan and Irawan, Dasapta E.},
  year = {2025},
  version = {0.0.1},
  institution = {Samudera Sains Teknologi Ltd.},
  url = {https://github.com/sandyherho/simple_idealized_1d_nlse}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_idealized_1d_nlse-0.0.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_idealized_1d_nlse-0.0.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file simple_idealized_1d_nlse-0.0.1.tar.gz.

File metadata

  • Download URL: simple_idealized_1d_nlse-0.0.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.2 Linux/6.11.9-100.fc39.x86_64

File hashes

Hashes for simple_idealized_1d_nlse-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3705bffca6075b4e1aa426a13fc6d70322b1f4112d04497e97869a9f3a13507b
MD5 cbebf45689c17e379636db770e13c4ba
BLAKE2b-256 743a5b9d8bf6bdd6076823af630eb02af3fe47e3103089d16fbc1e82c2710fef

See more details on using hashes here.

File details

Details for the file simple_idealized_1d_nlse-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_idealized_1d_nlse-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e318dd91d86c1e34d7a8652fa75f3563e9b36369c75fc6bbbfaff296f16b1042
MD5 df08f763bff011cafaa427df7501995e
BLAKE2b-256 24011445fc5f0b8250bbcf9ac1dbcb19c0396d7c2fe8098969c237c8d518a747

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page