amangkurat: Idealized (1+1)D nonlinear Klein-Gordon solver
Overview
Numerical solver for the $(1+1)$-dimensional nonlinear Klein-Gordon equation using symplectic pseudo-spectral methods. Features adaptive timestepping, Numba acceleration, and scientific data output.
Key Features:
- Pseudo-spectral Fourier discretization (exponential convergence)
- Størmer-Verlet symplectic integration (structure-preserving)
- Adaptive CFL-based timestepping
- Parallel execution with Numba
- NetCDF4 data output + 3D animations
Mathematical Foundation
Klein-Gordon Equation
$$(1+1)$-dimensional relativistic field equation in natural units ($c = \hbar = 1$):
$$\frac{\partial^2 \phi}{\partial t^2} - \frac{\partial^2 \phi}{\partial x^2} + V'(\phi) = 0$$
Supported Potentials
| Potential | $V(\phi)$ | $V'(\phi)$ | Physics |
|---|---|---|---|
| Linear | $\frac{1}{2}m^2\phi^2$ | $m^2\phi$ | Free massive scalar field |
| $\phi^4$ | $\frac{\lambda}{4}(\phi^2 - v^2)^2$ | $\lambda\phi(\phi^2 - v^2)$ | Topological kinks, domain walls |
| Sine-Gordon | $1 - \cos(\phi)$ | $\sin(\phi)$ | Breathers, Josephson junctions |
Numerical Method
Spatial: Pseudo-spectral Fourier with wavenumbers $k_n = 2\pi n/L$
Temporal: Størmer-Verlet (symplectic leapfrog) $$\phi^{n+1} = 2\phi^n - \phi^{n-1} + \Delta t^2 \left[\nabla^2\phi^n - V'(\phi^n)\right]$$
Stability: CFL condition $\Delta t \leq 0.5/k_{\max}$ enforced via adaptive timestepping
Installation
From Source
git clone https://github.com/sandyherho/amangkurat.git
cd amangkurat
pip install -e .
From PyPI
pip install amangkurat
Dependencies: numpy, scipy, matplotlib, netCDF4, tqdm, numba (optional, recommended for 10-100× speedup)
Quick Start
Command Line
amangkurat case1 # Linear wave
amangkurat case2 # Kink soliton
amangkurat case3 # Breather
amangkurat case4 # Kink-antikink collision
# Options
amangkurat case1 --cores 8 --output-dir results/ --quiet
amangkurat --all # Run all cases
Python API
from amangkurat import KGSolver
from amangkurat.core.initial_conditions import KinkIC
# Initialize solver
solver = KGSolver(nx=512, x_min=-30.0, x_max=30.0, adaptive_dt=True, n_cores=4)
# Create initial condition
ic = KinkIC(vacuum=1.0, position=0.0, velocity=0.0)
phi0, phi_dot0 = ic(solver.x)
# Solve
result = solver.solve(
phi0=phi0, phi_dot0=phi_dot0,
dt=0.005, t_final=50.0,
potential='phi4', lambda_=1.0, vacuum=1.0,
n_snapshots=200
)
# Access results
x = result['x'] # Spatial grid
t = result['t'] # Time snapshots
phi = result['phi'] # Field evolution (nt × nx)
Test Cases
| Case | Potential | Initial Condition | Description |
|---|---|---|---|
| 1 | Linear | Gaussian pulse | Dispersive wave propagation |
| 2 | $\phi^4$ | Static kink | Topological soliton ($\phi = v\tanh(x/\xi)$) |
| 3 | Sine-Gordon | Breather | Time-periodic localized oscillation |
| 4 | $\phi^4$ | Kink-antikink pair | Collision dynamics ($v = 0.3c$) |
Configuration
Simple key-value format (configs/case*.txt):
scenario_name = Kink Soliton
nx = 1024
x_min = -50.0
x_max = 50.0
t_final = 50.0
dt = 0.005
adaptive_dt = true
potential = phi4
lambda = 1.0
vacuum = 1.0
ic_type = kink
position = 0.0
velocity = 0.0
n_cores = 0
save_netcdf = true
save_animation = true
n_frames = 200
fps = 30
colormap = inferno
Output Files
NetCDF4 data (outputs/*.nc):
- Variables:
x(nx),t(nt),phi(nt, nx) - Metadata: grid parameters, potential type, timestep info
Animated GIFs (outputs/*.gif):
- 3D visualization of $\phi(x,t)$ evolution
- Dynamic camera rotation, color-coded amplitude
Log files (logs/*.log):
- Detailed diagnostics, parameter listings, timing
Physical Units
Code uses dimensionless units. Map to physical systems via scale factors:
$\phi^4$ Kinks
Natural scales: Length $\xi = \sqrt{2}/v$, Time $T = \xi/c$, Energy $E_0 = \frac{2\sqrt{2}}{3}\lambda v^3$
| Context | Length Scale | Time Scale | Application |
|---|---|---|---|
| Particle physics | $\xi \sim 10^{-18}$ m | $T \sim 10^{-26}$ s | Higgs field (theoretical) |
| Condensed matter | $\xi \sim 10$ nm | $T \sim 1$ ps | Ferromagnetic domain walls |
| Josephson junctions | $\lambda_J \sim 1$ μm | $T \sim 10$ ps | Superconducting phase |
Conversion:
units = result['units']
x_physical = result['x'] * length_scale_physical / units.length_scale
Directory Structure
amangkurat/
├── configs/ # Test configurations
├── src/amangkurat/
│ ├── core/ # Solver + initial conditions
│ ├── io/ # NetCDF + config parser
│ ├── visualization/ # 3D animations
│ └── utils/ # Logger + timer
├── outputs/ # Results (*.nc, *.gif)
├── logs/ # Simulation logs
└── pyproject.toml # Build config
Limitations
- 1D spatial domain only ($(1+1)$D spacetime)
- Periodic boundary conditions (not suitable for scattering)
- Uniform grid (no adaptive mesh refinement)
- CFL-limited timestep (explicit integration)
- Requires smooth solutions (spectral methods)
Citation
@software{herho2025_amangkurat,
author = {Herho, Sandy H. S.},
title = {amangkurat: Idealized Nonlinear Klein-Gordon Solver},
year = {2025},
version = {0.0.1},
url = {https://github.com/sandyherho/amangkurat}
}
Metadata
Release files for amangkurat 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| amangkurat-0.0.1.tar.gz | 19.0 kB | Without provenance | Details for amangkurat-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| amangkurat-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for amangkurat-0.0.1-py3-none-any.whl |
Total release size: 39.9 kB
Release files / amangkurat-0.0.1.tar.gz
| Download URL | amangkurat-0.0.1.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
800de890aea27c41901ef98bfff5cd7d7c5359adb59dff50a609a984ddb1cebe
|
|
BLAKE2b-256 checksum How to use checksums |
96ced9a2e035d4a45bb8509a6b9349e0a64c843488d9f55d09fb9c1c06e6f7d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.2 Linux/6.11.9-100.fc39.x86_64
|
Release files / amangkurat-0.0.1-py3-none-any.whl
| Download URL | amangkurat-0.0.1-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17bc4d634cc0103db0da917659ae50e3c832bbb3fd54e618339bae123013b7c3
|
|
BLAKE2b-256 checksum How to use checksums |
a20651945259b2b8cc58ba978aef60dbda8513bf87a824704ae30b036f81a040
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.2 Linux/6.11.9-100.fc39.x86_64
|
Security for amangkurat 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.