Skip to content

maddiepr/1d-pde-simulation-sandbox

Repository files navigation

Monte Carlo Simulation of 1D Advection-Diffusion Equations

This repository contains Python code for simulating 1D advection-diffusion equations with divergence-dependent velocity fields using Monte Carlo methods. It serves as an exploratory sandbox for

  • Testing numerical strategies
  • Analyzing stochastic behavior of particle systems
  • Comparing simulation output to analytical solutions
  • Laying the groundwork for higher-dimensional implementations

🔍 Project Overview

The simulation solves PDEs of the form:

∂T/∂t = ∂/∂x (D(x) ∂T/∂x) − ∂/∂x (u(x) T)

where:

  • D(x) is a spatially dependent diffusion coefficient
  • u(x) is a divergence-dependent drift field

Particles undergo stochastic motion with path weights governed by the PDE. The final density is estimated via weighted histograms and compared with known exact solutions where possible.


🗂 Project Structure

1d-pde-simulation-sandbox/
├── data/                       # Output particle data and weights
│  ├── reaction/
│  │  ├── T1.0_D1.0_alpha1.0_x0_0.0/
│  │  │  ├── positions.npy
│  │  │  └── weights.npy
│  │  └── ...
│  ├── advection/
│  │  ├── T1.0_D1.0_alpha1.0_x0_0.0/ 
│  │  │  ├── positions.npy
│  │  │  └── weights.npy
│  │  └── ...
├── docs/                       # Documentation, example plots, and reference figures
│  ├── reaction/
│  │  ├── T1.0_D1.0_alpha1.0_x0_0.0.png
│  │  └── ...
│  ├── advection/
│  │  ├── T1.0_D1.0_alpha1.0_x0_0.0.png
│  │  └── ...
├── notebooks/                  # Notebooks for visualization and exploration
│  ├── visualize_reaction.ipynb
│  └── visualize_advection.ipynb
├── src/
│  ├── __init__.py
│  ├── advection.py             # Advection term logic
│  ├── diffusion.py             # Shared core diffusion logic
│  ├── exact_solutions.py       # Compute exact solutions for both linear advection and reaction equations
│  ├── parameters.py            # Defines parameters for simulation
│  ├── plotting.py              # Histogram, comparison plots, etc. 
│  ├── reaction.py              # Reaction term logic 
│  └── utils.py                 # Loading, saving, data wrangling
├── run_batch_reaction.py       # Script to run reaction-diffusion simulation
├── run_batch_advection.py     # Script to run the advection-diffusion simulation
├── requirements.txt
├── .gitignore
├── README.md
└── tests/                  # Unit and validation tests
│  ├── test_diffusion.py
│  ├── test_parameters.py
│  ├── test_reaction.py
│  ├── test_run_batch_advection.py
│  └── test_run_batch_reaction.py


🛠 Getting Started

1. Clone the Repository

git clone https://github.com/maddiepr/monte-carlo-1d.git
cd monte-carlo-1d

2. Install Dependencies

python -m venv env
source env/bin/activate # or env\Scripts\activate on Windows
pip install -r requirements.txt

3. Run a Simulation

python run_reaction.py
python run_advection.py

You can adjust parameters in Parameters.py


🚧 Project Status

This is an early-stage, research-driven codebase. While core logic is functional and documented, structure and performance optimizations are ongoing. Furture versions may modularize the code further and add 2D support (see related repo:monte-carlo-2d-mapping).

📎 License / Use

⚠️ This repository is provided for demonstration and reference only. Please do not reuse or distribute code without written permission.

Author

Madeline "Maddie" Preston www.linkedin.com/in/madeline-preston | https://github.com/maddiepr

About

Research sandbox for testing MC solutions 1D divergence-dependent PDEs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors