Skip to main content

A robust Python library for Poiseuille and stabilized Cavity flow simulations.

Project description

CFD Solver Library ๐ŸŒŠ

PyPI - Version GitHub Workflow Status License

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:

  1. Clone the repository:
    git clone https://github.com/hardwork9047/cfd-solver.git
    cd cfd-solver
    
  2. Install dependencies with uv:
    uv sync
    
    This 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

๐Ÿš€ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cfd_solver-0.2.0.tar.gz (159.4 kB view details)

Uploaded Source

Built Distribution

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

cfd_solver-0.2.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

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

Hashes for cfd_solver-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c78b3c35ba66dce5dbec96ce6311d51766e9bfc28902d6a9a5778dbbc75053ed
MD5 8c678c1542c57a645671b3b1f649be5f
BLAKE2b-256 b22403e59d182171b196306e979669797cc39b4a48aed5402261a94a55a3d9f5

See more details on using hashes here.

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

Hashes for cfd_solver-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 065cf157dc48451163049ebca658b04f1f227a906675c2dd539acab440f15bb7
MD5 26305c3b2ed8ebbd589582910acd498e
BLAKE2b-256 35e8f110f19ce5032c1369a76de3fdce56cdf50b88a476241dbddfb6b7c72fc3

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