重构: 采用模块化 src 布局
- 重组代码为模块化结构:lbm/, common/, cuda/ - LBM 相关代码移至 src/CelerisLab/lbm/ - 通用工具移至 src/CelerisLab/common/ - CUDA 编译器移至 src/CelerisLab/cuda/ - 更新所有导入路径以适配新结构 - 提供灵活的导入接口(直接导入/模块导入/命名空间风格) - 为未来扩展(FEM, SPH, MPM 等)做好准备
This commit is contained in:
parent
1137e9a247
commit
d3b32c8be3
@ -35,9 +35,6 @@ dependencies = [
|
||||
Homepage = "https://github.com/frank14f/CelerisLab"
|
||||
Repository = "https://github.com/frank14f/CelerisLab.git"
|
||||
|
||||
[project.scripts]
|
||||
celerislab = "CelerisLab.driver:main"
|
||||
|
||||
[tool.setuptools]
|
||||
package-dir = {"" = "src"}
|
||||
|
||||
@ -45,4 +42,4 @@ package-dir = {"" = "src"}
|
||||
where = ["src"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
CelerisLab = ["kernels/*.cu", "kernels/*.h", "configs/*.json"]
|
||||
"CelerisLab.lbm" = ["kernels/*.cu", "kernels/*.h", "configs/*.json"]
|
||||
|
||||
7
setup.py
7
setup.py
@ -14,7 +14,7 @@ setup(
|
||||
packages=find_packages(where='src'),
|
||||
package_dir={'': 'src'},
|
||||
package_data={
|
||||
'CelerisLab': [
|
||||
'CelerisLab.lbm': [
|
||||
'kernels/*.cu',
|
||||
'kernels/*.h',
|
||||
'configs/*.json',
|
||||
@ -37,9 +37,4 @@ setup(
|
||||
'Programming Language :: Python :: 3.10',
|
||||
'Programming Language :: Python :: 3.11',
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'celerislab=CelerisLab.driver:main',
|
||||
],
|
||||
},
|
||||
)
|
||||
@ -1,24 +1,44 @@
|
||||
# CelerisLab/__init__.py
|
||||
"""
|
||||
CelerisLab: GPU-Accelerated Lattice Boltzmann Method CFD Solver
|
||||
CelerisLab: GPU-Accelerated Computational Physics Simulation Library
|
||||
|
||||
A modular framework for GPU-accelerated physics simulations including:
|
||||
- Lattice Boltzmann Method (LBM) for fluid dynamics
|
||||
- Future: Finite Element Method (FEM), Smoothed Particle Hydrodynamics (SPH), etc.
|
||||
|
||||
Usage:
|
||||
# Direct import of main classes
|
||||
from CelerisLab import FlowField
|
||||
|
||||
# Module-specific imports
|
||||
from CelerisLab.lbm import FlowField
|
||||
|
||||
# Namespace style
|
||||
import CelerisLab as cl
|
||||
solver = cl.lbm.FlowField(...)
|
||||
"""
|
||||
|
||||
__version__ = '0.2.0'
|
||||
|
||||
# Always import utils (no pycuda dependency)
|
||||
from . import utils
|
||||
# Import submodules
|
||||
from . import common
|
||||
from . import cuda
|
||||
from . import lbm
|
||||
|
||||
# Try to import FlowField (requires pycuda)
|
||||
# Import commonly used utilities for convenience
|
||||
from .common import utils
|
||||
|
||||
# Attempt to import main classes for direct access
|
||||
try:
|
||||
from .driver import FlowField
|
||||
__all__ = ['FlowField', 'utils']
|
||||
from .lbm import FlowField
|
||||
__all__ = ['lbm', 'common', 'cuda', 'utils', 'FlowField', '__version__']
|
||||
except ImportError as e:
|
||||
# PyCUDA not available, only utils module will be accessible
|
||||
# PyCUDA not available, only submodules accessible
|
||||
import warnings
|
||||
warnings.warn(
|
||||
f"FlowField not available: {e}. "
|
||||
"Install pycuda to use the full CelerisLab functionality. "
|
||||
"Utils module is still accessible for configuration management.",
|
||||
"Utils and other modules are still accessible.",
|
||||
ImportWarning
|
||||
)
|
||||
__all__ = ['utils']
|
||||
__all__ = ['lbm', 'common', 'cuda', 'utils', '__version__']
|
||||
|
||||
9
src/CelerisLab/common/__init__.py
Normal file
9
src/CelerisLab/common/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
# CelerisLab/common/__init__.py
|
||||
"""
|
||||
Common utilities and preprocessing functions.
|
||||
"""
|
||||
|
||||
from . import utils
|
||||
from . import preprocess
|
||||
|
||||
__all__ = ['utils', 'preprocess']
|
||||
@ -125,8 +125,9 @@ def find_config_file(config_filename: str, config_path: Optional[str] = None) ->
|
||||
search_paths.append(os.path.join(os.getcwd(), 'configs', config_filename))
|
||||
|
||||
# Priority 4: Package installation location (relative to this utils.py)
|
||||
package_root = os.path.dirname(os.path.abspath(__file__))
|
||||
search_paths.append(os.path.join(package_root, 'configs', config_filename))
|
||||
# configs are in lbm/configs/
|
||||
package_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
search_paths.append(os.path.join(package_root, 'lbm', 'configs', config_filename))
|
||||
|
||||
# Search for the file
|
||||
for path in search_paths:
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"multi_gpu": false,
|
||||
"gpu_connection": "NVLink",
|
||||
"required_cuda_capability": "7.0",
|
||||
"threads_per_block": 128,
|
||||
"X_1U": 128,
|
||||
"Y_1U": 32,
|
||||
"Z_1U": 1
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
{
|
||||
"data_type": "FP32",
|
||||
"dimensionality": 2,
|
||||
"lattice": 9,
|
||||
"field_dim_in_U": [10, 16, 1],
|
||||
"viscosity": 0.002,
|
||||
"velocity": 0.01,
|
||||
"boundary_conditions": {
|
||||
"x": ["parabolic", "outflow"],
|
||||
"y": ["noslip", "noslip"],
|
||||
"z": ["none", "none"]
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
|
||||
}
|
||||
8
src/CelerisLab/cuda/__init__.py
Normal file
8
src/CelerisLab/cuda/__init__.py
Normal file
@ -0,0 +1,8 @@
|
||||
# CelerisLab/cuda/__init__.py
|
||||
"""
|
||||
CUDA compiler and kernel management utilities.
|
||||
"""
|
||||
|
||||
from . import compiler
|
||||
|
||||
__all__ = ['compiler']
|
||||
@ -1,15 +1,16 @@
|
||||
# CelerisLab/kernels/compiler.py
|
||||
# CelerisLab/cuda/compiler.py
|
||||
|
||||
import subprocess
|
||||
import re
|
||||
import os
|
||||
|
||||
from .utils import FlowFieldConfig, CudaConfig
|
||||
from ..common.utils import FlowFieldConfig, CudaConfig
|
||||
|
||||
|
||||
def kernel_path(file_name: str) -> str:
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
return os.path.join(current_dir, "kernels", file_name)
|
||||
# kernels are in lbm/kernels/
|
||||
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
return os.path.join(current_dir, "lbm", "kernels", file_name)
|
||||
|
||||
|
||||
def read_lines(file_path):
|
||||
16
src/CelerisLab/lbm/__init__.py
Normal file
16
src/CelerisLab/lbm/__init__.py
Normal file
@ -0,0 +1,16 @@
|
||||
# CelerisLab/lbm/__init__.py
|
||||
"""
|
||||
Lattice Boltzmann Method (LBM) module for fluid simulation.
|
||||
"""
|
||||
|
||||
try:
|
||||
from .driver import FlowField
|
||||
__all__ = ['FlowField']
|
||||
except ImportError as e:
|
||||
import warnings
|
||||
warnings.warn(
|
||||
f"LBM module not fully available: {e}. "
|
||||
"Install pycuda to use the full LBM functionality.",
|
||||
ImportWarning
|
||||
)
|
||||
__all__ = []
|
||||
@ -1,4 +1,4 @@
|
||||
# CelerisLab/driver.py
|
||||
# CelerisLab/lbm/driver.py
|
||||
|
||||
import pycuda.driver as cuda
|
||||
import numpy as np
|
||||
@ -6,9 +6,9 @@ import struct
|
||||
from scipy.special import jv, expi
|
||||
from typing import List, Tuple, Union, Optional
|
||||
|
||||
from . import utils
|
||||
from . import preprocess as preproc
|
||||
from . import compiler
|
||||
from ..common import utils
|
||||
from ..common import preprocess as preproc
|
||||
from ..cuda import compiler
|
||||
|
||||
FLUID = 0b00000001
|
||||
SOLID = 0b00000010
|
||||
Loading…
Reference in New Issue
Block a user