Skip to content

nsreelekha/poisson_equation

Repository files navigation

🌀 Meshfree 2D Poisson Equation Solvers (Dirichlet, Neumann, Mixed) — CuPy + Jupyter

This project provides GPU-accelerated solutions to the 2D Poisson equation using the Finite Pointset Method (FPM) — a meshfree Lagrangian method well-suited for complex geometries and evolving domains.

Implemented in Python using Jupyter notebooks, and accelerated with CuPy for NVIDIA GPUs (CUDA 12.x), the solvers cover:

  • 🔴 dirichlet.ipynb — Dirichlet boundary conditions on all sides
  • 🔵 neumann.ipynb — Neumann boundary conditions on all sides
  • 🟡 mixed.ipynb — Mixed Dirichlet and Neumann conditions

🧠 Method Overview

The solution domain is discretized using a meshfree point cloud, and the Laplacian operator in the Poisson equation is approximated via a second-order Taylor expansion fitted with Gaussian-weighted least squares over local neighbors.

Key components:

  • Discretization: Irregular point cloud on a unit square domain
  • Laplacian Approximation: Based on Taylor expansion + weighted least squares
  • Weight Function: Gaussian kernel with compact support
  • Boundary Conditions: Imposed directly by adjusting the local minimization system
  • Solver: Dense GPU-based system solve using cp.linalg.solve()
  • Output: Visualized as 2D heatmaps or 3D surfaces using matplotlib

This approach leverages CuPy's GPU parallelism to significantly reduce solve time compared to CPU-based methods like NumPy or SciPy.


📁 Project Structure

poisson_equation/ ├── dirichlet.ipynb # Poisson solver with Dirichlet BCs ├── neumann.ipynb # Poisson solver with Neumann BCs ├── mixed.ipynb # Poisson solver with Mixed BCs ├── environment.yml # Conda environment (includes CuPy) ├── requirements.txt # pip alternative for non-conda users └── README.md # This file


⚙️ Setup Instructions

⚠️ Requires Anaconda and a CUDA-enabled GPU (with CUDA 12.x drivers).

🧱 Step 1: Clone the repository

git clone https://github.com/nsreelekha/poisson_equation.git
cd poisson_equation

🧪 Step 2A: Create and activate the Conda environment

conda env create -f environment.yml
conda activate cupy129env

🧪 Step 2B: (Alternative) Use pip + virtualenv

python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

pip install -r requirements.txt

🚀 Running the Code

You can run the notebooks using Jupyter.

▶️ Step 3: Launch Jupyter Notebook

jupyter notebook

Then open any of the following:

  • 📘 dirichlet.ipynb — fixed boundary values

  • 📘 neumann.ipynb — derivative (flux) conditions

  • 📘 mixed.ipynb — combination of Dirichlet and Neumann BCs

Each notebook will:

  • ✅ Assemble a grid

  • ✅ Set up boundary conditions

  • ✅ Solve the 2D Poisson equation on the GPU using CuPy

  • ✅ Visualize the solution using Matplotlib

📦 Dependencies

All dependencies are managed via Conda or requirements.txt

Key packages include:

  • cupy-cuda12x — GPU array library (NumPy-compatible)
  • numpy, scipy, matplotlib
  • pycuda (optional)
  • Python 3.11

These are installed automatically when you run:

conda env create -f environment.yml

🛠️ Troubleshooting

  • No GPU? Replace all import cupy as cp with import numpy as cp in the notebooks to run on CPU (slower).

  • Environment errors? Re-create the environment:

conda env remove -n cupy129env
conda env create -f environment.yml
  • Kernel crashes or CuPy import errors? Make sure your system has a working CUDA 12.x installation that matches the cupy-cuda12x package.

📜 License

MIT License

👤 Author

Sreelekha Nampally
🎓 B.Tech in Mathematics and Computing, NIT Mizoram
🛠️ Project developed as part of Summer Internship at IIT Tirupati
🌐 LinkedIn | GitHub

About

GPU-accelerated 2D Poisson equation solvers using Finite Pointset Method (CuPy, Python)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published