diff --git a/pyproject.toml b/pyproject.toml index b702f2c..5288151 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/setup.py b/setup.py index 3c67a73..1160c69 100644 --- a/setup.py +++ b/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', - ], - }, ) \ No newline at end of file diff --git a/src/CelerisLab/__init__.py b/src/CelerisLab/__init__.py index ba87619..e64195c 100644 --- a/src/CelerisLab/__init__.py +++ b/src/CelerisLab/__init__.py @@ -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'] \ No newline at end of file + __all__ = ['lbm', 'common', 'cuda', 'utils', '__version__'] diff --git a/src/CelerisLab/common/__init__.py b/src/CelerisLab/common/__init__.py new file mode 100644 index 0000000..7663ec6 --- /dev/null +++ b/src/CelerisLab/common/__init__.py @@ -0,0 +1,9 @@ +# CelerisLab/common/__init__.py +""" +Common utilities and preprocessing functions. +""" + +from . import utils +from . import preprocess + +__all__ = ['utils', 'preprocess'] diff --git a/src/CelerisLab/preprocess.py b/src/CelerisLab/common/preprocess.py similarity index 100% rename from src/CelerisLab/preprocess.py rename to src/CelerisLab/common/preprocess.py diff --git a/src/CelerisLab/utils.py b/src/CelerisLab/common/utils.py similarity index 98% rename from src/CelerisLab/utils.py rename to src/CelerisLab/common/utils.py index 9410a29..a087da7 100644 --- a/src/CelerisLab/utils.py +++ b/src/CelerisLab/common/utils.py @@ -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: diff --git a/src/CelerisLab/configs/config_cuda.json b/src/CelerisLab/configs/config_cuda.json deleted file mode 100644 index 3d4c10b..0000000 --- a/src/CelerisLab/configs/config_cuda.json +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/src/CelerisLab/configs/config_flowfield.json b/src/CelerisLab/configs/config_flowfield.json deleted file mode 100644 index 3f2f42d..0000000 --- a/src/CelerisLab/configs/config_flowfield.json +++ /dev/null @@ -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"] - } -} \ No newline at end of file diff --git a/src/CelerisLab/configs/config_gym.json b/src/CelerisLab/configs/config_gym.json deleted file mode 100644 index 544b7b4..0000000 --- a/src/CelerisLab/configs/config_gym.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} \ No newline at end of file diff --git a/src/CelerisLab/cuda/__init__.py b/src/CelerisLab/cuda/__init__.py new file mode 100644 index 0000000..8151d57 --- /dev/null +++ b/src/CelerisLab/cuda/__init__.py @@ -0,0 +1,8 @@ +# CelerisLab/cuda/__init__.py +""" +CUDA compiler and kernel management utilities. +""" + +from . import compiler + +__all__ = ['compiler'] diff --git a/src/CelerisLab/compiler.py b/src/CelerisLab/cuda/compiler.py similarity index 91% rename from src/CelerisLab/compiler.py rename to src/CelerisLab/cuda/compiler.py index c51cbe5..3734d75 100644 --- a/src/CelerisLab/compiler.py +++ b/src/CelerisLab/cuda/compiler.py @@ -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): diff --git a/src/CelerisLab/lbm/__init__.py b/src/CelerisLab/lbm/__init__.py new file mode 100644 index 0000000..0a8f33b --- /dev/null +++ b/src/CelerisLab/lbm/__init__.py @@ -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__ = [] diff --git a/configs/config_cuda.json b/src/CelerisLab/lbm/configs/config_cuda.json similarity index 100% rename from configs/config_cuda.json rename to src/CelerisLab/lbm/configs/config_cuda.json diff --git a/configs/config_flowfield.json b/src/CelerisLab/lbm/configs/config_flowfield.json similarity index 100% rename from configs/config_flowfield.json rename to src/CelerisLab/lbm/configs/config_flowfield.json diff --git a/configs/config_gym.json b/src/CelerisLab/lbm/configs/config_gym.json similarity index 100% rename from configs/config_gym.json rename to src/CelerisLab/lbm/configs/config_gym.json diff --git a/src/CelerisLab/driver.py b/src/CelerisLab/lbm/driver.py similarity index 99% rename from src/CelerisLab/driver.py rename to src/CelerisLab/lbm/driver.py index 09832ad..94649f2 100644 --- a/src/CelerisLab/driver.py +++ b/src/CelerisLab/lbm/driver.py @@ -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 diff --git a/src/CelerisLab/kernels/D2Q9.cu b/src/CelerisLab/lbm/kernels/D2Q9.cu similarity index 100% rename from src/CelerisLab/kernels/D2Q9.cu rename to src/CelerisLab/lbm/kernels/D2Q9.cu diff --git a/src/CelerisLab/kernels/IO.cu b/src/CelerisLab/lbm/kernels/IO.cu similarity index 100% rename from src/CelerisLab/kernels/IO.cu rename to src/CelerisLab/lbm/kernels/IO.cu diff --git a/src/CelerisLab/kernels/const.h b/src/CelerisLab/lbm/kernels/const.h similarity index 100% rename from src/CelerisLab/kernels/const.h rename to src/CelerisLab/lbm/kernels/const.h diff --git a/src/CelerisLab/kernels/kernel.cu b/src/CelerisLab/lbm/kernels/kernel.cu similarity index 100% rename from src/CelerisLab/kernels/kernel.cu rename to src/CelerisLab/lbm/kernels/kernel.cu diff --git a/src/CelerisLab/kernels/macros.h b/src/CelerisLab/lbm/kernels/macros.h similarity index 100% rename from src/CelerisLab/kernels/macros.h rename to src/CelerisLab/lbm/kernels/macros.h diff --git a/src/CelerisLab/kernels/preproc.cu b/src/CelerisLab/lbm/kernels/preproc.cu similarity index 100% rename from src/CelerisLab/kernels/preproc.cu rename to src/CelerisLab/lbm/kernels/preproc.cu