Skip to main content

Iterative PDE solvers for 2D elliptic equations with finite differences

Project description

iterpdesolver

Iterative PDE solvers for 2D elliptic equations with finite differences.

A Python library implementing 11 solver algorithms for second-order elliptic PDEs on uniform rectangular grids, including classical iterative methods, Krylov solvers, and multigrid methods.

Originally based on a Bachelor thesis on iterative methods for the discrete Poisson equation (University of Regensburg), now extended to support multiple equation types.

Installation

pip install iterpdesolver

Or install from source:

git clone https://github.com/michaelwallner/iterpdesolver.git
cd iterpdesolver
pip install -e ".[dev]"

Quick Start

import iterpdesolver as pde

result = pde.solve(
    equation=pde.Poisson(source=lambda x, y: -4.0),
    grid=pde.UniformGrid(nx=63, ny=63),
    boundary=pde.DirichletBC(lambda x, y: x**2 + y**2),
    solver="cg",
    tol=1e-6,
)

print(f"Converged in {result.iterations} iterations ({result.time_seconds:.3f}s)")
print(f"Residual: {result.residual_norm:.2e}")

Supported Equations

Equation Class PDE
Poisson pde.Poisson(source) $-\nabla^2 u = f$
Helmholtz pde.Helmholtz(source, k) $-\nabla^2 u + k^2 u = f$
Convection-Diffusion pde.ConvectionDiffusion(source, diffusion, velocity) $-D\nabla^2 u + \mathbf{v} \cdot \nabla u = f$
Heat (implicit Euler) pde.Heat(source, alpha, dt, u_prev) $u^{n+1}/\Delta t - \alpha \nabla^2 u^{n+1} = u^n/\Delta t + f$

Available Solvers

Solver Key Type
Direct (LU) "direct" Direct
Jacobi "jacobi" Iterative
Jacobi Relaxation "jacobi_relaxation" Iterative
Gauss-Seidel "gauss_seidel" Iterative
SOR "sor" Iterative
Conjugate Gradient "cg" Krylov
PCG (ILU) "pcg_ilu" Krylov
PCG (MILU) "pcg_milu" Krylov
Two-Grid "two_grid" Multigrid
V-Cycle "v_cycle" Multigrid
W-Cycle "w_cycle" Multigrid

SolveResult

Every solver returns a SolveResult with:

  • solution — 1D numpy array of interior point values
  • iterations — number of iterations (0 for direct solver)
  • time_seconds — wall-clock solve time
  • residual_norm — final residual norm
  • converged — whether tolerance was met
  • residual_history — list of residual norms per iteration
  • plot(grid=...) — quick matplotlib surface plot

Examples

python examples/basic_poisson.py
python examples/solver_comparison.py
python examples/helmholtz_example.py

Streamlit App

pip install iterpdesolver[app]
streamlit run examples/streamlit_app/app.py

Testing

pip install -e ".[dev]"
pytest tests/ -v

License

MIT

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

iterpdesolver-0.1.0.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

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

iterpdesolver-0.1.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file iterpdesolver-0.1.0.tar.gz.

File metadata

  • Download URL: iterpdesolver-0.1.0.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for iterpdesolver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3e0ed86d776104d0602d2bc53d80e4ecc59ec8607ecb1206a8feb0ba888d174
MD5 1cbff9b5522d6f44989ef5da7e070fc5
BLAKE2b-256 fa401de11566284be68243b875a152b6d5bcc5f647d7d7a0f468807951d83ce9

See more details on using hashes here.

File details

Details for the file iterpdesolver-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iterpdesolver-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for iterpdesolver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05d764b04c9187c4b9ddac5e4efcef17787dc761f746e8128301189ce1d3e166
MD5 fe1fcb0cfb50433ba9cccbceaaba2abd
BLAKE2b-256 73a50e3b97ba26a5174a4d3885eb6a52ba3b4cadafbdb3168e9d998498f12ab5

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