Skip to main content

A simplified 2D flood diffusion model with GPU acceleration

Project description

MiniFlood

GPU 加速的简化二维洪水扩散模拟引擎。


构建与安装

前置条件

  • CMake >= 3.18
  • CUDA Toolkit(如需 GPU 加速)
  • Python >= 3.10
  • C++ 编译器(MSVC / GCC / Clang)

安装方式

# 方式一:从源码安装(推荐)
pip install . -v

# 方式二:构建 wheel 再安装
pip install build
python -m build
pip install dist/miniflood-*.whl

# 方式三:可编辑安装(开发模式)
pip install -e . -v

Windows + CUDA 用户须知

如果安装了多个 Visual Studio 版本(如 VS 2022 + VS 2026),CMake 默认选最新版本, 但 nvcc 可能不兼容最新 VS。请指定 VS 2022

# 在构建前设置环境变量
$env:CMAKE_GENERATOR = "Visual Studio 17 2022"
pip install . -v --force-reinstall --no-deps

手动 CMake 构建(传统方式,仅用于调试)

pip install pybind11
mkdir build
cd build
cmake .. -DPython3_EXECUTABLE=python              # Windows / Linux / macOS 通用
cmake --build . --config Release

使用示例

from miniflood import flood

# 运行案例
status = flood.run("miniflood/examples/case01")
if status == 0:
    print("✅ 模拟成功!")
else:
    print(f"❌ 模拟失败,返回码: {status}")

案例配置 (case01/config.json):

{
  "num_steps": 200,
  "dt": 1.0,
  "output_interval": 50
}

模拟结果将输出到 case01/output/ 目录,为 ASC 格式的水深栅格文件。


项目结构

MiniFlood/
├── pyproject.toml              # 现代构建配置(scikit-build-core)
├── CMakeLists.txt              # 顶层 CMake
├── miniflood/
│   ├── __init__.py
│   ├── version.py
│   ├── lib/flood/              # CUDA 核心 + pybind11 绑定
│   │   ├── flood_solver.cu     # CUDA 扩散求解器
│   │   ├── flood_solver.h
│   │   └── bindings/binding.cpp
│   ├── examples/               # 示例数据
│   ├── tests/                  # 单元测试
│   └── IO/                     # IO 工具
├── third_party/nlohmann_json/  # JSON 解析头文件库
└── python/run.py               # 示例启动脚本

打包发布

# 1. 构建 wheel + sdist(会自动检测 CUDA)
pip install build
python -m build

# 2. 上传到 PyPI
pip install twine
twine upload dist/*

跨平台说明

  • sdist(源码包)dist/miniflood-*.tar.gz 是跨平台的,Linux/macOS/Windows 均可 pip install 从源码编译
  • wheel(二进制包)dist/miniflood-*-win_amd64.whl 绑定当前平台,需在各目标平台分别构建
  • 在 Linux 上构建:克隆仓库 → 安装 CUDA Toolkit → pip install .

CUDA 检测

构建时自动检测 CUDA,优先级:

  1. 环境变量 CUDAToolkit_ROOT(如 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4
  2. CMake find_package(CUDAToolkit) 自动搜索标准路径
  3. 未检测到则编译 CPU stub(运行时有明确提示)

技术栈

层面 技术
计算核心 CUDA C++
Python 绑定 pybind11
配置解析 nlohmann/json
构建系统 CMake + scikit-build-core
打包规范 PEP 517 / PEP 621

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

miniflood-2.1.0.tar.gz (299.9 kB view details)

Uploaded Source

Built Distribution

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

miniflood-2.1.0-cp313-cp313-win_amd64.whl (174.6 kB view details)

Uploaded CPython 3.13Windows x86-64

File details

Details for the file miniflood-2.1.0.tar.gz.

File metadata

  • Download URL: miniflood-2.1.0.tar.gz
  • Upload date:
  • Size: 299.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for miniflood-2.1.0.tar.gz
Algorithm Hash digest
SHA256 a6c736fbffba5b7746a5d889d0ca7b69e6c0d7930d8d606b8d1df39367c7d3a1
MD5 4ff009b3ee260a19c635e4a6c648ba2e
BLAKE2b-256 d7376d96a0d1d7c77bc00ac28cd4fb53fcf6cab1efff481ec8374d2c4ff729c7

See more details on using hashes here.

File details

Details for the file miniflood-2.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: miniflood-2.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 174.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for miniflood-2.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 082b9a902a50ab2d98ab0019aa82a4059f0bf45bfe2aec4b972a0b0a83d89107
MD5 cc2387800b230a24c0b39bf759115088
BLAKE2b-256 816479a2e8b85e78971371ea484f33c6c4c20711f64111c97da4e3503efd817b

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