physics-and-simulation
Route direct PDE, fluid, particle, and SPH simulation workflows built on phi.physics.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- physics-and-simulation
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Route direct PDE, fluid, particle, and SPH simulation workflows built on phi.physics.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/troubleshooting.md7.8 KB
- 参考文档references/workflows.md12.8 KB
- 脚本scripts/wave_smoke.py3.4 KB
03 SKILL.md 正文
Physics and Simulation
Use this sub-skill when the task is to run or modify direct simulation code with phi.physics: grid advection, diffusion, incompressible pressure projection, obstacles, particle/grid FLIP or PIC coupling, wave-equation stepping, SPH kernels, finite-volume mesh terms, higher-order fluid stepping, or legacy Domain / boundary behavior.
Route here for
- Advection:
advect.semi_lagrangian(),advect.mac_cormack(),advect.advect(),advect.points(),advect.rk4(),advect.finite_rk4(), andadvect.differential()/advect.finite_difference(). - Diffusion:
diffuse.explicit(),diffuse.implicit(),diffuse.fourier(),diffuse.differential()/diffuse.finite_difference(). - Incompressible flow:
fluid.make_incompressible(),fluid.Obstacle,fluid.apply_boundary_conditions(),fluid.boundary_push(), andfluid.incompressible_rk4(). - Particles and SPH: FLIP/PIC particle-grid transfer patterns, boundary push after point advection,
sph.neighbor_graph(),sph.evaluate_kernel(), and SPH kernel forces. - Waves:
wave.step(),wave.euler_step(),wave.differential(), and the bundled deterministic wave smoke helper. - Boundaries: modern grid
boundary/extrapolationarguments, per-side extrapolations,Obstaclegeometries, active masks, and deprecatedDomainnotes. - Higher-order and FVM: direct PDE terms, orders 4/6 where supported,
fluid.incompressible_rk4(), meshFieldboundary dictionaries, and finite-volumediffuse.differential()/advect.differential().
Do not route optimization-through-gradients, plotting/UI, visualization-only notebooks, or maintainer-only topology-optimization demos here.
Start with these imports
from phi.flow import *
from phi import field, math
from phi.physics import advect, diffuse, fluid, wave, sph
from phiml.math import extrapolation, Solve, batch, channel, dual, instance, tensor, vec
Use the phi.flow import for common CenteredGrid, StaggeredGrid, PointCloud, Box, Sphere, Cuboid, Obstacle, Noise, resample, and math helpers. Import wave and sph explicitly; they are not part of the short fluid import trio.
Most common decisions
- Grid fluid step: create a
StaggeredGridvelocity, optionally a markerCenteredGrid, then do advection -> diffusion -> projection. PreferSolve(x0=pressure)in loops to reuse the pressure guess. - Advection scheme: use
semi_lagrangianfor robust defaults; usemac_cormackwhen numerical diffusion is the main issue and bounded correction is acceptable; useadvect.points(..., integrator=advect.finite_rk4)for particle positions sampled from grids. - Diffusion scheme: use
explicit(..., substeps=N)only when the diffusion CFL is safe; useimplicit()for largerdtor viscosity; usefourier()only for periodic grids with constant diffusivity. - Obstacle handling: pass
Geometryorfluid.Obstacleobjects tomake_incompressible(); use movingObstacle(..., velocity=..., angular_velocity=...)to impose obstacle velocities. Higher-order pressure projection does not support obstacles. - FLIP/PIC: transfer particles to a grid, project with
active=occupied, then update particles with either a FLIP delta (particles += resample(grid_v - prev_grid_v, to=particles)) or PIC replacement, advect points, and callboundary_push(). - SPH: build a particle
Geometry, callsph.neighbor_graph(nodes, kernel, ...), sum edge kernel values overdual, then integrate velocities and positions in your own step function. - Waves: use
wave.step(u, u_prev, c, dt)for leapfrog state pairs orwave.euler_step(u, v, c, dt)when initial velocity is known. Keepdtsmall relative to grid spacing and wave speed. - Legacy code: replace deprecated
Domain(...)helpers with direct constructor dictionaries when possible, e.g.domain = dict(x=64, y=64, bounds=Box(x=1, y=1), extrapolation=extrapolation.PERIODIC).
Verified signatures to rely on
advect.semi_lagrangian(field, velocity, dt, integrator=advect.euler)fluid.make_incompressible(velocity, obstacles=(), solve=Solve(), active=None, order=2, correct_skew=False, wide_stencil=None)wave.step(u, u_prev, c=1., dt=1., source=None)andwave.euler_step(u, v, c=1., dt=1., source=None)diffuse.explicit(u, diffusivity, dt, substeps=1, order=2, ...),diffuse.implicit(field, diffusivity, dt, solve=Solve('CG'), ...),diffuse.fourier(field, diffusivity, dt)sph.neighbor_graph(nodes, kernel, boundary=None, desired_neighbors=None, compute='kernel,grad', format='sparse', search_method='auto', domain=None, periodic=False)
Bundled references and helper
- Detailed recipes:
references/workflows.md - Failure handling:
references/troubleshooting.md - Deterministic wave smoke:
scripts/wave_smoke.py
From this sub-skill directory, smoke-test wave stepping with:
python scripts/wave_smoke.py --resolution 32 --steps 24 --dt 0.002
The helper intentionally uses a small grid and far fewer steps than the source demo so it is safe as an installation/API smoke test rather than a benchmark.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).