Undermind审计前,Cursor重构
This commit is contained in:
1 parent
654e3290a4
commit
925417abcb
55 files changed
+5510
-3554
No files matched your search
@@ -44,6 +44,7 @@ pip install -e . # Installs from src/ directory
|
||||
```python
|
||||
from CelerisLab import Simulation
|
||||
|
||||
# Path is optional; see Configuration → paths. Example passes the usual relative name.
|
||||
sim = Simulation("configs/config_lbm.json")
|
||||
sim.add_cylinder(center=(50, 50), radius=10)
|
||||
sim.initialize()
|
||||
@@ -67,41 +68,63 @@ with Simulation("configs/config_lbm.json") as sim:
|
||||
|
||||
## Configuration
|
||||
|
||||
### `configs/config_lbm.json`
|
||||
### Where `config_lbm.json` is loaded from
|
||||
|
||||
`load_lbm_config()` resolves `config_lbm.json` in this order: an explicit path argument to `Simulation(...)` / `load_lbm_config(path)`, then `$CELERISLAB_CONFIG_DIR/config_lbm.json`, then `./configs/config_lbm.json` under the current working directory, then the copy shipped inside the installed package at `CelerisLab/configs/config_lbm.json`. In a source checkout the same file lives at `src/CelerisLab/configs/config_lbm.json`. There is **no** top-level `configs/` directory at the repository root; from the clone root you can omit the path (`Simulation()`), set `CELERISLAB_CONFIG_DIR`, or create your own `./configs/config_lbm.json`.
|
||||
|
||||
### `config_lbm.json` shape
|
||||
|
||||
The on-disk schema matches `src/CelerisLab/configs/config_lbm.json` (nested sections). Example fragment:
|
||||
|
||||
```json
|
||||
{
|
||||
"dim": 2,
|
||||
"nq": 9,
|
||||
"nx": 384,
|
||||
"ny": 192,
|
||||
"nz": 1,
|
||||
"viscosity": 0.0005,
|
||||
"velocity": 0.04,
|
||||
"rho": 1.0,
|
||||
"collision": "MRT",
|
||||
"streaming": "double_buffer",
|
||||
"les_enabled": true,
|
||||
"les_cs": 0.16,
|
||||
"trt_magic_param": 0.001,
|
||||
"omega_max": 1.90,
|
||||
"inlet_profile": "parabolic",
|
||||
"outlet_mode": "neq_extrap",
|
||||
"compute_capability": "auto",
|
||||
"threads_per_block": 256
|
||||
"grid": {
|
||||
"lattice_model": "D2Q9",
|
||||
"nx": 512,
|
||||
"ny": 256,
|
||||
"nz": 1
|
||||
},
|
||||
"physics": {
|
||||
"data_type": "FP32",
|
||||
"viscosity": 0.0035,
|
||||
"velocity": 0.03,
|
||||
"rho": 1.0
|
||||
},
|
||||
"method": {
|
||||
"collision": "SRT",
|
||||
"streaming": "double_buffer",
|
||||
"store_precision": "FP32",
|
||||
"ddf_shifting": false,
|
||||
"les": { "enabled": false, "cs": 0.16, "closed_form": true },
|
||||
"trt": { "magic_param": 0.1875 },
|
||||
"inlet": { "profile": "parabolic", "trt_neq_damp": 0.5 },
|
||||
"outlet": {
|
||||
"mode": "neq_extrap",
|
||||
"backflow_clamp": true,
|
||||
"blend_alpha": 0.7,
|
||||
"srt_neq_damp": 0.5
|
||||
},
|
||||
"omega_guard": { "min": 0.01, "max": 1.96 }
|
||||
},
|
||||
"cuda": {
|
||||
"threads_per_block": 256,
|
||||
"compute_capability": "auto"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Lattice size and model come from `grid`; viscosity and scales from `physics`; collision, LES, boundaries, and ω clamps from `method` (ω upper bound is `method.omega_guard.max`, not a top-level `omega_max`). For high-Re runs, keep `method.omega_guard.max` in the `1.90-1.96` window. See `src/CelerisLab/configs/CONFIG.md` for the full parameter tables.
|
||||
|
||||
### Parameter tiers
|
||||
|
||||
| Tier | Headers | Examples |
|
||||
|---|---|---|
|
||||
| Global/Grid | `config_grid.h` | DIM, NQ, NX, NY, NZ |
|
||||
| Global/Grid | `config_grid.h` | `NX`, `NY`, `NZ`, `LATTICE_MODEL`; `DIM` / `NQ` are **derived** from `LATTICE_MODEL` when `cuda/compiler_v2.py` emits headers (they are not separate keys in JSON) |
|
||||
| Global/Physics | `config_physics.h` | VIS, RHO, U0, flag constants |
|
||||
| Method | `config_method.h` | COLLISION_MODEL, USE_LES, TRT_MAGIC_PARAM, OMEGA_COLLISION_MAX |
|
||||
| Case | `config_objects.h` | N_OBJS |
|
||||
| Case | `config_objects.h`, `config_obs.h` | `N_OBJS`; packed obs macros `OBS_*` from `generate_config(cfg, n_objects=K)` (`max(N_OBJS,1)` × `DIM` per segment; no extra JSON keys) |
|
||||
|
||||
Headers are auto-generated by the compiler from `LBMConfig`; do not edit manually.
|
||||
Headers are auto-generated by `cuda/compiler_v2.py` from `LBMConfig`; do not edit manually.
|
||||
|
||||
## API Reference
|
||||
|
||||
@@ -111,17 +134,28 @@ Headers are auto-generated by the compiler from `LBMConfig`; do not edit manuall
|
||||
sim = Simulation(lbm_config_path=None, body_config_path=None, device_id=0)
|
||||
sim.add_cylinder(center, radius) -> int
|
||||
sim.add_sensor(center, radius) -> int
|
||||
sim.initialize()
|
||||
sim.run(steps)
|
||||
sim.initialize() # recompiles with N_OBJS when bodies were added
|
||||
sim.run(steps, checkpoint_interval=0) # wires bodies.action_gpu / bodies.obs_gpu
|
||||
sim.step(n=1)
|
||||
sim.bodies # ObjectManager: packed buffers + zero_force_segment_async, ...
|
||||
sim.get_macroscopic() -> {"rho": ndarray, "ux": ndarray, "uy": ndarray}
|
||||
sim.get_ddf() -> ndarray
|
||||
sim.get_flags() -> ndarray
|
||||
sim.update_runtime_params(omega=..., u_inlet=...)
|
||||
sim.snapshot() / sim.restore()
|
||||
sim.save_checkpoint(path=None) -> str # HDF5; default path if omitted
|
||||
sim.load_checkpoint(path) # restores field, step count, bodies
|
||||
sim.close()
|
||||
```
|
||||
|
||||
### `LBMStepper` (advanced)
|
||||
|
||||
```python
|
||||
stepper.step(n=1, *, action_gpu, obs_gpu, stream=None)
|
||||
```
|
||||
|
||||
Curved BC / sensor lists live on `field.curved` and `field.sensors` (`CurvedLinkSoA` / `SensorSoA`), filled by `ObjectManager.sync_to_gpu(field)`.
|
||||
|
||||
### Vortex initialization
|
||||
|
||||
```python
|
||||
@@ -137,7 +171,7 @@ add_vortex(sim.field, center=(50, 50), radius=10.0, strength=1.0, vortex_type="l
|
||||
|---|---|
|
||||
| Low Re (≤ 500) | SRT or TRT, LES off |
|
||||
| Medium Re (500–2000) | MRT or SRT+LES |
|
||||
| High Re (2000–5000) | MRT+LES (most robust); SRT+LES; TRT+LES with `omega_max=1.90`, `trt_magic_param=0.001` |
|
||||
| High Re (2000–5000) | MRT+LES (most robust); SRT+LES; TRT+LES with `method.omega_guard.max` in `1.90-1.96` (default `1.96`) and tuned `method.trt.magic_param` (default `0.1875`) |
|
||||
|
||||
## Project Layout
|
||||
|
||||
@@ -149,12 +183,13 @@ src/CelerisLab/
|
||||
compiler_v2.py Config header generation + nvcc + PTX load
|
||||
context.py CUDA context lifecycle
|
||||
lbm/
|
||||
field.py GPU memory management
|
||||
stepper.py Time-step driver
|
||||
field.py GPU memory + ``curved`` / ``sensors`` SoA handles
|
||||
curved_links.py CurvedLinkSoA / SensorSoA
|
||||
stepper.py Time-step driver (``action_gpu``, ``obs_gpu``)
|
||||
initializers.py Vortex superposition
|
||||
kernels/
|
||||
kernel_v2.cu Kernel entry (thin wrapper)
|
||||
config/ Auto-generated config headers
|
||||
config/ Auto-generated headers (``config_grid.h``, …, ``config_obs.h``)
|
||||
core/ Descriptors, layout, flags, params
|
||||
operators/ Collision, LES, forcing
|
||||
boundary/ Inlet, outlet, wall, curved, IBM
|
||||
@@ -162,12 +197,9 @@ src/CelerisLab/
|
||||
step/ Step orchestration
|
||||
body/
|
||||
objects.py SimObject / Cylinder / Sensor
|
||||
manager.py ObjectManager + GPU sync
|
||||
manager.py ObjectManager; packed ``obs_gpu`` / ``obs_pinned``, B3 helpers
|
||||
common/
|
||||
preprocess.py Geometry utilities
|
||||
tests/
|
||||
test_stability_matrix.py 13-case stability matrix (Re × collision × LES × streaming)
|
||||
test_high_re_validation.py High-Re directed validation (Re5000, 2D/3D, parameter sweep)
|
||||
output/
|
||||
CelerisLab_stage1_architecture.md Architecture specification (v3)
|
||||
refactor_brief_stage1.md Refactoring brief
|
||||
|
||||
Reference in new issue
Block a user