A robust Python library for Poiseuille and stabilized Cavity flow simulations.
Project description
CFD Solver Library ๐
A specialized Python library for calculating fundamental flows in Computational Fluid Dynamics (CFD). Designed to be easy to learn while remaining numerically robust and suitable for educational and research purposes.
๐ฏ Key Features
| Feature | Description |
|---|---|
| Educational | Clear implementations of FDM, SOR, and Upwind schemes |
| Robust | Comprehensive logging and error handling for numerical stability |
| Non-Newtonian | Support for Power-Law fluids (shear-thinning/thickening) |
| Visual | Built-in plotting and easy animation workflows |
| Verified | All solvers verified against analytical solutions |
๐ง Capabilities
1. Newtonian Poiseuille Flow
Classic pressure-driven laminar flows:
- Plane Poiseuille: Flow between parallel plates
- Circular Poiseuille: Flow in circular pipes
- Features: SOR solver, analytical verification, convergence tracking
2. Non-Newtonian Flow โจ
Power-Law model for variable viscosity fluids:
- Shear-thinning ($n < 1$): blood, paint
- Newtonian ($n = 1$): water
- Shear-thickening ($n > 1$): cornstarch suspension
- Features: Non-linear iterative solver with robust stability controls
3. Lid-Driven Cavity Flow
Benchmark 2D Navier-Stokes solver:
- Physics: Incompressible, viscous flow in square cavity
- Stability: Upwind differencing, dynamic time-stepping, numerical clipping
- Outputs: Velocity field, pressure distribution, vorticity analysis
- Animation: Frame generation for video creation
๐ Installation
Stable Release (Recommended for Users)
You can install cfd-solver directly from PyPI using pip:
pip install cfd-solver
Development Version (For Contributors)
If you wish to contribute to the project or use the latest development features, you can install it from source. We recommend using uv for dependency management during development:
- Clone the repository:
git clone https://github.com/hardwork9047/cfd-solver.git cd cfd-solver
- Install dependencies with
uv:uv syncThis will install all necessary development and runtime dependencies.
Quick Start Example
Here's a quick way to get started with a simple Plane Poiseuille flow simulation:
import matplotlib.pyplot as plt
from cfd import PlanePoiseuille
# Initialize the solver for a plane Poiseuille flow
# (distance between plates, pressure gradient, viscosity)
flow = PlanePoiseuille(L=0.01, dp_dx=-100, mu=1e-3, ny=51)
# Get analytical solution
u_analytical = flow.analytical_solution()
# Get numerical solution
u_numerical = flow.numerical_solution()
# Plot the velocity profile
plt.figure(figsize=(8, 5))
plt.plot(u_analytical, flow.y, label='Analytical Solution')
plt.plot(u_numerical, flow.y, 'o', markersize=4, fillstyle='none', label='Numerical Solution')
plt.xlabel('Velocity (m/s)')
plt.ylabel('Position (m)')
plt.title('Plane Poiseuille Flow')
plt.legend()
plt.grid(True)
plt.show()
๏ฟฝ Numerical Methods
To ensure robust and accurate simulations, this library implements:
- FDM (Finite Difference Method): 2nd-order central difference for diffusion
- Upwind Scheme: 1st-order upwind for stable advection
- SOR (Successive Over-Relaxation): Accelerated iterative solver
- Dynamic Time-Stepping: Automatic adjustment based on CFL and viscous stability limits
๐ Project Structure
cfd/
โโโ src/cfd/
โ โโโ poiseuille.py # SOR-based Newtonian solvers
โ โโโ cavity.py # Stabilized Navier-Stokes solver
โ โโโ non_newtonian.py # Power-Law fluid solvers
โโโ examples/
โ โโโ verify_*.py # Rigorous verification scripts
โ โโโ demo_*.py # Feature demonstrations
โ โโโ make_animation_frames.py # Animation frame generator
โโโ docs/
โ โโโ VERIFICATION_REPORT.md # Test results and performance
โ โโโ VIDEO_TUTORIAL.md # Animation creation guide
โโโ TUTORIAL.md # Step-by-step learning path
๐ Documentation
- TUTORIAL.md: Step-by-step learning path for beginners
- docs/VERIFICATION_REPORT.md: Detailed verification results and performance metrics
- docs/VIDEO_TUTORIAL.md: Guide to creating animations with FFmpeg
๐ Quick Demo
Want to see something cool right now? Try running the Lid-Driven Cavity demo:
uv run python examples/demo.py
Or see how a shear-thinning fluid flows:
uv run python examples/demo_shear_thinning.py
๐ Engineering Standards
This library follows high standards for your safety and success:
- Python 3.11+
- Robust Error Handling (No more silent NaNs!)
- Comprehensive Logging
- Strict Analytical Verification
- Test Coverage: 15+ tests, all passing โ
๐ค Contributing
We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to get started.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Created with care to help you master the world of fluids. ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfd_solver-0.2.0.tar.gz.
File metadata
- Download URL: cfd_solver-0.2.0.tar.gz
- Upload date:
- Size: 159.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.1 CPython/3.11.10 Linux/6.8.0-100-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c78b3c35ba66dce5dbec96ce6311d51766e9bfc28902d6a9a5778dbbc75053ed
|
|
| MD5 |
8c678c1542c57a645671b3b1f649be5f
|
|
| BLAKE2b-256 |
b22403e59d182171b196306e979669797cc39b4a48aed5402261a94a55a3d9f5
|
File details
Details for the file cfd_solver-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cfd_solver-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.1 CPython/3.11.10 Linux/6.8.0-100-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
065cf157dc48451163049ebca658b04f1f227a906675c2dd539acab440f15bb7
|
|
| MD5 |
26305c3b2ed8ebbd589582910acd498e
|
|
| BLAKE2b-256 |
35e8f110f19ce5032c1369a76de3fdce56cdf50b88a476241dbddfb6b7c72fc3
|